Ejemplo n.º 1
0
 /**
  * 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;
 }