Amiro.CMS API Reference
Amiro.Ru / Manual
Loading search...

The AMI_ModTableList class

• Introduction

Module table list model.

• Class synopsis

AMI_ModTableList implements AMI_iModTableList, Countable (internal interface), SeekableIterator (internal interface) {
/* Properties */
// Recordset columns
protected array $aColumns = array();
// Expression columns struct
protected array $aExpressionColumns = array();
// Do calculate found rows
protected bool $bCalcFoundRows = false;
// Number of found rows (works only when bCalcFoundRows is true).
protected int $numberOfFoundRows = 0;
// DB_Query object
protected DB_Query $oQuery;
// DB recordset
protected DB_iRecordset $oRS;
// AMI_ModTable object
protected AMI_ModTable $oTable;
/* Methods */
// Initializing table list data.
public __construct ( AMI_ModTable $oTable, $oQuery ) returns AMI_ModTableList;
// Destructor.
public __destruct ( ) returns void;
// Set the SQL_CALC_FOUND_ROWS selection flag.
public addCalcFoundRows ( [ bool $bState = true ] ) returns this;
// Repairs item position.
public addColumn ( mixed $name, [ mixed $model = '' ] ) returns AMI_ModTableList;
// Adds several columns at time for list selection.
public addColumns ( $aColumns, [ string $model = '' ] ) returns AMI_ModTableList;
// Adds expression column to list selection.
public addExpressionColumn ( string $name, DB_Snippet|string $expression, [ string $model = '' ] ) returns AMI_ModTableList;
// Adds expression to selection.
public addExpressionField ( DB_Snippet|string $expression ) returns AMI_ModTableList;
// Adds grouping.
public addGrouping ( DB_Snippet|string $expression ) returns AMI_ModTableList;
// Adds having definition.
public addHavingDef ( DB_Snippet|string $expression ) returns AMI_ModTableList;
// Adds navigation columns.
public addNavColumns ( ) returns AMI_ModTableList;
// Adds order.
public addOrder ( string $field, [ string $direction = '' ] ) returns AMI_ModTableList;
// Adds item search condition.
public addSearchCondition ( $aCondition ) returns AMI_ModTableItem;
// Adds columns to SELECT from table in DB_Query.
public addSelectedFields ( $oQuery, [ string $prefix = '' ] ) returns void;
// Adds where definition.
public addWhereDef ( DB_Snippet|string $expression ) returns AMI_ModTableList;
// Counts elements of an object.
public count ( ) returns int;
// Returns the current element.
public current ( ) returns AMI_ModTableItem;
// Deletes column from list selection.
public dropColumn ( string $name, [ string $model = '' ] ) returns AMI_ModTableList;
// Exludes fields not from available list.
public filterFields ( $aFields, [ string $modelAlias = '' ] ) returns array;
// Returns array of available fields.
public getAvailableFields ( [ bool $bAppendEventFields = true ] ) returns array;
// Returns field name with its alias or expression.
public getColumn ( string $column, [ string $alias = '' ], [ bool $bAppendEventFields = TRUE ] ) returns bool;
// Returns real field name by its alias.
public getFieldName ( string $alias ) returns string;
// Make the query and return recordset for selected fields.
public getListRecordset ( ) returns DB_iRecordset;
// Returns main table alias.
public getMainTableAlias ( [ bool $bAsPrefix = false ] ) returns string;
// Get the number of found rows when bCalcFoundRows is true.
// Gets position of the applied element.
public getPosition ( string $fieldName, integer $appliedValue, integer $position ) returns integer;
// Returns table object.
public getTable ( ) returns AMI_ModTable;
// Returns TRUE if list model has passed column (including expression columns).
public hasColumn ( string $column, [ string $alias = '' ], [ bool $bAppendEventFields = TRUE ] ) returns bool;
// Returns the key of the current element.
public key ( ) returns mixed;
// Called before recordset initialization. Allows to add additional list query parameters.
public load ( ) returns void;
// Move forward to next element.
public next ( ) returns void;
// Forces list to collect page sublinks after all data loaded.
public requestModLinks ( ) returns AMI_ModTableList;
// Rewinds the Iterator to the first element.
public rewind ( ) returns void;
// Seeks to a position.
public seek ( int $position ) returns bool;
// Sets having definition.
public setHavingDef ( DB_Snippet|string $expression ) returns AMI_ModTableList;
// Specifies to autoexlude or not invalid columns during AMI_ModTableList::addColumns().
public setInvalidColumnExclusion ( bool $bExclude ) returns AMI_ModTableList;
// Sets a dependent model and loads its data to a new column $fieldAlias after the list data was loaded.
public setLateDataBinding ( string $modelField, string $fieldAlias, string $bindedModel, string $bindedField, [ $oWhereDefSnippet = null ], [ string $bindedKey = null ], [ string $default = null ], [ $bindEnumerating = array() ] ) returns AMI_ModTableList;
// Sets limit parameters.
public setLimitParameters ( int $start, int $limit ) returns AMI_ModTableList;
// Sets where definition.
public setWhereDef ( DB_Snippet|string $expression ) returns AMI_ModTableList;
// Checks if current position is valid.
public valid ( ) returns bool;
// Returns module id.
protected getModId ( ) returns string;
}
Tags:
abstract
since 5.10.0

• Class Properies

protected array $aColumns

Recordset columns

protected array $aExpressionColumns

Expression columns struct

protected bool $bCalcFoundRows

Do calculate found rows

protected int $numberOfFoundRows

Number of found rows (works only when bCalcFoundRows is true).

protected DB_Query $oQuery

DB_Query object

protected DB_iRecordset $oRS

DB recordset

protected AMI_ModTable $oTable

AMI_ModTable object

• Class Methods

// Initializing table list data.
public __construct ( AMI_ModTable $oTable, $oQuery ) returns AMI_ModTableList;
  • AMI_ModTable $oTable
    Table model
  • DB_Query $oQuery
    DB_Query object, required for load or save operations
// Destructor.
public __destruct ( ) returns void;
Tags:
see self::cleanupExtensions()
since 6.0.2
// Set the SQL_CALC_FOUND_ROWS selection flag.
public addCalcFoundRows ( [ bool $bState = true ] ) returns this;
  • bool $bState
    Flag
// Repairs item position.
public addColumn ( mixed $name, [ mixed $model = '' ] ) returns AMI_ModTableList;
Tags:
todo Implement
amidev temporary
// Adds several columns at time for list selection.
public addColumns ( $aColumns, [ string $model = '' ] ) returns AMI_ModTableList;
  • array $aColumns
    Array of column field names, may be in format AMI_ModTable::getAvailableFields()
  • string $model
    Dependent model alias

Implementation of: AMI_iModTableList::addColumns().

// Adds expression column to list selection.
public addExpressionColumn ( string $name, DB_Snippet|string $expression, [ string $model = '' ] ) returns AMI_ModTableList;
  • string $name
    Column field name
  • DB_Snippet|string $expression
    Expression
  • string $model
    Dependent model alias
  Example:
  •  // ...
  •  class DemoModule_TableList extends AMI_ModTableList{
  •      public function __construct(AMI_ModTable $oTableDB_Query $oQuery){
  •          parent::__construct($oTable$oQuery);
  •          $this->addExpressionColumn('id2''(id * 2)');
  •      }
  •  }
  •  // ...
  •  $modId 'demo_module';
  •  $oTable AMI::getResourceModel($modId '/table');
  •  $oList $oTable->getList()->addColumn('id2')->load();
  •  foreach($oList as $oItem){
  •      AMI::getSingleton('response')->write($oItem->id ' ' $oItem->id2 '<br />');
  •  }
Tags:
since 5.14.0
// Adds expression to selection.
public addExpressionField ( DB_Snippet|string $expression ) returns AMI_ModTableList;
Tags:
see AMI_ModTableList::addExpressionColumn()
deprecated Sinse 5.14.0, use AMI_ModTableList::addExpressionColumn() instead.
// Adds grouping.
public addGrouping ( DB_Snippet|string $expression ) returns AMI_ModTableList;
// Adds having definition.
public addHavingDef ( DB_Snippet|string $expression ) returns AMI_ModTableList;
// Adds navigation columns.
public addNavColumns ( ) returns AMI_ModTableList;
Tags:
see AMI_ModTable::getNavFields()
see AMI_ModTableList::addColumns()
// Adds order.
public addOrder ( string $field, [ string $direction = '' ] ) returns AMI_ModTableList;
  • string $field
    Field name
  • string $direction
    Order

Implementation of: AMI_iModTableList::addOrder().

Use 'rand()' for random sorting, field from result of AMI_ModTableList::getAvailableFields() or field from dependent table model in format "{$alias}.{$field}".
Tags:
todo Order replacement functionality for expression columns
todo Example
// Adds item search condition.
public addSearchCondition ( $aCondition ) returns AMI_ModTableItem;
  • array $aCondition
    Item search condition - array(field => value)
  Example:
  •  // Load not published news items list
  •  $oModelItem =
  •      AMI::getResourceModel('news/table')->getList()
  •          ->addColumns(array('id''header''announce'))
  •          ->addSearchCondition(
  •              array(
  •                  'public' => 0
  •              )
  •          )
  •          ->load();
Tags:
see AMI_ModTableList::addWhereDef()
since 6.0.2
// Adds columns to SELECT from table in DB_Query.
public addSelectedFields ( $oQuery, [ string $prefix = '' ] ) returns void;
  • DB_Query $oQuery
    Query
  • string $prefix
    Prefix for every field
// Adds where definition.
public addWhereDef ( DB_Snippet|string $expression ) returns AMI_ModTableList;
// Counts elements of an object.
public count ( ) returns int;

Implementation of: Countable::count.

Countable::count() implementation.
// Returns the current element.
public current ( ) returns AMI_ModTableItem;

Implementation of: SeekableIterator::current.

Iterator interface implementation.
// Deletes column from list selection.
public dropColumn ( string $name, [ string $model = '' ] ) returns AMI_ModTableList;
  • string $name
    Column field name
  • string $model
    Dependent model alias
Tags:
since 5.14.4
// Exludes fields not from available list.
public filterFields ( $aFields, [ string $modelAlias = '' ] ) returns array;
  • array $aFields
    Fields
  • string $modelAlias
    Model alias

Implementation of: AMI_iModTableList::filterFields().

Tags:
since 5.12.0
// Returns array of available fields.
public getAvailableFields ( [ bool $bAppendEventFields = true ] ) returns array;
  • bool $bAppendEventFields
    Fire 'on_get_available_fields' event to append extension fields
// Returns field name with its alias or expression.
public getColumn ( string $column, [ string $alias = '' ], [ bool $bAppendEventFields = TRUE ] ) returns bool;
  • string $column
    Column name
  • string $alias
    Model alias
  • bool $bAppendEventFields
    See AMI_ModTable::getAvailableFields()
Tags:
see AMI_ModTable::addExpressionColumn()
see AMI_ModTable::getAvailableFields()
since 5.14.0
// Returns real field name by its alias.
public getFieldName ( string $alias ) returns string;
  • string $alias
    Alias
Tags:
see AMI_ModTable::getFieldName()
deprecated After db field names standardization this method will became useless.
// Make the query and return recordset for selected fields.
public getListRecordset ( ) returns DB_iRecordset;
// Returns main table alias.
public getMainTableAlias ( [ bool $bAsPrefix = false ] ) returns string;
  • bool $bAsPrefix
    Append '.' if true
// Get the number of found rows when bCalcFoundRows is true.
// Gets position of the applied element.
public getPosition ( string $fieldName, integer $appliedValue, integer $position ) returns integer;
  • string $fieldName
    Field name to search in
  • integer $appliedValue
    Field value of the applied element
  • integer $position
    Initial position

Implementation of: AMI_iModTableList::getPosition().

// Returns table object.
public getTable ( ) returns AMI_ModTable;
Tags:
since 5.14.8
// Returns TRUE if list model has passed column (including expression columns).
public hasColumn ( string $column, [ string $alias = '' ], [ bool $bAppendEventFields = TRUE ] ) returns bool;
  • string $column
    Column name
  • string $alias
    Model alias
  • bool $bAppendEventFields
    See AMI_ModTable::getAvailableFields()
Tags:
see AMI_ModTable::getAvailableFields()
since 5.14.0
// Returns the key of the current element.
public key ( ) returns mixed;

Implementation of: SeekableIterator::key.

Iterator interface implementation.
// Called before recordset initialization. Allows to add additional list query parameters.
public load ( ) returns void;

Implementation of: AMI_iModTableList::load().

// Move forward to next element.
public next ( ) returns void;

Implementation of: SeekableIterator::next.

Iterator interface implementation.
  Example:
  •  $oList AMI::getResourceModel('news/table')
  •       ->addColumns(array('id','id_page'))
  •       ->requestModLinks()
  •       ->load();
  •  foreach($oList as $oItem){
  •       // getFrontLink will use data from the list queries
  •       d::vd($oItem->getFrontLink());
  •  }
Tags:
since 5.12.8
// Rewinds the Iterator to the first element.
public rewind ( ) returns void;

Implementation of: SeekableIterator::rewind.

Iterator interface implementation.
// Seeks to a position.
public seek ( int $position ) returns bool;
  • int $position
    The position to seek to

Implementation of: SeekableIterator::seek.

SeekableIterator::seek() implementation.
// Sets having definition.
public setHavingDef ( DB_Snippet|string $expression ) returns AMI_ModTableList;
// Specifies to autoexlude or not invalid columns during AMI_ModTableList::addColumns().
public setInvalidColumnExclusion ( bool $bExclude ) returns AMI_ModTableList;
  • bool $bExclude
    Autoexlude flag
Tags:
since 5.12.0
// Sets a dependent model and loads its data to a new column $fieldAlias after the list data was loaded.
public setLateDataBinding ( string $modelField, string $fieldAlias, string $bindedModel, string $bindedField, [ $oWhereDefSnippet = null ], [ string $bindedKey = null ], [ string $default = null ], [ $bindEnumerating = array() ] ) returns AMI_ModTableList;
  • string $modelField
    Current model's field name with id's from binded model
  • string $fieldAlias
    Field name to contain data from binded model
  • string $bindedModel
    Binded model name e.g. 'users', 'pages', etc.
  • string $bindedField
    Field of the binded model to get data from
  • DB_Snippet $oWhereDefSnippet
    Additional addWhereDef snipet [optional]
  • string $bindedKey
    Field name of the binded model to be used as a foreign key
  • string $default
    Default value, will be returned if no corresponding row found in binded model
  • array $bindEnumerating
    Bind IDs enumerating
  Example:
  •  class MyModule_TableList extends AMI_ModTableList{
  •      // Binds table users with "id=id_user" condition.
  •      // Fills "user_name" column with the values of the "firstname" column.
  •      public function __construct(AMI_ModTable $oTableDB_Query $oQuery){
  •          parent::__construct($oTable$oQuery);
  •          $this->setLateDataBinding('id_user''user_name''users''firstname');
  •      }
  •  }
Tags:
since 5.12.8
// Sets limit parameters.
public setLimitParameters ( int $start, int $limit ) returns AMI_ModTableList;
  • int $start
    Start
  • int $limit
    Limit
// Sets where definition.
public setWhereDef ( DB_Snippet|string $expression ) returns AMI_ModTableList;
// Checks if current position is valid.
public valid ( ) returns bool;

Implementation of: SeekableIterator::valid.

Iterator interface implementation.
// Returns module id.
protected getModId ( ) returns string;