本文整理汇总了PHP中CCatalog::_PrepareSql方法的典型用法代码示例。如果您正苦于以下问题:PHP CCatalog::_PrepareSql方法的具体用法?PHP CCatalog::_PrepareSql怎么用?PHP CCatalog::_PrepareSql使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCatalog
的用法示例。
在下文中一共展示了CCatalog::_PrepareSql方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: GetList
function GetList($arOrder = array(), $arFilter = array(), $arGroupBy = false, $arNavStartParams = false, $arSelectFields = array())
{
global $DB, $USER;
// for old-style execution
if (!is_array($arOrder) && !is_array($arFilter)) {
$arOrder = strval($arOrder);
$arFilter = strval($arFilter);
if ('' != $arOrder && '' != $arFilter) {
$arOrder = array($arOrder => $arFilter);
} else {
$arOrder = array();
}
if (is_array($arGroupBy)) {
$arFilter = $arGroupBy;
} else {
$arFilter = array();
}
$arGroupBy = false;
if ($arNavStartParams != false && '' != $arNavStartParams) {
$arFilter["LID"] = $arNavStartParams;
} else {
$arFilter["LID"] = LANGUAGE_ID;
}
}
if (!isset($arFilter['LID'])) {
$arFilter['LID'] = LANGUAGE_ID;
}
$strUserGroups = CCatalog::IsUserExists() ? $USER->GetGroups() : '2';
if (empty($arSelectFields)) {
$arSelectFields = array("ID", "NAME", "BASE", "SORT", "NAME_LANG", "CAN_ACCESS", "CAN_BUY", "XML_ID", "MODIFIED_BY", "CREATED_BY", "DATE_CREATE", "TIMESTAMP_X");
}
if ($arGroupBy == false) {
$arGroupBy = array("ID", "NAME", "BASE", "SORT", "XML_ID", "MODIFIED_BY", "CREATED_BY", "DATE_CREATE", "TIMESTAMP_X", "NAME_LANG");
}
$arFields = array("ID" => array("FIELD" => "CG.ID", "TYPE" => "int"), "NAME" => array("FIELD" => "CG.NAME", "TYPE" => "string"), "BASE" => array("FIELD" => "CG.BASE", "TYPE" => "char"), "SORT" => array("FIELD" => "CG.SORT", "TYPE" => "int"), "XML_ID" => array("FIELD" => "CG.XML_ID", "TYPE" => "string"), "TIMESTAMP_X" => array("FIELD" => "CG.TIMESTAMP_X", "TYPE" => "datetime"), "MODIFIED_BY" => array("FIELD" => "CG.MODIFIED_BY", "TYPE" => "int"), "DATE_CREATE" => array("FIELD" => "CG.DATE_CREATE", "TYPE" => "datetime"), "CREATED_BY" => array("FIELD" => "CG.CREATED_BY", "TYPE" => "int"), "NAME_LANG" => array("FIELD" => "CGL.NAME", "TYPE" => "string", "FROM" => "LEFT JOIN b_catalog_group_lang CGL ON (CG.ID = CGL.CATALOG_GROUP_ID AND CGL.LANG = '" . $DB->ForSql($arFilter["LID"], 2) . "')"));
$arFields["CAN_ACCESS"] = array("FIELD" => "IF(CGG.ID IS NULL, 'N', 'Y')", "TYPE" => "char", "FROM" => "LEFT JOIN b_catalog_group2group CGG ON (CG.ID = CGG.CATALOG_GROUP_ID AND CGG.GROUP_ID IN (" . $strUserGroups . ") AND CGG.BUY <> 'Y')", "GROUPED" => "N");
$arFields["CAN_BUY"] = array("FIELD" => "IF(CGG1.ID IS NULL, 'N', 'Y')", "TYPE" => "char", "FROM" => "LEFT JOIN b_catalog_group2group CGG1 ON (CG.ID = CGG1.CATALOG_GROUP_ID AND CGG1.GROUP_ID IN (" . $strUserGroups . ") AND CGG1.BUY = 'Y')", "GROUPED" => "N");
$arSqls = CCatalog::_PrepareSql($arFields, $arOrder, $arFilter, $arGroupBy, $arSelectFields);
$arSqls["SELECT"] = str_replace("%%_DISTINCT_%%", "", $arSqls["SELECT"]);
if (empty($arGroupBy) && is_array($arGroupBy)) {
$strSql = "SELECT " . $arSqls["SELECT"] . " FROM b_catalog_group CG " . $arSqls["FROM"];
if (!empty($arSqls["WHERE"])) {
$strSql .= " WHERE " . $arSqls["WHERE"];
}
if (!empty($arSqls["GROUPBY"])) {
$strSql .= " GROUP BY " . $arSqls["GROUPBY"];
}
if (!empty($arSqls["HAVING"])) {
$strSql .= " HAVING " . $arSqls["HAVING"];
}
$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_catalog_group CG " . $arSqls["FROM"];
if (!empty($arSqls["WHERE"])) {
$strSql .= " WHERE " . $arSqls["WHERE"];
}
if (!empty($arSqls["GROUPBY"])) {
$strSql .= " GROUP BY " . $arSqls["GROUPBY"];
}
if (!empty($arSqls["HAVING"])) {
$strSql .= " HAVING " . $arSqls["HAVING"];
}
if (!empty($arSqls["ORDERBY"])) {
$strSql .= " ORDER BY " . $arSqls["ORDERBY"];
}
$intTopCount = 0;
$boolNavStartParams = !empty($arNavStartParams) && is_array($arNavStartParams);
if ($boolNavStartParams && array_key_exists('nTopCount', $arNavStartParams)) {
$intTopCount = intval($arNavStartParams["nTopCount"]);
}
if ($boolNavStartParams && 0 >= $intTopCount) {
$strSql_tmp = "SELECT COUNT('x') as CNT FROM b_catalog_group CG " . $arSqls["FROM"];
if (!empty($arSqls["WHERE"])) {
$strSql_tmp .= " WHERE " . $arSqls["WHERE"];
}
if (!empty($arSqls["GROUPBY"])) {
$strSql_tmp .= " GROUP BY " . $arSqls["GROUPBY"];
}
if (!empty($arSqls["HAVING"])) {
$strSql_tmp .= " HAVING " . $arSqls["HAVING"];
}
$dbRes = $DB->Query($strSql_tmp, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
$cnt = 0;
if (empty($arSqls["GROUPBY"])) {
if ($arRes = $dbRes->Fetch()) {
$cnt = $arRes["CNT"];
}
} else {
$cnt = $dbRes->SelectedRowsCount();
}
$dbRes = new CDBResult();
$dbRes->NavQuery($strSql, $cnt, $arNavStartParams);
} else {
if ($boolNavStartParams && 0 < $intTopCount) {
$strSql .= " LIMIT " . $intTopCount;
//.........这里部分代码省略.........