_CourseList.php

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

Classes

NameDescription
_CourseList

File

classes/_CourseList.php
View source
  1. <?php
  2. require_once("ObjList.php");
  3. class _CourseList extends ObjList
  4. {
  5. // This inherits most of its classes from ObjList,
  6. // but, it has to be able to do special functions
  7. // specific to Courses. Use parent:: to access
  8. // a parent function within ObjList.
  9. // Example: parent::indexOf();
  10. //public $arrayCourseIDList = array();
  11. /**
  12. * Used to cast a regular ObjList object into a CourseList.
  13. *
  14. * @param ObjList $obj
  15. *
  16. * @return CourseList
  17. */
  18. static public function cast(ObjList $obj)
  19. { // This can be used to cast a regular ObjList
  20. // into a CourseList object.
  21. // Use the syntax: CourseList::cast($x);
  22. $new_c_l = new CourseList();
  23. $new_c_l->array_list = $obj->array_list;
  24. $new_c_l->is_empty = $obj->is_empty;
  25. $new_c_l->reset_counter();
  26. return $new_c_l;
  27. }
  28. /**
  29. * Give every course in the list a minimum grade.
  30. *
  31. * @param string $min_grade
  32. */
  33. function assign_min_grade($min_grade)
  34. {
  35. // Go through the list and give every course the specified
  36. // min grade.
  37. for ($t = 0; $t < $this->count; $t++)
  38. {
  39. $course = $this->array_list[$t];
  40. $course->min_grade = $min_grade;
  41. }
  42. }
  43. /**
  44. * Go through the list and find any course whose hours are greater
  45. * than $hours. Make that course "unselectable." Used in the groups.
  46. *
  47. * For example, if a student may only select 3 hours from a group, we don't
  48. * want to give them the option of selecting a 5 hour course. But we also
  49. * don't want to remove that course either. We want to display it so they
  50. * know it was an option (and possibly need to substitute or move things
  51. * around if they need it).
  52. *
  53. * Returns TRUE if anything got assigned, FALSE if nothing got assigned.
  54. *
  55. * @param int $hours
  56. *
  57. * @return bool
  58. */
  59. function assign_unselectable_courses_with_hours_greater_than($hours)
  60. {
  61. // Go through the list and assign bool_unselectable courses whose minHour
  62. // is greater than $hours.
  63. // Returns TRUE if it did assign something,
  64. // false if it didn't.
  65. $bool_assigned = false;
  66. for ($t = 0; $t < $this->count; $t++)
  67. {
  68. $course = $this->array_list[$t];
  69. if ($course->subject_id == "")
  70. {
  71. $course->load_descriptive_data();
  72. }
  73. if ($course->min_hours > $hours)
  74. {
  75. $course->bool_unselectable = true;
  76. $bool_assigned = true;
  77. }
  78. }
  79. return $bool_assigned;
  80. }
  81. /**
  82. * Find and return a specific course from the list.
  83. *
  84. * @param int $course_id
  85. * - The course_id to look for. Do not set if using
  86. * $use_course.
  87. *
  88. * @param int $term_id
  89. * - The term_id for the course to look for. Do not set if using
  90. * $use_course.
  91. *
  92. * @param bool $bool_transfer
  93. * - Is the course we are looking for a transfer course? Do not
  94. * use if using $use_course.
  95. *
  96. * @param bool $bool_exclude_substitutions
  97. * - If TRUE, we will not consider courses which have been used
  98. * in a substitution.
  99. *
  100. * @param Course $use_course
  101. * - Optional. If you already have a course object which can be used
  102. * as a template to search for, specify it here. Otherwise, set to
  103. * NULL. If using this, then $course_id, $term_id, and $bool_transfer
  104. * will be ignored.
  105. *
  106. * @param Int $sub_req_by_degree_id
  107. * - Optional. If set, we will only exclude substituted courses if they were substitutions made for this degree_id. Leave 0 if not sure
  108. * what to use.
  109. *
  110. *
  111. * @return Course
  112. */
  113. function find_specific_course($course_id = 0, $term_id = 0, $bool_transfer = false, $bool_exclude_substitutions = true, Course $use_course = null, $sub_req_by_degree_id = 0)
  114. {
  115. if ($use_course != null && is_object($use_course))
  116. {
  117. $course_id = $use_course->course_id;
  118. $term_id = $use_course->term_id;
  119. $bool_transfer = $use_course->bool_transfer;
  120. }
  121. // Look through the array for a course with this id, termId, and
  122. // transfer credit status.
  123. for ($t = 0; $t < $this->count; $t++)
  124. {
  125. $course = $this->array_list[$t];
  126. $check_course_id = $course->course_id;
  127. if ($bool_transfer == true && is_object($course->course_transfer))
  128. {
  129. $check_course_id = $course->course_transfer->course_id;
  130. }
  131. if ($check_course_id == $course_id && $course->term_id == $term_id && $course->bool_transfer == $bool_transfer)
  132. {
  133. if ($bool_exclude_substitutions == true)
  134. {
  135. if ($course->get_bool_substitution($sub_req_by_degree_id) == TRUE)
  136. {
  137. continue;
  138. }
  139. }
  140. return $course;
  141. }
  142. }
  143. return false;
  144. }
  145. /**
  146. * Call the $course->load_course_descriptive_data() on
  147. * every course in the list.
  148. *
  149. */
  150. function load_course_descriptive_data()
  151. {
  152. // Call the load_descriptive_data() method
  153. // for every course in the list.
  154. for ($t = 0; $t < $this->count; $t++)
  155. {
  156. $course = $this->array_list[$t];
  157. $course->load_descriptive_data();
  158. }
  159. }
  160. /**
  161. * Call the $course->load_descriptive_transfer_data() on
  162. * every course in the list. Meant for transfer courses.
  163. *
  164. */
  165. function load_descriptive_transfer_data($student_id = 0)
  166. {
  167. for ($t = 0; $t < $this->count; $t++)
  168. {
  169. $course = $this->array_list[$t];
  170. $course->load_descriptive_transfer_data($student_id);
  171. }
  172. }
  173. /**
  174. * Using the parent's function of find_all_matches, this
  175. * will return a CourseList of all courses which match
  176. * the Course object.
  177. *
  178. * @param Course $course_c
  179. * @return CourseList
  180. */
  181. function find_all_matches(stdClass $course_c)
  182. {
  183. if (!$list_matches = parent::find_all_matches($course_c))
  184. {
  185. return false;
  186. }
  187. $list_matches = CourseList::cast($list_matches);
  188. return $list_matches;
  189. }
  190. /**
  191. * Returns a match to the Course courseC which does
  192. * not have any courses fulfilling it. Usefull for finding
  193. * course requirement matches in a list which have not
  194. * yet been assigned.
  195. *
  196. * @param Course $course_c
  197. * @return Course
  198. */
  199. function find_first_unfulfilled_match(Course $course_c)
  200. {
  201. // Returns match to courseC which does not have
  202. // any courses fulfilling it. Useful for finding
  203. // course requirement matches in a list which have not
  204. // yet been assigned.
  205. for ($t = 0; $t < $this->count; $t++)
  206. {
  207. if ($this->array_list[$t]->equals($course_c) && $this->array_list[$t]->course_list_fulfilled_by->is_empty == true)
  208. {
  209. return $this->array_list[$t];
  210. }
  211. }
  212. return false;
  213. }
  214. /**
  215. * Go through the list and set the $bool_exclude_repeat flag to TRUE
  216. * for all matches of $course in this list.
  217. *
  218. * Returns FALSE if no matches could be found.
  219. *
  220. * @param Course $course
  221. * @return bool
  222. */
  223. function mark_repeats_exclude(Course $course, $degree_id = 0, Course $except_for_course = NULL)
  224. {
  225. // Set the bool_exclude_repeat flag to TRUE for all
  226. // occurances of $course in THIS list.
  227. if (!$list_matches = parent::find_all_matches($course))
  228. {
  229. return false;
  230. }
  231. $list_matches = CourseList::cast($list_matches);
  232. $list_matches->reset_counter();
  233. while($list_matches->has_more())
  234. {
  235. $c = $list_matches->get_next();
  236. if ($except_for_course != NULL) {
  237. if ($c == $except_for_course) {
  238. // Skip it.
  239. continue;
  240. }
  241. }
  242. $c->set_bool_exclude_repeat($degree_id, TRUE);
  243. }
  244. return true;
  245. }
  246. /**
  247. * Find a list of matches to Course courseC, which fulfill
  248. * the min_grade requirement, ordered by most recently taken.
  249. *
  250. * Returns FALSE if no matches were found, else it will
  251. * return the matched Course object.
  252. *
  253. * @return Course
  254. */
  255. function find_most_recent_match(Course $course_c, $min_grade = "", $bool_mark_repeats_exclude = false, $degree_id = 0, $bool_skip_already_assigned_to_degree = TRUE, $bool_skip_subs = FALSE, $group_id = 0)
  256. {
  257. // Get a list of all matches to courseC, and
  258. // then order them by the most recently taken course
  259. // first.
  260. // We should, too, check for minimum grades here
  261. // as well.
  262. if (!$list_matches = parent::find_all_matches($course_c))
  263. {
  264. return false;
  265. }
  266. $list_matches = CourseList::cast($list_matches);
  267. if ($list_matches->is_empty)
  268. {
  269. return false;
  270. }
  271. // If we are here, then we have at least one match.
  272. // Meaning, we have at least one class which might fit
  273. // into this course requirement.
  274. // Sort the courses into most recently taken first.
  275. $list_matches->sort_most_recent_first();
  276. $withdrew_grades = csv_to_array(variable_get("withdrew_grades", "W"));
  277. // So, now that it's sorted, we should look through the list,
  278. // checking the min grade requirements (if any). When we find
  279. // a good one, we will select it.
  280. $list_matches->reset_counter();
  281. while($list_matches->has_more())
  282. {
  283. $c = $list_matches->get_next();
  284. if ($c->get_bool_exclude_repeat($degree_id, TRUE))
  285. {
  286. continue;
  287. }
  288. if ($bool_skip_subs && $c->get_bool_substitution($degree_id) == TRUE) {
  289. // It is already being used in a substitution for this degree id, so we skip it.
  290. continue;
  291. }
  292. //////////////////////////////////////////
  293. /// Check for min grade, etc, here.
  294. if (!$c->meets_min_grade_requirement_of(null, $min_grade))
  295. {
  296. //if ($min_grade == "B-") fpm("[did not meet min grade requirement of $min_grade :: $c->subject_id $c->course_num $c->grade");
  297. if ($bool_mark_repeats_exclude == true)
  298. {
  299. // Since this course does not meet the min_grade,
  300. // check to see if it may be repeated. If it can't,
  301. // then we must mark ALL previous attempts at this
  302. // course as being excluded from further consideration.
  303. //
  304. // We don't do this consideration if they simply
  305. // withdrew from a course...
  306. if (in_array($c->grade, $withdrew_grades)) { continue; }
  307. if ($c->min_hours < 1 || $c->min_hours == "") {
  308. $c->load_descriptive_data(); // make sure we get hour data for this course.
  309. }
  310. if ($c->repeat_hours <= $c->min_hours)
  311. {
  312. // No repeats.
  313. $this->mark_repeats_exclude($c, $degree_id);
  314. return false;
  315. } else {
  316. // Repeats allowed, so just continue.
  317. continue;
  318. }
  319. } // if bool_mark_repeats_exclude == true
  320. else {
  321. // We did NOT meet the min_grade requirement!
  322. //if ($min_grade == "B-") fpm("[did not meet min grade requirement of $min_grade :: $c->subject_id $c->course_num $c->grade");
  323. $c = FALSE;
  324. continue;
  325. }
  326. } // course did NOT meet the min_grade requirement
  327. else {
  328. // The course DID meet the min grade requirement.
  329. // Are we supposed to exclude repeats?
  330. if ($bool_mark_repeats_exclude) {
  331. // Make sure the course isn't allowed to be repeated...
  332. if ($c->repeat_hours <= $c->min_hours) {
  333. // No repeats allowed.
  334. $this->mark_repeats_exclude($c, $degree_id, $c);
  335. }
  336. }
  337. }
  338. // Has the course already been assigned [to this degree]?
  339. if ($bool_skip_already_assigned_to_degree && $c->get_has_been_assigned_to_degree_id($degree_id)) {
  340. // Yes, it's been assigned, so we can just skip it.
  341. continue;
  342. }
  343. // At this point, we are going to invoke a hook, to give add-on modules
  344. // one last chance to "skip" the course or not.
  345. $bool_can_proceed = TRUE;
  346. $result = invoke_hook("courselist_find_match_allow_course", array($c, $course_c, $list_matches, $degree_id, $group_id));
  347. foreach ($result as $m => $val) {
  348. // If *any* module said FALSE, then we must skip this course and not assign it to this degree.
  349. if ($val === FALSE) $bool_can_proceed = $val;
  350. }
  351. if (!$bool_can_proceed) {
  352. continue;
  353. }
  354. return $c;
  355. }
  356. return FALSE;
  357. }
  358. /**
  359. * Find a list of matches to Course courseC, which fulfill
  360. * the min_grade requirement, ordered by most best grade first.
  361. *
  362. * Returns FALSE if no matches were found, else it will
  363. * return the matched Course object.
  364. *
  365. *
  366. * @return Course
  367. */
  368. function find_best_grade_match(Course $course_c, $min_grade = "", $bool_mark_repeats_exclude = false, $degree_id = 0, $bool_skip_already_assigned_to_degree = TRUE, $bool_skip_subs = FALSE, $group_id = 0)
  369. {
  370. $list_matches = parent::find_all_matches($course_c);
  371. if (!$list_matches) {
  372. return false;
  373. }
  374. $list_matches = CourseList::cast($list_matches);
  375. //sort the courses into largest hours first, so equal grades will be sorted by hours
  376. $list_matches->sort_largest_hours_first();
  377. // Sort the courses into best grade first.
  378. $list_matches->sort_best_grade_first();
  379. if (!$list_matches || $list_matches->is_empty)
  380. {
  381. return false;
  382. }
  383. // If we are here, then we have more than one match.
  384. // Meaning, we have more than one class which might fit
  385. // into this course requirement.
  386. $withdrew_grades = csv_to_array(variable_get("withdrew_grades", "W"));
  387. // So, now that it's sorted, we should look through the list,
  388. // checking the min grade requirements (if any). When we find
  389. // a good one, we will select it.
  390. $list_matches->reset_counter();
  391. while($list_matches->has_more())
  392. {
  393. $c = $list_matches->get_next();
  394. if ($c->get_bool_exclude_repeat($degree_id) == TRUE)
  395. {
  396. continue;
  397. }
  398. // Has the course already been assigned [to this degree]?
  399. if ($bool_skip_already_assigned_to_degree && $c->get_has_been_assigned_to_degree_id($degree_id)) {
  400. // Yes, it's been assigned, so we can just skip it.
  401. continue;
  402. }
  403. if ($bool_skip_subs && $c->get_bool_substitution($degree_id) == TRUE) {
  404. // It is already being used in a substitution for this degree id, so we skip it.
  405. continue;
  406. }
  407. //////////////////////////////////////////
  408. /// Check for min grade, etc, here.
  409. if (!$c->meets_min_grade_requirement_of(null, $min_grade))
  410. {
  411. if ($bool_mark_repeats_exclude == true)
  412. {
  413. // Since this course does not meet the min_grade,
  414. // check to see if it may be repeated. If it can't,
  415. // then we must mark ALL previous attempts at this
  416. // course as being excluded from further consideration.
  417. // (ULM policy on repeats).
  418. // We don't do this consideration if they simply
  419. // withdrew from a course...
  420. if (in_array($c->grade, $withdrew_grades)) { continue; }
  421. if ($c->min_hours < 1 || $c->min_hours == "") {
  422. $c->load_descriptive_data(); // make sure we get hour data for this course.
  423. }
  424. if ($c->repeat_hours <= $c->min_hours)
  425. {
  426. // No repeats.
  427. $this->mark_repeats_exclude($c, $degree_id);
  428. return false;
  429. } else {
  430. // Repeats allowed, so just continue.
  431. continue;
  432. }
  433. } // if bool_mark_repeats_exclude == true
  434. else {
  435. // We did NOT meet the min_grade requirement!
  436. $c = FALSE;
  437. continue;
  438. }
  439. } // course did NOT meet the min_grade requirement
  440. else {
  441. // The course DID meet the min grade requirement.
  442. // Are we supposed to exclude repeats?
  443. if ($bool_mark_repeats_exclude) {
  444. // Make sure the course isn't allowed to be repeated...
  445. if ($c->repeat_hours <= $c->min_hours) {
  446. // No repeats allowed.
  447. $this->mark_repeats_exclude($c, $degree_id, $c);
  448. }
  449. }
  450. }
  451. // At this point, we are going to invoke a hook, to give add-on modules
  452. // one last chance to "skip" the course or not.
  453. $bool_can_proceed = TRUE;
  454. $result = invoke_hook("courselist_find_match_allow_course", array($c, $course_c, $list_matches, $degree_id, $group_id));
  455. foreach ($result as $m => $val) {
  456. // If *any* module said FALSE, then we must skip this course and not assign it to this degree.
  457. if ($val === FALSE) $bool_can_proceed = $val;
  458. }
  459. if (!$bool_can_proceed) {
  460. continue;
  461. }
  462. return $c;
  463. } // while
  464. return FALSE;
  465. } // find_best_grade_match
  466. /**
  467. * Sorts best-grade-first, as defined by the setting "grade_order", which is a CSV of
  468. * grades, best-first. Ex: A, B, C, D, F
  469. *
  470. * If the student object is set to a student, we will use that's student's best grade for a course, rather
  471. * than the actual course's grade. Generally, this can be left as set to null. This is only for when we are
  472. * trying to organize a list of courses into the grade order, based on what a student has taken. For example, if we want
  473. * to order a Group's list of courses based on what the student has taken and the grades they made.
  474. *
  475. */
  476. function sort_best_grade_first(Student $student = NULL) {
  477. $temp = csv_to_array(variable_get("grade_order", "AMID,BMID,CMID,DMID,FMID,A,B,C,D,F,W,I"));
  478. // We will use array_flip to get back an assoc array where the grades are the keys and the indexes are the values.
  479. $temp = array_flip($temp);
  480. // Go through the grades and convert the integers to strings, padd with zeros so that everything is at least 3 digits.
  481. $grades = array();
  482. foreach ($temp as $grade => $val) {
  483. $grades[$grade] = str_pad((string)$val, 3, "0", STR_PAD_LEFT);
  484. }
  485. // We now have our grades array just how we want it. Best grade has lowest value. Worst grade has highest value.
  486. $unknown_grade_value = 999; // sort to the very end, in other words.
  487. $student_grade_score = 0;
  488. // We are going to go through our courses and, based on the grade, assign them a value.
  489. $tarray = array();
  490. for ($t = 0; $t < $this->count; $t++) {
  491. // $t is the index for the array_list, keep in mind.
  492. $c = $this->array_list[$t];
  493. $use_grade = $c->grade;
  494. if ($student != null) {
  495. $use_grade = $student->get_best_grade_for_course($c);
  496. if (!$use_grade) $use_grade = "";
  497. }
  498. @$grade_value = $grades[$use_grade];
  499. if ($grade_value == "") {
  500. // Couldn't find this grade in our array, so give it the unknown value.
  501. $grade_value = $unknown_grade_value;
  502. }
  503. $student_grade_score += intval($grade_value);
  504. // Add to a string in array so we can sort easily using a normal sort operation.
  505. $tarray[$grade_value][] = $c;
  506. }
  507. // Sort best-grade-first:
  508. ksort($tarray,SORT_NUMERIC);
  509. // Okay, now go back through tarray and re-construct a new CourseList
  510. $new_list = new CourseList();
  511. foreach ($tarray as $per_grade_courses) {
  512. foreach ($per_grade_courses as $course) {
  513. $new_list->add($course);
  514. }
  515. }
  516. // Okay, now $new_list should contain the correct values.
  517. // We will transfer over the reference.
  518. $this->array_list = $new_list->array_list;
  519. // And we are done!
  520. if ($student != NULL) {
  521. // Return the "student grade score" for this list of courses.
  522. return $student_grade_score;
  523. }
  524. }
  525. /**
  526. * This is the original sort_best_grade_first method, replaced by the new one (modified by Logan Buth) on 3-29-2018)
  527. */
  528. function z____sort_best_grade_first(Student $student = NULL) {
  529. $temp = csv_to_array(variable_get("grade_order", "AMID,BMID,CMID,DMID,FMID,A,B,C,D,F,W,I"));
  530. // We will use array_flip to get back an assoc array where the grades are the keys and the indexes are the values.
  531. $temp = array_flip($temp);
  532. // Go through the grades and convert the integers to strings, padd with zeros so that everything is at least 3 digits.
  533. $grades = array();
  534. foreach ($temp as $grade => $val) {
  535. $grades[$grade] = str_pad((string)$val, 3, "0", STR_PAD_LEFT);
  536. }
  537. // We now have our grades array just how we want it. Best grade has lowest value. Worst grade has highest value.
  538. $unknown_grade_value = "999"; // sort to the very end, in other words.
  539. $student_grade_score = 0;
  540. // We are going to go through our courses and, based on the grade, assign them a value.
  541. $tarray = array();
  542. for ($t = 0; $t < $this->count; $t++) {
  543. // $t is the index for the array_list, keep in mind.
  544. $c = $this->array_list[$t];
  545. $use_grade = $c->grade;
  546. if ($student != null) {
  547. $use_grade = $student->get_best_grade_for_course($c);
  548. if (!$use_grade) $use_grade = "";
  549. }
  550. @$grade_value = $grades[$use_grade];
  551. if ($grade_value == "") {
  552. // Couldn't find this grade in our array, so give it the unknown value.
  553. $grade_value = $unknown_grade_value;
  554. }
  555. $student_grade_score += intval($grade_value);
  556. // Add to a string in array so we can sort easily using a normal sort operation.
  557. $tarray[] = "$grade_value ~~ $t";
  558. }
  559. // Sort best-grade-first:
  560. sort($tarray);
  561. // Okay, now go back through tarray and re-construct a new CourseList
  562. $new_list = new CourseList();
  563. for($t = 0; $t < count($tarray); $t++)
  564. {
  565. $temp = explode(" ~~ ",$tarray[$t]);
  566. $i = $temp[1];
  567. $new_list->add($this->array_list[$i]);
  568. }
  569. // Okay, now $new_list should contain the correct values.
  570. // We will transfer over the reference.
  571. $this->array_list = $new_list->array_list;
  572. // And we are done!
  573. if ($student != NULL) {
  574. // Return the "student grade score" for this list of courses.
  575. return $student_grade_score;
  576. }
  577. }
  578. /**
  579. * Remove courses from THIS list which appear in listCourses under
  580. * these conditions:
  581. * - the listCourses->"assigned_to_group_id" != $group_id
  582. * This function is being used primarily with $list_courses being the
  583. * list of courses that students have taken.
  584. * Also checking substitutions for courses substituted into groups.
  585. * @param CourseList $list_courses
  586. * @param int $group_id
  587. * @param bool $bool_keep_repeatable_courses
  588. * @param SubstitutionList $list_substitutions
  589. * @param $degree_id The degree id to look for. If it's -1, then ignore it. If it's 0, use the course's req_by_degree_id.
  590. */
  591. function remove_previously_fulfilled(CourseList $list_courses, $group_id, $bool_keep_repeatable_courses = true, $list_substitutions, $degree_id = 0)
  592. {
  593. $rtn_list = new CourseList();
  594. for ($t = 0; $t < $this->count; $t++)
  595. {
  596. $course = $this->array_list[$t];
  597. if ($bool_keep_repeatable_courses == true)
  598. { // We can always keep repeatable courses in the list.
  599. if ($course->repeat_hours > $course->min_hours)
  600. {
  601. $rtn_list->add($course);
  602. continue;
  603. }
  604. }
  605. // Has the course been substituted?
  606. if ($test_sub = $list_substitutions->find_requirement($course, false, -1))
  607. {
  608. // it WAS substituted, so we should NOT add it to our
  609. // rtnList.
  610. // We should only skip it if the test_sub's degree_id matches the one supplied...
  611. if ($degree_id >= 0) {
  612. if ($test_sub->assigned_to_degree_id == $degree_id) {
  613. continue;
  614. }
  615. }
  616. else if ($degree_id < 0) {
  617. // degree_id is -1, so we don't care what degree it was assigned to.
  618. continue;
  619. }
  620. }
  621. // Okay, now check if $course is anywhere in $list_courses
  622. //if ($test_course = $list_courses->find_match($course))
  623. // Instead of using simply find_match(), which does not allow for any hook interventions, switch to using find_best_match.
  624. // Thanks for Logan Buth for this.
  625. if ($test_course = $list_courses->find_best_match($course, '', FALSE, $degree_id, TRUE, FALSE, $group_id))
  626. {
  627. // Yes, it found a match.
  628. // I am taking out this part where I say if it is in
  629. // this group then we can keep it. I think that shouldn't
  630. // be in.
  631. // This course is in another group, so do nothing
  632. // and skip it.
  633. // perhaps the course is on the degreePlan in excess with a W
  634. // or F?
  635. if (!$test_course->meets_min_grade_requirement_of(null, "D"))
  636. {
  637. // Meaning, this was a failed attempt, so we can add
  638. // our original course back in.
  639. $rtn_list->add($course);
  640. continue;
  641. }
  642. // perhaps this course was purposefully excluded from
  643. // this list because it did not meet the min grade
  644. // requirements? If this is the case, $course should
  645. // still appear in THIS list.
  646. if (!$test_course->meets_min_grade_requirement_of($course))
  647. {
  648. // Meaning, this was attempt did not meet the
  649. // min grade of the original requirement, so we can add
  650. // our original requirement back in.
  651. $rtn_list->add($course);
  652. continue;
  653. }
  654. } else {
  655. // The course was NOT found in the courseList,
  656. // so its safe to add it back in.
  657. $rtn_list->add($course);
  658. }
  659. }
  660. $this->array_list = $rtn_list->array_list;
  661. $this->reset_counter();
  662. }
  663. /**
  664. * Return an array of all the course_id's in this course_list.
  665. */
  666. function get_course_id_array() {
  667. $rtn = array();
  668. for ($t = 0; $t < $this->count; $t++)
  669. {
  670. $course = $this->array_list[$t];
  671. $rtn[$course->course_id] = TRUE;
  672. }
  673. return $rtn;
  674. }
  675. /**
  676. * Returns an array containing the unique subject_id's of
  677. * the courses in this list. Its assumed to be ordered
  678. * already!
  679. *
  680. * @param bool $bool_ignore_excluded
  681. * @return array
  682. */
  683. function get_course_subjects($bool_ignore_excluded = true)
  684. {
  685. // returns an array containing the unique subject_id's
  686. // of the courses in this list.
  687. // IMPORTANT: The list is assumed to be ordered already! Either
  688. // alphabetically or reverse alphabetically.
  689. $old_subject_id = "";
  690. $rtn_array = array();
  691. for ($t = 0; $t < $this->count; $t++)
  692. {
  693. $course = $this->array_list[$t];
  694. if ($course->subject_id == "")
  695. {
  696. $course->load_descriptive_data();
  697. }
  698. // Go through all valid names for this course.
  699. for ($x = 0; $x < count($course->array_valid_names); $x++)
  700. {
  701. $temp = explode("~",$course->array_valid_names[$x]);
  702. $subj = strtoupper($temp[0]);
  703. if (in_array($subj, $rtn_array))
  704. { // skip ones with subjects we have already looked at.
  705. continue;
  706. }
  707. if ($course->db_exclude == 1)
  708. {
  709. continue;
  710. }
  711. // We have a new subject. Add it to the array.
  712. $rtn_array[] = $subj;
  713. }
  714. }
  715. return $rtn_array;
  716. }
  717. /**
  718. * Go through the courseList and take out any course
  719. * which does not have the $subject as its subject_id.
  720. *
  721. * @param string $subject
  722. * @param bool $bool_reassign_valid_name
  723. * - If set to TRUE, we will look at other possible valid names
  724. * for this course. If we find one, we will reassign the course's
  725. * subject_id and course_num to the new valid name.
  726. *
  727. */
  728. function exclude_all_subjects_except($subject, $bool_reassign_valid_name = true)
  729. {
  730. $new_course_list = new CourseList();
  731. for ($t = 0; $t < $this->count; $t++)
  732. {
  733. $course = $this->array_list[$t];
  734. if ($course->subject_id == $subject)
  735. {
  736. $new_course_list->add($course);
  737. continue;
  738. }
  739. // Not the right subject-- but perhaps the course has another
  740. // valid name with this subject? Ex: CSCI 373 and MATH 373.
  741. if ($bool_reassign_valid_name == true && count($course->array_valid_names) > 1)
  742. {
  743. for ($x = 0; $x < count($course->array_valid_names); $x++)
  744. {
  745. if (strstr($course->array_valid_names[$x], $subject))
  746. {
  747. $temp = explode("~",$course->array_valid_names[$x]);
  748. $course->subject_id = $temp[0];
  749. $course->course_num = $temp[1];
  750. $new_course_list->add($course);
  751. continue;
  752. }
  753. }
  754. }
  755. }
  756. // Now, transfer ownership of the arraylist.
  757. $this->array_list = $new_course_list->array_list;
  758. }
  759. /**
  760. * This re-sorts the CourseList so that fulfilled courses
  761. * are first, in alphabetical order, followed by
  762. * unfulfilled courses, in alphabetical order.
  763. * This is most useful for making the groups
  764. * show up correctly.
  765. *
  766. */
  767. function sort_fulfilled_first_alphabetical()
  768. {
  769. $tarray = array();
  770. for ($t = 0; $t < $this->count; $t++)
  771. {
  772. //if (!is_object($this->array_list[$t]->courseFulfilledBy))
  773. if ($this->array_list[$t]->course_list_fulfilled_by->is_empty == true)
  774. { // Skip if not fulfilled.
  775. continue;
  776. }
  777. $c = $this->array_list[$t];
  778. $str = "$c->subject_id ~~ $c->course_num ~~ $t";
  779. array_push($tarray,$str);
  780. }
  781. sort($tarray);
  782. $new_list = new CourseList();
  783. for($t = 0; $t < count($tarray); $t++)
  784. {
  785. $temp = explode(" ~~ ",$tarray[$t]);
  786. $i = $temp[2];
  787. $new_list->add($this->array_list[$i]);
  788. }
  789. // Alright, now we do it again, but with unfulfilled courses.
  790. $tarray = array();
  791. for ($t = 0; $t < $this->count; $t++)
  792. {
  793. //if (is_object($this->array_list[$t]->courseFulfilledBy))
  794. if ($this->array_list[$t]->course_list_fulfilled_by->is_empty != true)
  795. { // Skip if fulfilled.
  796. continue;
  797. }
  798. $c = $this->array_list[$t];
  799. $str = "$c->subject_id ~~ $c->course_num ~~ $t";
  800. array_push($tarray,$str);
  801. }
  802. sort($tarray);
  803. $new_list2 = new CourseList();
  804. for($t = 0; $t < count($tarray); $t++)
  805. {
  806. $temp = explode(" ~~ ",$tarray[$t]);
  807. $i = $temp[2];
  808. $new_list2->add($this->array_list[$i]);
  809. }
  810. // Now, combine the two lists.
  811. $new_list->add_list($new_list2);
  812. // And, transfer the newList into this list.
  813. $this->array_list = $new_list->array_list;
  814. }
  815. /**
  816. * This re-sorts the CourseList so that advised courses
  817. * are last, in alphabetical order, preceeded by
  818. * unfulfilled courses, in alphabetical order.
  819. *
  820. *
  821. */
  822. function sort_advised_last_alphabetical()
  823. {
  824. $tarray = array();
  825. for ($t = 0; $t < $this->count; $t++)
  826. {
  827. if ($this->array_list[$t]->bool_advised_to_take == true)
  828. { // Skip if not fulfilled.
  829. continue;
  830. }
  831. $c = $this->array_list[$t];
  832. $str = "$c->subject_id ~~ $c->course_num ~~ $t";
  833. array_push($tarray,$str);
  834. }
  835. sort($tarray);
  836. // Alright, now we do it again, but with advised courses.
  837. $t2array = array();
  838. for ($t = 0; $t < $this->count; $t++)
  839. {
  840. if ($this->array_list[$t]->bool_advised_to_take == false)
  841. { // Skip if not advised
  842. continue;
  843. }
  844. $c = $this->array_list[$t];
  845. $str = "$c->subject_id ~~ $c->course_num ~~ $t";
  846. array_push($t2array,$str);
  847. }
  848. sort($t2array);
  849. $t3array = array_merge($tarray, $t2array);
  850. $new_list = new CourseList();
  851. for($t = 0; $t < count($t3array); $t++)
  852. {
  853. $temp = explode(" ~~ ",$t3array[$t]);
  854. $i = $temp[2];
  855. $new_list->add($this->array_list[$i]);
  856. }
  857. // And, transfer the newList into this list.
  858. $this->array_list = $new_list->array_list;
  859. }
  860. /**
  861. * This function will resort this courselist for which a substitution
  862. * has been made in listSubstitutions.
  863. *
  864. * @param SubstitutionList $list_substitutions
  865. * @param int $group_id
  866. */
  867. function sort_substitutions_first($list_substitutions, $group_id = 0)
  868. {
  869. // This will sort courses in a list for which
  870. // a substitution has been made in listSubstitutions.
  871. // It will place those courses at the top of the list.
  872. $top_array = array();
  873. // Since I need the indexes, I will have to go through the array
  874. // myself...
  875. // array to keep track of all the substitutions that have been used for this list (Logan's change ticket 2291)
  876. $used_substitution_ids = array();
  877. for ($t = 0; $t < $this->count; $t++) {
  878. $c = $this->array_list[$t];
  879. // So-- does this course have a substitution somewhere in
  880. // the list (for the supplied groupID) ?
  881. // supply the list of used ids, so they are not reused in this list. (Logan's change ticket 2291)
  882. if ($substitution = $list_substitutions->find_requirement($c, true, $group_id,0,$used_substitution_ids))
  883. {
  884. // yes, there is a sub for this group (or bare degree plan)
  885. //mark the substitution so it doesn't get used again (Logan's change ticket 2291)
  886. $used_substitution_ids[] = $substitution->db_substitution_id;
  887. $top_array[] = $t;
  888. }
  889. }
  890. // Okay, we now have, in the topArray, a list of indexes which should
  891. // appear at the top.
  892. $new_list = new CourseList();
  893. for ($j = 0; $j < count($top_array); $j++)
  894. {
  895. $new_list->add($this->array_list[$top_array[$j]]);
  896. }
  897. // Now, add everything else in the array (except indecies
  898. // appearing in topArray)
  899. for ($t = 0; $t < $this->count; $t++)
  900. {
  901. if (in_array($t, $top_array))
  902. {
  903. continue;
  904. }
  905. $new_list->add($this->array_list[$t]);
  906. }
  907. $this->array_list = $new_list->array_list;
  908. $new_list->reset_counter();
  909. }
  910. /**
  911. * This will sort so that courses with the smallest hours
  912. * (first trying hours_awarded, then min_hours)
  913. * are at the top of the list. If the list contains more
  914. * than one course with a set of hours (like there are 30
  915. * courses all worth 3 hours) then it orders those as
  916. * most-recently-taken first.
  917. *
  918. */
  919. function sort_smallest_hours_first()
  920. {
  921. $tarray = array();
  922. // Since I need the indexes, I will have to go through the array
  923. // myself...
  924. for ($t = 0; $t < $this->count; $t++)
  925. {
  926. $c = $this->array_list[$t];
  927. $hours = $c->get_hours_awarded();
  928. if ($hours < 1)
  929. {
  930. $hours = $c->min_hours*1;
  931. }
  932. $str = "$hours ~~ $t";
  933. array_push($tarray,$str);
  934. }
  935. // Now, sort the array...
  936. //print_pre(print_r($tarray));
  937. sort($tarray);
  938. //print_pre(print_r($tarray));
  939. // Now, convert the array back into a list of courses.
  940. $new_list = new CourseList();
  941. for($t = 0; $t < count($tarray); $t++)
  942. {
  943. $temp = explode(" ~~ ",$tarray[$t]);
  944. $i = $temp[1];
  945. $new_list->add($this->array_list[$i]);
  946. }
  947. // Okay, now $new_list should contain the correct values.
  948. // We will transfer over the reference.
  949. $this->array_list = $new_list->array_list;
  950. } // sort_smallest_hours_first
  951. /*
  952. * Sort the courses of this list by number of hours descending.
  953. * Order of courses with the same number of hours is preserved.
  954. */
  955. function sort_largest_hours_first() {
  956. $sort_list = array();
  957. // go through the courses, creating an array keyed by hours.
  958. for ($t = 0; $t < count($this->array_list); $t++) {
  959. $hrs = $this->array_list[$t]->get_hours();
  960. if ($this->array_list[$t]->bool_ghost_hour) $hrs = 0;
  961. $sort_list[$hrs][] = $this->array_list[$t];
  962. }
  963. //sort the array in order of hours descending
  964. krsort($sort_list,SORT_NUMERIC);
  965. //clear the internal array, then refill it with the now sorted courses.
  966. $this->array_list = array();
  967. foreach ($sort_list as $courses) {
  968. foreach ($courses as $course) {
  969. $this->array_list[] = $course;
  970. }
  971. }
  972. $this->reset_counter();
  973. }
  974. /**
  975. * This method will sort by the most recently taken
  976. * courses (determined by the term_id).
  977. * The easiest way I can think to do this is to temporarily
  978. * put their term_id's and index#'s into an array, and then
  979. * have PHP sort the array itself. PHP's sorting algorithm
  980. * is faster than anything I can program right now, anyway.
  981. *
  982. * @param bool $bool_maintain_alpha_order
  983. */
  984. function sort_most_recent_first($bool_maintain_alpha_order = true)
  985. {
  986. $tarray = array();
  987. // Since I need the indexes, I will have to go through the array
  988. // myself...
  989. for ($t = 0; $t < $this->count; $t++)
  990. {
  991. $c = $this->array_list[$t];
  992. $cn = "";
  993. if ($bool_maintain_alpha_order == true)
  994. {
  995. // We say 1000- the course number in order to give
  996. // us the complement of the number. That is so it will
  997. // reverse-sort in the correct order. Strange, but it fixes
  998. // a small display issue where PHYS 207 and PHYS 209, taken at
  999. // the same time, causes PHYS 209 to be displayed first.
  1000. // We also reverse the subject_id, again, so that
  1001. // MATH will be sorted above ZOOL, when taken at the same time.
  1002. // This might not work at all, though...
  1003. $cn = strrev($c->subject_id) . "," . (1000 - $c->course_num);
  1004. }
  1005. $str = "$c->term_id ~~ $cn ~~ $t";
  1006. array_push($tarray,$str);
  1007. }
  1008. // Now, sort the array...
  1009. rsort($tarray);
  1010. // Now, convert the array back into a list of courses.
  1011. $new_list = new CourseList();
  1012. for($t = 0; $t < count($tarray); $t++)
  1013. {
  1014. $temp = explode(" ~~ ",$tarray[$t]);
  1015. $i = $temp[2];
  1016. $new_list->add($this->array_list[$i]);
  1017. }
  1018. // Okay, now $new_list should contain the correct values.
  1019. // We will transfer over the reference.
  1020. $this->array_list = $new_list->array_list;
  1021. }
  1022. /**
  1023. * Convienence function. It simply calls sort_alphabetical_order(), but
  1024. * passes the boolean value to make it be reversed.
  1025. *
  1026. */
  1027. function sort_reverse_alphabetical_order()
  1028. {
  1029. $this->sort_alphabetical_order(true);
  1030. }
  1031. /**
  1032. * Sorts the course list into alphabetical order. If load_descriptive_data()
  1033. * has not already been called for each course, it will call it.
  1034. *
  1035. * @param bool $bool_reverse_order
  1036. * - If set to TRUE, the list will be in reverse order.
  1037. *
  1038. * @param unknown_type $bool_only_transfers
  1039. * - Only sort the transfer courses.
  1040. *
  1041. * @param unknown_type $bool_set_array_index
  1042. * - If set to true, it will set the $course->array_index value
  1043. * to the index value in $this's array_list array.
  1044. * @param new_split_subs_higher_priority_in_degree_id
  1045. * - If the course is a split substitution for the supplied degree_id, then give it a higher "priority" so it will
  1046. * sort above courses with identical names.
  1047. *
  1048. */
  1049. function sort_alphabetical_order($bool_reverse_order = false, $bool_only_transfers = false, $bool_set_array_index = false, $subs_higher_prority_in_degree_id = 0, $bool_include_degree_sort = FALSE)
  1050. {
  1051. // Sort the list into alphabetical order, based
  1052. // on the subject_id and course_num.
  1053. $tarray = array();
  1054. // Since I need the indexes, I will have to go through the array
  1055. // myself...
  1056. for ($t = 0; $t < $this->count; $t++)
  1057. {
  1058. $c = $this->array_list[$t];
  1059. if ($c->subject_id == "")
  1060. {
  1061. $c->load_descriptive_data();
  1062. }
  1063. $priority = 5; // default sort priority for courses with identical names.
  1064. if ($subs_higher_prority_in_degree_id > 0) {
  1065. if (@$c->details_by_degree_array[$subs_higher_prority_in_degree_id]["bool_substitution_new_from_split"] == TRUE
  1066. || @$c->details_by_degree_array[$subs_higher_prority_in_degree_id]["bool_substitution_split"] == TRUE
  1067. || @$c->details_by_degree_array[$subs_higher_prority_in_degree_id]["bool_substitution"] == TRUE) {
  1068. //fpm("here for $c->subject_id $c->course_num");
  1069. $priority = 3; // lower priority so it sorts higher in the list.
  1070. }
  1071. }
  1072. // Make $t at least 5 characters long, padded with zeroes on the left, so sorting works correctly. We are using it to
  1073. // find out our index later, but it is throwing off the sorting when courses have the same name. For example,
  1074. // if a course is from a split sub.
  1075. $tpad = str_pad("$t",5,"0",STR_PAD_LEFT);
  1076. $degree_title = "n"; // Default.
  1077. $degree_advising_weight = "0000";
  1078. if ($bool_include_degree_sort) {
  1079. // Find the actual degree title for this course.
  1080. if (intval($c->req_by_degree_id) > 0) {
  1081. // Get the degree title...
  1082. $dtitle = @$GLOBALS["fp_temp_degree_titles"][$c->req_by_degree_id];
  1083. $dweight = intval(@$GLOBALS["fp_temp_degree_advising_weights"][$c->req_by_degree_id]);
  1084. if ($dtitle == "" || $dweight == "" || $dweight == 0) {
  1085. $t_degree_plan = new DegreePlan($c->req_by_degree_id);
  1086. $t_degree_plan->load_descriptive_data();
  1087. $dtitle = $t_degree_plan->get_title2(TRUE, TRUE);
  1088. $dweight = $t_degree_plan->db_advising_weight;
  1089. $GLOBALS["fp_temp_degree_titles"][$c->req_by_degree_id] = $dtitle . " "; //save for next time.
  1090. $GLOBALS["fp_temp_degree_advising_weights"][$c->req_by_degree_id] = $dweight . " "; //save for next time.
  1091. }
  1092. $degree_title = fp_get_machine_readable($dtitle); // make it machine readable. No funny characters.
  1093. $degree_advising_weight = str_pad($dweight, 4, "0", STR_PAD_LEFT);
  1094. }
  1095. }
  1096. if ($bool_only_transfers == true)
  1097. {
  1098. // Rarer. We only want to sort the transfer credits. If the course doesn not
  1099. // have transfers, don't skip, just put in the original. Otherwise, we will be using
  1100. // the transfer credit's SI and CN.
  1101. if (is_object($c->course_transfer))
  1102. {
  1103. $str = $degree_advising_weight . " ~~ " . $degree_title . " ~~ " . $c->course_transfer->subject_id . " ~~ " . $c->course_transfer->course_num ." ~~ $priority ~~ $tpad";
  1104. } else {
  1105. // There was no transfer!
  1106. $str = "$degree_advising_weight ~~ $degree_title ~~ $c->subject_id ~~ $c->course_num ~~ $priority ~~ $tpad";
  1107. }
  1108. } else {
  1109. // This is the one which will be run most often. Just sort the list
  1110. // in alphabetical order.
  1111. $str = "$degree_advising_weight ~~ $degree_title ~~ $c->subject_id ~~ $c->course_num ~~ $priority ~~ $tpad";
  1112. }
  1113. array_push($tarray,$str);
  1114. }
  1115. // Now, sort the array...
  1116. //print_pre(print_r($tarray));
  1117. if ($bool_reverse_order == true)
  1118. {
  1119. rsort($tarray);
  1120. } else {
  1121. sort($tarray);
  1122. }
  1123. //print_pre(print_r($tarray));
  1124. // Now, convert the array back into a list of courses.
  1125. $new_list = new CourseList();
  1126. for($t = 0; $t < count($tarray); $t++)
  1127. {
  1128. $temp = explode(" ~~ ",$tarray[$t]);
  1129. $i = intval($temp[5]);
  1130. if ($bool_set_array_index == true)
  1131. {
  1132. $this->array_list[$i]->array_index = $i;
  1133. }
  1134. $new_list->add($this->array_list[$i]);
  1135. }
  1136. // Okay, now $new_list should contain the correct values.
  1137. // We will transfer over the reference.
  1138. $this->array_list = $new_list->array_list;
  1139. }
  1140. /**
  1141. * Returns an array of db_group_requirement_id's from the courses
  1142. * in this list.
  1143. *
  1144. * @return array
  1145. */
  1146. function get_group_requirement_id_array()
  1147. {
  1148. // Return an array of db_group_requirement_id's
  1149. // from the courses in this list, indexed by the
  1150. // id's.
  1151. $rtn_array = array();
  1152. for ($t = 0; $t < $this->count; $t++)
  1153. {
  1154. $course = $this->array_list[$t];
  1155. $rtn_array[$course->db_group_requirement_id] = true;
  1156. }
  1157. return $rtn_array;
  1158. }
  1159. /**
  1160. * Returns TRUE if this list has a course which contains
  1161. * $id for it's db_group_requirement_id property.
  1162. *
  1163. * @param int $id
  1164. * - This is the id to test for.
  1165. *
  1166. * @return bool
  1167. */
  1168. function contains_group_requirement_id($id)
  1169. {
  1170. // Returns true if the list has a course
  1171. // which contains $id for it's db_group_requirement_id.
  1172. // False if it cannot be found.
  1173. for ($t = 0; $t < $this->count; $t++)
  1174. {
  1175. $course = $this->array_list[$t];
  1176. if ($course->db_group_requirement_id == $id)
  1177. {
  1178. return true;
  1179. }
  1180. }
  1181. return false;
  1182. }
  1183. /**
  1184. * Returns the first course in the list
  1185. * which the user may select for advising. This
  1186. * method is used by the popup window to determine
  1187. * what exactly is the first element of the course list.
  1188. * (so it can make that radio button checked).
  1189. *
  1190. * Returns FALSE if it cannot find a selectable course.
  1191. *
  1192. * @return Course
  1193. */
  1194. function find_first_selectable()
  1195. {
  1196. /*
  1197. */
  1198. $temp_i = $this->i; // preserve the counter.
  1199. $this->reset_counter();
  1200. while($this->has_more())
  1201. {
  1202. $c = $this->get_next();
  1203. if ($c->bool_advised_to_take == true)
  1204. {
  1205. continue;
  1206. }
  1207. if (!$c->course_list_fulfilled_by->is_empty)
  1208. {
  1209. continue;
  1210. }
  1211. if ($c->bool_unselectable == true)
  1212. {
  1213. continue;
  1214. }
  1215. // $c is our valid course...
  1216. $this->i = $temp_i;
  1217. //print_pre($c->to_string());
  1218. return $c;
  1219. }
  1220. $this->i = $temp_i;
  1221. return false;
  1222. }
  1223. /**
  1224. * Returns TRUE if there is at least one course in this list which
  1225. * is selected (for advising).
  1226. *
  1227. * @return bool
  1228. */
  1229. function has_any_course_selected()
  1230. {
  1231. /*
  1232. Returns TRUE if there is at least one course
  1233. in this list which is "selected." FALSE, otherwise.
  1234. */
  1235. $temp_i = $this->i; // preserve the counter.
  1236. $this->reset_counter();
  1237. $rtn = false;
  1238. while($this->has_more())
  1239. {
  1240. $c = $this->get_next();
  1241. if ($c->bool_selected == true)
  1242. {
  1243. $rtn = true;
  1244. break;
  1245. }
  1246. }
  1247. $this->i = $temp_i;
  1248. return $rtn;
  1249. }
  1250. /**
  1251. * Mark every course in this list as bool_has_been_displayed = true.
  1252. * Used for making sure we don't display the same course twice on
  1253. * screen.
  1254. *
  1255. * Returns FALSE if we did not mark any courses.
  1256. *
  1257. * @param int $semester_num
  1258. * - If > -1, we will first make sure the course
  1259. * falls into this semesterNum. This way we can only
  1260. * perform this operation on a particular semester.
  1261. *
  1262. * @return bool
  1263. */
  1264. function mark_as_displayed($semester_num = -1)
  1265. {
  1266. $temp_i = $this->i; // preserve the counter.
  1267. $this->reset_counter();
  1268. $rtn = false;
  1269. while($this->has_more())
  1270. {
  1271. $c = $this->get_next();
  1272. if ($semester_num != -1)
  1273. { // A semesterNum was specified.
  1274. // Make sure the course is in the correct semester.
  1275. if ($c->assigned_to_semester_num != $semester_num)
  1276. {
  1277. continue;
  1278. }
  1279. }
  1280. $c->bool_has_been_displayed = true;
  1281. $rtn = true;
  1282. }
  1283. $this->i = $temp_i;
  1284. return $rtn;
  1285. }
  1286. /**
  1287. * Returns a CourseList of all the courses matching course_id
  1288. * that has bool_has_been_assigned == TRUE for the requested degree
  1289. *
  1290. * @param int $course_id
  1291. * @return CourseList
  1292. */
  1293. function get_previous_assignments($course_id, $degree_id = 0)
  1294. {
  1295. // Return a courseList of all the times a course matching
  1296. // course_id has the bool_has_been_assigned set to TRUE.
  1297. $rtn_list = new CourseList();
  1298. for ($t = 0; $t < $this->count; $t++)
  1299. {
  1300. $course = $this->array_list[$t];
  1301. if ($course->course_id == $course_id && $course->get_has_been_assigned_to_degree_id($degree_id) == true)
  1302. {
  1303. $rtn_list->add($course);
  1304. }
  1305. }
  1306. return $rtn_list;
  1307. }
  1308. /**
  1309. * Find the "best" match for this course, based on what
  1310. * the university considers a best match.
  1311. * This largely has to do with repeats.
  1312. * If the student has more than one credit, what is
  1313. * the "best" match?
  1314. *
  1315. * For example, at ULM we consider the best match to be the
  1316. * most recent that meets the minimum requirements.
  1317. * Other schools might simply take the best grade.
  1318. *
  1319. *
  1320. * @return Course
  1321. */
  1322. function find_best_match(Course $course_c, $min_grade = "", $bool_mark_repeats_exclude = false, $degree_id = 0, $bool_skip_already_assigned_to_degree = TRUE, $bool_skip_subs = FALSE, $group_id = 0)
  1323. {
  1324. $rtn = FALSE;
  1325. // We will look at the course_repeat_policy to determine which type of search to do on this list.
  1326. $course_repeat_policy = variable_get("course_repeat_policy", "most_recent_exclude_previous");
  1327. if ($course_repeat_policy == "best_grade_exclude_others") {
  1328. // Search for best grade, exclude other attempts.
  1329. $rtn = $this->find_best_grade_match($course_c, $min_grade, TRUE, $degree_id, $bool_skip_already_assigned_to_degree, $bool_skip_subs, $group_id);
  1330. }
  1331. else {
  1332. // Search for most recent first, possibly mark previous as excluded.
  1333. $rtn = $this->find_most_recent_match($course_c, $min_grade, $bool_mark_repeats_exclude, $degree_id, $bool_skip_already_assigned_to_degree, $bool_skip_subs, $group_id);
  1334. }
  1335. return $rtn;
  1336. }
  1337. /**
  1338. * Adds the supplied CourseList to the bottom of $this's list.
  1339. *
  1340. * @param CourseList $course_l
  1341. */
  1342. function add_list(CourseList $course_l) {
  1343. $c = count($course_l->array_list);
  1344. for ($t = 0; $t < $c; $t++)
  1345. {
  1346. $this->add($course_l->array_list[$t]);
  1347. }
  1348. }
  1349. /**
  1350. * Returns hour many hours are in $this CourseList.
  1351. *
  1352. * @param string $requirement_type
  1353. * - If specified, we will only count courses which match this
  1354. * requirement_type.
  1355. *
  1356. * @param bool $bool_use_ignore_list
  1357. * @return int
  1358. */
  1359. function count_hours($requirement_type = "", $bool_use_ignore_list = false, $bool_correct_ghost_hour = true, $bool_force_zero_hours_to_one_hour = false, $bool_exclude_all_transfer_credits = FALSE, $degree_id = 0)
  1360. {
  1361. // Returns how many hours are being represented in this courseList.
  1362. // A requirement type of "uc" is the same as "c"
  1363. // (university capstone is a core requirement)
  1364. $count = 0;
  1365. for ($t = 0; $t < $this->count; $t++)
  1366. {
  1367. $course = $this->array_list[$t];
  1368. // Does this course belong to the same degree we are interested in? If not, skip it.
  1369. if ($degree_id > 0) {
  1370. if ($course->req_by_degree_id != $degree_id && $course->get_has_been_assigned_to_degree_id($degree_id) != TRUE) continue;
  1371. }
  1372. if ($bool_use_ignore_list == true)
  1373. {
  1374. // Do ignore some courses...
  1375. $temp_course_name = $course->subject_id . " " . $course->course_num;
  1376. // Check in our settings to see if we should ignore this course
  1377. // (configured in /custom/settings.php)
  1378. if (in_array($temp_course_name, csv_to_array(@$GLOBALS["fp_system_settings"]["ignore_courses_from_hour_counts"]))) {
  1379. continue;
  1380. }
  1381. // Also, if the course's requirement_type is "x" it means we should ignore it.
  1382. if ($course->requirement_type == 'x') continue;
  1383. }
  1384. if ($course->get_bool_substitution_new_from_split($degree_id) == TRUE)
  1385. {
  1386. // Do not count the possible fragments that are created
  1387. // from a new substitution split. This is causing problems
  1388. // in getting accurate numbers on the pie charts.
  1389. // BUT-- only skip if this new fragment isn't also being
  1390. // substituted somewhere else!
  1391. if ($course->get_bool_substitution($degree_id) == FALSE)
  1392. { // not being used in another sub, so skip it.
  1393. continue;
  1394. }
  1395. }
  1396. $h_get_hours = $course->get_hours($degree_id);
  1397. if ($bool_correct_ghost_hour) {
  1398. // If this course has a ghosthour, then use the
  1399. // hours_awarded (probably 1). However, if it was substituted,
  1400. // then we actually want the 0 hour. Confusing, isn't it?
  1401. if ($course->bool_ghost_hour) {
  1402. $h_get_hours = $course->get_hours_awarded($degree_id);
  1403. }
  1404. }
  1405. if ($bool_force_zero_hours_to_one_hour) {
  1406. // We want to force anything with a 0 hour to be 1 hour.
  1407. // Helps when selecting 0 hour courses from groups.
  1408. if ($h_get_hours == 0) {
  1409. $h_get_hours = 1;
  1410. }
  1411. }
  1412. // Make sure we aren't trying to exclude any transfer credits.
  1413. if ($bool_exclude_all_transfer_credits) {
  1414. if ($course->bool_transfer) {
  1415. continue;
  1416. }
  1417. // Is this a requirement which has been fulfilled by a course? And if so, is THAT course a transfer?
  1418. if ($course->course_list_fulfilled_by->is_empty == false) {
  1419. $cc = $course->course_list_fulfilled_by->get_first();
  1420. if ($cc->bool_transfer) {
  1421. continue;
  1422. }
  1423. }
  1424. }
  1425. if ($requirement_type == "")
  1426. {
  1427. $count = $count + $h_get_hours;
  1428. }
  1429. else {
  1430. // Requirement Type not blank, so only count these hours
  1431. // if it has the set requirement type.
  1432. if ($course->requirement_type == $requirement_type)
  1433. {
  1434. $count = $count + $h_get_hours;
  1435. continue;
  1436. }
  1437. // For specifically "university capstone" courses (which have a 'u' in front)...
  1438. if ($course->requirement_type == "u" . $requirement_type)
  1439. {
  1440. $count = $count + $h_get_hours;
  1441. }
  1442. }
  1443. }
  1444. return $count;
  1445. }
  1446. /**
  1447. * Removes courses which have neither been fulfilled or advised.
  1448. *
  1449. */
  1450. function remove_unfulfilled_and_unadvised_courses()
  1451. {
  1452. // remove courses from THIS list
  1453. // which have not been fulfilled AND
  1454. // are not currently advised.
  1455. $rtn_list = new CourseList();
  1456. for ($t = 0; $t < $this->count; $t++)
  1457. {
  1458. $course = $this->array_list[$t];
  1459. if ($course->course_list_fulfilled_by->is_empty == false)
  1460. {
  1461. // something IS fulfilling it!
  1462. $rtn_list->add($course);
  1463. } else if ($course->bool_advised_to_take == true)
  1464. {
  1465. // Was not being fulfilled, but, it was advised
  1466. // to take.
  1467. $rtn_list->add($course);
  1468. }
  1469. }
  1470. $this->array_list = $rtn_list->array_list;
  1471. $this->reset_counter();
  1472. }
  1473. /**
  1474. * Removes courses from this list which have not been fulfilled
  1475. * (ther course_list_fulfilled_by is empty).
  1476. *
  1477. */
  1478. function remove_unfulfilled_courses()
  1479. {
  1480. // remove courses in THIS list
  1481. // which have nothing in their course_list_fulfilled_by
  1482. // object.
  1483. $rtn_list = new CourseList();
  1484. for ($t = 0; $t < $this->count; $t++)
  1485. {
  1486. $course = $this->array_list[$t];
  1487. if ($course->course_list_fulfilled_by->is_empty == false)
  1488. {
  1489. $rtn_list->add($course);
  1490. }
  1491. }
  1492. $this->array_list = $rtn_list->array_list;
  1493. $this->reset_counter();
  1494. }
  1495. /**
  1496. * Returns a clone CourseList of $this.
  1497. *
  1498. * @param bool $bool_return_new_courses
  1499. * - If set to TRUE, it will create new Course objects
  1500. * based on the course_id's of the ones in $this's list.
  1501. * If set to FALSE, this will add the exact same Course
  1502. * objects by reference to the new list.
  1503. *
  1504. * @return CourseList
  1505. */
  1506. function get_clone($bool_return_new_courses = FALSE)
  1507. {
  1508. // This will return a clone of this list.
  1509. // If boolReturnNewCourses is true, then it will
  1510. // return a new list of new instances of courses
  1511. // from this list.
  1512. $rtn_list = new CourseList();
  1513. for ($t = 0; $t < $this->count; $t++)
  1514. {
  1515. $course = $this->array_list[$t];
  1516. if ($bool_return_new_courses)
  1517. {
  1518. $new_course = new Course();
  1519. $new_course->course_id = $course->course_id;
  1520. $rtn_list->add($new_course);
  1521. } else {
  1522. $rtn_list->add($course);
  1523. }
  1524. }
  1525. return $rtn_list;
  1526. }
  1527. /**
  1528. * Returns a CourseList of all the fulfilled or advised courses
  1529. * in $this's list.
  1530. *
  1531. * @param bool $bool_return_new_courses
  1532. * - Works the same as get_clone()'s boolReturnNewCourses
  1533. * variable.
  1534. *
  1535. * @return Course
  1536. */
  1537. function get_fulfilled_or_advised($bool_return_new_courses = false)
  1538. {
  1539. $rtn_list = new CourseList();
  1540. for ($t = 0; $t < $this->count; $t++)
  1541. {
  1542. $course = $this->array_list[$t];
  1543. $add_course = $course;
  1544. if ($bool_return_new_courses == true)
  1545. {
  1546. $add_course = new Course();
  1547. $add_course->course_id = $course->course_id;
  1548. }
  1549. if ($course->bool_advised_to_take == true)
  1550. {
  1551. $rtn_list->add($add_course);
  1552. }
  1553. // Several ways to tell if a course is here by credit...
  1554. if (!$course->course_list_fulfilled_by->is_empty) {
  1555. $rtn_list->add($add_course);
  1556. }
  1557. else if ($course->grade != "") {
  1558. $rtn_list->add($add_course);
  1559. }
  1560. else if ($course->get_bool_substitution() == true) {
  1561. $rtn_list->add($add_course);
  1562. }
  1563. }
  1564. return $rtn_list;
  1565. }
  1566. /**
  1567. * Returns the number of courses in this list which have either
  1568. * been fulfilled or advised to take. It does not count hours,
  1569. * just the courses themselves.
  1570. *
  1571. * @return int
  1572. */
  1573. function count_fulfilled_or_advised()
  1574. {
  1575. // This function returns the number of courses in this
  1576. // courseList which is either fulfilled or has been advised
  1577. // to take. It does care about hours, just the number of
  1578. // courses themselves.
  1579. $count = 0;
  1580. for ($t = 0; $t < $this->count; $t++)
  1581. {
  1582. $course = $this->array_list[$t];
  1583. if ($course->bool_advised_to_take == true)
  1584. {
  1585. $count++;
  1586. }
  1587. // Several ways to tell if a course is here by credit...
  1588. if (!$course->course_list_fulfilled_by->is_empty)
  1589. {
  1590. $count++;
  1591. } else if ($course->grade != "") {
  1592. $count++;
  1593. } else if ($course->bool_substitution == true)
  1594. {
  1595. $count++;
  1596. }
  1597. }
  1598. return $count;
  1599. }
  1600. /**
  1601. * Returns a CourseList of courses which have bool_advised_to_take == true.
  1602. *
  1603. * @return CourseList
  1604. */
  1605. function get_advised_courses_list()
  1606. {
  1607. // Return a courseList object of courses in THIS
  1608. // list which have bool_advised_to_take == true.
  1609. $rtn_list = new CourseList();
  1610. for ($t = 0; $t < $this->count; $t++)
  1611. {
  1612. $course = $this->array_list[$t];
  1613. if ($course->bool_advised_to_take == true)
  1614. {
  1615. $rtn_list->add($course);
  1616. }
  1617. }
  1618. return $rtn_list;
  1619. }
  1620. /**
  1621. * Similar to count_hours, but this will only count courses
  1622. * which have been taken and have a grade.
  1623. *
  1624. * @param string $requirement_type
  1625. * - If set, we will only look for courses matching this requirement_type.
  1626. *
  1627. * @param bool $bool_use_ignore_list
  1628. * @param bool $bool_ignore_enrolled
  1629. * @return int
  1630. */
  1631. function count_credit_hours($requirement_type = "", $bool_use_ignore_list = false, $bool_ignore_enrolled = false, $bool_qpts_grades_only = FALSE, $bool_exclude_all_transfer_credits = FALSE, $degree_id = 0)
  1632. {
  1633. // Similar to count_hours, but this will only
  1634. // count courses which have been taken (have a grade).
  1635. $count = 0;
  1636. // Let's find out what our quality point grades & values are...
  1637. $qpts_grades = array();
  1638. $tlines = explode("\n", variable_get("quality_points_grades", "A ~ 4\nB ~ 3\nC ~ 2\nD ~ 1\nF ~ 0\nI ~ 0"));
  1639. foreach ($tlines as $tline) {
  1640. $temp = explode("~", trim($tline));
  1641. if (trim($temp[0]) != "") {
  1642. $qpts_grades[trim($temp[0])] = trim($temp[1]);
  1643. }
  1644. }
  1645. $enrolled_grades = csv_to_array($GLOBALS["fp_system_settings"]["enrolled_grades"]);
  1646. $retake_grades = csv_to_array($GLOBALS["fp_system_settings"]["retake_grades"]);
  1647. for ($t = 0; $t < $this->count; $t++)
  1648. {
  1649. $course = $this->array_list[$t];
  1650. // Does this course belong to the same degree we are interested in? If not, skip it.
  1651. if ($degree_id > 0) {
  1652. if ($course->req_by_degree_id != $degree_id && $course->get_has_been_assigned_to_degree_id($degree_id) != TRUE) continue;
  1653. }
  1654. if ($bool_use_ignore_list == true)
  1655. {
  1656. // Do ignore some courses...
  1657. $temp_course_name = $course->subject_id . " " . $course->course_num;
  1658. // Check in our settings to see if we should ignore this course
  1659. // (configured in /custom/settings.php)
  1660. if (in_array($temp_course_name, csv_to_array(@$GLOBALS["fp_system_settings"]["ignore_courses_from_hour_counts"]))) {
  1661. continue;
  1662. }
  1663. // Also, if the course's requirement_type is "x" it means we should ignore it.
  1664. if ($course->requirement_type == 'x') continue;
  1665. }
  1666. if ($bool_ignore_enrolled == true)
  1667. {
  1668. if (in_array($course->grade, $enrolled_grades)) {
  1669. continue;
  1670. }
  1671. /*
  1672. if ($course->is_completed() == false)
  1673. {
  1674. if ($course->course_list_fulfilled_by->is_empty)
  1675. {
  1676. continue;
  1677. } else {
  1678. if ($course->course_list_fulfilled_by->get_first()->is_completed() == false)
  1679. {
  1680. continue;
  1681. }
  1682. }
  1683. }
  1684. */
  1685. }
  1686. // Only allowing grades which we have quality points for?
  1687. if ($bool_qpts_grades_only) {
  1688. if ($course->grade != "" && !isset($qpts_grades[$course->grade])) {
  1689. continue;
  1690. }
  1691. }
  1692. else {
  1693. // Is this grade a "retake" grade? If so, skip it.
  1694. if (in_array($course->grade, $retake_grades)) continue;
  1695. }
  1696. // Correct the course's requirement type, if needed (remove the "u")
  1697. $cr_type = $course->requirement_type;
  1698. $cr_type = str_replace("u", "", $cr_type);
  1699. if ($course->grade != "")// || !($course->course_list_fulfilled_by->is_empty))
  1700. {
  1701. // Make sure we aren't trying to exclude any transfer credits.
  1702. if ($bool_exclude_all_transfer_credits) {
  1703. if ($course->bool_transfer) {
  1704. continue;
  1705. }
  1706. // Is this a requirement which has been fulfilled by a course? And if so, is THAT course a transfer?
  1707. if ($course->course_list_fulfilled_by->is_empty == false) {
  1708. $cc = $course->course_list_fulfilled_by->get_first();
  1709. if ($cc->bool_transfer) {
  1710. continue;
  1711. }
  1712. }
  1713. }
  1714. // If we require the grade to be a qpts_grade, then check that now.
  1715. if ($bool_qpts_grades_only && !isset($qpts_grades[$course->grade])) {
  1716. continue;
  1717. }
  1718. // Do our requirement types match?
  1719. if ($requirement_type == "" || ($requirement_type != "" && $requirement_type == $cr_type))
  1720. {
  1721. $h = $course->get_hours();
  1722. $count = $count + $h;
  1723. }
  1724. }
  1725. else {
  1726. // maybe it's a substitution?
  1727. if ($requirement_type == "" || ($requirement_type != "" && $requirement_type == $cr_type))
  1728. {
  1729. if ($course->course_list_fulfilled_by->is_empty == false)
  1730. {
  1731. $cc = $course->course_list_fulfilled_by->get_first();
  1732. if ($cc->get_bool_substitution())
  1733. {
  1734. // If we require the grade to be a qpts_grade, then check that now.
  1735. if ($bool_qpts_grades_only && !isset($qpts_grades[$cc->grade])) {
  1736. continue;
  1737. }
  1738. // Make sure we aren't trying to exclude any transfer credits.
  1739. if ($bool_exclude_all_transfer_credits && $cc->bool_transfer) {
  1740. //fpm($requirement_type);
  1741. //fpm($cc);
  1742. continue;
  1743. }
  1744. $h = $cc->get_substitution_hours();
  1745. if ($cc->bool_ghost_hour) {
  1746. $h = 0;
  1747. }
  1748. $count = $count + $h;
  1749. }
  1750. }
  1751. }
  1752. }
  1753. }
  1754. return $count;
  1755. }
  1756. /**
  1757. * Similar to count_credit_hours, but this will only count courses
  1758. * which have been taken and have a grade. We will return back
  1759. * a sum of their quality points.
  1760. *
  1761. * @param string $requirement_type
  1762. * - If set, we will only look for courses matching this requirement_type.
  1763. *
  1764. * @param bool $bool_use_ignore_list
  1765. * @param bool $bool_ignore_enrolled
  1766. * @return int
  1767. */
  1768. function count_credit_quality_points($requirement_type = "", $bool_use_ignore_list = false, $bool_ignore_enrolled = false, $bool_exclude_all_transfer_credits = FALSE, $degree_id = 0)
  1769. {
  1770. $points = 0;
  1771. for ($t = 0; $t < $this->count; $t++)
  1772. {
  1773. $course = $this->array_list[$t];
  1774. // Does this course belong to the same degree we are interested in? If not, skip it.
  1775. if ($degree_id > 0) {
  1776. if ($course->req_by_degree_id != $degree_id && $course->get_has_been_assigned_to_degree_id($degree_id) != TRUE) continue;
  1777. }
  1778. // Correct the course's requirement type, if needed (remove the "u")
  1779. $cr_type = $course->requirement_type;
  1780. $cr_type = str_replace("u", "", $cr_type);
  1781. if ($bool_use_ignore_list == true)
  1782. {
  1783. // Do ignore some courses...
  1784. $temp_course_name = $course->subject_id . " " . $course->course_num;
  1785. // Check in our settings to see if we should ignore this course
  1786. // (configured in /custom/settings.php)
  1787. if (in_array($temp_course_name, csv_to_array(@$GLOBALS["fp_system_settings"]["ignore_courses_from_hour_counts"]))) {
  1788. continue;
  1789. }
  1790. // Also, if the course's requirement_type is "x" it means we should ignore it.
  1791. if ($course->requirement_type == 'x') continue;
  1792. }
  1793. if ($bool_ignore_enrolled == true)
  1794. {
  1795. if ($course->is_completed() == false)
  1796. {
  1797. if ($course->course_list_fulfilled_by->is_empty)
  1798. {
  1799. continue;
  1800. } else {
  1801. if ($course->course_list_fulfilled_by->get_first()->is_completed() == false)
  1802. {
  1803. continue;
  1804. }
  1805. }
  1806. }
  1807. }
  1808. if ($course->grade != "")
  1809. {
  1810. // Make sure we aren't trying to exclude any transfer credits.
  1811. if ($bool_exclude_all_transfer_credits) {
  1812. if ($course->bool_transfer) {
  1813. continue;
  1814. }
  1815. // Is this a requirement which has been fulfilled by a course? And if so, is THAT course a transfer?
  1816. if ($course->course_list_fulfilled_by->is_empty == false) {
  1817. $cc = $course->course_list_fulfilled_by->get_first();
  1818. if ($cc->bool_transfer) {
  1819. continue;
  1820. }
  1821. }
  1822. }
  1823. if ($requirement_type == "")
  1824. {
  1825. $p = $course->get_quality_points($degree_id);
  1826. $points = $points + $p;
  1827. } else {
  1828. if ($cr_type == $requirement_type)
  1829. {
  1830. $p = $course->get_quality_points($degree_id);
  1831. $points = $points + $p;
  1832. continue;
  1833. }
  1834. }
  1835. }
  1836. else {
  1837. // maybe it's a substitution?
  1838. if (($requirement_type == "") || ($requirement_type != "" && $requirement_type == $cr_type))
  1839. {
  1840. if ($course->course_list_fulfilled_by->is_empty == false)
  1841. {
  1842. $cc = $course->course_list_fulfilled_by->get_first();
  1843. if ($cc->get_bool_substitution($degree_id))
  1844. {
  1845. // Make sure we aren't trying to exclude any transfer credits.
  1846. if ($bool_exclude_all_transfer_credits) {
  1847. if ($cc->bool_transfer) {
  1848. //fpm($course);
  1849. continue;
  1850. }
  1851. }
  1852. //$h = $cc->substitution_hours;
  1853. //if ($cc->bool_ghost_hour) {
  1854. // $h = 0;
  1855. //}
  1856. // What are the quality points for this course?
  1857. $p = $cc->get_quality_points($degree_id);
  1858. $points = $points + $p;
  1859. }
  1860. }
  1861. }
  1862. }
  1863. }
  1864. return $points;
  1865. }
  1866. /**
  1867. * Assign a groupID to every course in the list.
  1868. *
  1869. * @param int $group_id
  1870. */
  1871. function assign_group_id($group_id)
  1872. {
  1873. for ($t = 0; $t < $this->count; $t++)
  1874. {
  1875. $course = $this->array_list[$t];
  1876. //$course->assigned_to_group_id = $group_id;
  1877. $course->assigned_to_group_ids_array[$group_id] = $group_id;
  1878. }
  1879. }
  1880. /**
  1881. * Assign a semesterNum to every course in the list.
  1882. *
  1883. * @param int $semester_num
  1884. */
  1885. function assign_semester_num($semester_num)
  1886. {
  1887. for ($t = 0; $t < $this->count; $t++)
  1888. {
  1889. $course = $this->array_list[$t];
  1890. $course->assigned_to_semester_num = $semester_num;
  1891. }
  1892. }
  1893. /**
  1894. * Sets the bool_has_been_assigned property of every course in
  1895. * the list.
  1896. *
  1897. * @param bool $bool_has_been_assigned
  1898. * - What to set each course's->boolhasBeenAssigned property
  1899. * to.
  1900. *
  1901. */
  1902. function set_has_been_assigned($bool_has_been_assigned = true)
  1903. {
  1904. // Set the bool_has_been_assigned for all items
  1905. // in this list.
  1906. for ($t = 0; $t < $this->count; $t++)
  1907. {
  1908. $course = $this->array_list[$t];
  1909. $course->bool_has_been_assigned = $bool_has_been_assigned;
  1910. }
  1911. }
  1912. /**
  1913. * Set's each course's bool_substitution value.
  1914. *
  1915. * @param bool $bool_s
  1916. * - What to set each course's bool_substitution value to.
  1917. */
  1918. function set_bool_substitution($degree_id = 0, $bool_s = true)
  1919. {
  1920. // Set the bool_substitution for all items
  1921. // in this list.
  1922. for ($t = 0; $t < $this->count; $t++)
  1923. {
  1924. $course = $this->array_list[$t];
  1925. $course->set_bool_substitution($degree_id, $bool_s);
  1926. }
  1927. }
  1928. /**
  1929. * Set all the courses in this list to have the same "req_by_degree_id" value.
  1930. */
  1931. function set_req_by_degree_id($degree_id = 0)
  1932. {
  1933. // Set the bool_substitution for all items
  1934. // in this list.
  1935. for ($t = 0; $t < $this->count; $t++)
  1936. {
  1937. $course = $this->array_list[$t];
  1938. $course->req_by_degree_id = $degree_id;
  1939. }
  1940. }
  1941. /**
  1942. * Set all the courses in this list to have the same "requirement_type" value.
  1943. */
  1944. function set_requirement_type($requirement_type = "")
  1945. {
  1946. // Set the bool_substitution for all items
  1947. // in this list.
  1948. for ($t = 0; $t < $this->count; $t++)
  1949. {
  1950. $course = $this->array_list[$t];
  1951. $course->requirement_type = $requirement_type;
  1952. }
  1953. }
  1954. /**
  1955. * Sets each course's $course_substitution value to the supplied
  1956. * Course object.
  1957. *
  1958. * @param Course $course_s
  1959. * @param string $sub_remarks
  1960. */
  1961. function set_course_substitution(Course $course_s, $sub_remarks = "", $degree_id = 0)
  1962. {
  1963. for ($t = 0; $t < $this->count; $t++)
  1964. {
  1965. $course = $this->array_list[$t];
  1966. $course->set_course_substitution($degree_id, $course_s);
  1967. $course->req_by_degree_id = $course_s->req_by_degree_id; // match it up to the degree its being subbed for
  1968. $course->sub_remarks = $sub_remarks;
  1969. }
  1970. }
  1971. /**
  1972. * Go through the list and decrement the specified_repeats
  1973. * value for all instances of Course $course.
  1974. *
  1975. * @param Course $course
  1976. */
  1977. function dec_specified_repeats(Course $course, $bool_ignore_infinite_repeats = TRUE) {
  1978. // Go through the list, and decrement the specified_repeats
  1979. // value for all instances of $course.
  1980. for ($t = 0; $t < $this->count; $t++)
  1981. {
  1982. $course2 = $this->array_list[$t];
  1983. if ($course2->course_id == $course->course_id)
  1984. {
  1985. if ($bool_ignore_infinite_repeats && $course2->specified_repeats == Group::GROUP_COURSE_INFINITE_REPEATS) continue;
  1986. $course2->specified_repeats--;
  1987. }
  1988. }
  1989. }
  1990. /**
  1991. * Go through the list and set the specified_repeats value to $num
  1992. * for all instances of $course.
  1993. *
  1994. * @param Course $course
  1995. * @param int $num
  1996. */
  1997. function set_specified_repeats(Course $course, $num)
  1998. {
  1999. for ($t = 0; $t < $this->count; $t++)
  2000. {
  2001. $course2 = $this->array_list[$t];
  2002. if ($course2->course_id == $course->course_id)
  2003. {
  2004. $course2->specified_repeats = $num;
  2005. $course2->bool_specified_repeats = true;
  2006. }
  2007. }
  2008. }
  2009. /**
  2010. * Removes excluded courses from the list (courses that
  2011. * have db_exclude == 1)
  2012. *
  2013. */
  2014. function remove_excluded()
  2015. {
  2016. // Removes courses from the list that have a db_exclude == 1.
  2017. $new_list = new CourseList();
  2018. // Do this by adding elements to an array.
  2019. // course_id => index in list.
  2020. for ($t = 0; $t < $this->count; $t++)
  2021. {
  2022. $course = $this->array_list[$t];
  2023. if ($course->subject_id == "")
  2024. { // load descriptive data (include exclude info)
  2025. $course->load_descriptive_data();
  2026. }
  2027. if ($course->db_exclude == 1)
  2028. {
  2029. continue;
  2030. }
  2031. $new_list->add($course);
  2032. }
  2033. $this->array_list = $new_list->array_list;
  2034. $this->reset_counter();
  2035. }
  2036. /**
  2037. * Remove occurances of the course in the course list.
  2038. *
  2039. * If a limit is higher than zero, we will STOP after that limit has been reached.
  2040. */
  2041. function remove_course_with_course_id($course_id, $limit = 0) {
  2042. // If the limit is 0, set it to an int's max, which is around 2 billion (32bit) or 9 quintillion (64 bit).
  2043. // Either way, it's effectively infinite for FlightPath in this purpose.
  2044. if ($limit == 0) $limit = PHP_INT_MAX;
  2045. $new_list = new CourseList();
  2046. $c = 0;
  2047. for ($t = 0; $t < $this->count; $t++)
  2048. {
  2049. $course = $this->array_list[$t];
  2050. if ($course == null)
  2051. {
  2052. continue;
  2053. }
  2054. if ($c < $limit && $course->course_id == $course_id) {
  2055. // We found the course. Since we do not want it to be part of the list,
  2056. // we will skip adding it to the new_list.
  2057. $c++;
  2058. continue;
  2059. }
  2060. // Otherwise, let's add it to the new_list.
  2061. $new_list->add($course);
  2062. }
  2063. // Switch over the reference.
  2064. $this->array_list = $new_list->array_list;
  2065. $this->reset_counter();
  2066. }
  2067. /**
  2068. * Removes all courses which are not assigned to this degree_id.
  2069. */
  2070. function remove_courses_not_in_degree($degree_id) {
  2071. $new_list = new CourseList();
  2072. for ($t = 0; $t < $this->count; $t++)
  2073. {
  2074. $course = $this->array_list[$t];
  2075. if ($course == null)
  2076. {
  2077. continue;
  2078. }
  2079. if ($course->req_by_degree_id != $degree_id) {
  2080. continue;
  2081. }
  2082. // Otherwise, let's add it to the new_list.
  2083. $new_list->add($course);
  2084. }
  2085. // Switch over the reference.
  2086. $this->array_list = $new_list->array_list;
  2087. $this->reset_counter();
  2088. }
  2089. /**
  2090. * Removes null's and duplicate courses from the list.
  2091. *
  2092. */
  2093. function remove_duplicates()
  2094. {
  2095. // Go through and remove duplicates from the list.
  2096. // Also remove null's
  2097. $tarray = array();
  2098. $new_list = new CourseList();
  2099. // Do this by adding elements to an array.
  2100. // course_id => index in list.
  2101. for ($t = 0; $t < $this->count; $t++)
  2102. {
  2103. $course = $this->array_list[$t];
  2104. if ($course == null)
  2105. {
  2106. continue;
  2107. }
  2108. $tarray[$course->course_id] = -1;
  2109. }
  2110. for ($t = 0; $t < $this->count; $t++)
  2111. {
  2112. $course = $this->array_list[$t];
  2113. if ($course == null)
  2114. {
  2115. continue;
  2116. }
  2117. //if (is_object($course->courseFulfilledBy))
  2118. if (!($course->course_list_fulfilled_by->is_empty))
  2119. {
  2120. $tarray[$course->course_id] = $t;
  2121. continue;
  2122. }
  2123. if ($tarray[$course->course_id]*1 < 0)
  2124. {
  2125. $tarray[$course->course_id] = $t;
  2126. }
  2127. }
  2128. // Now, go through tarray and rebuild the newList.
  2129. foreach($tarray as $course_id => $i)
  2130. {
  2131. $new_list->add($this->array_list[$i]);
  2132. }
  2133. // Switch over the reference.
  2134. $this->array_list = $new_list->array_list;
  2135. $this->reset_counter();
  2136. }
  2137. } // end class CourseList