renderer.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905
  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * Competence Graph
  18. *
  19. * Competence graph format allows the visualization of courses with competencies in a graph.
  20. * In the course structure, teacher associates activities to competencies. Each course module
  21. * can have restrictions between them, so a module is opened only when the student accomplish
  22. * its requirements. In student visualization, the structure of the course is presented as a
  23. * graph. In such graph, each node is a resource available to the student that can be handled.
  24. * Subgraphs in the main graph represent competences. As students can have different paths in
  25. * the course, the plugin registers all the steps that a student produces.
  26. *
  27. * @package course/format
  28. * @subpackage competencegraph
  29. * @version 0.1
  30. * @author Laboratório de Informática na Educação <http://www.usp.br/line>
  31. * @link http://www.usp.br/line/competencegraph
  32. * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
  33. */
  34. defined('MOODLE_INTERNAL') || die();
  35. use core_competency\course_competency;
  36. use core_competency\api;
  37. use core_competency\course_module_competency;
  38. require_once($CFG->dirroot . '/course/format/renderer.php');
  39. require_once($CFG->dirroot . '/course/format/competencegraph/lib.php');
  40. class format_competencegraph_renderer extends format_section_renderer_base {
  41. public function __construct(moodle_page $page, $target) {
  42. parent::__construct($page, $target);
  43. global $PAGE;
  44. //$this->courserenderer = $PAGE->get_renderer('core','course');
  45. $this->courseformat = course_get_format($page->course); // Needed for collapsed topics settings retrieval.
  46. $page->set_other_editing_capability('moodle/course:setcurrentsection');
  47. $this->userisediting = $page->user_is_editing();
  48. $this->rtl = right_to_left();
  49. if (strcmp($page->theme->name, 'boost') === 0) {
  50. $this->bsnewgrid = true;
  51. } else if (!empty($page->theme->parents)) {
  52. if (in_array('boost', $page->theme->parents) === true) {
  53. $this->bsnewgrid = true;
  54. }
  55. }
  56. }
  57. protected function start_section_list() {
  58. if ($this->bsnewgrid) {
  59. return html_writer::start_tag('ul', array('class' => 'ctopics bsnewgrid'));
  60. } else {
  61. return html_writer::start_tag('ul', array('class' => 'ctopics'));
  62. }
  63. }
  64. protected function end_section_list() {
  65. return html_writer::end_tag('ul');
  66. }
  67. protected function page_title() {
  68. return get_string('sectionname', 'format_competencegrah');
  69. }
  70. public function set_portable($portable) {
  71. switch ($portable) {
  72. case 1:
  73. $this->mobiletheme = true;
  74. break;
  75. case 2:
  76. $this->tablettheme = true;
  77. break;
  78. default:
  79. $this->mobiletheme = false;
  80. $this->tablettheme = false;
  81. break;
  82. }
  83. }
  84. public function print_graph_teacher_view($course, $sections, $mods, $modnames, $modnamesused) {
  85. $context = context_course::instance($course->id);
  86. if (has_capability('moodle/course:update', $context)) {
  87. $maintabs = array(
  88. new tabobject( 'tab_list', '?id='.$course->id.'&format=list', get_string('listview', 'format_competencegraph'), get_string('listview', 'format_competencegraph') ),
  89. new tabobject( 'tab_graph', '?id='.$course->id.'&format=graph', get_string('graphview', 'format_competencegraph'), get_string('graphview', 'format_competencegraph') )
  90. );
  91. $active = 'tab_graph';
  92. print_tabs( array($maintabs), $active );
  93. //echo $this->get_js_dependencies_sigma_graph();
  94. //$this->print_test_graph($course, $sections, $mods, $modnames, $modnamesused);
  95. echo '<script src="https://d3js.org/d3.v4.min.js"></script>';
  96. $this->print_nodes_graph($course, $sections, $mods, $modnames, $modnamesused);
  97. } else {
  98. echo '<script src="https://d3js.org/d3.v4.min.js"></script>';
  99. $this->print_nodes_graph($course, $sections, $mods, $modnames, $modnamesused);
  100. }
  101. }
  102. public function print_nodes_graph($course, $sections, $mods, $modnames, $modnamesused) {
  103. echo "<script>";
  104. echo 'var svgContainer = d3.select(".course-content").append("svg")
  105. .attr("width", 800)
  106. .attr("height", 1000);';
  107. echo 'svgContainer.append("svg:defs").append("svg:marker")
  108. .attr("id", "triangle")
  109. .attr("refX", 36)
  110. .attr("refY", 6)
  111. .attr("markerWidth", 30)
  112. .attr("markerHeight", 30)
  113. .attr("markerUnits","userSpaceOnUse")
  114. .attr("orient", "auto")
  115. .append("path")
  116. .attr("d", "M 0 0 12 6 0 12 3 6")
  117. .style("fill", "#9e9e9f");';
  118. echo 'var jsonCircles = [';
  119. $context = context_course::instance($course->id);
  120. $colors = ['#617db4', '#668f3c', '#c6583e', '#b956af', '#fcba03', '#03fcf0', '#fc0339', '#a6ffc8', '#000000'];
  121. // Print the competencies as name section:
  122. $list_competencies = course_competency::list_course_competencies($course->id);
  123. $all_mod_info_printed = array();
  124. $modinfo = get_fast_modinfo($course);
  125. $count = 0;
  126. $atual_competence = 0;
  127. $vet_id = 0;
  128. $distancia_quadrantes = 100;
  129. $tamanho_quadrante = 250;
  130. $quadrante_da_vez = 1;
  131. $para_y = 0;
  132. $para_x = 0;
  133. $arestas = [];
  134. foreach ($list_competencies as $competence) {
  135. $idcompetence = $competence->get('competencyid');
  136. api::read_competency($idcompetence)->get('shortname');
  137. $list_modules = course_module_competency::list_course_modules($idcompetence, $course->id);
  138. foreach ($list_modules as $item) {
  139. array_push($all_mod_info_printed, $item);
  140. }
  141. if ($quadrante_da_vez % 2 != 0) {
  142. $para_y = $quadrante_da_vez / 2 * ($distancia_quadrantes + $tamanho_quadrante) - 100;
  143. $para_x = 0;
  144. } else {
  145. $para_y -= 00;
  146. $para_x = $distancia_quadrantes + $tamanho_quadrante;
  147. }
  148. $para_x = intval($para_x);
  149. $para_y = intval($para_y);
  150. $linha = 1;
  151. $contPorLinha = 1;
  152. $contItens = 1;
  153. $andou = 0;
  154. foreach ($list_modules as $modnumber) {
  155. $andou ++;
  156. $mod = $modinfo->cms[$modnumber];
  157. $teste = new moodle_url($mod->url);
  158. if ($contPorLinha == 4) {
  159. $contPorLinha = 1;
  160. $linha ++;
  161. }
  162. $xx = -500;
  163. $yy = -500;
  164. switch ($contItens) {
  165. case 1:
  166. $xx = 100;
  167. $yy = 100;
  168. break;
  169. case 2:
  170. $xx = 180;
  171. $yy = 10;
  172. break;
  173. case 3:
  174. $xx = 305;
  175. $yy = 45;
  176. break;
  177. case 4:
  178. $xx = 280;
  179. $yy = 150;
  180. break;
  181. case 5:
  182. $xx = 175;
  183. $yy = 170;
  184. break;
  185. case 6:
  186. $xx = 80;
  187. $yy = 250;
  188. break;
  189. case 7:
  190. $xx = 240;
  191. $yy = 260;
  192. break;
  193. }
  194. echo '
  195. { "vet_id": '.$vet_id.', "cm_id": '.$mod->id.', "x_axis": ' . ($para_x + ($xx)) . ', "y_axis": ' . ($para_y + ($yy)) .', "radius": 25, "color" : "'.$colors[$count].'", "name": "'.$mod->name.'", "icon": "'.$mod->get_icon_url().'", "url": "'.$mod->url.'" },';
  196. if ($mod->availability) {
  197. $temp = json_decode($mod->availability);
  198. for ($k = 0; $k < count($temp->c); $k++) {
  199. array_push($arestas, [$temp->c[$k]->cm, $mod->id]);
  200. }
  201. }
  202. $contPorLinha ++;
  203. $contItens ++;
  204. $vet_id ++;
  205. }
  206. if ($andou != 0) {
  207. $count ++;
  208. $quadrante_da_vez ++;
  209. }
  210. }
  211. $list_mod_without_competences = array();
  212. foreach ($modinfo->cms as $tempmod) {
  213. if (!in_array($tempmod->id, $all_mod_info_printed)) {
  214. array_push($list_mod_without_competences, $tempmod->id);
  215. }
  216. }
  217. echo '];';
  218. echo "var tempCircles = jsonCircles;";
  219. for ($i = 0; $i < count($arestas); $i++) {
  220. /*print '
  221. ' . $arestas[$i][0];*/
  222. // $arestas[$i][0] -> dependência
  223. // $arestas[$i][1] -> recurso que depende do [0]
  224. echo "var dependencia = " . $arestas[$i][1] . ";";
  225. echo "var depende = " . $arestas[$i][0] . ";";
  226. echo "var x1 = 0; var x2 = 0; var y1 = 0; var y2 = 0;";
  227. echo '
  228. for (i = 0; i < tempCircles.length; i++) {
  229. if (tempCircles[i].cm_id == depende) {
  230. x1 = tempCircles[i].x_axis;
  231. y1 = tempCircles[i].y_axis;
  232. break;
  233. }
  234. }
  235. for (i = 0; i < tempCircles.length; i++) {
  236. if (tempCircles[i].cm_id == dependencia) {
  237. x2 = tempCircles[i].x_axis;
  238. y2 = tempCircles[i].y_axis;
  239. break;
  240. }
  241. }
  242. ';
  243. echo 'svgContainer.append("line")
  244. .attr("x1", x1)
  245. .attr("y1", y1)
  246. .attr("x2", x2)
  247. .attr("y2", y2)
  248. .attr("stroke-width", 2)
  249. .attr("stroke", "#9e9e9e")
  250. .attr("marker-end", "url(#triangle)");';
  251. }
  252. echo 'var circles = svgContainer.selectAll("circle")
  253. .data(jsonCircles)
  254. .enter()
  255. .append("circle");';
  256. echo 'var circleAttributes = circles
  257. .attr("cx", function (d) { return d.x_axis; })
  258. .attr("cy", function (d) { return d.y_axis; })
  259. .attr("r", function (d) { return d.radius; })
  260. .style("fill", function(d) { return d.color; })
  261. .on("click", function(d) {
  262. openId(d.vet_id);
  263. console.log(d.url);
  264. });';
  265. echo "for (var i = 0; i < tempCircles.length; i++) {
  266. var svgimg = document.createElementNS('http://www.w3.org/2000/svg','image');
  267. svgimg.setAttributeNS(null,'height','25');
  268. svgimg.setAttributeNS(null,'width','35');
  269. svgimg.setAttributeNS('http://www.w3.org/1999/xlink','href', tempCircles[i].icon);
  270. svgimg.setAttributeNS(null,'x', tempCircles[i].x_axis - 18);
  271. svgimg.setAttributeNS(null,'y', tempCircles[i].y_axis - 12);
  272. svgimg.setAttributeNS(null, 'visibility', 'visible');
  273. svgimg.setAttributeNS(null, 'id', tempCircles[i].vet_id);
  274. svgimg.onclick = function (e) {
  275. openId(e.originalTarget.id);
  276. };
  277. document.getElementsByTagName('svg')[0].append(svgimg);
  278. }";
  279. echo "
  280. function openId(vet_id) {
  281. $('#janela').remove();
  282. $('#sup_janela').append($(\"<iframe src='\" + tempCircles[vet_id].url + \"' id='janela'>\" ));
  283. modal.style.display = 'block';
  284. }";
  285. print '';
  286. print "</script>";
  287. print '<button id="modal-btn"> click me, I make a modal</button><div class="modal">
  288. <div class="modal-content">
  289. <div class="close-btn">&times;</div>
  290. <div id="sup_janela"><iframe src="" id="janela"></iframe></div>
  291. </div>
  292. </div>';
  293. print '<style>
  294. svg circle, svg image {
  295. cursor: pointer;
  296. }
  297. .modal {
  298. display: none;
  299. position: fixed;
  300. padding-top: 50px;
  301. left: 0;
  302. top: 0;
  303. width: 100%;
  304. height: 100%;
  305. background-color: rgb(0, 0, 0);
  306. background-color: rgba(0, 0, 0, 0.5);
  307. }
  308. #modal-btn {
  309. display: none;
  310. }
  311. #janela {
  312. height: 100%;
  313. border: none;
  314. width: 100%;
  315. }
  316. #sup_janela {
  317. height: 100%;
  318. width: 100% !important;
  319. }
  320. .modal-content {
  321. position: relative;
  322. background-color: white;
  323. padding: 20px;
  324. margin: auto;
  325. width: 85%;
  326. height: 90%;
  327. -webkit-animation-name: animatetop;
  328. -webkit-animation-duration: 0.4s;
  329. animation-name: animatetop;
  330. animation-duration: 0.4s
  331. }.close-btn {
  332. float: right;
  333. color: lightgray;
  334. font-weight: bold;
  335. text-align: right;
  336. font-size: 2em;
  337. margin-top: -20px;
  338. margin-right: -5px;
  339. cursor: pointer;
  340. }.close-btn:hover {
  341. color: darkgray;
  342. }@-webkit-keyframes animatetop {
  343. from {top:-300px; opacity:0}
  344. to {top:0; opacity:1}
  345. }@keyframes animatetop {
  346. from {top:-300px; opacity:0}
  347. to {top:0; opacity:1}
  348. }</style>';
  349. print '<script>
  350. var modalBtn = document.getElementById("modal-btn") ;
  351. var modal = document.querySelector(".modal");
  352. var closeBtn = document.querySelector(".close-btn");
  353. modalBtn.onclick = function(){
  354. }
  355. closeBtn.onclick = function(){
  356. modal.style.display = "none";
  357. }
  358. window.onclick = function(e){
  359. if(e.target == modal){
  360. modal.style.display = "none";
  361. }
  362. }</script>';
  363. }
  364. public function print_multiple_section_page($course, $sections, $mods, $modnames, $modnamesused) {
  365. $context = context_course::instance($course->id);
  366. global $OUTPUT;
  367. if (has_capability('moodle/course:update', $context)) {
  368. echo $this->get_css_list_teacher();
  369. //$this->print_modules_page_teacher_list($course, $sections, $mods, $modnames, $modnamesused);
  370. $modinfo = get_fast_modinfo($course);
  371. $course = $this->courseformat->get_course();
  372. $context = context_course::instance($course->id);
  373. $sections = $modinfo->get_section_info_all();
  374. // General section if non-empty.
  375. $thissection = $sections[0];
  376. if ($thissection->summary or ! empty($modinfo->sections[0]) or $this->userisediting) {
  377. print('<div class="tohidden firstitem">');
  378. echo $this->section_header($thissection, $course, false, 0);
  379. print('</div>');
  380. echo $this->courserenderer->course_section_add_cm_control($course, $thissection->section, 0);
  381. }
  382. $maintabs = array(
  383. new tabobject( 'tab_list', '?id='.$course->id.'&format=list', get_string('listview', 'format_competencegraph'), get_string('listview', 'format_competencegraph') ),
  384. new tabobject( 'tab_graph', '?id='.$course->id.'&format=graph', get_string('graphview', 'format_competencegraph'), get_string('graphview', 'format_competencegraph') )
  385. );
  386. $active = 'tab_list';
  387. print_tabs( array($maintabs), $active );
  388. // Print the competencies as name section:
  389. $list_competencies = course_competency::list_course_competencies($course->id);
  390. if (count($list_competencies) < 1) {
  391. echo '<div class="coursewithoutcompetence"> <i class="fa fa-exclamation-triangle" aria-hidden="true"></i>' . get_string('coursewithoutcompetence', 'format_competencegraph') . '</div>';
  392. }
  393. $all_mod_info_printed = array();
  394. foreach ($list_competencies as $competence) {
  395. $idcompetence = $competence->get('competencyid');
  396. echo '<h4 class="sectionname"><span><a href="#">' . api::read_competency($idcompetence)->get('shortname') . '</a></span></h4>';
  397. $list_modules = course_module_competency::list_course_modules($idcompetence, $course->id);
  398. if (!$list_modules || count($list_modules) < 1) {
  399. echo '<div class="emptycompetence"><i class="fa fa-info-circle" aria-hidden="true"></i>' . get_string('emptycompetence', 'format_competencegraph') . "</div>";
  400. }
  401. echo $this->course_section_cm_list($course, null, 0, array(), $list_modules);
  402. foreach ($list_modules as $item) {
  403. array_push($all_mod_info_printed, $item);
  404. }
  405. }
  406. $list_mod_without_competences = array();
  407. foreach ($modinfo->cms as $tempmod) {
  408. if (!in_array($tempmod->id, $all_mod_info_printed)) {
  409. array_push($list_mod_without_competences, $tempmod->id);
  410. }
  411. }
  412. if (count($list_mod_without_competences) > 0) {
  413. echo '<h4 class="withoutcompetence"><span><a href="#">' . get_string('itemswithoutcompetence', 'format_competencegraph') . '</a></span></h4>';
  414. echo $this->course_section_cm_list($course, null, 0, array(), $list_mod_without_competences);
  415. }
  416. $sections = $modinfo->get_section_info_all();
  417. // General section if non-empty.
  418. $thissection = $sections[0];
  419. if ($thissection->summary or ! empty($modinfo->sections[0]) or $this->userisediting) {
  420. print('<div class="tohidden">');
  421. echo $this->section_header($thissection, $course, false, 0);
  422. print('</div>');
  423. echo $this->courserenderer->course_section_add_cm_control($course, $thissection->section, 0);
  424. }
  425. }
  426. }
  427. public function course_section_cm_list($course, $section, $sectionreturn = null, $displayoptions = array(), $includeditems = array()) {
  428. global $USER;
  429. $output = '';
  430. $modinfo = get_fast_modinfo($course);
  431. $completioninfo = new completion_info($course);
  432. // check if we are currently in the process of moving a module with JavaScript disabled
  433. $ismoving = $this->page->user_is_editing() && ismoving($course->id);
  434. if ($ismoving) {
  435. $movingpix = new pix_icon('movehere', get_string('movehere'), 'moodle', array('class' => 'movetarget'));
  436. $strmovefull = strip_tags(get_string("movefull", "", "'$USER->activitycopyname'"));
  437. }
  438. // Get the list of modules visible to user (excluding the module being moved if there is one)
  439. $moduleshtml = array();
  440. foreach ($includeditems as $modnumber) {
  441. $mod = $modinfo->cms[$modnumber];
  442. /*if ($mod->availability) {
  443. echo $modnumber . ':: ';
  444. print_r($mod->availability);
  445. }*/
  446. if ($ismoving and $mod->id == $USER->activitycopy) {
  447. // do not display moving mod
  448. continue;
  449. }
  450. if ($modulehtml = $this->courserenderer->course_section_cm_list_item($course,
  451. $completioninfo, $mod, $sectionreturn, $displayoptions)) {
  452. $moduleshtml[$modnumber] = $modulehtml;
  453. }
  454. }
  455. $sectionoutput = '';
  456. if (!empty($moduleshtml) || $ismoving) {
  457. foreach ($moduleshtml as $modnumber => $modulehtml) {
  458. if ($ismoving) {
  459. $movingurl = new moodle_url('/course/mod.php', array('moveto' => $modnumber, 'sesskey' => sesskey()));
  460. $sectionoutput .= html_writer::tag('li',
  461. html_writer::link($movingurl, $this->output->render($movingpix), array('title' => $strmovefull)),
  462. array('class' => 'movehere'));
  463. }
  464. $sectionoutput .= $modulehtml;
  465. }
  466. if ($ismoving) {
  467. $movingurl = new moodle_url('/course/mod.php', array('movetosection' => $section->id, 'sesskey' => sesskey()));
  468. $sectionoutput .= html_writer::tag('li',
  469. html_writer::link($movingurl, $this->output->render($movingpix), array('title' => $strmovefull)),
  470. array('class' => 'movehere'));
  471. }
  472. }
  473. // Always output the section module list.
  474. $output .= html_writer::tag('ul', $sectionoutput, array('class' => 'section img-text'));
  475. return $output;
  476. }
  477. public function print_modules_page_teacher_list($course, $sections, $mods, $modnames, $modnamesused) {
  478. $modinfo = get_fast_modinfo($course);
  479. $course = $this->courseformat->get_course();
  480. $context = context_course::instance($course->id);
  481. //echo $this->start_section_list();
  482. $sections = $modinfo->get_section_info_all();
  483. // General section if non-empty.
  484. $thissection = $sections[0];
  485. if ($thissection->summary or ! empty($modinfo->sections[0]) or $this->userisediting) {
  486. echo $this->section_header($thissection, $course, false, 0);
  487. //echo $this->course_section_cm_list($course, $thissection, 0);
  488. echo $this->courserenderer->course_section_add_cm_control($course, $thissection->section, 0);
  489. }
  490. $coursenumsections = $this->courseformat->get_last_section_number();
  491. if ($coursenumsections > 0) {
  492. $sectiondisplayarray = array();
  493. $currentsectionfirst = false;
  494. if ((!$this->userisediting)) {
  495. $currentsectionfirst = true;
  496. }
  497. if (($this->userisediting)) {
  498. $section = 1;
  499. } else {
  500. $timenow = time();
  501. $weekofseconds = 604800;
  502. $course->enddate = $course->startdate + ($weekofseconds * $coursenumsections);
  503. $section = $coursenumsections;
  504. $weekdate = $course->enddate; // This should be 0:00 Monday of that week.
  505. $weekdate -= 7200; // Subtract two hours to avoid possible DST problems.
  506. }
  507. $numsections = $coursenumsections; // Because we want to manipulate this for column breakpoints.
  508. if (($this->userisediting == false)) {
  509. $loopsection = 1;
  510. $numsections = 0;
  511. while ($loopsection <= $coursenumsections) {
  512. $nextweekdate = $weekdate - ($weekofseconds);
  513. if ((($thissection->uservisible ||
  514. ($thissection->visible && !$thissection->available && !empty($thissection->availableinfo))) &&
  515. ($nextweekdate <= $timenow)) == true) {
  516. $numsections++; // Section not shown so do not count in columns calculation.
  517. }
  518. $weekdate = $nextweekdate;
  519. $section--;
  520. $loopsection++;
  521. }
  522. // Reset.
  523. $section = $coursenumsections;
  524. $weekdate = $course->enddate; // This should be 0:00 Monday of that week.
  525. $weekdate -= 7200; // Subtract two hours to avoid possible DST problems.
  526. }
  527. echo $this->end_section_list();
  528. $loopsection = 1;
  529. $breaking = false; // Once the first section is shown we can decide if we break on another column.
  530. while ($loopsection <= $coursenumsections) {
  531. $thissection = $modinfo->get_section_info($section);
  532. /* Show the section if the user is permitted to access it, OR if it's not available
  533. but there is some available info text which explains the reason & should display. */
  534. if (($this->userisediting)) {
  535. $showsection = $thissection->uservisible ||
  536. ($thissection->visible && !$thissection->available && !empty($thissection->availableinfo));
  537. } else {
  538. $showsection = ($thissection->uservisible ||
  539. ($thissection->visible && !$thissection->available && !empty($thissection->availableinfo))) &&
  540. ($nextweekdate <= $timenow);
  541. }
  542. if (($currentsectionfirst == true) && ($showsection == true)) {
  543. // Show the section if we were meant to and it is the current section:....
  544. $showsection = ($course->marker == $section);
  545. }
  546. if (!$showsection) {
  547. // Hidden section message is overridden by 'unavailable' control.
  548. $testhidden = false;
  549. if ($testhidden) {
  550. if (!$course->hiddensections && $thissection->available) {
  551. $thissection->ishidden = true;
  552. $sectiondisplayarray[] = $thissection;
  553. }
  554. }
  555. } else {
  556. $thissection->isshown = true;
  557. $sectiondisplayarray[] = $thissection;
  558. }
  559. if (($this->userisediting)) {
  560. $section++;
  561. } else {
  562. $section--;
  563. if (($this->userisediting == false)) {
  564. $weekdate = $nextweekdate;
  565. }
  566. }
  567. $loopsection++;
  568. if (($currentsectionfirst == true) && ($loopsection > $coursenumsections)) {
  569. // Now show the rest.
  570. $currentsectionfirst = false;
  571. $loopsection = 1;
  572. $section = 1;
  573. }
  574. if ($section > $coursenumsections) {
  575. // Activities inside this section are 'orphaned', this section will be printed as 'stealth' below.
  576. break;
  577. }
  578. }
  579. foreach ($sectiondisplayarray as $thissection) {
  580. if (!empty($thissection->ishidden)) {
  581. echo $this->section_hidden($thissection);
  582. } else if (!empty($thissection->issummary)) {
  583. echo $this->section_summary($thissection, $course, null);
  584. } else if (!empty($thissection->isshown)) {
  585. //echo $this->section_header($thissection, $course, false, 0);
  586. if ($thissection->uservisible) {
  587. //echo $this->course_section_cm_list($course, $thissection, 0);
  588. //echo $this->courserenderer->course_section_add_cm_control($course, $thissection->section, 0);
  589. }
  590. echo html_writer::end_tag('div');
  591. }
  592. unset($sections[$thissection->section]);
  593. }
  594. }
  595. }
  596. private function get_css_list_teacher() {
  597. $style = "<style>";
  598. $style .= ".sectionname, .withoutcompetence {
  599. border-top: 1px solid #cfdacf;
  600. margin-top: 1em;
  601. padding-top: .3em;
  602. }
  603. .emptycompetence {
  604. margin-left: 1.5em;
  605. opacity: .8;
  606. }
  607. .emptycompetence i {
  608. margin-right: .5em;
  609. }
  610. .tohidden .right.side {
  611. display: none;
  612. }
  613. .tohidden li {
  614. list-style-type: none;
  615. }
  616. .coursewithoutcompetence {
  617. border: 1px solid gray;
  618. padding: 1em;
  619. border-radius: .5em;
  620. margin: 1em;
  621. color: #c63100;
  622. }
  623. .coursewithoutcompetence i {
  624. opacity: .8;
  625. margin-right: .5em;
  626. }
  627. .firstitem .section-modchooser-link {
  628. float: right;
  629. }";
  630. return $style . "</style>";
  631. }
  632. private function print_test_graph($course, $sections, $mods, $modnames, $modnamesused) {
  633. echo '<div id="container">
  634. <style>
  635. #graph-container {
  636. top: 4em;
  637. bottom: 0;
  638. left: 0;
  639. right: 0;
  640. border: 1px solid red;
  641. }
  642. </style>
  643. <div id="graph-container"></div>
  644. </div>';
  645. echo "<script>
  646. var i,
  647. s,
  648. img,
  649. N = 10,
  650. E = 50,
  651. g = {
  652. nodes: [],
  653. edges: []
  654. },
  655. colors = [
  656. '#617db4',
  657. '#668f3c',
  658. '#c6583e',
  659. '#b956af'
  660. ];";
  661. $this->print_nodes_graph($course, $sections, $mods, $modnames, $modnamesused);
  662. echo "
  663. /*for (i = 0; i < E; i++) {
  664. g.edges.push({
  665. id: 'e' + i,
  666. source: 'n' + (Math.random() * N | 0),
  667. target: 'n' + (Math.random() * N | 0),
  668. type: ['arrow'][0],
  669. size: 1,
  670. color: '#bdbdbd'
  671. });
  672. }*/
  673. s = new sigma({
  674. graph: g,
  675. renderer: {
  676. container: document.getElementById('graph-container'),
  677. type: 'svg'
  678. },
  679. settings: {
  680. minNodeSize: 1,
  681. maxNodeSize: 10,
  682. minEdgeSize: 0.1,
  683. maxEdgeSize: 2,
  684. enableEdgeHovering: true,
  685. edgeHoverSizeRatio: 2,
  686. sideMargin: 0,
  687. enableCamera: false
  688. }
  689. });
  690. </script>
  691. ";
  692. }
  693. private function get_js_dependencies_sigma_graph() {
  694. global $CFG;
  695. $dirjs = $CFG->wwwroot . '/course/format/competencegraph/js/sigma';
  696. $o = '<script src="'.$dirjs.'/src/sigma.core.js"></script>
  697. <script src="'.$dirjs.'/src/conrad.js"></script>
  698. <script src="'.$dirjs.'/src/utils/sigma.utils.js"></script>
  699. <script src="'.$dirjs.'/src/utils/sigma.polyfills.js"></script>
  700. <script src="'.$dirjs.'/src/sigma.settings.js"></script>
  701. <script src="'.$dirjs.'/src/classes/sigma.classes.dispatcher.js"></script>
  702. <script src="'.$dirjs.'/src/classes/sigma.classes.configurable.js"></script>
  703. <script src="'.$dirjs.'/src/classes/sigma.classes.graph.js"></script>
  704. <script src="'.$dirjs.'/src/classes/sigma.classes.camera.js"></script>
  705. <script src="'.$dirjs.'/src/classes/sigma.classes.quad.js"></script>
  706. <script src="'.$dirjs.'/src/classes/sigma.classes.edgequad.js"></script>
  707. <script src="'.$dirjs.'/src/captors/sigma.captors.mouse.js"></script>
  708. <script src="'.$dirjs.'/src/captors/sigma.captors.touch.js"></script>
  709. <script src="'.$dirjs.'/src/renderers/sigma.renderers.canvas.js"></script>
  710. <script src="'.$dirjs.'/src/renderers/sigma.renderers.webgl.js"></script>
  711. <script src="'.$dirjs.'/src/renderers/sigma.renderers.svg.js"></script>
  712. <script src="'.$dirjs.'/src/renderers/sigma.renderers.def.js"></script>
  713. <script src="'.$dirjs.'/src/renderers/webgl/sigma.webgl.nodes.def.js"></script>
  714. <script src="'.$dirjs.'/src/renderers/webgl/sigma.webgl.nodes.fast.js"></script>
  715. <script src="'.$dirjs.'/src/renderers/webgl/sigma.webgl.edges.def.js"></script>
  716. <script src="'.$dirjs.'/src/renderers/webgl/sigma.webgl.edges.fast.js"></script>
  717. <script src="'.$dirjs.'/src/renderers/webgl/sigma.webgl.edges.arrow.js"></script>
  718. <script src="'.$dirjs.'/src/renderers/canvas/sigma.canvas.labels.def.js"></script>
  719. <script src="'.$dirjs.'/src/renderers/canvas/sigma.canvas.hovers.def.js"></script>
  720. <script src="'.$dirjs.'/src/renderers/canvas/sigma.canvas.nodes.def.js"></script>
  721. <script src="'.$dirjs.'/src/renderers/canvas/sigma.canvas.edges.def.js"></script>
  722. <script src="'.$dirjs.'/src/renderers/canvas/sigma.canvas.edges.curve.js"></script>
  723. <script src="'.$dirjs.'/src/renderers/canvas/sigma.canvas.edges.arrow.js"></script>
  724. <script src="'.$dirjs.'/src/renderers/canvas/sigma.canvas.edges.curvedArrow.js"></script>
  725. <script src="'.$dirjs.'/src/renderers/canvas/sigma.canvas.edgehovers.def.js"></script>
  726. <script src="'.$dirjs.'/src/renderers/canvas/sigma.canvas.edgehovers.curve.js"></script>
  727. <script src="'.$dirjs.'/src/renderers/canvas/sigma.canvas.edgehovers.arrow.js"></script>
  728. <script src="'.$dirjs.'/src/renderers/canvas/sigma.canvas.edgehovers.curvedArrow.js"></script>
  729. <script src="'.$dirjs.'/src/renderers/canvas/sigma.canvas.extremities.def.js"></script>
  730. <script src="'.$dirjs.'/src/renderers/svg/sigma.svg.utils.js"></script>
  731. <script src="'.$dirjs.'/src/renderers/svg/sigma.svg.nodes.def.js"></script>
  732. <script src="'.$dirjs.'/src/renderers/svg/sigma.svg.edges.def.js"></script>
  733. <script src="'.$dirjs.'/src/renderers/svg/sigma.svg.edges.curve.js"></script>
  734. <script src="'.$dirjs.'/src/renderers/svg/sigma.svg.labels.def.js"></script>
  735. <script src="'.$dirjs.'/src/renderers/svg/sigma.svg.hovers.def.js"></script>
  736. <script src="'.$dirjs.'/src/middlewares/sigma.middlewares.rescale.js"></script>
  737. <script src="'.$dirjs.'/src/middlewares/sigma.middlewares.copy.js"></script>
  738. <script src="'.$dirjs.'/src/misc/sigma.misc.animation.js"></script>
  739. <script src="'.$dirjs.'/src/misc/sigma.misc.bindEvents.js"></script>
  740. <script src="'.$dirjs.'/src/misc/sigma.misc.bindDOMEvents.js"></script>
  741. <script src="'.$dirjs.'/src/misc/sigma.misc.drawHovers.js"></script>
  742. <!-- END SIGMA IMPORTS -->
  743. <script src="'.$dirjs.'/sigma.renderers.customEdgeShapes/sigma.canvas.edges.dashed.js"></script>
  744. <script src="'.$dirjs.'/sigma.renderers.customEdgeShapes/sigma.canvas.edges.dotted.js"></script>
  745. <script src="'.$dirjs.'/sigma.renderers.customEdgeShapes/sigma.canvas.edges.parallel.js"></script>
  746. <script src="'.$dirjs.'/sigma.renderers.customEdgeShapes/sigma.canvas.edges.tapered.js"></script>
  747. <script src="'.$dirjs.'/sigma.renderers.customEdgeShapes/sigma.canvas.edgehovers.dashed.js"></script>
  748. <script src="'.$dirjs.'/sigma.renderers.customEdgeShapes/sigma.canvas.edgehovers.dotted.js"></script>
  749. <script src="'.$dirjs.'/sigma.renderers.customEdgeShapes/sigma.canvas.edgehovers.parallel.js"></script>
  750. <script src="'.$dirjs.'/sigma.renderers.customEdgeShapes/sigma.canvas.edgehovers.tapered.js"></script>';
  751. return $o;
  752. }
  753. }