renderer.php 37 KB

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