Esempio n. 1
0
 public function view()
 {
     if (!is_numeric($this->_context[0])) {
         $this->_status = 400;
         $this->_Result = json_encode(array('error' => __('Invalid section ID.')));
     } else {
         if (!($section = SectionManager::fetch((int) $this->_context[0]) && is_numeric($this->_context[0]))) {
             $this->_status = 404;
             $this->_Result = json_encode(array('error' => __('The section specified does not exist.')));
         } else {
             $fields = array(array('id' => '0', 'title' => 'Use Entry ID Number'));
             foreach (ApiPage::getFieldObjects($this->_context[0]) as $field) {
                 $fields[] = array('id' => $field->get('id'), 'title' => $field->get('label'));
             }
             $this->_Result = json_encode($fields);
         }
     }
 }
 public function __viewEdit()
 {
     $isNew = true;
     //Check if the Api Page ID passed in the URL exists
     if ($this->_context[0] == 'edit') {
         $isNew = false;
         if (!($setting_id = $this->_context[1])) {
             redirect(extension_RestEngine::baseURL() . 'settings/');
         }
         if (!($existing = RestResourceManager::fetch($setting_id))) {
             throw new SymphonyErrorPage(__('The API Resource page you requested to edit does not exist.'), __('API Page not found'), 'error');
         }
     }
     Administration::instance()->Page->addScriptToHead(URL . '/extensions/restengine/assets/restengine.fields.js');
     //Page Alerts from forms
     if (isset($this->_context[2])) {
         switch ($this->_context[2]) {
             case 'saved':
                 $this->pageAlert(__('API Resource Setting updated at %1$s. <a href="%2$s" accesskey="c">Create another?</a> <a href="%3$s" accesskey="a">View all Settings</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), extension_RestEngine::baseURL() . 'settings/new/', extension_RestEngine::baseURL() . 'settings/')), Alert::SUCCESS);
                 break;
             case 'created':
                 $this->pageAlert(__('API Resource created at %1$s. <a href="%2$s" accesskey="c">Create another?</a> <a href="%3$s" accesskey="a">View all Roles</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), extension_RestEngine::baseURL() . 'settings/new/', extension_RestEngine::baseURL() . 'settings/')), Alert::SUCCESS);
                 break;
         }
     }
     $formHasErrors = is_array($this->_errors) && !empty($this->_errors);
     if ($formHasErrors) {
         $this->pageAlert(__('An error occurred while processing this form. <a href="#error">See below for details.</a>'), Alert::ERROR);
     }
     $this->setPageType('form');
     if ($isNew) {
         $this->setTitle(__('Symphony &ndash; RestEngine API Resource Settings'));
         $this->appendSubheading(__('Untitled'));
         $fields = array('page_id' => null, 'section_id' => null, 'field_id' => null, 'uid_parameter' => null, 'format_parameter' => null);
     } else {
         $this->setTitle(__('Symphony &ndash; RestEngine API Resource Settings &ndash; ') . $existing->get('page_title'));
         $this->appendSubheading($existing->get('page_title'));
         if (isset($_POST['fields'])) {
             $fields = $_POST['fields'];
         } else {
             $fields = array('page_id' => $existing->get('page_id'), 'section_id' => $existing->get('section_id'), 'field_id' => $existing->get('field_id'), 'uid_parameter' => $existing->get('uid_parameter'), 'format_parameter' => $existing->get('format_parameter'));
         }
     }
     $this->insertBreadcrumbs(array(Widget::Anchor(__('RestEngine API Resources'), extension_RestEngine::baseURL() . 'settings/')));
     $fieldset = new XMLElement('fieldset');
     $fieldset->setAttribute('class', 'settings type-file');
     $fieldset->appendChild(new XMLElement('legend', __('API Resource Settings')));
     $pageLabel = Widget::Label(__('Page'));
     $pageLabel->appendChild(Widget::Select('fields[page_id]', ApiPage::getPageList($fields['page_id'])));
     $sectionLabel = Widget::Label(__('Section'));
     $sectionLabel->appendChild(Widget::Select('fields[section_id]', ApiPage::getSectionList($fields['section_id']), array('id' => 'section')));
     $fieldLabel = Widget::Label(__('Field to use as unique ID in resource URL'));
     $fieldLabel->appendChild(Widget::Select('fields[field_id]', ApiPage::getFieldList($fields['section_id'], $fields['field_id']), array('id' => 'field')));
     $uid_parameterLabel = Widget::Label(__('URL Parameter to use as unique ID in resource URL'));
     $uid_parameterLabel->appendChild(Widget::Input('fields[uid_parameter]', $fields['uid_parameter']));
     $format_parameterLabel = Widget::Label(__('Response Format URL Parameter (optional)'));
     $format_parameterLabel->appendChild(Widget::Input('fields[format_parameter]', $fields['format_parameter']));
     if (isset($this->_errors['page_id'])) {
         //TODO: fix this error wrapping bit
         $fieldset->appendChild(Widget::Error($pageLabel, $this->_errors['name']));
     } else {
         $fieldset->appendChildArray(array($pageLabel, $sectionLabel, $fieldLabel, $uid_parameterLabel, $format_parameterLabel));
     }
     $this->Form->appendChild($fieldset);
     $div = new XMLElement('div');
     $div->setAttribute('class', 'actions');
     $div->appendChild(Widget::Input('action[save]', __('Save Changes'), 'submit', array('accesskey' => 's')));
     if (!$isNew) {
         $deleteButton = new XMLElement('button', __('Delete'));
         $deleteButton->setAttributeArray(array('name' => 'action[delete]', 'class' => 'button confirm delete', 'title' => __('Delete this API Resource'), 'type' => 'submit', 'accesskey' => 'd'));
         $div->appendChild($deleteButton);
     }
     $this->Form->appendChild($div);
 }