/** * Add a page to an exhibit. * * The URL param 'id' refers to the exhibit that will contain the page, and * 'previous' refers to an existing page the new one will be placed after. */ public function addPageAction() { $db = $this->_helper->db->getDb(); $request = $this->getRequest(); $exhibitId = $request->getParam('id'); //check if a parent page is coming in $previousPageId = $request->getParam('previous'); $exhibitPage = new ExhibitPage(); $exhibitPage->exhibit_id = $exhibitId; $exhibit = $exhibitPage->getExhibit(); //Set the order for the new page if ($previousPageId) { //set the order to be right after the previous one. Page's beforeSave method will bump up later page orders as needed $previousPage = $db->getTable('ExhibitPage')->find($previousPageId); $exhibitPage->parent_id = $previousPage->parent_id; $exhibitPage->order = $previousPage->order + 1; } else { $childCount = $exhibit->countPages(true); $exhibitPage->order = $childCount + 1; } $success = $this->processPageForm($exhibitPage, 'Add', $exhibit); if ($success) { $this->_helper->flashMessenger("Changes to the exhibit's page were successfully saved!", 'success'); if (array_key_exists('add-another-page', $_POST)) { $this->_helper->redirector->gotoRoute(array('action' => 'add-page', 'id' => $exhibit->id, 'previous' => $exhibitPage->id), 'exhibitStandard'); } else { $this->_helper->redirector->gotoRoute(array('action' => 'edit-page', 'id' => $exhibitPage->id), 'exhibitStandard'); } return; } $this->render('page-form'); }