本文整理汇总了PHP中E::ModuleDatabase方法的典型用法代码示例。如果您正苦于以下问题:PHP E::ModuleDatabase方法的具体用法?PHP E::ModuleDatabase怎么用?PHP E::ModuleDatabase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类E
的用法示例。
在下文中一共展示了E::ModuleDatabase方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addEnumType
/**
* Добавляет новый тип в поле enum(перечисление)
*
* @see ModuleDatabase::addEnumType
*
* @param string $sTableName - Название таблицы, необходимо перед именем таблицы добавлять "prefix_",
* это позволит учитывать произвольный префикс таблиц у пользователя
* @param string $sFieldName - Название поля в таблице
* @param string $sType - Название типа
*/
protected function addEnumType($sTableName, $sFieldName, $sType)
{
E::ModuleDatabase()->AddEnumType($sTableName, $sFieldName, $sType);
}
示例2: GetBlogsIdByCriteria
//.........这里部分代码省略.........
$aFilter['not_blog_id'] = array(intval($aFilter['not_blog_id']));
}
}
if (isset($aFilter['blog_title_like'])) {
if (substr($aFilter['blog_title_like'], -1) !== '%') {
$aFilter['blog_title_like'] .= '%';
}
}
if (isset($aFilter['exclude_type']) && !isset($aFilter['not_blog_type'])) {
$aFilter['not_blog_type'] = $aFilter['exclude_type'];
}
if (isset($aFilter['include_type']) && !isset($aFilter['blog_type'])) {
$aFilter['blog_type'] = $aFilter['include_type'];
}
// Сортировка
$sSqlOrder = '';
if (isset($aCriteria['order'])) {
$aOrderAllow = array('blog_id', 'blog_title', 'blog_rating', 'blog_count_user', 'blog_count_topic');
if (!is_array($aCriteria['order'])) {
$aCriteria['order'] = array($aCriteria['order']);
}
$aOrders = F::Array_FlipIntKeys($aCriteria['order'], 'ASC');
$aOrderList = array();
foreach ($aOrders as $sField => $sWay) {
$sField = strtolower(trim($sField));
if (strpos($sField, ' ')) {
list($sField, $sWay) = explode(' ', $sField, 2);
}
if (in_array($sField, $aOrderAllow)) {
$aOrderList[] = $sField . ' ' . (strtoupper($sWay) == 'DESC' ? 'DESC' : 'ASC');
}
}
if ($aOrderList) {
$sSqlOrder = 'ORDER BY ' . implode(',', $aOrderList);
}
}
// Установка лимита
$sSqlLimit = '';
list($nOffset, $nLimit) = $this->_prepareLimit($aCriteria);
// Если задан ID блога, то всегда устанавливаем лимит
if (isset($aFilter['blog_id']) && !is_array($aFilter['blog_id'])) {
$nOffset = false;
$nLimit = 1;
}
// Формируем строку лимита и автосчетчик общего числа записей
if ($nOffset !== false && $nLimit !== false) {
$sSqlLimit = 'LIMIT ' . $nOffset . ', ' . $nLimit;
$nCalcTotal = static::CRITERIA_CALC_TOTAL_AUTO;
} elseif ($nLimit != false && $nLimit != 1) {
$sSqlLimit = 'LIMIT ' . $nLimit;
$nCalcTotal = static::CRITERIA_CALC_TOTAL_AUTO;
} else {
$nCalcTotal = static::CRITERIA_CALC_TOTAL_SKIP;
}
// Обрабатываем опции
if (isset($aCriteria['options']) && is_array($aCriteria['options'])) {
if (array_key_exists('calc_total', $aCriteria['options'])) {
if ($aCriteria['options']['calc_total'] != static::CRITERIA_CALC_TOTAL_AUTO) {
$nCalcTotal = $aCriteria['options']['calc_total'];
}
// Если требуется только подсчет записей, то строку лимита принудительно устанавливаем в 0
// Запрос с LIMIT 0 отрабатывает моментально
if ($aCriteria['options']['calc_total'] != static::CRITERIA_CALC_TOTAL_ONLY) {
$sSqlLimit = 'LIMIT 0';
}
}
}
// Необходимость JOIN'ов
$aBlogTypeFields = array('allow_add', 'min_rate_add', 'allow_list', 'min_rate_list', 'acl_read', 'min_rate_read', 'acl_write', 'min_rate_write', 'acl_comment', 'min_rate_comment', 'index_ignore', 'membership');
if ($aFilter && array_intersect(array_keys($aFilter), $aBlogTypeFields)) {
$bBlogTypeJoin = true;
} else {
$bBlogTypeJoin = false;
}
$aBlogUserFields = array('user_role');
if ($aFilter && array_intersect(array_keys($aFilter), $aBlogUserFields)) {
$bBlogUserJoin = true;
} else {
$bBlogUserJoin = false;
}
$sql = "\n SELECT b.blog_id\n FROM ?_blog AS b\n { INNER JOIN ?_blog_type AS bt ON bt.type_code=b.blog_type AND 1=?d }\n { INNER JOIN ?_blog_user AS bu ON bu.blog_id=b.blog_id AND 1=?d }\n WHERE\n 1 = 1\n { AND (b.blog_id = ?d) }\n { AND (b.blog_id IN (?a)) }\n { AND (b.blog_id NOT IN (?a)) }\n { AND (b.user_owner_id = ?d) }\n { AND (b.user_owner_id IN (?a)) }\n { AND (b.user_owner_id = ?d) }\n { AND (b.user_owner_id IN (?a)) }\n { AND (b.blog_type = ?) }\n { AND (b.blog_type IN (?a)) }\n { AND (b.blog_type != ?) }\n { AND (b.blog_type NOT IN (?a)) }\n { AND blog_url = ? }\n { AND blog_url IN(?a) }\n { AND blog_title = ? }\n { AND blog_title LIKE ? }\n { AND (bt.allow_add = ?d) }\n { AND (bt.min_rate_add >= ?d) }\n { AND (bt.allow_list = ?d) }\n { AND (bt.min_rate_list >= ?d) }\n { AND (bt.acl_read & ?d > 0) }\n { AND (bt.min_rate_read >= ?d) }\n { AND (bt.acl_write & ?d > 0) }\n { AND (bt.min_rate_write >= ?d) }\n { AND (bt.acl_comment & ?d > 0) }\n { AND (bt.min_rate_comment >= ?d) }\n { AND (bt.index_ignore = ?d) }\n { AND (bt.membership = ?d) }\n { AND (bu.user_role = ?d) }\n " . $sSqlOrder . ' ' . $sSqlLimit;
$aData = $this->oDb->selectCol($sql, $bBlogTypeJoin ? 1 : DBSIMPLE_SKIP, $bBlogUserJoin ? 1 : DBSIMPLE_SKIP, isset($aFilter['blog_id']) && !is_array($aFilter['blog_id']) ? $aFilter['blog_id'] : DBSIMPLE_SKIP, isset($aFilter['blog_id']) && is_array($aFilter['blog_id']) ? $aFilter['blog_id'] : DBSIMPLE_SKIP, isset($aFilter['not_blog_id']) ? $aFilter['not_blog_id'] : DBSIMPLE_SKIP, isset($aFilter['user_id']) && !is_array($aFilter['user_id']) ? $aFilter['user_id'] : DBSIMPLE_SKIP, isset($aFilter['user_id']) && is_array($aFilter['user_id']) ? $aFilter['user_id'] : DBSIMPLE_SKIP, isset($aFilter['user_owner_id']) && !is_array($aFilter['user_owner_id']) ? $aFilter['user_owner_id'] : DBSIMPLE_SKIP, isset($aFilter['user_owner_id']) && is_array($aFilter['user_owner_id']) ? $aFilter['user_owner_id'] : DBSIMPLE_SKIP, isset($aFilter['blog_type']) && !is_array($aFilter['blog_type']) ? $aFilter['blog_type'] : DBSIMPLE_SKIP, isset($aFilter['blog_type']) && is_array($aFilter['blog_type']) ? $aFilter['blog_type'] : DBSIMPLE_SKIP, isset($aFilter['not_blog_type']) && !is_array($aFilter['not_blog_type']) ? $aFilter['not_blog_type'] : DBSIMPLE_SKIP, isset($aFilter['not_blog_type']) && is_array($aFilter['not_blog_type']) ? $aFilter['not_blog_type'] : DBSIMPLE_SKIP, isset($aFilter['blog_url']) && !is_array($aFilter['blog_url']) ? $aFilter['blog_url'] : DBSIMPLE_SKIP, isset($aFilter['blog_url']) && is_array($aFilter['blog_url']) ? $aFilter['blog_url'] : DBSIMPLE_SKIP, isset($aFilter['blog_title']) ? $aFilter['blog_title'] : DBSIMPLE_SKIP, isset($aFilter['blog_title_like']) ? $aFilter['blog_title_like'] : DBSIMPLE_SKIP, isset($aFilter['allow_add']) ? $aFilter['allow_add'] ? 1 : 0 : DBSIMPLE_SKIP, isset($aFilter['min_rate_add']) ? $aFilter['min_rate_add'] : DBSIMPLE_SKIP, isset($aFilter['allow_list']) ? $aFilter['allow_list'] ? 1 : 0 : DBSIMPLE_SKIP, isset($aFilter['min_rate_list']) ? $aFilter['min_rate_list'] : DBSIMPLE_SKIP, isset($aFilter['acl_read']) ? $aFilter['acl_read'] : DBSIMPLE_SKIP, isset($aFilter['min_rate_read']) ? $aFilter['min_rate_read'] : DBSIMPLE_SKIP, isset($aFilter['acl_write']) ? $aFilter['acl_write'] : DBSIMPLE_SKIP, isset($aFilter['min_rate_write']) ? $aFilter['min_rate_write'] : DBSIMPLE_SKIP, isset($aFilter['acl_comment']) ? $aFilter['acl_comment'] : DBSIMPLE_SKIP, isset($aFilter['min_rate_comment']) ? $aFilter['min_rate_comment'] : DBSIMPLE_SKIP, isset($aFilter['index_ignore']) ? $aFilter['index_ignore'] ? 1 : 0 : DBSIMPLE_SKIP, isset($aFilter['membership']) ? $aFilter['membership'] ? 1 : 0 : DBSIMPLE_SKIP, isset($aFilter['user_role']) ? $aFilter['user_role'] : DBSIMPLE_SKIP);
$aResult = array('data' => $aData ? $aData : array(), 'total' => -1);
if ($nCalcTotal) {
if ($nOffset == 0 && $nLimit > 0 && sizeof($aResult['data']) < $nLimit) {
$aResult['total'] = sizeof($aResult['data']);
} else {
$sLastQuery = trim(E::ModuleDatabase()->GetLastQuery());
$n = strpos($sLastQuery, ' LIMIT ');
if ($n) {
$sql = str_replace('SELECT b.blog_id', 'SELECT COUNT(*) AS cnt', substr($sLastQuery, 0, $n));
$aData = $this->oDb->select($sql);
if ($aData) {
$aResult['total'] = $aData[0]['cnt'];
}
}
}
}
return $aResult;
}