protected static function generateWhereList($controller, $prefix = false) { if (!($session_search = self::getSearchSession($controller))) { return false; } $prefix = $prefix ? $prefix . '.' : ''; $first = true; foreach ($session_search as $key => $val) { $val = ClassTools::pSQL($val); if ($first) { $first = false; $search = "{$prefix}`{$key}` LIKE '%{$val}%'"; } else { $search .= " AND {$prefix}`{$key}` LIKE '%{$val}%'"; } } return $search; }
public static function sqlGetCountItems($controller_search = '', array $custom_where = array()) { global $DB; $table_name = (static::$use_prefix ? static::$prefix : '') . static::$definition['table']; $where = ''; if (static::$has_deleted_column) { $where = " WHERE `deleted` = '0'"; } if (static::$is_search && $controller_search != '' && ($where_search = self::generateWhereList($controller_search))) { if ($where == '') { $where = "WHERE "; } else { $where .= " AND "; } $where .= $where_search; } if (count($custom_where) > 0) { if ($where == '') { $where = "WHERE "; } else { $where .= " AND "; } $first = true; foreach ($custom_where as $key => $value) { if ($first) { $first = false; $where .= "`{$key}` = '" . ClassTools::pSQL($value) . "'"; } else { $where .= " AND `{$key}` = '" . ClassTools::pSQL($value) . "'"; } } } $zapytanie = "SELECT COUNT(*) as count_items\n FROM `{$table_name}`\n {$where}\n ;"; $sql = $DB->pdo_fetch($zapytanie, true); if (($sql === false || !is_array($sql)) && (static::$is_search && $controller_search != '' && isset($_SESSION['search'][$controller_search]))) { if (static::$is_search && isset($_SESSION['search'][$controller_search])) { $_SESSION['search'][$controller_search] = array(); } } if (!$sql || !is_array($sql) || count($sql) < 1) { return false; } return $sql['count_items']; }
protected function sqlGetWhenPasswordSendByPasswordKey($password_key) { global $DB; $zapytanie = "SELECT `id_user_new_password`, `date_send`, `id_user`\n FROM `sew_user_new_password`\n WHERE `password_key` = '" . ClassTools::pSQL($password_key) . "'\n AND `generated` = '0'\n ;"; $sql = $DB->pdo_fetch($zapytanie); if (!$sql || !is_array($sql) || count($sql) < 1) { return false; } return $sql; }