/** * Perform the necessary actions required to "delete" a cluster from the system. * * @uses CURMAN * @uses CFG * @param none * @return bool True on success, False otherwise. */ function delete($deletesubs = 0) { global $CURMAN, $CFG; require_once CURMAN_DIRLOCATION . '/cluster/profile/lib.php'; $result = true; $delete_ids = array(); $promote_ids = array(); $cluster_context_level = context_level_base::get_custom_context_level('cluster', 'block_curr_admin'); if ($deletesubs > 0) { /// Figure out all the sub-cluster ids and whether to delete or promote them $LIKE = $CURMAN->db->sql_compare(); $cluster_context_instance = get_context_instance($cluster_context_level, $this->id); $instance_id = $cluster_context_instance->id; $instance_path = $cluster_context_instance->path; $sql = "SELECT instanceid FROM {$CFG->prefix}context\n WHERE path {$LIKE} '{$instance_path}/%' ORDER BY instanceid DESC"; $clusters = get_records_sql($sql); foreach ($clusters as $cluster) { if ($deletesubs == 1) { // This sub-cluster will be deleted $delete_ids[] = $cluster->instanceid; } else { // This sub-cluster will be promoted $promote_ids[] = $cluster->instanceid; } } } $delete_ids[] = $this->id; // The specified cluster always gets deleted foreach ($delete_ids as $delete_id) { // Cascade to regular datarecords $result = $result && clustercurriculum::delete_for_cluster($delete_id); // in clustercurriculum $result = $result && clustertrack::delete_for_cluster($delete_id); // in clustercurriculum $result = $result && clusterassignment::delete_for_cluster($delete_id); $result = $result && usercluster::delete_for_cluster($delete_id); $result = $result && delete_context($cluster_context_level, $delete_id); // Cascade to all plugins $plugins = $this->get_plugins(); foreach ($plugins as $plugin) { require_once CURMAN_DIRLOCATION . '/cluster/' . $plugin . '/lib.php'; $result = $result && call_user_func('cluster_' . $plugin . '_delete_for_cluster', $delete_id); } $result = $result && datarecord::data_delete_record($delete_id); // this record } if (count($promote_ids) > 0) { foreach ($promote_ids as $promote_id) { $cluster_data = get_record(CLSTTABLE, 'id', $promote_id); $lower_depth = $cluster_data->depth - 1; $select = "id='{$cluster_data->parent}'"; $parent_cnt = $CURMAN->db->count_records_select(CLSTTABLE, $select); $newclusterdata = new stdClass(); $newclusterdata->id = $promote_id; if ($parent_cnt < 1) { /// Parent not found so this cluster will be top-level $newclusterdata->parent = 0; $newclusterdata->depth = 1; } else { /// A child cluster found so lets lower the depth $newclusterdata->depth = $lower_depth; } $result = update_record(CLSTTABLE, $newclusterdata); $cluster_context_level = context_level_base::get_custom_context_level('cluster', 'block_curr_admin'); $sql = "UPDATE {$CFG->prefix}context\n SET depth=0, path=NULL\n WHERE contextlevel='{$cluster_context_level}' AND instanceid='{$promote_id}'"; $feedback = ""; execute_sql($sql, $feedback); } build_context_path(); // Re-build the context table for all sub-clusters } return $result; }
public function delete() { global $CFG; $result = false; $muser = cm_get_moodleuserid($this->id); if (empty($muser) || !is_primary_admin($muser)) { $level = context_level_base::get_custom_context_level('user', 'block_curr_admin'); $result = attendance::delete_for_user($this->id); $result = $result && curriculumstudent::delete_for_user($this->id); $result = $result && instructor::delete_for_user($this->id); $result = $result && student::delete_for_user($this->id); $result = $result && student_grade::delete_for_user($this->id); $result = $result && usertrack::delete_for_user($this->id); $result = $result && usercluster::delete_for_user($this->id); $result = $result && clusterassignment::delete_for_user($this->id); $result = $result && waitlist::delete_for_user($this->id); $result = $result && delete_context($level, $this->id); // Delete Moodle user. if ($muser = get_record('user', 'idnumber', $this->idnumber, 'mnethostid', $CFG->mnet_localhost_id, 'deleted', 0)) { $result = $result && delete_user($muser); } $result = $result && parent::delete(); } return $result; }
function can_do_delete() { $aid = 0; if (!empty($this->params['association_id'])) { $aid = $this->params['association_id']; } else { $aid = $this->optional_param('association_id', '', PARAM_INT); } $clustass = new clusterassignment($aid); return usercluster::can_manage_assoc($clustass->userid, $clustass->clusterid); }