* 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:
2017-04-25 14:43:53 +00:00
parent 48ce12accc
commit 39d34965c0
2 changed files with 104 additions and 44 deletions

View File

@@ -165,6 +165,7 @@ class dblayeroo
/* {{{ */
{
unset (self::$instance[$this->dsn]);
self::$sortOrder = 0;
}
/* }}} */
@@ -1224,6 +1225,20 @@ class dblayeroo
*/
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
*/
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
* 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
* 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))
$this->DBException (
"Invalid columnNames provided (not string and not array)");
@@ -1356,7 +1381,7 @@ class dblayeroo
if (! array_key_exists ($name, $this->fields))
$this->DBException (sprintf (
"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;
}
@@ -1385,7 +1410,7 @@ class dblayeroo
{
foreach (array_keys ($this->fields) as $name)
{
$displayColumn[] = $this->sep.$name.$this->sep;
$displayColumn[$this->getSortOrder()] = $this->sep.$name.$this->sep;
}
}
else
@@ -1399,7 +1424,7 @@ class dblayeroo
{
foreach (array_keys ($this->fields) as $name)
{
$displayColumn[] = $this->sep.$name.$this->sep;
$displayColumn[$this->getSortOrder()] = $this->sep.$name.$this->sep;
}
}
else
@@ -1407,19 +1432,20 @@ class dblayeroo
$displayColumn = $this->displayColumn;
}
}
foreach ($displayColumn as $d)
foreach ($displayColumn as $pos=>$d)
{
if ($full !== false)
$columns[] = $this->sep.$this->tableprefix.$this->table.$this->sep.".".
$d;
$columns[$pos] = $this->sep.$this->tableprefix.$this->table.$this->sep.
".".$d;
else
$columns[] = $d;
$columns[$pos] = $d;
}
if ($this->joinObject)
{
foreach ($this->joinObject as $obj)
$columns = array_merge ($columns, $obj->displayGet (true));
}
ksort ($columns, SORT_NATURAL);
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|null $sort The sort order ("ASC", "DESC");
*/
@@ -1685,7 +1712,8 @@ class dblayeroo
if (! array_key_exists ($field, $this->fields))
$this->DBException (sprintf (
"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;
}
/* }}} */
@@ -1702,18 +1730,20 @@ class dblayeroo
$order = array ();
if ($this->joinObject)
$full = true;
foreach ($this->orderExpression as $o)
foreach ($this->orderExpression as $pos=>$o)
{
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
$order[] = $o;
$order[$pos] = $o;
}
if ($this->joinObject)
{
foreach ($this->joinObject as $obj)
$order = array_merge ($order, $obj->orderGet (true));
}
ksort ($order, SORT_NATURAL);
return $order;
}
/* }}} */
@@ -2118,8 +2148,8 @@ class dblayeroo
$objTmp->debugDepth++;
$objTmp->clearRequest ();
$objTmp->Select ();
$objTmp->displayColumn ($this->primary);
$objTmp->displayColumn ($columns);
$objTmp->displayAdd ($this->primary);
$objTmp->displayAdd ($columns);
$objTmp->whereValues = $this->whereValues;
$objTmp->whereExpression = $this->whereExpression;
$objTmp->limitLines (3);
@@ -2141,7 +2171,7 @@ class dblayeroo
$objTmp->debugDepth++;
$objTmp->clearRequest ();
$objTmp->Select ();
$objTmp->displayColumn ($this->primary);
$objTmp->displayAdd ($this->primary);
if (is_array ($columns))
{
// Multiple columns in unique
@@ -2205,7 +2235,7 @@ class dblayeroo
$objTmp->debugDepth++;
$objTmp->clearRequest ();
$objTmp->Select ();
$objTmp->displayColumn ($objTmp->primary);
$objTmp->displayAdd ($objTmp->primary);
$objTmp->whereAdd ($params[1], "=", $this->setValues[$field]);
if (count ($objTmp->execute ()) === 0)
$errors[$field] = sprintf (dgettext ("domframework",
@@ -2284,6 +2314,7 @@ class dblayeroo
{
$columns = $this->displayGet (true);
}
$columns = array_values ($columns);
foreach ($result as $rownb=>$row)
{
foreach ($row as $colNb=>$val)