예제 #1
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;
             }
         }
     }
 }
예제 #3
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;
 }