Example #1
0
 /**
  * Render group view
  *
  * @param  string $name
  * @param  string $dateFormat
  * @param  array  $filters
  * @param  string $table
  * @param  array  $conds
  * @param  string $order
  * @return mixed
  */
 public function render($name, $dateFormat = null, array $filters = [], $table = null, array $conds = [], $order = null)
 {
     if (is_numeric($name)) {
         $this->getById($name);
     } else {
         $this->getByName($name);
     }
     if (isset($this->data['models'][0]) && isset($this->data['models'][0]['model'])) {
         $model = $this->data['models'][0]['model'];
         if (null !== $this->data['models'][0]['type_field'] && null !== $this->data['models'][0]['type_value']) {
             $params = [str_replace('type_id', 'typeId', $this->data['models'][0]['type_field']) => $this->data['models'][0]['type_value']];
             if (null !== $table) {
                 $objects = \Phire\Fields\Model\FieldValue::getModelObjectsFromTable($table, $model, $params, $filters, $conds, $order);
             } else {
                 $objects = \Phire\Fields\Model\FieldValue::getModelObjects($model, $params, 'getAll', $filters);
             }
             if (count($objects) > $this->data['pagination']) {
                 $page = !empty($_GET['page']) ? (int) $_GET['page'] : null;
                 $limit = $this->data['pagination'];
                 $offset = null !== $page && (int) $page > 1 ? $page * $limit - $limit : 0;
                 $objects = array_slice($objects, $offset, $limit);
             }
             return $this->build($objects, $dateFormat);
         } else {
             return null;
         }
     } else {
         return null;
     }
 }