예제 #1
0
 /**
  * Добавляет голосование
  *
  * @param ModuleVote_EntityVote $oVote	Объект голосования
  * @return bool
  */
 public function AddVote(ModuleVote_EntityVote $oVote)
 {
     if (!$oVote->getIp()) {
         $oVote->setIp(func_getIp());
     }
     if ($this->oMapper->AddVote($oVote)) {
         $this->Cache_Delete("vote_{$oVote->getTargetType()}_{$oVote->getTargetId()}_{$oVote->getVoterId()}");
         $this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array("vote_update_{$oVote->getTargetType()}_{$oVote->getVoterId()}"));
         return true;
     }
     return false;
 }
예제 #2
0
 /**
  * Добавляет голосование
  *
  * @param ModuleVote_EntityVote $oVote    Объект голосования
  *
  * @return bool
  */
 public function AddVote(ModuleVote_EntityVote $oVote)
 {
     if (!$oVote->getIp()) {
         $oVote->setIp(F::GetUserIp());
     }
     if ($this->oMapper->AddVote($oVote)) {
         E::ModuleCache()->Delete("vote_{$oVote->getTargetType()}_{$oVote->getTargetId()}_{$oVote->getVoterId()}");
         E::ModuleCache()->CleanByTags(array("vote_update_{$oVote->getTargetType()}_{$oVote->getVoterId()}", "vote_update_{$oVote->getTargetType()}_{$oVote->getTargetId()}", "vote_update_{$oVote->getTargetType()}"));
         return true;
     }
     return false;
 }
예제 #3
0
 public function AddVote(ModuleVote_EntityVote $oVote)
 {
     if (!$oVote->getIp()) {
         $oVote->setIp(func_getIp());
     }
     if ($this->oMapper->AddVote($oVote)) {
         $this->Cache_Delete("vote_{$oVote->getTargetType()}_{$oVote->getTargetId()}_{$oVote->getVoterId()}");
         $this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array("vote_update_{$oVote->getTargetType()}_{$oVote->getVoterId()}"));
         if (in_array($oVote->getTargetType(), array('topic', 'comment', 'user'))) {
             $oAction = Engine::GetEntity("PluginFeedbacks_ModuleFeedbacks_EntityAction");
             $oAction->setUserIdFrom($oVote->getVoterId());
             $oAction->setId(null);
             $oAction->setAddDatetime(time());
             $oAction->setDestinationObjectId($oVote->getTargetId());
             if ($oVote->getTargetType() == 'topic') {
                 $oTopic = $this->Topic_GetTopicById($oVote->getTargetId());
                 $oAction->setUserIdTo($oTopic->getUserId());
                 if ($oVote->getDirection() > 0) {
                     $oAction->setActionType('VoteTopic');
                 }
                 if ($oVote->getDirection() < 0) {
                     $oAction->setActionType('VoteDownTopic');
                 }
                 if ($oVote->getDirection() == 0) {
                     $oAction->setActionType('VoteAbstainTopic');
                 }
             }
             if ($oVote->getTargetType() == 'comment') {
                 $oComment = $this->Comment_GetCommentById($oVote->getTargetId());
                 $oAction->setUserIdTo($oComment->getUserId());
                 if ($oVote->getDirection() > 0) {
                     $oAction->setActionType('VoteComment');
                 } else {
                     $oAction->setActionType('VoteDownComment');
                 }
             }
             if ($oVote->getTargetType() == 'user') {
                 $oAction->setUserIdTo($oVote->getTargetId());
                 if ($oVote->getDirection() > 0) {
                     $oAction->setActionType('VoteUser');
                 } else {
                     $oAction->setActionType('VoteDownUser');
                 }
             }
             return true;
             $this->PluginFeedbacks_Feedbacks_SaveAction($oAction);
         }
         return true;
     }
     return false;
 }
예제 #4
0
 /**
  * Добавляет голосование
  *
  * @param ModuleVote_EntityVote $oVote	Объект голосования
  * @return bool
  */
 public function AddVote(ModuleVote_EntityVote $oVote)
 {
     $sql = "INSERT INTO " . Config::Get('db.table.vote') . " \n\t\t\t(target_id,\n\t\t\ttarget_type,\n\t\t\tuser_voter_id,\n\t\t\tvote_direction,\n\t\t\tvote_value,\t\t\t\n\t\t\tvote_date,\n\t\t\tvote_ip\n\t\t\t)\n\t\t\tVALUES(?d, ?, ?d, ?d, ?f, ?, ?)\n\t\t";
     if ($this->oDb->query($sql, $oVote->getTargetId(), $oVote->getTargetType(), $oVote->getVoterId(), $oVote->getDirection(), $oVote->getValue(), $oVote->getDate(), $oVote->getIp()) === 0) {
         return true;
     }
     return false;
 }
 /**
  * @param ModuleVote_EntityVote $oVote
  *
  * @return bool
  */
 public function CheckForCreateBlockVote($oVote)
 {
     if (!($oUser = E::ModuleUser()->GetUserById($oVote->getVoterId()))) {
         return FALSE;
     }
     $sTarget = $oVote->getTargetType();
     $sType = $this->aVoteMirrow[$oVote->getDirection()];
     $aGroups = (array) Config::Get('plugin.magicrules.rule_block_vote');
     foreach ($aGroups as $aRule) {
         if (!in_array($sTarget, $aRule['target'])) {
             continue;
         }
         if (!in_array($sType, $aRule['type'])) {
             continue;
         }
         if (isset($aRule['rating'])) {
             if ($oUser->getRating() >= $aRule['rating']) {
                 continue;
             }
         }
         $sDate = date('Y-m-d H:i:s', time() - $aRule['period']);
         $iCount = $this->GetCountVote($oUser->getId(), $sTarget, $sDate);
         if ($iCount >= $aRule['count']) {
             $oBlock = Engine::GetEntity('PluginMagicrules_ModuleRule_EntityBlock');
             $oBlock->setUserId($oUser->getId());
             $oBlock->setType(self::BLOCK_TYPE_VOTE);
             $oBlock->setName(isset($aRule['name']) ? $aRule['name'] : '');
             $oBlock->setTarget($sTarget);
             if (isset($aRule['block_msg'])) {
                 $sMsg = $this->_text($aRule['block_msg']);
                 $oBlock->setMsg($sMsg);
             }
             $oBlock->setDateBlock(date('Y-m-d H:i:s', time() + $aRule['block_time']));
             $oBlock->setData(array('direction' => array_values(array_intersect_key(array_flip($this->aVoteMirrow), array_flip($aRule['type'])))));
             $oBlock->Add();
             // * Прекращаем обход правил
             if (!Config::Get('plugin.magicrules.processing_block_rule_all')) {
                 break;
             }
         }
     }
 }
예제 #6
0
 /**
  * Добавляет голосование
  *
  * @param ModuleVote_EntityVote $oVote    Объект голосования
  *
  * @return bool
  */
 public function AddVote(ModuleVote_EntityVote $oVote)
 {
     $sql = "INSERT INTO ?_vote\n\t\t\t(target_id,\n\t\t\ttarget_type,\n\t\t\tuser_voter_id,\n\t\t\tvote_direction,\n\t\t\tvote_value,\n\t\t\tvote_date,\n\t\t\tvote_ip\n\t\t\t)\n\t\t\tVALUES(?d, ?, ?d, ?d, ?f, ?, ?)\n\t\t";
     $xResult = $this->oDb->query($sql, $oVote->getTargetId(), $oVote->getTargetType(), $oVote->getVoterId(), $oVote->getDirection(), $oVote->getValue(), $oVote->getDate(), $oVote->getIp());
     return $xResult !== false;
 }