Beispiel #1
0
 /**
  * Delete a record and any associated data
  *
  * @return  bool
  */
 public function destroy()
 {
     // Remove children
     foreach ($this->children()->rows() as $child) {
         if ($child->get('standalone')) {
             continue;
         }
         if (!$child->destroy()) {
             $this->setError($child->getError());
             return false;
         }
     }
     // Remove parent associations
     $parents = Association::all()->whereEquals('child_id', $this->get('id'))->rows();
     foreach ($parents as $parent) {
         if (!$parent->destroy()) {
             $this->setError($parent->getError());
             return false;
         }
     }
     return parent::destroy();
 }
Beispiel #2
0
 /**
  * Reorder an attachment
  *
  * @return  void
  */
 public function reorderTask()
 {
     // Incoming
     $id = Request::getInt('id', 0);
     $pid = Request::getInt('pid', 0);
     $move = Request::getVar('move', 'down');
     // Ensure we have an ID to work with
     if (!$id) {
         $this->setError(Lang::txt('CONTRIBUTE_NO_CHILD_ID'));
         return $this->displayTask($pid);
     }
     // Ensure we have a parent ID to work with
     if (!$pid) {
         $this->setError(Lang::txt('CONTRIBUTE_NO_ID'));
         return $this->displayTask($pid);
     }
     switch ($move) {
         case 'up':
             $move = -1;
             break;
         case 'down':
             $move = 1;
             break;
     }
     // Move the record
     $association = Association::oneByRelationship($pid, $id);
     if (!$association->move($move)) {
         $this->setError($association->getError());
     }
     // Push through to the attachments view
     $this->displayTask($pid);
 }