|
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
|
|
|
/** |
|
20
|
|
|
* Class SmartPersistableMlObjectHandler |
|
21
|
|
|
*/ |
|
22
|
|
|
class PersistableMlObjectHandler extends Smartobject\PersistableObjectHandler |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @param null|\CriteriaElement $criteria |
|
26
|
|
|
* @param bool $id_as_key |
|
27
|
|
|
* @param bool $as_object |
|
28
|
|
|
* @param bool $debug |
|
29
|
|
|
* @param bool $language |
|
30
|
|
|
* @return array |
|
31
|
|
|
*/ |
|
32
|
|
|
public function getObjects( |
|
33
|
|
|
\CriteriaElement $criteria = null, |
|
34
|
|
|
$id_as_key = false, |
|
35
|
|
|
$as_object = true, |
|
36
|
|
|
$debug = false, |
|
37
|
|
|
$language = false |
|
38
|
|
|
) { |
|
39
|
|
|
// Create the first part of the SQL query to join the "_text" table |
|
40
|
|
|
$sql = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname . ' INNER JOIN ' . $this->table . '_text AS ' . $this->_itemname . '_text ON ' . $this->_itemname . '.' . $this->keyName . '=' . $this->_itemname . '_text.' . $this->keyName; |
|
41
|
|
|
|
|
42
|
|
View Code Duplication |
if ($language) { |
|
|
|
|
|
|
43
|
|
|
// If a language was specified, then let's create a WHERE clause to only return the objects associated with this language |
|
44
|
|
|
|
|
45
|
|
|
// if no criteria was previously created, let's create it |
|
46
|
|
|
if (!$criteria) { |
|
47
|
|
|
$criteria = new \CriteriaCompo(); |
|
48
|
|
|
} |
|
49
|
|
|
$criteria->add(new \Criteria('language', $language)); |
|
50
|
|
|
|
|
51
|
|
|
return parent::getObjects($criteria, $id_as_key, $as_object, $debug, $sql); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
return parent::getObjects($criteria, $id_as_key, $as_object, $debug, $sql); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @param mixed $id |
|
59
|
|
|
* @param bool $language |
|
60
|
|
|
* @param bool $as_object |
|
61
|
|
|
* @param bool $debug |
|
62
|
|
|
* @return mixed |
|
63
|
|
|
*/ |
|
64
|
|
|
public function &get($id, $language = false, $as_object = true, $debug = false) |
|
65
|
|
|
{ |
|
66
|
|
View Code Duplication |
if (!$language) { |
|
|
|
|
|
|
67
|
|
|
return parent::get($id, $as_object, $debug); |
|
68
|
|
|
} else { |
|
69
|
|
|
$criteria = new \CriteriaCompo(); |
|
70
|
|
|
$criteria->add(new \Criteria('language', $language)); |
|
71
|
|
|
|
|
72
|
|
|
return parent::get($id, $as_object, $debug, $criteria); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function changeTableNameForML() |
|
77
|
|
|
{ |
|
78
|
|
|
$this->table = $this->db->prefix($this->_moduleName . '_' . $this->_itemname . '_text'); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
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.