Exemplo n.º 1
0
 /**
  * Removes all associations with a track, this entails removing
  * user track, cluster track and class track associations
  * @param none
  * @return none
  */
 function delete()
 {
     // Cascade
     //clean make the delete cascade into association records
     $filter = new field_filter('trackid', $this->id);
     usertrack::delete_records($filter, $this->_db);
     clustertrack::delete_records($filter, $this->_db);
     trackassignment::delete_records($filter, $this->_db);
     parent::delete();
     //Delete this leve's context
     $context = \local_elisprogram\context\track::instance($this->id);
     $context->delete();
 }
Exemplo n.º 2
0
 /**
  * Perform the necessary actions required to "delete" a cluster from the system.
  *
  * @param none
  * @return bool True on success, False otherwise.
  */
 function delete()
 {
     require_once elis::lib('data/data_filter.class.php');
     if ($this->deletesimple) {
         //core delete method, not including recursion (entered once for each
         //individual userset being delete)
         //clean make the delete cascade into association records
         $filter = new field_filter('clusterid', $this->id);
         clustercurriculum::delete_records($filter, $this->_db);
         clustertrack::delete_records($filter, $this->_db);
         clusterassignment::delete_records($filter, $this->_db);
         //cluster plugin cleanup
         $plugins = get_plugin_list(self::ENROL_PLUGIN_TYPE);
         foreach ($plugins as $plugin => $plugindir) {
             require_once elis::plugin_file(self::ENROL_PLUGIN_TYPE . '_' . $plugin, 'lib.php');
             call_user_func('cluster_' . $plugin . '_delete_for_cluster', $this->id);
         }
         //delete the userset record
         parent::delete();
         //delete this cluster's context
         //get a new context instance,
         $contextclass = \local_eliscore\context\helper::get_class_for_level(CONTEXT_ELIS_USERSET);
         $userset_context = $contextclass::instance($this->id);
         $userset_context->delete();
         events_trigger('cluster_deleted', $this->id);
         return;
     }
     $result = true;
     $children = array();
     $delete_ids = array();
     $promote_ids = array();
     /// Figure out all the sub-clusters
     $cluster_context_instance = \local_elisprogram\context\userset::instance($this->id);
     $instance_id = $cluster_context_instance->id;
     $instance_path = $cluster_context_instance->path;
     $children = userset::find(new join_filter('id', 'context', 'instanceid', new AND_filter(array(new field_filter('path', "{$instance_path}/%", field_filter::LIKE), new field_filter('contextlevel', CONTEXT_ELIS_USERSET)))), array('depth' => 'ASC'), 0, 0, $this->_db);
     $children = $children->to_array();
     if ($this->deletesubs) {
         $todelete = $children;
         $todelete[] = $this;
         // The specified cluster always gets deleted
     } else {
         $todelete = array($this);
     }
     foreach ($todelete as $userset) {
         //delete without recursion
         $userset->deletesimple = true;
         $userset->delete();
     }
     if (!$this->deletesubs && !empty($children)) {
         foreach ($children as $child) {
             $lower_depth = $child->depth - 1;
             if (userset::exists(new field_filter('id', $child->parent))) {
                 /// A parent found so lets lower the depth
                 $child->depth = 0;
             } else {
                 /// Parent not found so this cluster will be top-level
                 $child->parent = 0;
                 $child->depth = 1;
             }
             $child->save();
             $sql = "UPDATE {context}\n                        SET depth=0, path=NULL\n                        WHERE contextlevel=? AND instanceid=?";
             $this->_db->execute($sql, array(CONTEXT_ELIS_USERSET, $child->id));
         }
         \local_eliscore\context\helper::build_all_paths(false, array(CONTEXT_ELIS_USERSET));
         // Re-build the context table for all sub-clusters
     }
     return $result;
 }