_GroupList.php

  1. 4.x classes/_GroupList.php
  2. 5.x classes/_GroupList.php

File

classes/_GroupList.php
View source
  1. <?php
  2. require_once("ObjList.php");
  3. class _GroupList extends ObjList
  4. {
  5. /*
  6. This class inherits mosts of its classes from ObjList
  7. in a similar fashion as CourseList.
  8. */
  9. function reset_list_counters()
  10. {
  11. $this->reset_counter();
  12. // Also, go through all groups in the list and call
  13. // their "reset_list_counters" method.
  14. for ($t = 0; $t < $this->count; $t++)
  15. {
  16. $group = $this->array_list[$t];
  17. $group->reset_list_counters();
  18. }
  19. }
  20. function contains_group_requirement_id($group_requirement_id)
  21. {
  22. // Returns true if any of the lists of courses in these groups
  23. // contain the group requirement ID.
  24. for ($t = 0; $t < count($this->array_list); $t++)
  25. {
  26. $group = $this->array_list[$t];
  27. if ($group->list_courses->contains_group_requirement_id($group_requirement_id))
  28. {
  29. return true;
  30. }
  31. }
  32. return false;
  33. }
  34. /**
  35. * Set all the courses and branches in this group to the specified degree_id.
  36. */
  37. function set_req_by_degree_id($degree_id = 0) {
  38. // Loop through all the groups in this list...
  39. $this->reset_counter();
  40. while ($this->has_more()) {
  41. $g = $this->get_next();
  42. // Set req_by_degree_id on this group...
  43. $g->set_req_by_degree_id($degree_id);
  44. }
  45. }
  46. /**
  47. * Adds the supplied GroupList to the bottom of $this's list.
  48. *
  49. */
  50. function add_list(GroupList $glist)
  51. {
  52. for ($t = 0; $t < count($glist->array_list); $t++)
  53. {
  54. $this->add($glist->array_list[$t]);
  55. }
  56. }
  57. /**
  58. * Return back the matching group object, if it's degree_id matches. Otherwise, FALSE
  59. */
  60. function find_match_with_degree_id($group, $degree_id) {
  61. for ($t = 0; $t < $this->count; $t++)
  62. {
  63. $g = $this->array_list[$t];
  64. if ($g->group_id == $group->group_id && $g->req_by_degree_id == $degree_id) {
  65. return $g;
  66. }
  67. }
  68. return FALSE;
  69. }
  70. /**
  71. * Return an array of course_id's for all the groups in this list.
  72. * will look like: $rtn[group_id][course_id] = TRUE
  73. */
  74. function get_group_course_id_array() {
  75. $rtn = array();
  76. $this->reset_counter();
  77. for ($t = 0; $t < $this->count; $t++)
  78. {
  79. $g = $this->array_list[$t];
  80. $rtn[$g->group_id] = $g->get_course_id_array();
  81. }
  82. return $rtn;
  83. }
  84. /**
  85. * Calls the function "reload_missing_courses" on all groups in this list.
  86. */
  87. function reload_missing_courses() {
  88. for ($t = 0; $t < $this->count; $t++)
  89. {
  90. $group = $this->array_list[$t];
  91. $group->reload_missing_courses();
  92. }
  93. }
  94. /**
  95. * Return a GroupList which is a clone of this list.
  96. */
  97. function get_clone($bool_return_new_groups = FALSE, $bool_load_groups = TRUE, $bool_reload_missing_courses = FALSE)
  98. {
  99. $rtn_list = new GroupList();
  100. for ($t = 0; $t < $this->count; $t++)
  101. {
  102. $group = $this->array_list[$t];
  103. if ($bool_return_new_groups == TRUE)
  104. {
  105. $new_group = new Group();
  106. $new_group->group_id = $group->group_id;
  107. if ($bool_load_groups) {
  108. $new_group->load_group(); // Make sure the group has all its courses loaded in.
  109. }
  110. $new_group->set_requirement_type($group->requirement_type);
  111. $new_group->set_req_by_degree_id($group->req_by_degree_id);
  112. $rtn_list->add($new_group);
  113. }
  114. else {
  115. if ($bool_load_groups) {
  116. $group->load_group(); // Make sure the group has all its courses loaded in.
  117. }
  118. if ($bool_reload_missing_courses) {
  119. $group->reload_missing_courses();
  120. }
  121. $group->set_requirement_type($group->requirement_type);
  122. $group->set_req_by_degree_id($group->req_by_degree_id);
  123. $rtn_list->add($group);
  124. }
  125. }
  126. return $rtn_list;
  127. }
  128. function get_advised_courses_list()
  129. {
  130. // Return a courseList object of courses in THIS
  131. // group which have boolAdvisedToTake == true.
  132. $rtn_list = new CourseList();
  133. for ($t = 0; $t < count($this->array_list); $t++)
  134. {
  135. $group = $this->array_list[$t];
  136. $rtn_list->add_list($group->list_courses->get_advised_courses_list());
  137. $group->list_groups->reset_counter();
  138. while($group->list_groups->has_more())
  139. {
  140. $gg = $group->list_groups->get_next();
  141. $rtn_list->add_list($gg->list_courses->get_advised_courses_list());
  142. }
  143. }
  144. $rtn_list->remove_duplicates();
  145. return $rtn_list;
  146. }
  147. function assign_min_grade($min_grade)
  148. {
  149. // Assign a min grade to every group in this grouplist.
  150. $count = count($this->array_list);
  151. for ($t = 0; $t < $count; $t++)
  152. {
  153. $group = $this->array_list[$t];
  154. $group->assign_min_grade($min_grade);
  155. }
  156. }
  157. /**
  158. * Sort this list of groups by the advising weights of the degrees they belong to.
  159. *
  160. * This solution (which allows for negative numbers) was provided by user oantby (Logan Bluth) from Morningside.
  161. * The original function is z__sort_degree_advising_weight()
  162. */
  163. function sort_degree_advising_weight() {
  164. $tarray = array();
  165. $per_major_code = array();
  166. for ($t = 0; $t < count($this->array_list); $t++)
  167. {
  168. $g = $this->array_list[$t];
  169. // Get the degree_id for this group
  170. $degree_id = $g->req_by_degree_id;
  171. $major_code = fp_get_degree_major_code($degree_id);
  172. $advising_weight = fp_get_degree_advising_weight($degree_id);
  173. if (!$advising_weight) $advising_weight = 0;
  174. $tarray[$major_code] = $advising_weight;
  175. $per_major_code[$advising_weight][$major_code][] = &$this->array_list[$t];//use a reference so we don't need extra memory/cpu overhead.
  176. }
  177. // Now, sort the array to get everything in the correct order
  178. // Use asort to preserve keys (major codes)
  179. asort($tarray,SORT_NUMERIC);
  180. // Now, convert the array back into a list of groups.
  181. $new_list = new GroupList();
  182. foreach ($tarray as $major_code => $weight) {
  183. // As a secondary measure, we also wanted to sort equal weighted majors alphabetically by major_code.
  184. ksort($per_major_code[$weight]);
  185. foreach ($per_major_code[$weight][$major_code] as &$group) {
  186. $new_list->add($group);
  187. }
  188. }
  189. // Okay, now $new_list should contain the correct values.
  190. // We will transfer over the reference.
  191. $this->array_list = $new_list->array_list;
  192. } // sort_degree_advising_weight
  193. function z__sort_degree_advising_weight() {
  194. $tarray = array();
  195. for ($t = 0; $t < count($this->array_list); $t++)
  196. {
  197. $g = $this->array_list[$t];
  198. // Get the degree_id for this group
  199. $degree_id = $g->req_by_degree_id;
  200. $major_code = fp_get_degree_major_code($degree_id);
  201. $advising_weight = fp_get_degree_advising_weight($degree_id);
  202. if (!$advising_weight) $advising_weight = 0;
  203. // Make the number a string, uniformly long
  204. $advising_weight = str_pad($advising_weight, 4, "0", STR_PAD_LEFT);
  205. //$new_html[$degree_advising_weight . "__" . $degree_title][$req_by_degree_id] = $content;
  206. $tarray[] = $advising_weight . "___" . $major_code . " ~~ " . $t;
  207. }
  208. // Now, sort the array to get everything in the correct order.
  209. sort($tarray);
  210. // Now, convert the array back into a list of groups.
  211. $new_list = new GroupList();
  212. for($t = 0; $t < count($tarray); $t++)
  213. {
  214. $temp = explode(" ~~ ",$tarray[$t]);
  215. $i = $temp[1];
  216. $new_list->add($this->array_list[$i]);
  217. }
  218. // Okay, now $new_list should contain the correct values.
  219. // We will transfer over the reference.
  220. $this->array_list = $new_list->array_list;
  221. } // sort_degree_advising_weight
  222. /**
  223. * Sort this list of groups by their priority number. Higher priorities appear at the top of the list.
  224. *
  225. * This will allow negative numbers (thanks to user oantby (Logan Bluth) from Morningside.
  226. * The original function is z__sort_priority(), which is left in the code in case it is needed.
  227. */
  228. function sort_priority() {
  229. /*
  230. Sort this list of groups by their priority number.
  231. Higher priorities should appear at the
  232. top of the list.
  233. */
  234. $tarray = array();
  235. for ($t = 0; $t < count($this->array_list); $t++)
  236. {
  237. $g = $this->array_list[$t];
  238. $g->load_descriptive_data();
  239. $pri = "" . intval($g->priority) . "";
  240. $str = "$pri ~~ $t";
  241. array_push($tarray,$str);
  242. }
  243. // We use SORT_NUMERIC so that negative numbers may be used.
  244. rsort($tarray,SORT_NUMERIC);
  245. // Now, convert the array back into a list of groups.
  246. $new_list = new GroupList();
  247. for($t = 0; $t < count($tarray); $t++)
  248. {
  249. $temp = explode(" ~~ ",$tarray[$t]);
  250. $i = $temp[1];
  251. $new_list->add($this->array_list[$i]);
  252. }
  253. // Okay, now $new_list should contain the correct values.
  254. // We will transfer over the reference.
  255. $this->array_list = $new_list->array_list;
  256. }
  257. function z__sort_priority()
  258. {
  259. /*
  260. Sort this list of groups by their priority number.
  261. Higher priorities should appear at the
  262. top of the list.
  263. */
  264. $tarray = array();
  265. // Since I need the indexes, I will have to go through the array
  266. // myself...
  267. for ($t = 0; $t < count($this->array_list); $t++)
  268. {
  269. $g = $this->array_list[$t];
  270. $g->load_descriptive_data();
  271. $pri = "" . ($g->priority*1) . "";
  272. if (strlen($pri) == 1)
  273. {
  274. $pri = "0" . $pri; // padd with 0 on the front.
  275. // This fixes a sorting problem, because priorities
  276. // were being evaluated as text, not nums, so "5" seemed
  277. // larger than "15" (because it was comparing the 5 to the 1).
  278. }
  279. $str = "$pri ~~ $t";
  280. array_push($tarray,$str);
  281. }
  282. rsort($tarray);
  283. // Now, convert the array back into a list of groups.
  284. $new_list = new GroupList();
  285. for($t = 0; $t < count($tarray); $t++)
  286. {
  287. $temp = explode(" ~~ ",$tarray[$t]);
  288. $i = $temp[1];
  289. $new_list->add($this->array_list[$i]);
  290. }
  291. // Okay, now $new_list should contain the correct values.
  292. // We will transfer over the reference.
  293. $this->array_list = $new_list->array_list;
  294. }
  295. /**
  296. * Sorts best-grade-first, as defined by the setting "grade_order", which is a CSV of
  297. * grades, best-first. Ex: A, B, C, D, F
  298. *
  299. * We will use the student's best grade for a course, rather
  300. * than the actual course's grade. Generally, this can be left as set to null. This is only for when we are
  301. * trying to organize a list of courses into the grade order, based on what a student has taken. For example, if we want
  302. * to order a Group's list of courses based on what the student has taken and the grades they made.
  303. *
  304. * We will do this for each group in this group list, and the group list with the best grades overall will be sorted
  305. * to the top, the group with the worst grades will sort to the bottom.
  306. *
  307. */
  308. function sort_best_grade_first_by_student_grades(Student $student) {
  309. $temp = csv_to_array(variable_get("grade_order", "AMID,BMID,CMID,DMID,FMID,A,B,C,D,F,W,I"));
  310. // We will use array_flip to get back an assoc array where the grades are the keys and the indexes are the values.
  311. $temp = array_flip($temp);
  312. // Go through the grades and convert the integers to strings, padd with zeros so that everything is at least 3 digits.
  313. $grades = array();
  314. foreach ($temp as $grade => $val) {
  315. $grades[$grade] = str_pad((string)$val, 3, "0", STR_PAD_LEFT);
  316. }
  317. // We now have our grades array just how we want it. Best grade has lowest value. Worst grade has highest value.
  318. $unknown_grade_value = "999"; // sort to the very end, in other words.
  319. $tarray = array();
  320. for ($t = 0; $t < $this->count; $t++) {
  321. $g = $this->array_list[$t];
  322. $student_grade_score = $g->list_courses->sort_best_grade_first($student);
  323. // Now, we want to record their "grade score", which we will use for sorting.
  324. // Make sure all the values are uniformly 6 digits long
  325. $student_grade_score = str_pad((string)$student_grade_score, 6, "0", STR_PAD_LEFT);
  326. $tarray[] = "$student_grade_score ~~ $t";
  327. }
  328. // Sort by those grade scores
  329. sort($tarray);
  330. // Okay, now go back through tarray and re-construct a new GroupList
  331. $new_list = new GroupList();
  332. for($t = 0; $t < count($tarray); $t++)
  333. {
  334. $temp = explode(" ~~ ",$tarray[$t]);
  335. $i = $temp[1];
  336. $new_list->add($this->array_list[$i]);
  337. }
  338. // Okay, now $new_list should contain the correct values.
  339. // We will transfer over the reference.
  340. $this->array_list = $new_list->array_list;
  341. // And we are done!
  342. } // function
  343. function sort_alphabetical_order($bool_reverse_order = false)
  344. {
  345. $tarray = array();
  346. // Since I need the indexes, I will have to go through the array
  347. // myself...
  348. for ($t = 0; $t < count($this->array_list); $t++)
  349. {
  350. $g = $this->array_list[$t];
  351. $g->load_descriptive_data();
  352. $str = "$g->title ~~ $t";
  353. array_push($tarray,$str);
  354. }
  355. if ($bool_reverse_order == true)
  356. {
  357. rsort($tarray);
  358. } else {
  359. sort($tarray);
  360. }
  361. // Now, convert the array back into a list of groups.
  362. $new_list = new GroupList();
  363. for($t = 0; $t < count($tarray); $t++)
  364. {
  365. $temp = explode(" ~~ ",$tarray[$t]);
  366. $i = $temp[1];
  367. $new_list->add($this->array_list[$i]);
  368. }
  369. // Okay, now $new_list should contain the correct values.
  370. // We will transfer over the reference.
  371. $this->array_list = $new_list->array_list;
  372. }
  373. }

Classes

Namesort descending Description
_GroupList