CourseList.php

  1. 7.x classes/CourseList.php
  2. 6.x classes/CourseList.php
  3. 4.x custom/classes/CourseList.php
  4. 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 (intval($course->db_exclude) === 1) {
  672. continue;
  673. }
  674. // probably because it was excluded.
  675. if ($subj != $course->subject_id) {
  676. continue;
  677. }
  678. // We have a new subject. Add it to the array.
  679. $rtn_array[] = $subj;
  680. }
  681. }
  682. return $rtn_array;
  683. }
  684. /**
  685. * Go through the courseList and take out any course
  686. * which does not have the $subject as its subject_id.
  687. *
  688. * @param string $subject
  689. * @param bool $bool_reassign_valid_name
  690. * - If set to TRUE, we will look at other possible valid names
  691. * for this course. If we find one, we will reassign the course's
  692. * subject_id and course_num to the new valid name.
  693. *
  694. */
  695. function exclude_all_subjects_except($subject, $bool_reassign_valid_name = true)
  696. {
  697. $new_course_list = new CourseList();
  698. for ($t = 0; $t < $this->count; $t++)
  699. {
  700. $course = $this->array_list[$t];
  701. if ($course->subject_id == $subject)
  702. {
  703. $new_course_list->add($course);
  704. continue;
  705. }
  706. // Not the right subject-- but perhaps the course has another
  707. // valid name with this subject? Ex: CSCI 373 and MATH 373.
  708. if ($bool_reassign_valid_name == true && count($course->array_valid_names) > 1)
  709. {
  710. for ($x = 0; $x < count($course->array_valid_names); $x++)
  711. {
  712. if (strstr($course->array_valid_names[$x], $subject))
  713. {
  714. $temp = explode("~",$course->array_valid_names[$x]);
  715. $course->subject_id = $temp[0];
  716. $course->course_num = $temp[1];
  717. $new_course_list->add($course);
  718. continue;
  719. }
  720. }
  721. }
  722. }
  723. // Now, transfer ownership of the arraylist.
  724. $this->array_list = $new_course_list->array_list;
  725. }
  726. /**
  727. * This re-sorts the CourseList so that fulfilled courses
  728. * are first, in alphabetical order, followed by
  729. * unfulfilled courses, in alphabetical order.
  730. * This is most useful for making the groups
  731. * show up correctly.
  732. *
  733. */
  734. function sort_fulfilled_first_alphabetical()
  735. {
  736. $tarray = array();
  737. for ($t = 0; $t < $this->count; $t++)
  738. {
  739. //if (!is_object($this->array_list[$t]->courseFulfilledBy))
  740. if ($this->array_list[$t]->course_list_fulfilled_by->is_empty == true)
  741. { // Skip if not fulfilled.
  742. continue;
  743. }
  744. $c = $this->array_list[$t];
  745. $str = "$c->subject_id ~~ $c->course_num ~~ $t";
  746. array_push($tarray,$str);
  747. }
  748. sort($tarray);
  749. $new_list = new CourseList();
  750. for($t = 0; $t < count($tarray); $t++)
  751. {
  752. $temp = explode(" ~~ ",$tarray[$t]);
  753. $i = $temp[2];
  754. $new_list->add($this->array_list[$i]);
  755. }
  756. // Alright, now we do it again, but with unfulfilled courses.
  757. $tarray = array();
  758. for ($t = 0; $t < $this->count; $t++)
  759. {
  760. //if (is_object($this->array_list[$t]->courseFulfilledBy))
  761. if ($this->array_list[$t]->course_list_fulfilled_by->is_empty != true)
  762. { // Skip if fulfilled.
  763. continue;
  764. }
  765. $c = $this->array_list[$t];
  766. $str = "$c->subject_id ~~ $c->course_num ~~ $t";
  767. array_push($tarray,$str);
  768. }
  769. sort($tarray);
  770. $new_list2 = new CourseList();
  771. for($t = 0; $t < count($tarray); $t++)
  772. {
  773. $temp = explode(" ~~ ",$tarray[$t]);
  774. $i = $temp[2];
  775. $new_list2->add($this->array_list[$i]);
  776. }
  777. // Now, combine the two lists.
  778. $new_list->add_list($new_list2);
  779. // And, transfer the newList into this list.
  780. $this->array_list = $new_list->array_list;
  781. }
  782. /**
  783. * This re-sorts the CourseList so that advised courses
  784. * are last, in alphabetical order, preceeded by
  785. * unfulfilled courses, in alphabetical order.
  786. *
  787. *
  788. */
  789. function sort_advised_last_alphabetical()
  790. {
  791. $tarray = array();
  792. for ($t = 0; $t < $this->count; $t++)
  793. {
  794. if ($this->array_list[$t]->bool_advised_to_take == true)
  795. { // Skip if not 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. // Alright, now we do it again, but with advised courses.
  804. $t2array = array();
  805. for ($t = 0; $t < $this->count; $t++)
  806. {
  807. if ($this->array_list[$t]->bool_advised_to_take == false)
  808. { // Skip if not advised
  809. continue;
  810. }
  811. $c = $this->array_list[$t];
  812. $str = "$c->subject_id ~~ $c->course_num ~~ $t";
  813. array_push($t2array,$str);
  814. }
  815. sort($t2array);
  816. $t3array = array_merge($tarray, $t2array);
  817. $new_list = new CourseList();
  818. for($t = 0; $t < count($t3array); $t++)
  819. {
  820. $temp = explode(" ~~ ",$t3array[$t]);
  821. $i = $temp[2];
  822. $new_list->add($this->array_list[$i]);
  823. }
  824. // And, transfer the newList into this list.
  825. $this->array_list = $new_list->array_list;
  826. }
  827. /**
  828. * This function will resort this courselist for which a substitution
  829. * has been made in listSubstitutions.
  830. *
  831. * @param SubstitutionList $list_substitutions
  832. * @param int $group_id
  833. */
  834. function sort_substitutions_first($list_substitutions, $group_id = 0)
  835. {
  836. // This will sort courses in a list for which
  837. // a substitution has been made in listSubstitutions.
  838. // It will place those courses at the top of the list.
  839. $top_array = array();
  840. // Since I need the indexes, I will have to go through the array
  841. // myself...
  842. // array to keep track of all the substitutions that have been used for this list (Logan's change ticket 2291)
  843. $used_substitution_ids = array();
  844. for ($t = 0; $t < $this->count; $t++) {
  845. $c = $this->array_list[$t];
  846. // So-- does this course have a substitution somewhere in
  847. // the list (for the supplied groupID) ?
  848. // supply the list of used ids, so they are not reused in this list. (Logan's change ticket 2291)
  849. if ($substitution = $list_substitutions->find_requirement($c, true, $group_id,0,$used_substitution_ids))
  850. {
  851. // yes, there is a sub for this group (or bare degree plan)
  852. //mark the substitution so it doesn't get used again (Logan's change ticket 2291)
  853. $used_substitution_ids[] = $substitution->db_substitution_id;
  854. $top_array[] = $t;
  855. }
  856. }
  857. // Okay, we now have, in the topArray, a list of indexes which should
  858. // appear at the top.
  859. $new_list = new CourseList();
  860. for ($j = 0; $j < count($top_array); $j++)
  861. {
  862. $new_list->add($this->array_list[$top_array[$j]]);
  863. }
  864. // Now, add everything else in the array (except indecies
  865. // appearing in topArray)
  866. for ($t = 0; $t < $this->count; $t++)
  867. {
  868. if (in_array($t, $top_array))
  869. {
  870. continue;
  871. }
  872. $new_list->add($this->array_list[$t]);
  873. }
  874. $this->array_list = $new_list->array_list;
  875. $new_list->reset_counter();
  876. }
  877. /**
  878. * This will sort so that courses with the smallest hours
  879. * (first trying hours_awarded, then min_hours)
  880. * are at the top of the list. If the list contains more
  881. * than one course with a set of hours (like there are 30
  882. * courses all worth 3 hours) then it orders those as
  883. * most-recently-taken first.
  884. *
  885. */
  886. function sort_smallest_hours_first()
  887. {
  888. $tarray = array();
  889. // Since I need the indexes, I will have to go through the array
  890. // myself...
  891. for ($t = 0; $t < $this->count; $t++)
  892. {
  893. $c = $this->array_list[$t];
  894. $hours = $c->get_hours_awarded();
  895. if (floatval($hours) == 0)
  896. {
  897. $hours = $c->min_hours*1;
  898. }
  899. $str = "$hours ~~ $t";
  900. array_push($tarray,$str);
  901. }
  902. // Now, sort the array...
  903. //print_pre(print_r($tarray));
  904. sort($tarray);
  905. //print_pre(print_r($tarray));
  906. // Now, convert the array back into a list of courses.
  907. $new_list = new CourseList();
  908. for($t = 0; $t < count($tarray); $t++)
  909. {
  910. $temp = explode(" ~~ ",$tarray[$t]);
  911. $i = $temp[1];
  912. $new_list->add($this->array_list[$i]);
  913. }
  914. // Okay, now $new_list should contain the correct values.
  915. // We will transfer over the reference.
  916. $this->array_list = $new_list->array_list;
  917. } // sort_smallest_hours_first
  918. /*
  919. * Sort the courses of this list by number of hours descending.
  920. * Order of courses with the same number of hours is preserved.
  921. */
  922. function sort_largest_hours_first() {
  923. $sort_list = array();
  924. // go through the courses, creating an array keyed by hours.
  925. for ($t = 0; $t < count($this->array_list); $t++) {
  926. $hrs = $this->array_list[$t]->get_hours();
  927. if ($this->array_list[$t]->bool_ghost_hour) $hrs = 0;
  928. $sort_list[$hrs][] = $this->array_list[$t];
  929. }
  930. //sort the array in order of hours descending
  931. krsort($sort_list,SORT_NUMERIC);
  932. //clear the internal array, then refill it with the now sorted courses.
  933. $this->array_list = array();
  934. foreach ($sort_list as $courses) {
  935. foreach ($courses as $course) {
  936. $this->array_list[] = $course;
  937. }
  938. }
  939. $this->reset_counter();
  940. }
  941. /**
  942. * This method will sort by the most recently taken
  943. * courses (determined by the term_id).
  944. * The easiest way I can think to do this is to temporarily
  945. * put their term_id's and index#'s into an array, and then
  946. * have PHP sort the array itself. PHP's sorting algorithm
  947. * is faster than anything I can program right now, anyway.
  948. *
  949. * @param bool $bool_maintain_alpha_order
  950. */
  951. function sort_most_recent_first($bool_maintain_alpha_order = true)
  952. {
  953. $tarray = array();
  954. // Since I need the indexes, I will have to go through the array
  955. // myself...
  956. for ($t = 0; $t < $this->count; $t++)
  957. {
  958. $c = $this->array_list[$t];
  959. $cn = "";
  960. if ($bool_maintain_alpha_order == true)
  961. {
  962. // We say 1000- the course number in order to give
  963. // us the complement of the number. That is so it will
  964. // reverse-sort in the correct order. Strange, but it fixes
  965. // a small display issue where PHYS 207 and PHYS 209, taken at
  966. // the same time, causes PHYS 209 to be displayed first.
  967. // We also reverse the subject_id, again, so that
  968. // MATH will be sorted above ZOOL, when taken at the same time.
  969. // This might not work at all, though...
  970. // TODO: The 1000 - course_num bit doesn't work (throws a warning) if the course_num
  971. // is non-numeric. Ex: 301A. Let's instead use the same strrev() function on course_num, but we put it in quotes
  972. // to guarantee it gets evaluated as a string.
  973. //$cn = strrev($c->subject_id) . "," . (1000 - $c->course_num);
  974. $cn = strrev($c->subject_id) . "," . strrev("$c->course_num");
  975. }
  976. $str = "$c->term_id ~~ $cn ~~ $t";
  977. array_push($tarray,$str);
  978. }
  979. // Now, sort the array...
  980. rsort($tarray);
  981. // Now, convert the array back into a list of courses.
  982. $new_list = new CourseList();
  983. for($t = 0; $t < count($tarray); $t++)
  984. {
  985. $temp = explode(" ~~ ",$tarray[$t]);
  986. $i = $temp[2];
  987. $new_list->add($this->array_list[$i]);
  988. }
  989. // Okay, now $new_list should contain the correct values.
  990. // We will transfer over the reference.
  991. $this->array_list = $new_list->array_list;
  992. }
  993. /**
  994. * Convienence function. It simply calls sort_alphabetical_order(), but
  995. * passes the boolean value to make it be reversed.
  996. *
  997. */
  998. function sort_reverse_alphabetical_order()
  999. {
  1000. $this->sort_alphabetical_order(true);
  1001. }
  1002. /**
  1003. * Sorts the courses based on their db_degree_requirement_id value
  1004. */
  1005. function sort_degree_requirement_id() {
  1006. $sort_list = array();
  1007. // go through the courses, creating an array keyed by db_degree_requirement_id.
  1008. for ($t = 0; $t < count($this->array_list); $t++) {
  1009. $id = intval($this->array_list[$t]->db_degree_requirement_id);
  1010. $sort_list[$id][] = $this->array_list[$t];
  1011. }
  1012. //sort the array in order ascending
  1013. ksort($sort_list,SORT_NUMERIC);
  1014. //clear the internal array, then refill it with the now sorted courses.
  1015. $this->array_list = array();
  1016. foreach ($sort_list as $courses) {
  1017. foreach ($courses as $course) {
  1018. $this->array_list[] = $course;
  1019. }
  1020. }
  1021. $this->reset_counter();
  1022. }
  1023. /**
  1024. * Sorts the courses based on their db_group_requirement_id value
  1025. */
  1026. function sort_group_requirement_id() {
  1027. $sort_list = array();
  1028. // go through the courses, creating an array keyed by db_degree_requirement_id.
  1029. for ($t = 0; $t < count($this->array_list); $t++) {
  1030. $id = (string) $this->array_list[$t]->db_group_requirement_id; // not necessarily an integer, don't cast as one.
  1031. // 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
  1032. // number of digits.
  1033. $id = str_pad($id, 20, "0", STR_PAD_LEFT);
  1034. $sort_list[$id][] = $this->array_list[$t];
  1035. }
  1036. //sort the array in order ascending
  1037. ksort($sort_list);
  1038. //clear the internal array, then refill it with the now sorted courses.
  1039. $this->array_list = array();
  1040. foreach ($sort_list as $courses) {
  1041. foreach ($courses as $course) {
  1042. $this->array_list[] = $course;
  1043. }
  1044. }
  1045. $this->reset_counter();
  1046. }
  1047. /**
  1048. * Sorts the course list into alphabetical order. If load_descriptive_data()
  1049. * has not already been called for each course, it will call it.
  1050. *
  1051. * @param bool $bool_reverse_order
  1052. * - If set to TRUE, the list will be in reverse order.
  1053. *
  1054. * @param unknown_type $bool_only_transfers
  1055. * - Only sort the transfer courses.
  1056. *
  1057. * @param unknown_type $bool_set_array_index
  1058. * - If set to true, it will set the $course->array_index value
  1059. * to the index value in $this's array_list array.
  1060. * @param new_split_subs_higher_priority_in_degree_id
  1061. * - If the course is a split substitution for the supplied degree_id, then give it a higher "priority" so it will
  1062. * sort above courses with identical names.
  1063. *
  1064. */
  1065. 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)
  1066. {
  1067. // Sort the list into alphabetical order, based
  1068. // on the subject_id and course_num.
  1069. $tarray = array();
  1070. // Since I need the indexes, I will have to go through the array
  1071. // myself...
  1072. for ($t = 0; $t < $this->count; $t++)
  1073. {
  1074. $c = $this->array_list[$t];
  1075. if ($c == NULL) continue;
  1076. // If this is a transfer credit, make sure we load it's information
  1077. if ($c->bool_transfer == TRUE && is_object($c->course_transfer)) {
  1078. if ($c->course_transfer->subject_id == '') {
  1079. $c->course_transfer->load_descriptive_transfer_data();
  1080. }
  1081. if ($c->subject_id == '') {
  1082. $c->subject_id = $c->course_transfer->subject_id;
  1083. $c->course_num = $c->course_transfer->course_num;
  1084. }
  1085. }
  1086. if ($c->subject_id == "")
  1087. {
  1088. $c->load_descriptive_data();
  1089. }
  1090. $priority = 5; // default sort priority for courses with identical names.
  1091. if ($subs_higher_prority_in_degree_id > 0) {
  1092. if (@$c->details_by_degree_array[$subs_higher_prority_in_degree_id]["bool_substitution_new_from_split"] == TRUE
  1093. || @$c->details_by_degree_array[$subs_higher_prority_in_degree_id]["bool_substitution_split"] == TRUE
  1094. || @$c->details_by_degree_array[$subs_higher_prority_in_degree_id]["bool_substitution"] == TRUE) {
  1095. //fpm("here for $c->subject_id $c->course_num");
  1096. $priority = 3; // lower priority so it sorts higher in the list.
  1097. }
  1098. }
  1099. // Make $t at least 5 characters long, padded with zeroes on the left, so sorting works correctly. We are using it to
  1100. // find out our index later, but it is throwing off the sorting when courses have the same name. For example,
  1101. // if a course is from a split sub.
  1102. $tpad = str_pad("$t",5,"0",STR_PAD_LEFT);
  1103. $degree_title = "n"; // Default.
  1104. $degree_advising_weight = "0000";
  1105. if ($bool_include_degree_sort) {
  1106. // Find the actual degree title for this course.
  1107. if (intval($c->req_by_degree_id) > 0) {
  1108. // Get the degree title...
  1109. $dtitle = @$GLOBALS["fp_temp_degree_titles"][$c->req_by_degree_id];
  1110. $dweight = intval(@$GLOBALS["fp_temp_degree_advising_weights"][$c->req_by_degree_id]);
  1111. if ($dtitle == "" || $dweight == "" || $dweight == 0) {
  1112. $t_degree_plan = new DegreePlan($c->req_by_degree_id);
  1113. $t_degree_plan->load_descriptive_data();
  1114. $dtitle = $t_degree_plan->get_title2(TRUE, TRUE);
  1115. $dweight = $t_degree_plan->db_advising_weight;
  1116. $GLOBALS["fp_temp_degree_titles"][$c->req_by_degree_id] = $dtitle . " "; //save for next time.
  1117. $GLOBALS["fp_temp_degree_advising_weights"][$c->req_by_degree_id] = $dweight . " "; //save for next time.
  1118. }
  1119. $degree_title = fp_get_machine_readable($dtitle); // make it machine readable. No funny characters.
  1120. $degree_advising_weight = str_pad($dweight, 4, "0", STR_PAD_LEFT);
  1121. }
  1122. }
  1123. if ($bool_only_transfers == true)
  1124. {
  1125. // Rarer. We only want to sort the transfer credits. If the course doesn not
  1126. // have transfers, don't skip, just put in the original. Otherwise, we will be using
  1127. // the transfer credit's SI and CN.
  1128. if (is_object($c->course_transfer))
  1129. {
  1130. $str = $degree_advising_weight . " ~~ " . $degree_title . " ~~ " . $c->course_transfer->subject_id . " ~~ " . $c->course_transfer->course_num ." ~~ $priority ~~ $tpad";
  1131. } else {
  1132. // There was no transfer!
  1133. $str = "$degree_advising_weight ~~ $degree_title ~~ $c->subject_id ~~ $c->course_num ~~ $priority ~~ $tpad";
  1134. }
  1135. } else {
  1136. // This is the one which will be run most often. Just sort the list
  1137. // in alphabetical order.
  1138. $str = "$degree_advising_weight ~~ $degree_title ~~ $c->subject_id ~~ $c->course_num ~~ $priority ~~ $tpad";
  1139. }
  1140. array_push($tarray,$str);
  1141. }
  1142. // Now, sort the array...
  1143. //print_pre(print_r($tarray));
  1144. if ($bool_reverse_order == true)
  1145. {
  1146. rsort($tarray);
  1147. } else {
  1148. sort($tarray);
  1149. }
  1150. //print_pre(print_r($tarray));
  1151. // Now, convert the array back into a list of courses.
  1152. $new_list = new CourseList();
  1153. for($t = 0; $t < count($tarray); $t++)
  1154. {
  1155. $temp = explode(" ~~ ",$tarray[$t]);
  1156. $i = intval($temp[5]);
  1157. if ($bool_set_array_index == true)
  1158. {
  1159. $this->array_list[$i]->array_index = $i;
  1160. }
  1161. $new_list->add($this->array_list[$i]);
  1162. }
  1163. // Okay, now $new_list should contain the correct values.
  1164. // We will transfer over the reference.
  1165. $this->array_list = $new_list->array_list;
  1166. }
  1167. /**
  1168. * Returns an array of db_group_requirement_id's from the courses
  1169. * in this list.
  1170. *
  1171. * @return array
  1172. */
  1173. function get_group_requirement_id_array()
  1174. {
  1175. // Return an array of db_group_requirement_id's
  1176. // from the courses in this list, indexed by the
  1177. // id's.
  1178. $rtn_array = array();
  1179. for ($t = 0; $t < $this->count; $t++)
  1180. {
  1181. $course = $this->array_list[$t];
  1182. $rtn_array[$course->db_group_requirement_id] = true;
  1183. }
  1184. return $rtn_array;
  1185. }
  1186. /**
  1187. * Returns TRUE if this list has a course which contains
  1188. * $id for it's db_group_requirement_id property.
  1189. *
  1190. * @param int $id
  1191. * - This is the id to test for.
  1192. *
  1193. * @return bool
  1194. */
  1195. function contains_group_requirement_id($id)
  1196. {
  1197. // Returns true if the list has a course
  1198. // which contains $id for it's db_group_requirement_id.
  1199. // False if it cannot be found.
  1200. for ($t = 0; $t < $this->count; $t++)
  1201. {
  1202. $course = $this->array_list[$t];
  1203. if ($course->db_group_requirement_id == $id)
  1204. {
  1205. return true;
  1206. }
  1207. }
  1208. return false;
  1209. }
  1210. /**
  1211. * Returns the first course in the list
  1212. * which the user may select for advising. This
  1213. * method is used by the popup window to determine
  1214. * what exactly is the first element of the course list.
  1215. * (so it can make that radio button checked).
  1216. *
  1217. * Returns FALSE if it cannot find a selectable course.
  1218. *
  1219. * @return Course
  1220. */
  1221. function find_first_selectable()
  1222. {
  1223. /*
  1224. */
  1225. $temp_i = $this->i; // preserve the counter.
  1226. $this->reset_counter();
  1227. while($this->has_more())
  1228. {
  1229. $c = $this->get_next();
  1230. if ($c->bool_advised_to_take == true)
  1231. {
  1232. continue;
  1233. }
  1234. if (!$c->course_list_fulfilled_by->is_empty)
  1235. {
  1236. continue;
  1237. }
  1238. if ($c->bool_unselectable == true)
  1239. {
  1240. continue;
  1241. }
  1242. // $c is our valid course...
  1243. $this->i = $temp_i;
  1244. //print_pre($c->to_string());
  1245. return $c;
  1246. }
  1247. $this->i = $temp_i;
  1248. return false;
  1249. }
  1250. /**
  1251. * Returns TRUE if there is at least one course in this list which
  1252. * is selected (for advising).
  1253. *
  1254. * @return bool
  1255. */
  1256. function has_any_course_selected()
  1257. {
  1258. /*
  1259. Returns TRUE if there is at least one course
  1260. in this list which is "selected." FALSE, otherwise.
  1261. */
  1262. $temp_i = $this->i; // preserve the counter.
  1263. $this->reset_counter();
  1264. $rtn = false;
  1265. while($this->has_more())
  1266. {
  1267. $c = $this->get_next();
  1268. if ($c->bool_selected == true)
  1269. {
  1270. $rtn = true;
  1271. break;
  1272. }
  1273. }
  1274. $this->i = $temp_i;
  1275. return $rtn;
  1276. }
  1277. /**
  1278. * Mark every course in this list as bool_has_been_displayed = true.
  1279. * Used for making sure we don't display the same course twice on
  1280. * screen.
  1281. *
  1282. * Returns FALSE if we did not mark any courses.
  1283. *
  1284. * @param int $semester_num
  1285. * - If > -1, we will first make sure the course
  1286. * falls into this semesterNum. This way we can only
  1287. * perform this operation on a particular semester.
  1288. *
  1289. * @return bool
  1290. */
  1291. function mark_as_displayed($semester_num = -1)
  1292. {
  1293. $temp_i = $this->i; // preserve the counter.
  1294. $this->reset_counter();
  1295. $rtn = false;
  1296. while($this->has_more())
  1297. {
  1298. $c = $this->get_next();
  1299. if ($semester_num != -1)
  1300. { // A semesterNum was specified.
  1301. // Make sure the course is in the correct semester.
  1302. if ($c->assigned_to_semester_num != $semester_num)
  1303. {
  1304. continue;
  1305. }
  1306. }
  1307. $c->bool_has_been_displayed = true;
  1308. $rtn = true;
  1309. }
  1310. $this->i = $temp_i;
  1311. return $rtn;
  1312. }
  1313. /**
  1314. * Returns a CourseList of all the courses matching course_id
  1315. * that has bool_has_been_assigned == TRUE for the requested degree
  1316. *
  1317. * @param int $course_id
  1318. * @return CourseList
  1319. */
  1320. function get_previous_assignments($course_id, $degree_id = 0)
  1321. {
  1322. // Return a courseList of all the times a course matching
  1323. // course_id has the bool_has_been_assigned set to TRUE.
  1324. $rtn_list = new CourseList();
  1325. for ($t = 0; $t < $this->count; $t++)
  1326. {
  1327. $course = $this->array_list[$t];
  1328. if ($course->course_id == $course_id && $course->get_has_been_assigned_to_degree_id($degree_id) == true)
  1329. {
  1330. $rtn_list->add($course);
  1331. }
  1332. }
  1333. return $rtn_list;
  1334. }
  1335. /**
  1336. * Find the "best" match for this course, based on what
  1337. * the university considers a best match.
  1338. * This largely has to do with repeats.
  1339. * If the student has more than one credit, what is
  1340. * the "best" match?
  1341. *
  1342. * For example, at ULM we consider the best match to be the
  1343. * most recent that meets the minimum requirements.
  1344. * Other schools might simply take the best grade.
  1345. *
  1346. *
  1347. * @return Course
  1348. */
  1349. 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)
  1350. {
  1351. $rtn = FALSE;
  1352. $school_id = $course_c->school_id;
  1353. // We will look at the course_repeat_policy to determine which type of search to do on this list.
  1354. $course_repeat_policy = variable_get_for_school("course_repeat_policy", "most_recent_exclude_previous", $school_id);
  1355. if ($course_repeat_policy == "best_grade_exclude_others") {
  1356. // Search for best grade, exclude other attempts.
  1357. $rtn = $this->find_best_grade_match($course_c, $min_grade, TRUE, $degree_id, $bool_skip_already_assigned_to_degree, $bool_skip_subs, $group_id);
  1358. }
  1359. else {
  1360. // Search for most recent first, possibly mark previous as excluded.
  1361. $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);
  1362. }
  1363. return $rtn;
  1364. }
  1365. /**
  1366. * Adds the supplied CourseList to the bottom of $this's list.
  1367. *
  1368. * @param CourseList $course_l
  1369. */
  1370. function add_list(CourseList $course_l) {
  1371. $c = count($course_l->array_list);
  1372. for ($t = 0; $t < $c; $t++)
  1373. {
  1374. $this->add($course_l->array_list[$t]);
  1375. }
  1376. }
  1377. /**
  1378. * Returns hour many hours are in $this CourseList.
  1379. *
  1380. * @param string $requirement_type
  1381. * - If specified, we will only count courses which match this
  1382. * requirement_type.
  1383. *
  1384. * @param bool $bool_use_ignore_list
  1385. * @return int
  1386. */
  1387. 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)
  1388. {
  1389. // Returns how many hours are being represented in this courseList.
  1390. // A requirement type of "uc" is the same as "c"
  1391. // (university capstone is a core requirement)
  1392. $count = 0;
  1393. for ($t = 0; $t < $this->count; $t++)
  1394. {
  1395. $course = $this->array_list[$t];
  1396. // Does this course belong to the same degree we are interested in? If not, skip it.
  1397. if ($degree_id > 0) {
  1398. if ($course->req_by_degree_id != $degree_id && $course->get_has_been_assigned_to_degree_id($degree_id) != TRUE) continue;
  1399. }
  1400. $school_id = $course->school_id;
  1401. if ($bool_use_ignore_list == true)
  1402. {
  1403. // Do ignore some courses...
  1404. $temp_course_name = $course->subject_id . " " . $course->course_num;
  1405. // Check in our settings to see if we should ignore this course
  1406. // (configured in /custom/settings.php)
  1407. if (in_array($temp_course_name, csv_to_array(@variable_get_for_school("ignore_courses_from_hour_counts", "", $school_id)))) {
  1408. continue;
  1409. }
  1410. // Also, if the course's requirement_type is "x" it means we should ignore it.
  1411. if ($course->requirement_type == 'x') continue;
  1412. }
  1413. if ($course->get_bool_substitution_new_from_split($degree_id) == TRUE)
  1414. {
  1415. // Do not count the possible fragments that are created
  1416. // from a new substitution split. This is causing problems
  1417. // in getting accurate numbers on the pie charts.
  1418. // BUT-- only skip if this new fragment isn't also being
  1419. // substituted somewhere else!
  1420. if ($course->get_bool_substitution($degree_id) == FALSE)
  1421. { // not being used in another sub, so skip it.
  1422. continue;
  1423. }
  1424. }
  1425. $h_get_hours = $course->get_hours($degree_id);
  1426. if ($bool_correct_ghost_hour) {
  1427. // If this course has a ghosthour, then use the
  1428. // hours_awarded (probably 1). However, if it was substituted,
  1429. // then we actually want the 0 hour. Confusing, isn't it?
  1430. if ($course->bool_ghost_hour) {
  1431. $h_get_hours = $course->get_hours_awarded($degree_id);
  1432. }
  1433. }
  1434. if ($bool_force_zero_hours_to_one_hour) {
  1435. // We want to force anything with a 0 hour to be 1 hour.
  1436. // Helps when selecting 0 hour courses from groups.
  1437. if ($h_get_hours == 0) {
  1438. $h_get_hours = 1;
  1439. }
  1440. }
  1441. // Make sure we aren't trying to exclude any transfer credits.
  1442. if ($bool_exclude_all_transfer_credits) {
  1443. if ($course->bool_transfer) {
  1444. continue;
  1445. }
  1446. // Is this a requirement which has been fulfilled by a course? And if so, is THAT course a transfer?
  1447. if ($course->course_list_fulfilled_by->is_empty == false) {
  1448. $cc = $course->course_list_fulfilled_by->get_first();
  1449. if ($cc->bool_transfer) {
  1450. continue;
  1451. }
  1452. }
  1453. }
  1454. if ($requirement_type == "")
  1455. {
  1456. $count = $count + $h_get_hours;
  1457. }
  1458. else {
  1459. // Requirement Type not blank, so only count these hours
  1460. // if it has the set requirement type.
  1461. if ($course->requirement_type == $requirement_type)
  1462. {
  1463. $count = $count + $h_get_hours;
  1464. continue;
  1465. }
  1466. // For specifically "university capstone" courses (which have a 'u' in front)...
  1467. if ($course->requirement_type == "u" . $requirement_type)
  1468. {
  1469. $count = $count + $h_get_hours;
  1470. }
  1471. }
  1472. }
  1473. return $count;
  1474. }
  1475. /**
  1476. * Removes courses which have neither been fulfilled or advised.
  1477. *
  1478. */
  1479. function remove_unfulfilled_and_unadvised_courses()
  1480. {
  1481. // remove courses from THIS list
  1482. // which have not been fulfilled AND
  1483. // are not currently advised.
  1484. $rtn_list = new CourseList();
  1485. for ($t = 0; $t < $this->count; $t++)
  1486. {
  1487. $course = $this->array_list[$t];
  1488. if ($course->course_list_fulfilled_by->is_empty == false)
  1489. {
  1490. // something IS fulfilling it!
  1491. $rtn_list->add($course);
  1492. } else if ($course->bool_advised_to_take == true)
  1493. {
  1494. // Was not being fulfilled, but, it was advised
  1495. // to take.
  1496. $rtn_list->add($course);
  1497. }
  1498. }
  1499. $this->array_list = $rtn_list->array_list;
  1500. $this->reset_counter();
  1501. }
  1502. /**
  1503. * Removes courses from this list which have not been fulfilled
  1504. * (ther course_list_fulfilled_by is empty).
  1505. *
  1506. */
  1507. function remove_unfulfilled_courses()
  1508. {
  1509. // remove courses in THIS list
  1510. // which have nothing in their course_list_fulfilled_by
  1511. // object.
  1512. $rtn_list = new CourseList();
  1513. for ($t = 0; $t < $this->count; $t++)
  1514. {
  1515. $course = $this->array_list[$t];
  1516. if ($course->course_list_fulfilled_by->is_empty == false)
  1517. {
  1518. $rtn_list->add($course);
  1519. }
  1520. }
  1521. $this->array_list = $rtn_list->array_list;
  1522. $this->reset_counter();
  1523. }
  1524. /**
  1525. * Returns a clone CourseList of $this.
  1526. *
  1527. * @param bool $bool_return_new_courses
  1528. * - If set to TRUE, it will create new Course objects
  1529. * based on the course_id's of the ones in $this's list.
  1530. * If set to FALSE, this will add the exact same Course
  1531. * objects by reference to the new list.
  1532. *
  1533. * @return CourseList
  1534. */
  1535. function get_clone($bool_return_new_courses = FALSE)
  1536. {
  1537. // This will return a clone of this list.
  1538. // If boolReturnNewCourses is true, then it will
  1539. // return a new list of new instances of courses
  1540. // from this list.
  1541. $rtn_list = new CourseList();
  1542. for ($t = 0; $t < $this->count; $t++)
  1543. {
  1544. $course = $this->array_list[$t];
  1545. if ($bool_return_new_courses)
  1546. {
  1547. $new_course = new Course();
  1548. $new_course->course_id = $course->course_id;
  1549. $rtn_list->add($new_course);
  1550. } else {
  1551. $rtn_list->add($course);
  1552. }
  1553. }
  1554. return $rtn_list;
  1555. }
  1556. /**
  1557. * Returns a CourseList of all the fulfilled or advised courses
  1558. * in $this's list.
  1559. *
  1560. * @param bool $bool_return_new_courses
  1561. * - Works the same as get_clone()'s boolReturnNewCourses
  1562. * variable.
  1563. *
  1564. * @return Course
  1565. */
  1566. function get_fulfilled_or_advised($bool_return_new_courses = false)
  1567. {
  1568. $rtn_list = new CourseList();
  1569. for ($t = 0; $t < $this->count; $t++)
  1570. {
  1571. $course = $this->array_list[$t];
  1572. $add_course = $course;
  1573. if ($bool_return_new_courses == true)
  1574. {
  1575. $add_course = new Course();
  1576. $add_course->course_id = $course->course_id;
  1577. }
  1578. if ($course->bool_advised_to_take == true)
  1579. {
  1580. $rtn_list->add($add_course);
  1581. }
  1582. // Several ways to tell if a course is here by credit...
  1583. if (!$course->course_list_fulfilled_by->is_empty) {
  1584. $rtn_list->add($add_course);
  1585. }
  1586. else if ($course->grade != "") {
  1587. $rtn_list->add($add_course);
  1588. }
  1589. else if ($course->get_bool_substitution() == true) {
  1590. $rtn_list->add($add_course);
  1591. }
  1592. }
  1593. return $rtn_list;
  1594. }
  1595. /**
  1596. * Returns the number of courses in this list which have either
  1597. * been fulfilled or advised to take. It does not count hours,
  1598. * just the courses themselves.
  1599. *
  1600. * @return int
  1601. */
  1602. function count_fulfilled_or_advised()
  1603. {
  1604. // This function returns the number of courses in this
  1605. // courseList which is either fulfilled or has been advised
  1606. // to take. It does care about hours, just the number of
  1607. // courses themselves.
  1608. $count = 0;
  1609. for ($t = 0; $t < $this->count; $t++)
  1610. {
  1611. $course = $this->array_list[$t];
  1612. if ($course->bool_advised_to_take == true)
  1613. {
  1614. $count++;
  1615. }
  1616. // Several ways to tell if a course is here by credit...
  1617. if (!$course->course_list_fulfilled_by->is_empty)
  1618. {
  1619. $count++;
  1620. } else if ($course->grade != "") {
  1621. $count++;
  1622. } else if ($course->bool_substitution == true)
  1623. {
  1624. $count++;
  1625. }
  1626. }
  1627. return $count;
  1628. }
  1629. /**
  1630. * Returns a CourseList of courses which have bool_advised_to_take == true.
  1631. *
  1632. * @return CourseList
  1633. */
  1634. function get_advised_courses_list()
  1635. {
  1636. // Return a courseList object of courses in THIS
  1637. // list which have bool_advised_to_take == true.
  1638. $rtn_list = new CourseList();
  1639. for ($t = 0; $t < $this->count; $t++)
  1640. {
  1641. $course = $this->array_list[$t];
  1642. if ($course->bool_advised_to_take == true)
  1643. {
  1644. $rtn_list->add($course);
  1645. }
  1646. }
  1647. return $rtn_list;
  1648. }
  1649. /**
  1650. * Similar to count_hours, but this will only count courses
  1651. * which have been taken and have a grade.
  1652. *
  1653. * @param string $requirement_type
  1654. * - If set, we will only look for courses matching this requirement_type.
  1655. *
  1656. * @param bool $bool_use_ignore_list
  1657. * @param bool $bool_ignore_enrolled
  1658. * @return int
  1659. */
  1660. 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)
  1661. {
  1662. // Similar to count_hours, but this will only
  1663. // count courses which have been taken (have a grade).
  1664. $count = 0;
  1665. $qpts_grades = NULL;
  1666. $retake_grades = $enrolled_grades = NULL;
  1667. for ($t = 0; $t < $this->count; $t++)
  1668. {
  1669. $course = $this->array_list[$t];
  1670. // Does this course belong to the same degree we are interested in? If not, skip it.
  1671. if ($degree_id > 0) {
  1672. if ($course->req_by_degree_id != $degree_id && $course->get_has_been_assigned_to_degree_id($degree_id) != TRUE) continue;
  1673. }
  1674. $school_id = $course->school_id;
  1675. // Now that we have a school_id, let's figure out some variables....
  1676. if (!$retake_grades || !$enrolled_grades) {
  1677. $retake_grades = csv_to_array(variable_get_for_school("retake_grades", 'F,W,I', $school_id));
  1678. $enrolled_grades = csv_to_array(variable_get_for_school("enrolled_grades",'E', $school_id));
  1679. }
  1680. if (!$qpts_grades) {
  1681. $tlines = explode("\n", variable_get_for_school("quality_points_grades", "A ~ 4\nB ~ 3\nC ~ 2\nD ~ 1\nF ~ 0\nI ~ 0", $school_id));
  1682. foreach ($tlines as $tline) {
  1683. $temp = explode("~", trim($tline));
  1684. if (trim($temp[0]) != "") {
  1685. $qpts_grades[trim($temp[0])] = trim($temp[1]);
  1686. }
  1687. }
  1688. }
  1689. if ($bool_use_ignore_list == true)
  1690. {
  1691. // Do ignore some courses...
  1692. $temp_course_name = $course->subject_id . " " . $course->course_num;
  1693. // Check in our settings to see if we should ignore this course
  1694. // (configured in /custom/settings.php)
  1695. if (in_array($temp_course_name, csv_to_array(@variable_get_for_school("ignore_courses_from_hour_counts", "", $school_id)))) {
  1696. continue;
  1697. }
  1698. // Also, if the course's requirement_type is "x" it means we should ignore it.
  1699. if ($course->requirement_type == 'x') continue;
  1700. }
  1701. if ($bool_ignore_enrolled == true)
  1702. {
  1703. if (in_array($course->grade, $enrolled_grades)) {
  1704. continue;
  1705. }
  1706. }
  1707. // Only allowing grades which we have quality points for?
  1708. if ($bool_qpts_grades_only) {
  1709. if ($course->grade != "" && !isset($qpts_grades[$course->grade])) {
  1710. continue;
  1711. }
  1712. }
  1713. else {
  1714. // Is this grade a "retake" grade? If so, skip it.
  1715. if (in_array($course->grade, $retake_grades)) continue;
  1716. }
  1717. // Correct the course's requirement type, if needed (remove the "u")
  1718. $cr_type = $course->requirement_type;
  1719. $cr_type = str_replace("u", "", $cr_type);
  1720. if ($course->grade != "")// || !($course->course_list_fulfilled_by->is_empty))
  1721. {
  1722. // Make sure we aren't trying to exclude any transfer credits.
  1723. if ($bool_exclude_all_transfer_credits) {
  1724. if ($course->bool_transfer) {
  1725. continue;
  1726. }
  1727. // Is this a requirement which has been fulfilled by a course? And if so, is THAT course a transfer?
  1728. if ($course->course_list_fulfilled_by->is_empty == false) {
  1729. $cc = $course->course_list_fulfilled_by->get_first();
  1730. if ($cc->bool_transfer) {
  1731. continue;
  1732. }
  1733. }
  1734. }
  1735. // If we require the grade to be a qpts_grade, then check that now.
  1736. if ($bool_qpts_grades_only && !isset($qpts_grades[$course->grade])) {
  1737. continue;
  1738. }
  1739. // Do our requirement types match?
  1740. if ($requirement_type == "" || ($requirement_type != "" && $requirement_type == $cr_type))
  1741. {
  1742. $h = $course->get_hours();
  1743. $count = $count + $h;
  1744. }
  1745. }
  1746. else {
  1747. // maybe it's a substitution?
  1748. if ($requirement_type == "" || ($requirement_type != "" && $requirement_type == $cr_type))
  1749. {
  1750. if ($course->course_list_fulfilled_by->is_empty == false)
  1751. {
  1752. $cc = $course->course_list_fulfilled_by->get_first();
  1753. if ($cc->get_bool_substitution())
  1754. {
  1755. // If we require the grade to be a qpts_grade, then check that now.
  1756. if ($bool_qpts_grades_only && !isset($qpts_grades[$cc->grade])) {
  1757. continue;
  1758. }
  1759. // Make sure we aren't trying to exclude any transfer credits.
  1760. if ($bool_exclude_all_transfer_credits && $cc->bool_transfer) {
  1761. //fpm($requirement_type);
  1762. //fpm($cc);
  1763. continue;
  1764. }
  1765. $h = $cc->get_substitution_hours();
  1766. if ($cc->bool_ghost_hour) {
  1767. $h = 0;
  1768. }
  1769. $count = $count + $h;
  1770. }
  1771. }
  1772. }
  1773. }
  1774. }
  1775. return $count;
  1776. }
  1777. /**
  1778. * Similar to count_credit_hours, but this will only count courses
  1779. * which have been taken and have a grade. We will return back
  1780. * a sum of their quality points.
  1781. *
  1782. * @param string $requirement_type
  1783. * - If set, we will only look for courses matching this requirement_type.
  1784. *
  1785. * @param bool $bool_use_ignore_list
  1786. * @param bool $bool_ignore_enrolled
  1787. * @return int
  1788. */
  1789. 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)
  1790. {
  1791. $points = 0;
  1792. for ($t = 0; $t < $this->count; $t++)
  1793. {
  1794. $course = $this->array_list[$t];
  1795. // Does this course belong to the same degree we are interested in? If not, skip it.
  1796. if ($degree_id > 0) {
  1797. if ($course->req_by_degree_id != $degree_id && $course->get_has_been_assigned_to_degree_id($degree_id) != TRUE) continue;
  1798. }
  1799. $school_id = $course->school_id;
  1800. // Correct the course's requirement type, if needed (remove the "u")
  1801. $cr_type = $course->requirement_type;
  1802. $cr_type = str_replace("u", "", $cr_type);
  1803. if ($bool_use_ignore_list == true)
  1804. {
  1805. // Do ignore some courses...
  1806. $temp_course_name = $course->subject_id . " " . $course->course_num;
  1807. // Check in our settings to see if we should ignore this course
  1808. // (configured in /custom/settings.php)
  1809. if (in_array($temp_course_name, csv_to_array(@variable_get_for_school("ignore_courses_from_hour_counts", "", $school_id)))) {
  1810. continue;
  1811. }
  1812. // Also, if the course's requirement_type is "x" it means we should ignore it.
  1813. if ($course->requirement_type == 'x') continue;
  1814. }
  1815. if ($bool_ignore_enrolled == true)
  1816. {
  1817. if ($course->is_completed() == false)
  1818. {
  1819. if ($course->course_list_fulfilled_by->is_empty)
  1820. {
  1821. continue;
  1822. } else {
  1823. if ($course->course_list_fulfilled_by->get_first()->is_completed() == false)
  1824. {
  1825. continue;
  1826. }
  1827. }
  1828. }
  1829. }
  1830. if ($course->grade != "")
  1831. {
  1832. // Make sure we aren't trying to exclude any transfer credits.
  1833. if ($bool_exclude_all_transfer_credits) {
  1834. if ($course->bool_transfer) {
  1835. continue;
  1836. }
  1837. // Is this a requirement which has been fulfilled by a course? And if so, is THAT course a transfer?
  1838. if ($course->course_list_fulfilled_by->is_empty == false) {
  1839. $cc = $course->course_list_fulfilled_by->get_first();
  1840. if ($cc->bool_transfer) {
  1841. continue;
  1842. }
  1843. }
  1844. }
  1845. if ($requirement_type == "")
  1846. {
  1847. $p = $course->get_quality_points($degree_id);
  1848. $points = $points + $p;
  1849. } else {
  1850. if ($cr_type == $requirement_type)
  1851. {
  1852. $p = $course->get_quality_points($degree_id);
  1853. $points = $points + $p;
  1854. continue;
  1855. }
  1856. }
  1857. }
  1858. else {
  1859. // maybe it's a substitution?
  1860. if (($requirement_type == "") || ($requirement_type != "" && $requirement_type == $cr_type))
  1861. {
  1862. if ($course->course_list_fulfilled_by->is_empty == false)
  1863. {
  1864. $cc = $course->course_list_fulfilled_by->get_first();
  1865. if ($cc->get_bool_substitution($degree_id))
  1866. {
  1867. // Make sure we aren't trying to exclude any transfer credits.
  1868. if ($bool_exclude_all_transfer_credits) {
  1869. if ($cc->bool_transfer) {
  1870. //fpm($course);
  1871. continue;
  1872. }
  1873. }
  1874. //$h = $cc->substitution_hours;
  1875. //if ($cc->bool_ghost_hour) {
  1876. // $h = 0;
  1877. //}
  1878. // What are the quality points for this course?
  1879. $p = $cc->get_quality_points($degree_id);
  1880. $points = $points + $p;
  1881. }
  1882. }
  1883. }
  1884. }
  1885. }
  1886. return $points;
  1887. }
  1888. /**
  1889. * Assign a groupID to every course in the list.
  1890. *
  1891. * @param int $group_id
  1892. */
  1893. function assign_group_id($group_id)
  1894. {
  1895. for ($t = 0; $t < $this->count; $t++)
  1896. {
  1897. $course = $this->array_list[$t];
  1898. //$course->assigned_to_group_id = $group_id;
  1899. $course->assigned_to_group_ids_array[$group_id] = $group_id;
  1900. }
  1901. }
  1902. /**
  1903. * Assign a semesterNum to every course in the list.
  1904. *
  1905. * @param int $semester_num
  1906. */
  1907. function assign_semester_num($semester_num)
  1908. {
  1909. for ($t = 0; $t < $this->count; $t++)
  1910. {
  1911. $course = $this->array_list[$t];
  1912. $course->assigned_to_semester_num = $semester_num;
  1913. }
  1914. }
  1915. /**
  1916. * Sets the bool_has_been_assigned property of every course in
  1917. * the list.
  1918. *
  1919. * @param bool $bool_has_been_assigned
  1920. * - What to set each course's->boolhasBeenAssigned property
  1921. * to.
  1922. *
  1923. */
  1924. function set_has_been_assigned($bool_has_been_assigned = true)
  1925. {
  1926. // Set the bool_has_been_assigned for all items
  1927. // in this list.
  1928. for ($t = 0; $t < $this->count; $t++)
  1929. {
  1930. $course = $this->array_list[$t];
  1931. $course->bool_has_been_assigned = $bool_has_been_assigned;
  1932. }
  1933. }
  1934. /**
  1935. * Set's each course's bool_substitution value.
  1936. *
  1937. * @param bool $bool_s
  1938. * - What to set each course's bool_substitution value to.
  1939. */
  1940. function set_bool_substitution($degree_id = 0, $bool_s = true)
  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->set_bool_substitution($degree_id, $bool_s);
  1948. }
  1949. }
  1950. /**
  1951. * Set all the courses in this list to have the same "req_by_degree_id" value.
  1952. */
  1953. function set_req_by_degree_id($degree_id = 0)
  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->req_by_degree_id = $degree_id;
  1961. }
  1962. }
  1963. /**
  1964. * Set all the courses in this list to have the same "requirement_type" value.
  1965. */
  1966. function set_requirement_type($requirement_type = "")
  1967. {
  1968. // Set the bool_substitution for all items
  1969. // in this list.
  1970. for ($t = 0; $t < $this->count; $t++)
  1971. {
  1972. $course = $this->array_list[$t];
  1973. $course->requirement_type = $requirement_type;
  1974. }
  1975. }
  1976. /**
  1977. * Sets each course's $course_substitution value to the supplied
  1978. * Course object.
  1979. *
  1980. * @param Course $course_s
  1981. * @param string $sub_remarks
  1982. */
  1983. function set_course_substitution(Course $course_s, $sub_remarks = "", $degree_id = 0)
  1984. {
  1985. for ($t = 0; $t < $this->count; $t++)
  1986. {
  1987. $course = $this->array_list[$t];
  1988. $course->set_course_substitution($degree_id, $course_s);
  1989. $course->req_by_degree_id = $course_s->req_by_degree_id; // match it up to the degree its being subbed for
  1990. $course->sub_remarks = $sub_remarks;
  1991. }
  1992. }
  1993. /**
  1994. * Go through the list and decrement the specified_repeats
  1995. * value for all instances of Course $course.
  1996. *
  1997. * @param Course $course
  1998. */
  1999. function dec_specified_repeats(Course $course, $bool_ignore_infinite_repeats = TRUE) {
  2000. // Go through the list, and decrement the specified_repeats
  2001. // value for all instances of $course.
  2002. for ($t = 0; $t < $this->count; $t++)
  2003. {
  2004. $course2 = $this->array_list[$t];
  2005. if ($course2->course_id == $course->course_id)
  2006. {
  2007. if ($bool_ignore_infinite_repeats && $course2->specified_repeats == Group::GROUP_COURSE_INFINITE_REPEATS) continue;
  2008. $course2->specified_repeats--;
  2009. }
  2010. }
  2011. }
  2012. /**
  2013. * Go through the list and set the specified_repeats value to $num
  2014. * for all instances of $course.
  2015. *
  2016. * @param Course $course
  2017. * @param int $num
  2018. */
  2019. function set_specified_repeats(Course $course, $num)
  2020. {
  2021. for ($t = 0; $t < $this->count; $t++)
  2022. {
  2023. $course2 = $this->array_list[$t];
  2024. if ($course2->course_id == $course->course_id)
  2025. {
  2026. $course2->specified_repeats = $num;
  2027. $course2->bool_specified_repeats = true;
  2028. }
  2029. }
  2030. }
  2031. /**
  2032. * Removes excluded courses from the list (courses that
  2033. * have db_exclude == 1)
  2034. *
  2035. */
  2036. function remove_excluded()
  2037. {
  2038. // Removes courses from the list that have a db_exclude == 1.
  2039. $new_list = new CourseList();
  2040. // Do this by adding elements to an array.
  2041. // course_id => index in list.
  2042. for ($t = 0; $t < $this->count; $t++)
  2043. {
  2044. $course = $this->array_list[$t];
  2045. if ($course->subject_id == "")
  2046. { // load descriptive data (include exclude info)
  2047. $course->load_descriptive_data();
  2048. }
  2049. if ($course->db_exclude == 1)
  2050. {
  2051. continue;
  2052. }
  2053. $new_list->add($course);
  2054. }
  2055. $this->array_list = $new_list->array_list;
  2056. $this->reset_counter();
  2057. }
  2058. /**
  2059. * Remove occurances of the course in the course list.
  2060. *
  2061. * If a limit is higher than zero, we will STOP after that limit has been reached.
  2062. */
  2063. function remove_course_with_course_id($course_id, $limit = 0) {
  2064. // If the limit is 0, set it to an int's max, which is around 2 billion (32bit) or 9 quintillion (64 bit).
  2065. // Either way, it's effectively infinite for FlightPath in this purpose.
  2066. if ($limit == 0) $limit = PHP_INT_MAX;
  2067. $new_list = new CourseList();
  2068. $c = 0;
  2069. for ($t = 0; $t < $this->count; $t++)
  2070. {
  2071. $course = $this->array_list[$t];
  2072. if ($course == null)
  2073. {
  2074. continue;
  2075. }
  2076. if ($c < $limit && intval($course->course_id) == intval($course_id)) {
  2077. // We found the course. Since we do not want it to be part of the list,
  2078. // we will skip adding it to the new_list.
  2079. $c++;
  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 all courses which are not assigned to this degree_id.
  2091. */
  2092. function remove_courses_not_in_degree($degree_id) {
  2093. $new_list = new CourseList();
  2094. for ($t = 0; $t < $this->count; $t++)
  2095. {
  2096. $course = $this->array_list[$t];
  2097. if ($course == null)
  2098. {
  2099. continue;
  2100. }
  2101. if ($course->req_by_degree_id != $degree_id) {
  2102. continue;
  2103. }
  2104. // Otherwise, let's add it to the new_list.
  2105. $new_list->add($course);
  2106. }
  2107. // Switch over the reference.
  2108. $this->array_list = $new_list->array_list;
  2109. $this->reset_counter();
  2110. }
  2111. /**
  2112. * Removes null's and duplicate courses from the list.
  2113. *
  2114. */
  2115. function remove_duplicates()
  2116. {
  2117. // Go through and remove duplicates from the list.
  2118. // Also remove null's
  2119. $tarray = array();
  2120. $new_list = new CourseList();
  2121. // Do this by adding elements to an array.
  2122. // course_id => index in list.
  2123. for ($t = 0; $t < $this->count; $t++)
  2124. {
  2125. $course = $this->array_list[$t];
  2126. if ($course == null)
  2127. {
  2128. continue;
  2129. }
  2130. $tarray[$course->course_id] = -1;
  2131. }
  2132. for ($t = 0; $t < $this->count; $t++)
  2133. {
  2134. $course = $this->array_list[$t];
  2135. if ($course == null)
  2136. {
  2137. continue;
  2138. }
  2139. //if (is_object($course->courseFulfilledBy))
  2140. if (!($course->course_list_fulfilled_by->is_empty))
  2141. {
  2142. $tarray[$course->course_id] = $t;
  2143. continue;
  2144. }
  2145. if ($tarray[$course->course_id]*1 < 0)
  2146. {
  2147. $tarray[$course->course_id] = $t;
  2148. }
  2149. }
  2150. // Now, go through tarray and rebuild the newList.
  2151. foreach($tarray as $course_id => $i)
  2152. {
  2153. $new_list->add($this->array_list[$i]);
  2154. }
  2155. // Switch over the reference.
  2156. $this->array_list = $new_list->array_list;
  2157. $this->reset_counter();
  2158. }
  2159. } // end class CourseList

Classes

Namesort descending Description
CourseList