Esempio n. 1
0
 /**
  * Get count of field groups
  *
  * @return int
  */
 public function getCount()
 {
     return Table\FieldGroups::findAll()->count();
 }
Esempio n. 2
0
 /**
  * Edit action method
  *
  * @param  int $id
  * @return void
  */
 public function edit($id)
 {
     $field = new Model\Field();
     $field->getById($id);
     $fields = $this->application->config()['forms']['Phire\\Fields\\Form\\Field'];
     if (!file_exists(getcwd() . CONTENT_PATH . '/modules/phire/assets/js/ckeditor')) {
         unset($fields[1]['editor']['value']['ckeditor-local']);
     }
     if (!file_exists(getcwd() . CONTENT_PATH . '/modules/phire/assets/js/tinymce')) {
         unset($fields[1]['editor']['value']['tinymce-local']);
     }
     if (null !== $field->editor) {
         $fields[1]['editor']['attributes']['style'] = 'display: block;';
     }
     $groups = Table\FieldGroups::findAll();
     foreach ($groups->rows() as $group) {
         $fields[0]['group_id']['value'][$group->id] = $group->name;
     }
     $models = $this->application->module('phire-fields')->config()['models'];
     foreach ($models as $model => $type) {
         $fields[4]['model_1']['value'][$model] = $model;
     }
     $this->prepareView('fields/edit.phtml');
     $this->view->title = 'Fields : Edit';
     $this->view->field_name = $field->name;
     $fields[2]['name']['attributes']['onkeyup'] = 'phire.changeTitle(this.value);';
     $this->view->form = new Form\Field($fields);
     $this->view->form->addFilter('htmlentities', [ENT_QUOTES, 'UTF-8'])->setFieldValues($field->toArray());
     if ($this->request->isPost()) {
         $this->view->form->addFilter('strip_tags')->setFieldValues($this->request->getPost());
         if ($this->view->form->isValid()) {
             $this->view->form->clearFilters()->addFilter('html_entity_decode', [ENT_QUOTES, 'UTF-8'])->filter();
             $field = new Model\Field();
             $field->update($this->view->form->getFields());
             $this->view->id = $field->id;
             $this->sess->setRequestValue('saved', true);
             $this->redirect(BASE_PATH . APP_URI . '/fields/edit/' . $field->id);
         }
     }
     $this->send();
 }
Esempio n. 3
0
 /**
  * Add dynamic fields to the form configs
  *
  * @param  Application $application
  * @return void
  */
 public static function addFields(Application $application)
 {
     $forms = $application->config()['forms'];
     $fields = Table\Fields::findBy(['group_id' => null], ['order' => 'order'], Table\FieldGroups::ROW_AS_ARRAYOBJECT);
     $groups = Table\FieldGroups::findAll(['order' => 'order'], Table\FieldGroups::ROW_AS_ARRAYOBJECT);
     if ($fields->count() > 0) {
         foreach ($fields->rows() as $field) {
             $field->validators = unserialize($field->validators);
             $field->models = unserialize($field->models);
             foreach ($field->models as $i => $model) {
                 if ($model['model'] == 'Phire\\Model\\User') {
                     $register = $model;
                     $registerEmail = $model;
                     $profile = $model;
                     $profileEmail = $model;
                     $register['model'] = 'Phire\\Model\\Register';
                     $registerEmail['model'] = 'Phire\\Model\\RegisterEmail';
                     $profile['model'] = 'Phire\\Model\\Profile';
                     $profileEmail['model'] = 'Phire\\Model\\ProfileEmail';
                     $field->models[] = $register;
                     $field->models[] = $registerEmail;
                     $field->models[] = $profile;
                     $field->models[] = $profileEmail;
                 }
             }
             foreach ($field->models as $model) {
                 $form = str_replace('Model', 'Form', $model['model']);
                 if (isset($forms[$form]) && self::isAllowed($model, $application)) {
                     end($forms[$form]);
                     $key = key($forms[$form]);
                     reset($forms[$form]);
                     $fieldConfig = self::createFieldConfig($field);
                     if ($form == 'Phire\\Form\\Register' || $form == 'Phire\\Form\\RegisterEmail' || $form == 'Phire\\Form\\Profile' || $form == 'Phire\\Form\\ProfileEmail') {
                         $forms[$form][1]['field_' . $field->id] = $fieldConfig;
                     } else {
                         if ($field->dynamic) {
                             if (isset($fieldConfig['label'])) {
                                 $fieldConfig['label'] = '<a href="#" onclick="return phire.addField(' . $field->id . ');">[+]</a> ' . $fieldConfig['label'];
                             } else {
                                 $fieldConfig['label'] = '<a href="#" onclick="return phire.addField(' . $field->id . ');">[+]</a>';
                             }
                             if (isset($fieldConfig['attributes'])) {
                                 $fieldConfig['attributes']['data-path'] = BASE_PATH . APP_URI;
                                 $fieldConfig['attributes']['data-model'] = $model['model'];
                             } else {
                                 $fieldConfig['attributes'] = ['data-path' => BASE_PATH . APP_URI, 'data-model' => $model['model']];
                             }
                         }
                         if (is_numeric($key)) {
                             if ($field->prepend) {
                                 $forms[$form][$key] = array_merge(['field_' . $field->id => $fieldConfig], $forms[$form][$key]);
                             } else {
                                 $forms[$form][$key]['field_' . $field->id] = $fieldConfig;
                             }
                         } else {
                             if ($field->prepend) {
                                 $forms[$form] = array_merge(['field_' . $field->id => $fieldConfig], $forms[$form]);
                             } else {
                                 $forms[$form]['field_' . $field->id] = $fieldConfig;
                             }
                         }
                     }
                 }
             }
         }
     }
     $fieldGroups = [];
     $groupPrepend = [];
     if ($groups->count() > 0) {
         $tab = 1001;
         foreach ($groups->rows() as $group) {
             $groupPrepend[$group->id] = (bool) $group->prepend;
             $fields = Table\Fields::findBy(['group_id' => $group->id], ['order' => 'order']);
             if ($fields->count() > 0) {
                 $i = 0;
                 foreach ($fields->rows() as $field) {
                     $field->validators = unserialize($field->validators);
                     $field->models = unserialize($field->models);
                     foreach ($field->models as $model) {
                         $form = str_replace('Model', 'Form', $model['model']);
                         if (isset($forms[$form]) && self::isAllowed($model, $application)) {
                             $fieldConfig = self::createFieldConfig($field);
                             if ($field->dynamic) {
                                 if (isset($fieldConfig['label'])) {
                                     $fieldConfig['label'] = '<a href="#" onclick="return phire.addField(' . $field->id . ');">[+]</a> ' . $fieldConfig['label'];
                                 } else {
                                     $fieldConfig['label'] = '<a href="#" onclick="return phire.addField(' . $field->id . ']);">[+]</a>';
                                 }
                             }
                             if (isset($fieldConfig['attributes'])) {
                                 $fieldConfig['attributes']['tabindex'] = $tab;
                                 $fieldConfig['attributes']['data-path'] = BASE_PATH . APP_URI;
                                 $fieldConfig['attributes']['data-model'] = $model['model'];
                             } else {
                                 $fieldConfig['attributes'] = ['tabindex' => $tab, 'data-path' => BASE_PATH . APP_URI, 'data-model' => $model['model']];
                             }
                             $tab++;
                             if (!isset($fieldGroups[$form])) {
                                 $fieldGroups[$form] = [];
                             }
                             if (!isset($fieldGroups[$form][$field->group_id])) {
                                 $fieldGroups[$form][$field->group_id] = [];
                             }
                             if ($field->prepend) {
                                 $fieldGroups[$form][$field->group_id] = array_merge(['field_' . $field->id => $fieldConfig], $fieldGroups[$form][$field->group_id]);
                             } else {
                                 $fieldGroups[$form][$field->group_id]['field_' . $field->id] = $fieldConfig;
                             }
                         }
                     }
                     $i++;
                 }
             }
         }
     }
     foreach ($fieldGroups as $form => $configs) {
         $keys = array_keys($forms[$form]);
         $numeric = true;
         foreach ($keys as $key) {
             if (!is_numeric($key)) {
                 $numeric = false;
             }
         }
         $formConfig = $numeric ? $forms[$form] : [$forms[$form]];
         foreach ($configs as $id => $config) {
             if ($groupPrepend[$id]) {
                 $formConfig = array_merge($config, $formConfig);
             } else {
                 $formConfig[] = $config;
             }
         }
         $forms[$form] = $formConfig;
     }
     $application->mergeConfig(['forms' => $forms], true);
 }