/** * Render row item into template * @param Row $row * @return mixed */ public function render(Row $row) { /** * Renderer function may be used */ if ($renderer = $this->getRenderer()) { if (!$renderer->getConditionCallback()) { return call_user_func_array($renderer->getCallback(), [$row->getItem()]); } if (call_user_func_array($this->getRenderer(), [$row->getItem()])) { return call_user_func_array($renderer->getCallback(), [$row->getItem()]); } } $a = Html::el('a')->href($this->grid->getPresenter()->link($this->href, $this->getItemParams($row))); if ($this->icon) { $a->add(Html::el('span')->class(DataGrid::$icon_prefix . $this->icon)); if (strlen($this->name)) { $a->add(' '); } } $a->add($this->name); if ($this->title) { $a->title($this->title); } if ($this->class) { $a->class($this->class); } if ($confirm = $this->getConfirm($row)) { $a->data('confirm', $confirm); } return $a; }
/** * Get value from column using Row::getValue() or custom callback * @param Row $row * @param Column\Column $column * @return bool */ private function getValue(Row $row, $column) { if (!$this->rowCallback) { return $row->getValue($column->getColumn()); } return call_user_func_array($this->rowCallback, [$row->getItem(), $column->getColumn()]); }
/** * Render row item into template * @param Row $row * @return mixed */ public function render(Row $row) { /** * Renderer function may be used */ if ($renderer = $this->getRenderer()) { if (!$renderer->getConditionCallback()) { return call_user_func_array($renderer->getCallback(), [$row->getItem()]); } if (call_user_func_array($renderer->getConditionCallback(), [$row->getItem()])) { return call_user_func_array($renderer->getCallback(), [$row->getItem()]); } } /** * Or replacements may be applied */ list($do_replace, $replaced) = $this->applyReplacements($row); if ($do_replace) { return $replaced; } return $this->getColumnValue($row); }
/** * Render row item into template * @param Row $row * @return mixed */ public function render(Row $row) { /** * Renderer function may be used */ if ($renderer = $this->getRenderer()) { if (!$renderer->getConditionCallback()) { return call_user_func_array($renderer->getCallback(), [$row->getItem()]); } if (call_user_func_array($renderer->getConditionCallback(), [$row->getItem()])) { return call_user_func_array($renderer->getCallback(), [$row->getItem()]); } } $value = parent::render($row); $href = $this->grid->getPresenter()->link($this->href, $this->getItemParams($row)); $a = Html::el('a')->href($href)->setText($value); if ($this->title) { $a->title($this->title); } if ($this->class) { $a->class($this->class); } return $a; }
/** * Check whether given property is string or callable * in that case call callback and check property and return it * @param Row $row * @param string|callable|null $property * @param string $name * @return string * @throws DataGridException */ public function getPropertyStringOrCallableGetString(Row $row, $property, $name) { /** * String */ if (is_string($property)) { return $property; } /** * Callable */ if (is_callable($property)) { $value = call_user_func($property, $row->getItem()); if (!is_string($value)) { throw new DataGridException("Action {$name} callback has to return a string"); } return $value; } return $property; }
/** * Try to render item with custom renderer * @param Row $row * @return mixed */ public function useRenderer(Row $row) { $renderer = $this->getRenderer(); if (!$renderer) { throw new DataGridColumnRendererException(); } if ($renderer->getConditionCallback()) { if (!call_user_func_array($renderer->getConditionCallback(), [$row->getItem()])) { throw new DataGridColumnRendererException(); } return call_user_func_array($renderer->getCallback(), [$row->getItem()]); } return call_user_func_array($renderer->getCallback(), [$row->getItem()]); }
/** * @param Row $row * @return bool */ public function shouldBeRendered(Row $row) { $condition = $this->render_condition_callback; return $condition ? $condition($row->getItem()) : TRUE; }