/** * Execute the action */ public function execute() { $this->id = $this->getParameter('id', 'int'); if ($this->id !== null && BackendFaqModel::exists($this->id)) { parent::execute(); $this->record = BackendFaqModel::get($this->id); // delete item BackendFaqModel::delete($this->id); BackendModel::triggerEvent($this->getModule(), 'after_delete', array('item' => $this->record)); $this->redirect(BackendModel::createURLForAction('Index') . '&report=deleted&var=' . rawurlencode($this->record['question'])); } else { $this->redirect(BackendModel::createURLForAction('Index') . '&error=non-existing'); } }
/** * Execute the action */ public function execute() { $this->id = $this->getParameter('id', 'int'); // does the item exists if ($this->id !== null && BackendFaqModel::exists($this->id)) { parent::execute(); $this->getData(); $this->loadForm(); $this->validateForm(); $this->parse(); $this->display(); } else { $this->redirect(BackendModel::createURLForAction('Index') . '&error=non-existing'); } }
/** * 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'); } else { // 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'); } }