1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Contains the basis classes for managing any objects derived from SmartObjects |
5
|
|
|
* |
6
|
|
|
* @license GNU |
7
|
|
|
* @author marcan <[email protected]> |
8
|
|
|
* @link http://smartfactory.ca The SmartFactory |
9
|
|
|
* @package SmartObject |
10
|
|
|
* @subpackage SmartObjectCore |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); |
|
|
|
|
14
|
|
|
include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobject.php'; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* SmartObject base Multilanguage-enabled class |
18
|
|
|
* |
19
|
|
|
* Base class representing a single SmartObject with multilanguages capabilities |
20
|
|
|
* |
21
|
|
|
* @package SmartObject |
22
|
|
|
* @author marcan <[email protected]> |
23
|
|
|
* @link http://smartfactory.ca The SmartFactory |
24
|
|
|
*/ |
25
|
|
|
class SmartMlObject extends SmartObject |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* SmartMlObject constructor. |
29
|
|
|
*/ |
30
|
|
|
public function __construct() |
31
|
|
|
{ |
32
|
|
|
$this->initVar('language', XOBJ_DTYPE_TXTBOX, 'english', false, null, '', true, _CO_SOBJECT_LANGUAGE_CAPTION, _CO_SOBJECT_LANGUAGE_DSC, true, true); |
33
|
|
|
$this->setControl('language', 'language'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* If object is not new, change the control of the not-multilanguage fields |
38
|
|
|
* |
39
|
|
|
* We need to intercept this function from SmartObject because if the object is not new... |
40
|
|
|
*/ |
41
|
|
|
// function getForm() { |
|
|
|
|
42
|
|
|
|
43
|
|
|
//} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Strip Multilanguage Fields |
47
|
|
|
* |
48
|
|
|
* Get rid of all the multilanguage fields to have an object with only global fields. |
49
|
|
|
* This will be usefull when creating the ML object for the first time. Then we will be able |
50
|
|
|
* to create translations. |
51
|
|
|
*/ |
52
|
|
View Code Duplication |
public function stripMultilanguageFields() |
|
|
|
|
53
|
|
|
{ |
54
|
|
|
$objectVars =& $this->getVars(); |
55
|
|
|
$newObjectVars = array(); |
56
|
|
|
foreach ($objectVars as $key => $var) { |
57
|
|
|
if (!$var['multilingual']) { |
58
|
|
|
$newObjectVars[$key] = $var; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
$this->vars = $newObjectVars; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
View Code Duplication |
public function stripNonMultilanguageFields() |
|
|
|
|
65
|
|
|
{ |
66
|
|
|
$objectVars =& $this->getVars(); |
67
|
|
|
$newObjectVars = array(); |
68
|
|
|
foreach ($objectVars as $key => $var) { |
69
|
|
|
if ($var['multilingual'] || $key == $this->handler->keyName) { |
70
|
|
|
$newObjectVars[$key] = $var; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
$this->vars = $newObjectVars; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Make non multilanguage fields read only |
78
|
|
|
* |
79
|
|
|
* This is used when we are creating/editing a translation. |
80
|
|
|
* We only want to edit the multilanguag fields, not the global one. |
81
|
|
|
*/ |
82
|
|
|
public function makeNonMLFieldReadOnly() |
83
|
|
|
{ |
84
|
|
|
foreach ($this->getVars() as $key => $var) { |
85
|
|
|
//if (($key == 'language') || (!$var['multilingual'] && $key <> $this->handler->keyName)) { |
|
|
|
|
86
|
|
|
if (!$var['multilingual'] && $key != $this->handler->keyName) { |
87
|
|
|
$this->setControl($key, 'label'); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @param bool $onlyUrl |
94
|
|
|
* @param bool $withimage |
95
|
|
|
* @return string |
96
|
|
|
*/ |
97
|
|
|
public function getEditLanguageLink($onlyUrl = false, $withimage = true) |
98
|
|
|
{ |
99
|
|
|
$controller = new SmartObjectController($this->handler); |
100
|
|
|
|
101
|
|
|
return $controller->getEditLanguageLink($this, $onlyUrl, $withimage); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Class SmartPersistableMlObjectHandler |
107
|
|
|
*/ |
108
|
|
|
class SmartPersistableMlObjectHandler extends SmartPersistableObjectHandler |
109
|
|
|
{ |
110
|
|
|
/** |
111
|
|
|
* @param null $criteria |
112
|
|
|
* @param bool $id_as_key |
113
|
|
|
* @param bool $as_object |
114
|
|
|
* @param bool $debug |
115
|
|
|
* @param bool $language |
116
|
|
|
* @return array |
117
|
|
|
*/ |
118
|
|
|
public function getObjects($criteria = null, $id_as_key = false, $as_object = true, $debug = false, $language = false) |
119
|
|
|
{ |
120
|
|
|
// Create the first part of the SQL query to join the "_text" table |
121
|
|
|
$sql = 'SELECT * FROM ' . |
122
|
|
|
$this->table . |
123
|
|
|
' AS ' . |
124
|
|
|
$this->_itemname . |
125
|
|
|
' INNER JOIN ' . |
126
|
|
|
$this->table . |
127
|
|
|
'_text AS ' . |
128
|
|
|
$this->_itemname . |
129
|
|
|
'_text ON ' . |
130
|
|
|
$this->_itemname . |
131
|
|
|
'.' . |
132
|
|
|
$this->keyName . |
133
|
|
|
'=' . |
134
|
|
|
$this->_itemname . |
135
|
|
|
'_text.' . |
136
|
|
|
$this->keyName; |
137
|
|
|
|
138
|
|
View Code Duplication |
if ($language) { |
|
|
|
|
139
|
|
|
// If a language was specified, then let's create a WHERE clause to only return the objects associated with this language |
140
|
|
|
|
141
|
|
|
// if no criteria was previously created, let's create it |
142
|
|
|
if (!$criteria) { |
143
|
|
|
$criteria = new CriteriaCompo(); |
144
|
|
|
} |
145
|
|
|
$criteria->add(new Criteria('language', $language)); |
146
|
|
|
|
147
|
|
|
return parent::getObjects($criteria, $id_as_key, $as_object, $debug, $sql); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
return parent::getObjects($criteria, $id_as_key, $as_object, $debug, $sql); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @param mixed $id |
155
|
|
|
* @param bool $language |
156
|
|
|
* @param bool $as_object |
157
|
|
|
* @param bool $debug |
158
|
|
|
* @return mixed |
159
|
|
|
*/ |
160
|
|
|
public function &get($id, $language = false, $as_object = true, $debug = false) |
161
|
|
|
{ |
162
|
|
View Code Duplication |
if (!$language) { |
|
|
|
|
163
|
|
|
return parent::get($id, $as_object, $debug); |
164
|
|
|
} else { |
165
|
|
|
$criteria = new CriteriaCompo(); |
166
|
|
|
$criteria->add(new Criteria('language', $language)); |
167
|
|
|
|
168
|
|
|
return parent::get($id, $as_object, $debug, $criteria); |
169
|
|
|
} |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
public function changeTableNameForML() |
173
|
|
|
{ |
174
|
|
|
$this->table = $this->db->prefix($this->_moduleName . '_' . $this->_itemname . '_text'); |
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.