Version 4.3.0

This commit is contained in:
Neo committed 2025-12-19 05:47:12 -08:00
1 parent 96997ddd8e
commit fe1acf984a
1349 files changed
+116159 -67711

No files matched your search

+41 -41
View File
@@ -36,16 +36,21 @@ class _Db extends Table
* @brief Initial WHERE clause
*/
public $where;
/**
* @brief Initial GROUP BY clause
*/
protected $group;
/**
* @brief Force index clause
*/
protected $index;
/**
* @brief Primary sort column
*/
public $primarySortBy;
/**
* @brief Direction of primary sort
*/
public $primarySortDirection;
/**
* @brief Joins
@@ -57,31 +62,26 @@ class _Db extends Table
*/
public $keyField = NULL;
/**
* @brief Restrict select columns to only those listed - useful when grouping
*/
public $onlySelected = NULL;
/**
* Constructor
*
* @param array|string $table Database table
* @param string $table Database table
* @param \IPS\Http\Url $baseUrl Base URL
* @param array|null $where WHERE clause
* @param string|null $group GROUP clause
* @param array|null $forceIndex Index to force
* @return void
*/
public function __construct( $table, \IPS\Http\Url $baseUrl, $where=NULL, $group=NULL, $forceIndex=NULL )
public function __construct( $table, \IPS\Http\Url $baseUrl, $where=NULL, $forceIndex=NULL )
{
$this->table = $table;
$this->where = $where;
$this->group = $group;
$this->index = $forceIndex;
return parent::__construct( $baseUrl );
}
protected $onlySelected = false;
/**
* Get rows
*
@@ -285,29 +285,13 @@ class _Db extends Table
$selects = $this->selects;
if( $this->onlySelected !== NULL )
if ( count( $this->joins ) )
{
foreach( $this->onlySelected as $column )
foreach( $this->joins as $join )
{
$selects[] = $column;
}
if( $this->group !== NULL )
{
$this->group = is_array( $this->group ) ? $this->group : array( $this->group );
$this->group = array_unique( array_merge( $this->group, $this->onlySelected ) );
}
}
else
{
if ( count( $this->joins ) )
{
foreach( $this->joins as $join )
if ( isset( $join['select'] ) )
{
if ( isset( $join['select'] ) )
{
$selects[] = $join['select'];
}
$selects[] = $join['select'];
}
}
}
@@ -324,8 +308,8 @@ class _Db extends Table
$count = $count->first();
/* Now get column headers */
$query = \IPS\Db::i()->select( $this->onlySelected ? implode( ', ', $selects ) : '*', $this->table, NULL, NULL, array( 0, 1 ) );
$query = \IPS\Db::i()->select( '*', $this->table, NULL, NULL, array( 0, 1 ) );
if ( count( $this->joins ) )
{
foreach( $this->joins as $join )
@@ -368,17 +352,22 @@ class _Db extends Table
}, explode( ',', $this->sortBy ) ) );
$orderBy .= $this->sortDirection == 'asc' ? ' asc' : ' desc';
/* Primary sorting effectively creates a way to 'pin' records regardless of the user selected sort */
if( $this->primarySortBy !== NULL AND $this->primarySortDirection !== NULL )
{
$orderBy = "{$this->primarySortBy} {$this->primarySortDirection}, {$orderBy}";
}
}
/* Run query */
$rows = array();
$select = \IPS\Db::i()->select(
$this->onlySelected ? implode( ', ', $selects ) : ( ( count( $selects ) ) ? $this->table . '.*, ' . implode( ', ', $selects ) : '*' ),
( count( $selects ) ) ? $this->table . '.*, ' . implode( ', ', $selects ) : '*',
$this->table,
$where,
$orderBy,
array( ( $this->limit * ( $this->page - 1 ) ), $this->limit ),
$this->group
array( ( $this->limit * ( $this->page - 1 ) ), $this->limit )
);
if ( $this->index )
@@ -429,7 +418,7 @@ class _Db extends Table
}
else
{
$v = htmlspecialchars( $v, ENT_QUOTES | \IPS\HTMLENTITIES, 'UTF-8', FALSE );
$v = htmlspecialchars( $v, ENT_QUOTES | ENT_DISALLOWED, 'UTF-8', FALSE );
}
/* Are we including this one? */
@@ -449,6 +438,12 @@ class _Db extends Table
$row['_buttons'] = call_user_func( $this->rowButtons, $_row );
}
/* Highlighting? */
if ( isset( $this->parsers['_highlight'] ) and $class = call_user_func( $this->parsers['_highlight'], $_row ) )
{
$this->highlightRows[ $rowId ] = $class;
}
$rows[ $rowId ] = $row;
}
@@ -485,6 +480,11 @@ class _Db extends Table
{
return false;
}
if( !is_array( $count ) )
{
$count = array( $count );
}
if ( mb_strstr( $this->sortBy, ',' ) )
{