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

Source for file AmiClean_AmiSample_Adm.php

Documentation is available at AmiClean_AmiSample_Adm.php

  • <?php
  • /**
  •  * AmiClean/AmiSample configuration.
  •  *
  •  * @copyright  Amiro.CMS. All rights reserved.
  •  * @category   Module
  •  * @package    Config_AmiClean_AmiSample
  •  * @version    $Id: AmiClean_AmiSample_Adm.php 61273 2013-08-07 10:47:54Z Leontiev Anton $
  •  * @since      5.14.4
  •  * @filesource
  •  */
  •  
  • /**
  •  * AmiClean/AmiSample configuration admin action controller.
  •  *
  •  * @package    Config_AmiClean_AmiSample
  •  * @subpackage Controller
  •  * @resource   {$modId}/module/controller/adm <code>AMI::getResource('{$modId}/module/controller/adm')*</code>
  •  * @since      5.14.4
  •  */
  •     /**
  •      * Constructor.
  •      *
  •      * @param AMI_Request  $oRequest   Request object
  •      * @param AMI_Response $oResponse  Response object
  •      */
  •     public function __construct(AMI_Request $oRequestAMI_Response $oResponse){
  •         parent::__construct($oRequest$oResponse);
  •         // Load plugin status messages
  •         $oResponse->loadStatusMessages(AMI_iTemplate::LOCAL_LNG_MOD_PATH '/' $this->getModId('_messages.lng');
  •  
  •         $this->addComponents(array('filter''list''form'));
  •  
  •         // Add handler on adding status messages
  •         AMI_Event::addHandler('on_add_status_message'array($this'handleAddStatusMessage')$this->getModId());
  •     }
  •  
  •     /**
  •      * Replaces the status message with a new one.
  •      *
  •      * @param  string $name          Event name
  •      * @param  array  $aEvent        Event data
  •      * @param  string $handlerModId  Handler module id
  •      * @param  string $srcModId      Source module id
  •      * @return array 
  •      */
  •     public function handleAddStatusMessage($namearray $aEvent$handlerModId$srcModId){
  •         if($aEvent['key'== 'status_add'){
  •             $aEvent['key''status_name_add';
  •             $aEvent['aParams'array('name' => $this->getRequestParam('nickname'));
  •         }
  •  
  •         return $aEvent;
  •     }
  •  
  • }
  •  
  • /**
  •  * AmiClean/AmiSample configuration model.
  •  *
  •  * @package    Config_AmiClean_AmiSample
  •  * @subpackage Model
  •  * @resource   {$modId}/module/model <code>AMI::getResourceModel('{$modId}/module')*</code>
  •  * @since      5.14.4
  •  */
  • }
  •  
  • /**
  •  * AmiClean/AmiSample configuration admin filter component action controller.
  •  *
  •  * @package    Config_AmiClean_AmiSample
  •  * @subpackage Controller
  •  * @resource   {$modId}/filter/controller/adm <code>AMI::getResource('{$modId}/filter/controller/adm')*</code>
  •  * @since      5.14.4
  •  */
  • }
  •  
  • /**
  •  * AmiClean/AmiSample configuration item list component filter model.
  •  *
  •  * @package    Config_AmiClean_AmiSample
  •  * @subpackage Model
  •  * @resource   {$modId}/filter/model/adm <code>AMI::getResource('{$modId}/filter/model/adm')*</code>
  •  * @since      5.14.4
  •  */
  •     /**
  •      * Constructor.
  •      */
  •     public function __construct(){
  •         $this->addViewField(
  •             array(
  •                 'name'          => 'nickname',
  •                 'type'          => 'input',
  •                 'flt_type'      => 'text',
  •                 'flt_default'   => '',
  •                 'flt_condition' => 'like',
  •                 'flt_column'    => 'nickname'
  •             )
  •         );
  •         $this->addViewField(
  •             array(
  •                 'name'          => 'datefrom',
  •                 'type'          => 'datefrom',
  •                 'flt_type'      => 'date',
  •                 'flt_default'   => AMI_Lib_Date::formatUnixTime(AMI_Lib_Date::UTIME_MIN),
  •                 'flt_condition' => '>=',
  •                 'flt_column'    => 'birth'
  •             )
  •         );
  •         $this->addViewField(
  •             array(
  •                 'name'          => 'dateto',
  •                 'type'          => 'dateto',
  •                 'flt_type'      => 'date',
  •                 'flt_default'   => AMI_Lib_Date::formatUnixTime(AMI_Lib_Date::UTIME_MAX),
  •                 'flt_condition' => '<',
  •                 'flt_column'    => 'birth'
  •             )
  •         );
  •     }
  • }
  •  
  • /**
  •  * AmiClean/AmiSample configuration admin filter component view.
  •  *
  •  * @package    Config_AmiClean_AmiSample
  •  * @subpackage View
  •  * @resource   {$modId}/filter/view/adm <code>AMI::getResource('{$modId}/filter/view/adm')*</code>
  •  * @since      5.14.4
  •  */
  •     /**
  •      * Constructor.
  •      */
  •     public function __construct(){
  •         parent::__construct();
  •  
  •         // Add admin filter form placeholder for 'nickname' before 'datefrom' filter field
  •         $this->putPlaceholder('nickname''datefrom.before');
  •     }
  • }
  •  
  • /**
  •  * AmiClean/AmiSample configuration admin form component action controller.
  •  *
  •  * @package    Config_AmiClean_AmiSample
  •  * @subpackage Controller
  •  * @resource   {$modId}/form/controller/adm <code>AMI::getResource('{$modId}/form/controller/adm')*</code>
  •  * @since      5.14.4
  •  */
  •  
  •     /**
  •      * Save action dispatcher.
  •      *
  •      * @param  array &$aEvent  Event data
  •      * @return void 
  •      */
  •     protected function _save(array &$aEvent){
  •         parent::_save($aEvent);
  •         if(is_object($this->oItem)){
  •             AMI::getSingleton('response')->addStatusMessage('origin_data'array('data' => d::getDumpAsString($this->oItem->getOriginData())));
  •             AMI::getSingleton('response')->addStatusMessage('difference_from_origin'array('data' => d::getDumpAsString($this->oItem->getDiffFromOrigin())));
  •         }
  •     }
  •  
  •     /**
  •      * Returns module file storage path.
  •      *
  •      * @return string 
  •      * @amidev Temporary
  •      */
  •     protected function getFileStoragePath(){
  •         return '_mod_files/_upload/';
  •     }
  •  
  • }
  •  
  • /**
  •  * AmiClean/AmiSample configuration form component view.
  •  *
  •  * @package    Config_AmiClean_AmiSample
  •  * @subpackage View
  •  * @resource   {$modId}/form/view/adm <code>AMI::getResource('{$modId}/form/view/adm')*</code>
  •  * @since      5.14.4
  •  */
  •     /**
  •      * Fields init.
  •      *
  •      */
  •     public function init(){
  •         // Add custom sets for the fields
  •         $this->addTemplate(AMI_iTemplate::LOCAL_TPL_MOD_PATH '/' $this->getModId('_fields.tpl');
  •         // Common form fields {
  •  
  •         // Item id
  •         $this->addField(array('name' => 'id''type' => 'hidden'));
  •         // Form save action
  •         $this->addField(array('name' => 'mod_action''value' => 'form_save''type' => 'hidden'));
  •  
  •         // } Common form fields
  •  
  •         $this->addField(array('name' => 'public''type' => 'checkbox''default_checked' => true));
  •         $this->addField(array('name' => 'nickname'));
  •         $this->addField(array('name' => 'birth''type' => 'date''validate' => array('custom''stop_on_error')));
  •         $this->addField(array('name' => 'email'));
  •  
  •         // Add tabs
  •         $this->addTabContainer('tabset');
  •         $this->addTab('info''tabset'self::TAB_STATE_ACTIVE);
  •         $this->addTab('contacts''tabset',self::TAB_STATE_COMMON,''array('edit','show'));
  •  
  •         // Add fields on tabs
  •         $this->addField(array('name' => 'about''type' => 'htmleditor''cols' => 80'rows' => 10'position' => 'info.end''modes' => array('editor''bb')));
  •         $this->addField(array('name' => 'phone''position' => 'contacts.end'));
  •         $this->addField(array('name' => 'homepage''position' => 'contacts.end''validate' => array('domain')));
  •  
  •         $this->addField(array('name' => 'file''type' => 'file''position' => 'email.after''validate' => array('required')));
  •  
  •         // Reset defaults
  •         $this->dropPlaceholders(array('sublink''ext_image'));
  •         $this->addField(array('name' => 'sublink''position' => 'file.after'));
  •         $this->addSection('ext_image''sublink.after');
  •  
  •         // Add custom script
  •         $this->addScriptFile('_local/_admin/_js/' $this->getModId(.  '/form.adm.js');
  •  
  •         $this->putPlaceholder('special''birth.begin'true);
  •         $this->addTemplate(AMI_iTemplate::LOCAL_TPL_MOD_PATH '/' $this->getModId('_fields_custom.tpl''special');
  •         $this->addField(array('name' => 'views''position' => 'special.begin' ,'display_by_action' => array('edit''show')));
  •  
  •         return parent::init();
  •     }
  •  
  • }
  •  
  • /**
  •  * AmiClean/AmiSample configuration admin list component action controller.
  •  *
  •  * @package    Config_AmiClean_AmiSample
  •  * @subpackage Controller
  •  * @resource   {$modId}/list/controller/adm <code>AMI::getResource('{$modId}/list/controller/adm')*</code>
  •  * @since      5.14.4
  •  */
  •     /**
  •      * Initialization.
  •      *
  •      * @return AmiSample_ListAdm 
  •      */
  •     public function init(){
  •         // AMI_ModListAdm::addActions() must be called before parent::init()!
  •  
  •         // Add actions to "actions" column
  •         $this->addActions(array(self::REQUIRE_FULL_ENV 'edit'self::REQUIRE_FULL_ENV 'delete'self::REQUIRE_FULL_ENV 'copy''show'));
  •  
  •         // Add separate column action
  •         $this->addColActions(array(self::REQUIRE_FULL_ENV 'public')true);
  •  
  •         // Add separate column action
  •         $this->addColActions(array(self::REQUIRE_FULL_ENV 'rename'));
  •  
  •         // Add action inside existing column
  •         $this->addActions(array('inner')'nickname');
  •  
  •         // Add group actions
  •         $this->addGroupActions(
  •             array(
  •                 array(self::REQUIRE_FULL_ENV 'public',   'public_section'),
  •                 array(self::REQUIRE_FULL_ENV 'unpublic''public_section'),
  •                 array(self::REQUIRE_FULL_ENV 'rename',   'rename_section'),
  •                 array(self::REQUIRE_FULL_ENV 'delete',   'delete_section'),
  •             )
  •         );
  •  
  •         $this->listActionsResId = $this->getModId('/list_actions/controller/adm';
  •         $this->listGrpActionsResId = $this->getModId('/list_group_actions/controller/adm';
  •  
  •         parent::init();
  •         return $this;
  •     }
  •  
  • }
  •  
  • /**
  •  * AmiClean/AmiSample configuration admin list component view.
  •  *
  •  * @package    Config_AmiClean_AmiSample
  •  * @subpackage View
  •  * @resource   {$modId}/list/view/adm <code>AMI::getResource('{$modId}/list/view/adm')*</code>
  •  * @since      5.14.4
  •  */
  •  
  •    /**
  •      * Order column
  •      *
  •      * @var string 
  •      */
  •     protected $orderColumn = 'nickname';
  •  
  •     /**
  •      * Order column direction
  •      *
  •      * @var bool 
  •      */
  •     protected $orderDirection = 'asc';
  •  
  •     /**
  •      * Constructor.
  •      */
  •     public function __construct(){
  •         $this->tplFileName = AMI_iTemplate::LOCAL_TPL_MOD_PATH '/' $this->getModId('_list.tpl';
  •         parent::__construct();
  •  
  •         // Init columns
  •         $this
  •             ->addColumnType('id''hidden')
  •             ->addColumn('nickname')
  •             ->addColumn('birth')
  •             ->addColumnType('age''int')
  •             ->setColumnTensility('nickname')
  •             ->addSortColumns(
  •                 array(
  •                     'public',
  •                     'nickname',
  •                     'birth'
  •                 )
  •             );
  •  
  •         // place 'rename' action column before 'nickname' column
  •         $this->putPlaceholder('rename''nickname.before');
  •  
  •         // Truncate 'nickname' column by 50 symbols
  •         $this->formatColumn(
  •             'nickname',
  •             array($this'fmtTruncate'),
  •             array(
  •                 'length' => 50
  •             )
  •         );
  •  
  •         // Format 'birth' column as date
  •         $this->formatColumn(
  •             'birth',
  •             array($this'fmtDateTime'),
  •             array(
  •                 'format' => AMI_Lib_Date::FMT_DATE
  •             )
  •         );
  •  
  •         // Use custom formatter on 'value' column
  •         $this->formatColumn(
  •             'birth',
  •             array($this'fmtCustom')
  •         );
  •  
  •         // Add custom script
  •     $this->addScriptFile('_local/_admin/_js/' $this->getModId('/list.adm.js');
  •     }
  •  
  •     /**
  •      * Custom column formatter.
  •      *
  •      * @param  mixed $value  Value to format
  •      * @param  array $aArgs  Arguments
  •      * @return mixed 
  •      * @see    AMI_ModListView::formatColumn()
  •      */
  •     protected function fmtCustom($valuearray $aArgs){
  •         return '~ ' $value ' ~';
  •     }
  • }
  •  
  • /**
  • /**
  •  * AmiClean/AmiSample configuration admin list actions controller.
  •  *
  •  * @package    Config_AmiClean_AmiSample
  •  * @subpackage Controller
  •  * @resource   {$modId}/list_actions/controller/adm <code>AMI::getResource('{$modId}_cat/list_actions/controller/adm')*</code>
  •  * @since      5.14.4
  •  */
  • class AmiClean_AmiSample_ListActionsAdm extends Hyper_AmiClean_ListActionsAdm{
  •  
  •     /**#@+
  •      * Event handler.
  •      *
  •      * @see AMI_Event::addHandler()
  •      * @see AMI_Event::fire()
  •      * @see AMI_ModListAdm::addActions()
  •      * @see AMI_ModListAdm::addColActions()
  •      */
  •  
  •     /**
  • /**
  •      * Dispatches 'delete' action.
  •      *
  •      * Overridden item deletion. Denies deletion of item having id == 1.
  •      *
  •      * @param  string $name          Event name
  •      * @param  array  $aEvent        Event data
  •      * @param  string $handlerModId  Handler module id
  •      * @param  string $srcModId      Source module id
  •      * @return array 
  •      */
  •     public function dispatchDelete($namearray $aEvent$handlerModId$srcModId){
  •         $oItem $this->getItem($this->getRequestId());
  •         if($oItem->getId(== 1){
  •             $aEvent['oResponse']->addStatusMessage('status_del_forbidden'array()AMI_Response::STATUS_MESSAGE_ERROR);
  •             $this->refreshView();
  •         }else{
  •             parent::dispatchDelete($name$aEvent$handlerModId$srcModId);
  •         }
  •         return $aEvent;
  •     }
  •  
  •     /**
  •      * Dispatches 'inner' action.
  •      *
  •      * Displays three messages.
  •      *
  •      * @param  string $name          Event name
  •      * @param  array  $aEvent        Event data
  •      * @param  string $handlerModId  Handler module id
  •      * @param  string $srcModId      Source module id
  •      * @return array 
  •      */
  •     public function dispatchInner($namearray $aEvent$handlerModId$srcModId){
  •         $aEvent['oResponse']
  •             ->addStatusMessage('status_inner_note')
  •             ->addStatusMessage('status_inner_warning'array()AMI_Response::STATUS_MESSAGE_WARNING)
  •             ->addStatusMessage('status_inner_error'array()AMI_Response::STATUS_MESSAGE_ERROR);
  •         $this->refreshView();
  •         return $aEvent;
  •     
  •  
  •  
  •     /**
  •      * Dispatches 'rename' action.
  •      *
  •      * Renames 'nickname' field to "[{$nickname}]".
  •      *
  •      * @param  string $name          Event name
  •      * @param  array  $aEvent        Event data
  •      * @param  string $handlerModId  Handler module id
  •      * @param  string $srcModId      Source module id
  •      * @return array 
  •      */
  •     public function dispatchRename($namearray $aEvent$handlerModId$srcModId){
  •         $oItem $this->getItem($this->getRequestId());
  •         $nickname $oItem->nickname;
  •         $oItem->nickname '[' $nickname ']';
  •         $oItem->save();
  •         $aEvent['oResponse']->addStatusMessage(
  •             'status_renamed',
  •             array(
  •                 'source'      => $nickname,
  •                 'destination' => $oItem->nickname
  •             )
  •         );
  •         $this->refreshView();
  •         return $aEvent;
  •     
  •  
  •     /**
  •      * Dispatches 'copy' action.
  •      *
  •      * Copies item and prepends '- ' string to the new 'nickname' field.
  •      *
  •      * @param  string $name          Event name
  •      * @param  array  $aEvent        Event data
  •      * @param  string $handlerModId  Handler module id
  •      * @param  string $srcModId      Source module id
  •      * @return array 
  •      */
  •     public function dispatchCopy($namearray $aEvent$handlerModId$srcModId){
  •         $oItem $this->getItem($this->getRequestId());
  •         $nickname $oItem->nickname;
  •         $newNickname '- ' $nickname;
  •         $oItem->nickname $newNickname;
  •         $oItem->resetId();
  •         $oItem->save();
  •         $aEvent['oResponse']->addStatusMessage(
  •             'status_copied',
  •             array(
  •                 'source'      => $nickname,
  •                 'destination' => $newNickname
  •             )
  •         );
  •         $this->refreshView();
  •         return $aEvent;
  •     
  •  
  •     /**#@-*/
  • }
  •  
  • /**
  •  * AmiClean/AmiSample configuration admin list group actions controller.
  •  *
  •  * @package    Config_AmiClean_AmiSample
  •  * @subpackage Controller
  •  * @resource   {$modId}/list_group_actions/controller/adm <code>AMI::getResource('{$modId}_cat/list_group_actions/controller/adm')*</code>
  •  * @since      5.14.4
  •  */
  •     /**#@+
  •      * Event handler.
  •      *
  •      * @see AMI_Event::addHandler()
  •      * @see AMI_Event::fire()
  •      * @see AMI_ModListAdm::addGroupActions()
  •      */
  •  
  •     /**
  •      * Dispatches 'delete' group action.
  •      *
  •      * @param  string $name          Event name
  •      * @param  array  $aEvent        Event data
  •      * @param  string $handlerModId  Handler module id
  •      * @param  string $srcModId      Source module id
  •      * @return array 
  •      */
  •     public function dispatchGrpDelete($namearray $aEvent$handlerModId$srcModId){
  •         return parent::dispatchGrpDelete($name$aEvent$handlerModId$srcModId);
  •     }
  •  
  •     /**
  •      * Dispatches 'rename' group action.
  •      *
  •      * Renames 'nickname' field to "[{$nickname}]".
  •      *
  •      * @param  string $name          Event name
  •      * @param  array  $aEvent        Event data
  •      * @param  string $handlerModId  Handler module id
  •      * @param  string $srcModId      Source module id
  •      * @return array 
  •      */
  •     public function dispatchGrpRename($namearray $aEvent$handlerModId$srcModId){
  •         $oListActionsAdm AMI::getResource($handlerModId '/list_actions/controller/adm');
  •  
  •         $aRequestIds $this->getRequestIds();
  •         foreach($aRequestIds as $id){
  •             $aEvent['oRequest']->set('mod_action_id'$id);
  •             $oListActionsAdm->setActionData($name$aEvent$handlerModId$srcModId);
  •             $oListActionsAdm->dispatchRename($name$aEvent$handlerModId$srcModId);
  •         }
  •         $aEvent['oResponse']->resetStatusMessages();
  •         $aEvent['oResponse']->addStatusMessage('status_grp_rename'array('num_items' => sizeof($aRequestIds)));
  •  
  •         $this->refreshView();
  •  
  •         return $aEvent;
  •     }
  •  
  •     /**#@-*/
  • }