mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 07:23:13 +00:00
search user on like %...%
This commit is contained in:
@@ -87,6 +87,7 @@ class Manage extends Helper
|
||||
$this->query_parms = [
|
||||
'inactives' => $this->request->get('inactives'),
|
||||
'like_field' => $this->request->get('like_field'),
|
||||
'like_type' => $this->request->get('like_type'),
|
||||
'like_value' => $this->request->get('like_value'),
|
||||
'sbas_id' => $this->request->get('sbas_id'),
|
||||
'base_id' => $this->request->get('base_id'),
|
||||
@@ -98,6 +99,7 @@ class Manage extends Helper
|
||||
'offset_start' => $offset_start,
|
||||
];
|
||||
|
||||
/** @var \User_Query $query */
|
||||
$query = $this->app['phraseanet.user-query'];
|
||||
|
||||
if (is_array($this->query_parms['base_id']))
|
||||
@@ -106,7 +108,7 @@ class Manage extends Helper
|
||||
$query->on_sbas_ids($this->query_parms['sbas_id']);
|
||||
|
||||
$results = $query->sort_by($this->query_parms["srt"], $this->query_parms["ord"])
|
||||
->like($this->query_parms['like_field'], $this->query_parms['like_value'])
|
||||
->like($this->query_parms['like_field'], $this->query_parms['like_value'], $this->query_parms['like_type'])
|
||||
->last_model_is($this->query_parms['last_model'])
|
||||
->get_inactives($this->query_parms['inactives'])
|
||||
->include_templates(true)
|
||||
|
@@ -36,11 +36,14 @@ class User_Query
|
||||
const LIKE_COUNTRY = 'country';
|
||||
const LIKE_MATCH_AND = 'AND';
|
||||
const LIKE_MATCH_OR = 'OR';
|
||||
const LIKE_TYPE_START = 'like_start';
|
||||
const LIKE_TYPE_CONTAINS = 'like_contains';
|
||||
|
||||
protected $app;
|
||||
protected $results = [];
|
||||
protected $sort = [];
|
||||
protected $like_field = [];
|
||||
protected $like_type = 'like_start';
|
||||
protected $have_rights = null;
|
||||
protected $have_not_rights = null;
|
||||
protected $like_match = 'OR';
|
||||
@@ -400,12 +403,14 @@ class User_Query
|
||||
*
|
||||
* @param $like_field
|
||||
* @param $like_value
|
||||
* @param $like_type
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function like($like_field, $like_value)
|
||||
public function like($like_field, $like_value, $like_type = self::LIKE_TYPE_START)
|
||||
{
|
||||
$this->like_field[trim($like_field)] = trim($like_value);
|
||||
$this->like_type = $like_type;
|
||||
$this->total = $this->page = $this->total_page = null;
|
||||
|
||||
return $this;
|
||||
@@ -994,6 +999,15 @@ class User_Query
|
||||
if (trim($like_val) === '')
|
||||
continue;
|
||||
|
||||
if ($this->like_type == self::LIKE_TYPE_CONTAINS) {
|
||||
$queries[] = sprintf(
|
||||
' (Users.`%s` LIKE "%%%s%%" COLLATE utf8_unicode_ci OR Users.`%s` LIKE "%%%s%%" COLLATE utf8_unicode_ci) '
|
||||
, self::LIKE_FIRSTNAME
|
||||
, str_replace(['"', '%'], ['\"', '\%'], $like_val)
|
||||
, self::LIKE_LASTNAME
|
||||
, str_replace(['"', '%'], ['\"', '\%'], $like_val)
|
||||
);
|
||||
} else {
|
||||
$queries[] = sprintf(
|
||||
' (Users.`%s` LIKE "%s%%" COLLATE utf8_unicode_ci OR Users.`%s` LIKE "%s%%" COLLATE utf8_unicode_ci) '
|
||||
, self::LIKE_FIRSTNAME
|
||||
@@ -1003,6 +1017,8 @@ class User_Query
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (count($queries) > 0) {
|
||||
$sql_like[] = ' (' . implode(' AND ', $queries) . ') ';
|
||||
}
|
||||
@@ -1013,11 +1029,20 @@ class User_Query
|
||||
case self::LIKE_EMAIL:
|
||||
case self::LIKE_LOGIN:
|
||||
case self::LIKE_COUNTRY:
|
||||
if ($this->like_type == self::LIKE_TYPE_CONTAINS) {
|
||||
$sql_like[] = sprintf(
|
||||
' Users.`%s` LIKE "%%%s%%" COLLATE utf8_unicode_ci '
|
||||
, $like_field
|
||||
, str_replace(['"', '%'], ['\"', '\%'], $like_value)
|
||||
);
|
||||
} else {
|
||||
$sql_like[] = sprintf(
|
||||
' Users.`%s` LIKE "%s%%" COLLATE utf8_unicode_ci '
|
||||
, $like_field
|
||||
, str_replace(['"', '%'], ['\"', '\%'], $like_value)
|
||||
);
|
||||
}
|
||||
|
||||
break;
|
||||
default;
|
||||
break;
|
||||
|
@@ -47,8 +47,8 @@
|
||||
<option {% if parm['like_field'] == "email" %}selected="selected"{% endif %} value="email">{{ 'Push::filter on emails' | trans }}</option>
|
||||
</select>
|
||||
<select name="like_type" class="input-medium without-border">
|
||||
<option selected="selected" value="content">{{ 'admin::users:filter: content' | trans }}</option>
|
||||
<option value="start_with">{{ 'admin::users:filter: start with' | trans }}</option>
|
||||
<option selected="selected" value="like_contains">{{ 'admin::users:filter: content' | trans }}</option>
|
||||
<option value="like_start">{{ 'admin::users:filter: start with' | trans }}</option>
|
||||
</select>
|
||||
<input type="text" value="{{parm['like_value']}}" name="like_value" class="input-medium">
|
||||
<span>{{ 'Last applied template' | trans }}</span>
|
||||
|
Reference in New Issue
Block a user