Ejemplo n.º 1
0
 public static function checkVote($relatedModule, $relatedId, $uid = 0)
 {
     $result = false;
     $uid = empty($uid) ? Ibos::app()->user->uid : $uid;
     $condition = "relatedmodule=:relatedmodule AND relatedid=:relatedid";
     $params = array(":relatedmodule" => $relatedModule, ":relatedid" => $relatedId);
     $vote = Vote::model()->fetch($condition, $params);
     if (!empty($vote)) {
         $voteid = $vote["voteid"];
         $voteItemList = VoteItem::model()->fetchAll("voteid=:voteid", array(":voteid" => $voteid));
         foreach ($voteItemList as $voteItem) {
             $itemid = $voteItem["itemid"];
             $itemCountList = VoteItemCount::model()->fetchAll("itemid=:itemid", array(":itemid" => $itemid));
             if (!empty($itemCountList) && 0 < count($itemCountList)) {
                 foreach ($itemCountList as $itemCount) {
                     if ($itemCount["uid"] == $uid) {
                         $result = true;
                         break;
                     }
                 }
             }
         }
     }
     return $result;
 }
Ejemplo n.º 2
0
 public function deleteAllByRelationIdsAndModule($relatedids, $relatedModule)
 {
     $relatedidArr = explode(",", $relatedids);
     foreach ($relatedidArr as $relatedid) {
         $vote = $this->fetch(array("select" => array("voteid"), "condition" => "relatedid=:relatedid AND relatedmodule=:relatedmodule", "params" => array(":relatedid" => $relatedid, ":relatedmodule" => $relatedModule)));
         if (!empty($vote)) {
             $voteId = $vote["voteid"];
             $voteItemList = VoteItem::model()->fetchAll("voteid=:voteid", array(":voteid" => $voteId));
             if (!empty($voteItemList)) {
                 $voteItemIds = "";
                 foreach ($voteItemList as $voteitem) {
                     $voteItemIds .= $voteitem["itemid"] . ",";
                 }
                 $voteitemids = trim($voteItemIds, ",");
                 VoteItemCount::model()->deleteAll("itemid IN({$voteitemids})");
                 VoteItem::model()->deleteAll("itemid IN({$voteitemids})");
             }
         }
     }
     return $this->deleteAll("relatedmodule='{$relatedModule}' AND relatedid IN({$relatedids})");
 }
Ejemplo n.º 3
0
 public function clickVote($relatedModule, $relatedId, $voteItemids)
 {
     $result = 0;
     if (!VoteUtil::checkVote($relatedModule, $relatedId)) {
         $affectedRow = VoteItem::model()->updateNumber($voteItemids);
         if ($affectedRow) {
             $voteitemidArray = explode(",", rtrim($voteItemids, ","));
             foreach ($voteitemidArray as $voteitemid) {
                 $voteItemCount = new VoteItemCount();
                 $voteItemCount->itemid = $voteitemid;
                 $voteItemCount->uid = Ibos::app()->user->uid;
                 $voteItemCount->save();
             }
             $voteData = Vote::model()->fetchVote($relatedModule, $relatedId);
             $result = VoteUtil::processVoteData($voteData);
         }
     } else {
         $result = -1;
     }
     return $result;
 }
Ejemplo n.º 4
0
<?php

$articleComments = Comment::model()->fetchAllByAttributes(array("module" => "article"));
$cidArr = ConvertUtil::getSubByKey($articleComments, "cid");
if (!empty($articleComments)) {
    $cidStr = implode(",", $cidArr);
    Comment::model()->deleteAll("rowid IN({$cidStr})");
    Comment::model()->deleteAllByAttributes(array("module" => "article"));
}
$isInstallVote = ModuleUtil::getIsEnabled("vote");
if ($isInstallVote) {
    $articleVotes = Vote::model()->fetchAllByAttributes(array("relatedmodule" => "article"));
    $voteidArr = ConvertUtil::getSubByKey($articleVotes, "voteid");
    $voteidStr = implode(",", $voteidArr);
    $articleVoteItems = VoteItem::model()->fetchAll("FIND_IN_SET(voteid, '{$voteidStr}')");
    $itemidArr = ConvertUtil::getSubByKey($articleVoteItems, "itemid");
    $itemidStr = implode(",", $itemidArr);
    VoteItemCount::model()->deleteAll("FIND_IN_SET(itemid, '{$itemidStr}')");
    VoteItem::model()->deleteAll("FIND_IN_SET(itemid, '{$itemidStr}')");
    Vote::model()->deleteAllByAttributes(array("relatedmodule" => "article"));
}
Ejemplo n.º 5
0
 private function updateVote($voteItemType, $type, $articleId, $uid)
 {
     if (empty($_POST["voteid"])) {
         $voteId = $this->addOrUpdateVote($_POST[$type], $articleId, $uid, "add");
         $this->addVoteItem($_POST[$type], $voteId, $voteItemType);
     } else {
         $newVoteItemArr = $oldVoteItemArr = $delFlagItemId = array();
         foreach ($_POST[$type]["voteItem"] as $key => $value) {
             if (substr($key, 0, 3) == "new") {
                 $newVoteItemArr[$key] = $value;
             } else {
                 $oldVoteItemArr[$key] = $value;
             }
         }
         $voteData = Vote::model()->fetchVote("article", $articleId);
         $itemData = $voteData["voteItemList"];
         foreach ($itemData as $value) {
             if (!array_key_exists($value["itemid"], $oldVoteItemArr)) {
                 $delFlagItemId[] = $value["itemid"];
             }
         }
         $this->addOrUpdateVote($_POST[$type], $articleId, $uid, "update", $_POST["voteid"]);
         $data = array("voteItem" => $newVoteItemArr);
         if ($type == "imageVote") {
             $data["picpath"] = $_POST[$type]["picpath"];
         }
         $this->addVoteItem($data, $_POST["voteid"], $voteItemType);
         foreach ($oldVoteItemArr as $key => $value) {
             $voteItem = array("content" => $value);
             if ($type == "imageVote") {
                 $voteItem["picpath"] = $_POST[$type]["picpath"][$key];
             }
             VoteItem::model()->modify($key, $voteItem);
         }
         VoteItem::model()->deleteByPk($delFlagItemId);
     }
     return true;
 }