/mod/exercise/index.php

https://bitbucket.org/ciceidev/cicei_moodle_conditional_activities · PHP · 144 lines · 131 code · 13 blank · 0 comment · 38 complexity · 5441e135833b0257bcef133c9b154408 MD5 · raw file

  1. <?php // $Id$
  2. require_once("../../config.php");
  3. require_once("lib.php");
  4. require_once("locallib.php");
  5. $id = required_param('id', PARAM_INT); // course
  6. if (! $course = get_record("course", "id", $id)) {
  7. error("Course ID is incorrect");
  8. }
  9. require_login($course->id);
  10. add_to_log($course->id, "exercise", "view all", "index.php?id=$course->id", "");
  11. $strexercises = get_string("modulenameplural", "exercise");
  12. $strexercise = get_string("modulename", "exercise");
  13. $strweek = get_string("week");
  14. $strtopic = get_string("topic");
  15. $strname = get_string("name");
  16. $strtitle = get_string("title", "exercise");
  17. $strphase = get_string("phase", "exercise");
  18. $strgrade = get_string("grade");
  19. $strdeadline = get_string("deadline", "exercise");
  20. $strsubmitted = get_string("submitted", "assignment");
  21. $navlinks = array();
  22. $navlinks[] = array('name' => $strexercises, 'link' => '', 'type' => 'activity');
  23. $navigation = build_navigation($navlinks);
  24. print_header_simple("$strexercises", "", $navigation, "", "", true, "", navmenu($course));
  25. if (! $exercises = get_all_instances_in_course("exercise", $course)) {
  26. notice(get_string('thereareno', 'moodle', $strexercises), "../../course/view.php?id=$course->id");
  27. die;
  28. }
  29. $timenow = time();
  30. if ($course->format == "weeks") {
  31. if (isteacher($course->id)) {
  32. $table->head = array ($strweek, $strname, $strtitle, $strphase, $strsubmitted, $strdeadline);
  33. } else {
  34. $table->head = array ($strweek, $strname, $strtitle, $strgrade, $strsubmitted, $strdeadline);
  35. }
  36. $table->align = array ("center", "left", "left","center","left", "left");
  37. } else if ($course->format == "topics") {
  38. if (isteacher($course->id)) {
  39. $table->head = array ($strtopic, $strname, $strtitle, $strphase, $strsubmitted, $strdeadline);
  40. } else {
  41. $table->head = array ($strtopic, $strname, $strtitle, $strgrade, $strsubmitted, $strdeadline);
  42. }
  43. $table->align = array ("center", "left", "left", "center", "left", "left");
  44. } else {
  45. $table->head = array ($strname, $strsubmitted, $strdeadline);
  46. $table->align = array ("left", "left", "left");
  47. }
  48. foreach ($exercises as $exercise) {
  49. if ($exercise->deadline > $timenow) {
  50. $due = userdate($exercise->deadline);
  51. } else {
  52. $due = "<font color=\"red\">".userdate($exercise->deadline)."</font>";
  53. }
  54. if ($submissions = exercise_get_user_submissions($exercise, $USER)) {
  55. foreach ($submissions as $submission) {
  56. if ($submission->late) {
  57. $submitted = "<font color=\"red\">".userdate($submission->timecreated)."</font>";
  58. }
  59. else {
  60. $submitted = userdate($submission->timecreated);
  61. }
  62. $link = "<a href=\"view.php?id=$exercise->coursemodule\">".format_string($exercise->name,true)."</a>";
  63. $title = $submission->title;
  64. if ($course->format == "weeks" or $course->format == "topics") {
  65. if (isteacher($course->id)) {
  66. $phase = '';
  67. switch ($exercise->phase) {
  68. case 0:
  69. case 1: $phase = get_string("phase1short", "exercise");
  70. break;
  71. case 2: $phase = get_string("phase2short", "exercise");
  72. if ($num = exercise_count_unassessed_student_submissions($exercise)) {
  73. $phase .= " [".get_string("unassessed", "exercise", $num)."]";
  74. }
  75. break;
  76. case 3: $phase = get_string("phase3short", "exercise");
  77. if ($num = exercise_count_unassessed_student_submissions($exercise)) {
  78. $phase .= " [".get_string("unassessed", "exercise", $num)."]";
  79. }
  80. break;
  81. }
  82. $table->data[] = array ($exercise->section, $link, $title, $phase,
  83. $submitted, $due);
  84. } else { // it's a student
  85. if ($assessments = exercise_get_user_assessments($exercise, $USER)) { // should be only one...
  86. foreach ($assessments as $studentassessment) {
  87. break;
  88. }
  89. if ($studentassessment->timegraded) { // it's been assessed
  90. if ($teacherassessment = exercise_get_submission_assessment($submission)) {
  91. $actualgrade = number_format(($studentassessment->gradinggrade *
  92. $exercise->gradinggrade / 100.0) + ($teacherassessment->grade *
  93. $exercise->grade / 100.0), 1);
  94. if ($submission->late) {
  95. $actualgrade = "<font color=\"red\">(".$actualgrade.")<font color=\"red\">";
  96. }
  97. $actualgrade .= " (".get_string("maximumshort").": ".
  98. number_format($exercise->gradinggrade + $exercise->grade, 0).")";
  99. $table->data[] = array ($exercise->section, $link, $title, $actualgrade,
  100. $submitted, $due);
  101. }
  102. } else {
  103. $table->data[] = array ($exercise->section, $link, $title,
  104. "-", $submitted, $due);
  105. }
  106. }
  107. }
  108. } else {
  109. $table->data[] = array ($link, $submitted, $due);
  110. }
  111. }
  112. } else {
  113. $submitted = get_string("no");
  114. $title = '';
  115. $link = "<a href=\"view.php?id=$exercise->coursemodule\">".format_string($exercise->name,true)."</a>";
  116. if ($course->format == "weeks" or $course->format == "topics") {
  117. if (isteacher($course->id)) {
  118. $table->data[] = array ($exercise->section, $link, $title, $exercise->phase,
  119. $submitted, $due);
  120. } else {
  121. $table->data[] = array ($exercise->section, $link, $title, "-", $submitted, $due);
  122. }
  123. } else {
  124. $table->data[] = array ($link, $submitted, $due);
  125. }
  126. }
  127. }
  128. echo "<br />";
  129. print_table($table);
  130. print_footer($course);
  131. ?>