Qual: Mutualize code

This commit is contained in:
Laurent Destailleur 2014-02-06 20:40:01 +01:00
parent cfb9150e10
commit 80046a5310
6 changed files with 38 additions and 161 deletions

View File

@ -61,5 +61,37 @@ abstract class DoliDB
public $ok;
public $error;
/**
* Define sort criteria of request
*
* @param string $sortfield List of sort fields
* @param string $sortorder Sort order
* @return string String to provide syntax of a sort sql string
*/
function order($sortfield=0,$sortorder=0)
{
if ($sortfield)
{
$return='';
$fields=explode(',',$sortfield);
foreach($fields as $val)
{
if (! $return) $return.=' ORDER BY ';
else $return.=',';
$return.=preg_replace('/[^0-9a-z_\.]/i','',$val);
if ($sortorder) $return.=' '.preg_replace('/[^0-9a-z]/i','',$sortorder);
}
return $return;
}
else
{
return '';
}
}
}

View File

@ -239,7 +239,7 @@ class DoliDBMssql extends DoliDB
{
return '';
}
/**
* Close database connexion
*
@ -525,37 +525,6 @@ class DoliDBMssql extends DoliDB
}
/**
* Define sort criteria of request
*
* @param string $sortfield List of sort fields
* @param string $sortorder Sort order
* @return string String to provide syntax of a sort sql string
* TODO Mutualized this into a mother class
*/
function order($sortfield=0,$sortorder=0)
{
if ($sortfield)
{
$return='';
$fields=explode(',',$sortfield);
foreach($fields as $val)
{
if (! $return) $return.=' ORDER BY ';
else $return.=',';
$return.=preg_replace('/[^0-9a-z_\.]/i','',$val);
if ($sortorder) $return.=' '.preg_replace('/[^0-9a-z]/i','',$sortorder);
}
return $return;
}
else
{
return '';
}
}
/**
* Escape a string to insert data
*

View File

@ -257,7 +257,7 @@ class DoliDBMysql extends DoliDB
{
return explode('.',$this->getVersion());
}
/**
* Return version of database client driver
*
@ -267,7 +267,7 @@ class DoliDBMysql extends DoliDB
{
return mysqli_get_client_info();
}
/**
* Close database connexion
@ -506,37 +506,6 @@ class DoliDBMysql extends DoliDB
}
/**
* Define sort criteria of request
*
* @param string $sortfield List of sort fields
* @param string $sortorder Sort order
* @return string String to provide syntax of a sort sql string
* TODO Mutualized this into a mother class
*/
function order($sortfield=0,$sortorder=0)
{
if ($sortfield)
{
$return='';
$fields=explode(',',$sortfield);
foreach($fields as $val)
{
if (! $return) $return.=' ORDER BY ';
else $return.=',';
$return.=preg_replace('/[^0-9a-z_\.]/i','',$val);
if ($sortorder) $return.=' '.preg_replace('/[^0-9a-z]/i','',$sortorder);
}
return $return;
}
else
{
return '';
}
}
/**
* Escape a string to insert data
*

View File

@ -262,7 +262,7 @@ class DoliDBMysqli extends DoliDB
{
return mysqli_get_client_info($this->db);
}
/**
* Close database connexion
@ -508,37 +508,6 @@ class DoliDBMysqli extends DoliDB
}
/**
* Define sort criteria of request
*
* @param string $sortfield List of sort fields
* @param string $sortorder Sort order
* @return string String to provide syntax of a sort sql string
* TODO Mutualized this into a mother class
*/
function order($sortfield=0,$sortorder=0)
{
if ($sortfield)
{
$return='';
$fields=explode(',',$sortfield);
foreach($fields as $val)
{
if (! $return) $return.=' ORDER BY ';
else $return.=',';
$return.=preg_replace('/[^0-9a-z_\.]/i','',$val);
if ($sortorder) $return.=' '.preg_replace('/[^0-9a-z]/i','',$sortorder);
}
return $return;
}
else
{
return '';
}
}
/**
* Escape a string to insert data
*

View File

@ -724,37 +724,6 @@ class DoliDBPgsql extends DoliDB
}
/**
* Define sort criteria of request
*
* @param string $sortfield List of sort fields
* @param string $sortorder Sort order
* @return string String to provide syntax of a sort sql string
* TODO Mutualized this into a mother class
*/
function order($sortfield=0,$sortorder=0)
{
if ($sortfield)
{
$return='';
$fields=explode(',',$sortfield);
foreach($fields as $val)
{
if (! $return) $return.=' ORDER BY ';
else $return.=',';
$return.=preg_replace('/[^0-9a-z_\.]/i','',$val);
if ($sortorder) $return.=' '.preg_replace('/[^0-9a-z]/i','',$sortorder);
}
return $return;
}
else
{
return '';
}
}
/**
* Escape a string to insert data
*

View File

@ -391,8 +391,8 @@ class DoliDBSqlite extends DoliDB
{
return '';
}
/**
* Close database connexion
*
@ -647,37 +647,6 @@ class DoliDBSqlite extends DoliDB
}
/**
* Define sort criteria of request
*
* @param string $sortfield List of sort fields
* @param string $sortorder Sort order
* @return string String to provide syntax of a sort sql string
* TODO Mutualized this into a mother class
*/
function order($sortfield=0,$sortorder=0)
{
if ($sortfield)
{
$return='';
$fields=explode(',',$sortfield);
foreach($fields as $val)
{
if (! $return) $return.=' ORDER BY ';
else $return.=',';
$return.=preg_replace('/[^0-9a-z_\.]/i','',$val);
if ($sortorder) $return.=' '.preg_replace('/[^0-9a-z]/i','',$sortorder);
}
return $return;
}
else
{
return '';
}
}
/**
* Escape a string to insert data
*