Get the data for a record
public static get ( integer $id, integer $revisionId = null, string $language = null ) : mixed | ||
$id | integer | The Id of the page to fetch. |
$revisionId | integer | |
$language | string | The language to use while fetching the page. |
return | mixed | False if the record can't be found, otherwise an array with all data. |
/** * Execute the action */ public function execute() { // call parent parent::execute(); // get parameters $id = \SpoonFilter::getPostValue('id', null, 0, 'int'); // validate if ($id === 0) { $this->output(self::BAD_REQUEST, null, 'no id provided'); } else { // get page $page = BackendPagesModel::get($id); // output $this->output(self::OK, $page); } }
/** * Execute the action */ public function execute() { // get parameters $this->id = $this->getParameter('id', 'int'); // does the item exist if ($this->id !== null && BackendPagesModel::exists($this->id)) { // call parent, this will probably add some general CSS/JS or other required files parent::execute(); // init var $success = false; // cannot have children if (BackendPagesModel::getFirstChildId($this->id) !== false) { $this->redirect(BackendModel::createURLForAction('Edit') . '&error=non-existing'); } $revisionId = $this->getParameter('revision_id', 'int'); if ($revisionId == 0) { $revisionId = null; } // get page (we need the title) $page = BackendPagesModel::get($this->id, $revisionId); // valid page? if (!empty($page)) { // delete the page $success = BackendPagesModel::delete($this->id, null, $revisionId); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_delete', array('id' => $this->id)); // delete search indexes BackendSearchModel::removeIndex($this->getModule(), $this->id); // build cache BackendPagesModel::buildCache(BL::getWorkingLanguage()); } // page is deleted, so redirect to the overview if ($success) { $this->redirect(BackendModel::createURLForAction('Index') . '&id=' . $page['parent_id'] . '&report=deleted&var=' . rawurlencode($page['title'])); } else { $this->redirect(BackendModel::createURLForAction('Edit') . '&error=non-existing'); } } else { $this->redirect(BackendModel::createURLForAction('Edit') . '&error=non-existing'); } }
/** * Execute the action */ public function execute() { // call parent parent::execute(); // get parameters $id = \SpoonFilter::getPostValue('id', null, 0, 'int'); $droppedOn = \SpoonFilter::getPostValue('dropped_on', null, -1, 'int'); $typeOfDrop = \SpoonFilter::getPostValue('type', null, ''); $tree = \SpoonFilter::getPostValue('tree', array('main', 'meta', 'footer', 'root'), ''); // init validation $errors = array(); // validate if ($id === 0) { $errors[] = 'no id provided'; } if ($droppedOn === -1) { $errors[] = 'no dropped_on provided'; } if ($typeOfDrop == '') { $errors[] = 'no type provided'; } if ($tree == '') { $errors[] = 'no tree provided'; } // got errors if (!empty($errors)) { $this->output(self::BAD_REQUEST, array('errors' => $errors), 'not all fields were filled'); } else { // get page $success = BackendPagesModel::move($id, $droppedOn, $typeOfDrop, $tree); // build cache BackendPagesModel::buildCache(BL::getWorkingLanguage()); // output if ($success) { $this->output(self::OK, BackendPagesModel::get($id), 'page moved'); } else { $this->output(self::ERROR, null, 'page not moved'); } } }
/** * Load the record */ private function loadData() { // get record $this->id = $this->getParameter('id', 'int'); $this->isGod = BackendAuthentication::getUser()->isGod(); // check if something went wrong if ($this->id === null || !BackendPagesModel::exists($this->id)) { $this->redirect(BackendModel::createURLForAction('Index') . '&error=non-existing'); } // get the record $this->record = BackendPagesModel::get($this->id); // load blocks $this->blocksContent = BackendPagesModel::getBlocks($this->id, $this->record['revision_id']); // is there a revision specified? $revisionToLoad = $this->getParameter('revision', 'int'); // if this is a valid revision if ($revisionToLoad !== null) { // overwrite the current record $this->record = (array) BackendPagesModel::get($this->id, $revisionToLoad); // load blocks $this->blocksContent = BackendPagesModel::getBlocks($this->id, $revisionToLoad); // show warning $this->tpl->assign('appendRevision', true); } // is there a revision specified? $draftToLoad = $this->getParameter('draft', 'int'); // if this is a valid revision if ($draftToLoad !== null) { // overwrite the current record $this->record = (array) BackendPagesModel::get($this->id, $draftToLoad); // load blocks $this->blocksContent = BackendPagesModel::getBlocks($this->id, $draftToLoad); // show warning $this->tpl->assign('appendRevision', true); } // reset some vars $this->record['full_url'] = BackendPagesModel::getFullURL($this->record['id']); $this->record['is_hidden'] = $this->record['hidden'] == 'Y'; }