AdvisingScreenTypeView.php

  1. 6.x classes/AdvisingScreenTypeView.php
  2. 4.x custom/classes/AdvisingScreenTypeView.php
  3. 5.x custom/classes/AdvisingScreenTypeView.php

File

classes/AdvisingScreenTypeView.php
View source
  1. <?php
  2. /**
  3. * This class is the View by Type view for FlightPath. As such, it
  4. * inherits most of it's classes from __advising_screen.
  5. *
  6. * The biggest difference with View by Type from the default
  7. * View by Year is that we don't care about the original semesters
  8. * that were spelled out in the degree plan. We need to re-organize them
  9. * into new semesters for Major, Core, Supporting, and Electives. So,
  10. * most of the methods here will be about doing that.
  11. *
  12. */
  13. class AdvisingScreenTypeView extends AdvisingScreen
  14. {
  15. /**
  16. * In __advising_screen, this method simply displays the degree plan's
  17. * semesters to the screen. But here, we need to go through the
  18. * type categories: ex: Core, Major, Supporting, and Electives,
  19. * and only display courses and groups from each semester fitting
  20. * that type.
  21. *
  22. */
  23. function build_semester_list()
  24. {
  25. $list_semesters = $this->degree_plan->list_semesters;
  26. // Go through each semester and add it to the screen...
  27. $list_semesters->reset_counter();
  28. // We want to go through our requirement types, and create a box for each one, if available.
  29. $types = fp_get_requirement_types($this->student->school_id);
  30. foreach ($types as $code => $desc) {
  31. $temp = $this->display_semester_list($list_semesters, $code, $desc, TRUE);
  32. if ($temp) {
  33. $this->add_to_screen($temp, "SEMESTER_TYPE_" . $code);
  34. }
  35. }
  36. $temp_d_s = new Semester(DegreePlan::SEMESTER_NUM_FOR_DEVELOPMENTALS); // developmental requirements.
  37. if ($dev_sem = $list_semesters->find_match($temp_d_s))
  38. {
  39. $this->add_to_screen($this->display_semester($dev_sem), "SEMESTER_" . DegreePlan::SEMESTER_NUM_FOR_DEVELOPMENTALS);
  40. }
  41. }
  42. /**
  43. * Does the testType match the reqType? This function is used
  44. * to make sure that courses or groups with a certain requirement_type
  45. * are placed in the correct semester blocks on screen.
  46. *
  47. * @param string $test_type
  48. * @param string $req_type
  49. * @return bool
  50. */
  51. function match_requirement_type($test_type, $req_type)
  52. {
  53. // Does the testType match the reqType?
  54. if ($test_type == $req_type)
  55. {
  56. return true;
  57. }
  58. // Does it match if there's a u in front?
  59. if ($test_type == ("u" . $req_type))
  60. { // university captone type.
  61. return true;
  62. }
  63. if ($req_type == "e")
  64. {
  65. // type "elective." We will make sure the test_type isn't in
  66. // one of our defined types already.
  67. // Also, make sure it doesn't begin with a 'u'. Ex: um, for University Capstone + m. That would be undefined as well.
  68. $no_u_test_type = ltrim($test_type, 'u');
  69. $types = fp_get_requirement_types($this->student->school_id);
  70. if (!isset($types[$test_type]) && !isset($types[$no_u_test_type])) {
  71. // Yes-- the user is using a code NOT defined, so let's just call it
  72. // an "elective" type.
  73. return TRUE;
  74. }
  75. }
  76. return false;
  77. }
  78. /**
  79. * Display contents of a semester list as a single semester,
  80. * only displaying courses matching the requirement_type.
  81. * If the requirement_type is "e", then we will also look for anything
  82. * not containing a defined requirement_type.
  83. *
  84. * @param SemesterList $list_semesters
  85. * @param string $requirement_type
  86. * @param string $title
  87. * @param bool $bool_display_hour_count
  88. * @return string
  89. */
  90. function display_semester_list($list_semesters, $requirement_type, $title, $bool_display_hour_count = false)
  91. {
  92. // TODO: convert to using render array.
  93. // Display the contents of a semester object
  94. // on the screen (in HTML)
  95. $pC = "";
  96. $pC .= $this->draw_semester_box_top($title);
  97. $is_empty = TRUE;
  98. $degree_sort_policy = variable_get_for_school("degree_requirement_sort_policy", "alpha", $this->student->school_id);
  99. $count_hours_completed = 0;
  100. $list_semesters->reset_counter();
  101. while($list_semesters->has_more())
  102. {
  103. $semester = $list_semesters->get_next();
  104. if ($semester->semester_num == DegreePlan::SEMESTER_NUM_FOR_COURSES_ADDED)
  105. { // These are the "added by advisor" courses. Skip them.
  106. continue;
  107. }
  108. $last_req_by_degree_id = -1;
  109. // First, display the list of bare courses.
  110. if ($degree_sort_policy == 'database') {
  111. $semester->list_courses->sort_degree_requirement_id();
  112. }
  113. else {
  114. // By default, sort alphabetical
  115. $semester->list_courses->sort_alphabetical_order(); // sort, including the degree title we're sorting for.
  116. }
  117. $semester->list_courses->reset_counter();
  118. $sem_is_empty = true;
  119. $html = array();
  120. $sem_rnd = rand(0,99999);
  121. $pC .= "<tr><td colspan='4' class='tenpt'>
  122. <span class='advise-type-view-sem-title'><!--SEMTITLE$sem_rnd--></span></td></tr>";
  123. while($semester->list_courses->has_more())
  124. {
  125. $course = $semester->list_courses->get_next();
  126. // Make sure the requirement type matches!
  127. if (!$this->match_requirement_type($course->requirement_type, $requirement_type))
  128. {
  129. continue;
  130. }
  131. $is_empty = FALSE;
  132. if (!isset($html[$course->req_by_degree_id])) {
  133. $html[$course->req_by_degree_id] = "";
  134. }
  135. // Is this course being fulfilled by anything?
  136. //if (is_object($course->courseFulfilledBy))
  137. if (!($course->course_list_fulfilled_by->is_empty))
  138. { // this requirement is being fulfilled by something the student took...
  139. $c = $course->course_list_fulfilled_by->get_first();
  140. $c->req_by_degree_id = $course->req_by_degree_id; // make sure we assign it to the current degree_id.
  141. $html[$course->req_by_degree_id] .= $this->draw_course_row($c);
  142. $c->set_has_been_displayed($course->req_by_degree_id);
  143. if ($c->display_status == "completed")
  144. { // We only want to count completed hours, no midterm or enrolled courses.
  145. $h = $c->get_hours_awarded();
  146. if ($c->bool_ghost_hour == TRUE) {
  147. $h = 0;
  148. }
  149. $count_hours_completed += $h;
  150. }
  151. } else {
  152. // This requirement is not being fulfilled...
  153. $html[$course->req_by_degree_id] .= $this->draw_course_row($course);
  154. }
  155. $sem_is_empty = false;
  156. } //while list_courses
  157. // Now, draw all the groups.
  158. $semester->list_groups->sort_alphabetical_order();
  159. $semester->list_groups->reset_counter();
  160. while($semester->list_groups->has_more())
  161. {
  162. $group = $semester->list_groups->get_next();
  163. if (!$this->match_requirement_type($group->requirement_type, $requirement_type))
  164. {
  165. continue;
  166. }
  167. if (!isset($html[$group->req_by_degree_id])) {
  168. $html[$group->req_by_degree_id] = "";
  169. }
  170. $html[$group->req_by_degree_id] .= "<tr><td colspan='8'>";
  171. $html[$group->req_by_degree_id] .= $this->display_group($group);
  172. $count_hours_completed += $group->hours_fulfilled_for_credit;
  173. $html[$group->req_by_degree_id] .= "</td></tr>";
  174. $sem_is_empty = false;
  175. $is_empty = FALSE;
  176. } // while list_groups
  177. if ($sem_is_empty == false)
  178. {
  179. // There WAS something in this semester, put in the title.
  180. //debugCT("replacing $sem_rnd with $semester->title");
  181. $pC = str_replace("<!--SEMTITLE$sem_rnd-->",$semester->title,$pC);
  182. }
  183. // Okay, let's plan to put it all on the screen for this semester....
  184. // Sort by degree's advising weight
  185. $new_html = array();
  186. foreach($html as $req_by_degree_id => $content) {
  187. $dtitle = @$GLOBALS["fp_temp_degree_titles"][$req_by_degree_id];
  188. $dweight = intval(@$GLOBALS["fp_temp_degree_advising_weights"][$req_by_degree_id]);
  189. if ($dtitle == "") {
  190. $t_degree_plan = new DegreePlan();
  191. $t_degree_plan->degree_id = $req_by_degree_id;
  192. $dtitle = $t_degree_plan->get_title2(TRUE, TRUE);
  193. $dweight = $t_degree_plan->db_advising_weight;
  194. $dtype = $t_degree_plan->degree_type;
  195. $dclass = $t_degree_plan->degree_class;
  196. $dlevel = $t_degree_plan->degree_level;
  197. $GLOBALS["fp_temp_degree_types"][$req_by_degree_id] = $dtype; //save for next time.
  198. $GLOBALS["fp_temp_degree_classes"][$req_by_degree_id] = $dclass; //save for next time.
  199. $GLOBALS["fp_temp_degree_levels"][$req_by_degree_id] = $dlevel; //save for next time.
  200. $GLOBALS["fp_temp_degree_titles"][$req_by_degree_id] = $dtitle . " "; //save for next time.
  201. $GLOBALS["fp_temp_degree_advising_weights"][$req_by_degree_id] = $dweight . " "; //save for next time.
  202. }
  203. $degree_title = fp_get_machine_readable($dtitle); // make it machine readable. No funny characters.
  204. $degree_advising_weight = str_pad($dweight, 4, "0", STR_PAD_LEFT);
  205. $new_html[$degree_advising_weight . "__" . $degree_title][$req_by_degree_id] = $content;
  206. }
  207. // Sort by the first index, the advising weight.
  208. ksort($new_html);
  209. //////////////////////////
  210. // Okay, now let's go through our HTML array and add to the screen....
  211. foreach ($new_html as $w => $html) {
  212. foreach($html as $req_by_degree_id => $content) {
  213. // Get the degree title...
  214. $dtitle = @$GLOBALS["fp_temp_degree_titles"][$req_by_degree_id];
  215. $css_dtitle = @$GLOBALS["fp_temp_degree_css_titles"][$req_by_degree_id];
  216. $dtype = @$GLOBALS["fp_temp_degree_types"][$req_by_degree_id];
  217. $dclass = @$GLOBALS["fp_temp_degree_classes"][$req_by_degree_id];
  218. $dlevel = @$GLOBALS["fp_temp_degree_levels"][$req_by_degree_id];
  219. if ($dtitle == "" || $css_dtitle == "") {
  220. $t_degree_plan = new DegreePlan();
  221. $t_degree_plan->degree_id = $req_by_degree_id;
  222. $dtitle = $t_degree_plan->get_title2(TRUE, TRUE);
  223. $css_dtitle = $t_degree_plan->get_title2(TRUE, TRUE, FALSE);
  224. $dtype = $t_degree_plan->degree_type;
  225. $dclass = $t_degree_plan->degree_class;
  226. $dlevel = $t_degree_plan->degree_level;
  227. $GLOBALS["fp_temp_degree_types"][$req_by_degree_id] = $dtype; //save for next time.
  228. $GLOBALS["fp_temp_degree_classes"][$req_by_degree_id] = $dclass; //save for next time.
  229. $GLOBALS["fp_temp_degree_levels"][$req_by_degree_id] = $dlevel; //save for next time.
  230. $GLOBALS["fp_temp_degree_titles"][$req_by_degree_id] = $dtitle; //save for next time.
  231. $GLOBALS["fp_temp_degree_css_titles"][$req_by_degree_id] = $css_dtitle; //save for next time.
  232. }
  233. $css_dtitle = fp_get_machine_readable($css_dtitle);
  234. $theme = array(
  235. 'classes' => array('tenpt', 'required-by-degree',
  236. "required-by-degree-$css_dtitle",
  237. "required-by-degree-type-" . fp_get_machine_readable($dtype),
  238. "required-by-degree-class-" . fp_get_machine_readable($dclass),
  239. "required-by-degree-level-" . fp_get_machine_readable($dlevel),
  240. ),
  241. 'css_dtitle' => $css_dtitle,
  242. 'degree_id' => $req_by_degree_id,
  243. 'required_by_html' => "<span class='req-by-label'>" . t("Required by") . "</span> <span class='req-by-degree-title'>$dtitle</span>",
  244. 'view_by' => 'type',
  245. );
  246. invoke_hook("theme_advise_degree_header_row", array(&$theme));
  247. // Don't display if we are in the Courses Added semester, or if we are NOT a "combined" degree.
  248. if ($semester->semester_num == DegreePlan::SEMESTER_NUM_FOR_COURSES_ADDED || (is_object($this->degree_plan)) && !$this->degree_plan->is_combined_dynamic_degree_plan) {
  249. $theme['required_by_html'] = '';
  250. }
  251. if ($theme['required_by_html']) {
  252. $pC .= "<tr><td colspan='8'>
  253. <div class='" . implode(' ',$theme['classes']) ."'>{$theme['required_by_html']}</div>
  254. </td></tr>";
  255. }
  256. $pC .= $content;
  257. }
  258. }
  259. } // while list_semester
  260. if ($is_empty == TRUE) {
  261. // There was nothing in this box. Do not return anything.
  262. return FALSE;
  263. }
  264. // Add hour count to the bottom...
  265. if ($bool_display_hour_count == true && $count_hours_completed > 0)
  266. {
  267. $pC .= "<tr><td colspan='8'>
  268. <div class='tenpt advise-completed-hours' style='text-align:right; margin-top: 10px;'>
  269. <span class='completed-hours-label'>" . t("Completed hours:") . "</span> <span class='count-hours-completed'>$count_hours_completed</span>
  270. </div>
  271. ";
  272. $pC .= "</td></tr>";
  273. }
  274. $pC .= $this->draw_semester_box_bottom();
  275. return $pC;
  276. }
  277. } //class

Classes

Namesort descending Description
AdvisingScreenTypeView This class is the View by Type view for FlightPath. As such, it inherits most of it's classes from __advising_screen.