|
1
|
|
|
<?php namespace XoopsModules\Smartobject; |
|
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
|
|
|
use XoopsModules\Smartobject; |
|
14
|
|
|
|
|
15
|
|
|
// defined('XOOPS_ROOT_PATH') || die('Restricted access'); |
|
|
|
|
|
|
16
|
|
|
//require_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobject.php'; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* SmartObject base Multilanguage-enabled class |
|
20
|
|
|
* |
|
21
|
|
|
* Base class representing a single SmartObject with multilanguages capabilities |
|
22
|
|
|
* |
|
23
|
|
|
* @package SmartObject |
|
24
|
|
|
* @author marcan <[email protected]> |
|
25
|
|
|
* @link http://smartfactory.ca The SmartFactory |
|
26
|
|
|
*/ |
|
27
|
|
|
class MlObject extends Smartobject\BaseSmartObject |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* SmartMlObject constructor. |
|
31
|
|
|
*/ |
|
32
|
|
|
public function __construct() |
|
33
|
|
|
{ |
|
34
|
|
|
$this->initVar('language', XOBJ_DTYPE_TXTBOX, 'english', false, null, '', true, _CO_SOBJECT_LANGUAGE_CAPTION, _CO_SOBJECT_LANGUAGE_DSC, true, true); |
|
35
|
|
|
$this->setControl('language', 'language'); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* If object is not new, change the control of the not-multilanguage fields |
|
40
|
|
|
* |
|
41
|
|
|
* We need to intercept this function from SmartObject because if the object is not new... |
|
42
|
|
|
*/ |
|
43
|
|
|
// function getForm() { |
|
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
//} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Strip Multilanguage Fields |
|
49
|
|
|
* |
|
50
|
|
|
* Get rid of all the multilanguage fields to have an object with only global fields. |
|
51
|
|
|
* This will be usefull when creating the ML object for the first time. Then we will be able |
|
52
|
|
|
* to create translations. |
|
53
|
|
|
*/ |
|
54
|
|
View Code Duplication |
public function stripMultilanguageFields() |
|
|
|
|
|
|
55
|
|
|
{ |
|
56
|
|
|
$objectVars =& $this->getVars(); |
|
57
|
|
|
$newObjectVars = []; |
|
58
|
|
|
foreach ($objectVars as $key => $var) { |
|
59
|
|
|
if (!$var['multilingual']) { |
|
60
|
|
|
$newObjectVars[$key] = $var; |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
$this->vars = $newObjectVars; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
View Code Duplication |
public function stripNonMultilanguageFields() |
|
|
|
|
|
|
67
|
|
|
{ |
|
68
|
|
|
$objectVars =& $this->getVars(); |
|
69
|
|
|
$newObjectVars = []; |
|
70
|
|
|
foreach ($objectVars as $key => $var) { |
|
71
|
|
|
if ($var['multilingual'] || $key == $this->handler->keyName) { |
|
72
|
|
|
$newObjectVars[$key] = $var; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
$this->vars = $newObjectVars; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Make non multilanguage fields read only |
|
80
|
|
|
* |
|
81
|
|
|
* This is used when we are creating/editing a translation. |
|
82
|
|
|
* We only want to edit the multilanguag fields, not the global one. |
|
83
|
|
|
*/ |
|
84
|
|
|
public function makeNonMLFieldReadOnly() |
|
85
|
|
|
{ |
|
86
|
|
|
foreach ($this->getVars() as $key => $var) { |
|
87
|
|
|
//if (($key == 'language') || (!$var['multilingual'] && $key <> $this->handler->keyName)) { |
|
|
|
|
|
|
88
|
|
|
if (!$var['multilingual'] && $key != $this->handler->keyName) { |
|
89
|
|
|
$this->setControl($key, 'label'); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @param bool $onlyUrl |
|
96
|
|
|
* @param bool $withimage |
|
97
|
|
|
* @return string |
|
98
|
|
|
*/ |
|
99
|
|
|
public function getEditLanguageLink($onlyUrl = false, $withimage = true) |
|
100
|
|
|
{ |
|
101
|
|
|
$controller = new ObjectController($this->handler); |
|
102
|
|
|
|
|
103
|
|
|
return $controller->getEditLanguageLink($this, $onlyUrl, $withimage); |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
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.