Exemplo n.º 1
0
 /**
  * Move an item one down or own up int he ordering
  *
  * @param      string $move Direction to move
  * @return     void
  */
 protected function reorderTask($move = 'down')
 {
     // Check for request forgeries
     Request::checkToken(['get', 'post']);
     // Incoming
     $id = Request::getVar('id', array());
     $id = $id[0];
     $pid = Request::getInt('event', 0);
     // Ensure we have an ID to work with
     if (!$id) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_EVENTS_PAGE_NO_ID'), 'error');
         return;
     }
     // Ensure we have a parent ID to work with
     if (!$pid) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_EVENTS_PAGE_NO_EVENT_ID'), 'error');
         return;
     }
     // Get the element moving down - item 1
     $page1 = new Page($this->database);
     $page1->load($id);
     // Get the element directly after it in ordering - item 2
     $page2 = clone $page1;
     $page2->getNeighbor($this->_task);
     switch ($move) {
         case 'up':
             // Switch places: give item 1 the position of item 2, vice versa
             $orderup = $page2->ordering;
             $orderdn = $page1->ordering;
             $page1->ordering = $orderup;
             $page2->ordering = $orderdn;
             break;
         case 'down':
             // Switch places: give item 1 the position of item 2, vice versa
             $orderup = $page1->ordering;
             $orderdn = $page2->ordering;
             $page1->ordering = $orderdn;
             $page2->ordering = $orderup;
             break;
     }
     // Save changes
     $page1->store();
     $page2->store();
     // Redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&id[]=' . $pid, false));
 }