PageRenderTime 44ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/course/format/weeks/format.php

https://github.com/plymouthstate/moodle
PHP | 288 lines | 200 code | 54 blank | 34 comment | 43 complexity | d160b99a35e631369c6a772460b914b5 MD5 | raw file
  1. <?php
  2. // Display the whole course as "weeks" made of of modules
  3. // Included from "view.php"
  4. /**
  5. * Evaluation weekly format for course display - NO layout tables, for accessibility, etc.
  6. *
  7. * A duplicate course format to enable the Moodle development team to evaluate
  8. * CSS for the multi-column layout in place of layout tables.
  9. * Less risk for the Moodle 1.6 beta release.
  10. * 1. Straight copy of weeks/format.php
  11. * 2. Replace <table> and <td> with DIVs; inline styles.
  12. * 3. Reorder columns so that in linear view content is first then blocks;
  13. * styles to maintain original graphical (side by side) view.
  14. *
  15. * Target: 3-column graphical view using relative widths for pixel screen sizes
  16. * 800x600, 1024x768... on IE6, Firefox. Below 800 columns will shift downwards.
  17. *
  18. * http://www.maxdesign.com.au/presentation/em/ Ideal length for content.
  19. * http://www.svendtofte.com/code/max_width_in_ie/ Max width in IE.
  20. *
  21. * @copyright &copy; 2006 The Open University
  22. * @author N.D.Freear@open.ac.uk, and others.
  23. * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
  24. * @package
  25. */
  26. defined('MOODLE_INTERNAL') || die();
  27. require_once($CFG->libdir.'/filelib.php');
  28. require_once($CFG->libdir.'/completionlib.php');
  29. $week = optional_param('week', -1, PARAM_INT);
  30. if ($week != -1) {
  31. $displaysection = course_set_display($course->id, $week);
  32. } else {
  33. $displaysection = course_get_display($course->id);
  34. }
  35. $streditsummary = get_string('editsummary');
  36. $stradd = get_string('add');
  37. $stractivities = get_string('activities');
  38. $strshowallweeks = get_string('showallweeks');
  39. $strweek = get_string('week');
  40. $strgroups = get_string('groups');
  41. $strgroupmy = get_string('groupmy');
  42. $editing = $PAGE->user_is_editing();
  43. if ($editing) {
  44. $strweekhide = get_string('hideweekfromothers');
  45. $strweekshow = get_string('showweekfromothers');
  46. $strmoveup = get_string('moveup');
  47. $strmovedown = get_string('movedown');
  48. }
  49. $context = get_context_instance(CONTEXT_COURSE, $course->id);
  50. //Print the Your progress icon if the track completion is enabled
  51. $completioninfo = new completion_info($course);
  52. echo $completioninfo->display_help_icon();
  53. echo $OUTPUT->heading(get_string('weeklyoutline'), 2, 'headingblock header outline');
  54. // Note, an ordered list would confuse - "1" could be the clipboard or summary.
  55. echo "<ul class='weeks'>\n";
  56. /// If currently moving a file then show the current clipboard
  57. if (ismoving($course->id)) {
  58. $stractivityclipboard = strip_tags(get_string('activityclipboard', '', $USER->activitycopyname));
  59. $strcancel= get_string('cancel');
  60. echo '<li class="clipboard">';
  61. echo $stractivityclipboard.'&nbsp;&nbsp;(<a href="mod.php?cancelcopy=true&amp;sesskey='.sesskey().'">'.$strcancel.'</a>)';
  62. echo "</li>\n";
  63. }
  64. /// Print Section 0 with general activities
  65. $section = 0;
  66. $thissection = $sections[$section];
  67. unset($sections[0]);
  68. if ($thissection->summary or $thissection->sequence or $PAGE->user_is_editing()) {
  69. // Note, 'right side' is BEFORE content.
  70. echo '<li id="section-0" class="section main clearfix" >';
  71. echo '<div class="left side">&nbsp;</div>';
  72. echo '<div class="right side" >&nbsp;</div>';
  73. echo '<div class="content">';
  74. if (!empty($thissection->name)) {
  75. echo $OUTPUT->heading(format_string($thissection->name, true, array('context' => $context)), 3, 'sectionname');
  76. }
  77. echo '<div class="summary">';
  78. $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
  79. $summarytext = file_rewrite_pluginfile_urls($thissection->summary, 'pluginfile.php', $coursecontext->id, 'course', 'section', $thissection->id);
  80. $summaryformatoptions = new stdClass;
  81. $summaryformatoptions->noclean = true;
  82. $summaryformatoptions->overflowdiv = true;
  83. echo format_text($summarytext, $thissection->summaryformat, $summaryformatoptions);
  84. if ($PAGE->user_is_editing() && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
  85. echo '<p><a title="'.$streditsummary.'" '.
  86. ' href="editsection.php?id='.$thissection->id.'"><img src="'.$OUTPUT->pix_url('t/edit') . '" '.
  87. ' class="iconsmall edit" alt="'.$streditsummary.'" /></a></p>';
  88. }
  89. echo '</div>';
  90. print_section($course, $thissection, $mods, $modnamesused);
  91. if ($PAGE->user_is_editing()) {
  92. print_section_add_menus($course, $section, $modnames);
  93. }
  94. echo '</div>';
  95. echo "</li>\n";
  96. }
  97. /// Now all the normal modules by week
  98. /// Everything below uses "section" terminology - each "section" is a week.
  99. $timenow = time();
  100. $weekdate = $course->startdate; // this should be 0:00 Monday of that week
  101. $weekdate += 7200; // Add two hours to avoid possible DST problems
  102. $section = 1;
  103. $sectionmenu = array();
  104. $weekofseconds = 604800;
  105. $course->enddate = $course->startdate + ($weekofseconds * $course->numsections);
  106. $strftimedateshort = ' '.get_string('strftimedateshort');
  107. while ($weekdate < $course->enddate) {
  108. $nextweekdate = $weekdate + ($weekofseconds);
  109. $weekday = userdate($weekdate, $strftimedateshort);
  110. $endweekday = userdate($weekdate+518400, $strftimedateshort);
  111. if (!empty($sections[$section])) {
  112. $thissection = $sections[$section];
  113. } else {
  114. unset($thissection);
  115. $thissection->course = $course->id; // Create a new week structure
  116. $thissection->section = $section;
  117. $thissection->name = null;
  118. $thissection->summary = '';
  119. $thissection->summaryformat = FORMAT_HTML;
  120. $thissection->visible = 1;
  121. $thissection->id = $DB->insert_record('course_sections', $thissection);
  122. }
  123. $showsection = (has_capability('moodle/course:viewhiddensections', $context) or $thissection->visible or !$course->hiddensections);
  124. if (!empty($displaysection) and $displaysection != $section) { // Check this week is visible
  125. if ($showsection) {
  126. $sectionmenu[$section] = get_section_name($course, $thissection);
  127. }
  128. $section++;
  129. $weekdate = $nextweekdate;
  130. continue;
  131. }
  132. if ($showsection) {
  133. $currentweek = (($weekdate <= $timenow) && ($timenow < $nextweekdate));
  134. $currenttext = '';
  135. if (!$thissection->visible) {
  136. $sectionstyle = ' hidden';
  137. } else if ($currentweek) {
  138. $sectionstyle = ' current';
  139. $currenttext = get_accesshide(get_string('currentweek','access'));
  140. } else {
  141. $sectionstyle = '';
  142. }
  143. echo '<li id="section-'.$section.'" class="section main clearfix'.$sectionstyle.'" >';
  144. echo '<div class="left side">&nbsp;'.$currenttext.'</div>';
  145. // Note, 'right side' is BEFORE content.
  146. echo '<div class="right side">';
  147. if ($displaysection == $section) {
  148. echo '<a href="view.php?id='.$course->id.'&amp;week=0#section-'.$section.'" title="'.$strshowallweeks.'">'.
  149. '<img src="'.$OUTPUT->pix_url('i/all') . '" class="icon wkall" alt="'.$strshowallweeks.'" /></a><br />';
  150. } else {
  151. $strshowonlyweek = get_string("showonlyweek", "", $section);
  152. echo '<a href="view.php?id='.$course->id.'&amp;week='.$section.'" title="'.$strshowonlyweek.'">'.
  153. '<img src="'.$OUTPUT->pix_url('i/one') . '" class="icon wkone" alt="'.$strshowonlyweek.'" /></a><br />';
  154. }
  155. if ($PAGE->user_is_editing() && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
  156. if ($thissection->visible) { // Show the hide/show eye
  157. echo '<a href="view.php?id='.$course->id.'&amp;hide='.$section.'&amp;sesskey='.sesskey().'#section-'.$section.'" title="'.$strweekhide.'">'.
  158. '<img src="'.$OUTPUT->pix_url('i/hide') . '" class="icon hide" alt="'.$strweekhide.'" /></a><br />';
  159. } else {
  160. echo '<a href="view.php?id='.$course->id.'&amp;show='.$section.'&amp;sesskey='.sesskey().'#section-'.$section.'" title="'.$strweekshow.'">'.
  161. '<img src="'.$OUTPUT->pix_url('i/show') . '" class="icon hide" alt="'.$strweekshow.'" /></a><br />';
  162. }
  163. if ($section > 1) { // Add a arrow to move section up
  164. echo '<a href="view.php?id='.$course->id.'&amp;random='.rand(1,10000).'&amp;section='.$section.'&amp;move=-1&amp;sesskey='.sesskey().'#section-'.($section-1).'" title="'.$strmoveup.'">'.
  165. '<img src="'.$OUTPUT->pix_url('t/up') . '" class="icon up" alt="'.$strmoveup.'" /></a><br />';
  166. }
  167. if ($section < $course->numsections) { // Add a arrow to move section down
  168. echo '<a href="view.php?id='.$course->id.'&amp;random='.rand(1,10000).'&amp;section='.$section.'&amp;move=1&amp;sesskey='.sesskey().'#section-'.($section+1).'" title="'.$strmovedown.'">'.
  169. '<img src="'.$OUTPUT->pix_url('t/down') . '" class="icon down" alt="'.$strmovedown.'" /></a><br />';
  170. }
  171. }
  172. echo '</div>';
  173. $weekperiod = $weekday.' - '.$endweekday;
  174. echo '<div class="content">';
  175. if (!has_capability('moodle/course:viewhiddensections', $context) and !$thissection->visible) { // Hidden for students
  176. echo $OUTPUT->heading($currenttext.$weekperiod.' ('.get_string('notavailable').')', 3, 'weekdates');
  177. } else {
  178. if (isset($thissection->name) && ($thissection->name !== NULL)) { // empty string is ok
  179. echo $OUTPUT->heading(format_string($thissection->name, true, array('context' => $context)), 3, 'weekdates');
  180. } else {
  181. echo $OUTPUT->heading($currenttext.$weekperiod, 3, 'weekdates');
  182. }
  183. echo '<div class="summary">';
  184. $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
  185. $summarytext = file_rewrite_pluginfile_urls($thissection->summary, 'pluginfile.php', $coursecontext->id, 'course', 'section', $thissection->id);
  186. $summaryformatoptions = new stdClass;
  187. $summaryformatoptions->noclean = true;
  188. $summaryformatoptions->overflowdiv = true;
  189. echo format_text($summarytext, $thissection->summaryformat, $summaryformatoptions);
  190. if ($PAGE->user_is_editing() && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
  191. echo ' <a title="'.$streditsummary.'" href="editsection.php?id='.$thissection->id.'">'.
  192. '<img src="'.$OUTPUT->pix_url('t/edit') . '" class="iconsmall edit" alt="'.$streditsummary.'" /></a><br /><br />';
  193. }
  194. echo '</div>';
  195. print_section($course, $thissection, $mods, $modnamesused);
  196. if ($PAGE->user_is_editing()) {
  197. print_section_add_menus($course, $section, $modnames);
  198. }
  199. }
  200. echo '</div>';
  201. echo "</li>\n";
  202. }
  203. unset($sections[$section]);
  204. $section++;
  205. $weekdate = $nextweekdate;
  206. }
  207. if (!$displaysection and $PAGE->user_is_editing() and has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
  208. // print stealth sections if present
  209. $modinfo = get_fast_modinfo($course);
  210. foreach ($sections as $section=>$thissection) {
  211. if (empty($modinfo->sections[$section])) {
  212. continue;
  213. }
  214. echo '<li id="section-'.$section.'" class="section main clearfix stealth hidden">'; //'<div class="left side">&nbsp;</div>';
  215. echo '<div class="left side">';
  216. echo '</div>';
  217. // Note, 'right side' is BEFORE content.
  218. echo '<div class="right side">';
  219. echo '</div>';
  220. echo '<div class="content">';
  221. echo $OUTPUT->heading(get_string('orphanedactivities'), 3, 'sectionname');
  222. print_section($course, $thissection, $mods, $modnamesused);
  223. echo '</div>';
  224. echo "</li>\n";
  225. }
  226. }
  227. echo "</ul>\n";
  228. if (!empty($sectionmenu)) {
  229. $select = new single_select(new moodle_url('/course/view.php', array('id'=>$course->id)), 'week', $sectionmenu);
  230. $select->label = get_string('jumpto');
  231. $select->class = 'jumpmenu';
  232. $select->formid = 'sectionmenu';
  233. echo $OUTPUT->render($select);
  234. }