function write_per_context_data($bf, $preferences, $context, $startlevel) {
write_role_overrides_xml($bf, $context, $startlevel);
write_role_assignments_xml($bf, $preferences, $context, $startlevel);
+ write_local_filter_settings($bf, $preferences, $context, $startlevel);
}
/**
fwrite ($bf, end_tag("ROLES_ASSIGNMENTS", $startlevel, true));
}
+ /**
+ * Write any local filter settings for this context to the backup file.
+ * They comprise On/off filter_active.active overrides, and any filter_config
+ * records for this contextid.
+ */
+ function write_local_filter_settings($bf, $preferences, $context, $startlevel) {
+ if (!filter_context_may_have_filter_settings($context)) {
+ return;
+ }
+ list($actives, $configs) = filter_get_all_local_settings($context->id);
+
+ fwrite($bf, start_tag("FILTERACTIVES", $startlevel, true));
+ foreach ($actives as $active) {
+ fwrite($bf, start_tag("FILTERACTIVE", $startlevel + 1, true));
+ fwrite($bf, full_tag("FILTER", $startlevel + 2, false, $active->filter));
+ fwrite($bf, full_tag("ACTIVE", $startlevel + 2, false, $active->active));
+ fwrite($bf, end_tag("FILTERACTIVE", $startlevel + 1, true));
+ }
+ fwrite($bf, end_tag("FILTERACTIVES", $startlevel, true));
+
+ fwrite($bf, start_tag("FILTERCONFIGS", $startlevel, true));
+ foreach ($configs as $config) {
+ fwrite($bf, start_tag("FILTERCONFIG", $startlevel + 1, true));
+ fwrite($bf, full_tag("FILTER", $startlevel + 2, false, $config->filter));
+ fwrite($bf, full_tag("NAME", $startlevel + 2, false, $config->name));
+ fwrite($bf, full_tag("VALUE", $startlevel + 2, false, $config->value));
+ fwrite($bf, end_tag("FILTERCONFIG", $startlevel + 1, true));
+ }
+ fwrite($bf, end_tag("FILTERCONFIGS", $startlevel, true));
+ }
function backup_execute(&$preferences, &$errorstr) {
global $CFG, $DB;
}
}
} /// ends role_overrides
+
+ if ($this->tree[4] == "FILTERACTIVES") {
+ if ($this->level == 6) {
+ switch ($tagName) {
+ case "FILTER":
+ $this->info->tempfilter = $this->getContents();
+ break;
+ case "ACTIVE":
+ $this->info->filteractives[$this->info->tempfilter] = $this->getContents();
+ break;
+ }
+ }
+ } /// ends FILTERACTIVES
+
+ if ($this->tree[4] == "FILTERCONFIGS") {
+ if ($this->level == 6) {
+ switch ($tagName) {
+ case "FILTER":
+ $this->info->tempfilter = $this->getContents();
+ break;
+ case "NAME":
+ $this->info->tempname = $this->getContents();
+ break;
+ case "VALUE":
+ $fc = new stdClass;
+ $fc->filter = $this->info->tempfilter;
+ $fc->name = $this->info->tempfilter;
+ $fc->value = $this->getContents();
+ $this->info->filterconfigs[] = $fc;
+ break;
+ }
+ }
+ } /// ends FILTERCONFIGS
}
//Stop parsing if todo = COURSE_HEADER and tagName = HEADER (en of the tag, of course)
}
} /// ends role_overrides
+
+ if (isset($this->tree[7]) && $this->tree[7] == "FILTERACTIVES") {
+ if ($this->level == 9) {
+ switch ($tagName) {
+ case "FILTER":
+ $this->info->tempfilter = $this->getContents();
+ break;
+ case "ACTIVE":
+ $this->info->filteractives[$this->info->tempfilter] = $this->getContents();
+ break;
+ }
+ }
+ } /// ends FILTERACTIVES
+
+ if (isset($this->tree[7]) && $this->tree[7] == "FILTERCONFIGS") {
+ if ($this->level == 9) {
+ switch ($tagName) {
+ case "FILTER":
+ $this->info->tempfilter = $this->getContents();
+ break;
+ case "NAME":
+ $this->info->tempname = $this->getContents();
+ break;
+ case "VALUE":
+ $fc = new stdClass;
+ $fc->filter = $this->info->tempfilter;
+ $fc->name = $this->info->tempfilter;
+ $fc->value = $this->getContents();
+ $this->info->filteractives[]->filter = $fc;
+ break;
+ }
+ }
+ } /// ends FILTERCONFIGS
+
if (isset($this->tree[7]) && $this->tree[7] == "COMPLETIONDATA") {
if($this->level == 8) {
switch($tagName) {
}
}
+ // Per-context filter settings.
+ restore_write_local_filter_settings($restore, $course, $newcoursecontext);
+
/*******************************************************
* Restoring role assignments/overrdies *
* from module level assignments *
restore_write_roleoverrides($restore, $modoverride->overrides, $newmodcontext, $oldroleid);
}
}
+ // Per-context filter settings.
+ restore_write_local_filter_settings($restore, $mod, $newmodcontext);
}
}
}
assign_capability($override->capability, $override->permission, $override->roleid, $override->contextid);
}
}
+
+ /**
+ * Write any per-context filter settings from the backup XML to the DB.
+ * @param object $restore the restore we are part of.
+ * @param object $data sata loaded from the XML.
+ * @param object $newmodcontext the restored context object.
+ */
+ function restore_write_local_filter_settings($restore, $data, $newcontext) {
+ if (filter_context_may_have_filter_settings($newcontext)) {
+ return;
+ }
+
+ $installedfilters = filter_get_all_installed();
+
+ if (!isset($data->filteractives)) {
+ $data->filteractives = array();
+ }
+ foreach ($data->filteractives as $filter => $state) {
+ if (isset($installedfilters[$filter])) {
+ filter_set_local_state($filter, $newcontext->id, $state);
+ }
+ }
+
+ if (!isset($data->filterconfigs)) {
+ $data->filterconfigs = array();
+ }
+ foreach ($data->filterconfigs as $fc) {
+ if (isset($installedfilters[$fc->filter])) {
+ filter_set_local_config($fc->filter, $newcontext->id, $fc->name, $fc->value);
+ }
+ }
+ }
+
//write activity date changes to the html log file, and update date values in the the xml array
function restore_log_date_changes($recordtype, &$restore, &$xml, $TAGS, $NAMETAG='NAME') {
return $DB->get_records_menu('filter_config', array('filter' => $filter, 'contextid' => $contextid), '', 'name,value');
}
+/**
+ * This function is for use by backup. Gets all the filter information specific
+ * to one context.
+ * @return array with two elements. The first element is an array of objects with
+ * fields filter and active. These come from the filter_active table. The
+ * second element is an array of objects with fields filter, name and value
+ * from the filter_config table.
+ */
+function filter_get_all_local_settings($contextid) {
+ global $DB;
+ $context = get_context_instance(CONTEXT_SYSTEM);
+ return array(
+ $DB->get_records('filter_active', array('contextid' => $contextid), 'filter', 'filter,active'),
+ $DB->get_records('filter_config', array('contextid' => $contextid), 'filter,name', 'filter,name,value'),
+ );
+}
+
/**
* Get the list of active filters, in the order that they should be used
* for a particular context, along with any local configuration variables.
return is_readable($settingspath);
}
+/**
+ * Certain types of context (block and user) may not have local filter settings.
+ * the function checks a context to see whether it may have local config.
+ * @param object $context a context.
+ * @return boolean whether this context may have local filter settings.
+ */
+function filter_context_may_have_filter_settings($context) {
+ return $context->contextlevel != CONTEXT_BLOCK && $context->contextlevel != CONTEXT_USER;
+}
+
/**
* Process phrases intelligently found within a HTML text (such as adding links)
*