diff --git a/block_course_level.php b/block_course_level.php index 7c2ca2f..1108351 100644 --- a/block_course_level.php +++ b/block_course_level.php @@ -127,7 +127,10 @@ public function get_content() { // Do we show hidden courses? $context = get_context_instance(CONTEXT_SYSTEM); - $showhiddencourses = has_capability('block/course_level:show_hidden_courses', $context); + $showhiddencoursesstudents = has_capability('block/course_level:show_hidden_courses_students', $context); + $showhiddencoursesstaff = has_capability('block/course_level:show_hidden_courses_staff', $context); + + // $showhiddencourses = has_capability('block/course_level:show_hidden_courses_staff', $context); $this->content = new stdClass(); @@ -144,7 +147,7 @@ public function get_content() { if(!$courseid) { $courseid = 1; // Assume we are on the site front page } - $this->content->text = $renderer->course_level_tree($showcode, $trimmode, $trimlength, $courseid, $showmoodlecourses, $admin_tool_url, $admin_tool_magic_text, $showhiddencourses); + $this->content->text = $renderer->course_level_tree($showcode, $trimmode, $trimlength, $courseid, $showmoodlecourses, $admin_tool_url, $admin_tool_magic_text, $showhiddencoursesstudents, $showhiddencoursesstaff); $this->content->footer = ''; } diff --git a/db/access.php b/db/access.php index b104590..570749d 100644 --- a/db/access.php +++ b/db/access.php @@ -45,12 +45,22 @@ ) ), - 'block/course_level:show_hidden_courses' => array( - 'riskbitmask' => RISK_PERSONAL, - 'captype' => 'write', - 'contextlevel' => CONTEXT_SYSTEM, - 'archetypes' => array( - 'manager' => CAP_ALLOW - ) - ) + 'block/course_level:show_hidden_courses_staff' => array( + 'riskbitmask' => RISK_PERSONAL, + 'captype' => 'write', + 'contextlevel' => CONTEXT_SYSTEM, + 'archetypes' => array( + 'manager' => CAP_ALLOW + ) + ), + + 'block/course_level:show_hidden_courses_students' => array( + 'riskbitmask' => RISK_PERSONAL, + 'captype' => 'write', + 'contextlevel' => CONTEXT_SYSTEM, + 'archetypes' => array( + 'manager' => CAP_ALLOW + ) + ) + ); diff --git a/lang/en/block_course_level.php b/lang/en/block_course_level.php index 64c7412..d993e56 100644 --- a/lang/en/block_course_level.php +++ b/lang/en/block_course_level.php @@ -90,4 +90,5 @@ // Capabilities $string['course_level:can_edit'] = 'Can edit'; $string['course_level:admin_db_link'] = 'Display Admin DB Tool Link'; -$string['course_level:show_hidden_courses'] = 'Show hidden courses'; +$string['course_level:show_hidden_courses_staff'] = 'Show hidden courses: staff'; +$string['course_level:show_hidden_courses_students'] = 'Show hidden courses: students'; diff --git a/lib.php b/lib.php index 010934b..16b10d0 100644 --- a/lib.php +++ b/lib.php @@ -212,14 +212,19 @@ private function construct_view_tree($programmes, $courses, $units) { $this->orphaned_units = $orphaned_units; // Finally, finally... loop through courses and insert 'overview' pages where necessary. - foreach($result as $course) { - if($course->get_children() != null) { - $overview = clone $course; - $overview->set_fullname(get_string('homepage', 'block_course_level')); - $overview->set_shortname(get_string('homepage', 'block_course_level')); - $overview->abandon_children(); - - $course->push_child($overview); + foreach($result as $course_all_years) { + if($course_all_years->get_children() != null) { + $courses = $course_all_years->get_children(); + foreach($courses as $this_course) { + if(isset($this_course)) { + $overview = clone $this_course; + $overview->set_fullname(get_string('homepage', 'block_course_level')); + $overview->set_shortname(get_string('homepage', 'block_course_level')); + $overview->abandon_children(); + + $this_course->push_child($overview); + } + } } } } @@ -263,6 +268,7 @@ private function get_years_from_courses($course_years) { $new_course->set_fullname($moodle_course->fullname); $mis = ual_api::getInstance(); $new_course->set_user_enrolled($mis->get_enrolled($USER->id, $moodle_course->id)); + $new_course->set_visible($moodle_course->visible); } foreach($courses as $course) { diff --git a/renderer.php b/renderer.php index 5cf5919..c919beb 100644 --- a/renderer.php +++ b/renderer.php @@ -45,7 +45,7 @@ class block_course_level_renderer extends plugin_renderer_base { * Prints course level tree view * @return string */ - public function course_level_tree($showcode, $trimmode, $trimlength, $courseid, $showmoodlecourses, $admin_tool_url, $admin_tool_magic_text, $showhiddencourses) { + public function course_level_tree($showcode, $trimmode, $trimlength, $courseid, $showmoodlecourses, $admin_tool_url, $admin_tool_magic_text, $showhiddencoursesstudents, $showhiddencoursesstaff ) { $this->showcode = $showcode; $this->showmoodlecourses = $showmoodlecourses; $this->trimmode = $trimmode; @@ -53,8 +53,8 @@ public function course_level_tree($showcode, $trimmode, $trimlength, $courseid, $this->courseid = $courseid; $this->admin_tool_url = $admin_tool_url; $this->admin_tool_magic_text = $admin_tool_magic_text; - $this->showhiddencourses = $showhiddencourses; - + $this->showhiddencoursesstudents = $showhiddencoursesstudents; + $this->showhiddencoursesstaff = $showhiddencoursesstaff; return $this->render(new course_level_tree); } @@ -141,7 +141,7 @@ public function render_course_level_tree(course_level_tree $tree) { * @return string */ protected function htmllize_tree($tree, $indent=0) { - global $CFG; + global $CFG, $USER; $yuiconfig = array(); $yuiconfig['type'] = 'html'; @@ -163,6 +163,9 @@ protected function htmllize_tree($tree, $indent=0) { $name = preg_replace('/&(?![#]?[a-z0-9]+;)/i', "&$1", $name); $name = $this->trim($name); + // Is this course visible? + $visible = $node->get_visible(); + $node_type = $node->get_type(); $type_class = 'unknown'; @@ -182,10 +185,24 @@ protected function htmllize_tree($tree, $indent=0) { break; } - $display_node = $node->get_visible() || $this->showhiddencourses; - $attributes = array(); + // is the node hidden? + if($visible == false) { + //$attributes['class'] = 'hidden'; + + $ual_api = ual_api::getInstance(); + if(isset($ual_api)) { + $role = $ual_api->get_user_role($USER->username); + + if($role) { + $showhiddencourses = (((strcmp($role, 'STAFF') == 0) && $this->showhiddencoursesstaff) || ((strcmp($role, 'STUDENT') == 0) && $this->showhiddencoursesstudents)); + } + } + } + + $display_node = $node->get_visible() || $showhiddencourses; + // Insert a span tag to allow us to insert an arrow... $span = html_writer::tag('span', ''); @@ -201,7 +218,7 @@ protected function htmllize_tree($tree, $indent=0) { // Display the name but it's not clickable... // TODO make this a configuration option... if($this->showhiddencourses) { - $attributes['class'] = 'hidden'; + $attributes['class'] = 'hidden'; } $content = html_writer::tag('i', $name, $attributes); } @@ -210,13 +227,45 @@ protected function htmllize_tree($tree, $indent=0) { } } else { // This is an expandable node... - $content = html_writer::tag('div', $name.$span, $attributes); + if($display_node) { + if ($node_type == ual_course::COURSETYPE_ALLYEARS){ + if(($node->get_user_enrolled() == true) && $node->get_visible()) { + $moodle_url = $CFG->wwwroot.'/course/view.php?id='.$node->get_moodle_course_id(); + $content = html_writer::link($moodle_url, $name, $attributes); + }else { + // Display the name but it's not clickable... + // TODO make this a configuration option... + if($this->showhiddencourses) { + $attributes['class'] = 'hidden'; + } + + // $content = html_writer::tag('i', $name, $attributes); + // $content = html_writer::label($name, '#'); + // $content = html_writer::tag('div', $name.$span, $attributes); + $content = html_writer::link('#', $name, $attributes); - if($indent != 0) { - $attributes['class'] = 'expanded'; + } + // Append 'expanded' to the class type + $type_class = $type_class . ' expanded'; + }elseif($node_type == ual_course::COURSETYPE_COURSE){ + $content = html_writer::tag('div', $name.$span, $attributes); + } + $result .= html_writer::tag('li', $content.$this->htmllize_tree($children, $indent+1), array('yuiConfig'=>json_encode($yuiconfig), 'class' => $type_class)); + } else { + // Expandable but hidden node. + if ($node_type == ual_course::COURSETYPE_COURSE){ + $content = html_writer::tag('div', $name.$span, $attributes); + // Get rid of 'overview' - the link that accesses the course. + unset($children[0]); + $result .= html_writer::tag('li', $content.$this->htmllize_tree($children, $indent+1), array('yuiConfig'=>json_encode($yuiconfig), 'class' => $type_class)); + } else { + $type_class = $type_class . ' expanded'; + // $content = html_writer::tag('div', '', $attributes); + $content = html_writer::link('', '', $attributes); + $result .= html_writer::tag('li', $content.$this->htmllize_tree($children, $indent+1), array('yuiConfig'=>json_encode($yuiconfig), 'class' => $type_class)); + // $result .= $this->htmllize_tree($children, $indent+1); + } } - - $result .= html_writer::tag('li', $content.$this->htmllize_tree($children, $indent+1), array('yuiConfig'=>json_encode($yuiconfig), 'class' => $type_class)); } } } diff --git a/version.php b/version.php index f9a9726..87c20be 100644 --- a/version.php +++ b/version.php @@ -25,7 +25,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -$plugin->version = 2013030403; +$plugin->version = 2013050100; $plugin->maturity = MATURITY_ALPHA; $plugin->requires = 2011070100; // 2.1. $plugin->component = 'block_course_level';