Ignore:
Timestamp:
2006/12/12 23:43:18 (19 years ago)
Author:
uehara
Message:
 
Location:
temp/test-xoops.ec-cube.net/html/modules/xoopspoll/class
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • temp/test-xoops.ec-cube.net/html/modules/xoopspoll/class/xoopspoll.php

    r731 r770  
    149149 
    150150    // public 
    151     function vote($option_id, $ip, $user_id=null) 
     151    function vote($option_id, $ip, $user_id=null, $rating_id = 1, $comment = "") 
    152152    { 
    153153        if (!empty($option_id)) { 
     
    160160                        $log->setVar("option_id", $vote); 
    161161                        $log->setVar("ip", $ip); 
     162                        $log->setVar("rating_id", $rating_id); 
     163                        $log->setVar("comment", $comment); 
    162164                        if ( isset($user_id) ) { 
    163165                            $log->setVar("user_id", $user_id); 
     
    165167                        if(!$log->store()) { 
    166168                        } else { 
    167                             $option->updateCount(); 
     169                            $option->updateCount($rating_id); 
    168170                        } 
    169171                    } 
     
    176178                    $log->setVar("option_id", $option_id); 
    177179                    $log->setVar("ip", $ip); 
     180                    $log->setVar("rating_id", $rating_id); 
     181                    $log->setVar("comment", $comment); 
    178182                    if ( isset($user_id) ) { 
    179183                        $log->setVar("user_id", $user_id); 
    180184                    } 
    181185                    $log->store(); 
    182                     $option->updateCount(); 
     186                    $option->updateCount($rating_id); 
    183187                } 
    184188            } 
  • temp/test-xoops.ec-cube.net/html/modules/xoopspoll/class/xoopspolllog.php

    r405 r770  
    4545        $this->initVar("user_id", XOBJ_DTYPE_INT, 0); 
    4646        $this->initVar("time", XOBJ_DTYPE_INT, null); 
     47        $this->initVar("rating_id", XOBJ_DTYPE_INT, null); 
     48        $this->initVar("comment", XOBJ_DTYPE_TXTAREA, null); 
    4749        if ( !empty($id) ) { 
    4850            if ( is_array($id) ) { 
     
    6365            $$k = $v; 
    6466        } 
     67 
    6568        $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).")"; 
    6770        $result = $this->db->query($sql); 
    6871        if (!$result) { 
     
    148151    { 
    149152        $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"; 
    151154        $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"; 
    153156        $anons = $db->getRowsNum($db->query($sql)); 
    154157        return $users+$anons; 
     
    159162    { 
    160163        $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"; 
    162165        list($votes) = $db->fetchRow($db->query($sql)); 
    163166        return $votes; 
     
    165168 
    166169    // public static 
    167     function getTotalVotesByOptionId($option_id) 
     170    function getTotalVotesByOptionId($option_id, $rating_id) 
    168171    { 
    169172        $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"; 
    171174        list($votes) = $db->fetchRow($db->query($sql)); 
    172175        return $votes; 
  • temp/test-xoops.ec-cube.net/html/modules/xoopspoll/class/xoopspolloption.php

    r739 r770  
    9898 
    9999    // public 
    100     function updateCount() 
     100    function updateCount($rating_id) 
    101101    { 
    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 
    104110        $this->db->query($sql); 
    105111    } 
     
    124130        $db =& Database::getInstance(); 
    125131        $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 AND l.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"; 
    127133        $result = $db->query($sql); 
    128134        while ( $myrow = $db->fetchArray($result) ) { 
Note: See TracChangeset for help on using the changeset viewer.