/** * @param array $params * @param Smarty_Internal_Template $smarty * * @throws SmartyException * * @author Kovács Vince */ function smarty_function_datatable_column($params, Smarty_Internal_Template &$smarty) { if (!class_exists('Datatable')) { throw new SmartyException('chumper/datatable not installed'); } if (!isset($params['label']) && !isset($params['token'])) { throw new SmartyException('Missing label or token attribute for datatable_column tag'); } $tables = $smarty->getVariable('datatables')->value; $table = end($tables); $table->addColumn(isset($params['label']) ? $params['label'] : Lang::get($params['token'])); $options = array(); if (isset($params['sortable'])) { $options['sortable'] = (bool) $params['sortable']; } if (isset($params['orderable'])) { $options['orderable'] = (bool) $params['orderable']; } if (isset($params['width'])) { $options['width'] = $params['width']; } if (isset($params['class'])) { $options['className'] = $params['class']; } if (isset($params['type']) && in_array($params['type'], array('html', 'string', 'numeric', 'date'))) { $options['cellType'] = $params['type']; } $tableOptions = $table->getOptions(); $tableOptions['columns'][] = count($options) == 0 ? null : $options; $table->setOptions($tableOptions); }
/** * compile variable * * @param string $variable * * @return string */ public function compileVariable($variable) { if (strpos($variable, '(') == 0) { // not a variable variable $var = trim($variable, '\''); $this->tag_nocache = $this->tag_nocache | $this->template->getVariable($var, null, true, false)->nocache; $this->template->properties['variables'][$var] = $this->tag_nocache | $this->nocache; } return '$_smarty_tpl->tpl_vars[' . $variable . ']->value'; }
/** * @param array $params * @param string $content * @param Smarty_Internal_Template $smarty * @param boolean $repeat * * @throws SmartyException * @return string * * @author Kovács Vince */ function smarty_block_datatable($params, $content, Smarty_Internal_Template &$smarty, &$repeat) { if (!class_exists('Datatable')) { throw new SmartyException('chumper/datatable not installed'); } if ($repeat) { $options = array('language' => \Lang::get('datatable', array()), 'processing' => true, 'bProcessing' => true, 'stateSave' => true, 'autoWidth' => false, 'columns' => array()); $table = Datatable::table(); if (isset($params['id'])) { $table->setId($params['id']); unset($params['id']); } if (isset($params['url'])) { $table->setUrl($params['url']); unset($params['url']); } elseif (isset($params['action'])) { $table->setUrl(URL::action($params['action'])); unset($params['action']); } if (isset($params['searching'])) { $options['searching'] = $params['searching']; } if (isset($params['lengthChange'])) { $options['lengthChange'] = $params['lengthChange']; } if (isset($params['class'])) { $table->setClass($params['class']); } $table->setOptions($options); $smarty->append('datatables', $table); } else { $tables = $smarty->getVariable('datatables')->value; $table = array_pop($tables); $smarty->assign('datatables', $tables); if (isset($params['view'])) { return $table->render($params['view']); } return $table->render('datatable'); } return ''; }