예제 #1
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']);
 }
예제 #2
0
 /**
  * Get count of fields
  *
  * @return int
  */
 public function getCount()
 {
     return Table\Fields::findAll()->count();
 }
예제 #3
0
 /**
  * Copy form
  *
  * @param  int $id
  * @param  \Pop\Module\Manager $modules
  * @return void
  */
 public function copy($id, \Pop\Module\Manager $modules = null)
 {
     $oldForm = Table\Forms::findById((int) $id);
     if (isset($oldForm->id)) {
         $i = 1;
         $name = $oldForm->name . ' (Copy ' . $i . ')';
         $dupeForm = Table\forms::findBy(['name' => $name]);
         while (isset($dupeForm->id)) {
             $i++;
             $name = $oldForm->name . ' (Copy ' . $i . ')';
             $dupeForm = Table\forms::findBy(['name' => $name]);
         }
         $form = new Table\Forms(['name' => $name, 'method' => !empty($oldForm->method) ? $oldForm->method : null, 'to' => !empty($oldForm->to) ? $oldForm->to : null, 'from' => !empty($oldForm->from) ? $oldForm->from : null, 'reply_to' => !empty($oldForm->reply_to) ? $oldForm->reply_to : null, 'action' => !empty($oldForm->action) ? $oldForm->action : null, 'redirect' => !empty($oldForm->redirect) ? $oldForm->redirect : null, 'attributes' => !empty($oldForm->attributes) ? $oldForm->attributes : null, 'submit_value' => !empty($oldForm->submit_value) ? $oldForm->submit_value : null, 'submit_attributes' => !empty($oldForm->submit_attributes) ? $oldForm->submit_attributes : null, 'use_captcha' => !empty($oldForm->use_captcha) ? (int) $oldForm->use_captcha : null, 'use_csrf' => !empty($oldForm->use_csrf) ? (int) $oldForm->use_csrf : null, 'force_ssl' => !empty($oldForm->force_ssl) ? (int) $oldForm->force_ssl : null]);
         $form->save();
         $flds = null;
         if (null !== $modules && $modules->isRegistered('phire-fields')) {
             $flds = \Phire\Fields\Table\Fields::findAll();
         }
         if (null !== $flds) {
             foreach ($flds->rows() as $f) {
                 if (!empty($f->models)) {
                     $models = unserialize($f->models);
                     print_r($models);
                     foreach ($models as $model) {
                         if ($model['model'] == 'Phire\\Forms\\Model\\Form' && $oldForm->id == $model['type_value']) {
                             $models[] = ['model' => 'Phire\\Forms\\Model\\Form', 'type_field' => 'id', 'type_value' => $form->id];
                             $newField = \Phire\Fields\Table\Fields::findById($f->id);
                             if (isset($newField->id)) {
                                 $newField->models = serialize($models);
                                 $newField->save();
                             }
                         }
                     }
                 }
             }
         }
     }
 }