/** * Loads the dataGrids */ private function loadDatagrids() { // load all categories $categories = BackendFaqModel::getCategories(true); // loop categories and create a dataGrid for each one foreach ($categories as $categoryId => $categoryTitle) { $dataGrid = new BackendDataGridDB(BackendFaqModel::QRY_DATAGRID_BROWSE, array(BL::getWorkingLanguage(), $categoryId)); $dataGrid->setAttributes(array('class' => 'dataGrid sequenceByDragAndDrop')); $dataGrid->setColumnsHidden(array('category_id', 'sequence')); $dataGrid->addColumn('dragAndDropHandle', null, '<span>' . BL::lbl('Move') . '</span>'); $dataGrid->setColumnsSequence('dragAndDropHandle'); $dataGrid->setColumnAttributes('question', array('class' => 'title')); $dataGrid->setColumnAttributes('dragAndDropHandle', array('class' => 'dragAndDropHandle')); $dataGrid->setRowAttributes(array('id' => '[id]')); // check if this action is allowed if (BackendAuthentication::isAllowedAction('edit')) { $dataGrid->setColumnURL('question', BackendModel::createURLForAction('edit') . '&id=[id]'); $dataGrid->addColumn('edit', null, BL::lbl('Edit'), BackendModel::createURLForAction('edit') . '&id=[id]', BL::lbl('Edit')); } // add dataGrid to list $this->dataGrids[] = array('id' => $categoryId, 'title' => $categoryTitle, 'content' => $dataGrid->getContent()); } // set empty datagrid $this->emptyDatagrid = new BackendDataGridArray(array(array('dragAndDropHandle' => '', 'question' => BL::msg('NoQuestionInCategory'), 'edit' => ''))); $this->emptyDatagrid->setAttributes(array('class' => 'dataGrid sequenceByDragAndDrop emptyGrid')); $this->emptyDatagrid->setHeaderLabels(array('edit' => null, 'dragAndDropHandle' => null)); }
/** * Load the datagrids * * @return void */ private function loadDataGrids() { // load all categories $categories = BackendFaqModel::getCategories(); // run over categories and create datagrid for each one foreach ($categories as $category) { // create datagrid $dataGrid = new BackendDataGridDB(BackendFaqModel::QRY_DATAGRID_BROWSE, array(BL::getWorkingLanguage(), $category['id'])); // set attributes $dataGrid->setAttributes(array('class' => 'dataGrid sequenceByDragAndDrop')); // disable paging $dataGrid->setPaging(false); // set colum URLs $dataGrid->setColumnURL('question', BackendModel::createURLForAction('edit') . '&id=[id]'); // set colums hidden $dataGrid->setColumnsHidden(array('category_id', 'sequence')); // add edit column $dataGrid->addColumn('edit', null, BL::lbl('Edit'), BackendModel::createURLForAction('edit') . '&id=[id]', BL::lbl('Edit')); // add a column for the handle, so users have something to hold while draging $dataGrid->addColumn('dragAndDropHandle', null, '<span>' . BL::lbl('Move') . '</span>'); // make sure the column with the handler is the first one $dataGrid->setColumnsSequence('dragAndDropHandle'); // add a class on the handler column, so JS knows this is just a handler $dataGrid->setColumnAttributes('dragAndDropHandle', array('class' => 'dragAndDropHandle')); // our JS needs to know an id, so we can send the new order $dataGrid->setRowAttributes(array('id' => '[id]')); // add datagrid to list $this->dataGrids[] = array('id' => $category['id'], 'name' => $category['name'], 'content' => $dataGrid->getContent()); } }
/** * Load the data */ private function loadData() { $allFeedback = BackendFaqModel::getAllFeedback(); // build the urls foreach ($allFeedback as $feedback) { $feedback['full_url'] = BackendModel::createURLForAction('edit', 'faq') . '&id=' . $feedback['question_id'] . '#tabFeedback'; $this->feedback[] = $feedback; } }
/** * Execute the action */ public function execute() { $feedbackId = $this->getParameter('id', 'int'); $feedback = BackendFaqModel::getFeedback($feedbackId); BackendModel::triggerEvent($this->getModule(), 'after_delete_feedback', array('item' => $feedback)); // there is no feedback data, so redirect if (empty($feedback)) { $this->redirect(BackendModel::createURLForAction('index') . '&error=non-existing'); } BackendFaqModel::deleteFeedback($feedbackId); $this->redirect(BackendModel::createURLForAction('edit') . '&id=' . $feedback['question_id'] . '&report=deleted#tabFeedback'); }
/** * 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=' . urlencode($this->record['question'])); } else { $this->redirect(BackendModel::createURLForAction('index') . '&error=non-existing'); } }
/** * 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'); }
/** * 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'); }
/** * Execute the action * * @return void */ public function execute() { // get parameters $this->id = $this->getParameter('id', 'int'); // does the item exist if ($this->id !== null && BackendFaqModel::existsCategory($this->id)) { // call parent, this will probably add some general CSS/JS or other required files parent::execute(); // get item $this->record = BackendFaqModel::getCategory($this->id); // delete item BackendFaqModel::deleteCategory($this->id); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_delete_category', array('id' => $this->id)); // item was deleted, so redirect $this->redirect(BackendModel::createURLForAction('categories') . '&report=deleted&var=' . urlencode($this->record['name'])); } else { $this->redirect(BackendModel::createURLForAction('categories') . '&error=non-existing'); } }
/** * Execute the action */ public function execute() { $this->id = $this->getParameter('id', 'int'); // does the item exist if ($this->id !== null && BackendFaqModel::existsCategory($this->id)) { $this->record = (array) BackendFaqModel::getCategory($this->id); if (BackendFaqModel::deleteCategoryAllowed($this->id)) { parent::execute(); // delete item BackendFaqModel::deleteCategory($this->id); BackendModel::triggerEvent($this->getModule(), 'after_delete_category', array('item' => $this->record)); // category was deleted, so redirect $this->redirect(BackendModel::createURLForAction('categories') . '&report=deleted-category&var=' . urlencode($this->record['title'])); } else { $this->redirect(BackendModel::createURLForAction('categories') . '&error=delete-category-not-allowed&var=' . urlencode($this->record['title'])); } } else { $this->redirect(BackendModel::createURLForAction('categories') . '&error=non-existing'); } }
/** * 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 $newIdSequence = trim(SpoonFilter::getPostValue('new_id_sequence', null, '', 'string')); // list id $ids = (array) explode(',', rtrim($newIdSequence, ',')); // loop id's and set new sequence foreach ($ids as $i => $id) { // build item $item['id'] = (int) $id; // change sequence $item['sequence'] = $i + 1; // update sequence if (BackendFaqModel::existsCategory($item['id'])) { BackendFaqModel::updateCategory($item); } } // success output $this->output(self::OK, null, 'sequence updated'); }
/** * Validate the form */ private function validateForm() { if ($this->frm->isSubmitted()) { $this->meta->setURLCallback('BackendFaqModel', 'getURLForCategory'); $this->frm->cleanupFields(); // validate fields $this->frm->getField('title')->isFilled(BL::err('TitleIsRequired')); $this->meta->validate(); if ($this->frm->isCorrect()) { // build item $item['title'] = $this->frm->getField('title')->getValue(); $item['language'] = BL::getWorkingLanguage(); $item['meta_id'] = $this->meta->save(); $item['sequence'] = BackendFaqModel::getMaximumCategorySequence() + 1; // save the data $item['id'] = BackendFaqModel::insertCategory($item); BackendModel::triggerEvent($this->getModule(), 'after_add_category', array('item' => $item)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('categories') . '&report=added-category&var=' . urlencode($item['title']) . '&highlight=row-' . $item['id']); } } }
/** * Validate the form */ private function validateForm() { if ($this->frm->isSubmitted()) { $this->meta->setUrlCallback('BackendFaqModel', 'getURLForCategory', array($this->record['id'])); $this->frm->cleanupFields(); // validate fields $this->frm->getField('title')->isFilled(BL::err('TitleIsRequired')); $this->meta->validate(); if ($this->frm->isCorrect()) { // build item $item['id'] = $this->id; $item['language'] = $this->record['language']; $item['title'] = $this->frm->getField('title')->getValue(); $item['meta_id'] = $this->meta->save(true); // update the item BackendFaqModel::updateCategory($item); BackendModel::triggerEvent($this->getModule(), 'after_edit_category', array('item' => $item)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('categories') . '&report=edited-category&var=' . urlencode($item['title']) . '&highlight=row-' . $item['id']); } } }
/** * 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('name')->isFilled(BL::err('NameIsRequired')); // no errors? if ($this->frm->isCorrect()) { // build item $item['language'] = BL::getWorkingLanguage(); $item['name'] = $this->frm->getField('name')->getValue(); $item['sequence'] = BackendFaqModel::getMaximumCategorySequence() + 1; // insert the item $item['id'] = BackendFaqModel::insertCategory($item); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_add_category', array('item' => $item)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('categories') . '&report=added-category&var=' . urlencode($item['name']) . '&highlight=row-' . $item['id']); } } }
/** * 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']); } } }
/** * 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['user_id'] = BackendAuthentication::getUser()->getUserId(); $item['category_id'] = $this->frm->getField('categories')->getValue(); $item['language'] = BL::getWorkingLanguage(); $item['question'] = $this->frm->getField('question')->getValue(); $item['answer'] = $this->frm->getField('answer')->getValue(true); $item['hidden'] = $this->frm->getField('hidden')->getValue(); $item['sequence'] = BackendFaqModel::getMaximumQuestionSequence($this->frm->getField('categories')->getValue()) + 1; $item['created_on'] = BackendModel::getUTCDate(); // insert the item $item['id'] = BackendFaqModel::insertQuestion($item); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_add', array('item' => $item)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('index') . '&report=added&var=' . urlencode($item['question']) . '&highlight=row-' . $item['id']); } } }
/** * 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']); } } }
/** * Validate the form */ private function validateForm() { if ($this->frm->isSubmitted()) { $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['meta_id'] = $this->meta->save(); $item['category_id'] = $this->frm->getField('category_id')->getValue(); $item['user_id'] = BackendAuthentication::getUser()->getUserId(); $item['language'] = BL::getWorkingLanguage(); $item['question'] = $this->frm->getField('title')->getValue(); $item['answer'] = $this->frm->getField('answer')->getValue(true); $item['created_on'] = BackendModel::getUTCDate(); $item['hidden'] = $this->frm->getField('hidden')->getValue(); $item['sequence'] = BackendFaqModel::getMaximumSequence($this->frm->getField('category_id')->getValue()) + 1; // save the data $item['id'] = BackendFaqModel::insert($item); BackendTagsModel::saveTags($item['id'], $this->frm->getField('tags')->getValue(), $this->URL->getModule()); BackendModel::triggerEvent($this->getModule(), 'after_add', array('item' => $item)); // add search index BackendSearchModel::saveIndex('faq', $item['id'], array('title' => $item['question'], 'text' => $item['answer'])); $this->redirect(BackendModel::createURLForAction('index') . '&report=added&var=' . urlencode($item['question']) . '&highlight=row-' . $item['id']); } } }