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

The AMI_ArrayIterator class

• Introduction

Module array iterator model.

• Class synopsis

AMI_ArrayIterator implements AMI_iModTable {
/* Properties */
// Initial data array
protected array $aData = array();
// Array of fields
protected array $aFields = array();
/* Methods */
// Initializing array iterator data.
public __construct ( [ $aData = array() ] ) returns AMI_ArrayIterator;
// Returns item model object and load data for primary key field param.
public find ( mixed $id, [ $aFields = array() ] ) returns AMI_ArrayIteratorItem;
// Returns item model object and load data for non-primary key field.
public findByFields ( $aSearchCondition, [ $aFields = array() ] ) returns AMI_ArrayIteratorItem;
// Returns the array of available fields.
public getAvailableFields ( [ bool $bAppendEventFields = null ] ) returns array;
// Returns initial data array.
public getData ( ) returns array;
// Necessary for AMI_ModTableList compatibility.
public getFieldName ( string $alias, [ string $prefix = '' ] ) returns null;
// Called when receive array of validators, allow add own validators.
public getItem ( [ mixed $type = '' ] ) returns void;
// Returns list model object.
public getList ( [ string $type = null ] ) returns AMI_ArrayIteratorList;
// Returns array of row fields.
public getTableFieldsData ( ) returns array;
// Checks if model has a field.
public hasField ( string $name, [ bool $bAppendEventFields = null ] ) returns bool;
// Set module id.
public setModId ( mixed $id ) returns void;
// Returns module id.
protected getModId ( ) returns string;
}

• Class Details

Usage example:
  •  require 'ami_env.php';
  •  
  •  $oResponse AMI::getSingleton('response');
  •  $oResponse->start();
  •  
  •  $modId 'my_module';
  •  
  •  // Make abstract classes children
  •  class MyModule_Table extends AMI_ArrayIterator{}
  •  class MyModule_TableItem extends AMI_ArrayIteratorItem{}
  •  class MyModule_TableList extends AMI_ArrayIteratorList{}
  •  
  •  // Add resource mapping
  •  $aResources array(
  •      $modId '/table/model'      => 'MyModule_Table',
  •      $modId '/table/model/item' => 'MyModule_TableItem',
  •      $modId '/table/model/list' => 'MyModule_TableList'
  •  );
  •  AMI::addResourceMapping($aResources);
  •  
  •  // Raw list data
  •  $aList array(
  •      // First row
  •      array('id' => 1'col1' => 'val11''col2' => 'val21''col3' => 'val31'),
  •      // Second row
  •      array('id' => 2'col1' => 'val12''col2' => 'val22''col3' => 'val32'),
  •      // same as row id =              1                  2                  -
  •      array('id' => 3'col1' => 'val11''col2' => 'val22''col3' => 'val33'),
  •      // ...
  •  );
  •  
  •  // Iterator object passing raw list data
  •  $oIterator AMI::getResourceModel($modId '/table'array($aList));
  •  
  •  // Object loaded from row having id = 2
  •  $oItem $oIterator->find(2);
  •  $oResponse->write("<p>Item data having 'id' = 2</p>");
  •  $oResponse->write('<pre>' d::getDumpAsString($oItem->getData()) '</pre>');
  •  
  •  $oItem $oIterator->findByFields(array('col2' => 'val21'));
  •  $oResponse->write("<p>Item data having 'col2' = 'val21'</p>");
  •  $oResponse->write('<pre>' d::getDumpAsString($oItem->getData()) '</pre>');
  •  
  •  $oResponse->write("<p>Searching by column 'col1' = 'val11'</p>");
  •  $oList $oIterator->getList()->addSearchCondition(array('col1' => 'val11'))->load();
  •  foreach($oList as $oItem){
  •      $oResponse->write('<pre>' d::getDumpAsString($oItem->getData()) '</pre>');
  •  }
  •  
  •  $oResponse->send();
Tags:
abstract
since 5.14.8

• Class Properies

protected array $aData

Initial data array

protected array $aFields

Array of fields

• Class Methods

// Initializing array iterator data.
public __construct ( [ $aData = array() ] ) returns AMI_ArrayIterator;
  • array $aData
    Initial data
// Returns item model object and load data for primary key field param.
public find ( mixed $id, [ $aFields = array() ] ) returns AMI_ArrayIteratorItem;
  • mixed $id
    Primary key value
  • array $aFields
    Fields to load

Implementation of: AMI_iModTable::find().

Tags:
see AMI_ArrayIteratorItem::addFields() for $aFields parameter explanation
// Returns item model object and load data for non-primary key field.
public findByFields ( $aSearchCondition, [ $aFields = array() ] ) returns AMI_ArrayIteratorItem;
  • array $aSearchCondition
    Filter array key => value
  • array $aFields
    Fields to load

Implementation of: AMI_iModTable::findByFields().

Tags:
see AMI_ArrayIteratorItem::addFields() for $aFields parameter explanation
// Returns the array of available fields.
public getAvailableFields ( [ bool $bAppendEventFields = null ] ) returns array;
  • bool $bAppendEventFields
    Null

Implementation of: AMI_iModTable::getAvailableFields().

Dependent model fields returns model alias as index and array of its fields as value.
// Returns initial data array.
public getData ( ) returns array;
// Necessary for AMI_ModTableList compatibility.
public getFieldName ( string $alias, [ string $prefix = '' ] ) returns null;
  • string $alias
    Alias
  • string $prefix
    Prefix
// Called when receive array of validators, allow add own validators.
public getItem ( [ mixed $type = '' ] ) returns void;

Implementation of: AMI_iModTable::getItem().

// Returns list model object.
public getList ( [ string $type = null ] ) returns AMI_ArrayIteratorList;
  • string $type
    Not implemented here

Implementation of: AMI_iModTable::getList().

Tags:
todo Implement or avoid $type argoment
// Returns array of row fields.
public getTableFieldsData ( ) returns array;
// Checks if model has a field.
public hasField ( string $name, [ bool $bAppendEventFields = null ] ) returns bool;
  • string $name
    Field name in array
  • bool $bAppendEventFields
    Null

Implementation of: AMI_iModTable::hasField().

See PlgAJAXResp::initModel() for usage example.
// Set module id.
public setModId ( mixed $id ) returns void;
  • mixed $id
    Module Id.

Implementation of: AMI_iModTable::setModId().

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

Overridden in child classes as: AMI_ModSpecblock_ArrayIterator::getModId().