Пример #1
0
 public function movePageAction()
 {
     //Make sure the user is logged in first
     if (!\ATPAdmin\Auth::isLoggedIn()) {
         $this->getResponse()->setStatusCode(401);
         return;
     }
     //Get the node
     $nodeId = $this->params()->fromPost('nodeId');
     $node = new \ATPComic\Model\Node();
     $node->loadById($nodeId);
     //Get the arc
     $arc = $node->arc;
     //Get the direction
     $direction = $this->params()->fromPost('direction');
     //Move node
     $result = false;
     $prevPageName = " ";
     $nextPageName = " ";
     if ($direction == 'prev' && !$node->isFirst()) {
         //Get prev node
         $prevNode = $node->prevNode(false);
         //Get the new previous page name
         if (!$prevNode->isFirst()) {
             $prevPageName = $prevNode->prevNode(false)->page->title;
         }
         //Update page numbers
         $prevNode->pageNumber++;
         $node->pageNumber--;
         //Update next page name
         $nextPageName = $prevNode->page->title;
         //Save the nodes
         $prevNode->save();
         $node->save();
         $result = true;
     } else {
         if ($direction == 'next' && !$node->isLast(false)) {
             //Get prev node
             $nextNode = $node->nextNode(false);
             //Get the new next page name
             if (!$nextNode->isLast(false)) {
                 $nextPageName = $nextNode->nextNode(false)->page->title;
             }
             //Update page numbers
             $nextNode->pageNumber--;
             $node->pageNumber++;
             //Update next page name
             $prevPageName = $nextNode->page->title;
             //Save the nodes
             $nextNode->save();
             $node->save();
             $result = true;
         }
     }
     echo json_encode(array("result" => $result, "direction" => $direction, "prevPageName" => $prevPageName, "nextPageName" => $nextPageName));
     die;
 }
Пример #2
0
 protected function init($checkLogin = true)
 {
     $this->noCache();
     //Set password salt for user
     \ATPAdmin\Model\User::setPasswordSalt($this->config('admin.auth.password_salt'));
     //Check for logged in user
     $this->_validLogin = !$checkLogin || !$this->_checkLogin || \ATPAdmin\Auth::isLoggedIn();
     if (!$this->_validLogin) {
         $this->redirect()->toRoute('admin', array('action' => 'login'));
     }
     //Set the admin layout
     $this->layout("atp-admin/layout/admin");
     //Get the model information
     $this->models = $this->config('admin.models');
     $this->reports = $this->config('admin.reports');
     //Setup the view
     $this->view = new \Zend\View\Model\ViewModel();
     //Get the flash messenger
     $this->flash = $this->flashMessenger();
     $this->layout()->addChild(new \ATPCore\View\Widget\FlashWidget($this->flash), 'flash');
     //Create the admin menu
     $adminMenu = array();
     //Add the models
     foreach ($this->models as $model => $modelData) {
         if (!isset($adminMenu[$modelData['category']])) {
             $adminMenu[$modelData['category']] = array();
         }
         $linkData = array('action' => 'list', 'model' => \ATP\Inflector::underscore($model));
         if (isset($modelData['custom_actions']['list'])) {
             $linkData['controller'] = $modelData['custom_actions']['list']['controller'];
             $linkData['action'] = $modelData['custom_actions']['list']['action'];
         }
         $adminMenu[$modelData['category']][] = array('label' => \ATP\Inflector::pluralize($modelData['displayName']), 'linkData' => $linkData);
     }
     //Add the reports
     foreach ($this->reports as $report => $reportData) {
         if (!isset($adminMenu[$reportData['category']])) {
             $adminMenu[$reportData['category']] = array();
         }
         $adminMenu[$reportData['category']][] = array('label' => $reportData['label'], 'linkData' => array('action' => 'report', 'model' => $report));
     }
     $this->layout()->menu = $adminMenu;
     //Load the model data if needed
     $this->modelType = $this->params('model');
     if (!empty($this->modelType) && $this->params('action') != 'report') {
         $this->modelData = $this->models[$this->modelType];
     }
 }