Example #1
0
 /**
  * 通过主键,删除一条记录
  * @param integer $optionId
  * @return integer
  */
 public function removeByPk($optionId)
 {
     if (($optionId = (int) $optionId) <= 0) {
         return false;
     }
     $tableName = $this->getTblprefix() . TableNames::getPolloptions();
     $sql = $this->getCommandBuilder()->createDelete($tableName, '`option_id` = ?');
     $rowCount = $this->delete($sql, $optionId);
     return $rowCount;
 }
Example #2
0
 /**
  * 获取“投票名”验证规则
  * @param mixed $value
  * @return array
  */
 public function getPollIdRule($value)
 {
     return array('DbExists' => new validator\DbExistsValidator($value, true, Lang::_('SRV_FILTER_POLLOPTIONS_POLL_ID_EXISTS'), $this->getDbProxy(), TableNames::getPolls(), 'poll_id'));
 }
Example #3
0
 /**
  * 获取“投票Key”验证规则
  * @param mixed $value
  * @return array
  */
 public function getPollKeyRule($value)
 {
     return array('AlphaNum' => new validator\AlphaNumValidator($value, true, Lang::_('SRV_FILTER_POLLS_POLL_KEY_ALPHANUM')), 'MinLength' => new validator\MinLengthValidator($value, 2, Lang::_('SRV_FILTER_POLLS_POLL_KEY_MINLENGTH')), 'MaxLength' => new validator\MaxLengthValidator($value, 20, Lang::_('SRV_FILTER_POLLS_POLL_KEY_MAXLENGTH')), 'DbExists' => new validator\DbExistsValidator($value, false, Lang::_('SRV_FILTER_POLLS_POLL_KEY_UNIQUE'), $this->getDbProxy(), TableNames::getPolls(), 'poll_key'));
 }
Example #4
0
 /**
  * 投票-支持会员或游客、支持单选或多选
  * @param integer $pollId
  * @param array|integer $optIds
  * @param integer $visitorIp
  * @param integer $memberId
  * @return boolean
  */
 public function addVote($pollId, $optIds, $visitorIp, $memberId)
 {
     if (($pollId = (int) $pollId) <= 0) {
         return false;
     }
     $tmpOptIds = (array) $optIds;
     $optIds = array();
     foreach ($tmpOptIds as $value) {
         if (($value = (int) $value) > 0 && !in_array($value, $optIds)) {
             $optIds[] = $value;
         }
     }
     if ($optIds === array()) {
         return false;
     }
     $visitorIp = (int) $visitorIp;
     $memberId = max((int) $memberId, 0);
     $commands = array();
     $tableName = $this->getTblprefix() . TableNames::getPolloptions();
     foreach ($optIds as $value) {
         $commands[] = array('sql' => 'UPDATE `' . $tableName . '` SET `votes` = `votes` + 1 WHERE `option_id` = ?', 'params' => $value);
     }
     $optIds = implode(',', $optIds);
     $nowTime = time();
     if ($memberId > 0) {
         $tableName = $this->getTblprefix() . TableNames::getPollMemberLogs();
         $row = $this->getMemberLogs($pollId, $memberId);
         if ($row && is_array($row) && isset($row['log_id']) && isset($row['join_count'])) {
             $commands[] = array('sql' => 'UPDATE `' . $tableName . '` SET `option_ids` = ?, `join_count` = ?, `ts_last_modified` = ?, `ip_last_modified` = ? WHERE `log_id` = ?', 'params' => array('option_ids' => $optIds, 'join_count' => $row['join_count'] + 1, 'ts_last_modified' => $nowTime, 'ip_last_modified' => $visitorIp, 'log_id' => $row['log_id']));
         } else {
             $commands[] = array('sql' => 'INSERT INTO `' . $tableName . '` SET `member_id` = ?, `poll_id` = ?, `option_ids` = ?, `join_count` = ?, `ts_last_modified` = ?, `ip_last_modified` = ?', 'params' => array('member_id' => $memberId, 'poll_id' => $pollId, 'option_ids' => $optIds, 'join_count' => 1, 'ts_last_modified' => $nowTime, 'ip_last_modified' => $visitorIp));
         }
     } else {
         $tableName = $this->getTblprefix() . TableNames::getPollVisitorLogs();
         $row = $this->getVisitorLogs($pollId, $visitorIp);
         if ($row && is_array($row) && isset($row['log_id']) && isset($row['join_count'])) {
             $commands[] = array('sql' => 'UPDATE `' . $tableName . '` SET `option_ids` = ?, `join_count` = ?, `ts_last_modified` = ? WHERE `log_id` = ?', 'params' => array('option_ids' => $optIds, 'join_count' => $row['join_count'] + 1, 'ts_last_modified' => $nowTime, 'log_id' => $row['log_id']));
         } else {
             $commands[] = array('sql' => 'INSERT INTO `' . $tableName . '` SET `visitor_ip` = ?, `poll_id` = ?, `option_ids` = ?, `join_count` = ?, `ts_last_modified` = ?', 'params' => array('visitor_ip' => $visitorIp, 'poll_id' => $pollId, 'option_ids' => $optIds, 'join_count' => 1, 'ts_last_modified' => $nowTime));
         }
     }
     //TODO: 解决General error: 2014 Cannot execute queries while other unbuffered queries are active.错误,只是暂时解决方案.
     $this->getDbProxy()->getDriver()->close();
     return $this->doTransaction($commands);
 }