本文整理汇总了PHP中db_sort函数的典型用法代码示例。如果您正苦于以下问题:PHP db_sort函数的具体用法?PHP db_sort怎么用?PHP db_sort使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了db_sort函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fn_get_banners
function fn_get_banners($params = array(), $lang_code = CART_LANGUAGE)
{
$default_params = array('items_per_page' => 0);
$params = array_merge($default_params, $params);
$sortings = array('position' => '?:banners.position', 'timestamp' => '?:banners.timestamp', 'name' => '?:banner_descriptions.banner');
$condition = $limit = '';
if (!empty($params['limit'])) {
$limit = db_quote(' LIMIT 0, ?i', $params['limit']);
}
$sorting = db_sort($params, $sortings, 'name', 'asc');
$condition = AREA == 'A' ? '' : " AND ?:banners.status = 'A' ";
$condition .= fn_get_localizations_condition('?:banners.localization');
$condition .= AREA == 'A' ? '' : " AND (?:banners.type != 'G' OR ?:banner_images.banner_image_id IS NOT NULL) ";
if (!empty($params['item_ids'])) {
$condition .= db_quote(' AND ?:banners.banner_id IN (?n)', explode(',', $params['item_ids']));
}
if (!empty($params['period']) && $params['period'] != 'A') {
list($params['time_from'], $params['time_to']) = fn_create_periods($params);
$condition .= db_quote(" AND (?:banners.timestamp >= ?i AND ?:banners.timestamp <= ?i)", $params['time_from'], $params['time_to']);
}
fn_set_hook('get_banners', $params, $condition, $sorting, $limit, $lang_code);
$fields = array('?:banners.banner_id', '?:banners.type', '?:banners.target', '?:banners.status', '?:banners.position', '?:banner_descriptions.banner', '?:banner_descriptions.description', '?:banner_descriptions.url', '?:banner_images.banner_image_id');
if (fn_allowed_for('ULTIMATE')) {
$fields[] = '?:banners.company_id';
}
$banners = db_get_array("SELECT ?p FROM ?:banners " . "LEFT JOIN ?:banner_descriptions ON ?:banner_descriptions.banner_id = ?:banners.banner_id AND ?:banner_descriptions.lang_code = ?s" . "LEFT JOIN ?:banner_images ON ?:banner_images.banner_id = ?:banners.banner_id AND ?:banner_images.lang_code = ?s" . "WHERE 1 ?p ?p ?p", implode(", ", $fields), $lang_code, $lang_code, $condition, $sorting, $limit);
foreach ($banners as $k => $v) {
$banners[$k]['main_pair'] = fn_get_image_pairs($v['banner_image_id'], 'promo', 'M', true, false, $lang_code);
}
fn_set_hook('get_banners_post', $banners, $params);
return array($banners, $params);
}
示例2: fn_get_tags
function fn_get_tags($params = array(), $items_per_page = 0)
{
// Init filter
$params = LastView::instance()->update('tags', $params);
$default_params = array('page' => 1, 'items_per_page' => $items_per_page);
$params = array_merge($default_params, $params);
// Define sort fields
$sortings = array('tag' => '?:tags.tag', 'status' => '?:tags.status', 'popularity' => 'popularity', 'users' => 'users');
$conditions = fn_tags_build_conditions($params);
$sorting = db_sort($params, $sortings, 'tag', 'asc');
$limit = '';
if (!empty($params['limit'])) {
$limit = db_quote(' LIMIT 0, ?i', $params['limit']);
} elseif (!empty($params['items_per_page'])) {
$params['total_items'] = db_get_field("SELECT COUNT(DISTINCT(?:tags.tag_id)) FROM ?:tags LEFT JOIN ?:tag_links ON ?:tags.tag_id = ?:tag_links.tag_id WHERE 1 ?p", $conditions);
$limit = db_paginate($params['page'], $params['items_per_page'], $params['total_items']);
}
$tags = db_get_hash_array("SELECT ?:tags.tag_id, ?:tag_links.object_id, ?:tag_links.object_type, ?:tags.tag, ?:tags.status, COUNT(?:tag_links.tag_id) as popularity " . "FROM ?:tags LEFT JOIN ?:tag_links ON ?:tag_links.tag_id = ?:tags.tag_id WHERE 1 ?p GROUP BY ?:tags.tag_id {$sorting} {$limit}", 'tag_id', $conditions);
if (!empty($params['count_objects'])) {
$objs = db_get_array("SELECT tag_id, COUNT(DISTINCT(object_id)) as count, object_type " . "FROM ?:tag_links WHERE tag_id IN (?n) GROUP BY tag_id, object_type", array_keys($tags));
foreach ($objs as $v) {
$tags[$v['tag_id']]['objects_count'][$v['object_type']] = $v['count'];
}
}
// Generate popularity level
foreach ($tags as $k => $v) {
$level = ceil(log($v['popularity']));
$tags[$k]['level'] = $level > TAGS_MAX_LEVEL ? TAGS_MAX_LEVEL : $level;
}
if (!empty($params['sort_popular'])) {
$tags = fn_sort_array_by_key($tags, 'tag', SORT_ASC);
}
return array($tags, $params);
}
示例3: fn_get_promotions
/**
* Get promotions
*
* @param array $params array with search params
* @param int $items_per_page
* @param string $lang_code
* @return array list of promotions in first element, filtered parameters in second
*/
function fn_get_promotions($params, $items_per_page = 0, $lang_code = CART_LANGUAGE)
{
// Init filter
$params = LastView::instance()->update('promotions', $params);
// Set default values to input params
$default_params = array('page' => 1, 'items_per_page' => $items_per_page, 'get_hidden' => true);
$params = array_merge($default_params, $params);
// Define fields that should be retrieved
$fields = array("?:promotions.*", "?:promotion_descriptions.name", "?:promotion_descriptions.detailed_description", "?:promotion_descriptions.short_description");
// Define sort fields
$sortings = array('name' => "?:promotion_descriptions.name", 'priority' => "?:promotions.priority", 'zone' => "?:promotions.zone", 'status' => "?:promotions.status");
$condition = $join = $group = '';
$condition .= fn_get_company_condition('?:promotions.company_id');
$statuses = array('A');
if (!empty($params['get_hidden'])) {
$statuses[] = 'H';
}
if (!empty($params['promotion_id'])) {
$condition .= db_quote(' AND ?:promotions.promotion_id IN (?n)', $params['promotion_id']);
}
if (!empty($params['active'])) {
$condition .= db_quote(" AND IF(from_date, from_date <= ?i, 1) AND IF(to_date, to_date >= ?i, 1) AND status IN (?a)", TIME, TIME, $statuses);
}
if (fn_allowed_for('ULTIMATE:FREE')) {
$params['zone'] = 'catalog';
}
if (!empty($params['zone'])) {
$condition .= db_quote(" AND ?:promotions.zone = ?s", $params['zone']);
}
if (!empty($params['coupon_code'])) {
$condition .= db_quote(" AND (CONCAT(LOWER(?:promotions.conditions_hash), ';') LIKE ?l OR CONCAT(LOWER(?:promotions.conditions_hash), ';') LIKE ?l)", "%coupon_code={$params['coupon_code']};%", "%auto_coupons={$params['coupon_code']};%");
}
if (!empty($params['coupons'])) {
$condition .= db_quote(" AND ?:promotions.conditions_hash LIKE ?l", "%coupon_code=%");
}
if (!empty($params['auto_coupons'])) {
$condition .= db_quote(" AND ?:promotions.conditions_hash LIKE ?l", "%auto_coupons=%");
}
$join .= db_quote(" LEFT JOIN ?:promotion_descriptions ON ?:promotion_descriptions.promotion_id = ?:promotions.promotion_id AND ?:promotion_descriptions.lang_code = ?s", $lang_code);
fn_set_hook('get_promotions', $params, $fields, $sortings, $condition, $join);
$sorting = db_sort($params, $sortings, 'name', 'desc');
$limit = '';
if (!empty($params['items_per_page'])) {
$params['total_items'] = db_get_field("SELECT COUNT(*) FROM ?:promotions {$join} WHERE 1 {$condition} {$group}");
$limit = db_paginate($params['page'], $params['items_per_page'], $params['total_items']);
}
if (!empty($params['simple'])) {
return db_get_hash_single_array("SELECT ?:promotions.promotion_id, ?:promotion_descriptions.name FROM ?:promotions {$join} WHERE 1 {$condition} {$group} {$sorting} {$limit}", array('promotion_id', 'name'));
} else {
$promotions = db_get_hash_array('SELECT ' . implode(', ', $fields) . " FROM ?:promotions {$join} WHERE 1 {$condition} {$group} {$sorting} {$limit}", 'promotion_id');
}
if (!empty($params['expand'])) {
foreach ($promotions as $k => $v) {
$promotions[$k]['conditions'] = !empty($v['conditions']) ? unserialize($v['conditions']) : array();
$promotions[$k]['bonuses'] = !empty($v['bonuses']) ? unserialize($v['bonuses']) : array();
}
}
return array($promotions, $params);
}
示例4: fn_get_discussions
function fn_get_discussions($params, $items_per_page)
{
// Init filter
$params = LastView::instance()->update('discussion', $params);
// Set default values to input params
$default_params = array('page' => 1, 'items_per_page' => $items_per_page);
$params = array_merge($default_params, $params);
// Define fields that should be retrieved
$fields = array('?:discussion_posts.*', '?:discussion_messages.message', '?:discussion_rating.rating_value', '?:discussion.*');
// Define sort fields
$sortings = array('object' => "?:discussion.object_type", 'name' => "?:discussion_posts.name", 'ip_address' => "?:discussion_posts.ip_address", 'timestamp' => "?:discussion_posts.timestamp", 'status' => "?:discussion_posts.status", 'date' => "?:orders.timestamp", 'total' => "?:orders.total");
$sorting = db_sort($params, $sortings, 'timestamp', 'desc');
$condition = $join = '';
if (isset($params['name']) && fn_string_not_empty($params['name'])) {
$condition .= db_quote(" AND ?:discussion_posts.name LIKE ?l", "%" . trim($params['name']) . "%");
}
if (isset($params['message']) && fn_string_not_empty($params['message'])) {
$condition .= db_quote(" AND ?:discussion_messages.message LIKE ?l", "%" . trim($params['message']) . "%");
}
if (!empty($params['type'])) {
$condition .= db_quote(" AND ?:discussion.type = ?s", $params['type']);
}
if (!empty($params['status'])) {
$condition .= db_quote(" AND ?:discussion_posts.status = ?s", $params['status']);
}
if (!empty($params['post_id'])) {
$condition .= db_quote(" AND ?:discussion_posts.post_id = ?i", $params['post_id']);
}
if (isset($params['ip_address']) && fn_string_not_empty($params['ip_address'])) {
$condition .= db_quote(" AND ?:discussion_posts.ip_address = ?s", fn_ip_to_db(trim($params['ip_address'])));
}
if (!empty($params['rating_value'])) {
$condition .= db_quote(" AND ?:discussion_rating.rating_value = ?i", $params['rating_value']);
}
if (!empty($params['object_type'])) {
$condition .= db_quote(" AND ?:discussion.object_type = ?s", $params['object_type']);
}
$condition .= fn_get_discussion_company_condition('?:discussion.company_id');
if (!empty($params['period']) && $params['period'] != 'A') {
list($params['time_from'], $params['time_to']) = fn_create_periods($params);
$condition .= db_quote(" AND (?:discussion_posts.timestamp >= ?i AND ?:discussion_posts.timestamp <= ?i)", $params['time_from'], $params['time_to']);
}
$join .= " INNER JOIN ?:discussion ON ?:discussion.thread_id = ?:discussion_posts.thread_id";
$join .= " INNER JOIN ?:discussion_messages ON ?:discussion_messages.post_id = ?:discussion_posts.post_id";
$join .= " INNER JOIN ?:discussion_rating ON ?:discussion_rating.post_id = ?:discussion_posts.post_id";
$limit = '';
if (!empty($params['items_per_page'])) {
$params['total_items'] = db_get_field("SELECT COUNT(*) FROM ?:discussion_posts {$join} WHERE 1 {$condition}");
$limit = db_paginate($params['page'], $params['items_per_page'], $params['total_items']);
}
$posts = db_get_array("SELECT " . implode(',', $fields) . " FROM ?:discussion_posts {$join} WHERE 1 {$condition} {$sorting} {$limit}");
foreach ($posts as $k => $post) {
if (isset($post['ip_address'])) {
$posts[$k]['ip_address'] = fn_ip_from_db($post['ip_address']);
}
}
return array($posts, $params);
}
示例5: fn_gift_registry_get_userlog
function fn_gift_registry_get_userlog($params, $items_per_page = 0)
{
// Set default values to input params
$default_params = array('page' => 1, 'items_per_page' => $items_per_page);
$params = array_merge($default_params, $params);
$sortings = array('timestamp' => 'timestamp', 'amount' => 'amount');
$sorting = db_sort($params, $sortings, 'timestamp', 'desc');
$limit = '';
if (!empty($params['items_per_page'])) {
$params['total_items'] = db_get_field("SELECT COUNT(*) FROM ?:reward_point_changes WHERE user_id = ?i", $params['user_id']);
$limit = db_paginate($params['page'], $params['items_per_page'], $params['total_items']);
}
$userlog = db_get_array("SELECT change_id, action, timestamp, amount, reason FROM ?:reward_point_changes WHERE user_id = ?i {$sorting} {$limit}", $params['user_id']);
return array($userlog, $params);
}
示例6: getList
/**
* Gets list of locations
*
* @param array $params input params
* @param string $lang_code 2 letter language code
* @return array Array of locations data
*/
public function getList($params = array(), $lang_code = CART_LANGUAGE)
{
/**
* Prepares params for SQL query before getting locations
* @param array $params input params
* @param string $lang_code 2 letter language code
*/
fn_set_hook('get_locations_pre', $params, $lang_code);
$sortings = array('location_id' => 'l.location_id', 'dispatch' => 'l.dispatch', 'is_default' => 'l.is_default', 'layout_id' => 'l.layout_id', 'location' => array('l.is_default', 'd.name'), 'object_ids' => 'l.object_ids', 'position' => 'l.position');
$sorting = db_sort($params, $sortings, 'is_default', 'desc');
$join = $condition = '';
if (!empty($params['dispatch'])) {
$condition .= db_quote(" AND l.dispatch = ?s", $params['dispatch']);
}
if (!empty($params['location_id'])) {
$condition .= db_quote(" AND l.location_id = ?i", $params['location_id']);
}
if (!empty($params['is_default'])) {
$condition .= db_quote(" AND l.is_default = 1");
}
if (!empty($params['dynamic_object']) && !empty($params['dispatch'])) {
if (!empty($params['dynamic_object']['object_id'])) {
$dynamic_object_scheme = SchemesManager::getDynamicObject($params['dispatch'], 'C');
if (!empty($dynamic_object_scheme)) {
$condition .= db_quote(" AND (FIND_IN_SET(?i, l.object_ids) OR l.object_ids = '')", $params['dynamic_object']['object_id']);
}
}
}
$limit = '';
if (!empty($params['limit'])) {
$limit = db_quote(" LIMIT ?i", $params['limit']);
}
// Try to get location for this dispatch
$locations = db_get_hash_array("SELECT * FROM ?:bm_locations as l " . "LEFT JOIN ?:bm_locations_descriptions as d ON d.location_id = l.location_id AND d.lang_code = ?s ?p" . "WHERE l.layout_id = ?i ?p {$sorting} {$limit}", 'location_id', $lang_code, $join, $this->_layout_id, $condition);
/**
* Processes locations list after getting it
* @param array $locations Array of locations data
* @param string $lang_code 2 letter language code
*/
fn_set_hook('get_locations_post', $locations, $lang_code);
return $locations;
}
示例7: fn_get_feedbacks
function fn_get_feedbacks($params, $items_per_page, $lang_code = CART_LANGUAGE)
{
$params = LastView::instance()->update('feedbacks', $params);
$default_params = array('page' => 1, 'items_per_page' => $items_per_page);
$params = array_merge($default_params, $params);
$fields = array("?:orders_feedback.feedback_id", "?:orders_feedback.statuses", "?:orders_feedback.subject", "?:orders_feedback.remind_in", "?:orders_feedback.status", "?:orders_feedback.lang_code");
$sortings = array('feedback_id' => "?:orders_feedback.feedback_id", 'subject' => "?:orders_feedback.subject", 'statuses' => "?:orders_feedback.statuses", 'remind_in' => "?:orders_feedback.remind_in");
$condition = $_condition = $join = $group = '';
/*conditions*/
$condition .= db_quote(' AND lang_code = ?s', $lang_code);
/*conditions*/
$sorting = db_sort($params, $sortings, 'feedback_id', 'desc');
$limit = '';
if (!empty($params['items_per_page'])) {
$params['total_items'] = db_get_field("SELECT COUNT(?:orders_feedback.feedback_id) FROM ?:orders_feedback {$join} WHERE 1 {$condition}");
$limit = db_paginate($params['page'], $params['items_per_page']);
}
$feedbacks = db_get_array('SELECT ' . implode(', ', $fields) . " FROM ?:orders_feedback {$join} WHERE 1 {$condition} {$group} {$sorting} {$limit}");
LastView::instance()->processResults('feedbacks', $feedbacks, $params);
return array($feedbacks, $params);
}
示例8: fn_get_call_requests
function fn_get_call_requests($params = array(), $lang_code = CART_LANGUAGE)
{
// Init filter
$params = LastView::instance()->update('call_requests', $params);
$params = array_merge(array('items_per_page' => 0, 'page' => 1), $params);
$fields = array('r.*', 'o.status as order_status', 'd.product');
$joins = array(db_quote("LEFT JOIN ?:users u USING(user_id)"), db_quote("LEFT JOIN ?:orders o USING(order_id)"), db_quote("LEFT JOIN ?:product_descriptions d ON d.product_id = r.product_id AND d.lang_code = ?s", $lang_code));
$sortings = array('id' => 'r.request_id', 'date' => 'r.timestamp', 'status' => 'r.status', 'name' => 'r.name', 'phone' => 'r.phone', 'user_id' => 'r.user_id', 'user' => array('u.lastname', 'u.firstname'), 'order' => 'r.order_id', 'order_status' => 'o.status');
$condition = array();
if (isset($params['id']) && fn_string_not_empty($params['id'])) {
$params['id'] = trim($params['id']);
$condition[] = db_quote("r.request_id = ?i", $params['id']);
}
if (isset($params['name']) && fn_string_not_empty($params['name'])) {
$params['name'] = trim($params['name']);
$condition[] = db_quote("r.name LIKE ?l", '%' . $params['name'] . '%');
}
if (isset($params['phone']) && fn_string_not_empty($params['phone'])) {
$params['phone'] = trim($params['phone']);
$condition[] = db_quote("r.phone LIKE ?l", '%' . $params['phone'] . '%');
}
if (!empty($params['status'])) {
$condition[] = db_quote("r.status = ?s", $params['status']);
}
if (!empty($params['order_status'])) {
$condition[] = db_quote("o.status = ?s", $params['order_status']);
}
if (!empty($params['user_id'])) {
$condition[] = db_quote("r.user_id = ?s", $params['user_id']);
}
if (!empty($params['order_exists'])) {
$sign = $params['order_exists'] == 'Y' ? '<>' : '=';
$condition[] = db_quote("r.order_id ?p 0", $sign);
}
$fields_str = implode(', ', $fields);
$joins_str = ' ' . implode(' ', $joins);
$condition_str = $condition ? ' WHERE ' . implode(' AND ', $condition) : '';
$sorting_str = db_sort($params, $sortings, 'date', 'desc');
$limit = '';
if (!empty($params['items_per_page'])) {
$params['total_items'] = db_get_field("SELECT COUNT(r.request_id) FROM ?:call_requests r" . $joins_str . $condition_str);
$limit = db_paginate($params['page'], $params['items_per_page'], $params['total_items']);
}
$items = db_get_array("SELECT " . $fields_str . " FROM ?:call_requests r" . $joins_str . $condition_str . $sorting_str . $limit);
if (!empty($items)) {
$cart_product_ids = array();
foreach ($items as &$item) {
if (!empty($item['cart_products'])) {
$item['cart_products'] = unserialize($item['cart_products']);
foreach ($item['cart_products'] as $cart_product) {
$cart_product_ids[] = $cart_product['product_id'];
}
}
}
$cart_product_names = db_get_hash_single_array("SELECT product_id, product FROM ?:product_descriptions WHERE product_id IN(?n) AND lang_code = ?s", array('product_id', 'product'), array_unique($cart_product_ids), $lang_code);
foreach ($items as &$item) {
if (!empty($item['cart_products'])) {
foreach ($item['cart_products'] as &$cart_product) {
if (!empty($cart_product_names[$cart_product['product_id']])) {
$cart_product['product'] = $cart_product_names[$cart_product['product_id']];
}
}
}
}
}
return array($items, $params);
}
示例9: fn_get_subscribers
function fn_get_subscribers($params, $items_per_page = 0, $lang_code = CART_LANGUAGE)
{
// Init filter
$params = LastView::instance()->update('subscribers', $params);
// Set default values to input params
$default_params = array('page' => 1, 'items_per_page' => $items_per_page);
$params = array_merge($default_params, $params);
// Define fields that should be retrieved
$fields = array('?:subscribers.subscriber_id', '?:subscribers.email', '?:subscribers.timestamp', '?:subscribers.subscriber_id', "GROUP_CONCAT(?:user_mailing_lists.list_id) as list_ids");
// Define sort fields
$sortings = array('email' => '?:subscribers.email', 'timestamp' => '?:subscribers.timestamp');
$condition = '';
$group_by = "?:subscribers.subscriber_id";
$join = db_quote(" LEFT JOIN ?:user_mailing_lists ON ?:user_mailing_lists.subscriber_id = ?:subscribers.subscriber_id");
if (isset($params['email']) && fn_string_not_empty($params['email'])) {
$condition .= db_quote(" AND ?:subscribers.email LIKE ?l", "%" . trim($params['email']) . "%");
}
if (!empty($params['list_id'])) {
$condition .= db_quote(" AND ?:user_mailing_lists.list_id = ?i", $params['list_id']);
}
if (!empty($params['confirmed'])) {
$condition .= db_quote(" AND ?:user_mailing_lists.confirmed = ?i", $params['confirmed'] == 'Y');
}
if (!empty($params['language'])) {
$condition .= db_quote(" AND ?:user_mailing_lists.lang_code = ?s", $params['language']);
}
if (!empty($params['period']) && $params['period'] != 'A') {
list($params['time_from'], $params['time_to']) = fn_create_periods($params);
$condition .= db_quote(" AND (?:subscribers.timestamp >= ?i AND ?:subscribers.timestamp <= ?i)", $params['time_from'], $params['time_to']);
}
$sorting = db_sort($params, $sortings, 'timestamp', 'desc');
$limit = '';
if (!empty($params['items_per_page'])) {
$params['total_items'] = db_get_field("SELECT COUNT(DISTINCT(?:subscribers.subscriber_id)) FROM ?:subscribers {$join} WHERE 1 {$condition}");
$limit = db_paginate($params['page'], $params['items_per_page'], $params['total_items']);
}
$subscribers = db_get_array('SELECT ' . implode(', ', $fields) . " FROM ?:subscribers {$join} WHERE 1 {$condition} GROUP BY {$group_by} {$sorting} {$limit}");
return array($subscribers, $params);
}
示例10: fn_get_logs
/**
* Returns store logs
*
* @param array $params Search parameters
* @param int $items_per_page Logs limit
* @return array Logs with search parameters
*/
function fn_get_logs($params, $items_per_page = 0)
{
// Init filter
$params = LastView::instance()->update('logs', $params);
$default_params = array('page' => 1, 'items_per_page' => $items_per_page);
$params = array_merge($default_params, $params);
$sortings = array('timestamp' => array('?:logs.timestamp', '?:logs.log_id'), 'user' => array('?:users.lastname', '?:users.firstname'));
$fields = array('?:logs.*', '?:users.firstname', '?:users.lastname');
$sorting = db_sort($params, $sortings, 'timestamp', 'desc');
$join = "LEFT JOIN ?:users USING(user_id)";
$condition = '';
if (!empty($params['period']) && $params['period'] != 'A') {
list($time_from, $time_to) = fn_create_periods($params);
$condition .= db_quote(" AND (?:logs.timestamp >= ?i AND ?:logs.timestamp <= ?i)", $time_from, $time_to);
}
if (isset($params['q_user']) && fn_string_not_empty($params['q_user'])) {
$condition .= db_quote(" AND (?:users.lastname LIKE ?l OR ?:users.firstname LIKE ?l)", "%" . trim($params['q_user']) . "%", "%" . trim($params['q_user']) . "%");
}
if (!empty($params['q_type'])) {
$condition .= db_quote(" AND ?:logs.type = ?s", $params['q_type']);
}
if (!empty($params['q_action'])) {
$condition .= db_quote(" AND ?:logs.action = ?s", $params['q_action']);
}
if (Registry::get('runtime.company_id')) {
$condition .= db_quote(" AND ?:logs.company_id = ?i", Registry::get('runtime.company_id'));
}
fn_set_hook('admin_get_logs', $params, $condition, $join, $sorting);
$limit = '';
if (!empty($params['items_per_page'])) {
$params['total_items'] = db_get_field("SELECT COUNT(DISTINCT(?:logs.log_id)) FROM ?:logs ?p WHERE 1 ?p", $join, $condition);
$limit = db_paginate($params['page'], $params['items_per_page']);
}
$data = db_get_array("SELECT " . join(', ', $fields) . " FROM ?:logs ?p WHERE 1 ?p {$sorting} {$limit}", $join, $condition);
foreach ($data as $k => $v) {
$data[$k]['backtrace'] = !empty($v['backtrace']) ? unserialize($v['backtrace']) : array();
$data[$k]['content'] = !empty($v['content']) ? unserialize($v['content']) : array();
}
return array($data, $params);
}
示例11: getList
/**
* Return list log items by filter
*
* @param array $params
* @param int $items_per_page
* @return array
*/
public static function getList($params, $items_per_page = 0)
{
// Set default values to input params
$default_params = array('page' => 1, 'items_per_page' => $items_per_page);
$types = static::getTypes();
$actions = static::getActions();
$params = array_merge($default_params, $params);
$condition = '';
$limit = '';
$sortings = array('id' => 'id', 'datetime' => 'datetime');
if (isset($params['template_id']) && fn_is_not_empty($params['template_id'])) {
$condition .= db_quote(' AND template_id = ?i', $params['template_id']);
}
if (isset($params['product_id']) && fn_is_not_empty($params['product_id'])) {
$condition .= db_quote(' AND product_id = ?i', $params['product_id']);
}
if (isset($params['product_ids']) && fn_is_not_empty($params['product_ids'])) {
$condition .= db_quote(' AND product_id IN (?n)', $params['product_ids']);
}
if (isset($params['code']) && fn_is_not_empty($params['code'])) {
$condition .= db_quote(' AND product_id = ?s', $params['code']);
}
if (isset($params['type']) && fn_is_not_empty($params['type'])) {
$condition .= db_quote(' AND type = ?i', $params['type']);
}
if (isset($params['action']) && fn_is_not_empty($params['action'])) {
$condition .= db_quote(' AND action = ?i', $params['action']);
}
if (!empty($params['period']) && $params['period'] != 'A') {
list($time_from, $time_to) = fn_create_periods($params);
$condition .= db_quote(' AND (datetime >= ?i AND datetime <= ?i)', $time_from, $time_to);
}
$sorting = db_sort($params, $sortings, 'id', 'desc');
if (!empty($params['items_per_page'])) {
$params['total_items'] = db_get_field("SELECT COUNT(*) FROM ?:ebay_product_log WHERE 1 {$condition}");
$limit = db_paginate($params['page'], $params['items_per_page'], $params['total_items']);
}
$result = db_get_array("SELECT * FROM ?:ebay_product_log WHERE 1 {$condition} {$sorting} {$limit}");
foreach ($result as &$item) {
switch ($item['type']) {
case static::TYPE_ERROR:
$item['type_code'] = 'error';
break;
case static::TYPE_INFO:
$item['type_code'] = 'info';
break;
case static::TYPE_WARNING:
$item['type_code'] = 'warning';
break;
default:
$item['type_code'] = 'undefined';
break;
}
$item['type_name'] = isset($types[$item['type']]) ? $types[$item['type']] : 'undefined';
$item['action_name'] = isset($actions[$item['action']]) ? $actions[$item['action']] : 'undefined';
}
unset($item);
return array($result, $params);
}
示例12: fn_get_tags
function fn_get_tags($params = array(), $items_per_page = 0)
{
// Init filter
$params = LastView::instance()->update('tags', $params);
$default_params = array('page' => 1, 'items_per_page' => $items_per_page);
/**
* Change parameters for getting tags
*
* @param array $params Params list
* @param int $items_per_page Tags per page
* @param array $default_params Default params
*/
fn_set_hook('get_tags_pre', $params, $items_per_page, $default_params);
$params = array_merge($default_params, $params);
$fields = array('?:tags.tag_id', '?:tag_links.object_id', '?:tag_links.object_type', '?:tags.tag', '?:tags.status', 'COUNT(?:tag_links.tag_id) as popularity');
$joins = array('LEFT JOIN ?:tag_links ON ?:tag_links.tag_id = ?:tags.tag_id');
$conditions = fn_tags_build_conditions($params);
// Define sort fields
$sortings = array('tag' => '?:tags.tag', 'status' => '?:tags.status', 'popularity' => 'popularity', 'users' => 'users');
$sorting = db_sort($params, $sortings, 'tag', 'asc');
$group = 'GROUP BY ?:tags.tag_id';
/**
* Gets tags
*
* @param array $params Params list
* @param int $items_per_page Tags per page
* @param array $fields List of SQL fields to be selected in an SQL-query
* @param array $joins List of strings with the complete JOIN information (JOIN type, tables and fields) for an SQL-query
* @param string $conditions String containing the SQL-query conditions prepended with a logical operator (AND or OR)
* @param string $group String containing the SQL-query GROUP BY field
* @param string $sorting String containing the SQL-query ORDER BY field
*/
fn_set_hook('get_tags', $params, $items_per_page, $fields, $joins, $conditions, $group, $sorting);
$limit = '';
if (!empty($params['limit'])) {
$limit = db_quote(' LIMIT 0, ?i', $params['limit']);
} elseif (!empty($params['items_per_page'])) {
$params['total_items'] = db_get_field("SELECT COUNT(DISTINCT(?:tags.tag_id)) FROM ?:tags LEFT JOIN ?:tag_links ON ?:tags.tag_id = ?:tag_links.tag_id WHERE 1 ?p", $conditions);
$limit = db_paginate($params['page'], $params['items_per_page'], $params['total_items']);
}
$tags = db_get_hash_array("SELECT " . implode(', ', $fields) . " " . "FROM ?:tags " . implode(' ', $joins) . " WHERE 1 ?p {$group} {$sorting} {$limit}", 'tag_id', $conditions);
if (!empty($params['count_objects'])) {
$objs = db_get_array("SELECT tag_id, COUNT(DISTINCT(object_id)) as count, object_type " . "FROM ?:tag_links WHERE tag_id IN (?n) GROUP BY tag_id, object_type", array_keys($tags));
foreach ($objs as $v) {
$tags[$v['tag_id']]['objects_count'][$v['object_type']] = $v['count'];
}
}
// Generate popularity level
foreach ($tags as $k => $v) {
$level = ceil(log($v['popularity']));
$tags[$k]['level'] = $level > TAGS_MAX_LEVEL ? TAGS_MAX_LEVEL : $level;
}
if (!empty($params['sort_popular'])) {
$tags = fn_sort_array_by_key($tags, 'tag', SORT_ASC);
}
/**
* Change tags
*
* @param array $params Params list
* @param int $items_per_page Tags per page
* @param array $tags Tags
*/
fn_set_hook('get_tags_post', $params, $items_per_page, $tags);
return array($tags, $params);
}
示例13: fn_em_get_subscribers
function fn_em_get_subscribers($params, $items_per_page = 0, $lang_code = CART_LANGUAGE)
{
// Init filter
$params = LastView::instance()->update('em_subscribers', $params);
// Set default values to input params
$default_params = array('page' => 1, 'items_per_page' => $items_per_page);
$params = array_merge($default_params, $params);
// Define fields that should be retrieved
$fields = array('?:em_subscribers.subscriber_id', '?:em_subscribers.email', '?:em_subscribers.timestamp', '?:em_subscribers.name', '?:em_subscribers.unsubscribe_key', '?:em_subscribers.status');
// Define sort fields
$sortings = array('email' => '?:em_subscribers.email', 'name' => '?:em_subscribers.name', 'status' => '?:em_subscribers.status', 'timestamp' => '?:em_subscribers.timestamp');
$condition = '';
$group_by = '';
$join = '';
if (!empty($params['subscriber_id'])) {
$condition .= db_quote(" AND ?:em_subscribers.subscriber_id = ?i", $params['subscriber_id']);
}
if (isset($params['email']) && fn_string_not_empty($params['email'])) {
$condition .= db_quote(" AND ?:em_subscribers.email LIKE ?l", "%" . trim($params['email']) . "%");
}
if (!empty($params['status'])) {
$condition .= db_quote(" AND ?:em_subscribers.status = ?s", $params['status']);
}
if (!empty($params['name'])) {
$condition .= db_quote(" AND ?:em_subscribers.name LIKE ?l", "%" . $params['name'] . "%");
}
if (!empty($params['lang_code'])) {
$condition .= db_quote(" AND ?:em_subscribers.lang_code = ?s", $params['lang_code']);
}
if (!empty($params['period']) && $params['period'] != 'A') {
list($params['time_from'], $params['time_to']) = fn_create_periods($params);
$condition .= db_quote(" AND (?:em_subscribers.timestamp >= ?i AND ?:em_subscribers.timestamp <= ?i)", $params['time_from'], $params['time_to']);
}
$condition .= fn_em_get_company_condition();
$sorting = db_sort($params, $sortings, 'timestamp', 'desc');
$limit = '';
if (!empty($params['items_per_page'])) {
$params['total_items'] = db_get_field("SELECT COUNT(?:em_subscribers.subscriber_id) FROM ?:em_subscribers {$join} WHERE 1 {$condition}");
$limit = db_paginate($params['page'], $params['items_per_page'], $params['total_items']);
}
$subscribers = db_get_array('SELECT ' . implode(', ', $fields) . " FROM ?:em_subscribers {$join} WHERE 1 {$condition} {$group_by} {$sorting} {$limit}");
return array($subscribers, $params);
}
示例14: fn_get_companies
/**
* Gets company data array
*
* @param array $params Array of search params:
* <ul>
* <li>string company - Name of company</li>
* <li>string status - Status of company</li>
* <li>string email - Email of company</li>
* <li>string address - Address of company</li>
* <li>string zipcode - Zipcode of company</li>
* <li>string country - 2-letters country code of company country</li>
* <li>string state - State code of company</li>
* <li>string city - City of company</li>
* <li>string phone - Phone of company</li>
* <li>string url - URL address of company</li>
* <li>string fax - Fax number of company</li>
* <li>mixed company_id - Company ID, array with company IDs or comma-separated list of company IDs.
* If defined, data will be returned only for companies with such company IDs.</li>
* <li>int exclude_company_id - Company ID, if defined,
* result array will not include the data for company with such company ID.</li>
* <li>int page - First page to displaying list of companies (if <i>$items_per_page</i> it not empty.</li>
* <li>string sort_order - <i>ASC</i> or <i>DESC</i>: database query sorting order</li>
* <li>string sort_by - One or list of database fields for sorting.</li>
* </ul>
* @param array $auth Array of user authentication data (e.g. uid, usergroup_ids, etc.)
* @param int $items_per_page
* @param string $lang_code 2-letter language code (e.g. 'en', 'ru', etc.)
* @return array Array:
* <ul>
* <li>0 - First element is array with companies data.</li>
* <li>1 - is possibly modified array with searh params (<i>$params</i>).</li>
* </ul>
*/
function fn_get_companies($params, &$auth, $items_per_page = 0, $lang_code = CART_LANGUAGE)
{
// Init filter
$_view = 'companies';
$params = LastView::instance()->update($_view, $params);
// Set default values to input params
$default_params = array('page' => 1, 'items_per_page' => $items_per_page);
$params = array_merge($default_params, $params);
// Define fields that should be retrieved
$fields = array('?:companies.company_id', '?:companies.lang_code', '?:companies.email', '?:companies.company', '?:companies.timestamp', '?:companies.status');
if (fn_allowed_for('ULTIMATE')) {
$fields[] = '?:companies.storefront';
$fields[] = '?:companies.secure_storefront';
}
// Define sort fields
$sortings = array('id' => '?:companies.company_id', 'company' => '?:companies.company', 'email' => '?:companies.email', 'date' => '?:companies.timestamp', 'status' => '?:companies.status');
if (fn_allowed_for('ULTIMATE')) {
$sortings['storefront'] = '?:companies.storefront';
}
$condition = $join = $group = '';
$condition .= fn_get_company_condition('?:companies.company_id');
$group .= " GROUP BY ?:companies.company_id";
if (isset($params['company']) && fn_string_not_empty($params['company'])) {
$condition .= db_quote(" AND ?:companies.company LIKE ?l", "%" . trim($params['company']) . "%");
}
if (!empty($params['status'])) {
if (is_array($params['status'])) {
$condition .= db_quote(" AND ?:companies.status IN (?a)", $params['status']);
} else {
$condition .= db_quote(" AND ?:companies.status = ?s", $params['status']);
}
}
if (isset($params['email']) && fn_string_not_empty($params['email'])) {
$condition .= db_quote(" AND ?:companies.email LIKE ?l", "%" . trim($params['email']) . "%");
}
if (isset($params['address']) && fn_string_not_empty($params['address'])) {
$condition .= db_quote(" AND ?:companies.address LIKE ?l", "%" . trim($params['address']) . "%");
}
if (isset($params['zipcode']) && fn_string_not_empty($params['zipcode'])) {
$condition .= db_quote(" AND ?:companies.zipcode LIKE ?l", "%" . trim($params['zipcode']) . "%");
}
if (!empty($params['country'])) {
$condition .= db_quote(" AND ?:companies.country = ?s", $params['country']);
}
if (isset($params['state']) && fn_string_not_empty($params['state'])) {
$condition .= db_quote(" AND ?:companies.state LIKE ?l", "%" . trim($params['state']) . "%");
}
if (isset($params['city']) && fn_string_not_empty($params['city'])) {
$condition .= db_quote(" AND ?:companies.city LIKE ?l", "%" . trim($params['city']) . "%");
}
if (isset($params['phone']) && fn_string_not_empty($params['phone'])) {
$condition .= db_quote(" AND ?:companies.phone LIKE ?l", "%" . trim($params['phone']) . "%");
}
if (isset($params['url']) && fn_string_not_empty($params['url'])) {
$condition .= db_quote(" AND ?:companies.url LIKE ?l", "%" . trim($params['url']) . "%");
}
if (isset($params['fax']) && fn_string_not_empty($params['fax'])) {
$condition .= db_quote(" AND ?:companies.fax LIKE ?l", "%" . trim($params['fax']) . "%");
}
if (!empty($params['company_id'])) {
$condition .= db_quote(' AND ?:companies.company_id IN (?n)', $params['company_id']);
}
if (!empty($params['exclude_company_id'])) {
$condition .= db_quote(' AND ?:companies.company_id != ?i', $params['exclude_company_id']);
}
fn_set_hook('get_companies', $params, $fields, $sortings, $condition, $join, $auth, $lang_code, $group);
$sorting = db_sort($params, $sortings, 'company', 'asc');
//.........这里部分代码省略.........
示例15: array
$sortings = array('id' => '?:hw_404.id', 'url' => '?:hw_404.url', 'timestamp' => '?:hw_404.created', 'redirect' => '?:hw_404.redirect', 'hits' => '?:hw_404.hits', 'redirect_type' => '?:hw_404.redirect_type');
$auth =& $_SESSION['auth'];
$condition = '1';
$join = $limit = $group_by = '';
if (isset($params['q']) && fn_string_not_empty($params['q'])) {
$condition .= db_quote(' AND ( url LIKE ?l OR redirect LIKE ?l OR referer LIKE ?l)', '%' . $params['q'] . '%', '%' . $params['q'] . '%', '%' . $params['q'] . '%');
}
$company_id = Registry::get('runtime.company_id');
if ($company_id > 0) {
$condition .= db_quote(' AND company_id=?i', $company_id);
}
#NEW
if (!isset($_REQUEST['show']) || $_REQUEST['show'] != 'all') {
$condition .= db_quote(' AND ( redirect=?s OR redirect IS NULL) AND object_id=?i', '', 0);
}
$sorting = db_sort($params, $sortings, 'timestamp', 'desc');
if (!empty($group_by)) {
$group_by = ' GROUP BY ' . $group_by;
}
if (!empty($params['items_per_page'])) {
$params['total_items'] = db_get_field("SELECT COUNT(*) FROM ?:hw_404 ?p WHERE ?p ?p ?p", $join, $condition, $group_by, $sorting);
$limit = db_paginate($params['page'], $params['items_per_page']);
}
$errors = db_get_hash_array("SELECT " . implode(', ', $fields) . " FROM ?:hw_404 ?p WHERE ?p ?p ?p ?p", 'id', $join, $condition, $group_by, $sorting, $limit);
//generate urls
if (!empty($_REQUEST['show']) && $_REQUEST['show'] == 'all' && !empty($errors)) {
foreach ($errors as $key => $error) {
if ($error['object_id'] > 0) {
$errors[$key]['redirect'] = fn_hw_404_fixer_generate_url($error['type'], $error['object_id']);
}
}