1
|
|
|
<?php namespace XoopsModules\Smartobject; |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Contains the class responsible for displaying a single SmartObject |
5
|
|
|
* |
6
|
|
|
* @license GNU |
7
|
|
|
* @author marcan <[email protected]> |
8
|
|
|
* @link http://smartfactory.ca The SmartFactory |
9
|
|
|
* @package SmartObject |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
use XoopsModules\Smartobject; |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* SmartObjectSingleView base class |
17
|
|
|
* |
18
|
|
|
* Base class handling the display of a single object |
19
|
|
|
* |
20
|
|
|
* @package SmartObject |
21
|
|
|
* @author marcan <[email protected]> |
22
|
|
|
* @link http://smartfactory.ca The SmartFactory |
23
|
|
|
*/ |
24
|
|
|
class SingleView |
25
|
|
|
{ |
26
|
|
|
public $_object; |
27
|
|
|
public $_userSide; |
28
|
|
|
public $_tpl; |
29
|
|
|
public $_rows; |
30
|
|
|
public $_actions; |
31
|
|
|
public $_headerAsRow = true; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Constructor |
35
|
|
|
* @param $object |
36
|
|
|
* @param bool $userSide |
37
|
|
|
* @param array $actions |
38
|
|
|
* @param bool $headerAsRow |
39
|
|
|
*/ |
40
|
|
|
public function __construct($object, $userSide = false, $actions = [], $headerAsRow = true) |
41
|
|
|
{ |
42
|
|
|
$this->_object = $object; |
43
|
|
|
$this->_userSide = $userSide; |
44
|
|
|
$this->_actions = $actions; |
45
|
|
|
$this->_headerAsRow = $headerAsRow; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param $rowObj |
50
|
|
|
*/ |
51
|
|
|
public function addRow($rowObj) |
52
|
|
|
{ |
53
|
|
|
$this->_rows[] = $rowObj; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param bool $fetchOnly |
58
|
|
|
* @param bool $debug |
59
|
|
|
* @return mixed|string|void |
60
|
|
|
*/ |
61
|
|
|
public function render($fetchOnly = false, $debug = false) |
62
|
|
|
{ |
63
|
|
|
require_once XOOPS_ROOT_PATH . '/class/template.php'; |
64
|
|
|
|
65
|
|
|
$this->_tpl = new \XoopsTpl(); |
66
|
|
|
$vars = $this->_object->vars; |
|
|
|
|
67
|
|
|
$smartobjectObjectArray = []; |
68
|
|
|
|
69
|
|
|
foreach ($this->_rows as $row) { |
70
|
|
|
$key = $row->getKeyName(); |
71
|
|
|
if ($row->_customMethodForValue && method_exists($this->_object, $row->_customMethodForValue)) { |
72
|
|
|
$method = $row->_customMethodForValue; |
73
|
|
|
$value = $this->_object->$method(); |
74
|
|
|
} else { |
75
|
|
|
$value = $this->_object->getVar($row->getKeyName()); |
76
|
|
|
} |
77
|
|
|
if ($row->isHeader()) { |
78
|
|
|
$this->_tpl->assign('smartobject_single_view_header_caption', $this->_object->vars[$key]['form_caption']); |
79
|
|
|
$this->_tpl->assign('smartobject_single_view_header_value', $value); |
80
|
|
|
} else { |
81
|
|
|
$smartobjectObjectArray[$key]['value'] = $value; |
82
|
|
|
$smartobjectObjectArray[$key]['header'] = $row->isHeader(); |
83
|
|
|
$smartobjectObjectArray[$key]['caption'] = $this->_object->vars[$key]['form_caption']; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
$action_row = ''; |
87
|
|
View Code Duplication |
if (in_array('edit', $this->_actions)) { |
|
|
|
|
88
|
|
|
$action_row .= $this->_object->getEditItemLink(false, true, true); |
89
|
|
|
} |
90
|
|
View Code Duplication |
if (in_array('delete', $this->_actions)) { |
|
|
|
|
91
|
|
|
$action_row .= $this->_object->getDeleteItemLink(false, true, true); |
92
|
|
|
} |
93
|
|
|
if ($action_row) { |
94
|
|
|
$smartobjectObjectArray['zaction']['value'] = $action_row; |
95
|
|
|
$smartobjectObjectArray['zaction']['caption'] = _CO_SOBJECT_ACTIONS; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
$this->_tpl->assign('smartobject_header_as_row', $this->_headerAsRow); |
99
|
|
|
$this->_tpl->assign('smartobject_object_array', $smartobjectObjectArray); |
100
|
|
|
|
101
|
|
|
if ($fetchOnly) { |
102
|
|
|
return $this->_tpl->fetch('db:smartobject_singleview_display.tpl'); |
103
|
|
|
} else { |
104
|
|
|
$this->_tpl->display('db:smartobject_singleview_display.tpl'); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @param bool $debug |
110
|
|
|
* @return mixed|string|void |
111
|
|
|
*/ |
112
|
|
|
public function fetch($debug = false) |
113
|
|
|
{ |
114
|
|
|
return $this->render(true, $debug); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.