Example #1
0
 public function getValue($record)
 {
     $value = $this->admin->getColumnValue($this->name, $record);
     list($column, $model) = $this->admin->getChainedModel($this->name, $record);
     if ($model === null) {
         return null;
     }
     $field = $model->getField($column, false);
     if ($field) {
         if (is_a($field, HasManyField::className()) || is_a($field, ManyToManyField::className())) {
             return null;
         } else {
             if (is_a($field, BooleanField::className())) {
                 return $value ? '<i class="icon checkmark"></i>' : '';
             } else {
                 if (!empty($field->choices) && array_key_exists($value, $field->choices)) {
                     return $field->choices[$value];
                 } else {
                     return (string) $value;
                 }
             }
         }
     } else {
         return (string) $model->{$column};
     }
 }
 public function renderHeadCell()
 {
     $title = $this->getTitle();
     $classes = ['th-' . $this->name];
     $orderColumn = $this->admin->orderColumn($this->name);
     if ($orderColumn) {
         if ($this->currentOrder == $orderColumn) {
             $class[] = 'desc';
             $orderColumn = '-' . $orderColumn;
         } else {
             $class[] = 'asc';
         }
         $request = Mindy::app()->request;
         $urlManager = Mindy::app()->urlManager;
         $title = strtr('<a href="{url}?order={order}&search={search}&id={id}">{title}</a>', ['{title}' => $title, '{url}' => $urlManager->reverse('admin:list', ['moduleName' => $this->moduleName, 'adminClass' => $this->admin->classNameShort()]), '{order}' => $orderColumn, '{search}' => $request->getParam('search'), '{id}' => $request->getParam('id')]);
     }
     return strtr($this->headCellTemplate, ['{title}' => $title, '{html}' => $this->formatHtmlAttributes(['class' => implode(' ', $classes)])]);
 }