예제 #1
0
 public function run()
 {
     $pages = array();
     foreach ($this->loadMultiple() as $schedule) {
         //Check the day of the week before releasing page
         $day = strtolower(date("l"));
         if (!$schedule->{$day}) {
             continue;
         }
         //Get the schedules arc id
         $arcId = $schedule->arcId;
         //Get the next node to release
         $options = array('where' => 'arc_id = ? and is_active = 0', 'orderBy' => 'page_number ASC', 'limit 1', 'data' => array($arcId));
         $node = new \ATPComic\Model\Node();
         $nodes = $node->loadMultiple($options);
         $node = count($nodes) > 0 ? $nodes[0] : null;
         //If there are no more pages, then skip this arc
         if (is_null($node)) {
             continue;
         }
         //Release the page
         $page = $node->page;
         $page->isActive = 1;
         $page->postDate = date('Y-m-d H:i:s');
         $page->save();
         $pages[] = $page;
     }
     return $pages;
 }
예제 #2
0
 public function getPageNodes()
 {
     if (is_null($this->_pageNodes)) {
         $options = array('where' => 'arc_id = ? and is_active=1', 'orderBy' => 'page_number ASC', 'data' => array($this->id));
         $node = new \ATPComic\Model\Node();
         $this->_pageNodes = $node->loadMultiple($options);
     }
     return $this->_pageNodes;
 }
예제 #3
0
 public function bookmarkAction()
 {
     $this->noCache();
     if (isset($this->remember->currentComicPage)) {
         $nodeId = $this->remember->currentComicPage;
         $node = new \ATPComic\Model\Node();
         $node->loadById($nodeId);
         $this->redirect()->toRoute('comic/page', $node->getRoutingData());
     } else {
         $this->redirect()->toRoute('home');
     }
 }
예제 #4
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;
 }
예제 #5
0
 public function postSave()
 {
     if (isset($this->arcAssignments)) {
         $newArcIds = $this->arcAssignments;
         $nodes = (array) $this->getNodes();
         //Determine nodes to delete
         $nodesToDelete = array_filter($nodes, function ($node) use($newArcIds) {
             return !in_array($node->arcId, $newArcIds);
         });
         //Determine arcs to add
         $arcsToAdd = array_filter($newArcIds, function ($id) use($nodes) {
             foreach ($nodes as $node) {
                 if ($node->arcId == $id) {
                     return false;
                 }
             }
             return true;
         });
         //Delete unneeded nodes
         foreach ($nodesToDelete as $node) {
             //Delete the node
             $node->delete();
             //Update page numbers on subsequent pages
             $db = $node->getAdapter();
             $sql = "UPDATE atpcomic_nodes SET page_number = page_number-1 WHERE page_number > ? AND arc_id = ?";
             $db->query($sql, array($node->pageNumber, $node->arcId));
         }
         //Add new arcs
         foreach ($arcsToAdd as $arcId) {
             //Get the last node in the arc
             $arc = new \ATPComic\Model\Arc();
             $arc->loadById($arcId);
             $lastNode = $arc->lastNode(false);
             $newNode = new \ATPComic\Model\Node();
             $newNode->arc = $arc;
             $newNode->page = $this;
             $newNode->pageNumber = $lastNode ? $lastNode->pageNumber + 1 : 1;
             $newNode->isActive = $this->isActive;
             $newNode->save();
         }
     }
     //Update active flag on nodes
     foreach ($this->getNodes() as $node) {
         $node->isActive = $this->isActive;
         $node->save();
     }
 }