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 TDataGridColumn.php

Documentation is available at TDataGridColumn.php

  1. <?php
  2. namespace Adianti\Widget\Datagrid;
  3.  
  4. use Adianti\Core\AdiantiCoreTranslator;
  5. use Adianti\Control\TAction;
  6. use Adianti\Widget\Form\TEntry;
  7.  
  8. /**
  9.  * Representes a DataGrid column
  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. {
  19.     private $name;
  20.     private $label;
  21.     private $align;
  22.     private $width;
  23.     private $action;
  24.     private $editaction;
  25.     private $transformer;
  26.     private $properties;
  27.     private $dataProperties;
  28.     private $totalFunction;
  29.     private $totalMask;
  30.     private $totalCallback;
  31.     private $totalTransformed;
  32.     private $searchable;
  33.     private $inputSearch;
  34.     
  35.     /**
  36.      * Class Constructor
  37.      * @param  $name  = Name of the column in the database
  38.      * @param  $label = Text label that will be shown in the header
  39.      * @param  $align = Column align (left, center, right)
  40.      * @param  $width = Column Width (pixels)
  41.      */
  42.     public function __construct($name$label$align$width NULL)
  43.     {
  44.         $this->name  $name;
  45.         $this->label $label;
  46.         $this->align $align;
  47.         $this->width $width;
  48.         $this->searchable false;
  49.         $this->properties array();
  50.         $this->dataProperties array();
  51.     }
  52.     
  53.     /**
  54.      * Define column visibility
  55.      */
  56.     public function setVisibility($bool)
  57.     {
  58.         if ($bool)
  59.         {
  60.             $this->setProperty('style''');
  61.             $this->setDataProperty('style''');
  62.         }
  63.         else
  64.         {
  65.             $this->setProperty('style''display:none');
  66.             $this->setDataProperty('style''display:none');
  67.         }
  68.     }
  69.     
  70.     /**
  71.      * Enable column auto hide
  72.      */
  73.     public function enableAutoHide($width)
  74.     {
  75.         $this->setProperty('hiddable'$width);
  76.         $this->setDataProperty('hiddable'$width);
  77.     }
  78.     
  79.     /**
  80.      * Enable column search
  81.      */
  82.     public function enableSearch()
  83.     {
  84.         $this->searchable true;
  85.         
  86.         $name 'search_' str_replace(['-''>'],['_'''],$this->name);
  87.         
  88.         $this->inputSearch new TEntry($name);
  89.         $this->inputSearch->setId($name);
  90.         $this->inputSearch->{'placeholder'AdiantiCoreTranslator::translate('Search');
  91.         $this->inputSearch->setSize('50%');
  92.     }
  93.     
  94.     /**
  95.      * Get input search
  96.      */
  97.     public function getInputSearch()
  98.     {
  99.         return $this->inputSearch;
  100.     }
  101.     
  102.     /**
  103.      * Returns if column is searchable
  104.      */
  105.     public function isSearchable()
  106.     {
  107.         return $this->searchable;
  108.     }
  109.     
  110.     /**
  111.      * Define a column header property
  112.      * @param $name  Property Name
  113.      * @param $value Property Value
  114.      */
  115.     public function setProperty($name$value)
  116.     {
  117.         $this->properties[$name$value;
  118.     }
  119.     
  120.     /**
  121.      * Define a data property
  122.      * @param $name  Property Name
  123.      * @param $value Property Value
  124.      */
  125.     public function setDataProperty($name$value)
  126.     {
  127.         $this->dataProperties[$name$value;
  128.     }
  129.     
  130.     /**
  131.      * Return a column property
  132.      * @param $name  Property Name
  133.      */
  134.     public function getProperty($name)
  135.     {
  136.         if (isset($this->properties[$name]))
  137.         {
  138.             return $this->properties[$name];
  139.         }
  140.     }
  141.     
  142.     /**
  143.      * Return a data property
  144.      * @param $name  Property Name
  145.      */
  146.     public function getDataProperty($name)
  147.     {
  148.         if (isset($this->dataProperties[$name]))
  149.         {
  150.             return $this->dataProperties[$name];
  151.         }
  152.     }
  153.     
  154.     /**
  155.      * Return column properties
  156.      */
  157.     public function getProperties()
  158.     {
  159.         return $this->properties;
  160.     }
  161.     
  162.     /**
  163.      * Return data properties
  164.      */
  165.     public function getDataProperties()
  166.     {
  167.         return $this->dataProperties;
  168.     }
  169.     
  170.     /**
  171.      * Intercepts whenever someones assign a new property's value
  172.      * @param $name     Property Name
  173.      * @param $value    Property Value
  174.      */
  175.     public function __set($name$value)
  176.     {
  177.         // objects and arrays are not set as properties
  178.         if (is_scalar($value))
  179.         {              
  180.             // store the property's value
  181.             $this->setProperty($name$value);
  182.         }
  183.     }
  184.     
  185.     /**
  186.      * Returns the database column's name
  187.      */
  188.     public function getName()
  189.     {
  190.         return $this->name;
  191.     }
  192.     
  193.     /**
  194.      * Returns the column's label
  195.      */
  196.     public function getLabel()
  197.     {
  198.         return $this->label;
  199.     }
  200.     
  201.     /**
  202.      * Set the column's label
  203.      * @param $label column label
  204.      */
  205.     public function setLabel($label)
  206.     {
  207.         $this->label $label;
  208.     }
  209.     
  210.     /**
  211.      * Returns the column's align
  212.      */
  213.     public function getAlign()
  214.     {
  215.         return $this->align;
  216.     }
  217.     
  218.     /**
  219.      * Returns the column's width
  220.      */
  221.     public function getWidth()
  222.     {
  223.         return $this->width;
  224.     }
  225.     
  226.     /**
  227.      * Define the action to be executed when
  228.      * the user clicks over the column header
  229.      * @param $action     TAction object
  230.      * @param $parameters Action parameters
  231.      */
  232.     public function setAction(TAction $action$parameters null)
  233.     {
  234.         $this->action $action;
  235.         
  236.         if ($parameters)
  237.         {
  238.             $this->action->setParameters($parameters);
  239.         }
  240.     }
  241.     
  242.     /**
  243.      * Returns the action defined by set_action() method
  244.      * @return the action to be executed when the
  245.      *  user clicks over the column header
  246.      */
  247.     public function getAction()
  248.     {
  249.         // verify if the column has an actions
  250.         if ($this->action)
  251.         {
  252.             return $this->action;
  253.         }
  254.     }
  255.     
  256.     /**
  257.      * Remove action
  258.      */
  259.     public function removeAction()
  260.     {
  261.         $this->action null;
  262.     }
  263.     
  264.     /**
  265.      * Define the action to be executed when
  266.      * the user clicks do edit the column
  267.      * @param $action   A TDataGridAction object
  268.      */
  269.     public function setEditAction(TDataGridAction $editaction)
  270.     {
  271.         $this->editaction $editaction;
  272.     }
  273.     
  274.     /**
  275.      * Returns the action defined by setEditAction() method
  276.      * @return the action to be executed when the
  277.      *  user clicks do edit the column
  278.      */
  279.     public function getEditAction()
  280.     {
  281.         // verify if the column has an actions
  282.         if ($this->editaction)
  283.         {
  284.             return $this->editaction;
  285.         }
  286.     }
  287.     
  288.     /**
  289.      * Define a callback function to be applyed over the column's data
  290.      * @param $callback  A function name of a method of an object
  291.      */
  292.     public function setTransformer(Callable $callback)
  293.     {
  294.         $this->transformer $callback;
  295.     }
  296.  
  297.     /**
  298.      * Returns the callback defined by the setTransformer()
  299.      */
  300.     public function getTransformer()
  301.     {
  302.         return $this->transformer;
  303.     }
  304.     
  305.     /**
  306.      * Enable total
  307.      */
  308.     public function enableTotal($function$prefix null$decimals 2$decimal_separator ','$thousand_separator '.')
  309.     {
  310.         $this->totalFunction $function;
  311.         $this->totalMask     "{$prefix}:{$decimals}{$decimal_separator}{$thousand_separator}";
  312.         
  313.         if ($function == 'sum')
  314.         {
  315.             $totalCallback function($values{
  316.                 return array_sum($values);
  317.             };
  318.             
  319.             $this->setTotalFunction$totalCallback );
  320.         }
  321.     }
  322.     
  323.     /**
  324.      * Define a callback function to totalize column
  325.      * @param $callback  A function name of a method of an object
  326.      * @param $apply_transformer Apply transform function also in total
  327.      */
  328.     public function setTotalFunction(Callable $callback$apply_transformer true)
  329.     {
  330.         $this->totalCallback $callback;
  331.         $this->totalTransformed = $apply_transformer;
  332.     }
  333.     
  334.     /**
  335.      * Returns the callback defined by the setTotalFunction()
  336.      */
  337.     public function getTotalCallback()
  338.     {
  339.         return $this->totalCallback;
  340.     }
  341.     
  342.     /**
  343.      * Returns total function
  344.      */
  345.     public function getTotalFunction()
  346.     {
  347.         return $this->totalFunction;
  348.     }
  349.     
  350.     /**
  351.      * Returns total mask
  352.      */
  353.     public function getTotalMask()
  354.     {
  355.         return $this->totalMask;
  356.     }
  357.     
  358.     /**
  359.      * Is total transformed
  360.      */
  361.     public function totalTransformed()
  362.     {
  363.         return $this->totalTransformed;
  364.     }
  365. }