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
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.