Пример #1
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     $questionId = SpoonFilter::getPostValue('questionId', null, '', 'int');
     $fromCategoryId = SpoonFilter::getPostValue('fromCategoryId', null, '', 'int');
     $toCategoryId = SpoonFilter::getPostValue('toCategoryId', null, '', 'int');
     $fromCategorySequence = SpoonFilter::getPostValue('fromCategorySequence', null, '', 'string');
     $toCategorySequence = SpoonFilter::getPostValue('toCategorySequence', null, '', 'string');
     // invalid question id
     if (!BackendFaqModel::exists($questionId)) {
         $this->output(self::BAD_REQUEST, null, 'question does not exist');
     }
     // list ids
     $fromCategorySequence = (array) explode(',', ltrim($fromCategorySequence, ','));
     $toCategorySequence = (array) explode(',', ltrim($toCategorySequence, ','));
     // is the question moved to a new category?
     if ($fromCategoryId != $toCategoryId) {
         $item['id'] = $questionId;
         $item['category_id'] = $toCategoryId;
         BackendFaqModel::update($item);
         // loop id's and set new sequence
         foreach ($toCategorySequence as $i => $id) {
             $item = array();
             $item['id'] = (int) $id;
             $item['sequence'] = $i + 1;
             // update sequence if the item exists
             if (BackendFaqModel::exists($item['id'])) {
                 BackendFaqModel::update($item);
             }
         }
     }
     // loop id's and set new sequence
     foreach ($fromCategorySequence as $i => $id) {
         $item['id'] = (int) $id;
         $item['sequence'] = $i + 1;
         // update sequence if the item exists
         if (BackendFaqModel::exists($item['id'])) {
             BackendFaqModel::update($item);
         }
     }
     // success output
     $this->output(self::OK, null, 'sequence updated');
 }
Пример #2
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->meta->setUrlCallback('BackendFaqModel', 'getURL', array($this->record['id']));
         $this->frm->cleanupFields();
         // validate fields
         $this->frm->getField('title')->isFilled(BL::err('QuestionIsRequired'));
         $this->frm->getField('answer')->isFilled(BL::err('AnswerIsRequired'));
         $this->frm->getField('category_id')->isFilled(BL::err('CategoryIsRequired'));
         $this->meta->validate();
         if ($this->frm->isCorrect()) {
             // build item
             $item['id'] = $this->id;
             $item['meta_id'] = $this->meta->save(true);
             $item['category_id'] = $this->frm->getField('category_id')->getValue();
             $item['language'] = $this->record['language'];
             $item['question'] = $this->frm->getField('title')->getValue();
             $item['answer'] = $this->frm->getField('answer')->getValue(true);
             $item['hidden'] = $this->frm->getField('hidden')->getValue();
             // update the item
             BackendFaqModel::update($item);
             BackendTagsModel::saveTags($item['id'], $this->frm->getField('tags')->getValue(), $this->URL->getModule());
             BackendModel::triggerEvent($this->getModule(), 'after_edit', array('item' => $item));
             // edit search index
             BackendSearchModel::editIndex('faq', $item['id'], array('title' => $item['question'], 'text' => $item['answer']));
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('index') . '&report=saved&var=' . urlencode($item['question']) . '&highlight=row-' . $item['id']);
         }
     }
 }