User Query on sbas or bas should not return phantom users

This commit is contained in:
Romain Neutron
2012-01-06 15:43:01 +01:00
parent 2a16efd4bc
commit 75f0e416dc

View File

@@ -23,96 +23,115 @@ class User_Query implements User_QueryInterface
* @var appbox * @var appbox
*/ */
protected $appbox; protected $appbox;
/** /**
* *
* @var Array * @var Array
*/ */
protected $results = array(); protected $results = array();
/** /**
* *
* @var Array * @var Array
*/ */
protected $sort = array(); protected $sort = array();
/** /**
* *
* @var Array * @var Array
*/ */
protected $like_field = array(); protected $like_field = array();
/** /**
* *
* @var Array * @var Array
*/ */
protected $have_rights; protected $have_rights;
/** /**
* *
* @var Array * @var Array
*/ */
protected $have_not_rights; protected $have_not_rights;
/** /**
* *
* @var string * @var string
*/ */
protected $like_match = 'OR'; protected $like_match = 'OR';
/** /**
* *
* @var string * @var string
*/ */
protected $get_inactives = ''; protected $get_inactives = '';
/** /**
* *
* @var int * @var int
*/ */
protected $total = 0; protected $total = 0;
/** /**
* *
* @var Array * @var Array
*/ */
protected $active_bases = array(); protected $active_bases = array();
/** /**
* *
* @var Array * @var Array
*/ */
protected $active_sbas = array(); protected $active_sbas = array();
/** /**
* *
* @var boolean * @var boolean
*/ */
protected $bases_restrictions = false; protected $bases_restrictions = false;
/** /**
* *
* @var boolean * @var boolean
*/ */
protected $sbas_restrictions = false; protected $sbas_restrictions = false;
/** /**
* *
* @var boolean * @var boolean
*/ */
protected $include_templates = false; protected $include_templates = false;
/** /**
* *
* @var boolean * @var boolean
*/ */
protected $only_templates = false; protected $only_templates = false;
/** /**
* *
* @var Array * @var Array
*/ */
protected $base_ids = array(); protected $base_ids = array();
/** /**
* *
* @var Array * @var Array
*/ */
protected $sbas_ids = array(); protected $sbas_ids = array();
/** /**
* *
* @var int * @var int
*/ */
protected $page; protected $page;
/** /**
* *
* @var int * @var int
*/ */
protected $offset_start; protected $offset_start;
/** /**
* *
* @var int * @var int
@@ -124,9 +143,8 @@ class User_Query implements User_QueryInterface
const ORD_ASC = 'asc'; const ORD_ASC = 'asc';
const ORD_DESC = 'desc'; const ORD_DESC = 'desc';
const SORT_FIRSTNAME = 'usr_prenom';
const SORT_FIRSTNAME= 'usr_prenom'; const SORT_LASTNAME = 'usr_nom';
const SORT_LASTNAME= 'usr_nom';
const SORT_COMPANY = 'societe'; const SORT_COMPANY = 'societe';
const SORT_LOGIN = 'usr_login'; const SORT_LOGIN = 'usr_login';
const SORT_EMAIL = 'usr_mail'; const SORT_EMAIL = 'usr_mail';
@@ -134,15 +152,13 @@ class User_Query implements User_QueryInterface
const SORT_CREATIONDATE = 'usr_creationdate'; const SORT_CREATIONDATE = 'usr_creationdate';
const SORT_COUNTRY = 'pays'; const SORT_COUNTRY = 'pays';
const SORT_LASTMODEL = 'lastModel'; const SORT_LASTMODEL = 'lastModel';
const LIKE_FIRSTNAME = 'usr_prenom';
const LIKE_FIRSTNAME= 'usr_prenom'; const LIKE_LASTNAME = 'usr_nom';
const LIKE_LASTNAME= 'usr_nom'; const LIKE_NAME = 'name';
const LIKE_NAME= 'name';
const LIKE_COMPANY = 'societe'; const LIKE_COMPANY = 'societe';
const LIKE_LOGIN = 'usr_login'; const LIKE_LOGIN = 'usr_login';
const LIKE_EMAIL = 'usr_mail'; const LIKE_EMAIL = 'usr_mail';
const LIKE_COUNTRY = 'pays'; const LIKE_COUNTRY = 'pays';
const LIKE_MATCH_AND = 'AND'; const LIKE_MATCH_AND = 'AND';
const LIKE_MATCH_OR = 'OR'; const LIKE_MATCH_OR = 'OR';
@@ -225,16 +241,13 @@ class User_Query implements User_QueryInterface
else else
{ {
$extra = $this->include_phantoms ? ' OR base_id IS NULL ' : ''; $extra = $this->include_phantoms ? ' OR base_id IS NULL ' : '';
if (count($this->active_bases) > count($this->base_ids))
$not_base_id = array_diff($this->active_bases, $this->base_ids);
if (count($not_base_id) > 0 && count($not_base_id) < count($this->base_ids))
{ {
$sql .= sprintf(' AND ((base_id != %s ) ' . $extra . ')' $sql .= sprintf(' AND ((base_id != %s ) ' . $extra . ')'
, implode( , implode(' AND base_id != ', $not_base_id)
' AND base_id != '
, array_diff(
$this->active_bases
, $this->base_ids
)
)
); );
} }
else else
@@ -246,7 +259,6 @@ class User_Query implements User_QueryInterface
} }
if (count($this->sbas_ids) == 0) if (count($this->sbas_ids) == 0)
{ {
if ($this->sbas_restrictions) if ($this->sbas_restrictions)
@@ -255,16 +267,13 @@ class User_Query implements User_QueryInterface
else else
{ {
$extra = $this->include_phantoms ? ' OR sbas_id IS NULL ' : ''; $extra = $this->include_phantoms ? ' OR sbas_id IS NULL ' : '';
if (count($this->active_sbas) > count($this->sbas_ids))
$not_sbas_id = array_diff($this->active_sbas, $this->sbas_ids);
if (count($not_sbas_id) > 0 && count($not_sbas_id) < count($this->sbas_ids))
{ {
$sql .= sprintf(' AND ((sbas_id != %s ) ' . $extra . ')' $sql .= sprintf(' AND ((sbas_id != %s ) ' . $extra . ')'
, implode( , implode(' AND sbas_id != ', $not_sbas_id)
' AND sbas_id != '
, array_diff(
$this->active_sbas
, $this->sbas_ids
)
)
); );
} }
else else
@@ -366,6 +375,7 @@ class User_Query implements User_QueryInterface
return $this; return $this;
} }
/** /**
* *
* @param boolean $boolean * @param boolean $boolean
@@ -479,7 +489,6 @@ class User_Query implements User_QueryInterface
public function get_total() public function get_total()
{ {
if ($this->total) if ($this->total)
return $this->total; return $this->total;
$conn = $this->appbox->get_connection(); $conn = $this->appbox->get_connection();
@@ -527,11 +536,9 @@ class User_Query implements User_QueryInterface
$baslist = array_keys($ACL->get_granted_base($rights)); $baslist = array_keys($ACL->get_granted_base($rights));
if (count($this->base_ids) > 0) if (count($this->base_ids) > 0)
$base_ids = array_intersect($this->base_ids, $baslist); $this->base_ids = array_intersect($this->base_ids, $baslist);
else else
$base_ids = $baslist; $this->base_ids = $baslist;
$this->on_base_ids($base_ids);
$this->total = $this->page = null; $this->total = $this->page = null;
@@ -550,11 +557,9 @@ class User_Query implements User_QueryInterface
$sbaslist = array_keys($ACL->get_granted_sbas($rights)); $sbaslist = array_keys($ACL->get_granted_sbas($rights));
if (count($this->sbas_ids) > 0) if (count($this->sbas_ids) > 0)
$sbas_ids = array_intersect($this->sbas_ids, $sbaslist); $this->sbas_ids = array_intersect($this->sbas_ids, $sbaslist);
else else
$sbas_ids = $sbaslist; $this->sbas_ids = $sbaslist;
$this->on_sbas_ids($sbas_ids);
$this->total = $this->page = null; $this->total = $this->page = null;
@@ -586,7 +591,7 @@ class User_Query implements User_QueryInterface
public function like($like_field, $like_value) public function like($like_field, $like_value)
{ {
if($like_field == self::LIKE_NAME) if ($like_field == self::LIKE_NAME)
{ {
$this->like_field[self::LIKE_FIRSTNAME] = trim($like_value); $this->like_field[self::LIKE_FIRSTNAME] = trim($like_value);
$this->like_field[self::LIKE_LASTNAME] = trim($like_value); $this->like_field[self::LIKE_LASTNAME] = trim($like_value);
@@ -632,7 +637,6 @@ class User_Query implements User_QueryInterface
public function on_base_ids(Array $base_ids = null) public function on_base_ids(Array $base_ids = null)
{ {
if (!$base_ids) if (!$base_ids)
return $this; return $this;
$this->bases_restrictions = true; $this->bases_restrictions = true;
@@ -657,7 +661,6 @@ class User_Query implements User_QueryInterface
public function on_sbas_ids(Array $sbas_ids = null) public function on_sbas_ids(Array $sbas_ids = null)
{ {
if (!$sbas_ids) if (!$sbas_ids)
return $this; return $this;
$this->sbas_restrictions = true; $this->sbas_restrictions = true;