Пример #1
0
 /**
  * Execute the action
  *
  * @return	void
  */
 public function execute()
 {
     // call parent, this will probably add some general CSS/JS or other required files
     parent::execute();
     // get parameters
     $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::existsQuestion($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) {
         // build item
         $item['id'] = $questionId;
         $item['category_id'] = $toCategoryId;
         // update the category
         BackendFaqModel::updateQuestion($item);
         // loop id's and set new sequence
         foreach ($toCategorySequence as $i => $id) {
             // build item
             $item = array();
             $item['id'] = (int) $id;
             $item['sequence'] = $i + 1;
             // update sequence
             if (BackendFaqModel::existsQuestion($item['id'])) {
                 BackendFaqModel::updateQuestion($item);
             }
         }
     }
     // loop id's and set new sequence
     foreach ($fromCategorySequence as $i => $id) {
         // build item
         $item['id'] = (int) $id;
         $item['sequence'] = $i + 1;
         // update sequence
         if (BackendFaqModel::existsQuestion($item['id'])) {
             BackendFaqModel::updateQuestion($item);
         }
     }
     // success output
     $this->output(self::OK, null, 'sequence updated');
 }
Пример #2
0
 /**
  * Validate the form
  *
  * @return	void
  */
 private function validateForm()
 {
     // is the form submitted?
     if ($this->frm->isSubmitted()) {
         // cleanup the submitted fields, ignore fields that were added by hackers
         $this->frm->cleanupFields();
         // validate fields
         $this->frm->getField('question')->isFilled(BL::err('QuestionIsRequired'));
         $this->frm->getField('answer')->isFilled(BL::err('AnswerIsRequired'));
         $this->frm->getField('categories')->isFilled(BL::err('CategoryIsRequired'));
         // no errors?
         if ($this->frm->isCorrect()) {
             // build item
             $item['id'] = $this->id;
             $item['language'] = $this->record['language'];
             $item['category_id'] = $this->frm->getField('categories')->getValue();
             $item['question'] = $this->frm->getField('question')->getValue();
             $item['answer'] = $this->frm->getField('answer')->getValue(true);
             $item['hidden'] = $this->frm->getField('hidden')->getValue();
             // update question values in database
             BackendFaqModel::updateQuestion($item);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_edit', array('item' => $item));
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('index') . '&report=saved&var=' . urlencode($item['question']) . '&highlight=row-' . $item['id']);
         }
     }
 }