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

The AMI_ModTableItemModifier class

• Introduction

Module table item model modifier.

• Class synopsis

AMI_ModTableItemModifier {
/* Properties */
// Module table model
protected AMI_ModTable $oTable;
// Module table item model
// Validator exception on item saving
/* Methods */
// Constructor.
public __construct ( AMI_ModTable $oTable, AMI_ModTableItem $oTableItem ) returns AMI_ModTableItemModifier;
// Deletes item from table.
public delete ( [ mixed $id = null ] ) returns bool;
// Returns default fields and its values on save.
public getDefaultsOnSave ( bool $onCreate ) returns array;
// Returns validator exception object validator after save or null.
// Calls when validation failed.
public rollback ( $aData, bool $onCreate ) returns void;
// Allows change data model before create / update item.
public save ( ) returns void;
// Validates item data.
public validate ( $aData, bool $onCreate ) returns AMI_ModTableItemModifier;
}

• Class Details

Class containing model modification functionality.
  Example:
Tags:
abstract
since 5.12.4

• Class Properies

protected AMI_ModTable $oTable

Module table model

protected AMI_ModTableItem $oTableItem

Module table item model

protected AMI_ModTableItemException|null $oValidatorException

Validator exception on item saving

• Class Methods

// Constructor.
public __construct ( AMI_ModTable $oTable, AMI_ModTableItem $oTableItem ) returns AMI_ModTableItemModifier;
// Deletes item from table.
public delete ( [ mixed $id = null ] ) returns bool;
  • mixed $id
    Primary key value of item

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

// Returns default fields and its values on save.
public getDefaultsOnSave ( bool $onCreate ) returns array;
  • bool $onCreate
    True on item create, false on update

Overridden in child classes as: Hyper_AmiFiles_TableItemModifier::getDefaultsOnSave().

Result is an array having two keys: 'append' and 'overwrite'.
Let your model have datetime field 'ts' and you need to set it to the current date/time on every INSERT/UPDATE query.

  Example:
  •      // ...
  •      public function getDefaultsOnSave($onCreate){
  •          $aDefaults parent::getDefaultsOnSave($onCreate);
  •          $aDefaults['append']['ts'DB_Query::getSnippet('%s')->plain('NOW()');
  •          $aDefaults['overwrite']['ts'DB_Query::getSnippet('%s')->plain('NOW()');
  •          return $aDefaults;
  •      }
  •      // ...
  •  }
Tags:
see AMI_ModTableItem::save()
todo Expect default item locale (`lang`)
// Returns validator exception object validator after save or null.
// Calls when validation failed.
public rollback ( $aData, bool $onCreate ) returns void;
  • array $aData
    Item data
  • bool $onCreate
    True on item create, false on update
  Example:
  •  // PrivateMessages_TableItemModifier::rollback() deletes dependent body model created before validation
  •  protected function rollback(array $aData$onCreate){
  •      parent::rollback($aData$onCreate);
  •      if($onCreate && $aData['id_body']){
  •          AMI::getResourceModel('private_message_bodies/table')->getItem()->delete($aData['id_body']);
  •      }
  •  }
Tags:
since 5.12.8
// Allows change data model before create / update item.
public save ( ) returns void;

Overridden in child classes as: AMI_CatModule_TableItemModifier::save().

// Validates item data.
public validate ( $aData, bool $onCreate ) returns AMI_ModTableItemModifier;
  • array $aData
    Item data
  • bool $onCreate
    True on item create, false on update
Tags:
todo Decide reaction for snippets
throws AMI_ModTableItemException If validation failed.