Merge branch 'wip-mdl-37329-new' of git://github.com/rajeshtaneja/moodle

This commit is contained in:
Damyon Wiese 2013-02-20 08:54:57 +08:00
commit cfd2addf3f
3 changed files with 41 additions and 19 deletions

View file

@ -24,6 +24,6 @@
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
$plugin->version = 2012112900; // The current plugin version (Date: YYYYMMDDXX) $plugin->version = 2013020800; // The current plugin version (Date: YYYYMMDDXX)
$plugin->requires = 2012112900; // Requires this Moodle version $plugin->requires = 2012112900; // Requires this Moodle version
$plugin->component = 'block_navigation'; // Full name of the plugin (used for diagnostics) $plugin->component = 'block_navigation'; // Full name of the plugin (used for diagnostics)

View file

@ -86,6 +86,8 @@ var NODETYPE = {
SYSTEM : 1, SYSTEM : 1,
/** @type int Course category = 10 */ /** @type int Course category = 10 */
CATEGORY : 10, CATEGORY : 10,
/** @type int MYCATEGORY = 11 */
MYCATEGORY : 11,
/** @type int Course = 20 */ /** @type int Course = 20 */
COURSE : 20, COURSE : 20,
/** @type int Course section = 30 */ /** @type int Course section = 30 */
@ -454,7 +456,8 @@ BRANCH.prototype = {
this.addChild(object.children[i]); this.addChild(object.children[i]);
} }
} }
if ((this.get('type') == NODETYPE.CATEGORY || this.get('type') == NODETYPE.ROOTNODE) && coursecount >= M.block_navigation.courselimit) { if ((this.get('type') == NODETYPE.CATEGORY || this.get('type') == NODETYPE.ROOTNODE || this.get('type') == NODETYPE.MYCATEGORY)
&& coursecount >= M.block_navigation.courselimit) {
this.addViewAllCoursesChild(this); this.addViewAllCoursesChild(this);
} }
this.get('tree').toggleExpansion({target:this.node}); this.get('tree').toggleExpansion({target:this.node});
@ -486,7 +489,8 @@ BRANCH.prototype = {
branch.addChild(children[i]); branch.addChild(children[i]);
} }
} }
if (branch.get('type') == NODETYPE.CATEGORY && count >= M.block_navigation.courselimit) { if ((branch.get('type') == NODETYPE.CATEGORY || branch.get('type') == NODETYPE.MYCATEGORY)
&& count >= M.block_navigation.courselimit) {
this.addViewAllCoursesChild(branch); this.addViewAllCoursesChild(branch);
} }
} }

View file

@ -57,6 +57,8 @@ class navigation_node implements renderable {
const TYPE_SYSTEM = 1; const TYPE_SYSTEM = 1;
/** @var int Category node type 10 */ /** @var int Category node type 10 */
const TYPE_CATEGORY = 10; const TYPE_CATEGORY = 10;
/** var int Category displayed in MyHome navigation node */
const TYPE_MY_CATEGORY = 11;
/** @var int Course node type 20 */ /** @var int Course node type 20 */
const TYPE_COURSE = 20; const TYPE_COURSE = 20;
/** @var int Course Structure node type 30 */ /** @var int Course Structure node type 30 */
@ -322,7 +324,7 @@ class navigation_node implements renderable {
// If added node is a category node or the user is logged in and it's a course // 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) // then mark added node as a branch (makes it expandable by AJAX)
$type = $childnode->type; $type = $childnode->type;
if (($type==self::TYPE_CATEGORY) || (isloggedin() && $type==self::TYPE_COURSE)) { if (($type == self::TYPE_CATEGORY) || (isloggedin() && ($type == self::TYPE_COURSE)) || ($type == self::TYPE_MY_CATEGORY)) {
$node->nodetype = self::NODETYPE_BRANCH; $node->nodetype = self::NODETYPE_BRANCH;
} }
// If this node is hidden mark it's children as hidden also // If this node is hidden mark it's children as hidden also
@ -1515,7 +1517,7 @@ class global_navigation extends navigation_node {
} }
$coursecount = count($this->addedcategories[$category]->children->type(self::TYPE_COURSE)); $coursecount = count($this->addedcategories[$category]->children->type(self::TYPE_COURSE));
} else if ($category instanceof navigation_node) { } else if ($category instanceof navigation_node) {
if ($category->type != self::TYPE_CATEGORY) { if (($category->type != self::TYPE_CATEGORY) || ($category->type != self::TYPE_MY_CATEGORY)) {
return false; return false;
} }
$coursecount = count($category->children->type(self::TYPE_COURSE)); $coursecount = count($category->children->type(self::TYPE_COURSE));
@ -1684,17 +1686,19 @@ class global_navigation extends navigation_node {
/** /**
* Adds a structured category to the navigation in the correct order/place * Adds a structured category to the navigation in the correct order/place
* *
* @param stdClass $category * @param stdClass $category category to be added in navigation.
* @param navigation_node $parent * @param navigation_node $parent parent navigation node
* @param int $nodetype type of node, if category is under MyHome then it's TYPE_MY_CATEGORY
* @return void.
*/ */
protected function add_category(stdClass $category, navigation_node $parent) { protected function add_category(stdClass $category, navigation_node $parent, $nodetype = self::TYPE_CATEGORY) {
if (array_key_exists($category->id, $this->addedcategories)) { if (array_key_exists($category->id, $this->addedcategories)) {
return; return;
} }
$url = new moodle_url('/course/category.php', array('id' => $category->id)); $url = new moodle_url('/course/category.php', array('id' => $category->id));
$context = context_coursecat::instance($category->id); $context = context_coursecat::instance($category->id);
$categoryname = format_string($category->name, true, array('context' => $context)); $categoryname = format_string($category->name, true, array('context' => $context));
$categorynode = $parent->add($categoryname, $url, self::TYPE_CATEGORY, $categoryname, $category->id); $categorynode = $parent->add($categoryname, $url, $nodetype, $categoryname, $category->id);
if (empty($category->visible)) { if (empty($category->visible)) {
if (has_capability('moodle/category:viewhiddencategories', get_system_context())) { if (has_capability('moodle/category:viewhiddencategories', get_system_context())) {
$categorynode->hidden = true; $categorynode->hidden = true;
@ -2318,7 +2322,7 @@ class global_navigation extends navigation_node {
$parent = $this->rootnodes['currentcourse']; $parent = $this->rootnodes['currentcourse'];
$url = new moodle_url('/course/view.php', array('id'=>$course->id)); $url = new moodle_url('/course/view.php', array('id'=>$course->id));
} else if ($coursetype == self::COURSE_MY && !$forcegeneric) { } else if ($coursetype == self::COURSE_MY && !$forcegeneric) {
if (!empty($CFG->navshowmycoursecategories) && ($parent = $this->rootnodes['mycourses']->find($course->category, self::TYPE_CATEGORY))) { if (!empty($CFG->navshowmycoursecategories) && ($parent = $this->rootnodes['mycourses']->find($course->category, self::TYPE_MY_CATEGORY))) {
// Nothing to do here the above statement set $parent to the category within mycourses. // Nothing to do here the above statement set $parent to the category within mycourses.
} else { } else {
$parent = $this->rootnodes['mycourses']; $parent = $this->rootnodes['mycourses'];
@ -2625,6 +2629,9 @@ class global_navigation_for_ajax extends global_navigation {
case self::TYPE_CATEGORY : case self::TYPE_CATEGORY :
$this->load_category($this->instanceid); $this->load_category($this->instanceid);
break; break;
case self::TYPE_MY_CATEGORY :
$this->load_category($this->instanceid, self::TYPE_MY_CATEGORY);
break;
case self::TYPE_COURSE : case self::TYPE_COURSE :
$course = $DB->get_record('course', array('id' => $this->instanceid), '*', MUST_EXIST); $course = $DB->get_record('course', array('id' => $this->instanceid), '*', MUST_EXIST);
require_course_login($course, true, null, false, true); require_course_login($course, true, null, false, true);
@ -2703,7 +2710,7 @@ class global_navigation_for_ajax extends global_navigation {
list($sql, $params) = $DB->get_in_or_equal($categoryids); list($sql, $params) = $DB->get_in_or_equal($categoryids);
$categories = $DB->get_recordset_select('course_categories', 'id '.$sql.' AND parent = 0', $params, 'sortorder, id'); $categories = $DB->get_recordset_select('course_categories', 'id '.$sql.' AND parent = 0', $params, 'sortorder, id');
foreach ($categories as $category) { foreach ($categories as $category) {
$this->add_category($category, $this->rootnodes['mycourses']); $this->add_category($category, $this->rootnodes['mycourses'], self::TYPE_MY_CATEGORY);
} }
$categories->close(); $categories->close();
} else { } else {
@ -2729,9 +2736,11 @@ class global_navigation_for_ajax extends global_navigation {
* request that. * request that.
* *
* @global moodle_database $DB * @global moodle_database $DB
* @param int $categoryid * @param int $categoryid id of category to load in navigation.
* @param int $nodetype type of node, if category is under MyHome then it's TYPE_MY_CATEGORY
* @return void.
*/ */
protected function load_category($categoryid) { protected function load_category($categoryid, $nodetype = self::TYPE_CATEGORY) {
global $CFG, $DB; global $CFG, $DB;
$limit = 20; $limit = 20;
@ -2753,7 +2762,7 @@ class global_navigation_for_ajax extends global_navigation {
foreach ($categories as $category) { foreach ($categories as $category) {
context_helper::preload_from_record($category); context_helper::preload_from_record($category);
if ($category->id == $categoryid) { if ($category->id == $categoryid) {
$this->add_category($category, $this); $this->add_category($category, $this, $nodetype);
$basecategory = $this->addedcategories[$category->id]; $basecategory = $this->addedcategories[$category->id];
} else { } else {
$subcategories[] = $category; $subcategories[] = $category;
@ -2763,15 +2772,23 @@ class global_navigation_for_ajax extends global_navigation {
if (!is_null($basecategory)) { if (!is_null($basecategory)) {
foreach ($subcategories as $category) { foreach ($subcategories as $category) {
$this->add_category($category, $basecategory); $this->add_category($category, $basecategory, $nodetype);
} }
} }
$courses = $DB->get_recordset('course', array('category' => $categoryid), 'sortorder', '*' , 0, $limit); // If category is shown in MyHome then only show enrolled courses, else show all courses.
foreach ($courses as $course) { if ($nodetype === self::TYPE_MY_CATEGORY) {
$this->add_course($course); $courses = enrol_get_my_courses();
foreach ($courses as $course) {
$this->add_course($course, true, self::COURSE_MY);
}
} else {
$courses = $DB->get_recordset('course', array('category' => $categoryid), 'sortorder', '*' , 0, $limit);
foreach ($courses as $course) {
$this->add_course($course);
}
$courses->close();
} }
$courses->close();
} }
/** /**
@ -4279,6 +4296,7 @@ class navigation_json {
} }
$attributes['hidden'] = ($child->hidden); $attributes['hidden'] = ($child->hidden);
$attributes['haschildren'] = ($child->children->count()>0 || $child->type == navigation_node::TYPE_CATEGORY); $attributes['haschildren'] = ($child->children->count()>0 || $child->type == navigation_node::TYPE_CATEGORY);
$attributes['haschildren'] = $attributes['haschildren'] || $child->type == navigation_node::TYPE_MY_CATEGORY;
if ($child->children->count() > 0) { if ($child->children->count() > 0) {
$attributes['children'] = array(); $attributes['children'] = array();