コード例 #1
0
ファイル: items.php プロジェクト: zooley/hubzero-cms
 /**
  * Reorders a resource child
  * Redirects to parent resource's children lsiting
  *
  * @return  void
  */
 public function reorderTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Incoming
     $id = Request::getVar('id', array());
     $id = $id[0];
     $pid = Request::getInt('pid', 0);
     // Ensure we have an ID to work with
     if (!$id) {
         $this->setMessage(Lang::txt('COM_RESOURCES_ERROR_MISSING_ID'));
         return $this->cancelTask();
     }
     // Ensure we have a parent ID to work with
     if (!$pid) {
         $this->setMessage(Lang::txt('COM_RESOURCES_ERROR_MISSING_PARENT_ID'));
         return $this->cancelTask();
     }
     // Get the element moving down - item 1
     $resource1 = new Assoc($this->database);
     $resource1->loadAssoc($pid, $id);
     // Get the element directly after it in ordering - item 2
     $resource2 = clone $resource1;
     $resource2->getNeighbor($this->_task);
     switch ($this->_task) {
         case 'orderup':
             // Switch places: give item 1 the position of item 2, vice versa
             $orderup = $resource2->ordering;
             $orderdn = $resource1->ordering;
             $resource1->ordering = $orderup;
             $resource2->ordering = $orderdn;
             break;
         case 'orderdown':
             // Switch places: give item 1 the position of item 2, vice versa
             $orderup = $resource1->ordering;
             $orderdn = $resource2->ordering;
             $resource1->ordering = $orderdn;
             $resource2->ordering = $orderup;
             break;
     }
     // Save changes
     $resource1->store();
     $resource2->store();
     // Redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&task=children&pid=' . $pid, false));
 }
コード例 #2
0
 /**
  * Reorder an attachment
  *
  * @return     void
  */
 public function reorderTask()
 {
     // Incoming
     $id = Request::getInt('id', 0);
     $pid = Request::getInt('pid', 0);
     $move = 'order' . Request::getVar('move', 'down');
     // Ensure we have an ID to work with
     if (!$id) {
         $this->setError(Lang::txt('CONTRIBUTE_NO_CHILD_ID'));
         $this->displayTask($pid);
         return;
     }
     // Ensure we have a parent ID to work with
     if (!$pid) {
         $this->setError(Lang::txt('CONTRIBUTE_NO_ID'));
         $this->displayTask($pid);
         return;
     }
     // Get the element moving down - item 1
     $resource1 = new Assoc($this->database);
     $resource1->loadAssoc($pid, $id);
     // Get the element directly after it in ordering - item 2
     $resource2 = clone $resource1;
     $resource2->getNeighbor($move);
     switch ($move) {
         case 'orderup':
             // Switch places: give item 1 the position of item 2, vice versa
             $orderup = $resource2->ordering;
             $orderdn = $resource1->ordering;
             $resource1->ordering = $orderup;
             $resource2->ordering = $orderdn;
             break;
         case 'orderdown':
             // Switch places: give item 1 the position of item 2, vice versa
             $orderup = $resource1->ordering;
             $orderdn = $resource2->ordering;
             $resource1->ordering = $orderdn;
             $resource2->ordering = $orderup;
             break;
     }
     // Save changes
     $resource1->store();
     $resource2->store();
     // Push through to the attachments view
     $this->displayTask($pid);
 }