function delete_with_sub() { // getting the subsections $c = new Section(); $c->where('parent_section', $this->id); $c->get(); // delete all subsections relations $c->delete_all(); // delete all children $cont = new Content(); $cont->get_where_parent_section($this->id); $cont->delete_all(); // update all the sections sort after that section // that in the same parent section $s = new Section(); $s->where('sort >', $this->sort); $s->where('parent_section', $this->parent_section); $s->get(); foreach ($s->all as $item) { $item->sort--; $item->save(); } //delete this section parent::delete($object); }
function delete($object = '') { if (empty($object)) { $this->deattach(); } return parent::delete($object); }
function delete($o = null, $log = true) { if ($log) { $this->logActivity('deleted'); } parent::delete(); }
/** * Delete this student or related object. * If no parameters are set, this method deletes current student and all participant record related with this student. * @param DataMapper|string $object related object to delete from relation. * @param string $related_field relation internal name. */ public function delete($object = '', $related_field = '') { if (empty($object) && !is_array($object) && !empty($this->id)) { $participant = new Participant(); $participant->where_related($this); $participant->get(); $participant->delete_all(); } parent::delete($object, $related_field); }
/** * Delete this test or related object. * If no parameters are set, this method deletes current test and all files associated with this test. * @param DataMapper|string $object related object to delete from relation. * @param string $related_field relation internal name. */ public function delete($object = '', $related_field = '') { if (empty($object) && !is_array($object) && !empty($this->id)) { $path_to_test_files = 'private/uploads/unit_tests/test_' . $this->id; if (file_exists($path_to_test_files)) { unlink_recursive($path_to_test_files, TRUE); } } parent::delete($object, $related_field); }
/** * Deletes relations (if parameters are set) or this object from database. * All comments which replies to this one will be deleted as well. * @param DataMapper|string $object related object to delete from relation. * @param string $related_field relation internal name. */ public function delete($object = '', $related_field = '') { $this_id = $this->id; if (empty($object) && !is_array($object) && !empty($this_id)) { $comments = $this->comment->get_iterated(); foreach ($comments as $comment) { $comment->delete(); } } parent::delete($object, $related_field); }
/** * delete that section with all it's subsections * plus eliminate the gap between it's siblings sort **/ public function delete($object = '', $related_field = '') { if (empty($object)) { // update all the sections sort after that section // that in the same parent section $s = new Section(); $s->where('sort >', $this->sort); $s->where('parent_section', $this->parent_section); $s->get(); foreach ($s as $item) { $item->sort--; $item->save(); } } //delete this section parent::delete($object, $related_field); }
/** * Delete this object from database or specified relations. * If this object is deleted, all student files will be deleted as well. * @param DataMapper|string $object related object to delete from relation. * @param string $related_field relation internal name. */ public function delete($object = '', $related_field = '') { $this_id = $this->id; $this_task_set_id = $this->task_set_id; $this_student_id = $this->student_id; parent::delete($object, $related_field); if (empty($object) && !is_array($object) && !empty($this_id)) { $task_set = new Task_set(); $task_set->get_by_id($this_task_set_id); if ($task_set->exists()) { $student_files = $task_set->get_student_files($this_student_id); if (count($student_files) > 0) { foreach ($student_files as $file) { @unlink($file['filepath']); } } } } }
/** * Delete this period or related object. * If no parameters are set, this method deletes current period and re-sort all other periods. * @param DataMapper|string $object related object to delete from relation. * @param string $related_field relation internal name. */ public function delete($object = '', $related_field = '') { if (empty($object) && !is_array($object) && !empty($this->id)) { $lower_periods = new Period(); $lower_periods->order_by('sorting', 'asc'); $lower_periods->where('sorting > ', $this->sorting); $lower_periods->get_iterated(); $ids = array(); foreach ($lower_periods as $lower_period) { $ids[] = $lower_period->id; } if (count($ids) > 0) { $this->db->set('sorting', 'sorting-1', FALSE); $this->db->where_in('id', $ids); $this->db->update('periods'); } } parent::delete($object, $related_field); }
function delete($object = '') { if (empty($object)) { $c = $this->children(); foreach ($c as $item) { $item->delete(); } } $this->deattach(); return parent::delete($object); }
/** * Deletes relations (if parameters are set) or this object from database. * All solutions related to this task set will be deleted as well. * @param DataMapper|string $object related object to delete from relation. * @param string $related_field relation internal name. */ public function delete($object = '', $related_field = '') { $this_id = $this->id; if (empty($object) && !is_array($object) && !empty($this_id)) { $solutions = new Solution(); $solutions->get_by_related('task_set', 'id', $this_id); foreach ($solutions as $solution) { set_time_limit(ini_get('max_execution_time')); $solution->delete(); } } parent::delete($object, $related_field); }
/** * Convert an associative array back into a DataMapper model. * * If $fields is provided, missing fields are assumed to be empty checkboxes. * Alse if $sub_array is TRUE, will save related object provided by sub array * * @param DataMapper $object The DataMapper Object to save to. * @param array $data A an associative array of fields to convert. * @param array $fields Array of 'safe' fields. If empty, only includes the database columns. * @param bool $sub_array If TRUE - will save provided by subarray related obj * @param bool $save If TRUE, then attempt to save the object automatically. * @return array|bool A list of newly related objects, or the result of the save if $save is TRUE. * If $sub_array TRUE, return array('error','created_ids') */ function save_from($object, $data, $fields = '', $sub_array = FALSE, $save = TRUE) { // keep track of newly related objects $new_related_objects = array(); $error = ''; //error string $created_ids = array(); //stores array of newly created ids ('related_class_name' => array(ids)) // Assume all database columns. // In this case, simply store $fields that are in the $data array. $object_fields = $object->fields; if (in_array('password', $object_fields)) { $object_fields[] = 'password_confirm'; } foreach ($data as $k => $v) { if (in_array($k, $object_fields)) { $object->{$k} = $v; } } if (!empty($fields)) { // If $fields is provided, assume all $fields should exist. foreach ($fields as $f) { if (array_key_exists($f, $object->has_one)) { // Store $has_one relationships $c = get_class($object->{$f}); $rel = new $c(); $id = isset($data[$f]) ? $data[$f] : 0; $rel->get_by_id($id); if ($rel->exists()) { // The new relationship exists, save it. $new_related_objects[$f] = $rel; } else { // The new relationship does not exist, delete the old one. $object->delete($object->{$f}->get()); } } else { if (array_key_exists($f, $object->has_many)) { // Store $has_many relationships $c = get_class($object->{$f}); $ids = isset($data[$f]) ? $data[$f] : FALSE; $has_join_table = false; if (!empty($object->has_many[$f]['join_table'])) { $has_join_table = true; //so, do not delete the record, only the relation } if ($sub_array) { $error_classes_to_check = array(); $created_ids[$f] = array(); if (empty($ids)) { $old_related_obj = $object->{$f}->select('id')->get(); if ($has_join_table) { $object->delete($old_related_obj); //delete relation to related object } else { $old_related_obj->delete_all(); //delete related object } } else { $related_ids = array(); foreach ($ids as $related_row) { $create = false; if (isset($related_row['id']) && $related_row['id']) { $id = $related_row['id']; $related_ids[] = $id; //add to list of provided ids unset($related_row['id']); //useless any more } else { $id = null; $create = true; } $related_obj = new $c($id); foreach ($related_row as $column => $value) { $related_obj->{$column} = $value; //fill object with new values } if ($create) { //create new record if (!$related_obj->save()) { $error .= $related_obj->error->string; } else { $created_ids[$f][] = $related_obj->id; //add id to returned array } } $error_classes_to_check[] = $f; $new_related_objects[$f][] = $related_obj; } //delete not provided objects if (!empty($related_ids)) { $old_related_obj = $object->{$f}->where_not_in('id', $related_ids)->select('id')->get(); } else { $old_related_obj = $object->{$f}->select('id')->get(); } if ($has_join_table) { $object->delete($old_related_obj); } else { $old_related_obj->delete_all(); } } } else { if (empty($ids)) { $object->delete(array($f => $object->{$f}->select('id')->get()->all)); } else { $rels = new $c(); // Otherwise, get the new ones... $rels->where_in('id', $ids)->select('id')->get(); // Store them... $new_related_objects[$f] = $rels->all; // And delete any old ones that do not exist. $old_rels = $object->{$f}->where_not_in('id', $ids)->select('id')->get(); $object->delete(array($f => $old_rels->all)); } } } else { // Otherwise, if the $data was set, store it... if (isset($data[$f])) { $v = $data[$f]; } else { // Or assume it was an unchecked checkbox, and clear it. $v = FALSE; } $object->{$f} = $v; } } } } if ($save) { if ($sub_array) { $object->save_from = new stdClass(); //add properties to object $object->save_from->error = $error; $object->save_from->created_ids = $created_ids; if (empty($error)) { //if no error while creating new related objects $object->save($new_related_objects); $error .= $object->error->string; foreach ($error_classes_to_check as $error_class) { $error .= $object->{$error_class}->error->string; //add errors from updated related objects } $object->save_from->error = $error; if (empty($error)) { return true; } else { //remove created objects, because some of relation couldn't be saved if (isset($created_ids) && !empty($created_ids) && is_array($created_ids)) { foreach ($created_ids as $related_class_name => $related_ids) { $class = get_class($object->{$related_class_name}); foreach ($related_ids as $created_id) { $related_class = new $class($created_id); $related_class->delete(); } } } return false; } } else { //remove created objects, because some of relation couldn't be saved if (isset($created_ids) && !empty($created_ids) && is_array($created_ids)) { foreach ($created_ids as $related_class_name => $related_ids) { $class = get_class($object->{$related_class_name}); foreach ($related_ids as $created_id) { $related_class = new $class($created_id); $related_class->delete(); } } } return false; } } return $object->save($new_related_objects); } else { // return new objects return $new_related_objects; } }
/** * delete this content from database * that will deattach the content from it's parent * and remove the sort gab between siblings * * @param $object * @param $related_field * @return boolean */ public function delete($object = '', $related_field = '') { $this->deattach(); return parent::delete($object, $related_field); }
/** * Deletes relations (if parameters are set) or this object from database. * @param DataMapper|string $object related object to delete from relation. * @param string $related_field relation internal name. */ public function delete($object = '', $related_field = '') { $this_id = $this->id; parent::delete($object, $related_field); if (empty($object) && !is_array($object) && !empty($this_id)) { $tests = new Test(); $tests->where_related($this); $tests->get(); if ($tests->result_count()) { foreach ($tests->all as $test) { $test->delete(); } } $path = 'private/uploads/task_files/task_' . intval($this_id) . '/'; if (file_exists($path)) { unlink_recursive($path, TRUE); } } }
/** * Convert an associative array back into a DataMapper model. * * If $fields is provided, missing fields are assumed to be empty checkboxes. * * @param DataMapper $object The DataMapper Object to save to. * @param array $data A an associative array of fields to convert. * @param array $fields Array of 'safe' fields. If empty, only includes the database columns. * @param bool $save If TRUE, then attempt to save the object automatically. * @return array|bool A list of newly related objects, or the result of the save if $save is TRUE */ function from_array($object, $data, $fields = '', $save = FALSE) { // keep track of newly related objects $new_related_objects = array(); // Assume all database columns. // In this case, simply store $fields that are in the $data array. if (empty($fields)) { $fields = $object->fields; foreach ($data as $k => $v) { if (in_array($k, $fields)) { $object->{$k} = $v; } } } else { // If $fields is provided, assume all $fields should exist. foreach ($fields as $f) { if (array_key_exists($f, $object->has_one)) { // Store $has_one relationships $c = get_class($object->{$f}); $rel = new $c(); $id = isset($data[$f]) ? $data[$f] : 0; $rel->get_by_id($id); if ($rel->exists()) { // The new relationship exists, save it. $new_related_objects[$f] = $rel; } else { // The new relationship does not exist, delete the old one. $object->delete($object->{$f}->get()); } } else { if (array_key_exists($f, $object->has_many)) { // Store $has_many relationships $c = get_class($object->{$f}); $rels = new $c(); $ids = isset($data[$f]) ? $data[$f] : FALSE; if (empty($ids)) { // if no IDs were provided, delete all old relationships. $object->delete($object->{$f}->select('id')->get()->all); } else { // Otherwise, get the new ones... $rels->where_in('id', $ids)->select('id')->get(); // Store them... $new_related_objects[$f] = $rels->all; // And delete any old ones that do not exist. $old_rels = $object->{$f}->where_not_in('id', $ids)->select('id')->get(); $object->delete($old_rels->all); } } else { // Otherwise, if the $data was set, store it... if (isset($data[$f])) { $v = $data[$f]; } else { // Or assume it was an unchecked checkbox, and clear it. $v = FALSE; } $object->{$f} = $v; } } } } if ($save) { // Auto save return $object->save($new_related_objects); } else { // return new objects return $new_related_objects; } }
function deep_delete() { $this->delete(array($this->newscomment)); parent::delete(); }
public function delete($object = '', $related_field = '') { $id = isset($this->id) ? $this->id : NULL; if (!parent::delete($object, $related_field)) { return FALSE; } if (mdi::config('admin_using_history')) { if (empty($object) && !is_array($object)) { if (!empty($id)) { // self delete $this->_save_history($id, 'delete'); } } else { // relation delete $this->_save_history($id, 'modify'); } } return TRUE; }
public function delete($object = '', $related_field = '') { $this->trigger_event('before_delete', $this); $return = parent::delete($object, $related_field); if ($return) { $this->trigger_event('after_delete', $this); } return $return; }
function deep_delete() { $this->productphoto->delete_all(); parent::delete(); }