예제 #1
0
 /**
  * Remove a view
  *
  * @param  array $fields
  * @return void
  */
 public function remove(array $fields)
 {
     if (isset($fields['rm_views'])) {
         foreach ($fields['rm_views'] as $id) {
             $view = Table\Views::findById((int) $id);
             if (isset($view->id)) {
                 $view->delete();
             }
         }
     }
 }
예제 #2
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']);
 }