1
|
|
|
<?php namespace XoopsModules\Smartobject; |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* You may not change or alter any portion of this comment or credits |
5
|
|
|
* of supporting developers from this source code or any supporting source code |
6
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
7
|
|
|
* |
8
|
|
|
* This program is distributed in the hope that it will be useful, |
9
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
10
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @copyright XOOPS Project https://xoops.org/ |
15
|
|
|
* @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) |
16
|
|
|
* @package |
17
|
|
|
* @since |
18
|
|
|
* @author XOOPS Development Team |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
use XoopsModules\Smartobject; |
22
|
|
|
|
23
|
|
|
// defined('XOOPS_ROOT_PATH') || die('Restricted access'); |
24
|
|
|
|
25
|
|
|
//require_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobject.php'; |
26
|
|
|
//require_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartplugins.php'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Class SmartobjectRating |
30
|
|
|
*/ |
31
|
|
|
class Rating extends Smartobject\BaseSmartObject |
32
|
|
|
{ |
33
|
|
|
public $_modulePlugin = false; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* SmartobjectRating constructor. |
37
|
|
|
*/ |
38
|
|
|
public function __construct() |
39
|
|
|
{ |
40
|
|
|
$this->quickInitVar('ratingid', XOBJ_DTYPE_INT, true); |
41
|
|
|
$this->quickInitVar('dirname', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_RATING_DIRNAME); |
42
|
|
|
$this->quickInitVar('item', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_RATING_ITEM); |
43
|
|
|
$this->quickInitVar('itemid', XOBJ_DTYPE_INT, true, _CO_SOBJECT_RATING_ITEMID); |
44
|
|
|
$this->quickInitVar('uid', XOBJ_DTYPE_INT, true, _CO_SOBJECT_RATING_UID); |
45
|
|
|
$this->quickInitVar('date', XOBJ_DTYPE_LTIME, true, _CO_SOBJECT_RATING_DATE); |
46
|
|
|
$this->quickInitVar('rate', XOBJ_DTYPE_INT, true, _CO_SOBJECT_RATING_RATE); |
47
|
|
|
|
48
|
|
|
$this->initNonPersistableVar('name', XOBJ_DTYPE_TXTBOX, 'user', _CO_SOBJECT_RATING_NAME); |
49
|
|
|
|
50
|
|
|
$this->setControl('dirname', [ |
51
|
|
|
'handler' => 'rating', |
52
|
|
|
'method' => 'getModuleList', |
53
|
|
|
'onSelect' => 'submit' |
54
|
|
|
]); |
55
|
|
|
|
56
|
|
|
$this->setControl('item', [ |
57
|
|
|
'object' => &$this, |
58
|
|
|
'method' => 'getItemList' |
59
|
|
|
]); |
60
|
|
|
|
61
|
|
|
$this->setControl('uid', 'user'); |
62
|
|
|
|
63
|
|
|
$this->setControl('rate', [ |
64
|
|
|
'handler' => 'rating', |
65
|
|
|
'method' => 'getRateList' |
66
|
|
|
]); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param string $key |
71
|
|
|
* @param string $format |
72
|
|
|
* @return mixed |
73
|
|
|
*/ |
74
|
|
View Code Duplication |
public function getVar($key, $format = 's') |
75
|
|
|
{ |
76
|
|
|
if ('s' === $format && in_array($key, ['name', 'dirname'])) { |
77
|
|
|
// return call_user_func(array($this, $key)); |
78
|
|
|
return $this->{$key}(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
return parent::getVar($key, $format); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @return string |
86
|
|
|
*/ |
87
|
|
|
public function name() |
88
|
|
|
{ |
89
|
|
|
$ret = Smartobject\Utility::getLinkedUnameFromId($this->getVar('uid', 'e'), true, []); |
|
|
|
|
90
|
|
|
|
91
|
|
|
return $ret; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @return mixed |
96
|
|
|
*/ |
97
|
|
|
public function dirname() |
98
|
|
|
{ |
99
|
|
|
global $smartobjectRatingHandler; |
100
|
|
|
$moduleArray = $smartobjectRatingHandler->getModuleList(); |
101
|
|
|
|
102
|
|
|
return $moduleArray[$this->getVar('dirname', 'n')]; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return mixed |
107
|
|
|
*/ |
108
|
|
|
public function getItemList() |
109
|
|
|
{ |
110
|
|
|
$plugin = $this->getModulePlugin(); |
111
|
|
|
|
112
|
|
|
return $plugin->getItemList(); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @return string |
117
|
|
|
*/ |
118
|
|
|
public function getItemValue() |
119
|
|
|
{ |
120
|
|
|
$moduleUrl = XOOPS_URL . '/modules/' . $this->getVar('dirname', 'n') . '/'; |
121
|
|
|
$plugin = $this->getModulePlugin(); |
122
|
|
|
$pluginItemInfo = $plugin->getItemInfo($this->getVar('item')); |
123
|
|
|
if (!$pluginItemInfo) { |
124
|
|
|
return ''; |
125
|
|
|
} |
126
|
|
|
$itemPath = sprintf($pluginItemInfo['url'], $this->getVar('itemid')); |
127
|
|
|
$ret = '<a href="' . $moduleUrl . $itemPath . '">' . $pluginItemInfo['caption'] . '</a>'; |
128
|
|
|
|
129
|
|
|
return $ret; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @return mixed |
134
|
|
|
*/ |
135
|
|
|
public function getRateValue() |
136
|
|
|
{ |
137
|
|
|
return $this->getVar('rate'); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @return bool |
142
|
|
|
*/ |
143
|
|
|
public function getModulePlugin() |
144
|
|
|
{ |
145
|
|
|
if (!$this->_modulePlugin) { |
146
|
|
|
global $smartobjectRatingHandler; |
147
|
|
|
$this->_modulePlugin = $smartobjectRatingHandler->pluginsObject->getPlugin($this->getVar('dirname', 'n')); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
return $this->_modulePlugin; |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: