public function copyPoll($tid, $newTid)
 {
     list($poll, $pollOption, $pollVoter) = $this->initInfo($tid);
     if (!$poll) {
         return;
     }
     Wind::import('SRV:poll.dm.PwPollDm');
     $pollDm = new PwPollDm();
     /* @var $pollDm PwPollDm */
     $pollDm->setVoterNum($poll['voter_num']);
     $pollDm->setIsViewResult($poll['isafter_view']);
     $pollDm->setIsIncludeImg($poll['isinclude_img']);
     $pollDm->setOptionLimit($poll['option_limit']);
     $pollDm->setRegtimeLimit($poll['regtime_limit']);
     $pollDm->setCreatedUserid($poll['created_userid']);
     $pollDm->setAppType($poll['app_type']);
     $pollDm->setExpiredTime($poll['expired_time']);
     $newPollid = $this->_getPollDS()->addPoll($pollDm);
     $optionVoter = array();
     foreach ($pollVoter as $value) {
         $optionVoter[$value['option_id']][] = $value['uid'];
     }
     Wind::import('SRV:poll.dm.PwPollOptionDm');
     foreach ($pollOption as $key => $value) {
         $pollOptionDm = new PwPollOptionDm();
         $pollOptionDm->setPollid($newPollid);
         $pollOptionDm->setVotedNum($value['voted_num']);
         $pollOptionDm->setContent($value['content']);
         $pollOptionDm->setImage($value['image']);
         $newOptionid = $this->_getPollOptionDs()->add($pollOptionDm);
         if (isset($optionVoter[$key]) && is_array($optionVoter[$key])) {
             $this->copyVoter($optionVoter[$key], $newPollid, $newOptionid);
         }
     }
     Wind::import('SRV:poll.dm.PwThreadPollDm');
     $threadPollDm = new PwThreadPollDm();
     $threadPollDm->setTid($newTid);
     $threadPollDm->setPollid($newPollid);
     $threadPollDm->setCreatedUserid($poll['created_userid']);
     $this->_getThreadPollDs()->addPoll($threadPollDm);
     return true;
 }
예제 #2
0
 /**
  * 用户投票
  *
  * @param int $userid
  * @param int $pollid
  * @param array $option
  * @return bool || PwError
  */
 public function doVote($userid, $pollid, $option)
 {
     $userid = intval($userid);
     $pollid = intval($pollid);
     if (!$userid || !$pollid) {
         return new PwError('VOTE:fail');
     }
     if (empty($option) || !is_array($option)) {
         return new PwError('VOTE:not.select.option');
     }
     $poll = $this->_getPollDs()->getPoll($pollid);
     if (!$poll) {
         return new PwError('VOTE:thread.not.exist');
     }
     $isVoted = $this->_getPollVoterDs()->isVoted($userid, $pollid);
     if ($isVoted) {
         return new PwError('VOTE:is.voted');
     }
     $voteTimeslimit = $poll['option_limit'] ? $poll['option_limit'] : 1;
     if (count($option) > $voteTimeslimit) {
         return new PwError('VOTE:most.times.limit', array('{mosttimes}' => $voteTimeslimit));
     }
     Wind::import('SRV:poll.dm.PwPollOptionDm');
     foreach ($option as $optionid) {
         $this->_getPollVoterDs()->add($userid, $pollid, $optionid);
         $pollOptionDm = new PwPollOptionDm($optionid);
         $pollOptionDm->addVotedNum(1);
         $this->_getPollOptionDs()->update($pollOptionDm);
     }
     //更新该投票人数
     $voterNum = $this->_getPollVoterDs()->countUser($pollid);
     Wind::import('SRV:poll.dm.PwPollDm');
     $pollDm = new PwPollDm($pollid);
     /* @var $pollDm PwPollDm */
     $pollDm->setVoterNum($voterNum);
     $this->_getPollDs()->updatePoll($pollDm);
     return true;
 }
예제 #3
0
 private function _afterUpdate($pollid)
 {
     $optionList = $this->_getPollOptionDS()->getByPollid($pollid);
     if (!$optionList) {
         return false;
     }
     $flag = false;
     foreach ($optionList as $value) {
         if (!$value['image']) {
             continue;
         }
         $flag = true;
     }
     Wind::import('SRV:poll.dm.PwPollDm');
     $dm = new PwPollDm($pollid);
     $dm->setIsIncludeImg($flag ? 1 : 0);
     $this->_getPollDs()->updatePoll($dm);
     return true;
 }
예제 #4
0
 /**
  * 更新投票选项
  *
  * @param PwPollDm $dm
  * @return boolean
  */
 public function updatePoll(PwPollDm $dm)
 {
     if (($result = $dm->beforeUpdate()) instanceof PwError) {
         return $result;
     }
     return $this->_getPollDao()->updatePoll($dm->poll_id, $dm->getData());
 }