Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions block_course_level.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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 = '';

}
Expand Down
26 changes: 18 additions & 8 deletions db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
)

);
3 changes: 2 additions & 1 deletion lang/en/block_course_level.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
22 changes: 14 additions & 8 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
}
Expand Down Expand Up @@ -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) {
Expand Down
73 changes: 61 additions & 12 deletions renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ 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;
$this->trimlength = $trimlength;
$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);
}

Expand Down Expand Up @@ -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';
Expand All @@ -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';
Expand All @@ -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', '');

Expand All @@ -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);
}
Expand All @@ -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));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down