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

The AMI_ModTableItem class

• Introduction

Module table item model.

• Class synopsis

AMI_ModTableItem implements AMI_iModTableItem, Iterator (internal interface), AMI_iFormModTableItem {
/* Properties */
// Element data
protected array $aData = array();
// Fields to load
protected array $aFields = array();
// Tainted fields list
protected array $aOrigFields = array('public' => false, 'cat_id' => false);
// Fields storing serialized data
protected array $aSerializedFields = array();
// Iterator pointer
protected int $dataIndex = -1;
// Element id value
protected int|string $id;
// Default value for empty element id
protected int|string $idEmpty = 0;
// DB query object
protected DB_Query $oQuery;
// Module table model
protected AMI_ModTable $oTable;
// Primary column field name
protected string $primaryKeyField = 'id';
/* Methods */
// Constructor.
public __construct ( AMI_ModTable $oTable, [ $oQuery = null ] ) returns AMI_ModTableItem;
// Destructor.
public __destruct ( ) returns void;
// Adds fields to load.
public addFields ( [ $aFields = array('*') ], [ bool $reset = false ] ) returns AMI_ModTableItem;
// Returns aData setuped on loading.
public addSearchCondition ( $aCondition ) returns array;
// Returns the current element.
public current ( ) returns mixed;
// Deletes item from table and clear data array.
public delete ( [ mixed $id = null ] ) returns AMI_ModTableItem;
// Returns data array.
public getData ( ) returns array;
// Returns difference from origin data.
public getDiffFromOrigin ( ) returns array;
// Returns item empty primary key value.
public getEmptyId ( ) returns mixed;
// Generates item module front link.
public getFrontLink ( ) returns string;
// Generates item full front URL.
public getFullURL ( ) returns string;
// Returns current item primary key value.
public getId ( ) returns mixed;
// Returns module id.
public getModId ( ) returns string;
// Returns link for current module & specific lang& pageID.
public getModLink ( [ string $locale = 'en' ], [ int $pageId = 0 ] ) returns string|false;
// Returns origin data.
public getOriginData ( ) returns array;
// Returns origin fields as array having keys as field names and values as hashing flag.
public getOriginFields ( ) returns array;
// Returns primary key field name.
public getPrimaryKeyField ( ) returns string;
// Returns table object.
public getTable ( ) returns AMI_ModTable;
// Generates item front URL.
public getURL ( ) returns string;
// Returns validator exception object validator after save or null.
// Returns field value from data array.
public getValue ( string $name ) returns mixed;
// Checks if the field has a specified callback.
public hasFieldCallback ( string $field, callback $callback ) returns bool;
// Returns the key of the current element.
public key ( ) returns mixed;
// Loads data by specified condition or sets new item data.
public load ( ) returns AMI_ModTableItem;
// Move forward to next element.
public next ( ) returns void;
// Resets primary key.
public resetId ( ) returns AMI_ModTableItem;
// Rewinds the Iterator to the first element.
public rewind ( ) returns void;
// Saves current item data.
public save ( ) returns AMI_ModTableItem;
// Sets field callback on AMI_ModTableItem::__get() and AMI_ModTableItem::__set().
public setFieldCallback ( string $field, callback $callback ) returns AMI_ModTableItem;
// Sets origin fields.
public setOriginFields ( $aFields, [ bool $bAsHash = false ], [ bool $bAppend = true ] ) returns AMI_ModTableItem;
// Sets model values from array.
public setValues ( $aData ) returns AMI_ModTableItem;
// Checks if current position is valid.
public valid ( ) returns bool;
// Property access getter.
public __get ( string $name ) returns mixed;
// Property access getter.
public __isset ( string $name ) returns bool;
// Property access setter.
public __set ( string $name, string $value ) returns void;
// Property access setter.
public __unset ( string $name ) returns void;
// Serialized field callback.
protected fcbSerialized ( $aData ) returns array;
// Returns table item modifier object.
protected getModifier ( ) returns AMI_ModTableItemModifier;
}
Tags:
abstract
since 5.10.0

• Class Properies

protected array $aData

Element data

protected array $aFields

Fields to load

protected array $aOrigFields

Tainted fields list

protected array $aSerializedFields

Fields storing serialized data

protected int $dataIndex

Iterator pointer

protected int|string $id

Element id value

protected int|string $idEmpty

Default value for empty element id

protected DB_Query $oQuery

DB query object

protected AMI_ModTable $oTable

Module table model

protected string $primaryKeyField

Primary column field name

• Class Methods

// Destructor.
public __destruct ( ) returns void;
Tags:
see self::cleanupExtensions()
since 6.0.2
// Adds fields to load.
public addFields ( [ $aFields = array('*') ], [ bool $reset = false ] ) returns AMI_ModTableItem;
  • array $aFields
    Fields to load
  • bool $reset
    Reset previous field list
  Example:
  •  $modId 'articles';
  •  $oTable AMI::getResourceModel($modId '/table');
  •  
  •  // Load all model fields, try to avoid loading all parameters when it isn't necessary
  •  $oItem $oTable->find(1array('*'));
  •  
  •  // Load only 'id', 'header' fields
  •  $oItem $oTable->find(1array('id''header'));
Tags:
see AMI_ModTable::find()
since 5.12.8
// Returns aData setuped on loading.
public addSearchCondition ( $aCondition ) returns array;
// Returns the current element.
public current ( ) returns mixed;

Implementation of: Iterator::current.

Iterator interface implementation.
// Deletes item from table and clear data array.
public delete ( [ mixed $id = null ] ) returns AMI_ModTableItem;
  • mixed $id
    Primary key value of item

Overridden in child classes as: Pages_TableItem::delete().

Facade method for AMI_ModTableItemModifier::delete().

  Example:
  •  $oTable AMI::getResourceModel('ami_sample/table');
  •  $oItem $oTable->getItem();
  •  // Delete item by primary key field
  •  $oItem->delete(1);
  •  
  •  // Load and delete item
  •  $oItem $oTable->find(2);
  •  $oModelItem->delete();
Tags:
since 5.12.0
// Returns data array.
public getData ( ) returns array;

Implementation of: AMI_iModTableItem::getData().

// Returns difference from origin data.
public getDiffFromOrigin ( ) returns array;
  Example:
  •  // AmiSample_FormAdm::_save()
  •  // ...
  •  if(is_object($this->oModelItem)){
  •      AMI::getSingleton('response')
  •          ->addStatusMessage(
  •              'difference_from_origin',
  •              array('data' => d::getDumpAsString($this->oModelItem->getDiffFromOrigin()))
  •          );
  •  }
// Returns item empty primary key value.
public getEmptyId ( ) returns mixed;
Tags:
since 5.12.4
// Generates item full front URL.
public getFullURL ( ) returns string;
// Returns current item primary key value.
public getId ( ) returns mixed;

Implementation of: AMI_iFormModTableItem::getId().

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

Implementation of: AMI_iModTableItem::getModId().

  • string $locale
    Locale
  • int $pageId
    Page id (used for multipage modules)
// Returns origin data.
public getOriginData ( ) returns array;
  Example:
  •  // AmiSample_FormAdm::_save()
  •  // ...
  •  if(is_object($this->oModelItem)){
  •      AMI::getSingleton('response')
  •          ->addStatusMessage(
  •              'origin_data',
  •              array('data' => d::getDumpAsString($this->oModelItem->getOriginData()))
  •          );
  •  }
// Returns origin fields as array having keys as field names and values as hashing flag.
public getOriginFields ( ) returns array;
// Returns primary key field name.
public getPrimaryKeyField ( ) returns string;
// Returns table object.
public getTable ( ) returns AMI_ModTable;
// Generates item front URL.
public getURL ( ) returns string;
// Returns validator exception object validator after save or null.

Implementation of: AMI_iFormModTableItem::getValidatorException().

Facade method for AMI_ModTableItemModifier::getValidatorException()
// Returns field value from data array.
public getValue ( string $name ) returns mixed;
  • string $name
    Field name

Implementation of: AMI_iFormModTableItem::getValue().

// Checks if the field has a specified callback.
public hasFieldCallback ( string $field, callback $callback ) returns bool;
  • string $field
    Field name
  • callback $callback
    Formatter callback

Implementation of: AMI_iModTableItem::hasFieldCallback().

Tags:
since 5.14.4
// Returns the key of the current element.
public key ( ) returns mixed;

Implementation of: Iterator::key.

Iterator interface implementation.
// Loads data by specified condition or sets new item data.
public load ( ) returns AMI_ModTableItem;
// Move forward to next element.
public next ( ) returns void;

Implementation of: Iterator::next.

Iterator interface implementation.
// Resets primary key.
public resetId ( ) returns AMI_ModTableItem;
Tags:
since 5.12.4
// Rewinds the Iterator to the first element.
public rewind ( ) returns void;

Implementation of: Iterator::rewind.

Iterator interface implementation.
// Saves current item data.
public save ( ) returns AMI_ModTableItem;
// Sets field callback on AMI_ModTableItem::__get() and AMI_ModTableItem::__set().
public setFieldCallback ( string $field, callback $callback ) returns AMI_ModTableItem;
  • string $field
    Field name
  • callback $callback
    Formatter callback

Implementation of: AMI_iModTableItem::setFieldCallback().

Used for computational/virtual fields or to convert field value from/to internal/external format.

  Example:
  •  class DemoModule_TableItem extends AMI_ModTableItem{
  •      public function __construct(AMI_ModTable $oTableDB_Query $oQuery null){
  •          parent::__construct($oTable$oQuery);
  •          // Add own field callback for virtual field (no db field)
  •          $this->setFieldCallback('virtual_field'array($this'fcbVirtualField'));
  •      }
  •  
  •      // $aData has following structure:
  •      //     'modId'     - module id
  •      //     'name'      - field name
  •      //     'action'    - 'get'/'set'/'save'/'after_save'
  •      //     'value'     - field value passed by reference
  •      //     'oItem'     - AMI_ModTableItem object
  •      // To skip storing virtual field callback can set following flag:
  •      // $aData['_skip'] = true;
  •      protected function fcbVirtualField(array $aData){
  •          $action $aData['action'];
  •          switch($action){
  •              case 'get':
  •                  // For example always return 1
  •                  $aData['value'1;
  •                  break;
  •              case 'set':
  •                  // Increment some counter
  •                  $aData['oItem']->counter++;
  •                  $aData['_skip'true;
  •                  break;
  •  
  •          return $aData;
  •      }
  •  
  •      // Notice that field callback is called if this field is present in form or you could override AMI_ModTableItem::save() next way:
  •      public function save(){
  •          $this->virtual_field = ...;
  •          return parent::save();
  •      }
  •  }
// Sets origin fields.
public setOriginFields ( $aFields, [ bool $bAsHash = false ], [ bool $bAppend = true ] ) returns AMI_ModTableItem;
  • array $aFields
    Fields
  • bool $bAsHash
    Store hash instead of value
  • bool $bAppend
    Append to existing fields
  Example:
  •  // AmiSample_TableItem::__construct()
  •  // ...
  •  $this->setOriginFields(array('nickname'));
// Sets model values from array.
public setValues ( $aData ) returns AMI_ModTableItem;
  • array $aData
    Data array
  Example:
  •  $oModelItem AMI::getResourceModel('ami_sample/table')->getItem();
  •  $oModelItem->setValues(
  •      array(
  •          'nickname' => 'Nickname',
  •          'birth'    => '1.1.2011'
  •      )
  •  );
  •  try{
  •      $oModelItem->save();
  •  }catch(AMI_ModTableItemException $oException){
  •      d::vd($oException->getData());
  •  }
Tags:
see AMI_ModTableItem::__set()
since 5.12.0
// Checks if current position is valid.
public valid ( ) returns bool;

Implementation of: Iterator::valid.

Iterator interface implementation.
// Property access getter.
public __get ( string $name ) returns mixed;
  • string $name
    Property name
Returns value from data array.
// Property access getter.
public __isset ( string $name ) returns bool;
  • string $name
    Property name
Check if key is exists in data array.
// Property access setter.
public __set ( string $name, string $value ) returns void;
  • string $name
    Property name
  • string $value
    Property value
Sets value to data array.
// Property access setter.
public __unset ( string $name ) returns void;
  • string $name
    Property name
Unsets value in data array by key.
// Serialized field callback.
protected fcbSerialized ( $aData ) returns array;
  • array $aData
    Formatter data
Tags:
since 6.0.6
// Returns table item modifier object.
protected getModifier ( ) returns AMI_ModTableItemModifier;