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

Source for file AmiSample_Table.php

Documentation is available at AmiSample_Table.php

  • <?php
  • /**
  •  * @copyright  Amiro.CMS. All rights reserved. The changes are undesirable and dangerous.
  •  * @category   AMI
  •  * @package    Module_Sample
  •  * @since      5.12.0
  •  * @filesource
  •  * @version    $Id: AmiSample_Table.php 61273 2013-08-07 10:47:54Z Leontiev Anton $
  •  */
  •  
  • /**
  •  * Sample module table model.
  •  *
  •  * See {@link AMI_ModTable::getAvailableFields()} for common fields description.
  •  *
  •  * @package    Module_Sample
  •  * @subpackage Model
  •  * @resource   ami_sample/table/model <code>AMI::getResourceModel('ami_sample/table')</code>
  •  * @since      5.12.0
  •  */
  • class AmiSample_Table extends AMI_ModTable{
  •     /**
  •      * Database table name
  •      *
  •      * @var string 
  •      */
  •     protected $tableName = 'ami_sample_plugin';
  • }
  •  
  • /**
  •  * Sample module table item model.
  •  *
  •  * @package    Module_Sample
  •  * @subpackage Model
  •  * @resource   ami_sample/table/model/item <code>AMI::getResourceModel('ami_sample/table')->getItem()</code>
  •  * @since      5.12.0
  •  */
  •     /**
  •      * Initializing table item data.
  •      *
  •      * @param AMI_ModTable $oTable  Module table model
  •      * @param DB_Query     $oQuery  Required for load or save operations
  •      */
  •     public function __construct(AMI_ModTable $oTableDB_Query $oQuery null){
  •         parent::__construct($oTable$oQuery);
  •  
  •         // Add field validators
  •         $this->oTable->addValidators(
  •             array(
  •                 'nickname' => array('filled'),
  •                 'birth'    => array('filled'),
  •                 'email'    => array('required''email')
  •             )
  •         );
  •  
  •         // Add virtual field callback
  •         $this->setFieldCallback('age'array($this'fcbAge'));
  •  
  •         // Append origin field
  •         $this->setOriginFields(array('nickname'));
  •  
  •         $this->setFieldType(
  •             'file',
  •             'file',
  •             array(
  •                 'path'     => '_local/plugins/' $this->getModId('/',
  •                 'aMapping' => array(
  •                     'file_name' => 'realName',
  •                     'file_path' => 'name'
  •                 )
  •             )
  •         );
  •     }
  •  
  •     /**
  •      * Virtual 'age' field callback.
  •      *
  •      * @param  array $aData  Field data
  •      * @return array 
  •      */
  •     protected function fcbAge(array $aData){
  •         if($aData['action'=== 'get'){
  •             // Sample age calculation
  •             list($y$m$dexplode('-'$this->aData['birth']);
  •             $aData['value'date('Y'$y - (int)(date('md'($m $d));
  •         }else{
  •             $aData['_skip'true;
  •         }
  •     }
  • }
  •  
  • /**
  •  * Sample module table list model.
  •  *
  •  * @package    Module_Sample
  •  * @subpackage Model
  •  * @resource   ami_sample/table/model/list <code>AMI::getResourceModel('ami_sample/table')->getList()</code>
  •  * @since      5.12.0
  •  */
  • }