Esempio n. 1
0
 public function save()
 {
     $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');
     }
     if (!empty($this->id)) {
         // cache the database values, so we can know if the parent changed
         $old = new userset($this->id);
         $old->load();
     }
     // figure out the right depth for the cluster
     if (empty($this->depth) || !empty($this->id)) {
         if ($this->parent == 0) {
             $this->depth = 1;
         } else {
             $this->depth = $this->parentset->depth + 1;
         }
     }
     parent::save();
     if (isset($old) && $this->parent != $old->parent) {
         $cluster_context_instance = \local_elisprogram\context\userset::instance($this->id);
         // find all subclusters and adjust their depth
         $delta_depth = $this->depth - $old->depth;
         $LIKE = $this->_db->sql_like('path', '?');
         $sql = 'UPDATE {' . self::TABLE . "}\n                       SET depth = depth + ?\n                     WHERE id IN (SELECT instanceid\n                                    FROM {context}\n                                   WHERE contextlevel = ?\n                                     AND {$LIKE})";
         $this->_db->execute($sql, array($delta_depth, CONTEXT_ELIS_USERSET, "{$cluster_context_instance->path}/%"));
         // Blank out the depth and path for associated records and child records in context table
         $sql = "UPDATE {context}\n                       SET depth=0, path=NULL\n                     WHERE id=? OR {$LIKE}";
         $this->_db->execute($sql, array($cluster_context_instance->id, "{$cluster_context_instance->path}/%"));
         // Rebuild any blanked out records in context table
         \local_eliscore\context\helper::build_all_paths(false, array(CONTEXT_ELIS_USERSET));
     }
     $plugins = get_plugin_list(self::ENROL_PLUGIN_TYPE);
     foreach ($plugins as $plugin => $plugindir) {
         call_user_func('userset_' . $plugin . '_update', $this);
     }
     if (isset($old)) {
         //signal that the cluster was created
         events_trigger('pm_userset_updated', $this);
     } else {
         events_trigger('pm_userset_created', $this);
     }
 }