コード例 #1
0
ファイル: user.php プロジェクト: Archerol/booking
function User_isExistsLogin($login)
{
    $q = "SELECT COUNT(*) FROM Users WHERE login = ?s";
    $result = Database_query(User_db(), $q, $login);
    if (Database_selectCell($result) > 0) {
        return true;
    } else {
        return false;
    }
}
コード例 #2
0
ファイル: orders.php プロジェクト: Archerol/booking
/**
 * This method get OrderList, which may be of two types:
 * free orders or orders history of current user
 *
 * @param string('created'|'done') $status  Status of required orders
 *
 * @param int $offset  Range offset
 *
 * @param int $limit   Count of orders for current selection
 *
 * @param int &$count  Full count of selection for paging
 *
 * @return array       Orders selection
 */
function Orders_getOrderList($status, $offset, $limit, &$count = NULL)
{
    if (!in_array($status, Orders_getOrderStatuses())) {
        return getError('wrong_order_status');
    }
    // set where condition:
    // free orders or orders history
    if ($status == 'created') {
        $where = "WHERE status = 'created'";
        $joinColumn = 'customer_id';
        $memcache = true;
    } else {
        // check user auth
        if (empty(User_currentUser())) {
            return getError('order_history_need_auth');
        }
        // get users types
        if (User_currentUser()['type'] == 'customer') {
            $currentUserCol = 'customer_id';
            $joinColumn = 'performer_id';
        } else {
            $currentUserCol = 'performer_id';
            $joinColumn = 'customer_id';
        }
        $where = " WHERE status = 'done' AND {$currentUserCol} = " . intval(User_currentUser()['id']);
        $memcache = false;
    }
    // get full count of list
    if (!($memcache && Orders_mc() && ($count = MCache_get(Orders_mc(), 'Orders_count')))) {
        $q = "SELECT COUNT(*) as count\n\t\t\t\t\tFROM Orders \n\t\t\t\t\t{$where}";
        $result = Database_query(Orders_db(), $q, $status);
        $count = Database_selectCell($result);
        if ($memcache) {
            MCache_set(Orders_mc(), 'Orders_count', $count);
        }
    }
    // get current range
    if ($memcache && Orders_mc()) {
        $orderList = MCache_get(Orders_mc(), 'Orders_list');
    }
    if (empty($orderList) || $offset + $limit > sizeof($orderList)) {
        $q = "SELECT Orders.id, title, description, price, customer_id, performer_id\n\t\t\t\t\tFROM Orders\n\t\t\t\t\tINNER JOIN \n\t\t\t\t\t(\n\t\t\t\t\t\tSELECT id \n\t\t\t\t\t\tFROM Orders \n\t\t\t\t\t\t{$where}\n\t\t\t\t\t\tORDER BY id DESC\n\t\t\t\t\t\tLIMIT ?i, ?i\n\t\t\t\t\t) as ids\n\t\t\t\t\tON Orders.id = ids.id\n\t\t\t\t\tORDER BY id DESC";
        $result = Database_query(Orders_db(), $q, $offset, $limit);
        $orders = Database_select($result);
        $orderList = Orders_joinOrderList($orders, $joinColumn);
        if ($memcache && $offset == 0) {
            MCache_set(Orders_mc(), 'Orders_list', $orderList, 10);
        }
    }
    return $orderList;
}