Exemplo n.º 1
0
 function GetListEx($arOrder = array("ID" => "ASC"), $arFilter = array())
 {
     $err_mess = CAllVoteQuestion::err_mess() . "<br>Function: GetListEx<br>Line: ";
     global $DB;
     $arSqlSearch = array();
     $strSqlSearch = "";
     $arSqlOrder = array();
     $strSqlOrder = "";
     $arFilter = is_array($arFilter) ? $arFilter : array();
     foreach ($arFilter as $key => $val) {
         if ($val === "NOT_REF") {
             continue;
         }
         $key_res = VoteGetFilterOperation($key);
         $strNegative = $key_res["NEGATIVE"];
         $strOperation = $key_res["OPERATION"];
         $key = strtoupper($key_res["FIELD"]);
         switch ($key) {
             case "ID":
             case "VOTE_ID":
                 $str = ($strNegative == "Y" ? "NOT" : "") . "(VQ." . $key . " IS NULL OR VQ." . $key . "<=0)";
                 if (!empty($val)) {
                     $str = ($strNegative == "Y" ? " VQ." . $key . " IS NULL OR NOT " : "") . "(VQ." . $key . " " . $strOperation . " " . intVal($val) . ")";
                     if ($strOperation == "IN") {
                         $val = array_unique(array_map("intval", is_array($val) ? $val : explode(",", $val)), SORT_NUMERIC);
                         if (!empty($val)) {
                             $str = ($strNegative == "Y" ? " NOT " : "") . "(VQ." . $key . " IN (" . implode(",", $val) . "))";
                         }
                     }
                 }
                 $arSqlSearch[] = $str;
                 break;
             case "CHANNEL_ID":
                 if (strlen($val) <= 0) {
                     $arSqlSearch[] = ($strNegative == "Y" ? "NOT" : "") . "(V." . $key . " IS NULL OR V." . $key . "<=0)";
                 } else {
                     $arSqlSearch[] = ($strNegative == "Y" ? " V." . $key . " IS NULL OR NOT " : "") . "(V." . $key . " " . $strOperation . " " . intVal($val) . ")";
                 }
                 break;
             case "ACTIVE":
                 if (empty($val)) {
                     $arSqlSearch[] = ($strNegative == "Y" ? "NOT" : "") . "(VQ." . $key . " IS NULL OR " . ($DB->type == "MSSQL" ? "LEN" : "LENGTH") . "(VQ." . $key . ")<=0)";
                 } else {
                     $arSqlSearch[] = ($strNegative == "Y" ? " VQ." . $key . " IS NULL OR NOT " : "") . "(VQ." . $key . " " . $strOperation . " '" . $DB->ForSql($val) . "')";
                 }
                 break;
         }
     }
     if (count($arSqlSearch) > 0) {
         $strSqlSearch = " AND (" . implode(") AND (", $arSqlSearch) . ") ";
     }
     foreach ($arOrder as $by => $order) {
         $by = strtoupper($by);
         $order = strtoupper($order);
         if ($order != "ASC") {
             $order = "DESC";
         }
         if ($by == "ID") {
             $arSqlOrder[] = " VQ.ID " . $order . " ";
         } elseif ($by == "ACTIVE") {
             $arSqlOrder[] = " VQ.ACTIVE " . $order . " ";
         } else {
             $arSqlOrder[] = " VQ.ID " . $order . " ";
             $by = "ID";
         }
     }
     DelDuplicateSort($arSqlOrder);
     if (count($arSqlOrder) > 0) {
         $strSqlOrder = " ORDER BY " . implode(", ", $arSqlOrder);
     }
     $strSql = "\n\t\t\tSELECT VQ.*\n\t\t\tFROM\n\t\t\t\tb_vote_question VQ, b_vote V\n\t\t\tWHERE VQ.VOTE_ID = V.ID " . $strSqlSearch . "\n\t\t\t" . $strSqlOrder;
     return $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
 }
Exemplo n.º 2
0
 public static function setActive($ID, $activate = true)
 {
     $ID = intval($ID);
     if ($ID <= 0) {
         return false;
     }
     $activate = !!$activate;
     /***************** Event onBeforeVoteQuestionUpdate ****************/
     foreach (GetModuleEvents("vote", "onVoteQuestionActivate", true) as $arEvent) {
         if (ExecuteModuleEventEx($arEvent, array($ID, $activate)) === false) {
             return false;
         }
     }
     /***************** /Event ******************************************/
     global $DB;
     $err_mess = CAllVoteQuestion::err_mess() . "<br>Function: activate<br>Line: ";
     $strUpdate = $DB->PrepareUpdate("b_vote_question", array("ACTIVE" => $activate ? "Y" : "N", "~TIMESTAMP_X" => $DB->GetNowFunction()));
     $DB->QueryBind("UPDATE b_vote_question SET " . $strUpdate . " WHERE ID=" . $ID, array(), false, $err_mess);
     unset($GLOBALS["VOTE_CACHE"]["QUESTION"][$ID]);
     return $ID;
 }
Exemplo n.º 3
0
 function Update($ID, $arFields)
 {
     global $DB, $CACHE_MANAGER;
     $arBinds = array();
     $ID = intVal($ID);
     $err_mess = CAllVoteQuestion::err_mess() . "<br>Function: Update<br>Line: ";
     if ($ID <= 0 || !CVoteAnswer::CheckFields("UPDATE", $arFields, $ID)) {
         return false;
     }
     /***************** Event onBeforeVoteQuestionUpdate ****************/
     $events = GetModuleEvents("vote", "onBeforeVoteAnswerUpdate");
     while ($arEvent = $events->Fetch()) {
         if (ExecuteModuleEventEx($arEvent, array(&$ID, &$arFields)) === false) {
             return false;
         }
     }
     /***************** /Event ******************************************/
     if (empty($arFields)) {
         return false;
     }
     $arFields["~TIMESTAMP_X"] = $DB->GetNowFunction();
     $strUpdate = $DB->PrepareUpdate("b_vote_answer", $arFields);
     if (is_set($arFields, "MESSAGE")) {
         $arBinds["MESSAGE"] = $arFields["MESSAGE"];
     }
     if (!empty($strUpdate)) {
         $strSql = "UPDATE b_vote_answer SET " . $strUpdate . " WHERE ID=" . $ID;
         /*			$DB->QueryBind($strSql, $arBinds);*/
         $DB->Query($strSql, false, $err_mess);
     }
     /***************** Event onAfterVoteAnswerUpdate *******************/
     $events = GetModuleEvents("vote", "onAfterVoteAnswerUpdate");
     while ($arEvent = $events->Fetch()) {
         ExecuteModuleEventEx($arEvent, array($ID, $arFields));
     }
     /***************** /Event ******************************************/
     return $ID;
 }