1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace XoopsModules\Xoopspoll; |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
XOOPS - PHP Content Management System |
7
|
|
|
Copyright (c) 2000-2020 XOOPS.org |
8
|
|
|
<https://xoops.org> |
9
|
|
|
This program is free software; you can redistribute it and/or modify |
10
|
|
|
it under the terms of the GNU General Public License as published by |
11
|
|
|
the Free Software Foundation; either version 2 of the License, or |
12
|
|
|
(at your option) any later version. |
13
|
|
|
|
14
|
|
|
You may not change or alter any portion of this comment or credits |
15
|
|
|
of supporting developers from this source code or any supporting |
16
|
|
|
source code which is considered copyrighted (c) material of the |
17
|
|
|
original comment or credit authors. |
18
|
|
|
|
19
|
|
|
This program is distributed in the hope that it will be useful, |
20
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
21
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22
|
|
|
GNU General Public License for more details. |
23
|
|
|
|
24
|
|
|
You should have received a copy of the GNU General Public License |
25
|
|
|
along with this program; if not, write to the Free Software |
26
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
27
|
|
|
*/ |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Poll Option class for the XoopsPoll Module |
31
|
|
|
* |
32
|
|
|
* @copyright :: {@link https://xoops.org/ XOOPS Project} |
33
|
|
|
* @license :: {@link http://www.fsf.org/copyleft/gpl.html GNU public license} |
34
|
|
|
* @package :: xoopspoll |
35
|
|
|
* @subpackage:: class |
36
|
|
|
* @since :: 1.0 |
37
|
|
|
* @author :: {@link http://www.myweb.ne.jp/ Kazumi Ono (AKA onokazu)} |
38
|
|
|
*/ |
39
|
|
|
|
40
|
|
|
use XoopsModules\Xoopspoll\{ |
41
|
|
|
Helper |
|
|
|
|
42
|
|
|
}; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Class Option |
46
|
|
|
* @package XoopsModules\Xoopspoll |
47
|
|
|
*/ |
48
|
|
|
class Option extends \XoopsObject |
49
|
|
|
{ |
50
|
|
|
/** |
51
|
|
|
* database connection object |
52
|
|
|
* @var \XoopsDatabasefactory |
53
|
|
|
*/ |
54
|
|
|
// protected $db; |
55
|
|
|
/** |
56
|
|
|
* holds option object |
57
|
|
|
* @var Option |
58
|
|
|
*/ |
59
|
|
|
protected $option; |
60
|
|
|
/** |
61
|
|
|
* Option Handler to be used to manipulate poll options |
62
|
|
|
* @var OptionHandler |
63
|
|
|
*/ |
64
|
|
|
protected $optionHandler; |
65
|
|
|
|
66
|
|
|
// constructor |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param int|null $id poll id |
70
|
|
|
*/ |
71
|
|
|
public function __construct($id = null) |
72
|
|
|
{ |
73
|
|
|
parent::__construct(); |
74
|
|
|
// $this->db = \XoopsDatabaseFactory::getDatabaseConnection(); |
75
|
|
|
$this->initVar('option_id', \XOBJ_DTYPE_INT, null, false); |
76
|
|
|
$this->initVar('poll_id', \XOBJ_DTYPE_INT, null, true); |
77
|
|
|
$this->initVar('option_text', \XOBJ_DTYPE_TXTBOX, null, true, 255); |
78
|
|
|
$this->initVar('option_count', \XOBJ_DTYPE_INT, 0, false); |
79
|
|
|
$this->initVar('option_color', \XOBJ_DTYPE_OTHER, null, false); |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* {@internal The following is provided for backward compatibility with newbb/xforum} |
83
|
|
|
*/ |
84
|
|
|
$this->optHandler = $this->getStaticOptHandler(); |
|
|
|
|
85
|
|
|
if (!empty($id)) { |
86
|
|
|
if (\is_array($id)) { |
|
|
|
|
87
|
|
|
$this->option = $this->optHandler->create(); |
88
|
|
|
$this->option->assignVars($id); |
89
|
|
|
} else { |
90
|
|
|
$this->option = $this->optHandler->get($id); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
|
96
|
|
|
/**#@+ |
97
|
|
|
* @deprecated since Xoopspoll 1.40, please @see OptionHandler & @see Option |
98
|
|
|
*/ |
99
|
|
|
/** |
100
|
|
|
* |
101
|
|
|
* Stores object into the database |
102
|
|
|
* @uses XoopsPersistableObjectHandler::insert |
103
|
|
|
* @return mixed |
104
|
|
|
* @deprecated since Xoopspoll 1.40, please @see XoopspollOptionHandler & @see XoopspollOption |
105
|
|
|
*/ |
106
|
|
|
public function store() |
107
|
|
|
{ |
108
|
|
|
$trace = \debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 1); |
109
|
|
|
$GLOBALS['xoopsLogger']->addDeprecated(__CLASS__ . '::' . __METHOD__ . ' is deprecated since Xoopspoll 1.40, please use Poll and PollHandler classes instead.' . ". Called from {$trace[0]['file']}line {$trace[0]['line']}"); |
110
|
|
|
|
111
|
|
|
return $this->optHandler->insert($this->option); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Delete all the poll options for a specific poll |
116
|
|
|
* @uses XoopsPersistableObjectHandler::deleteAll |
117
|
|
|
* @param int $pid is used to delete all options by this id |
118
|
|
|
* @return mixed results of deleting objects from database |
119
|
|
|
* @uses XoopsPersistableObjectHandler::deleteAll |
120
|
|
|
*/ |
121
|
|
|
public function deleteByPollId($pid) |
122
|
|
|
{ |
123
|
|
|
$trace = \debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 1); |
124
|
|
|
$GLOBALS['xoopsLogger']->addDeprecated(__CLASS__ . '::' . __METHOD__ . ' is deprecated since Xoopspoll 1.40, please use PollHandler::' . __METHOD__ . ' instead.' . ". Called from {$trace[0]['file']}line {$trace[0]['line']}"); |
125
|
|
|
$criteria = new \Criteria('poll_id', (int)$pid, '='); |
126
|
|
|
|
127
|
|
|
return $this->optHandler->deleteAll($criteria); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Get all options for a particular poll |
132
|
|
|
* @uses XoopsPersistableObjectHandler::getAll |
133
|
|
|
* @param unknown $pid |
|
|
|
|
134
|
|
|
* @return mixed results of getting objects from database |
135
|
|
|
* @uses XoopsPersistableObjectHandler::getAll |
136
|
|
|
*/ |
137
|
|
|
public function getAllByPollId($pid) |
138
|
|
|
{ |
139
|
|
|
$trace = \debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 1); |
140
|
|
|
$GLOBALS['xoopsLogger']->addDeprecated(__CLASS__ . '::' . __METHOD__ . ' is deprecated since Xoopspoll 1.40, please use PollHandler::' . __METHOD__ . ' instead.' . ". Called from {$trace[0]['file']}line {$trace[0]['line']}"); |
141
|
|
|
$criteria = new \Criteria('poll_id', (int)$pid, '='); |
142
|
|
|
|
143
|
|
|
return $this->optHandler->getAll($criteria); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Reset the poll's options vote count |
148
|
|
|
* @param unknown_type $pid |
|
|
|
|
149
|
|
|
* @uses XoopsPersistableObjectHandler::updateAll |
150
|
|
|
* @return mixed results of the object(s) update |
151
|
|
|
* @uses XoopsPersistableObjectHandler::updateAll |
152
|
|
|
*/ |
153
|
|
|
public function resetCountByPollId($pid) |
154
|
|
|
{ |
155
|
|
|
$trace = \debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 1); |
156
|
|
|
$GLOBALS['xoopsLogger']->addDeprecated(__CLASS__ . '::' . __METHOD__ . ' is deprecated since Xoopspoll 1.40, please use PollHandler::' . __METHOD__ . ' instead.' . ". Called from {$trace[0]['file']}line {$trace[0]['line']}"); |
157
|
|
|
$soptHandler = $this->getStaticOptHandler(); |
158
|
|
|
$criteria = new \Criteria('poll_id', (int)$pid, '='); |
159
|
|
|
|
160
|
|
|
return $soptHandler->updateAll('option_count', 0, $criteria); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* Get a static Option Handler to be used to manipulate poll options |
165
|
|
|
* @return mixed handler object returned on success, false on failure |
166
|
|
|
* @uses xoops_getModuleHandler |
167
|
|
|
*/ |
168
|
|
|
private function getStaticOptHandler() |
169
|
|
|
{ |
170
|
|
|
static $optionHandler; |
171
|
|
|
|
172
|
|
|
if (!isset($optionHandler)) { |
173
|
|
|
$optionHandler = Helper::getInstance()->getHandler('Option'); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
return $optionHandler; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/**#@-*/ |
180
|
|
|
} |
181
|
|
|
|
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: