Changeset 770 for temp/test-xoops.ec-cube.net
- Timestamp:
- 2006/12/12 23:43:18 (19 years ago)
- Location:
- temp/test-xoops.ec-cube.net/html/modules/xoopspoll/class
- Files:
-
- 3 edited
-
xoopspoll.php (modified) (4 diffs)
-
xoopspolllog.php (modified) (5 diffs)
-
xoopspolloption.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
temp/test-xoops.ec-cube.net/html/modules/xoopspoll/class/xoopspoll.php
r731 r770 149 149 150 150 // public 151 function vote($option_id, $ip, $user_id=null )151 function vote($option_id, $ip, $user_id=null, $rating_id = 1, $comment = "") 152 152 { 153 153 if (!empty($option_id)) { … … 160 160 $log->setVar("option_id", $vote); 161 161 $log->setVar("ip", $ip); 162 $log->setVar("rating_id", $rating_id); 163 $log->setVar("comment", $comment); 162 164 if ( isset($user_id) ) { 163 165 $log->setVar("user_id", $user_id); … … 165 167 if(!$log->store()) { 166 168 } else { 167 $option->updateCount( );169 $option->updateCount($rating_id); 168 170 } 169 171 } … … 176 178 $log->setVar("option_id", $option_id); 177 179 $log->setVar("ip", $ip); 180 $log->setVar("rating_id", $rating_id); 181 $log->setVar("comment", $comment); 178 182 if ( isset($user_id) ) { 179 183 $log->setVar("user_id", $user_id); 180 184 } 181 185 $log->store(); 182 $option->updateCount( );186 $option->updateCount($rating_id); 183 187 } 184 188 } -
temp/test-xoops.ec-cube.net/html/modules/xoopspoll/class/xoopspolllog.php
r405 r770 45 45 $this->initVar("user_id", XOBJ_DTYPE_INT, 0); 46 46 $this->initVar("time", XOBJ_DTYPE_INT, null); 47 $this->initVar("rating_id", XOBJ_DTYPE_INT, null); 48 $this->initVar("comment", XOBJ_DTYPE_TXTAREA, null); 47 49 if ( !empty($id) ) { 48 50 if ( is_array($id) ) { … … 63 65 $$k = $v; 64 66 } 67 65 68 $log_id = $this->db->genId($this->db->prefix("xoopspoll_log")."_log_id_seq"); 66 $sql = "INSERT INTO ".$this->db->prefix("xoopspoll_log")." (log_id, poll_id, option_id, ip, user_id, time ) VALUES ($log_id, $poll_id, $option_id, ".$this->db->quoteString($ip).", $user_id, ".time().")";69 $sql = "INSERT INTO ".$this->db->prefix("xoopspoll_log")." (log_id, poll_id, option_id, ip, user_id, time, rating_id, comment) VALUES ($log_id, $poll_id, $option_id, ".$this->db->quoteString($ip).", $user_id, ".time().", $rating_id, ".$this->db->quoteString($comment).")"; 67 70 $result = $this->db->query($sql); 68 71 if (!$result) { … … 148 151 { 149 152 $db =& Database::getInstance(); 150 $sql = "SELECT DISTINCT user_id FROM ".$db->prefix("xoopspoll_log")." WHERE poll_id=".intval($poll_id)." AND user_id > 0 ";153 $sql = "SELECT DISTINCT user_id FROM ".$db->prefix("xoopspoll_log")." WHERE poll_id=".intval($poll_id)." AND user_id > 0 AND rating_id = 1"; 151 154 $users = $db->getRowsNum($db->query($sql)); 152 $sql = "SELECT DISTINCT ip FROM ".$db->prefix("xoopspoll_log")." WHERE poll_id=".intval($poll_id)." AND user_id=0 ";155 $sql = "SELECT DISTINCT ip FROM ".$db->prefix("xoopspoll_log")." WHERE poll_id=".intval($poll_id)." AND user_id=0 AND rating_id = 1"; 153 156 $anons = $db->getRowsNum($db->query($sql)); 154 157 return $users+$anons; … … 159 162 { 160 163 $db =& Database::getInstance(); 161 $sql = "SELECT COUNT(*) FROM ".$db->prefix("xoopspoll_log")." WHERE poll_id = ".intval($poll_id) ;164 $sql = "SELECT COUNT(*) FROM ".$db->prefix("xoopspoll_log")." WHERE poll_id = ".intval($poll_id)." AND rating_id = 1"; 162 165 list($votes) = $db->fetchRow($db->query($sql)); 163 166 return $votes; … … 165 168 166 169 // public static 167 function getTotalVotesByOptionId($option_id )170 function getTotalVotesByOptionId($option_id, $rating_id) 168 171 { 169 172 $db =& Database::getInstance(); 170 $sql = "SELECT COUNT(*) FROM ".$db->prefix("xoopspoll_log")." WHERE option_id = ".intval($option_id) ;173 $sql = "SELECT COUNT(*) FROM ".$db->prefix("xoopspoll_log")." WHERE option_id = ".intval($option_id)." AND rating_id = $rating_id"; 171 174 list($votes) = $db->fetchRow($db->query($sql)); 172 175 return $votes; -
temp/test-xoops.ec-cube.net/html/modules/xoopspoll/class/xoopspolloption.php
r739 r770 98 98 99 99 // public 100 function updateCount( )100 function updateCount($rating_id) 101 101 { 102 $votes = XoopsPollLog::getTotalVotesByOptionId($this->getVar("option_id")); 103 $sql ="UPDATE ".$this->db->prefix("xoopspoll_option")." SET option_count=$votes WHERE option_id=".$this->getVar("option_id").""; 102 if($rating_id == 1) { 103 $colum = "option_count"; 104 } else { 105 $colum = "minus_count"; 106 } 107 $votes = XoopsPollLog::getTotalVotesByOptionId($this->getVar("option_id"), $rating_id); 108 $sql ="UPDATE ".$this->db->prefix("xoopspoll_option")." SET $colum=$votes WHERE option_id=".$this->getVar("option_id").""; 109 104 110 $this->db->query($sql); 105 111 } … … 124 130 $db =& Database::getInstance(); 125 131 $ret = array(); 126 $sql = "SELECT u.uid, u.uname, l.rating_id, l.comment FROM ".$db->prefix("xoopspoll_log")." l , ". $db->prefix("users") ." u WHERE l.user_id = u.uid ANDl.option_id=".intval($option_id)." ORDER BY time DESC";132 $sql = "SELECT u.uid, u.uname, l.rating_id, l.comment FROM ".$db->prefix("xoopspoll_log")." l LEFT JOIN ". $db->prefix("users") ." u ON l.user_id = u.uid WHERE l.option_id=".intval($option_id)." ORDER BY time DESC"; 127 133 $result = $db->query($sql); 128 134 while ( $myrow = $db->fetchArray($result) ) {
Note: See TracChangeset
for help on using the changeset viewer.
