Version 4.5.0

This commit is contained in:
Neo committed 2025-12-19 05:51:58 -08:00
1 parent 1a0c7fd3c2
commit f79dcf067a
3791 files changed
+248032 -76372

No files matched your search

+33 -9
View File
@@ -11,7 +11,7 @@
namespace IPS\Patterns;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -26,17 +26,25 @@ class _ActiveRecordIterator extends \IteratorIterator implements \Countable
* @brief Classname
*/
public $classname;
/**
* @brief Parent classname
*/
public $parentClassname = NULL;
/**
* Constructor
*
* @param \Traversable $iterator The iterator
* @param string $classname The classname
* @param \Traversable $iterator The iterator
* @param string $classname The classname
* @param string|NULL $parentClass Parent classname, if the parent data is also available (e.g. joined in a query)
* @return void
*/
public function __construct( \Traversable $iterator, $classname )
public function __construct( \Traversable $iterator, $classname, $parentClassname = NULL )
{
$this->classname = $classname;
$this->classname = $classname;
$this->parentClassname = $parentClassname;
return parent::__construct( $iterator );
}
@@ -47,18 +55,34 @@ class _ActiveRecordIterator extends \IteratorIterator implements \Countable
*/
public function current()
{
$current = parent::current();
/* This is here purely to prime caches to prevent queries later. If we've already joined (or otherwise have) the data for another class, then we can construct
an active record object of it in memory to prevent calls to load() against that class resulting in separate queries later. */
if( $this->parentClassname !== NULL )
{
$parentClass = $this->parentClassname;
/* We need to make sure we actually have the data first though */
$idColumn = $parentClass::$databasePrefix . $parentClass::$databaseColumnId;
if( isset( $current[ $idColumn ] ) )
{
$parentClass::constructFromData( $current );
}
}
$classname = $this->classname;
return $classname::constructFromData( parent::current() );
return $classname::constructFromData( $current );
}
/**
* Get count
*
* @param bool $allRows If TRUE, will get the number of rows ignoring the limit. In order for this to work, the query must have been ran with SQL_CALC_FOUND_ROWS
* @return int
*/
public function count( $allRows = FALSE )
public function count()
{
return (int) $this->getInnerIterator()->count( $allRows );
return (int) $this->getInnerIterator()->count();
}
}