. /** * Competence Graph * * Competence graph format allows the visualization of courses with competencies in a graph. * In the course structure, teacher associates activities to competencies. Each course module * can have restrictions between them, so a module is opened only when the student accomplish * its requirements. In student visualization, the structure of the course is presented as a * graph. In such graph, each node is a resource available to the student that can be handled. * Subgraphs in the main graph represent competences. As students can have different paths in * the course, the plugin registers all the steps that a student produces. * * @package course/format * @subpackage competencegraph * @version 0.1 * @author Laboratório de Informática na Educação * @link http://www.usp.br/line/competencegraph * @license http://www.gnu.org/copyleft/gpl.html GNU Public License */ defined('MOODLE_INTERNAL') || die(); use core_competency\course_competency; use core_competency\api; use core_competency\course_module_competency; require_once($CFG->dirroot . '/course/format/renderer.php'); require_once($CFG->dirroot . '/course/format/competencegraph/lib.php'); class format_competencegraph_renderer extends format_section_renderer_base { public function __construct(moodle_page $page, $target) { parent::__construct($page, $target); global $PAGE; //$this->courserenderer = $PAGE->get_renderer('core','course'); $this->courseformat = course_get_format($page->course); // Needed for collapsed topics settings retrieval. $page->set_other_editing_capability('moodle/course:setcurrentsection'); $this->userisediting = $page->user_is_editing(); $this->rtl = right_to_left(); if (strcmp($page->theme->name, 'boost') === 0) { $this->bsnewgrid = true; } else if (!empty($page->theme->parents)) { if (in_array('boost', $page->theme->parents) === true) { $this->bsnewgrid = true; } } } protected function start_section_list() { if ($this->bsnewgrid) { return html_writer::start_tag('ul', array('class' => 'ctopics bsnewgrid')); } else { return html_writer::start_tag('ul', array('class' => 'ctopics')); } } protected function end_section_list() { return html_writer::end_tag('ul'); } protected function page_title() { return get_string('sectionname', 'format_competencegrah'); } public function set_portable($portable) { switch ($portable) { case 1: $this->mobiletheme = true; break; case 2: $this->tablettheme = true; break; default: $this->mobiletheme = false; $this->tablettheme = false; break; } } public function print_graph_teacher_view($course, $sections, $mods, $modnames, $modnamesused) { $context = context_course::instance($course->id); echo ''; if (has_capability('moodle/course:update', $context)) { $maintabs = array( new tabobject( 'tab_list', '?id='.$course->id.'&format=list', get_string('listview', 'format_competencegraph'), get_string('listview', 'format_competencegraph') ), new tabobject( 'tab_graph', '?id='.$course->id.'&format=graph', get_string('graphview', 'format_competencegraph'), get_string('graphview', 'format_competencegraph') ) ); $active = 'tab_graph'; print_tabs( array($maintabs), $active ); //echo $this->get_js_dependencies_sigma_graph(); //$this->print_test_graph($course, $sections, $mods, $modnames, $modnamesused); echo ''; $this->print_nodes_graph($course, $sections, $mods, $modnames, $modnamesused); } else { echo ''; $this->print_nodes_graph($course, $sections, $mods, $modnames, $modnamesused); } } public function print_nodes_graph($course, $sections, $mods, $modnames, $modnamesused) { echo ""; print ''; print ''; print ''; print ' '; } public function print_multiple_section_page($course, $sections, $mods, $modnames, $modnamesused) { $context = context_course::instance($course->id); global $OUTPUT; if (has_capability('moodle/course:update', $context)) { echo $this->get_css_list_teacher(); //$this->print_modules_page_teacher_list($course, $sections, $mods, $modnames, $modnamesused); $modinfo = get_fast_modinfo($course); $course = $this->courseformat->get_course(); $context = context_course::instance($course->id); $sections = $modinfo->get_section_info_all(); // General section if non-empty. $thissection = $sections[0]; if ($thissection->summary or ! empty($modinfo->sections[0]) or $this->userisediting) { print('
'); echo $this->section_header($thissection, $course, false, 0); print('
'); echo $this->courserenderer->course_section_add_cm_control($course, $thissection->section, 0); } $maintabs = array( new tabobject( 'tab_list', '?id='.$course->id.'&format=list', get_string('listview', 'format_competencegraph'), get_string('listview', 'format_competencegraph') ), new tabobject( 'tab_graph', '?id='.$course->id.'&format=graph', get_string('graphview', 'format_competencegraph'), get_string('graphview', 'format_competencegraph') ) ); $active = 'tab_list'; print_tabs( array($maintabs), $active ); // Print the competencies as name section: $list_competencies = course_competency::list_course_competencies($course->id); if (count($list_competencies) < 1) { echo '
' . get_string('coursewithoutcompetence', 'format_competencegraph') . '
'; } $all_mod_info_printed = array(); foreach ($list_competencies as $competence) { $idcompetence = $competence->get('competencyid'); echo '

' . api::read_competency($idcompetence)->get('shortname') . '

'; $list_modules = course_module_competency::list_course_modules($idcompetence, $course->id); if (!$list_modules || count($list_modules) < 1) { echo '
' . get_string('emptycompetence', 'format_competencegraph') . "
"; } echo $this->course_section_cm_list($course, null, 0, array(), $list_modules); foreach ($list_modules as $item) { array_push($all_mod_info_printed, $item); } } $list_mod_without_competences = array(); foreach ($modinfo->cms as $tempmod) { if (!in_array($tempmod->id, $all_mod_info_printed)) { array_push($list_mod_without_competences, $tempmod->id); } } if (count($list_mod_without_competences) > 0) { echo '

' . get_string('itemswithoutcompetence', 'format_competencegraph') . '

'; echo $this->course_section_cm_list($course, null, 0, array(), $list_mod_without_competences); } $sections = $modinfo->get_section_info_all(); // General section if non-empty. $thissection = $sections[0]; if ($thissection->summary or ! empty($modinfo->sections[0]) or $this->userisediting) { print('
'); echo $this->section_header($thissection, $course, false, 0); print('
'); echo $this->courserenderer->course_section_add_cm_control($course, $thissection->section, 0); } } } public function course_section_cm_list($course, $section, $sectionreturn = null, $displayoptions = array(), $includeditems = array()) { global $USER; $output = ''; $modinfo = get_fast_modinfo($course); $completioninfo = new completion_info($course); // check if we are currently in the process of moving a module with JavaScript disabled $ismoving = $this->page->user_is_editing() && ismoving($course->id); if ($ismoving) { $movingpix = new pix_icon('movehere', get_string('movehere'), 'moodle', array('class' => 'movetarget')); $strmovefull = strip_tags(get_string("movefull", "", "'$USER->activitycopyname'")); } // Get the list of modules visible to user (excluding the module being moved if there is one) $moduleshtml = array(); foreach ($includeditems as $modnumber) { $mod = $modinfo->cms[$modnumber]; /*if ($mod->availability) { echo $modnumber . ':: '; print_r($mod->availability); }*/ if ($ismoving and $mod->id == $USER->activitycopy) { // do not display moving mod continue; } if ($modulehtml = $this->courserenderer->course_section_cm_list_item($course, $completioninfo, $mod, $sectionreturn, $displayoptions)) { $moduleshtml[$modnumber] = $modulehtml; } } $sectionoutput = ''; if (!empty($moduleshtml) || $ismoving) { foreach ($moduleshtml as $modnumber => $modulehtml) { if ($ismoving) { $movingurl = new moodle_url('/course/mod.php', array('moveto' => $modnumber, 'sesskey' => sesskey())); $sectionoutput .= html_writer::tag('li', html_writer::link($movingurl, $this->output->render($movingpix), array('title' => $strmovefull)), array('class' => 'movehere')); } $sectionoutput .= $modulehtml; } if ($ismoving) { $movingurl = new moodle_url('/course/mod.php', array('movetosection' => $section->id, 'sesskey' => sesskey())); $sectionoutput .= html_writer::tag('li', html_writer::link($movingurl, $this->output->render($movingpix), array('title' => $strmovefull)), array('class' => 'movehere')); } } // Always output the section module list. $output .= html_writer::tag('ul', $sectionoutput, array('class' => 'section img-text')); return $output; } public function print_modules_page_teacher_list($course, $sections, $mods, $modnames, $modnamesused) { $modinfo = get_fast_modinfo($course); $course = $this->courseformat->get_course(); $context = context_course::instance($course->id); //echo $this->start_section_list(); $sections = $modinfo->get_section_info_all(); // General section if non-empty. $thissection = $sections[0]; if ($thissection->summary or ! empty($modinfo->sections[0]) or $this->userisediting) { echo $this->section_header($thissection, $course, false, 0); //echo $this->course_section_cm_list($course, $thissection, 0); echo $this->courserenderer->course_section_add_cm_control($course, $thissection->section, 0); } $coursenumsections = $this->courseformat->get_last_section_number(); if ($coursenumsections > 0) { $sectiondisplayarray = array(); $currentsectionfirst = false; if ((!$this->userisediting)) { $currentsectionfirst = true; } if (($this->userisediting)) { $section = 1; } else { $timenow = time(); $weekofseconds = 604800; $course->enddate = $course->startdate + ($weekofseconds * $coursenumsections); $section = $coursenumsections; $weekdate = $course->enddate; // This should be 0:00 Monday of that week. $weekdate -= 7200; // Subtract two hours to avoid possible DST problems. } $numsections = $coursenumsections; // Because we want to manipulate this for column breakpoints. if (($this->userisediting == false)) { $loopsection = 1; $numsections = 0; while ($loopsection <= $coursenumsections) { $nextweekdate = $weekdate - ($weekofseconds); if ((($thissection->uservisible || ($thissection->visible && !$thissection->available && !empty($thissection->availableinfo))) && ($nextweekdate <= $timenow)) == true) { $numsections++; // Section not shown so do not count in columns calculation. } $weekdate = $nextweekdate; $section--; $loopsection++; } // Reset. $section = $coursenumsections; $weekdate = $course->enddate; // This should be 0:00 Monday of that week. $weekdate -= 7200; // Subtract two hours to avoid possible DST problems. } echo $this->end_section_list(); $loopsection = 1; $breaking = false; // Once the first section is shown we can decide if we break on another column. while ($loopsection <= $coursenumsections) { $thissection = $modinfo->get_section_info($section); /* Show the section if the user is permitted to access it, OR if it's not available but there is some available info text which explains the reason & should display. */ if (($this->userisediting)) { $showsection = $thissection->uservisible || ($thissection->visible && !$thissection->available && !empty($thissection->availableinfo)); } else { $showsection = ($thissection->uservisible || ($thissection->visible && !$thissection->available && !empty($thissection->availableinfo))) && ($nextweekdate <= $timenow); } if (($currentsectionfirst == true) && ($showsection == true)) { // Show the section if we were meant to and it is the current section:.... $showsection = ($course->marker == $section); } if (!$showsection) { // Hidden section message is overridden by 'unavailable' control. $testhidden = false; if ($testhidden) { if (!$course->hiddensections && $thissection->available) { $thissection->ishidden = true; $sectiondisplayarray[] = $thissection; } } } else { $thissection->isshown = true; $sectiondisplayarray[] = $thissection; } if (($this->userisediting)) { $section++; } else { $section--; if (($this->userisediting == false)) { $weekdate = $nextweekdate; } } $loopsection++; if (($currentsectionfirst == true) && ($loopsection > $coursenumsections)) { // Now show the rest. $currentsectionfirst = false; $loopsection = 1; $section = 1; } if ($section > $coursenumsections) { // Activities inside this section are 'orphaned', this section will be printed as 'stealth' below. break; } } foreach ($sectiondisplayarray as $thissection) { if (!empty($thissection->ishidden)) { echo $this->section_hidden($thissection); } else if (!empty($thissection->issummary)) { echo $this->section_summary($thissection, $course, null); } else if (!empty($thissection->isshown)) { //echo $this->section_header($thissection, $course, false, 0); if ($thissection->uservisible) { //echo $this->course_section_cm_list($course, $thissection, 0); //echo $this->courserenderer->course_section_add_cm_control($course, $thissection->section, 0); } echo html_writer::end_tag('div'); } unset($sections[$thissection->section]); } } } private function get_css_list_teacher() { $style = ""; } private function print_test_graph($course, $sections, $mods, $modnames, $modnamesused) { echo '
'; echo " "; } private function get_js_dependencies_sigma_graph() { global $CFG; $dirjs = $CFG->wwwroot . '/course/format/competencegraph/js/sigma'; $o = ' '; return $o; } }