8 require_once( CH_DIRECTORY_PATH_CLASSES .
'ChWsbDb.php' );
19 $this->_aSystem = &$aSystem;
20 parent::__construct();
25 $sPre = $this->_aSystem[
'row_prefix'];
26 $sTable = $this->_aSystem[
'table_rating'];
28 return $this->
getRow(
"SELECT `{$sPre}rating_count` as `count`, (`{$sPre}rating_sum` / `{$sPre}rating_count`) AS `rate` FROM {$sTable} WHERE `{$sPre}id` = ? LIMIT 1", [
$iId]);
33 $sPre = $this->_aSystem[
'row_prefix'];
35 $sTable = $this->_aSystem[
'table_rating'];
37 if ($this->
getOne(
"SELECT `{$sPre}id` FROM $sTable WHERE `{$sPre}id` = '$iId' LIMIT 1")) {
38 $ret = $this->
query (
"UPDATE {$sTable} SET `{$sPre}rating_count` = `{$sPre}rating_count` + 1, `{$sPre}rating_sum` = `{$sPre}rating_sum` + '$iRate' WHERE `{$sPre}id` = '$iId'");
40 $ret = $this->
query (
"INSERT INTO {$sTable} SET `{$sPre}id` = '$iId', `{$sPre}rating_count` = '1', `{$sPre}rating_sum` = '$iRate'");
45 $sTable = $this->_aSystem[
'table_track'];
46 return $this->
query (
"INSERT INTO {$sTable} SET `{$sPre}id` = '$iId', `{$sPre}ip` = '$sIp', `{$sPre}date` = NOW()");
51 $sPre = $this->_aSystem[
'row_prefix'];
52 $sTable = $this->_aSystem[
'table_track'];
53 $iSec = $this->_aSystem[
'is_duplicate'];
55 return $this->
getOne (
"SELECT `{$sPre}id` FROM {$sTable} WHERE `{$sPre}ip` = '$sIp' AND `{$sPre}id` = '$iId' AND UNIX_TIMESTAMP() - UNIX_TIMESTAMP(`{$sPre}date`) < $iSec");
65 $sMailField = $sMailTable.$sMailField;
67 $sPre = $this->_aSystem[
'row_prefix'];
68 $sTable = $this->_aSystem[
'table_rating'];
71 'fields' =>
",$sTable.`{$sPre}rating_count` as `voting_count`, ($sTable.`{$sPre}rating_sum` / $sTable.`{$sPre}rating_count`) AS `voting_rate` ",
73 'join' =>
" LEFT JOIN $sTable ON ({$sTable}.`{$sPre}id` = $sMailField) "
79 $sPre = $this->_aSystem[
'row_prefix'];
81 $sTable = $this->_aSystem[
'table_track'];
82 $this->
query (
"DELETE FROM {$sTable} WHERE `{$sPre}id` = '$iId'");
84 $sTable = $this->_aSystem[
'table_rating'];
85 return $this->
query (
"DELETE FROM {$sTable} WHERE `{$sPre}id` = '$iId'");
88 function getTopVotedItem ($iDays, $sJoinTable =
'', $sJoinField =
'', $sWhere =
'')
90 $sPre = $this->_aSystem[
'row_prefix'];
91 $sTable = $this->_aSystem[
'table_track'];
93 $sJoin = $sJoinTable && $sJoinField ?
" INNER JOIN $sJoinTable ON ({$sJoinTable}.{$sJoinField} = $sTable.`{$sPre}id`) " :
'';
95 return $this->
getOne (
"SELECT $sTable.`{$sPre}id`, COUNT($sTable.`{$sPre}id`) AS `voting_count` FROM {$sTable} $sJoin WHERE TO_DAYS(NOW()) - TO_DAYS($sTable.`{$sPre}date`) <= $iDays $sWhere GROUP BY $sTable.`{$sPre}id` HAVING `voting_count` > 2 ORDER BY `voting_count` DESC LIMIT 1");
100 $sPre = $this->_aSystem[
'row_prefix'];
101 $sTable = $this->_aSystem[
'table_track'];
102 $iSec = $this->_aSystem[
'is_duplicate'];
103 return $this->
getAll (
"SELECT `{$sPre}id` FROM {$sTable} WHERE `{$sPre}ip` = '$sIp' AND UNIX_TIMESTAMP() - UNIX_TIMESTAMP(`{$sPre}date`) < $iSec ORDER BY `{$sPre}date` DESC");
108 return $this->
query(
"UPDATE `{$this->_aSystem['trigger_table']}` SET `{$this->_aSystem['trigger_field_rate']}` = '$fRate', `{$this->_aSystem['trigger_field_rate_count']}` = '$iCount' WHERE `{$this->_aSystem['trigger_field_id']}` = '$iId'");