Current Path : /var/www/www-root/data/www.catalog.monolith-realty.ru/bitrix/modules/blog/mysql/ |
Current File : /var/www/www-root/data/www.catalog.monolith-realty.ru/bitrix/modules/blog/mysql/blog_group.php |
<?php require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/blog/general/blog_group.php"); class CBlogGroup extends CAllBlogGroup { /*************** ADD, UPDATE, DELETE *****************/ public static function Add($arFields) { global $DB; $arFields1 = array(); foreach ($arFields as $key => $value) { if (mb_substr($key, 0, 1) == "=") { $arFields1[mb_substr($key, 1)] = $value; unset($arFields[$key]); } } if (!CBlogGroup::CheckFields("ADD", $arFields)) return false; $arInsert = $DB->PrepareInsert("b_blog_group", $arFields); foreach ($arFields1 as $key => $value) { if ($arInsert[0] <> '') $arInsert[0] .= ", "; $arInsert[0] .= $key; if ($arInsert[1] <> '') $arInsert[1] .= ", "; $arInsert[1] .= $value; } if ($arInsert[0] <> '') { $strSql = "INSERT INTO b_blog_group(".$arInsert[0].") ". "VALUES(".$arInsert[1].")"; $DB->Query($strSql, False, "File: ".__FILE__."<br>Line: ".__LINE__); $ID = intval($DB->LastID()); return $ID; } return False; } public static function Update($ID, $arFields) { global $DB; $ID = intval($ID); $arFields1 = array(); foreach ($arFields as $key => $value) { if (mb_substr($key, 0, 1) == "=") { $arFields1[mb_substr($key, 1)] = $value; unset($arFields[$key]); } } if (!CBlogGroup::CheckFields("UPDATE", $arFields, $ID)) return false; $strUpdate = $DB->PrepareUpdate("b_blog_group", $arFields); foreach ($arFields1 as $key => $value) { if ($strUpdate <> '') $strUpdate .= ", "; $strUpdate .= $key."=".$value." "; } if ($strUpdate <> '') { $strSql = "UPDATE b_blog_group SET ". " ".$strUpdate." ". "WHERE ID = ".$ID." "; $DB->Query($strSql, False, "File: ".__FILE__."<br>Line: ".__LINE__); unset($GLOBALS["BLOG_GROUP"]["BLOG_GROUP_CACHE_".$ID]); return $ID; } return False; } //*************** SELECT *********************/ public static function GetList($arOrder = Array("ID" => "DESC"), $arFilter = Array(), $arGroupBy = false, $arNavStartParams = false, $arSelectFields = array()) { global $DB; if (!is_array($arSelectFields) || count($arSelectFields) <= 0) { $arSelectFields = array("ID", "NAME", "SITE_ID"); } // FIELDS --> $arFields = array( "ID" => array("FIELD" => "G.ID", "TYPE" => "int"), "NAME" => array("FIELD" => "G.NAME", "TYPE" => "string"), "SITE_ID" => array("FIELD" => "G.SITE_ID", "TYPE" => "string") ); // <-- FIELDS $arSqls = CBlog::PrepareSql($arFields, $arOrder, $arFilter, $arGroupBy, $arSelectFields); $arSqls["SELECT"] = str_replace("%%_DISTINCT_%%", "", $arSqls["SELECT"]); if (is_array($arGroupBy) && count($arGroupBy)==0) { $strSql = "SELECT ".$arSqls["SELECT"]." ". "FROM b_blog_group G ". " ".$arSqls["FROM"]." "; if ($arSqls["WHERE"] <> '') $strSql .= "WHERE ".$arSqls["WHERE"]." "; if ($arSqls["GROUPBY"] <> '') $strSql .= "GROUP BY ".$arSqls["GROUPBY"]." "; //echo "!1!=".htmlspecialcharsbx($strSql)."<br>"; $dbRes = $DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__); if ($arRes = $dbRes->Fetch()) return $arRes["CNT"]; else return False; } $strSql = "SELECT ".$arSqls["SELECT"]." ". "FROM b_blog_group G ". " ".$arSqls["FROM"]." "; if ($arSqls["WHERE"] <> '') $strSql .= "WHERE ".$arSqls["WHERE"]." "; if ($arSqls["GROUPBY"] <> '') $strSql .= "GROUP BY ".$arSqls["GROUPBY"]." "; if ($arSqls["ORDERBY"] <> '') $strSql .= "ORDER BY ".$arSqls["ORDERBY"]." "; if (is_array($arNavStartParams) && intval($arNavStartParams["nTopCount"])<=0) { $strSql_tmp = "SELECT COUNT('x') as CNT ". "FROM b_blog_group G ". " ".$arSqls["FROM"]." "; if ($arSqls["WHERE"] <> '') $strSql_tmp .= "WHERE ".$arSqls["WHERE"]." "; if ($arSqls["GROUPBY"] <> '') $strSql_tmp .= "GROUP BY ".$arSqls["GROUPBY"]." "; //echo "!2.1!=".htmlspecialcharsbx($strSql_tmp)."<br>"; $dbRes = $DB->Query($strSql_tmp, false, "File: ".__FILE__."<br>Line: ".__LINE__); $cnt = 0; if ($arSqls["GROUPBY"] == '') { if ($arRes = $dbRes->Fetch()) $cnt = $arRes["CNT"]; } else { // ������ ��� MYSQL!!! ��� ORACLE ������ ��� $cnt = $dbRes->SelectedRowsCount(); } $dbRes = new CDBResult(); //echo "!2.2!=".htmlspecialcharsbx($strSql)."<br>"; $dbRes->NavQuery($strSql, $cnt, $arNavStartParams); } else { if (is_array($arNavStartParams) && intval($arNavStartParams["nTopCount"]) > 0) $strSql .= "LIMIT ".intval($arNavStartParams["nTopCount"]); //echo "!3!=".htmlspecialcharsbx($strSql)."<br>"; $dbRes = $DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__); } return $dbRes; } }