public function addlikeAction()
 {
     $this->getRequest()->isPost() || $this->showError('operate.fail');
     $fromid = (int) $this->getInput('fromid', 'post');
     $fromApp = $this->getInput('app', 'post');
     $subject = $this->getInput('subject', 'post');
     $url = $this->getInput('url', 'post');
     if ($fromid < 1 || empty($fromApp)) {
         $this->showError('BBS:like.fail');
     }
     $source = $this->_getLikeSourceDs()->getSourceByAppAndFromid($fromApp, $fromid);
     $newId = isset($source['sid']) ? (int) $source['sid'] : 0;
     Wind::import('SRV:like.dm.PwLikeSourceDm');
     if ($newId < 1) {
         $dm = new PwLikeSourceDm();
         $dm->setSubject($subject)->setSourceUrl($url)->setFromApp($fromApp)->setFromid($fromid)->setLikeCount(0);
         $newId = $this->_getLikeSourceDs()->addSource($dm);
     } else {
         $dm = new PwLikeSourceDm($source['sid']);
         $dm->setLikeCount($source['like_count']);
         $this->_getLikeSourceDs()->updateSource($dm);
     }
     $resource = $this->_getLikeService()->addLike($this->loginUser, 9, $newId);
     if ($resource instanceof PwError) {
         $this->showError($resource->getError());
     }
     $this->setOutput($resource, 'data');
     $this->showMessage('BBS:like.success');
 }
Beispiel #2
0
 private function _updateLikeCount($typeid, $fromid, $count)
 {
     switch ($typeid) {
         case PwLikeContent::THREAD:
             Wind::import('SRV:forum.dm.PwTopicDm');
             $dm = new PwTopicDm($fromid);
             $dm->setLikeCount($count);
             return Wekit::load('forum.PwThread')->updateThread($dm, PwThread::FETCH_MAIN);
         case PwLikeContent::POST:
             Wind::import('SRV:forum.dm.PwReplyDm');
             $dm = new PwReplyDm($fromid);
             $dm->setLikeCount($count);
             return Wekit::load('forum.PwThread')->updatePost($dm);
         case PwLikeContent::WEIBO:
             Wind::import('SRV:weibo.dm.PwWeiboDm');
             $dm = new PwWeiboDm($fromid);
             $dm->setLikeCount($count);
             return Wekit::load('weibo.PwWeibo')->updateWeibo($dm);
         case PwLikeContent::APP:
             Wind::import('SRV:like.dm.PwLikeSourceDm');
             $dm = new PwLikeSourceDm($fromid);
             $dm->setLikeCount($count);
             return Wekit::load('like.PwLikeSource')->updateSource($dm);
     }
 }