_CourseList.php

Classes

NameDescription
_CourseList

File

classes/_CourseList.php
View source
  1. <?php
  2. require_once("ObjList.php");
  3. class _CourseList extends ObjList
  4. {
  5. // This inherits most of its classes from ObjList,
  6. // but, it has to be able to do special functions
  7. // specific to Courses. Use parent:: to access
  8. // a parent function within ObjList.
  9. // Example: parent::indexOf();
  10. //public $arrayCourseIDList = array();
  11. /**
  12. * Used to cast a regular ObjList object into a CourseList.
  13. *
  14. * @param ObjList $obj
  15. *
  16. * @return CourseList
  17. */
  18. static public function cast(ObjList $obj)
  19. { // This can be used to cast a regular ObjList
  20. // into a CourseList object.
  21. // Use the syntax: CourseList::cast($x);
  22. $new_c_l = new CourseList();
  23. $new_c_l->array_list = $obj->array_list;
  24. $new_c_l->is_empty = $obj->is_empty;
  25. $new_c_l->reset_counter();
  26. return $new_c_l;
  27. }
  28. /**
  29. * Give every course in the list a minimum grade.
  30. *
  31. * @param string $min_grade
  32. */
  33. function assign_min_grade($min_grade)
  34. {
  35. // Go through the list and give every course the specified
  36. // min grade.
  37. for ($t = 0; $t < $this->count; $t++)
  38. {
  39. $course = $this->array_list[$t];
  40. $course->min_grade = $min_grade;
  41. }
  42. }
  43. /**
  44. * Go through the list and find any course whose hours are greater
  45. * than $hours. Make that course "unselectable." Used in the groups.
  46. *
  47. * For example, if a student may only select 3 hours from a group, we don't
  48. * want to give them the option of selecting a 5 hour course. But we also
  49. * don't want to remove that course either. We want to display it so they
  50. * know it was an option (and possibly need to substitute or move things
  51. * around if they need it).
  52. *
  53. * Returns TRUE if anything got assigned, FALSE if nothing got assigned.
  54. *
  55. * @param int $hours
  56. *
  57. * @return bool
  58. */
  59. function assign_unselectable_courses_with_hours_greater_than($hours)
  60. {
  61. // Go through the list and assign bool_unselectable courses whose minHour
  62. // is greater than $hours.
  63. // Returns TRUE if it did assign something,
  64. // false if it didn't.
  65. $bool_assigned = false;
  66. for ($t = 0; $t < $this->count; $t++)
  67. {
  68. $course = $this->array_list[$t];
  69. if ($course->subject_id == "")
  70. {
  71. $course->load_descriptive_data();
  72. }
  73. if ($course->min_hours > $hours)
  74. {
  75. $course->bool_unselectable = true;
  76. $bool_assigned = true;
  77. }
  78. }
  79. return $bool_assigned;
  80. }
  81. /**
  82. * Find and return a specific course from the list.
  83. *
  84. * @param int $course_id
  85. * - The course_id to look for. Do not set if using
  86. * $use_course.
  87. *
  88. * @param int $term_id
  89. * - The term_id for the course to look for. Do not set if using
  90. * $use_course.
  91. *
  92. * @param bool $bool_transfer
  93. * - Is the course we are looking for a transfer course? Do not
  94. * use if using $use_course.
  95. *
  96. * @param bool $bool_exclude_substitutions
  97. * - If TRUE, we will not consider courses which have been used
  98. * in a substitution.
  99. *
  100. * @param Course $use_course
  101. * - Optional. If you already have a course object which can be used
  102. * as a template to search for, specify it here. Otherwise, set to
  103. * NULL. If using this, then $course_id, $term_id, and $bool_transfer
  104. * will be ignored.
  105. *
  106. *
  107. * @return Course
  108. */
  109. function find_specific_course($course_id = 0, $term_id = 0, $bool_transfer = false, $bool_exclude_substitutions = true, Course $use_course = null)
  110. {
  111. if ($use_course != null && is_object($use_course))
  112. {
  113. $course_id = $use_course->course_id;
  114. $term_id = $use_course->term_id;
  115. $bool_transfer = $use_course->bool_transfer;
  116. }
  117. // Look through the array for a course with this id, termId, and
  118. // transfer credit status.
  119. for ($t = 0; $t < $this->count; $t++)
  120. {
  121. $course = $this->array_list[$t];
  122. $check_course_id = $course->course_id;
  123. if ($bool_transfer == true && is_object($course->course_transfer))
  124. {
  125. $check_course_id = $course->course_transfer->course_id;
  126. }
  127. if ($check_course_id == $course_id && $course->term_id == $term_id && $course->bool_transfer == $bool_transfer)
  128. {
  129. if ($bool_exclude_substitutions == true)
  130. {
  131. if ($course->bool_substitution == true)
  132. {
  133. continue;
  134. }
  135. }
  136. return $course;
  137. }
  138. }
  139. return false;
  140. }
  141. /**
  142. * Call the $course->load_course_descriptive_data() on
  143. * every course in the list.
  144. *
  145. */
  146. function load_course_descriptive_data()
  147. {
  148. // Call the load_descriptive_data() method
  149. // for every course in the list.
  150. for ($t = 0; $t < $this->count; $t++)
  151. {
  152. $course = $this->array_list[$t];
  153. $course->load_descriptive_data();
  154. }
  155. }
  156. /**
  157. * Using the parent's function of find_all_matches, this
  158. * will return a CourseList of all courses which match
  159. * the Course object.
  160. *
  161. * @param Course $course_c
  162. * @return CourseList
  163. */
  164. function find_all_matches(Course $course_c)
  165. {
  166. if (!$list_matches = parent::find_all_matches($course_c))
  167. {
  168. return false;
  169. }
  170. $list_matches = CourseList::cast($list_matches);
  171. return $list_matches;
  172. }
  173. /**
  174. * Returns a match to the Course courseC which does
  175. * not have any courses fulfilling it. Usefull for finding
  176. * course requirement matches in a list which have not
  177. * yet been assigned.
  178. *
  179. * @param Course $course_c
  180. * @return Course
  181. */
  182. function find_first_unfulfilled_match(Course $course_c)
  183. {
  184. // Returns match to courseC which does not have
  185. // any courses fulfilling it. Useful for finding
  186. // course requirement matches in a list which have not
  187. // yet been assigned.
  188. for ($t = 0; $t < $this->count; $t++)
  189. {
  190. if ($this->array_list[$t]->equals($course_c) && $this->array_list[$t]->course_list_fulfilled_by->is_empty == true)
  191. {
  192. return $this->array_list[$t];
  193. }
  194. }
  195. return false;
  196. }
  197. /**
  198. * Go through the list and set the $bool_exclude_repeat flag to TRUE
  199. * for all matches of $course in this list.
  200. *
  201. * Returns FALSE if no matches could be found.
  202. *
  203. * @param Course $course
  204. * @return bool
  205. */
  206. function mark_repeats_exclude(Course $course)
  207. {
  208. // Set the bool_exclude_repeat flag to TRUE for all
  209. // occurances of $course in THIS list.
  210. if (!$list_matches = parent::find_all_matches($course))
  211. {
  212. return false;
  213. }
  214. $list_matches = CourseList::cast($list_matches);
  215. $list_matches->reset_counter();
  216. while($list_matches->has_more())
  217. {
  218. $c = $list_matches->get_next();
  219. $c->bool_exclude_repeat = true;
  220. }
  221. return true;
  222. }
  223. /**
  224. * Find a list of matches to Course courseC, which fulfill
  225. * the min_grade requirement, ordered by most recently taken.
  226. *
  227. * Returns FALSE if no matches were found, else it will
  228. * return the matched Course object.
  229. *
  230. * @param Course $course_c
  231. * @param string $min_grade
  232. * @param bool $bool_mark_repeats_exclude
  233. *
  234. * @return Course
  235. */
  236. function find_most_recent_match(Course $course_c, $min_grade = "D", $bool_mark_repeats_exclude = false)
  237. {
  238. // Get a list of all matches to courseC, and
  239. // then order them by the most recently taken course
  240. // first.
  241. // We should, too, check for minimum grades here
  242. // as well.
  243. if (!$list_matches = parent::find_all_matches($course_c))
  244. {
  245. return false;
  246. }
  247. $list_matches = CourseList::cast($list_matches);
  248. // Don't just return if it's only got a size of 1,
  249. // so that it forces it to do the min grade checking.
  250. /* if ($list_matches->getSize() == 1)
  251. {
  252. return $list_matches->get_next();
  253. }
  254. */
  255. if ($list_matches->is_empty)
  256. {
  257. return false;
  258. }
  259. // If we are here, then we have more than one match.
  260. // Meaning, we have more than one class which might fit
  261. // into this course requirement.
  262. // Sort the courses into most recently taken first.
  263. $list_matches->sort_most_recent_first();
  264. // So, now that it's sorted, we should look through the list,
  265. // checking the min grade requirements (if any). When we find
  266. // a good one, we will select it.
  267. $list_matches->reset_counter();
  268. while($list_matches->has_more())
  269. {
  270. $c = $list_matches->get_next();
  271. if ($c->bool_exclude_repeat == true)
  272. {
  273. continue;
  274. }
  275. //////////////////////////////////////////
  276. /// Check for min grade, etc, here.
  277. if (!$c->meets_min_grade_requirement_of(null, $min_grade))
  278. {
  279. if ($bool_mark_repeats_exclude == true)
  280. {
  281. // Since this course does not meet the min_grade,
  282. // check to see if it may be repeated. If it can't,
  283. // then we must mark ALL previous attempts at this
  284. // course as being excluded from further consideration.
  285. // (ULM policy on repeats).
  286. // We don't do this consideration if they simply
  287. // withdrew from a course...
  288. if ($c->grade == "W") { continue; }
  289. if ($c->min_hours < 1 || $c->min_hours == "") {
  290. $c->load_descriptive_data(); // make sure we get hour data for this course.
  291. }
  292. if ($c->repeat_hours <= $c->min_hours)
  293. {
  294. // No repeats.
  295. $this->mark_repeats_exclude($c);
  296. return false;
  297. } else {
  298. // Repeats allowed, so just continue.
  299. continue;
  300. }
  301. } else {
  302. continue;
  303. }
  304. }
  305. // Has the course already been assigned?
  306. if ($c->bool_has_been_assigned)
  307. { // Skip over it. Now, this is an important part here, because actually, we should
  308. // only skip it (and look at the next one) if this course is allowed to be
  309. // repeated. If it cannot be repeated, or if the student has taken the
  310. // maximum allowed hours, then we should return false right here.
  311. continue;
  312. }
  313. return $c;
  314. }
  315. return false;
  316. }
  317. /**
  318. * @todo implement this function.
  319. *
  320. */
  321. function sort_best_grade_first()
  322. {
  323. // This will look very similar to sort_most_recent_first
  324. // when I get a chance to fool with it.
  325. }
  326. /**
  327. * Remove courses from THIS list which appear in listCourses under
  328. * these conditions:
  329. * - the listCourses->"assigned_to_group_id" != $group_id
  330. * This function is being used primarily with $list_courses being the
  331. * list of courses that students have taken.
  332. * Also checking substitutions for courses substituted into groups.
  333. * @param CourseList $list_courses
  334. * @param int $group_id
  335. * @param bool $bool_keep_repeatable_courses
  336. * @param SubstitutionList $list_substitutions
  337. */
  338. function remove_previously_fulfilled(CourseList $list_courses, $group_id, $bool_keep_repeatable_courses = true, $list_substitutions)
  339. {
  340. $rtn_list = new CourseList();
  341. for ($t = 0; $t < $this->count; $t++)
  342. {
  343. $course = $this->array_list[$t];
  344. if ($bool_keep_repeatable_courses == true)
  345. { // We can always keep repeatable courses in the list.
  346. if ($course->repeat_hours > $course->min_hours)
  347. {
  348. $rtn_list->add($course);
  349. continue;
  350. }
  351. }
  352. // Has the course been substituted?
  353. if ($test_sub = $list_substitutions->find_requirement($course,false, -1))
  354. {
  355. // it WAS substituted, so we should NOT add it to our
  356. // rtnList.
  357. continue;
  358. }
  359. // Okay, now check if $course is anywhere in $list_courses
  360. if ($test_course = $list_courses->find_match($course))
  361. {
  362. // Yes, it found a match.
  363. // I am taking out this part where I say if it is in
  364. // this group then we can keep it. I think that shouldn't
  365. // be in.
  366. // This course is in another group, so do nothing
  367. // and skip it.
  368. // perhaps the course is on the degreePlan in excess with a W
  369. // or F?
  370. if (!$test_course->meets_min_grade_requirement_of(null, "D"))
  371. {
  372. // Meaning, this was a failed attempt, so we can add
  373. // our original course back in.
  374. $rtn_list->add($course);
  375. continue;
  376. }
  377. // perhaps this course was purposefully excluded from
  378. // this list because it did not meet the min grade
  379. // requirements? If this is the case, $course should
  380. // still appear in THIS list.
  381. if (!$test_course->meets_min_grade_requirement_of($course))
  382. {
  383. // Meaning, this was attempt did not meet the
  384. // min grade of the original requirement, so we can add
  385. // our original requirement back in.
  386. $rtn_list->add($course);
  387. continue;
  388. }
  389. } else {
  390. // The course was NOT found in the courseList,
  391. // so its safe to add it back in.
  392. $rtn_list->add($course);
  393. }
  394. }
  395. $this->array_list = $rtn_list->array_list;
  396. $this->reset_counter();
  397. }
  398. /**
  399. * Returns an array containing the unique subject_id's of
  400. * the courses in this list. Its assumed to be ordered
  401. * already!
  402. *
  403. * @param bool $bool_ignore_excluded
  404. * @return array
  405. */
  406. function get_course_subjects($bool_ignore_excluded = true)
  407. {
  408. // returns an array containing the unique subject_id's
  409. // of the courses in this list.
  410. // IMPORTANT: The list is assumed to be ordered already! Either
  411. // alphabetically or reverse alphabetically.
  412. $old_subject_id = "";
  413. $rtn_array = array();
  414. for ($t = 0; $t < $this->count; $t++)
  415. {
  416. $course = $this->array_list[$t];
  417. if ($course->subject_id == "")
  418. {
  419. $course->load_descriptive_data();
  420. }
  421. // Go through all valid names for this course.
  422. for ($x = 0; $x < count($course->array_valid_names); $x++)
  423. {
  424. $temp = explode("~",$course->array_valid_names[$x]);
  425. $subj = strtoupper($temp[0]);
  426. if (in_array($subj, $rtn_array))
  427. { // skip ones with subjects we have already looked at.
  428. continue;
  429. }
  430. if ($course->db_exclude == 1)
  431. {
  432. continue;
  433. }
  434. // We have a new subject. Add it to the array.
  435. $rtn_array[] = $subj;
  436. }
  437. }
  438. return $rtn_array;
  439. }
  440. /**
  441. * Go through the courseList and take out any course
  442. * which does not have the $subject as its subject_id.
  443. *
  444. * @param string $subject
  445. * @param bool $bool_reassign_valid_name
  446. * - If set to TRUE, we will look at other possible valid names
  447. * for this course. If we find one, we will reassign the course's
  448. * subject_id and course_num to the new valid name.
  449. *
  450. */
  451. function exclude_all_subjects_except($subject, $bool_reassign_valid_name = true)
  452. {
  453. $new_course_list = new CourseList();
  454. for ($t = 0; $t < $this->count; $t++)
  455. {
  456. $course = $this->array_list[$t];
  457. if ($course->subject_id == $subject)
  458. {
  459. $new_course_list->add($course);
  460. continue;
  461. }
  462. // Not the right subject-- but perhaps the course has another
  463. // valid name with this subject? Ex: CSCI 373 and MATH 373.
  464. if ($bool_reassign_valid_name == true && count($course->array_valid_names) > 1)
  465. {
  466. for ($x = 0; $x < count($course->array_valid_names); $x++)
  467. {
  468. if (strstr($course->array_valid_names[$x], $subject))
  469. {
  470. $temp = explode("~",$course->array_valid_names[$x]);
  471. $course->subject_id = $temp[0];
  472. $course->course_num = $temp[1];
  473. $new_course_list->add($course);
  474. continue;
  475. }
  476. }
  477. }
  478. }
  479. // Now, transfer ownership of the arraylist.
  480. $this->array_list = $new_course_list->array_list;
  481. }
  482. /**
  483. * This re-sorts the CourseList so that fulfilled courses
  484. * are first, in alphabetical order, followed by
  485. * unfulfilled courses, in alphabetical order.
  486. * This is most useful for making the groups
  487. * show up correctly.
  488. *
  489. */
  490. function sort_fulfilled_first_alphabetical()
  491. {
  492. $tarray = array();
  493. for ($t = 0; $t < $this->count; $t++)
  494. {
  495. //if (!is_object($this->array_list[$t]->courseFulfilledBy))
  496. if ($this->array_list[$t]->course_list_fulfilled_by->is_empty == true)
  497. { // Skip if not fulfilled.
  498. continue;
  499. }
  500. $c = $this->array_list[$t];
  501. $str = "$c->subject_id ~~ $c->course_num ~~ $t";
  502. array_push($tarray,$str);
  503. }
  504. sort($tarray);
  505. $new_list = new CourseList();
  506. for($t = 0; $t < count($tarray); $t++)
  507. {
  508. $temp = explode(" ~~ ",$tarray[$t]);
  509. $i = $temp[2];
  510. $new_list->add($this->array_list[$i]);
  511. }
  512. // Alright, now we do it again, but with unfulfilled courses.
  513. $tarray = array();
  514. for ($t = 0; $t < $this->count; $t++)
  515. {
  516. //if (is_object($this->array_list[$t]->courseFulfilledBy))
  517. if ($this->array_list[$t]->course_list_fulfilled_by->is_empty != true)
  518. { // Skip if fulfilled.
  519. continue;
  520. }
  521. $c = $this->array_list[$t];
  522. $str = "$c->subject_id ~~ $c->course_num ~~ $t";
  523. array_push($tarray,$str);
  524. }
  525. sort($tarray);
  526. $new_list2 = new CourseList();
  527. for($t = 0; $t < count($tarray); $t++)
  528. {
  529. $temp = explode(" ~~ ",$tarray[$t]);
  530. $i = $temp[2];
  531. $new_list2->add($this->array_list[$i]);
  532. }
  533. // Now, combine the two lists.
  534. $new_list->add_list($new_list2);
  535. // And, transfer the newList into this list.
  536. $this->array_list = $new_list->array_list;
  537. }
  538. /**
  539. * This re-sorts the CourseList so that advised courses
  540. * are last, in alphabetical order, preceeded by
  541. * unfulfilled courses, in alphabetical order.
  542. *
  543. *
  544. */
  545. function sort_advised_last_alphabetical()
  546. {
  547. $tarray = array();
  548. for ($t = 0; $t < $this->count; $t++)
  549. {
  550. if ($this->array_list[$t]->bool_advised_to_take == true)
  551. { // Skip if not fulfilled.
  552. continue;
  553. }
  554. $c = $this->array_list[$t];
  555. $str = "$c->subject_id ~~ $c->course_num ~~ $t";
  556. array_push($tarray,$str);
  557. }
  558. sort($tarray);
  559. // Alright, now we do it again, but with advised courses.
  560. $t2array = array();
  561. for ($t = 0; $t < $this->count; $t++)
  562. {
  563. if ($this->array_list[$t]->bool_advised_to_take == false)
  564. { // Skip if not advised
  565. continue;
  566. }
  567. $c = $this->array_list[$t];
  568. $str = "$c->subject_id ~~ $c->course_num ~~ $t";
  569. array_push($t2array,$str);
  570. }
  571. sort($t2array);
  572. $t3array = array_merge($tarray, $t2array);
  573. $new_list = new CourseList();
  574. for($t = 0; $t < count($t3array); $t++)
  575. {
  576. $temp = explode(" ~~ ",$t3array[$t]);
  577. $i = $temp[2];
  578. $new_list->add($this->array_list[$i]);
  579. }
  580. // And, transfer the newList into this list.
  581. $this->array_list = $new_list->array_list;
  582. }
  583. /**
  584. * This function will resort this courselist for which a substitution
  585. * has been made in listSubstitutions.
  586. *
  587. * @param SubstitutionList $list_substitutions
  588. * @param int $group_id
  589. */
  590. function sort_substitutions_first($list_substitutions, $group_id = 0)
  591. {
  592. // This will sort courses in a list for which
  593. // a substitution has been made in listSubstitutions.
  594. // It will place those courses at the top of the list.
  595. $top_array = array();
  596. // Since I need the indexes, I will have to go through the array
  597. // myself...
  598. for ($t = 0; $t < $this->count; $t++)
  599. {
  600. $c = $this->array_list[$t];
  601. // So-- does this course have a substitution somewhere in
  602. // the list (for the supplied groupID) ?
  603. if ($substitution = $list_substitutions->find_requirement($c, true, $group_id))
  604. {
  605. // yes, there is a sub for this group (or bare degree plan)
  606. $top_array[] = $t;
  607. }
  608. }
  609. // Okay, we now have, in the topArray, a list of indexes which should
  610. // appear at the top.
  611. $new_list = new CourseList();
  612. for ($j = 0; $j < count($top_array); $j++)
  613. {
  614. $new_list->add($this->array_list[$top_array[$j]]);
  615. }
  616. // Now, add everything else in the array (except indecies
  617. // appearing in topArray)
  618. for ($t = 0; $t < $this->count; $t++)
  619. {
  620. if (in_array($t, $top_array))
  621. {
  622. continue;
  623. }
  624. $new_list->add($this->array_list[$t]);
  625. }
  626. $this->array_list = $new_list->array_list;
  627. $new_list->reset_counter();
  628. }
  629. /**
  630. * This will sort so that courses with the smallest hours
  631. * (first trying hours_awarded, then min_hours)
  632. * are at the top of the list. If the list contains more
  633. * than one course with a set of hours (like there are 30
  634. * courses all worth 3 hours) then it orders those as
  635. * most-recently-taken first.
  636. *
  637. */
  638. function sort_smallest_hours_first()
  639. {
  640. $tarray = array();
  641. // Since I need the indexes, I will have to go through the array
  642. // myself...
  643. for ($t = 0; $t < $this->count; $t++)
  644. {
  645. $c = $this->array_list[$t];
  646. $hours = $c->hours_awarded*1;
  647. if ($hours < 1)
  648. {
  649. $hours = $c->min_hours*1;
  650. }
  651. $str = "$hours ~~ $t";
  652. array_push($tarray,$str);
  653. }
  654. // Now, sort the array...
  655. //print_pre(print_r($tarray));
  656. sort($tarray);
  657. //print_pre(print_r($tarray));
  658. // Now, convert the array back into a list of courses.
  659. $new_list = new CourseList();
  660. for($t = 0; $t < count($tarray); $t++)
  661. {
  662. $temp = explode(" ~~ ",$tarray[$t]);
  663. $i = $temp[1];
  664. $new_list->add($this->array_list[$i]);
  665. }
  666. // Okay, now $new_list should contain the correct values.
  667. // We will transfer over the reference.
  668. $this->array_list = $new_list->array_list;
  669. }
  670. /**
  671. * This method will sort by the most recently taken
  672. * courses (determined by the term_id).
  673. * The easiest way I can think to do this is to temporarily
  674. * put their term_id's and index#'s into an array, and then
  675. * have PHP sort the array itself. PHP's sorting algorithm
  676. * is faster than anything I can program right now, anyway.
  677. *
  678. * @param bool $bool_maintain_alpha_order
  679. */
  680. function sort_most_recent_first($bool_maintain_alpha_order = true)
  681. {
  682. $tarray = array();
  683. // Since I need the indexes, I will have to go through the array
  684. // myself...
  685. for ($t = 0; $t < $this->count; $t++)
  686. {
  687. $c = $this->array_list[$t];
  688. $cn = "";
  689. if ($bool_maintain_alpha_order == true)
  690. {
  691. // We say 1000- the course number in order to give
  692. // us the complement of the number. That is so it will
  693. // reverse-sort in the correct order. Strange, but it fixes
  694. // a small display issue where PHYS 207 and PHYS 209, taken at
  695. // the same time, causes PHYS 209 to be displayed first.
  696. // We also reverse the subject_id, again, so that
  697. // MATH will be sorted above ZOOL, when taken at the same time.
  698. // This might not work at all, though...
  699. $cn = strrev($c->subject_id) . "," . (1000 - $c->course_num);
  700. }
  701. $str = "$c->term_id ~~ $cn ~~ $t";
  702. array_push($tarray,$str);
  703. }
  704. // Now, sort the array...
  705. rsort($tarray);
  706. // Now, convert the array back into a list of courses.
  707. $new_list = new CourseList();
  708. for($t = 0; $t < count($tarray); $t++)
  709. {
  710. $temp = explode(" ~~ ",$tarray[$t]);
  711. $i = $temp[2];
  712. $new_list->add($this->array_list[$i]);
  713. }
  714. // Okay, now $new_list should contain the correct values.
  715. // We will transfer over the reference.
  716. $this->array_list = $new_list->array_list;
  717. }
  718. /**
  719. * Convienence function. It simply calls sort_alphabetical_order(), but
  720. * passes the boolean value to make it be reversed.
  721. *
  722. */
  723. function sort_reverse_alphabetical_order()
  724. {
  725. $this->sort_alphabetical_order(true);
  726. }
  727. /**
  728. * Sorts the course list into alphabetical order. If load_descriptive_data()
  729. * has not already been called for each course, it will call it.
  730. *
  731. * @param bool $bool_reverse_order
  732. * - If set to TRUE, the list will be in reverse order.
  733. *
  734. * @param unknown_type $bool_only_transfers
  735. * - Only sort the transfer courses.
  736. *
  737. * @param unknown_type $bool_set_array_index
  738. * - If set to true, it will set the $course->array_index value
  739. * to the index value in $this's array_list array.
  740. *
  741. */
  742. function sort_alphabetical_order($bool_reverse_order = false, $bool_only_transfers = false, $bool_set_array_index = false)
  743. {
  744. // Sort the list into alphabetical order, based
  745. // on the subject_id and course_num.
  746. $tarray = array();
  747. // Since I need the indexes, I will have to go through the array
  748. // myself...
  749. for ($t = 0; $t < $this->count; $t++)
  750. {
  751. $c = $this->array_list[$t];
  752. if ($c->subject_id == "")
  753. {
  754. $c->load_descriptive_data();
  755. }
  756. if ($bool_only_transfers == true)
  757. {
  758. // Rarer. We only want to sort the transfer credits. If the course doesn not
  759. // have transfers, don't skip, just put in the original. Otherwise, we will be using
  760. // the transfer credit's SI and CN.
  761. if (is_object($c->course_transfer))
  762. {
  763. $str = $c->course_transfer->subject_id . " ~~ " . $c->course_transfer->course_num ." ~~ $t";
  764. } else {
  765. // There was no transfer!
  766. $str = "$c->subject_id ~~ $c->course_num ~~ $t";
  767. }
  768. } else {
  769. // This is the one which will be run most often. Just sort the list
  770. // in alphabetical order.
  771. $str = "$c->subject_id ~~ $c->course_num ~~ $t";
  772. }
  773. array_push($tarray,$str);
  774. }
  775. // Now, sort the array...
  776. //print_pre(print_r($tarray));
  777. if ($bool_reverse_order == true)
  778. {
  779. rsort($tarray);
  780. } else {
  781. sort($tarray);
  782. }
  783. //print_pre(print_r($tarray));
  784. // Now, convert the array back into a list of courses.
  785. $new_list = new CourseList();
  786. for($t = 0; $t < count($tarray); $t++)
  787. {
  788. $temp = explode(" ~~ ",$tarray[$t]);
  789. $i = $temp[2];
  790. if ($bool_set_array_index == true)
  791. {
  792. $this->array_list[$i]->array_index = $i;
  793. }
  794. $new_list->add($this->array_list[$i]);
  795. }
  796. // Okay, now $new_list should contain the correct values.
  797. // We will transfer over the reference.
  798. $this->array_list = $new_list->array_list;
  799. }
  800. /**
  801. * Returns an array of db_group_requirement_id's from the courses
  802. * in this list.
  803. *
  804. * @return array
  805. */
  806. function get_group_requirement_id_array()
  807. {
  808. // Return an array of db_group_requirement_id's
  809. // from the courses in this list, indexed by the
  810. // id's.
  811. $rtn_array = array();
  812. for ($t = 0; $t < $this->count; $t++)
  813. {
  814. $course = $this->array_list[$t];
  815. $rtn_array[$course->db_group_requirement_id] = true;
  816. }
  817. return $rtn_array;
  818. }
  819. /**
  820. * Returns TRUE if this list has a course which contains
  821. * $id for it's db_group_requirement_id property.
  822. *
  823. * @param int $id
  824. * - This is the id to test for.
  825. *
  826. * @return bool
  827. */
  828. function contains_group_requirement_id($id)
  829. {
  830. // Returns true if the list has a course
  831. // which contains $id for it's db_group_requirement_id.
  832. // False if it cannot be found.
  833. for ($t = 0; $t < $this->count; $t++)
  834. {
  835. $course = $this->array_list[$t];
  836. if ($course->db_group_requirement_id == $id)
  837. {
  838. return true;
  839. }
  840. }
  841. return false;
  842. }
  843. /**
  844. * Returns the first course in the list
  845. * which the user may select for advising. This
  846. * method is used by the popup window to determine
  847. * what exactly is the first element of the course list.
  848. * (so it can make that radio button checked).
  849. *
  850. * Returns FALSE if it cannot find a selectable course.
  851. *
  852. * @return Course
  853. */
  854. function find_first_selectable()
  855. {
  856. /*
  857. */
  858. $temp_i = $this->i; // preserve the counter.
  859. $this->reset_counter();
  860. while($this->has_more())
  861. {
  862. $c = $this->get_next();
  863. if ($c->bool_advised_to_take == true)
  864. {
  865. continue;
  866. }
  867. if (!$c->course_list_fulfilled_by->is_empty)
  868. {
  869. continue;
  870. }
  871. if ($c->bool_unselectable == true)
  872. {
  873. continue;
  874. }
  875. // $c is our valid course...
  876. $this->i = $temp_i;
  877. //print_pre($c->to_string());
  878. return $c;
  879. }
  880. $this->i = $temp_i;
  881. return false;
  882. }
  883. /**
  884. * Returns TRUE if there is at least one course in this list which
  885. * is selected (for advising).
  886. *
  887. * @return bool
  888. */
  889. function has_any_course_selected()
  890. {
  891. /*
  892. Returns TRUE if there is at least one course
  893. in this list which is "selected." FALSE, otherwise.
  894. */
  895. $temp_i = $this->i; // preserve the counter.
  896. $this->reset_counter();
  897. $rtn = false;
  898. while($this->has_more())
  899. {
  900. $c = $this->get_next();
  901. if ($c->bool_selected == true)
  902. {
  903. $rtn = true;
  904. break;
  905. }
  906. }
  907. $this->i = $temp_i;
  908. return $rtn;
  909. }
  910. /**
  911. * Mark every course in this list as bool_has_been_displayed = true.
  912. * Used for making sure we don't display the same course twice on
  913. * screen.
  914. *
  915. * Returns FALSE if we did not mark any courses.
  916. *
  917. * @param int $semester_num
  918. * - If > -1, we will first make sure the course
  919. * falls into this semesterNum. This way we can only
  920. * perform this operation on a particular semester.
  921. *
  922. * @return bool
  923. */
  924. function mark_as_displayed($semester_num = -1)
  925. {
  926. $temp_i = $this->i; // preserve the counter.
  927. $this->reset_counter();
  928. $rtn = false;
  929. while($this->has_more())
  930. {
  931. $c = $this->get_next();
  932. if ($semester_num != -1)
  933. { // A semesterNum was specified.
  934. // Make sure the course is in the correct semester.
  935. if ($c->assigned_to_semester_num != $semester_num)
  936. {
  937. continue;
  938. }
  939. }
  940. $c->bool_has_been_displayed = true;
  941. $rtn = true;
  942. }
  943. $this->i = $temp_i;
  944. return $rtn;
  945. }
  946. /**
  947. * Returns a CourseList of all the courses matching course_id
  948. * that has bool_has_been_assigned == TRUE.
  949. *
  950. * @param int $course_id
  951. * @return CourseList
  952. */
  953. function get_previous_assignments($course_id)
  954. {
  955. // Return a courseList of all the times a course matching
  956. // course_id has the bool_has_been_assigned set to TRUE.
  957. $rtn_list = new CourseList();
  958. for ($t = 0; $t < $this->count; $t++)
  959. {
  960. $course = $this->array_list[$t];
  961. if ($course->course_id == $course_id && $course->bool_has_been_assigned == true)
  962. {
  963. $rtn_list->add($course);
  964. }
  965. }
  966. return $rtn_list;
  967. }
  968. /**
  969. * Find the "best" match for this course, based on what
  970. * the university considers a best match.
  971. * This largely has to do with repeats.
  972. * If the student has more than one credit, what is
  973. * the "best" match?
  974. *
  975. * For example, at ULM we consider the best match to be the
  976. * most recent that meets the minimum requirements.
  977. * Other schools might simply take the best grade.
  978. *
  979. * @param Course $course_c
  980. * @param string $min_grade
  981. * @param bool $bool_mark_repeats_exclude
  982. *
  983. * @return Course
  984. */
  985. function find_best_match(Course $course_c, $min_grade = "D", $bool_mark_repeats_exclude = false)
  986. {
  987. return $this->find_most_recent_match($course_c, $min_grade, $bool_mark_repeats_exclude);
  988. }
  989. /**
  990. * Adds the supplied CourseList to the bottom of $this's list.
  991. *
  992. * @param CourseList $course_l
  993. */
  994. function add_list(CourseList $course_l)
  995. {
  996. for ($t = 0; $t < count($course_l->array_list); $t++)
  997. {
  998. $this->add($course_l->array_list[$t]);
  999. }
  1000. }
  1001. /**
  1002. * Returns hour many hours are in $this CourseList.
  1003. *
  1004. * @todo The ignore list should be database-based. Should just get it
  1005. * from the settings.
  1006. *
  1007. * @param string $requirement_type
  1008. * - If specified, we will only count courses which match this
  1009. * requirement_type.
  1010. *
  1011. * @param bool $bool_use_ignore_list
  1012. * @return int
  1013. */
  1014. function count_hours($requirement_type = "", $bool_use_ignore_list = false, $bool_correct_ghost_hour = true, $bool_force_zero_hours_to_one_hour = false)
  1015. {
  1016. // Returns how many hours are being represented in this courseList.
  1017. // A requirement type of "uc" is the same as "c"
  1018. // (university capstone is a core requirement)
  1019. $count = 0;
  1020. for ($t = 0; $t < $this->count; $t++)
  1021. {
  1022. $course = $this->array_list[$t];
  1023. if ($bool_use_ignore_list == true)
  1024. {
  1025. // Do ignore some courses...
  1026. $temp_course_name = $course->subject_id . " " . $course->course_num;
  1027. // Check in our settings to see if we should ignore this course
  1028. // (configured in /custom/settings.php)
  1029. if (in_array($temp_course_name, csv_to_array($GLOBALS["fp_system_settings"]["ignore_courses_from_hour_counts"]))) {
  1030. continue;
  1031. }
  1032. }
  1033. if ($course->bool_substitution_new_from_split == true)
  1034. {
  1035. // Do not count the possible fragments that are created
  1036. // from a new substitution split. This is causing problems
  1037. // in getting accurate numbers on the pie charts.
  1038. // BUT-- only skip if this new fragment isn't also being
  1039. // substituted somewhere else!
  1040. if ($course->bool_substitution == false)
  1041. { // not being used in another sub, so skip it.
  1042. continue;
  1043. }
  1044. }
  1045. $h_get_hours = $course->get_hours();
  1046. if ($bool_correct_ghost_hour) {
  1047. // If this course has a ghosthour, then use the
  1048. // hours_awarded (probably 1). However, if it was substituted,
  1049. // then we actually want the 0 hour. Confusing, isn't it?
  1050. if ($course->bool_ghost_hour) {
  1051. $h_get_hours = $course->hours_awarded;
  1052. }
  1053. }
  1054. if ($bool_force_zero_hours_to_one_hour) {
  1055. // We want to force anything with a 0 hour to be 1 hour.
  1056. // Helps when selecting 0 hour courses from groups.
  1057. if ($h_get_hours == 0) {
  1058. $h_get_hours = 1;
  1059. }
  1060. }
  1061. if ($requirement_type == "")
  1062. {
  1063. $count = $count + $h_get_hours;
  1064. } else {
  1065. // Requirement Type not blank, so only count these hours
  1066. // if it has the set requirement type.
  1067. if ($course->requirement_type == $requirement_type)
  1068. {
  1069. $count = $count + $h_get_hours;
  1070. continue;
  1071. }
  1072. // For specifically "university capstone" courses...
  1073. if ($course->requirement_type == "uc" && $requirement_type == "c")
  1074. {
  1075. $count = $count + $h_get_hours;
  1076. }
  1077. if ($course->requirement_type == "um" && $requirement_type == "m")
  1078. {
  1079. $count = $count + $h_get_hours;
  1080. }
  1081. }
  1082. }
  1083. return $count;
  1084. }
  1085. /**
  1086. * Removes courses which have neither been fulfilled or advised.
  1087. *
  1088. */
  1089. function remove_unfulfilled_and_unadvised_courses()
  1090. {
  1091. // remove courses from THIS list
  1092. // which have not been fulfilled AND
  1093. // are not currently advised.
  1094. $rtn_list = new CourseList();
  1095. for ($t = 0; $t < $this->count; $t++)
  1096. {
  1097. $course = $this->array_list[$t];
  1098. if ($course->course_list_fulfilled_by->is_empty == false)
  1099. {
  1100. // something IS fulfilling it!
  1101. $rtn_list->add($course);
  1102. } else if ($course->bool_advised_to_take == true)
  1103. {
  1104. // Was not being fulfilled, but, it was advised
  1105. // to take.
  1106. $rtn_list->add($course);
  1107. }
  1108. }
  1109. $this->array_list = $rtn_list->array_list;
  1110. $this->reset_counter();
  1111. }
  1112. /**
  1113. * Removes courses from this list which have not been fulfilled
  1114. * (ther course_list_fulfilled_by is empty).
  1115. *
  1116. */
  1117. function remove_unfulfilled_courses()
  1118. {
  1119. // remove courses in THIS list
  1120. // which have nothing in their course_list_fulfilled_by
  1121. // object.
  1122. $rtn_list = new CourseList();
  1123. for ($t = 0; $t < $this->count; $t++)
  1124. {
  1125. $course = $this->array_list[$t];
  1126. if ($course->course_list_fulfilled_by->is_empty == false)
  1127. {
  1128. $rtn_list->add($course);
  1129. }
  1130. }
  1131. $this->array_list = $rtn_list->array_list;
  1132. $this->reset_counter();
  1133. }
  1134. /**
  1135. * Returns a clone CourseList of $this.
  1136. *
  1137. * @param bool $bool_return_new_courses
  1138. * - If set to TRUE, it will create new Course objects
  1139. * based on the course_id's of the ones in $this's list.
  1140. * If set to FALSE, this will add the exact same Course
  1141. * objects by reference to the new list.
  1142. *
  1143. * @return CourseList
  1144. */
  1145. function get_clone($bool_return_new_courses = false)
  1146. {
  1147. // This will return a clone of this list.
  1148. // If boolReturnNewCourses is true, then it will
  1149. // return a new list of new instances of courses
  1150. // from this list.
  1151. $rtn_list = new CourseList();
  1152. for ($t = 0; $t < $this->count; $t++)
  1153. {
  1154. $course = $this->array_list[$t];
  1155. if ($bool_return_new_courses == true)
  1156. {
  1157. $new_course = new Course();
  1158. $new_course->course_id = $course->course_id;
  1159. $rtn_list->add($new_course);
  1160. } else {
  1161. $rtn_list->add($course);
  1162. }
  1163. }
  1164. return $rtn_list;
  1165. }
  1166. /**
  1167. * Returns a CourseList of all the fulfilled or advised courses
  1168. * in $this's list.
  1169. *
  1170. * @param bool $bool_return_new_courses
  1171. * - Works the same as get_clone()'s boolReturnNewCourses
  1172. * variable.
  1173. *
  1174. * @return Course
  1175. */
  1176. function get_fulfilled_or_advised($bool_return_new_courses = false)
  1177. {
  1178. $rtn_list = new CourseList();
  1179. for ($t = 0; $t < $this->count; $t++)
  1180. {
  1181. $course = $this->array_list[$t];
  1182. $add_course = $course;
  1183. if ($bool_return_new_courses == true)
  1184. {
  1185. $add_course = new Course();
  1186. $add_course->course_id = $course->course_id;
  1187. }
  1188. if ($course->bool_advised_to_take == true)
  1189. {
  1190. $rtn_list->add($add_course);
  1191. }
  1192. // Several ways to tell if a course is here by credit...
  1193. if (!$course->course_list_fulfilled_by->is_empty)
  1194. {
  1195. $rtn_list->add($add_course);
  1196. } else if ($course->grade != "") {
  1197. $rtn_list->add($add_course);
  1198. } else if ($course->bool_substitution == true)
  1199. {
  1200. $rtn_list->add($add_course);
  1201. }
  1202. }
  1203. return $rtn_list;
  1204. }
  1205. /**
  1206. * Returns the number of courses in this list which have either
  1207. * been fulfilled or advised to take. It does not count hours,
  1208. * just the courses themselves.
  1209. *
  1210. * @return int
  1211. */
  1212. function count_fulfilled_or_advised()
  1213. {
  1214. // This function returns the number of courses in this
  1215. // courseList which is either fulfilled or has been advised
  1216. // to take. It does care about hours, just the number of
  1217. // courses themselves.
  1218. $count = 0;
  1219. for ($t = 0; $t < $this->count; $t++)
  1220. {
  1221. $course = $this->array_list[$t];
  1222. if ($course->bool_advised_to_take == true)
  1223. {
  1224. $count++;
  1225. }
  1226. // Several ways to tell if a course is here by credit...
  1227. if (!$course->course_list_fulfilled_by->is_empty)
  1228. {
  1229. $count++;
  1230. } else if ($course->grade != "") {
  1231. $count++;
  1232. } else if ($course->bool_substitution == true)
  1233. {
  1234. $count++;
  1235. }
  1236. }
  1237. return $count;
  1238. }
  1239. /**
  1240. * Returns a CourseList of courses which have bool_advised_to_take == true.
  1241. *
  1242. * @return CourseList
  1243. */
  1244. function get_advised_courses_list()
  1245. {
  1246. // Return a courseList object of courses in THIS
  1247. // list which have bool_advised_to_take == true.
  1248. $rtn_list = new CourseList();
  1249. for ($t = 0; $t < $this->count; $t++)
  1250. {
  1251. $course = $this->array_list[$t];
  1252. if ($course->bool_advised_to_take == true)
  1253. {
  1254. $rtn_list->add($course);
  1255. }
  1256. }
  1257. return $rtn_list;
  1258. }
  1259. /**
  1260. * Similar to count_hours, but this will only count courses
  1261. * which have been taken and have a grade.
  1262. *
  1263. * @todo ignore list should be db-based, in the settings.
  1264. *
  1265. * @param string $requirement_type
  1266. * - If set, we will only look for courses matching this requirement_type.
  1267. *
  1268. * @param bool $bool_use_ignore_list
  1269. * @param bool $bool_ignore_enrolled
  1270. * @return int
  1271. */
  1272. function count_credit_hours($requirement_type = "", $bool_use_ignore_list = false, $bool_ignore_enrolled = false, $bool_qpts_grades_only = FALSE)
  1273. {
  1274. // Similar to count_hours, but this will only
  1275. // count courses which have been taken (have a grade).
  1276. $count = 0;
  1277. // Let's find out what our quality point grades & values are...
  1278. $qpts_grades = array();
  1279. $tlines = explode("\n", variable_get("quality_points_grades", "A ~ 4\nB ~ 3\nC ~ 2\nD ~ 1\nF ~ 0\nI ~ 0"));
  1280. foreach ($tlines as $tline) {
  1281. $temp = explode("~", trim($tline));
  1282. if (trim($temp[0]) != "") {
  1283. $qpts_grades[trim($temp[0])] = trim($temp[1]);
  1284. }
  1285. }
  1286. $enrolled_grades = csv_to_array($GLOBALS["fp_system_settings"]["enrolled_grades"]);
  1287. $retake_grades = csv_to_array($GLOBALS["fp_system_settings"]["retake_grades"]);
  1288. for ($t = 0; $t < $this->count; $t++)
  1289. {
  1290. $course = $this->array_list[$t];
  1291. if ($bool_use_ignore_list == true)
  1292. {
  1293. // Do ignore some courses...
  1294. $temp_course_name = $course->subject_id . " " . $course->course_num;
  1295. // Check in our settings to see if we should ignore this course
  1296. // (configured in /custom/settings.php)
  1297. if (in_array($temp_course_name, csv_to_array($GLOBALS["fp_system_settings"]["ignore_courses_from_hour_counts"]))) {
  1298. continue;
  1299. }
  1300. }
  1301. if ($bool_ignore_enrolled == true)
  1302. {
  1303. if (in_array($course->grade, $enrolled_grades)) {
  1304. continue;
  1305. }
  1306. /*
  1307. if ($course->is_completed() == false)
  1308. {
  1309. if ($course->course_list_fulfilled_by->is_empty)
  1310. {
  1311. continue;
  1312. } else {
  1313. if ($course->course_list_fulfilled_by->get_first()->is_completed() == false)
  1314. {
  1315. continue;
  1316. }
  1317. }
  1318. }
  1319. */
  1320. }
  1321. // Only allowing grades which we have quality points for?
  1322. if ($bool_qpts_grades_only) {
  1323. if ($course->grade != "" && !isset($qpts_grades[$course->grade])) {
  1324. continue;
  1325. }
  1326. }
  1327. else {
  1328. // Is this grade a "retake" grade? If so, skip it.
  1329. if (in_array($course->grade, $retake_grades)) continue;
  1330. }
  1331. if ($course->grade != "")// || !($course->course_list_fulfilled_by->is_empty))
  1332. {
  1333. // If we require the grade to be a qpts_grade, then check that now.
  1334. if ($bool_qpts_grades_only && !isset($qpts_grades[$course->grade])) {
  1335. continue;
  1336. }
  1337. if ($requirement_type == "")
  1338. {
  1339. $h = $course->get_hours();
  1340. $count = $count + $h;
  1341. } else {
  1342. if ($course->requirement_type == $requirement_type)
  1343. {
  1344. $count = $count + $course->get_hours();
  1345. continue;
  1346. }
  1347. // For specifically "university capstone" courses...
  1348. if ($course->requirement_type == "uc" && $requirement_type == "c")
  1349. {
  1350. $count = $count + $course->get_hours();
  1351. }
  1352. if ($course->requirement_type == "um" && $requirement_type == "m")
  1353. {
  1354. $count = $count + $course->get_hours();
  1355. }
  1356. }
  1357. } else {
  1358. // maybe it's a substitution?
  1359. if ($requirement_type == "" || ($requirement_type != "" && $requirement_type == $course->requirement_type))
  1360. {
  1361. if ($course->course_list_fulfilled_by->is_empty == false)
  1362. {
  1363. $cc = $course->course_list_fulfilled_by->get_first();
  1364. if ($cc->bool_substitution)
  1365. {
  1366. // If we require the grade to be a qpts_grade, then check that now.
  1367. if ($bool_qpts_grades_only && !isset($qpts_grades[$cc->grade])) {
  1368. continue;
  1369. }
  1370. $h = $cc->substitution_hours;
  1371. if ($cc->bool_ghost_hour) {
  1372. $h = 0;
  1373. }
  1374. $count = $count + $h;
  1375. }
  1376. }
  1377. }
  1378. }
  1379. }
  1380. return $count;
  1381. }
  1382. /**
  1383. * Similar to count_credit_hours, but this will only count courses
  1384. * which have been taken and have a grade. We will return back
  1385. * a sum of their quality points.
  1386. *
  1387. * @todo ignore list should be db-based, in the settings.
  1388. *
  1389. * @param string $requirement_type
  1390. * - If set, we will only look for courses matching this requirement_type.
  1391. *
  1392. * @param bool $bool_use_ignore_list
  1393. * @param bool $bool_ignore_enrolled
  1394. * @return int
  1395. */
  1396. function count_credit_quality_points($requirement_type = "", $bool_use_ignore_list = false, $bool_ignore_enrolled = false)
  1397. {
  1398. $points = 0;
  1399. for ($t = 0; $t < $this->count; $t++)
  1400. {
  1401. $course = $this->array_list[$t];
  1402. if ($bool_use_ignore_list == true)
  1403. {
  1404. // Do ignore some courses...
  1405. $temp_course_name = $course->subject_id . " " . $course->course_num;
  1406. // Check in our settings to see if we should ignore this course
  1407. // (configured in /custom/settings.php)
  1408. if (in_array($temp_course_name, csv_to_array($GLOBALS["fp_system_settings"]["ignore_courses_from_hour_counts"]))) {
  1409. continue;
  1410. }
  1411. }
  1412. if ($bool_ignore_enrolled == true)
  1413. {
  1414. if ($course->is_completed() == false)
  1415. {
  1416. if ($course->course_list_fulfilled_by->is_empty)
  1417. {
  1418. continue;
  1419. } else {
  1420. if ($course->course_list_fulfilled_by->get_first()->is_completed() == false)
  1421. {
  1422. continue;
  1423. }
  1424. }
  1425. }
  1426. }
  1427. if ($course->grade != "")
  1428. {
  1429. if ($requirement_type == "")
  1430. {
  1431. $p = $course->get_quality_points();
  1432. $points = $points + $p;
  1433. } else {
  1434. if ($course->requirement_type == $requirement_type)
  1435. {
  1436. $p = $course->get_quality_points();
  1437. $points = $points + $p;
  1438. continue;
  1439. }
  1440. // For specifically "university capstone" courses...
  1441. if ($course->requirement_type == "uc" && $requirement_type == "c")
  1442. {
  1443. $p = $course->get_quality_points();
  1444. $points = $points + $p;
  1445. }
  1446. if ($course->requirement_type == "um" && $requirement_type == "m")
  1447. {
  1448. $p = $course->get_quality_points();
  1449. $points = $points + $p;
  1450. }
  1451. }
  1452. } else {
  1453. // maybe it's a substitution?
  1454. if (($requirement_type == "") || ($requirement_type != "" && $requirement_type == $course->requirement_type))
  1455. {
  1456. if ($course->course_list_fulfilled_by->is_empty == false)
  1457. {
  1458. $cc = $course->course_list_fulfilled_by->get_first();
  1459. if ($cc->bool_substitution)
  1460. {
  1461. //$h = $cc->substitution_hours;
  1462. //if ($cc->bool_ghost_hour) {
  1463. // $h = 0;
  1464. //}
  1465. // What are the quality points for this course?
  1466. $p = $cc->get_quality_points();
  1467. $points = $points + $p;
  1468. }
  1469. }
  1470. }
  1471. }
  1472. }
  1473. return $points;
  1474. }
  1475. /**
  1476. * Assign a groupID to every course in the list.
  1477. *
  1478. * @param int $group_id
  1479. */
  1480. function assign_group_id($group_id)
  1481. {
  1482. for ($t = 0; $t < $this->count; $t++)
  1483. {
  1484. $course = $this->array_list[$t];
  1485. $course->assigned_to_group_id = $group_id;
  1486. }
  1487. }
  1488. /**
  1489. * Assign a semesterNum to every course in the list.
  1490. *
  1491. * @param int $semester_num
  1492. */
  1493. function assign_semester_num($semester_num)
  1494. {
  1495. for ($t = 0; $t < $this->count; $t++)
  1496. {
  1497. $course = $this->array_list[$t];
  1498. $course->assigned_to_semester_num = $semester_num;
  1499. }
  1500. }
  1501. /**
  1502. * Sets the bool_has_been_assigned property of every course in
  1503. * the list.
  1504. *
  1505. * @param bool $bool_has_been_assigned
  1506. * - What to set each course's->boolhasBeenAssigned property
  1507. * to.
  1508. *
  1509. */
  1510. function set_has_been_assigned($bool_has_been_assigned = true)
  1511. {
  1512. // Set the bool_has_been_assigned for all items
  1513. // in this list.
  1514. for ($t = 0; $t < $this->count; $t++)
  1515. {
  1516. $course = $this->array_list[$t];
  1517. $course->bool_has_been_assigned = $bool_has_been_assigned;
  1518. }
  1519. }
  1520. /**
  1521. * Set's each course's bool_substitution value.
  1522. *
  1523. * @param bool $bool_s
  1524. * - What to set each course's bool_substitution value to.
  1525. */
  1526. function set_bool_substitution($bool_s = true)
  1527. {
  1528. // Set the bool_substitution for all items
  1529. // in this list.
  1530. for ($t = 0; $t < $this->count; $t++)
  1531. {
  1532. $course = $this->array_list[$t];
  1533. $course->bool_substitution = $bool_s;
  1534. }
  1535. }
  1536. /**
  1537. * Sets each course's $course_substitution value to the supplied
  1538. * Course object.
  1539. *
  1540. * @param Course $course_s
  1541. * @param string $sub_remarks
  1542. */
  1543. function set_course_substitution(Course $course_s, $sub_remarks = "")
  1544. {
  1545. for ($t = 0; $t < $this->count; $t++)
  1546. {
  1547. $course = $this->array_list[$t];
  1548. $course->course_substitution = $course_s;
  1549. $course->sub_remarks = $sub_remarks;
  1550. }
  1551. }
  1552. /**
  1553. * Go through the list and decrement the specified_repeats
  1554. * value for all instances of Course $course.
  1555. *
  1556. * @param Course $course
  1557. */
  1558. function dec_specified_repeats(Course $course)
  1559. {
  1560. // Go through the list, and decrement the specified_repeats
  1561. // value for all instances of $course.
  1562. for ($t = 0; $t < $this->count; $t++)
  1563. {
  1564. $course2 = $this->array_list[$t];
  1565. if ($course2->course_id == $course->course_id)
  1566. {
  1567. $course2->specified_repeats--;
  1568. }
  1569. }
  1570. }
  1571. /**
  1572. * Go through the list and set the specified_repeats value to $num
  1573. * for all instances of $course.
  1574. *
  1575. * @param Course $course
  1576. * @param int $num
  1577. */
  1578. function set_specified_repeats(Course $course, $num)
  1579. {
  1580. for ($t = 0; $t < $this->count; $t++)
  1581. {
  1582. $course2 = $this->array_list[$t];
  1583. if ($course2->course_id == $course->course_id)
  1584. {
  1585. $course2->specified_repeats = $num;
  1586. $course2->bool_specified_repeats = true;
  1587. }
  1588. }
  1589. }
  1590. /**
  1591. * Removes excluded courses from the list (courses that
  1592. * have db_exclude == 1)
  1593. *
  1594. */
  1595. function remove_excluded()
  1596. {
  1597. // Removes courses from the list that have a db_exclude == 1.
  1598. $new_list = new CourseList();
  1599. // Do this by adding elements to an array.
  1600. // course_id => index in list.
  1601. for ($t = 0; $t < $this->count; $t++)
  1602. {
  1603. $course = $this->array_list[$t];
  1604. if ($course->subject_id == "")
  1605. { // load descriptive data (include exclude info)
  1606. $course->load_descriptive_data();
  1607. }
  1608. if ($course->db_exclude == 1)
  1609. {
  1610. continue;
  1611. }
  1612. $new_list->add($course);
  1613. }
  1614. $this->array_list = $new_list->array_list;
  1615. $this->reset_counter();
  1616. }
  1617. /**
  1618. * Removes null's and duplicate courses from the list.
  1619. *
  1620. */
  1621. function remove_duplicates()
  1622. {
  1623. // Go through and remove duplicates from the list.
  1624. // Also remove null's
  1625. $tarray = array();
  1626. $new_list = new CourseList();
  1627. // Do this by adding elements to an array.
  1628. // course_id => index in list.
  1629. for ($t = 0; $t < $this->count; $t++)
  1630. {
  1631. $course = $this->array_list[$t];
  1632. if ($course == null)
  1633. {
  1634. continue;
  1635. }
  1636. $tarray[$course->course_id] = -1;
  1637. }
  1638. for ($t = 0; $t < $this->count; $t++)
  1639. {
  1640. $course = $this->array_list[$t];
  1641. if ($course == null)
  1642. {
  1643. continue;
  1644. }
  1645. //if (is_object($course->courseFulfilledBy))
  1646. if (!($course->course_list_fulfilled_by->is_empty))
  1647. {
  1648. $tarray[$course->course_id] = $t;
  1649. continue;
  1650. }
  1651. if ($tarray[$course->course_id]*1 < 0)
  1652. {
  1653. $tarray[$course->course_id] = $t;
  1654. }
  1655. }
  1656. // Now, go through tarray and rebuild the newList.
  1657. foreach($tarray as $course_id => $i)
  1658. {
  1659. $new_list->add($this->array_list[$i]);
  1660. }
  1661. // Switch over the reference.
  1662. $this->array_list = $new_list->array_list;
  1663. $this->reset_counter();
  1664. }
  1665. } // end class CourseList