Blanguage   A
last analyzed

Complexity

Total Complexity 20

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 43
dl 0
loc 73
rs 10
c 2
b 0
f 1
wmc 20

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A setBase() 0 3 1
C prepareVars() 0 33 17
A hasBase() 0 3 1
1
<?php
2
3
namespace XoopsModules\Xlanguage;
4
5
/**
6
 * xLanguage module (eXtensible Language Management For XOOPS)
7
 *
8
 * You may not change or alter any portion of this comment or credits
9
 * of supporting developers from this source code or any supporting source code
10
 * which is considered copyrighted (c) material of the original comment or credit authors.
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 *
15
 * @copyright    XOOPS Project (https://xoops.org)
16
 * @license      {@link https://www.gnu.org/licenses/gpl-2.0.html GNU Public License}
17
 * @package      xlanguage
18
 * @since        2.0
19
 * @author       D.J.(phppp) [email protected]
20
 **/
21
22
use XoopsDatabaseFactory;
23
use XoopsModules\Xlanguage;
24
use XoopsObject;
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//require(XOOPS_ROOT_PATH."/class/xoopslists.php");
39
//require XOOPS_ROOT_PATH.'/modules/xlanguage/include/vars.php';
40
//require XOOPS_ROOT_PATH.'/modules/xlanguage/class/Utility.php';
41
42
/**
43
 * Class Blanguage
44
 */
45
class Blanguage extends XoopsObject
46
{
47
    public $isBase = false;
48
    public $db;
49
    public $table;
50
51
    /**
52
     * Blanguage constructor.
53
     * @param bool $isBase
54
     */
55
    public function __construct($isBase = false)
56
    {
57
        $this->isBase = $isBase;
58
        $this->db     = XoopsDatabaseFactory::getDatabaseConnection();
59
        $this->table  = $this->db->prefix('xlanguage_base');
60
        $this->initVar('lang_id', \XOBJ_DTYPE_INT);
61
        $this->initVar('weight', \XOBJ_DTYPE_INT);
62
        $this->initVar('lang_name', \XOBJ_DTYPE_TXTBOX);
63
        $this->initVar('lang_desc', \XOBJ_DTYPE_TXTBOX);
64
        $this->initVar('lang_code', \XOBJ_DTYPE_TXTBOX);
65
        $this->initVar('lang_charset', \XOBJ_DTYPE_TXTBOX);
66
        $this->initVar('lang_image', \XOBJ_DTYPE_TXTBOX);
67
    }
68
69
    /**
70
     * @return bool
71
     */
72
    public function prepareVars()
73
    {
74
        foreach ($this->vars as $k => $v) {
75
            $cleanv = $this->cleanVars[$k];
76
            switch ($v['data_type']) {
77
                case \XOBJ_DTYPE_TXTBOX:
78
                case \XOBJ_DTYPE_TXTAREA:
79
                case \XOBJ_DTYPE_SOURCE:
80
                case \XOBJ_DTYPE_EMAIL:
81
                    $cleanv = $v['changed'] ? $cleanv : '';
82
                    if (!isset($v['not_gpc']) || !$v['not_gpc']) {
83
                        $cleanv = $this->db->quoteString($cleanv);
84
                    }
85
                    break;
86
                case \XOBJ_DTYPE_INT:
87
                    $cleanv = $v['changed'] ? (int)$cleanv : 0;
88
                    break;
89
                case \XOBJ_DTYPE_ARRAY:
90
                    $cleanv = $v['changed'] ? $cleanv : \serialize([]);
91
                    break;
92
                case \XOBJ_DTYPE_STIME:
93
                case \XOBJ_DTYPE_MTIME:
94
                case \XOBJ_DTYPE_LTIME:
95
                    $cleanv = $v['changed'] ? $cleanv : 0;
96
                    break;
97
                default:
98
                    break;
99
            }
100
            $this->cleanVars[$k] = &$cleanv;
101
            unset($cleanv);
102
        }
103
104
        return true;
105
    }
106
107
    public function setBase()
108
    {
109
        $this->isBase = true;
110
    }
111
112
    /**
113
     * @return bool
114
     */
115
    public function hasBase()
116
    {
117
        return $this->isBase;
118
    }
119
}
120