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;
 }
Beispiel #2
0
 public function addPoll($tid)
 {
     if (($attachInfo = $this->uploadOptionImage()) instanceof PwError) {
         return $attachInfo;
     }
     $pollData = $this->poll['poll'];
     $optionData = $this->poll['option'];
     Wind::import('SRV:poll.dm.PwPollDm');
     $pollDm = new PwPollDm();
     /* @var $pwPollDm PwPollDm */
     $pollDm->setIsViewResult($pollData['isviewresult']);
     $pollDm->setOptionLimit($pollData['optionlimit']);
     $pollDm->setCreatedUserid($this->user->uid);
     $pollData['regtimelimit'] && $pollDm->setRegtimeLimit(pw::str2time($pollData['regtimelimit']));
     $expiredTime = $pollData['expiredday'] ? intval($pollData['expiredday']) * 86400 + pw::getTime() : 0;
     $pollDm->setExpiredTime($expiredTime);
     $optinNum = $pollData['ismultiple'] ? count($optionData) : 0;
     $pollDm->setOptionLimit(min($optinNum, $pollData['optionlimit']));
     $attachInfo && $pollDm->setIsIncludeImg(1);
     $newPollid = $this->_getPollDS()->addPoll($pollDm);
     Wind::import('SRV:poll.dm.PwPollOptionDm');
     foreach ($optionData as $key => $value) {
         if (!$value) {
             continue;
         }
         $dm = new PwPollOptionDm();
         /* @var $pwPollDm PwPollDm */
         $image = isset($attachInfo['optionpic'][$key]) ? $attachInfo['optionpic'][$key]['path'] : '';
         $dm->setContent($value)->setPollid($newPollid)->setImage($image);
         $this->_getPollOptionDS()->add($dm);
     }
     Wind::import('SRV:poll.dm.PwThreadPollDm');
     $threadPollDm = new PwThreadPollDm();
     /* @var $threadPollDm PwThreadPollDm */
     $threadPollDm->setTid($tid)->setPollid($newPollid)->setCreatedUserid($this->user->uid);
     $this->_getThreadPollDS()->addPoll($threadPollDm);
     $this->_afterUpdate($newPollid);
     return true;
 }