Lançado Adianti Framework 7.6!
Clique aqui para saber mais
menu

Adianti Solutions

API

Adianti, Framework, PHP, MVC, Active record, Front controller, IDE, RAD, Web, multiplataforma, geração de código, desenvolvimento rápido, relatórios, formulários, listagens, datagrids, gráficos, banco de dados, padrões de projeto, design patterns API do Adianti Framework.
API Docs
code
Selecione a classe

Source for file TDataGridAction.php

Documentation is available at TDataGridAction.php

  1. <?php
  2. namespace Adianti\Widget\Datagrid;
  3.  
  4. use Adianti\Control\TAction;
  5. use Adianti\Core\AdiantiCoreTranslator;
  6. use Exception;
  7.  
  8. /**
  9.  * Represents an action inside a datagrid
  10.  *
  11.  * @version    7.4
  12.  * @package    widget
  13.  * @subpackage datagrid
  14.  * @author     Pablo Dall'Oglio
  15.  * @copyright  Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
  16.  * @license    http://www.adianti.com.br/framework-license
  17.  */
  18. class TDataGridAction extends TAction
  19. {
  20.     private $field;
  21.     private $fields;
  22.     private $image;
  23.     private $label;
  24.     private $buttonClass;
  25.     private $useButton;
  26.     private $displayCondition;
  27.     
  28.     /**
  29.      * Class Constructor
  30.      * @param $action Callback to be executed
  31.      * @param $parameters = array of parameters
  32.      */
  33.     public function __construct($action$parameters null)
  34.     {
  35.         parent::__construct($action$parameters);
  36.         
  37.         if ($parameters)
  38.         {
  39.             $this->setFieldsparent::getFieldParameters() );
  40.         }
  41.     }
  42.     
  43.     /**
  44.      * Define wich Active Record's property will be passed along with the action
  45.      * @param $field Active Record's property
  46.      */
  47.     public function setField($field)
  48.     {
  49.         $this->field $field;
  50.         
  51.         $this->setParameter('key',  '{'.$field.'}');
  52.         $this->setParameter($field'{'.$field.'}');
  53.     }
  54.     
  55.     /**
  56.      * Define wich Active Record's properties will be passed along with the action
  57.      * @param $field Active Record's property
  58.      */
  59.     public function setFields($fields)
  60.     {
  61.         $this->fields $fields;
  62.         
  63.         if ($fields)
  64.         {
  65.             if (empty($this->field&& empty(parent::getParameter('key')))
  66.             {
  67.                 $this->setParameter('key''{'.$fields[0].'}');
  68.             }
  69.             
  70.             foreach ($fields as $field)
  71.             {
  72.                 $this->setParameter($field'{'.$field.'}');
  73.             }
  74.         }
  75.     }
  76.     
  77.     /**
  78.      * Returns the Active Record's property that
  79.      * will be passed along with the action
  80.      */
  81.     public function getField()
  82.     {
  83.         return $this->field;
  84.     }
  85.     
  86.     /**
  87.      * Returns the Active Record's properties that
  88.      * will be passed along with the action
  89.      */
  90.     public function getFields()
  91.     {
  92.         return $this->fields;
  93.     }
  94.     
  95.     /**
  96.      * Return if there at least one field defined
  97.      */
  98.     public function fieldDefined()
  99.     {
  100.         return (!empty($this->fieldor !empty($this->fields));
  101.     }
  102.     
  103.     /**
  104.      * Define an icon for the action
  105.      * @param $image  The Image path
  106.      */
  107.     public function setImage($image)
  108.     {
  109.         $this->image $image;
  110.     }
  111.     
  112.     /**
  113.      * Returns the icon of the action
  114.      */
  115.     public function getImage()
  116.     {
  117.         return $this->image;
  118.     }
  119.     
  120.     /**
  121.      * define the label for the action
  122.      * @param $label A string containing a text label
  123.      */
  124.     public function setLabel($label)
  125.     {
  126.         $this->label $label;
  127.     }
  128.     
  129.     /**
  130.      * Returns the text label for the action
  131.      */
  132.     public function getLabel()
  133.     {
  134.         return $this->label;
  135.     }
  136.     
  137.     /**
  138.      * define the buttonClass for the action
  139.      * @param $buttonClass A string containing the button css class
  140.      */
  141.     public function setButtonClass($buttonClass)
  142.     {
  143.         $this->buttonClass $buttonClass;
  144.     }
  145.     
  146.     /**
  147.      * Returns the buttonClass
  148.      */
  149.     public function getButtonClass()
  150.     {
  151.         return $this->buttonClass;
  152.     }
  153.     
  154.     /**
  155.      * define if the action will use a regular button
  156.      * @param $useButton A boolean
  157.      */
  158.     public function setUseButton($useButton)
  159.     {
  160.         $this->useButton $useButton;
  161.     }
  162.     
  163.     /**
  164.      * Returns if the action will use a regular button
  165.      */
  166.     public function getUseButton()
  167.     {
  168.         return $this->useButton;
  169.     }
  170.     
  171.     /**
  172.      * Define a callback that must be valid to show the action
  173.      * @param Callback $displayCondition Action display condition
  174.      */
  175.     public function setDisplayCondition/*Callable*/ $displayCondition )
  176.     {
  177.         $this->displayCondition $displayCondition;
  178.     }
  179.     
  180.     /**
  181.      * Returns the action display condition
  182.      */
  183.     public function getDisplayCondition()
  184.     {
  185.         return $this->displayCondition;
  186.     }
  187.     
  188.     /**
  189.      * Prepare action for use over an object
  190.      * @param $object Data Object
  191.      */
  192.     public function prepare($object)
  193.     {
  194.         if !$this->fieldDefined() )
  195.         {
  196.             throw new Exception(AdiantiCoreTranslator::translate('Field for action ^1 not defined'parent::toString()) '.<br>' 
  197.                                 AdiantiCoreTranslator::translate('Use the ^1 method''setField'.'()').'.');
  198.         }
  199.         
  200.         if ($field $this->getField())
  201.         {
  202.             if !isset$object->$field ) )
  203.             {
  204.                 throw new Exception(AdiantiCoreTranslator::translate('Field ^1 not exists or contains NULL value'$field));
  205.             }
  206.         }
  207.         
  208.         if ($fields $this->getFields())
  209.         {
  210.             $field $fields[0];
  211.             
  212.             if !isset$object->$field ) )
  213.             {
  214.                 throw new Exception(AdiantiCoreTranslator::translate('Field ^1 not exists or contains NULL value'$field));
  215.             }
  216.         }
  217.         
  218.         return parent::prepare($object);
  219.     }
  220.     
  221.     /**
  222.      * Converts the action into an URL
  223.      * @param  $format_action = format action with document or javascript (ajax=no)
  224.      */
  225.     public function serialize($format_action TRUE)
  226.     {
  227.         if (is_array($this->actionAND is_object($this->action[0]))
  228.         {
  229.             if (isset$_REQUEST['offset'))
  230.             {
  231.                 $this->setParameter('offset',     $_REQUEST['offset');
  232.             }
  233.             if (isset$_REQUEST['limit'))
  234.             {
  235.                 $this->setParameter('limit',      $_REQUEST['limit');
  236.             }
  237.             if (isset$_REQUEST['page'))
  238.             {
  239.                 $this->setParameter('page',       $_REQUEST['page');
  240.             }
  241.             if (isset$_REQUEST['first_page'))
  242.             {
  243.                 $this->setParameter('first_page'$_REQUEST['first_page');
  244.             }
  245.             if (isset$_REQUEST['order'))
  246.             {
  247.                 $this->setParameter('order',      $_REQUEST['order');
  248.             }
  249.         }
  250.         if (parent::isStatic())
  251.         {
  252.             $this->setParameter('static',     '1' );
  253.         }
  254.         return parent::serialize($format_action);
  255.     }
  256. }