renderer.php 35 KB

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