Permalink
Browse files

Merge branch 'master' into backup-convert

  • Loading branch information...
2 parents db6491b + a56c68e commit a78b139ce6bc18c64f79eed9df210f9df16580db @mudrd8mz mudrd8mz committed Jun 3, 2011
@@ -80,6 +80,23 @@ public function launch_after_execute_methods() {
}
}
+ /**
+ * after_restore dispatcher for any restore_plugin class
+ *
+ * This method will dispatch execution to the corresponding
+ * after_restore_xxx() method when available, with xxx
+ * being the connection point of the instance, so plugin
+ * classes with multiple connection points will support
+ * multiple after_restore methods, one for each connection point
+ */
+ public function launch_after_restore_methods() {
+ // Check if the after_restore method exists and launch it
+ $afterrestore = 'after_restore_' . basename($this->connectionpoint->get_path());
+ if (method_exists($this, $afterrestore)) {
+ $this->$afterrestore();
+ }
+ }
+
/**
* Returns one array with all the decode contents
* to be processed by the links decoder
@@ -360,6 +360,43 @@ protected function launch_after_execute_methods() {
}
+ /**
+ * Launch all the after_restore methods present in all the processing objects
+ *
+ * This method will launch all the after_restore methods that can be defined
+ * both in restore_plugin class
+ *
+ * For restore_plugin classes the name of the method to be executed will be
+ * "after_restore_" + connection point (as far as can be multiple connection
+ * points in the same class)
+ */
+ public function launch_after_restore_methods() {
+ $alreadylaunched = array(); // To avoid multiple executions
+ foreach ($this->pathelements as $pathelement) {
+ // Get the processing object
+ $pobject = $pathelement->get_processing_object();
+ // Skip null processors (child of grouped ones for sure)
+ if (is_null($pobject)) {
+ continue;
+ }
+ // Skip restore structure step processors (this)
+ if ($pobject instanceof restore_structure_step) {
+ continue;
+ }
+ // Skip already launched processing objects
+ if (in_array($pobject, $alreadylaunched, true)) {
+ continue;
+ }
+ // Add processing object to array of launched ones
+ $alreadylaunched[] = $pobject;
+ // If the processing object has support for
+ // launching after_restore methods, use it
+ if (method_exists($pobject, 'launch_after_restore_methods')) {
+ $pobject->launch_after_restore_methods();
+ }
+ }
+ }
+
/**
* This method will be executed after the whole structure step have been processed
*
@@ -100,6 +100,13 @@ public function get_old_system_contextid() {
* method if available
*/
public function execute_after_restore() {
+ if ($this->executed) {
+ foreach ($this->steps as $step) {
+ if (method_exists($step, 'launch_after_restore_methods')) {
+ $step->launch_after_restore_methods();
+ }
+ }
+ }
if ($this->executed && method_exists($this, 'after_restore')) {
$this->after_restore();
}
@@ -428,7 +428,7 @@ function standard_coursemodule_elements(){
if (!empty($CFG->enableavailability)) {
// Conditional availability
- $mform->addElement('header', '', get_string('availabilityconditions', 'condition'));
+ $mform->addElement('header', 'availabilityconditionsheader', get_string('availabilityconditions', 'condition'));
$mform->addElement('date_selector', 'availablefrom', get_string('availablefrom', 'condition'), array('optional'=>true));
$mform->addHelpButton('availablefrom', 'availablefrom', 'condition');
$mform->addElement('date_selector', 'availableuntil', get_string('availableuntil', 'condition'), array('optional'=>true));
@@ -522,7 +522,7 @@ function standard_coursemodule_elements(){
$completion = new completion_info($COURSE);
}
if ($completion->is_enabled()) {
- $mform->addElement('header', '', get_string('activitycompletion', 'completion'));
+ $mform->addElement('header', 'activitycompletionheader', get_string('activitycompletion', 'completion'));
// Unlock button for if people have completed it (will
// be removed in definition_after_data if they haven't)
View
@@ -1062,7 +1062,7 @@ public function enrol_user(stdClass $instance, $userid, $roleid = NULL, $timesta
if (!is_null($status)) {
$ue->status = $status;
}
- $ue->modifier = $USER->id;
+ $ue->modifierid = $USER->id;
$ue->timemodified = time();
$DB->update_record('user_enrolments', $ue);
}
@@ -1073,7 +1073,7 @@ public function enrol_user(stdClass $instance, $userid, $roleid = NULL, $timesta
$ue->userid = $userid;
$ue->timestart = $timestart;
$ue->timeend = $timeend;
- $ue->modifier = $USER->id;
+ $ue->modifierid = $USER->id;
$ue->timecreated = time();
$ue->timemodified = $ue->timecreated;
$ue->id = $DB->insert_record('user_enrolments', $ue);
View
@@ -1074,6 +1074,8 @@ function get_fast_modinfo(&$course, $userid=0) {
if (count($cache) > MAX_MODINFO_CACHE_SIZE) {
reset($cache);
$key = key($cache);
+ unset($cache[$key]->instances);
+ unset($cache[$key]->cms);
unset($cache[$key]);
}
View
@@ -237,8 +237,8 @@ public static function override_active_url(moodle_url $url) {
}
/**
- * Adds a navigation node as a child of this node.
- *
+ * Creates a navigation node, ready to add it as a child using add_node
+ * function. (The created node needs to be added before you can use it.)
* @param string $text
* @param moodle_url|action_link $action
* @param int $type
@@ -247,11 +247,8 @@ public static function override_active_url(moodle_url $url) {
* @param pix_icon $icon
* @return navigation_node
*/
- public function add($text, $action=null, $type=self::TYPE_CUSTOM, $shorttext=null, $key=null, pix_icon $icon=null) {
- // First convert the nodetype for this node to a branch as it will now have children
- if ($this->nodetype !== self::NODETYPE_BRANCH) {
- $this->nodetype = self::NODETYPE_BRANCH;
- }
+ public static function create($text, $action=null, $type=self::TYPE_CUSTOM,
+ $shorttext=null, $key=null, pix_icon $icon=null) {
// Properties array used when creating the new navigation node
$itemarray = array(
'text' => $text,
@@ -269,26 +266,66 @@ public function add($text, $action=null, $type=self::TYPE_CUSTOM, $shorttext=nul
if ($icon!==null) {
$itemarray['icon'] = $icon;
}
- // Default the key to the number of children if not provided
- if ($key === null) {
- $key = $this->children->count();
- }
// Set the key
$itemarray['key'] = $key;
+ // Construct and return
+ return new navigation_node($itemarray);
+ }
+
+ /**
+ * Adds a navigation node as a child of this node.
+ *
+ * @param string $text
+ * @param moodle_url|action_link $action
+ * @param int $type
+ * @param string $shorttext
+ * @param string|int $key
+ * @param pix_icon $icon
+ * @return navigation_node
+ */
+ public function add($text, $action=null, $type=self::TYPE_CUSTOM, $shorttext=null, $key=null, pix_icon $icon=null) {
+ // Create child node
+ $childnode = self::create($text, $action, $type, $shorttext, $key, $icon);
+
+ // Add the child to end and return
+ return $this->add_node($childnode);
+ }
+
+ /**
+ * Adds a navigation node as a child of this one, given a $node object
+ * created using the create function.
+ * @param navigation_node $childnode Node to add
+ * @param int|string $key The key of a node to add this before. If not
+ * specified, adds at end of list
+ * @return navigation_node The added node
+ */
+ public function add_node(navigation_node $childnode, $beforekey=null) {
+ // First convert the nodetype for this node to a branch as it will now have children
+ if ($this->nodetype !== self::NODETYPE_BRANCH) {
+ $this->nodetype = self::NODETYPE_BRANCH;
+ }
// Set the parent to this node
- $itemarray['parent'] = $this;
+ $childnode->parent = $this;
+
+ // Default the key to the number of children if not provided
+ if ($childnode->key === null) {
+ $childnode->key = $this->children->count();
+ }
+
// Add the child using the navigation_node_collections add method
- $node = $this->children->add(new navigation_node($itemarray));
- // If the node is a category node or the user is logged in and its a course
- // then mark this node as a branch (makes it expandable by AJAX)
+ $node = $this->children->add($childnode, $beforekey);
+
+ // If added node is a category node or the user is logged in and it's a course
+ // then mark added node as a branch (makes it expandable by AJAX)
+ $type = $childnode->type;
if (($type==self::TYPE_CATEGORY) || (isloggedin() && $type==self::TYPE_COURSE)) {
$node->nodetype = self::NODETYPE_BRANCH;
}
// If this node is hidden mark it's children as hidden also
if ($this->hidden) {
$node->hidden = true;
}
- // Return the node (reference returned by $this->children->add()
+ // Return added node (reference returned by $this->children->add()
return $node;
}
@@ -647,13 +684,16 @@ class navigation_node_collection implements IteratorAggregate {
/**
* Adds a navigation node to the collection
*
- * @param navigation_node $node
- * @return navigation_node
+ * @param navigation_node $node Node to add
+ * @param string $beforekey If specified, adds before a node with this key,
+ * otherwise adds at end
+ * @return navigation_node Added node
*/
- public function add(navigation_node $node) {
+ public function add(navigation_node $node, $beforekey=null) {
global $CFG;
$key = $node->key;
$type = $node->type;
+
// First check we have a 2nd dimension for this type
if (!array_key_exists($type, $this->orderedcollection)) {
$this->orderedcollection[$type] = array();
@@ -662,15 +702,50 @@ public function add(navigation_node $node) {
if ($CFG->debug && array_key_exists($key, $this->orderedcollection[$type])) {
debugging('Navigation node intersect: Adding a node that already exists '.$key, DEBUG_DEVELOPER);
}
- // Add the node to the appropriate place in the ordered structure.
+
+ // Find the key to add before
+ $newindex = $this->count;
+ $last = true;
+ if ($beforekey !== null) {
+ foreach ($this->collection as $index => $othernode) {
+ if ($othernode->key === $beforekey) {
+ $newindex = $index;
+ $last = false;
+ break;
+ }
+ }
+ if ($newindex === $this->count) {
+ $allkeys = '';
+ foreach ($this->collection as $othernode) {
+ $allkeys .= ' ' . $othernode->key;
+ }
+ debugging('Navigation node add_before: Reference node not found ' . $beforekey .
+ ', options: ' . $allkeys, DEBUG_DEVELOPER);
+ }
+ }
+
+ // Add the node to the appropriate place in the by-type structure (which
+ // is not ordered, despite the variable name)
$this->orderedcollection[$type][$key] = $node;
+ if (!$last) {
+ // Update existing references in the ordered collection (which is the
+ // one that isn't called 'ordered') to shuffle them along if required
+ for ($oldindex = $this->count; $oldindex > $newindex; $oldindex--) {
+ $this->collection[$oldindex] = $this->collection[$oldindex - 1];
+ }
+ }
// Add a reference to the node to the progressive collection.
- $this->collection[$this->count] = &$this->orderedcollection[$type][$key];
+ $this->collection[$newindex] = &$this->orderedcollection[$type][$key];
// Update the last property to a reference to this new node.
$this->last = &$this->orderedcollection[$type][$key];
+
+ // Reorder the array by index if needed
+ if (!$last) {
+ ksort($this->collection);
+ }
$this->count++;
// Return the reference to the now added node
- return $this->last;
+ return $node;
}
/**
@@ -1700,9 +1775,16 @@ protected function load_for_user($user=null, $forceforcontext=false) {
}
// Add a reports tab and then add reports the the user has permission to see.
- $anyreport = has_capability('moodle/user:viewuseractivitiesreport', $usercontext);
+ $anyreport = has_capability('moodle/user:viewuseractivitiesreport', $usercontext);
+
+ $outlinetreport = ($anyreport || has_capability('coursereport/outline:view', $coursecontext));
+ $logtodayreport = ($anyreport || has_capability('coursereport/log:viewtoday', $coursecontext));
+ $logreport = ($anyreport || has_capability('coursereport/log:view', $coursecontext));
+ $statsreport = ($anyreport || has_capability('coursereport/stats:view', $coursecontext));
+
+ $somereport = $outlinetreport || $logtodayreport || $logreport || $statsreport;
- $viewreports = ($anyreport || ($course->showreports && $iscurrentuser && $forceforcontext));
+ $viewreports = ($anyreport || $somereport || ($course->showreports && $iscurrentuser && $forceforcontext));
if ($viewreports) {
$reporttab = $usernode->add(get_string('activityreports'));
$reportargs = array('user'=>$user->id);
@@ -1711,21 +1793,21 @@ protected function load_for_user($user=null, $forceforcontext=false) {
} else {
$reportargs['id'] = SITEID;
}
- if ($viewreports || has_capability('coursereport/outline:view', $coursecontext)) {
+ if ($viewreports || $outlinetreport) {
$reporttab->add(get_string('outlinereport'), new moodle_url('/course/user.php', array_merge($reportargs, array('mode'=>'outline'))));
$reporttab->add(get_string('completereport'), new moodle_url('/course/user.php', array_merge($reportargs, array('mode'=>'complete'))));
}
- if ($viewreports || has_capability('coursereport/log:viewtoday', $coursecontext)) {
+ if ($viewreports || $logtodayreport) {
$reporttab->add(get_string('todaylogs'), new moodle_url('/course/user.php', array_merge($reportargs, array('mode'=>'todaylogs'))));
}
- if ($viewreports || has_capability('coursereport/log:view', $coursecontext)) {
+ if ($viewreports || $logreport ) {
$reporttab->add(get_string('alllogs'), new moodle_url('/course/user.php', array_merge($reportargs, array('mode'=>'alllogs'))));
}
if (!empty($CFG->enablestats)) {
- if ($viewreports || has_capability('coursereport/stats:view', $coursecontext)) {
+ if ($viewreports || $statsreport) {
$reporttab->add(get_string('stats'), new moodle_url('/course/user.php', array_merge($reportargs, array('mode'=>'stats'))));
}
}
View
@@ -347,10 +347,11 @@ public static function standard_plugins_list($type) {
),
'theme' => array(
- 'anomaly', 'arialist', 'base', 'binarius', 'boxxie', 'brick',
- 'canvas', 'formal_white', 'formfactor', 'fusion',
- 'leatherbound', 'magazine', 'nimble', 'nonzero', 'overlay',
- 'serenity', 'sky_high', 'splash', 'standard', 'standardold'
+ 'afterburner', 'anomaly', 'arialist', 'base', 'binarius',
+ 'boxxie', 'brick', 'canvas', 'formal_white', 'formfactor',
+ 'fusion', 'leatherbound', 'magazine', 'nimble', 'nonzero',
+ 'overlay', 'serenity', 'sky_high', 'splash', 'standard',
+ 'standardold'
),
'webservice' => array(
@@ -98,6 +98,28 @@ public function test_add() {
$this->assertReference($node3, $this->node->get($node3->key, $node3->type));
}
+ public function test_add_before() {
+ global $CFG;
+ // Create 3 nodes
+ $node1 = navigation_node::create('test_add_1', null, navigation_node::TYPE_CUSTOM,
+ 'test 1', 'testadd1');
+ $node2 = navigation_node::create('test_add_2', null, navigation_node::TYPE_CUSTOM,
+ 'test 2', 'testadd2');
+ $node3 = navigation_node::create('test_add_3', null, navigation_node::TYPE_CUSTOM,
+ 'test 3', 'testadd3');
+ // Add node 2, then node 1 before 2, then node 3 at end
+ $this->node->add_node($node2);
+ $this->node->add_node($node1, 'testadd2');
+ $this->node->add_node($node3);
+ // Check the last 3 nodes are in 1, 2, 3 order and have those indexes
+ foreach($this->node->children as $child) {
+ $keys[] = $child->key;
+ }
+ $this->assertEqual('testadd1', $keys[count($keys)-3]);
+ $this->assertEqual('testadd2', $keys[count($keys)-2]);
+ $this->assertEqual('testadd3', $keys[count($keys)-1]);
+ }
+
public function test_add_class() {
$node = $this->node->get('demo1');
$this->assertIsA($node, 'navigation_node');
Oops, something went wrong.

0 comments on commit a78b139

Please sign in to comment.