8 require_once( CH_DIRECTORY_PATH_CLASSES .
'ChWsbVotingQuery.php' );
10 define(
'CH_PERIOD_PER_VOTE', 7 * 86400 );
11 define(
'CH_OLD_VOTES', 365*86400 );
107 $this->_sSystem = $sSystem;
108 if (isset($this->_aSystems[$sSystem]))
109 $this->_aSystem = $this->_aSystems[$sSystem];
133 $sClassName =
'ChTemplVotingView';
135 require_once (CH_DIRECTORY_PATH_ROOT .
$aSystems[
$sSys][
'override_class_file']);
139 return new $sClassName(
$sSys,
$iId, $iInit);
144 if (isset(
$GLOBALS[
'ch_dol_voting_systems'])) {
145 return $GLOBALS[
'ch_dol_voting_systems'];
152 if (
null ===
$GLOBALS[
'ch_dol_voting_systems']) {
156 $sQuery =
"SELECT * FROM `sys_objects_vote`";
157 $rResult =
db_res($sQuery);
159 $GLOBALS[
'ch_dol_voting_systems'] = array();
160 while( $aRow = $rResult ->fetch() ) {
161 $GLOBALS[
'ch_dol_voting_systems'][$aRow[
'ObjectName']] = array
163 'table_rating' => $aRow[
'TableRating'],
164 'table_track' => $aRow[
'TableTrack'],
165 'row_prefix' => $aRow[
'RowPrefix'],
166 'max_votes' => $aRow[
'MaxVotes'],
167 'post_name' => $aRow[
'PostName'],
168 'is_duplicate' => is_int($aRow[
'IsDuplicate']) ? $aRow[
'IsDuplicate'] : constant($aRow[
'IsDuplicate']),
169 'is_on' => $aRow[
'IsOn'],
171 'className' => $aRow[
'className'],
172 'classFile' => $aRow[
'classFile'],
174 'trigger_table' => $aRow[
'TriggerTable'],
175 'trigger_field_rate' => $aRow[
'TriggerFieldRate'],
176 'trigger_field_rate_count' => $aRow[
'TriggerFieldRateCount'],
177 'trigger_field_id' => $aRow[
'TriggerFieldId'],
179 'override_class_name' => $aRow[
'OverrideClassName'],
180 'override_class_file' => $aRow[
'OverrideClassFile'],
190 return $GLOBALS[
'ch_dol_voting_systems'];
201 if (!$this->_iId &&
$iId)
207 if(!$this->
isEnabled() || !$this->_oQuery)
210 $aVote = $this->_oQuery->getVote ($this->
getId());
211 if(
empty($aVote) || !is_array($aVote))
214 $this->_iCount = $aVote[
'count'];
215 $this->_fRate = $aVote[
'rate'];
227 if(!$this->_oQuery->putVote ($this->getId(), $sVoterIdentification, $iVote))
241 if (isset($this->_checkActionResult))
242 return $this->_checkActionResult;
254 return $this->_oQuery->isDublicateVote ($this->
getId(), $sVoterIdentification);
264 return $this->_aSystem[
'is_on'];
269 return $this->_aSystem[
'max_votes'];
300 return $this->_oQuery->getSqlParts ($sMailTable, $sMailField);
307 return isset($this->_aSystems[$sSystem]);
312 if (!(
int)
$iId)
return false;
313 $this->_oQuery->deleteVotings (
$iId);
319 return $this->_oQuery->getTopVotedItem ($iDays, $sJoinTable, $sJoinField, $sWhere);
324 return $this->_oQuery->getVotedItems ($sIp);
332 $iDeletedRecords = 0;
333 foreach ($this->_aSystems
as $aSystem) {
334 if (!$aSystem[
'is_on'])
336 $sPre = $aSystem[
'row_prefix'];
337 $iDeletedRecords +=
$GLOBALS[
'MySQL']->query(
"DELETE FROM `{$aSystem['table_track']}` WHERE `{$sPre}date` < DATE_SUB(NOW(), INTERVAL " .
CH_OLD_VOTES .
" SECOND)");
338 $GLOBALS[
'MySQL']->query(
"OPTIMIZE TABLE `{$aSystem['table_track']}`");
340 return $iDeletedRecords;
349 if($iResult ===
false)
361 if(strcasecmp($_SERVER[
'REQUEST_METHOD'],
'POST') !== 0 ||
ch_get($this->_aSystem[
'post_name']) ===
false)
364 $iVote = (int)
ch_get($this->_aSystem[
'post_name']);
379 if (!$this->_aSystem[
'trigger_table'])
387 return $this->_oQuery->updateTriggerTable(
$iId, $fRate, $iCount);