예제 #1
0
 /**
  * Set the field values
  *
  * @param  array $values
  * @return View
  */
 public function setFieldValues(array $values = null)
 {
     parent::setFieldValues($values);
     if ($_POST && null !== $this->name) {
         // Check for dupe name
         $view = Table\Views::findBy(['name' => $this->name]);
         if (isset($view->id) && $this->id != $view->id) {
             $this->getElement('name')->addValidator(new Validator\NotEqual($this->name, 'That view name already exists.'));
         }
     }
     return $this;
 }
예제 #2
0
 /**
  * Get count of views
  *
  * @return int
  */
 public function getCount()
 {
     return Table\Views::findAll()->count();
 }
예제 #3
0
 /**
  * JSON action method
  *
  * @param  int $id
  * @param  int $tid
  * @param  int $vid
  * @return void
  */
 public function json($id, $tid = null, $vid = null)
 {
     $json = [];
     if (is_numeric($id)) {
         $view = Table\Views::findById($id);
         if (isset($view->id)) {
             $json['models'] = null != $view->models ? unserialize($view->models) : [];
         }
     } else {
         $fields = \Phire\Fields\Table\Fields::findAll();
         $json['gMarked'] = [];
         $json['sMarked'] = [];
         $json['fields'] = ['_id' => 'id', '_title' => 'title'];
         foreach ($fields->rows() as $field) {
             $models = unserialize($field->models);
             foreach ($models as $model) {
                 if ($model['model'] == rawurldecode($id) && (null === $tid || null === $model['type_value'] || $model['type_value'] == $tid)) {
                     $json['fields']['_' . $field->id] = $field->name;
                 }
             }
         }
         if (null !== $vid) {
             $view = Table\Views::findById($vid);
             if (isset($view->id)) {
                 $json['gMarked'] = explode('|', $view->group_fields);
                 $json['sMarked'] = explode('|', $view->single_fields);
                 foreach ($json['gMarked'] as $k => $v) {
                     $json['gMarked'][$k] = '_' . $v;
                 }
                 foreach ($json['sMarked'] as $k => $v) {
                     $json['sMarked'][$k] = '_' . $v;
                 }
             }
         }
     }
     $this->response->setBody(json_encode($json, JSON_PRETTY_PRINT));
     $this->send(200, ['Content-Type' => 'application/json']);
 }