* @package tao */ abstract class tao_helpers_grid_GridContainer { // --- ASSOCIATIONS --- // --- ATTRIBUTES --- /** * Short description of attribute grid * * @access protected * @var Grid */ protected $grid = null; /** * Short description of attribute grids * * @access protected * @var array */ protected static $grids = []; /** * Short description of attribute options * * @access protected * @var array */ protected $options = []; /** * Short description of attribute data * * @access protected * @var array */ protected $data = []; /** * Short description of attribute excludedProperties * * @access protected * @var array */ protected $excludedProperties = []; // --- OPERATIONS --- /** * Short description of method __construct * * @access public * @author Somsack Sipasseuth, * @param array data * @param array options * @return mixed */ public function __construct($data = [], $options = []) { $this->data = $data; $this->options = $options; $this->excludedProperties = (is_array($this->options) && isset($this->options['excludedProperties'])) ? $this->options['excludedProperties'] : []; $this->grid = new tao_helpers_grid_Grid($options); //init columns ... $this->initGrid(); $this->initColumns(); $this->initOptions($options); } /** * Short description of method __destruct * * @access public * @author Somsack Sipasseuth, * @return mixed */ public function __destruct() { if (!is_null($this->grid)) { //remove the refs of the contained grid } } /** * Short description of method getGrid * * @access public * @author Somsack Sipasseuth, * @return tao_helpers_grid_Grid */ public function getGrid() { $returnValue = null; $returnValue = $this->grid; return $returnValue; } /** * Short description of method initGrid * * @access protected * @author Somsack Sipasseuth, * @return boolean */ protected function initGrid() { $returnValue = (bool) false; //set data if data given $returnValue = $this->grid->setData($this->data); return (bool) $returnValue; } /** * Short description of method initColumns * * @abstract * @access protected * @author Somsack Sipasseuth, * @return boolean */ abstract protected function initColumns(); /** * Short description of method toArray * * @access public * @author Somsack Sipasseuth, * @return array */ public function toArray() { $returnValue = []; $returnValue = $this->grid->toArray(); return (array) $returnValue; } /** * Short description of method initOptions * * @access public * @author Somsack Sipasseuth, * @return boolean */ public function initOptions($options = []) { $returnValue = (bool) false; $columns = $this->grid->getColumns(); if (isset($options['columns'])) { foreach ($options['columns'] as $columnId => $columnOptions) { if (isset($columns[$columnId])) { foreach ($columnOptions as $optionsName => $optionsValue) { if ($optionsName == 'columns') { //if the options is columns, the options will be used to augment the subgrid model $columns = $this->grid->getColumns(); $subGridAdapter = null; //get the last subgrid adapter which defines the column $adapters = $columns[$columnId]->getAdapters(); $adaptersLength = count($adapters); for ($i = $adaptersLength - 1; $i >= 0; $i--) { if ($adapters[$i] instanceof tao_helpers_grid_Cell_SubgridAdapter) { $subGridAdapter = $adapters[$i]; break; } } if (is_null($subGridAdapter)) { throw new Exception(__('The column ') . $columnId . __(' requires a subgrid adapter')); } //init options of the subgrid $subGridAdapter->getGridContainer()->initOptions($columnOptions); continue; } $columns[$columnId]->setOption($optionsName, $optionsValue); } } } } return (bool) $returnValue; } /** * Short description of method __clone * * @access public * @author Somsack Sipasseuth, * @return mixed */ public function __clone() { $this->grid = clone $this->grid; } } /* end of abstract class tao_helpers_grid_GridContainer */