* dblayeroo: allow to sort the ORDER statements (the first added is the first use)
* dblayeroo: allow to sort the Display statements (the first added is the first use) * dblayeroo: change displayColumns to displayAdd git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@3541 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
@@ -542,9 +542,9 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
|
|||||||
// Filter on the db1, do not display db2
|
// Filter on the db1, do not display db2
|
||||||
$db1 = $this->db1 ();
|
$db1 = $this->db1 ();
|
||||||
$db2 = $this->db2 ();
|
$db2 = $this->db2 ();
|
||||||
$db2->displayColumn ();
|
$db2->displayAdd ();
|
||||||
$res = $db1->select ()
|
$res = $db1->select ()
|
||||||
->displayColumn ("group")
|
->displayAdd ("group")
|
||||||
->joinLeft ($db2, array ("group"=>"group"))
|
->joinLeft ($db2, array ("group"=>"group"))
|
||||||
->execute ();
|
->execute ();
|
||||||
$db1->disconnect ();
|
$db1->disconnect ();
|
||||||
@@ -573,33 +573,33 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
|
|||||||
// Filter on the db1, display one column in db2
|
// Filter on the db1, display one column in db2
|
||||||
$db1 = $this->db1 ();
|
$db1 = $this->db1 ();
|
||||||
$db2 = $this->db2 ();
|
$db2 = $this->db2 ();
|
||||||
$db2->displayColumn ("group");
|
$db2->displayAdd ("group");
|
||||||
$res = $db1->select ()
|
$res = $db1->select ()
|
||||||
->displayColumn ("group")
|
->displayAdd ("group")
|
||||||
->joinLeft ($db2, array ("group"=>"group"))
|
->joinLeft ($db2, array ("group"=>"group"))
|
||||||
->execute ();
|
->execute ();
|
||||||
$db1->disconnect ();
|
$db1->disconnect ();
|
||||||
$db2->disconnect ();
|
$db2->disconnect ();
|
||||||
$this->assertSame (array (
|
$this->assertSame (array (
|
||||||
array (
|
array (
|
||||||
'groupedoo.group' => 'group1',
|
|
||||||
'usersoo.group' => 'group1',
|
'usersoo.group' => 'group1',
|
||||||
|
'groupedoo.group' => 'group1',
|
||||||
),
|
),
|
||||||
array (
|
array (
|
||||||
'groupedoo.group' => 'group1',
|
|
||||||
'usersoo.group' => 'group1',
|
'usersoo.group' => 'group1',
|
||||||
|
'groupedoo.group' => 'group1',
|
||||||
),
|
),
|
||||||
array (
|
array (
|
||||||
'groupedoo.group' => 'group1',
|
|
||||||
'usersoo.group' => 'group1',
|
'usersoo.group' => 'group1',
|
||||||
|
'groupedoo.group' => 'group1',
|
||||||
),
|
),
|
||||||
array (
|
array (
|
||||||
'groupedoo.group' => 'group1',
|
|
||||||
'usersoo.group' => 'group1',
|
'usersoo.group' => 'group1',
|
||||||
|
'groupedoo.group' => 'group1',
|
||||||
),
|
),
|
||||||
array (
|
array (
|
||||||
'groupedoo.group' => 'group2',
|
|
||||||
'usersoo.group' => NULL,
|
'usersoo.group' => NULL,
|
||||||
|
'groupedoo.group' => 'group2',
|
||||||
),
|
),
|
||||||
), $res);
|
), $res);
|
||||||
}
|
}
|
||||||
@@ -609,9 +609,9 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
|
|||||||
// Filter on the db1 and add order in full mode
|
// Filter on the db1 and add order in full mode
|
||||||
$db1 = $this->db1 ();
|
$db1 = $this->db1 ();
|
||||||
$db2 = $this->db2 ();
|
$db2 = $this->db2 ();
|
||||||
$db2->displayColumn ("group");
|
$db2->displayAdd ("group");
|
||||||
$res = $db1->select ()
|
$res = $db1->select ()
|
||||||
->displayColumn ("group")
|
->displayAdd ("group")
|
||||||
->joinLeft ($db2, array ("group"=>"group"))
|
->joinLeft ($db2, array ("group"=>"group"))
|
||||||
->orderAdd ("group", "DESC")
|
->orderAdd ("group", "DESC")
|
||||||
->execute ();
|
->execute ();
|
||||||
@@ -619,24 +619,24 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
|
|||||||
$db2->disconnect ();
|
$db2->disconnect ();
|
||||||
$this->assertSame (array (
|
$this->assertSame (array (
|
||||||
array (
|
array (
|
||||||
'groupedoo.group' => 'group2',
|
|
||||||
'usersoo.group' => NULL,
|
'usersoo.group' => NULL,
|
||||||
|
'groupedoo.group' => 'group2',
|
||||||
),
|
),
|
||||||
array (
|
array (
|
||||||
'groupedoo.group' => 'group1',
|
|
||||||
'usersoo.group' => 'group1',
|
'usersoo.group' => 'group1',
|
||||||
|
'groupedoo.group' => 'group1',
|
||||||
),
|
),
|
||||||
array (
|
array (
|
||||||
'groupedoo.group' => 'group1',
|
|
||||||
'usersoo.group' => 'group1',
|
'usersoo.group' => 'group1',
|
||||||
|
'groupedoo.group' => 'group1',
|
||||||
),
|
),
|
||||||
array (
|
array (
|
||||||
'groupedoo.group' => 'group1',
|
|
||||||
'usersoo.group' => 'group1',
|
'usersoo.group' => 'group1',
|
||||||
|
'groupedoo.group' => 'group1',
|
||||||
),
|
),
|
||||||
array (
|
array (
|
||||||
'groupedoo.group' => 'group1',
|
|
||||||
'usersoo.group' => 'group1',
|
'usersoo.group' => 'group1',
|
||||||
|
'groupedoo.group' => 'group1',
|
||||||
),
|
),
|
||||||
), $res);
|
), $res);
|
||||||
}
|
}
|
||||||
@@ -660,18 +660,18 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
// Two joins tables in left join
|
// Two joins tables in left join
|
||||||
$db1 = $this->db1 (); // Do not display anything from groupedoo
|
$db1 = $this->db1 (); // Do not display anything from groupedoo
|
||||||
$db1->displayColumn ("group");
|
$db1->displayAdd ("group")
|
||||||
|
->orderAdd ("group", "DESC");
|
||||||
|
|
||||||
$db2 = $this->db2 (); // Display the gecos and group from usersoo
|
$db2 = $this->db2 (); // Display the gecos and group from usersoo
|
||||||
$db2->displayColumn ("gecos")
|
$db2->displayAdd ("gecos")
|
||||||
->orderAdd ("gecos", "ASC");
|
->orderAdd ("gecos", "ASC");
|
||||||
|
|
||||||
$db4 = $this->db4 (); // Display the name in rightsoo
|
$db4 = $this->db4 (); // Display the name in rightsoo
|
||||||
$db4->displayColumn ("name");
|
$db4->displayAdd ("name");
|
||||||
$db1->joinLeft ($db4, array ("group"=>"group"));
|
$db1->joinLeft ($db4, array ("group"=>"group"));
|
||||||
$res = $db1->select ()
|
$res = $db1->select ()
|
||||||
->joinLeft ($db2, array ("group"=>"group"))
|
->joinLeft ($db2, array ("group"=>"group"))
|
||||||
->orderAdd ("group", "DESC")
|
|
||||||
->execute ();
|
->execute ();
|
||||||
$db1->disconnect ();
|
$db1->disconnect ();
|
||||||
$db2->disconnect ();
|
$db2->disconnect ();
|
||||||
@@ -679,29 +679,58 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
|
|||||||
$this->assertSame (array (
|
$this->assertSame (array (
|
||||||
array (
|
array (
|
||||||
'groupedoo.group' => 'group2',
|
'groupedoo.group' => 'group2',
|
||||||
'rightsoo.name' => NULL,
|
|
||||||
'usersoo.gecos' => NULL,
|
'usersoo.gecos' => NULL,
|
||||||
|
'rightsoo.name' => NULL,
|
||||||
),
|
),
|
||||||
array (
|
array (
|
||||||
'groupedoo.group' => 'group1',
|
'groupedoo.group' => 'group1',
|
||||||
'rightsoo.name' => 'RO',
|
|
||||||
'usersoo.gecos' => 'name',
|
'usersoo.gecos' => 'name',
|
||||||
|
'rightsoo.name' => 'RO',
|
||||||
),
|
),
|
||||||
array (
|
array (
|
||||||
'groupedoo.group' => 'group1',
|
'groupedoo.group' => 'group1',
|
||||||
'rightsoo.name' => 'RO',
|
|
||||||
'usersoo.gecos' => 'name2',
|
'usersoo.gecos' => 'name2',
|
||||||
|
'rightsoo.name' => 'RO',
|
||||||
),
|
),
|
||||||
array (
|
array (
|
||||||
'groupedoo.group' => 'group1',
|
'groupedoo.group' => 'group1',
|
||||||
'rightsoo.name' => 'RO',
|
|
||||||
'usersoo.gecos' => 'name3',
|
'usersoo.gecos' => 'name3',
|
||||||
|
'rightsoo.name' => 'RO',
|
||||||
),
|
),
|
||||||
array (
|
array (
|
||||||
'groupedoo.group' => 'group1',
|
'groupedoo.group' => 'group1',
|
||||||
'rightsoo.name' => 'RO',
|
|
||||||
'usersoo.gecos' => 'name4',
|
'usersoo.gecos' => 'name4',
|
||||||
|
'rightsoo.name' => 'RO',
|
||||||
),
|
),
|
||||||
), $res);
|
), $res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_sortOrder1 ()
|
||||||
|
{
|
||||||
|
$db1 = $this->db1 ();
|
||||||
|
$res = $db1->getSortOrder ();
|
||||||
|
$db1->disconnect ();
|
||||||
|
$this->assertSame ("order1", $res);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_sortOrder2 ()
|
||||||
|
{
|
||||||
|
$db1 = $this->db1 ();
|
||||||
|
$db1->getSortOrder ();
|
||||||
|
$res = $db1->getSortOrder ();
|
||||||
|
$db1->disconnect ();
|
||||||
|
$this->assertSame ("order2", $res);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_sortOrder3 ()
|
||||||
|
{
|
||||||
|
$db1 = $this->db1 ();
|
||||||
|
$db2 = $this->db2 ();
|
||||||
|
$db1->getSortOrder ();
|
||||||
|
$db1->getSortOrder ();
|
||||||
|
$res = $db2->getSortOrder ();
|
||||||
|
$db1->disconnect ();
|
||||||
|
$db2->disconnect ();
|
||||||
|
$this->assertSame ("order3", $res);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -165,6 +165,7 @@ class dblayeroo
|
|||||||
/* {{{ */
|
/* {{{ */
|
||||||
{
|
{
|
||||||
unset (self::$instance[$this->dsn]);
|
unset (self::$instance[$this->dsn]);
|
||||||
|
self::$sortOrder = 0;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
@@ -1224,6 +1225,20 @@ class dblayeroo
|
|||||||
*/
|
*/
|
||||||
private $debugDepth = 1;
|
private $debugDepth = 1;
|
||||||
|
|
||||||
|
/** The sort order of select/order entries crossed the differents objects
|
||||||
|
*/
|
||||||
|
private static $sortOrder = 0;
|
||||||
|
|
||||||
|
/** The method to get a new sorti order acrossed the differents objects
|
||||||
|
*/
|
||||||
|
public function getSortOrder ()
|
||||||
|
/* {{{ */
|
||||||
|
{
|
||||||
|
++self::$sortOrder;
|
||||||
|
return "order".self::$sortOrder;
|
||||||
|
}
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
/** Reinit the SQL request
|
/** Reinit the SQL request
|
||||||
*/
|
*/
|
||||||
public function clearRequest ()
|
public function clearRequest ()
|
||||||
@@ -1333,16 +1348,26 @@ class dblayeroo
|
|||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/** Set the columns to display for the next SELECT request
|
/** Changing the name displayColumns to displayAdd
|
||||||
|
* @param array|string|null $columnNames The columns name, separated by comma
|
||||||
|
* @deprecated 0.36
|
||||||
|
*/
|
||||||
|
public function displayColumns ($columnNames = array ())
|
||||||
|
{
|
||||||
|
return $this->displayAdd ($columnNames);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Set the columns to display for the next SELECT request.
|
||||||
|
* The columns are ordered by the first added to the last added
|
||||||
* @param array|string|null $columnNames The columns name, separated by comma
|
* @param array|string|null $columnNames The columns name, separated by comma
|
||||||
* By default, display all the columns if this method is not called
|
* By default, display all the columns if this method is not called
|
||||||
* If the value is null or not provided or an empty array, do not display
|
* If the value is null or not provided or an empty array, do not display
|
||||||
* any field
|
* any field
|
||||||
*/
|
*/
|
||||||
public function displayColumn ($columnNames = array ())
|
public function displayAdd ($columnNames = array ())
|
||||||
/* {{{ */
|
/* {{{ */
|
||||||
{
|
{
|
||||||
$this->debugLog ("Entering displayColumn (",$columnNames,")");
|
$this->debugLog ("Entering displayAdd (",$columnNames,")");
|
||||||
if (! is_string ($columnNames) && ! is_array ($columnNames))
|
if (! is_string ($columnNames) && ! is_array ($columnNames))
|
||||||
$this->DBException (
|
$this->DBException (
|
||||||
"Invalid columnNames provided (not string and not array)");
|
"Invalid columnNames provided (not string and not array)");
|
||||||
@@ -1356,7 +1381,7 @@ class dblayeroo
|
|||||||
if (! array_key_exists ($name, $this->fields))
|
if (! array_key_exists ($name, $this->fields))
|
||||||
$this->DBException (sprintf (
|
$this->DBException (sprintf (
|
||||||
"Invalid field to display '%s' : not defined in table", $name));
|
"Invalid field to display '%s' : not defined in table", $name));
|
||||||
$this->displayColumn[] = $this->sep.$name.$this->sep;
|
$this->displayColumn[$this->getSortOrder()] = $this->sep.$name.$this->sep;
|
||||||
}
|
}
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@@ -1385,7 +1410,7 @@ class dblayeroo
|
|||||||
{
|
{
|
||||||
foreach (array_keys ($this->fields) as $name)
|
foreach (array_keys ($this->fields) as $name)
|
||||||
{
|
{
|
||||||
$displayColumn[] = $this->sep.$name.$this->sep;
|
$displayColumn[$this->getSortOrder()] = $this->sep.$name.$this->sep;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -1399,7 +1424,7 @@ class dblayeroo
|
|||||||
{
|
{
|
||||||
foreach (array_keys ($this->fields) as $name)
|
foreach (array_keys ($this->fields) as $name)
|
||||||
{
|
{
|
||||||
$displayColumn[] = $this->sep.$name.$this->sep;
|
$displayColumn[$this->getSortOrder()] = $this->sep.$name.$this->sep;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -1407,19 +1432,20 @@ class dblayeroo
|
|||||||
$displayColumn = $this->displayColumn;
|
$displayColumn = $this->displayColumn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach ($displayColumn as $d)
|
foreach ($displayColumn as $pos=>$d)
|
||||||
{
|
{
|
||||||
if ($full !== false)
|
if ($full !== false)
|
||||||
$columns[] = $this->sep.$this->tableprefix.$this->table.$this->sep.".".
|
$columns[$pos] = $this->sep.$this->tableprefix.$this->table.$this->sep.
|
||||||
$d;
|
".".$d;
|
||||||
else
|
else
|
||||||
$columns[] = $d;
|
$columns[$pos] = $d;
|
||||||
}
|
}
|
||||||
if ($this->joinObject)
|
if ($this->joinObject)
|
||||||
{
|
{
|
||||||
foreach ($this->joinObject as $obj)
|
foreach ($this->joinObject as $obj)
|
||||||
$columns = array_merge ($columns, $obj->displayGet (true));
|
$columns = array_merge ($columns, $obj->displayGet (true));
|
||||||
}
|
}
|
||||||
|
ksort ($columns, SORT_NATURAL);
|
||||||
return $columns;
|
return $columns;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
@@ -1667,7 +1693,8 @@ class dblayeroo
|
|||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/** Add a new ORDER sort
|
/** Add a new ORDER sort. The multiple ORDERS are used from the first added to
|
||||||
|
* the last added
|
||||||
* @param string $field The field to sort
|
* @param string $field The field to sort
|
||||||
* @param string|null $sort The sort order ("ASC", "DESC");
|
* @param string|null $sort The sort order ("ASC", "DESC");
|
||||||
*/
|
*/
|
||||||
@@ -1685,7 +1712,8 @@ class dblayeroo
|
|||||||
if (! array_key_exists ($field, $this->fields))
|
if (! array_key_exists ($field, $this->fields))
|
||||||
$this->DBException (sprintf (
|
$this->DBException (sprintf (
|
||||||
"Invalid field to orderAdd '%s' : not defined in table", $field));
|
"Invalid field to orderAdd '%s' : not defined in table", $field));
|
||||||
$this->orderExpression[] = $this->sep.$field.$this->sep." ".$sort;
|
$this->orderExpression[$this->getSortOrder()] =
|
||||||
|
$this->sep.$field.$this->sep." ".$sort;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
@@ -1702,18 +1730,20 @@ class dblayeroo
|
|||||||
$order = array ();
|
$order = array ();
|
||||||
if ($this->joinObject)
|
if ($this->joinObject)
|
||||||
$full = true;
|
$full = true;
|
||||||
foreach ($this->orderExpression as $o)
|
foreach ($this->orderExpression as $pos=>$o)
|
||||||
{
|
{
|
||||||
if ($full !== false)
|
if ($full !== false)
|
||||||
$order[] = $this->sep.$this->tableprefix.$this->table.$this->sep.".".$o;
|
$order[$pos] = $this->sep.$this->tableprefix.$this->table.$this->sep.
|
||||||
|
".".$o;
|
||||||
else
|
else
|
||||||
$order[] = $o;
|
$order[$pos] = $o;
|
||||||
}
|
}
|
||||||
if ($this->joinObject)
|
if ($this->joinObject)
|
||||||
{
|
{
|
||||||
foreach ($this->joinObject as $obj)
|
foreach ($this->joinObject as $obj)
|
||||||
$order = array_merge ($order, $obj->orderGet (true));
|
$order = array_merge ($order, $obj->orderGet (true));
|
||||||
}
|
}
|
||||||
|
ksort ($order, SORT_NATURAL);
|
||||||
return $order;
|
return $order;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
@@ -2118,8 +2148,8 @@ class dblayeroo
|
|||||||
$objTmp->debugDepth++;
|
$objTmp->debugDepth++;
|
||||||
$objTmp->clearRequest ();
|
$objTmp->clearRequest ();
|
||||||
$objTmp->Select ();
|
$objTmp->Select ();
|
||||||
$objTmp->displayColumn ($this->primary);
|
$objTmp->displayAdd ($this->primary);
|
||||||
$objTmp->displayColumn ($columns);
|
$objTmp->displayAdd ($columns);
|
||||||
$objTmp->whereValues = $this->whereValues;
|
$objTmp->whereValues = $this->whereValues;
|
||||||
$objTmp->whereExpression = $this->whereExpression;
|
$objTmp->whereExpression = $this->whereExpression;
|
||||||
$objTmp->limitLines (3);
|
$objTmp->limitLines (3);
|
||||||
@@ -2141,7 +2171,7 @@ class dblayeroo
|
|||||||
$objTmp->debugDepth++;
|
$objTmp->debugDepth++;
|
||||||
$objTmp->clearRequest ();
|
$objTmp->clearRequest ();
|
||||||
$objTmp->Select ();
|
$objTmp->Select ();
|
||||||
$objTmp->displayColumn ($this->primary);
|
$objTmp->displayAdd ($this->primary);
|
||||||
if (is_array ($columns))
|
if (is_array ($columns))
|
||||||
{
|
{
|
||||||
// Multiple columns in unique
|
// Multiple columns in unique
|
||||||
@@ -2205,7 +2235,7 @@ class dblayeroo
|
|||||||
$objTmp->debugDepth++;
|
$objTmp->debugDepth++;
|
||||||
$objTmp->clearRequest ();
|
$objTmp->clearRequest ();
|
||||||
$objTmp->Select ();
|
$objTmp->Select ();
|
||||||
$objTmp->displayColumn ($objTmp->primary);
|
$objTmp->displayAdd ($objTmp->primary);
|
||||||
$objTmp->whereAdd ($params[1], "=", $this->setValues[$field]);
|
$objTmp->whereAdd ($params[1], "=", $this->setValues[$field]);
|
||||||
if (count ($objTmp->execute ()) === 0)
|
if (count ($objTmp->execute ()) === 0)
|
||||||
$errors[$field] = sprintf (dgettext ("domframework",
|
$errors[$field] = sprintf (dgettext ("domframework",
|
||||||
@@ -2284,6 +2314,7 @@ class dblayeroo
|
|||||||
{
|
{
|
||||||
$columns = $this->displayGet (true);
|
$columns = $this->displayGet (true);
|
||||||
}
|
}
|
||||||
|
$columns = array_values ($columns);
|
||||||
foreach ($result as $rownb=>$row)
|
foreach ($result as $rownb=>$row)
|
||||||
{
|
{
|
||||||
foreach ($row as $colNb=>$val)
|
foreach ($row as $colNb=>$val)
|
||||||
|
|||||||
Reference in New Issue
Block a user