CourseList.php

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

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

Classes

Namesort descending Description
CourseList