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