8 require_once( CH_DIRECTORY_PATH_CLASSES .
'ChWsbModuleDb.php' );
21 parent::__construct();
23 $this -> _oConfig = $oConfig;
24 $this -> _sTable = $oConfig -> sTableName;
25 $this -> sTablePrefix = $oConfig -> sTablePrefix;
41 function getAllPolls($sLimit, $iMemberID = 0, $bAllPolls =
false, $iApproval = 1, $sExtraSql =
null, $sOrder =
'`poll_date` DESC')
43 $sLimit = $this ->
escape($sLimit,
false);
44 $iMemberID = (int) $iMemberID;
45 $iApproval = (int) $iApproval;
46 $sExtraSql = $this ->
escape($sExtraSql,
false);
47 $sOrder = $this ->
escape($sOrder,
false);
52 $aWhereCondition = array();
54 $aWhereCondition[0] =
" AND `poll_status` = 'active' ";
55 $aWhereCondition[1] =
" AND `poll_approval` = {$iApproval}";
56 $aWhereCondition[2] =
" AND `id_profile` = {$iMemberID} ";
61 $sAddonSql = $aWhereCondition[1] . $aWhereCondition[2];
63 $sAddonSql = $aWhereCondition[0] . $aWhereCondition[1];
73 (UNIX_TIMESTAMP() - `poll_date`) AS 'sec',
87 return $this ->
getAll($sQuery);
99 $iStatus = (int) $iStatus;
100 settype($bOnlyPublic,
'boolean');
102 $sExtraSql = $bOnlyPublic ?
' AND `allow_view_to` = ' .
CH_WSB_PG_ALL :
null;
103 $sQuery =
"SELECT COUNT(*) FROM `{$this -> _sTable}` WHERE `poll_featured` = {$iStatus} {$sExtraSql}";
104 return $this ->
getOne($sQuery);
115 $sLimit = $this ->
escape($sLimit,
false);
116 $iStatus = (int) $iStatus;
117 settype($bOnlyPublic,
'boolean');
119 $sExtraSql = $bOnlyPublic ?
' AND `allow_view_to` = ' .
CH_WSB_PG_ALL :
null;
120 $sQuery =
"SELECT *, UNIX_TIMESTAMP()-`poll_date` AS `poll_ago` FROM `{$this -> _sTable}` WHERE `poll_status`='active' AND `poll_approval`='1' AND `poll_featured`='{$iStatus}' {$sExtraSql} ORDER BY `poll_date` DESC {$sLimit}";
121 return $this ->
getAll($sQuery);
132 function getPollsCount($iMemberID = 0, $bAllPools =
false, $iApproval = 1, $sExtraSql =
null)
134 $iMemberID = (int) $iMemberID;
136 $iApproval = (int) $iApproval;
137 $sExtraSql = $this ->
escape($sExtraSql,
false);
142 $aWhereCondition = array();
144 $aWhereCondition[0] =
" AND `poll_status` = 'active' ";
145 $aWhereCondition[1] =
" AND `poll_approval` = {$iApproval} ";
146 $aWhereCondition[2] =
" AND `id_profile` = {$iMemberID} ";
153 $sAddonSql = $aWhereCondition[1] . $aWhereCondition[2];
155 $sAddonSql = $aWhereCondition[2];
159 $sAddonSql = $aWhereCondition[0] . $aWhereCondition[1];
175 return $this ->
getOne($sQuery);
189 $sQuery =
"SELECT COUNT(*) FROM `{$this -> _sTable}` WHERE `poll_approval` = 0 AND `id_profile` = {$iProfileId}";
190 return $this ->
getOne($sQuery);
207 $sQuery =
"SELECT *, UNIX_TIMESTAMP()-`poll_date` AS 'poll_ago' FROM `{$this -> _sTable}` WHERE `id_poll` = {$iPollId}";
208 return $this ->
getAll($sQuery);
223 $iVotesCount = (int) $iVotesCount;
230 `poll_results` = '{$sVotes}',
231 `poll_total_votes` = {$iVotesCount}
233 `id_poll` = {$iPollId}
236 return $this ->
query($sQuery);
254 `poll_{$sAction}` = IF (`poll_{$sAction}` = 1, 0, 1)
256 `id_poll` = {$iPollId}
259 return $this ->
query($sQuery);
276 $isAdmin = (bool) $isAdmin;
278 if( !is_array($aPoolInfo) ) {
283 foreach($aPoolInfo
as $sKey => $sValue) {
294 if ($aPoolInfo[
'owner_id']) {
295 $iPollsCount = $this ->
getPollsCount( $aPoolInfo[
'owner_id'],
true );
296 $iAutoActive = ($this -> _oConfig -> iAutoActivate) ? 1 : 0;
298 if (!$this -> _oConfig -> iAlowMembersPolls) {
303 if ($iPollsCount < $this -> _oConfig -> iAlowPollNumber || $isAdmin) {
304 $iCurrentDate = date(
'U');
310 `id_profile` = {$aPoolInfo['owner_id']},
311 `poll_question` = '{$aPoolInfo['question']}',
312 `poll_answers` = '{$aPoolInfo['answers']}',
313 `poll_results` = '{$aPoolInfo['results']}',
314 `poll_status` = 'active',
315 `poll_approval` = {$iAutoActive},
316 `poll_date` = {$iCurrentDate},
317 `poll_tags` = '{$aPoolInfo['tags']}',
318 `allow_comment_to` = {$aPoolInfo['allow_comment']},
319 `allow_vote_to` = {$aPoolInfo['allow_vote']},
320 `poll_categories` = '{$aPoolInfo['category']}',
321 `allow_view_to` = '{$aPoolInfo['allow_view']}'
324 $this ->
query($sQuery);
347 if( !is_array($aPoolInfo) ) {
352 foreach($aPoolInfo
as $sKey => $sValue) {
353 if($sKey !=
'answers' ) {
364 if ( isset($aPoolInfo[
'approve']) ) {
365 $sAddonSql = ( $aPoolInfo[
'approve'] )
366 ?
',`poll_approval` = 1'
367 :
',`poll_approval` = 0';
375 `poll_question` = '{$aPoolInfo['question']}',
376 `poll_answers` = '{$aPoolInfo['answers']}',
377 `poll_status` = '{$aPoolInfo['status']}',
378 `poll_tags` = '{$aPoolInfo['tags']}',
379 `allow_comment_to` = {$aPoolInfo['allow_comment']},
380 `allow_vote_to` = {$aPoolInfo['allow_vote']},
381 `poll_categories` = '{$aPoolInfo['category']}',
382 `allow_view_to` = '{$aPoolInfo['allow_view']}'
385 `id_poll` = {$aPoolInfo['Id']}
388 return $this ->
query($sQuery);
401 $sQuery =
"DELETE FROM `{$this -> _sTable}` WHERE `id_poll` = {$iPollId}";
402 return $this ->
query($sQuery);
419 `{$this -> sTablePrefix}cmts`,
420 `{$this -> sTablePrefix}cmts_track`
422 `{$this -> sTablePrefix}cmts`
424 `{$this -> sTablePrefix}cmts_track`
426 `{$this -> sTablePrefix}cmts_track`.`cmt_id` = `{$this -> sTablePrefix}cmts`.`cmt_id`
428 `{$this -> sTablePrefix}cmts`.`cmt_object_id` = {$iPollId}
436 `{$this -> sTablePrefix}rating`,
437 `{$this -> sTablePrefix}voting_track`
439 `{$this -> sTablePrefix}rating`
441 `{$this -> sTablePrefix}voting_track`
443 `{$this -> sTablePrefix}voting_track`.`id` = `{$this -> sTablePrefix}rating`.`id`
445 `{$this -> sTablePrefix}rating`.`id` = {$iPollId}
462 $iYear = (int) $iYear;
463 $iMonth = (int) $iMonth;
464 $iNextYear = (int) $iNextYear;
465 $iNextMonth = (int) $iNextMonth;
467 return $this->
getAll (
"SELECT `id_poll`, DAYOFMONTH(FROM_UNIXTIME(`poll_date`)) AS `Day`
468 FROM `{$this -> _sTable}`
469 WHERE `poll_date` >= UNIX_TIMESTAMP('{$iYear}-{$iMonth}-1') AND `poll_date` < UNIX_TIMESTAMP('{$iNextYear}-{$iNextMonth}-1') AND `poll_approval` = 1");
480 return $this ->
getOne(
'SELECT `kateg` FROM `sys_options` WHERE `Name` = "' . $sCatName .
'"');