_FlightPath.php

Classes

NameDescription
_FlightPath

File

classes/_FlightPath.php
View source
  1. <?php
  2. class _FlightPath
  3. {
  4. public $student, $degree_plan, $db, $bool_what_if;
  5. public $course_list_advised_courses;
  6. function __construct($student = "", $degree_plan = "", DatabaseHandler $db = null, $bool_perform_full_init = false)
  7. {
  8. if ($student != "")
  9. {
  10. $this->student = $student;
  11. }
  12. if ($degree_plan != "")
  13. {
  14. $this->degree_plan = $degree_plan;
  15. }
  16. if ($db != null)
  17. {
  18. $this->db = $db;
  19. } else {
  20. $this->db = get_global_database_handler();
  21. }
  22. if ($bool_perform_full_init == true)
  23. {
  24. $this->init(true);
  25. }
  26. $this->course_list_advised_courses = new CourseList();
  27. }
  28. function init($bool_init_advising_variables = false, $bool_ignore_what_if_advising_variables = false, $bool_load_full = true) {
  29. global $current_student_id, $user;
  30. // This will initialize this flightPath object
  31. // based on what is available in the global variables.
  32. // Takes the place of what was going on at the beginning
  33. // of advise.php.
  34. if ($bool_init_advising_variables == true)
  35. {
  36. //$temp_screen = new AdvisingScreen();
  37. //$temp_screen->init_advising_variables($bool_ignore_what_if_advising_variables);
  38. //advise_load_advising_variables_from_db($current_student_id, $user->id);
  39. advise_init_advising_variables();
  40. }
  41. $major_code = $GLOBALS["fp_advising"]["advising_major_code"];
  42. $track_code = $GLOBALS["fp_advising"]["advising_track_code"];
  43. $student_id = $GLOBALS["fp_advising"]["advising_student_id"];
  44. $advising_term_id = $GLOBALS["fp_advising"]["advising_term_id"];
  45. $available_terms = $GLOBALS["fp_advising"]["available_advising_term_ids"];
  46. $this->bool_what_if = false;
  47. // Are we in WhatIf mode?
  48. if ($GLOBALS["fp_advising"]["advising_what_if"] == "yes")
  49. {
  50. $major_code = $GLOBALS["fp_advising"]["what_if_major_code"];
  51. $track_code = $GLOBALS["fp_advising"]["what_if_track_code"];
  52. $this->bool_what_if = true;
  53. }
  54. if ($bool_load_full == false)
  55. { // not trying to load anything, so return.
  56. return;
  57. }
  58. $db = $this->db;
  59. if ($bool_load_full == true)
  60. {
  61. $student = new Student($student_id);
  62. } else {
  63. $student = new Student();
  64. $student->student_id = $student_id;
  65. }
  66. $settings = fp_get_system_settings();
  67. $catalog_year = $student->catalog_year;
  68. if ($this->bool_what_if)
  69. {
  70. $catalog_year = $settings["current_catalog_year"];
  71. }
  72. // make sure their catalog year is not past the system's current
  73. // year setting.
  74. if ($catalog_year > $settings["current_catalog_year"]
  75. && $settings["current_catalog_year"] > $settings["earliest_catalog_year"])
  76. { // Make sure degree plan is blank if it is!
  77. $catalog_year = 99999;
  78. }
  79. if ($GLOBALS["fp_advising"]["advising_update_student_settings_flag"] != "")
  80. {
  81. $student->array_settings["track_code"] = $track_code;
  82. $student->array_settings["major_code"] = $major_code;
  83. }
  84. $t_major_code = $major_code;
  85. if ($track_code != "")
  86. {
  87. // Does the major_code already have a | in it?
  88. if (!strstr($t_major_code, "|"))
  89. {
  90. $t_major_code .= "|_" . $track_code;
  91. } else {
  92. // it DOES have a | in it already, so just add the
  93. // trackCode using _. This is most likely because
  94. // we are dealing with a track AND a concentration.
  95. $t_major_code .= "_" . $track_code;
  96. }
  97. }
  98. $degree_id = $db->get_degree_id($t_major_code, $catalog_year);
  99. if ($student->array_settings["track_code"] != "" && $this->bool_what_if == false
  100. && $student->array_settings["major_code"] == $major_code)
  101. {
  102. // The student has a selected track in their settings,
  103. // so use that (but only if it is for their current major-- settings
  104. // could be old!)
  105. $t_major_code = $student->get_major_and_track_code();
  106. $temp_degree_id = $db->get_degree_id($t_major_code, $student->catalog_year);
  107. if ($temp_degree_id) {
  108. $degree_id = $temp_degree_id;
  109. }
  110. }
  111. if ($bool_load_full == true)
  112. {
  113. $this->student = $student;
  114. $degree_plan = new DegreePlan($degree_id, $db, false, $student->array_significant_courses);
  115. $degree_plan->add_semester_developmental($student->student_id);
  116. $this->degree_plan = $degree_plan;
  117. }
  118. }
  119. /**
  120. * This function will check to see if we are trying to save
  121. * the draft from a tab change. It should be near the top
  122. * of all of FP's "tab" pages, like Main, Comments, etc.
  123. *
  124. */
  125. function process_request_save_draft()
  126. {
  127. /////////////////////////////////////
  128. /// Are we trying to save the draft
  129. /// from a tab change?
  130. /////////////////////////////////////
  131. if ($_REQUEST["save_draft"] == "yes")
  132. {
  133. $this->init(true, false, false);
  134. // If we are coming from the WhatIf tab, we need to save
  135. // as WhatIf. Else, save as normal.
  136. if ($_REQUEST["from_w_i"] == "yes")
  137. {
  138. // Yes, we are coming from WhatIf mode, so
  139. // save under WhatIf.
  140. $GLOBALS["advising_what_if"] = "yes";
  141. $this->init(false);
  142. } else {
  143. // NOT coming from WhatIf mode. Save as a normal draft.
  144. $GLOBALS["advising_what_if"] = "no";
  145. $this->init(true, true);
  146. }
  147. $this->save_advising_session_from_post(0,true);
  148. }
  149. }
  150. function assign_courses_to_groups()
  151. {
  152. // This method will look at the student's courses
  153. // and decide which groups they should be fit into.
  154. // We will be going through the degree plan's master list
  155. // of groups to decide this.
  156. $student = $this->student;
  157. $this->degree_plan->list_groups->sort_priority();
  158. $this->degree_plan->list_groups->reset_counter();
  159. while($this->degree_plan->list_groups->has_more())
  160. {
  161. $g = $this->degree_plan->list_groups->get_next();
  162. if ($g->group_id == -88)
  163. {
  164. // Add a course group. Skip.
  165. continue;
  166. }
  167. // Does the student have any group additions for this
  168. // group? Technically it is a substitution.
  169. // We will add them in now, because we do not take additions
  170. // into consideration when figuring out branches.
  171. if ($course_list_additions = $student->list_substitutions->find_group_additions($g))
  172. {
  173. $course_list_additions->reset_counter();
  174. while($course_list_additions->has_more())
  175. {
  176. $cA = $course_list_additions->get_next();
  177. $new_course = new Course();
  178. $new_course->course_id = $cA->course_id;
  179. if ($cA->bool_transfer == true)
  180. {
  181. if ($cA->course_id == 0 && is_object($cA->course_transfer))
  182. { // This is a transfer course which has been added.
  183. $new_course->course_id = $cA->course_transfer->course_id;
  184. }
  185. $new_course->bool_transfer = true;
  186. }
  187. $new_course->assigned_to_semester_num = $g->assigned_to_semester_num;
  188. $new_course->requirement_type = $g->requirement_type;
  189. // Add this course as a requirement.
  190. //$new_course->load_descriptive_data();
  191. $g->list_courses->add($new_course, true);
  192. // Later on, when we do assign_courses_to_list, it
  193. // will automatically find this course and apply the
  194. // substitution.
  195. }
  196. }
  197. // First we see if there are any bare courses at this level. If there
  198. // are, then this group has NO branches! Otherwise, the courses must
  199. // always be contained in a branch!
  200. if (!$g->list_courses->is_empty)
  201. {
  202. // Yes, there are courses here. So, assign them at this level.
  203. $this->assign_courses_to_list($g->list_courses, $this->student, true, $g, true);
  204. // Okay, if we have fulfilled our courses at this level.
  205. // then we can continue on to the next "top level" group.
  206. //continue;
  207. }
  208. if (!$g->list_groups->is_empty)
  209. {
  210. /*
  211. Now we've got some trouble. This is our first level of groups.
  212. If this object exists, then it means that this group branches off
  213. at its first level. So, instead of actually assigning courses to
  214. groups, we need to find out which group has the most matches, and THEN
  215. we will assign them.
  216. */
  217. $g->reload_missing_courses();
  218. $high_count = -1;
  219. $best_branch = -1;
  220. $g->list_groups->reset_counter();
  221. while($g->list_groups->has_more())
  222. {
  223. $branch_one = $g->list_groups->get_next();
  224. if (!$branch_one->list_courses->is_empty)
  225. {
  226. // This does not actually assign. Just counts.
  227. $count = $this->get_count_of_matches($branch_one, $this->student, $g);
  228. $branch_one->count_of_matches = $count;
  229. if ($count > $high_count)
  230. {
  231. $high_count = $count;
  232. $best_branch = $g->list_groups->object_index_of($branch_one);
  233. }
  234. }
  235. }
  236. // Okay, coming out of that, we should know which branch has the best count (number
  237. // of matches). So, let's assign courses to that branch.
  238. if ($best_branch != -1)
  239. {
  240. $winning_branch = $g->list_groups->get_element($best_branch);
  241. $winning_branch->bool_winning_branch = true;
  242. $this->assign_courses_to_list($winning_branch->list_courses, $this->student, true, $g, true);
  243. }
  244. }
  245. }
  246. }
  247. function get_count_of_matches($branch, $student, $group)
  248. {
  249. return $this->assign_courses_to_list($branch->list_courses, $student, false, $group, true);
  250. }
  251. function flag_outdated_substitutions()
  252. {
  253. // Go through the student's substitutions and flag ones that
  254. // do not apply to this degree plan. Also, unset any bool_substitution
  255. // variables which were set.
  256. $this->student->list_substitutions->reset_counter();
  257. while ($this->student->list_substitutions->has_more())
  258. {
  259. $substitution = $this->student->list_substitutions->get_next();
  260. $required_group_id = $substitution->course_requirement->assigned_to_group_id;
  261. // First check-- does this degree even have this group ID?
  262. $outdated_note = "";
  263. if ($required_group_id == 0)
  264. {
  265. // bare degree plan.
  266. // Does the bare degree plan list the course_requirement
  267. // anywhere?
  268. $bool_sub_valid = false;
  269. $this->degree_plan->list_semesters->reset_counter();
  270. while($this->degree_plan->list_semesters->has_more() && $bool_sub_valid == false)
  271. {
  272. $sem = $this->degree_plan->list_semesters->get_next();
  273. if ($sem->list_courses->find_match($substitution->course_requirement))
  274. {
  275. $bool_sub_valid = true;
  276. } else {
  277. // Could not find the course requirement in question.
  278. $bool_sub_valid = false;
  279. $scr = $substitution->course_requirement;
  280. $scr->load_descriptive_data();
  281. $outdated_note = "This substitution is for the course $scr->subject_id
  282. $scr->course_num (id: $scr->course_id) on the
  283. bare degree plan, but the student's current degree does
  284. not specify this course.";
  285. }
  286. }
  287. } else {
  288. // requiredGroupID != 0. So, does this
  289. // degree plan have a group with this id?
  290. $bool_sub_valid = false;
  291. if ($g = $this->degree_plan->find_group($required_group_id))
  292. {
  293. $bool_sub_valid = true;
  294. } else {
  295. // Could not find the group in question. Add an "outdated_note"
  296. // to the sub...
  297. $bool_sub_valid = false;
  298. $new_group = new Group();
  299. $new_group->group_id = $required_group_id;
  300. $new_group->load_descriptive_data();
  301. $group_name = "";
  302. if (user_has_permission("can_access_data_entry")) {
  303. // only show if we are a data entry administrator.
  304. $group_name = "<i>$new_group->group_name,</i>";
  305. }
  306. $outdated_note = "This substitution is for the group $new_group->title
  307. (id: $new_group->group_id, $group_name $new_group->catalog_year),
  308. but the student's current degree does not call for this
  309. specific group.";
  310. }
  311. }
  312. if ($bool_sub_valid == false)
  313. {
  314. // Couldn't find a match, so remove this sub!
  315. $substitution->bool_outdated = true;
  316. $substitution->outdated_note = $outdated_note;
  317. $substitution->course_list_substitutions->get_first()->bool_outdated_sub = true;
  318. $substitution->course_list_substitutions->get_first()->bool_substitution = false;
  319. if ($substitution->course_list_substitutions->get_first()->temp_old_course_id > 0)
  320. { // Restore the course_id *if* it was set to 0 on purpose. (happens
  321. // when there is a sub of a transfer to kill the transfer eqv. This will
  322. // restore it).
  323. $substitution->course_list_substitutions->get_first()->course_id = $substitution->course_list_substitutions->get_first()->temp_old_course_id;
  324. }
  325. }
  326. }
  327. }
  328. function assign_courses_to_list(ObjList $list_requirements, Student $student, $bool_perform_assignment = true, Group $group = null, $bool_check_significant_courses = false)
  329. {
  330. $count = 0;
  331. if ($group == null)
  332. {
  333. $group = new Group();
  334. $group->group_id = 0;
  335. }
  336. $group_id = $group->group_id;
  337. // If the group_id == 0, we may be talking about the bare degree plan.
  338. $hours_required = $group->hours_required*1;
  339. $hours_assigned = $group->hours_assigned;
  340. if ($hours_required*1 <= 0 || $hours_required == "")
  341. {
  342. $hours_required = 999999;
  343. }
  344. //print_pre($list_requirements->to_string());
  345. $list_requirements->sort_smallest_hours_first();
  346. $list_requirements->sort_substitutions_first($student->list_substitutions, $group_id);
  347. $list_requirements->reset_counter();
  348. while($list_requirements->has_more())
  349. {
  350. $course_requirement = $list_requirements->get_next();
  351. if ($bool_check_significant_courses == true)
  352. {
  353. // Only look for the course_requirement if it is in the student's
  354. // array_significant_courses array.
  355. if ($student->array_significant_courses[$course_requirement->course_id] != true)
  356. {// course was not in there, so skip!
  357. continue;
  358. }
  359. }
  360. if ($course_requirement->bool_specified_repeat == true)
  361. {
  362. // Since this requirement has specified repeats, we want
  363. // to make all of the student's taken courses (for this course)
  364. // also have specified repeats.
  365. $student->list_courses_taken->set_specified_repeats($course_requirement, $course_requirement->specified_repeats);
  366. }
  367. // Does the student have any substitutions for this requirement?
  368. if ($substitution = $student->list_substitutions->find_requirement($course_requirement, true, $group_id))
  369. {
  370. // Since the substitution was made, I don't really care about
  371. // min grades or the like. Let's just put it in.
  372. // Make sure this isn't a group addition and we are *currently*
  373. // NOT looking at the group it is being added to. This is to
  374. // correct a bug.
  375. if ($substitution->bool_group_addition == true)
  376. {
  377. if ($substitution->course_requirement->assigned_to_group_id != $group_id)
  378. {
  379. continue;
  380. }
  381. }
  382. if ($bool_perform_assignment == true)
  383. {
  384. // If the course_requirement's min_hours are greater than
  385. // the substitution's hours, then we have to split the
  386. // coureRequirement into 2 pieces, and add the second piece just
  387. // after this one in the list.
  388. $course_sub = $substitution->course_list_substitutions->get_first();
  389. if ($course_requirement->min_hours*1 > $course_sub->hours_awarded*1)
  390. {
  391. // Because float math can create some very strange results, we must
  392. // perform some rounding. We will round to 6 decimal places, which should
  393. // provide us the accuracy w/o losing precision (since we can only represent a max
  394. // of 4 decimals in the database anyway.
  395. $remaining_hours = round($course_requirement->min_hours - $course_sub->hours_awarded, 6);
  396. $new_course_string = $course_requirement->to_data_string();
  397. $new_course = new Course();
  398. $new_course->load_course_from_data_string($new_course_string);
  399. $new_course->min_hours = $new_course->max_hours = $remaining_hours;
  400. $new_course->bool_substitution_split = true;
  401. $new_course->bool_substitution_new_from_split = true;
  402. $new_course->requirement_type = $course_requirement->requirement_type;
  403. $course_requirement->bool_substitution_split = true;
  404. // I am commenting this out-- if we split up a sub multiple times, then we shouldn't
  405. // set the old course requirement to say it WASN'T from a split. This was causing a bug
  406. // where the pie charts got weird if you did more than 1 split. Was counting total
  407. // hours as more, in CourseList->count_hours().
  408. //$course_requirement->bool_substitution_new_from_split = false;
  409. // Now, add this into the list, right after the course_requirement.
  410. $current_i = $list_requirements->i;
  411. $list_requirements->insert_after_index($current_i, $new_course);
  412. }
  413. $course_requirement->course_list_fulfilled_by = $substitution->course_list_substitutions;
  414. $substitution->course_list_substitutions->assign_group_id($group_id);
  415. $substitution->course_list_substitutions->set_has_been_assigned(true);
  416. $substitution->course_list_substitutions->set_bool_substitution(true);
  417. $substitution->course_list_substitutions->set_course_substitution($course_requirement, $substitution->remarks);
  418. $substitution->bool_has_been_applied = true;
  419. }
  420. $count++;
  421. continue;
  422. }
  423. // Has the student taken this course requirement?
  424. if ($c = $student->list_courses_taken->find_best_match($course_requirement, $course_requirement->min_grade, true))
  425. {
  426. $h_get_hours = $c->get_hours();
  427. if ($c->bool_ghost_hour) {
  428. // If this is a ghost hour, then $h_get_hours would == 0 right now,
  429. // instead, use the the adjusted value (probably 1).
  430. $h_get_hours = $c->hours_awarded;
  431. }
  432. // Can we assign any more hours to this group? Are we
  433. // out of hours, and should stop?
  434. if ($hours_assigned >= $hours_required)
  435. {
  436. continue;
  437. }
  438. // Will the hours of this course put us over the hours_required limit?
  439. if ($hours_assigned + $c->hours_awarded > $hours_required)
  440. {
  441. continue;
  442. }
  443. // Do not apply substitutionSplit courses to anything automatically.
  444. // They must be applied by substitutions.
  445. if ($c->bool_substitution_new_from_split == true)
  446. {
  447. continue;
  448. }
  449. // Make sure the course meets min grade requirements.
  450. if (!$c->meets_min_grade_requirement_of($course_requirement))
  451. {
  452. continue;
  453. }
  454. // Has the course been unassigned from this group?
  455. if ($c->group_list_unassigned->find_match($group))
  456. {
  457. continue;
  458. }
  459. // Prereq checking would also go here.
  460. // Make sure $c is not being used in a substitution.
  461. if ($c->bool_substitution == true)
  462. {
  463. continue;
  464. }
  465. if ($c->bool_has_been_assigned != true)
  466. {//Don't count courses which have already been placed in other groups.
  467. // Has another version of this course already been
  468. // assigned? And if so, are repeats allowed for this
  469. // course? And if so, then how many hours of the
  470. // repeat_hours have I used up? If I cannot do any more
  471. // repeats, then quit. Otherwise, let it continue...
  472. $course_list_repeats = $student->list_courses_taken->get_previous_assignments($c->course_id);
  473. if ($course_list_repeats->get_size() > 0)
  474. {
  475. // So, a copy of this course has been assigned more than once...
  476. // Get the total number of hours taken up by this course.
  477. $cc = $course_list_repeats->count_hours();
  478. // have we exceeded the number of available repeat_hours
  479. // for this course?
  480. if ($course_requirement->repeat_hours <= 0)
  481. {
  482. $course_requirement->load_descriptive_data();
  483. }
  484. if ($cc + $h_get_hours > $course_requirement->repeat_hours*1)
  485. {
  486. // Do not allow the repeat.
  487. continue;
  488. }
  489. }
  490. // Basically--- if the most recent attempt fails
  491. // a min grade check, then tag all attempts as "unuseable"
  492. // so that they can't be used in other groups. --
  493. // unless they are able to be repeated. BARF!
  494. // Inc hours_assigned, even if we aren't actually
  495. // performing an assignment. This helps us accurately
  496. // calculate the count.
  497. $hours_assigned = $hours_assigned + $h_get_hours;
  498. if ($bool_perform_assignment == true)
  499. {
  500. $course_requirement->course_list_fulfilled_by->add($c);
  501. $course_requirement->grade = $c->grade;
  502. $course_requirement->hours_awarded = $c->hours_awarded;
  503. $course_requirement->bool_ghost_hour = $c->bool_ghost_hour;
  504. $c->bool_has_been_assigned = true;
  505. $c->requirement_type = $course_requirement->requirement_type;
  506. $c->assigned_to_group_id = $group_id;
  507. $group->hours_assigned = $hours_assigned;
  508. // Should check for:
  509. // Can it be assigned, based on the number of allowed course repeats?
  510. if ($course_requirement->bool_specified_repeat == true)
  511. {
  512. // $c is what they actually took.
  513. $c->bool_specified_repeat = true;
  514. $c->specified_repeats = $course_requirement->specified_repeats;
  515. $list_requirements->dec_specified_repeats($c);
  516. }
  517. }
  518. $count++;
  519. }
  520. }
  521. }
  522. return $count;
  523. }
  524. function assign_courses_to_semesters()
  525. {
  526. // This method will look at the student's courses
  527. // and decide if they should be assigned to degree requirements
  528. // which have been spelled out in each semester. This
  529. // is not where it looks into groups.
  530. $this->degree_plan->list_semesters->reset_counter();
  531. while($this->degree_plan->list_semesters->has_more())
  532. {
  533. $semester = $this->degree_plan->list_semesters->get_next();
  534. // Okay, let's look at the courses (not groups) in this
  535. // semester...
  536. $this->assign_courses_to_list($semester->list_courses, $this->student);
  537. }
  538. }
  539. /**
  540. * Get the plain English title of a subject, from
  541. * subject_id. Ex: COSC = Computer Science.
  542. *
  543. * @param unknown_type $subject_id
  544. * @return unknown
  545. */
  546. function get_subject_title($subject_id)
  547. {
  548. // From the subject_id, get the title.
  549. // Example: COSC = Computer Science.
  550. $res = $this->db->db_query("SELECT title FROM subjects
  551. WHERE subject_id = '?' LIMIT 1 ", $subject_id);
  552. $cur = $this->db->db_fetch_array($res);
  553. return trim($cur["title"]);
  554. }
  555. function get_all_courses_in_catalog_year($catalog_year = "2006", $bool_load_descriptive_data = false, $limit_start = 0, $limit_size = 0)
  556. {
  557. // Returns a CourseList object of all the
  558. // undergraduate courses in the
  559. // supplied catalog_year.
  560. $lim_line = "";
  561. if ($limit_size > 0)
  562. {
  563. $lim_line = " limit $limit_start, $limit_size ";
  564. }
  565. $rtn_list = new CourseList();
  566. $c_array = array();
  567. $result = $this->db->db_query("SELECT * FROM courses
  568. WHERE
  569. catalog_year = '?'
  570. AND course_num < '{$GLOBALS["fp_system_settings"]["graduate_level_course_num"]}'
  571. ORDER BY subject_id, course_num
  572. $lim_line
  573. ", $catalog_year);
  574. while($cur = $this->db->db_fetch_array($result))
  575. {
  576. $course = new Course();
  577. $course->course_id = $cur["course_id"];
  578. $course->subject_id = $cur["subject_id"];
  579. $course->course_num = $cur["course_num"];
  580. $course->min_hours = $cur["min_hours"];
  581. $course->max_hours = $cur["max_hours"];
  582. if ($bool_load_descriptive_data == true)
  583. {
  584. $course->load_descriptive_data();
  585. }
  586. $rtn_list->add($course);
  587. }
  588. return $rtn_list;
  589. }
  590. function cache_course_inventory($limit_start = 0, $limit_size = 4000)
  591. {
  592. // Load courses from the inventory into the inventory cache...
  593. // Attempt to load the course inventory cache...
  594. if ($course_inventory = unserialize($_SESSION["fp_cache_course_inventory"]))
  595. {
  596. $GLOBALS["fp_course_inventory"] = $course_inventory;
  597. }
  598. $result = $this->db->db_query("SELECT DISTINCT course_id FROM courses
  599. WHERE
  600. course_num < '{$GLOBALS["fp_system_settings"]["graduate_level_course_num"]}'
  601. LIMIT $limit_start, $limit_size
  602. ");
  603. while($cur = $this->db->db_fetch_array($result))
  604. {
  605. $course_id = $cur["course_id"];
  606. $this->db->load_course_descriptive_data(null, $course_id);
  607. }
  608. // Should we re-cache the course inventory? If there have been any changes
  609. // to it, then we will see that in a GLOBALS variable...
  610. if ($GLOBALS["cache_course_inventory"] == true)
  611. {
  612. $_SESSION["fp_cache_course_inventory"] = serialize($GLOBALS["fp_course_inventory"]);
  613. }
  614. }
  615. function replace_missing_course_in_group($course_id, $group_id)
  616. {
  617. // Given a group in the degree plan, this will
  618. // make sure that course is actually in the group. If it
  619. // is not, then it will add it in where it should be.
  620. // This is necessary because we have previously removed
  621. // courses which the student hadn't taken. Well, if the
  622. // student was advised for a particular course in a group,
  623. // then that course probably was originally removed
  624. // from the group. So, put it back in.
  625. // First, find the group.
  626. if (!$group = $this->degree_plan->find_group($group_id))
  627. {
  628. fpm(" ~~ could not find group $group_id for replacemMissingCourseInGroup");
  629. return;
  630. }
  631. // Okay, now tell the group to replace the instance of this course
  632. // in the group. This is made easy, because we have
  633. // the dbGroupRequirementID, which is the actual id from the
  634. // row in group_requirements that this course was advised from.
  635. $group->replace_missing_course($course_id);
  636. }
  637. function save_advising_session_from_post($faculty_id = 0, $bool_draft = true)
  638. {
  639. global $user;
  640. // This method will, only by looking at variables in the
  641. // POST, save an advising session into the database.
  642. $db = get_global_database_handler();
  643. if ($faculty_id == 0) {
  644. // if none supplied, use the one from the session of
  645. // whomever is currently logged in.
  646. $faculty_id = $user->cwid;
  647. }
  648. $bool_found_update_match = false;
  649. $student_id = $this->student->student_id;
  650. $degree_id = $this->degree_plan->degree_id;
  651. $major_code = $this->degree_plan->major_code;
  652. $available_terms = variable_get("available_advising_term_ids", "0");
  653. // Do we need to update the student's settings?
  654. if (trim($_POST["advising_update_student_settings_flag"]) != "")
  655. {
  656. // We are to assume that the student's array_settings
  657. // have already been updated by this point, so we will
  658. // simply convert them to XML and store in the database.
  659. $result = $db->db_query("REPLACE INTO student_settings
  660. (student_id, settings, posted)
  661. VALUES ('?','?', '?' ) ", $student_id, serialize($this->student->array_settings), time());
  662. watchdog("update_student_settings", "Settings updated for this student.");
  663. }
  664. // Is there anything in "log_addition" which we should write to the log?
  665. if ($_POST["log_addition"] != "")
  666. {
  667. $temp = explode("~",$_POST["log_addition"]);
  668. if ($temp[0] == "change_term") {
  669. watchdog("change_term", "$student_id," . $temp[1]);
  670. }
  671. if ($temp[0] == "change_track"){
  672. watchdog("change_track", "$student_id," . $temp[1]);
  673. }
  674. }
  675. // If this user cannot advise, then just return right now.
  676. if (!user_has_permission("can_advise_students")) {
  677. return;
  678. }
  679. // First, create a new entry in the advising_sessions table,
  680. // so we can get the advisingSessionID.
  681. // But before we can do that, we look for an existing entry
  682. // which matches this. If we find it, we delete it so the
  683. // new one will display instead.
  684. // Only delete if its a draft copy!
  685. $is_draft = intval($bool_draft);
  686. $is_what_if = intval($this->bool_what_if);
  687. // Since we only want one draft copy per term/per student,
  688. // let's delete
  689. // any draft copies already in existence, if we are saving a draft.
  690. $result = $db->db_query("DELETE FROM advising_sessions
  691. WHERE `student_id`='?'
  692. AND `is_draft`='1'
  693. AND `degree_id`='?'
  694. AND `is_whatif`='?' ", $student_id, $degree_id, $is_what_if);
  695. // The first thing we need to do is go through the availableTerms,
  696. // create new entries for them in the table, and store what their
  697. // session ID's are in an array.
  698. $advising_session_id_array = array();
  699. $advising_session_id_array_count = array();
  700. $temp = explode(",",$available_terms);
  701. foreach ($temp as $term_id)
  702. {
  703. $term_id = trim($term_id);
  704. if ($term_id == "") { continue; }
  705. // Okay, now create a new entry in the system for that term.
  706. // We create entries for all available terms, whether we
  707. // are going to use them later or not.
  708. $result = $db->db_query("INSERT INTO advising_sessions
  709. (student_id, faculty_id, term_id, degree_id,
  710. major_code,
  711. catalog_year, posted, is_whatif, is_draft)
  712. VALUES
  713. ('?', '?','?','?','?','?','?','?','?')
  714. ", $student_id, $faculty_id,$term_id,$degree_id, $major_code, $catalog_year, time(), $is_what_if, $is_draft);
  715. $advising_session_id = mysql_insert_id();
  716. $advising_session_id_array[$term_id] = $advising_session_id;
  717. $advising_session_id_array_count[$term_id] = 0;
  718. }
  719. $wi = "";
  720. if ($is_what_if == "1"){$wi = "_whatif";}
  721. if ($bool_draft) {
  722. watchdog("save_adv_draft$wi", "$student_id,major_code:$major_code");
  723. }
  724. else {
  725. watchdog("save_adv_active$wi", "$student_id,major_code:$major_code");
  726. }
  727. // Go through the POST, looking for the
  728. // phrase "advisecourse_" in the name of the variables.
  729. // There should be one of these for every course that was
  730. // on the page. It looks like this:
  731. // advisecourse_course_id_semesterNum_group_id_varHours_randomID
  732. //fpm($_POST);
  733. foreach($_POST as $key => $value)
  734. {
  735. if (!strstr($key,"advisecourse_"))
  736. { // Skip vars which don't have this as part of the name.
  737. continue;
  738. }
  739. if ($value != "true")
  740. { // This means the course was *not* advised to be taken,
  741. // so, skip it.
  742. continue;
  743. }
  744. $temp = explode("_",$key);
  745. $course_id = trim($temp[1]);
  746. $semester_num = trim($temp[2]);
  747. $group_id = trim($temp[3]);
  748. $var_hours = trim($temp[4]);
  749. $random_id = trim($temp[5]);
  750. $advised_term_id = trim($temp[6]);
  751. $db_group_requirement_id = trim($temp[7]);
  752. $advising_session_id = $advising_session_id_array[$advised_term_id];
  753. $new_course = new Course($course_id);
  754. $new_course->load_descriptive_data();
  755. $entry_value = "$new_course->subject_id~$new_course->course_num";
  756. // Some particular course should be updated. Possibly this one.
  757. // Updates happen because of a student changing the
  758. // variable hours, for example.
  759. if (trim($_POST["updatecourse"]) != "")
  760. {
  761. $temp2 = explode("~",trim($_POST["updatecourse"]));
  762. $tcourse_id = $temp2[0];
  763. $tgroup_id = $temp2[1] * 1;
  764. $tsemester_num = $temp2[2] * 1;
  765. $tvar_hours = $temp2[3];
  766. $trandom_id = $temp2[4];
  767. $tadvised_term_id = $temp2[5];
  768. // Do we have a match?
  769. if ($course_id == $tcourse_id && $random_id == $trandom_id)
  770. {
  771. // We have a match, so update with the new information.
  772. $var_hours = $tvar_hours;
  773. $bool_found_update_match = true;
  774. }
  775. }
  776. if ($group_id != 0)
  777. {
  778. $this->replace_missing_course_in_group($course_id, $group_id);
  779. }
  780. // Okay, write it to the table...
  781. $result = $db->db_query("INSERT INTO advised_courses
  782. (`advising_session_id`,`course_id`,
  783. `entry_value`,`semester_num`,
  784. `group_id`,`var_hours`,`term_id`)
  785. VALUES
  786. ('?','?','?','?','?','?','?')
  787. ", $advising_session_id,$course_id,$entry_value,$semester_num,$group_id,$var_hours,$advised_term_id);
  788. $advising_session_id_array_count[$advised_term_id]++;
  789. }
  790. // Did we have to perform an update-- but no course was found?
  791. if (trim($_POST["updatecourse"]) != "" && $bool_found_update_match == false)
  792. {
  793. // This means that the course was probably on the bare
  794. // degree program, and not already checked for advising. So,
  795. // let's add it to the advised_courses table, so it DOES
  796. // get checked for advising.
  797. $temp2 = explode("~",trim($_POST["updatecourse"]));
  798. $course_id = $temp2[0];
  799. $group_id = $temp2[1] * 1;
  800. $semester_num = $temp2[2] * 1;
  801. $var_hours = $temp2[3];
  802. $advised_term_id = $temp2[5];
  803. $advising_session_id = $advising_session_id_array[$advised_term_id];
  804. $result = $db->db_query("INSERT INTO advised_courses
  805. (`advising_session_id`,`course_id`,`semester_num`,
  806. `group_id`,`var_hours`,`term_id`)
  807. VALUES
  808. ('?','?','?','?','?','?')
  809. ", $advising_session_id,$course_id,$semester_num,$group_id,$var_hours,$advised_term_id);
  810. $advising_session_id_array_count[$advised_term_id]++;
  811. if ($group_id != 0)
  812. {
  813. $this->replace_missing_course_in_group($course_id, $group_id);
  814. }
  815. }
  816. //------------------------------------------------------
  817. //
  818. // Substitutions...
  819. //
  820. //-------------------------------------------------------
  821. // check permissions for substitutions before saving
  822. if (trim($_POST["savesubstitution"]) != "" && user_has_permission("can_substitute")) {
  823. $temp = explode("~",trim($_POST["savesubstitution"]));
  824. $course_id = $temp[0]; // required course
  825. $group_id = $temp[1] * 1;
  826. $semester_num = $temp[2] * 1;
  827. $sub_course_id = $temp[3];
  828. $sub_term_id = $temp[4];
  829. $sub_transfer_flag = $temp[5];
  830. $sub_hours = $temp[6] * 1;
  831. $sub_addition = $temp[7];
  832. $sub_remarks = urldecode($temp[8]);
  833. if ($sub_addition == "true")
  834. {
  835. $course_id = 0;
  836. }
  837. // Figure out the entry values for the required course & sub course...
  838. $required_entry_value = $sub_entry_value = "";
  839. if ($course_id > 0)
  840. {
  841. $new_course = new Course($course_id);
  842. $new_course->load_descriptive_data();
  843. $required_entry_value = "$new_course->subject_id~$new_course->course_num";
  844. }
  845. if ($sub_transfer_flag != 1)
  846. {
  847. $new_course = new Course($sub_course_id);
  848. $new_course->load_descriptive_data();
  849. $sub_entry_value = "$new_course->subject_id~$new_course->course_num";
  850. }
  851. if ($group_id != 0 && $course_id != 0)
  852. {
  853. $this->replace_missing_course_in_group($course_id, $group_id);
  854. }
  855. // Make sure the sub_hours aren't larger than the sub_course_id's awarded hours.
  856. // This is to stop a bug from happening where sometimes, some people are able to substitute
  857. // a course for larger than the awarded hours. I believe it is a javascript bug.
  858. if ($test_c = $this->student->list_courses_taken->find_specific_course($sub_course_id, $sub_term_id, (bool) $sub_transfer_flag, true)) {
  859. // Are the hours out of whack?
  860. if (floatval($sub_hours) > floatval($test_c->hours_awarded)) {
  861. // Yes! Set it to the value of the hours_awarded.
  862. $sub_hours = floatval($test_c->hours_awarded);
  863. }
  864. }
  865. $result = $db->db_query("INSERT INTO student_substitutions
  866. (`student_id`,`faculty_id`,`required_course_id`,`required_entry_value`,
  867. `required_group_id`,`required_semester_num`,`sub_course_id`,`sub_entry_value`,
  868. `sub_term_id`,`sub_transfer_flag`,`sub_hours`,`sub_remarks`,`posted`)
  869. VALUES
  870. ('?','?','?','?','?','?','?','?','?','?','?','?','?')
  871. ", $student_id,$faculty_id,$course_id,$required_entry_value,$group_id,$semester_num,$sub_course_id,$sub_entry_value,$sub_term_id,$sub_transfer_flag,$sub_hours,$sub_remarks, time());
  872. watchdog("save_substitution", "$student_id,group_id:$group_id,insert_id:" . mysql_insert_id());
  873. }
  874. if (trim($_POST["removesubstitution"]) != "")
  875. {
  876. $temp = explode("~",trim($_POST["removesubstitution"]));
  877. $sub_id = trim($temp[0]) * 1;
  878. $result = $db->db_query("UPDATE student_substitutions
  879. SET `delete_flag`='1'
  880. WHERE `id`='?' ", $sub_id);
  881. watchdog("remove_substitution", "$student_id,sub_id:$sub_id");
  882. }
  883. //------------------------------------------------------
  884. //
  885. // Group Unassignments
  886. //
  887. //-------------------------------------------------------
  888. if (trim($_POST["unassign_group"]) != "")
  889. {
  890. $temp = explode("~",trim($_POST["unassign_group"]));
  891. $course_id = $temp[0];
  892. $term_id = $temp[1];
  893. $transfer_flag = $temp[2];
  894. $group_id = $temp[3];
  895. $result = $db->db_query("INSERT INTO student_unassign_group
  896. (`student_id`,`faculty_id`,`course_id`,
  897. `term_id`,`transfer_flag`,`group_id`,
  898. `posted`)
  899. VALUES
  900. ('?','?','?','?','?','?','?')
  901. ", $student_id,$faculty_id,$course_id,$term_id,$transfer_flag,$group_id,time());
  902. watchdog("save_unassign_group", "$student_id,group_id:$group_id");
  903. }
  904. if (trim($_POST["restore_unassign_group"]) != "")
  905. {
  906. $temp = explode("~",trim($_POST["restore_unassign_group"]));
  907. $unassign_id = trim($temp[0]) * 1;
  908. $result = $db->db_query("UPDATE student_unassign_group
  909. SET `delete_flag`='1'
  910. WHERE `id`='?' ", $unassign_id);
  911. watchdog("restore_unassign_group", "$student_id,unassign_id:$unassign_id");
  912. }
  913. //------------------------------------------------------
  914. //
  915. // Transfer EQV Unassignments
  916. //
  917. //-------------------------------------------------------
  918. if (trim($_POST["unassign_transfer_eqv"]) != "")
  919. {
  920. $temp = explode("~",trim($_POST["unassign_transfer_eqv"]));
  921. $course_id = $temp[0];
  922. $result = $db->db_query("INSERT INTO student_unassign_transfer_eqv
  923. (`student_id`,`faculty_id`,`transfer_course_id`,
  924. `posted`)
  925. VALUES
  926. ('?','?','?','?')
  927. ", $student_id, $faculty_id, $course_id, time());
  928. watchdog("save_unassign_transfer", "$student_id,course_id:$course_id");
  929. }
  930. if (trim($_POST["restore_transfer_eqv"]) != "")
  931. {
  932. $temp = explode("~",trim($_POST["restore_transfer_eqv"]));
  933. $unassign_id = trim($temp[0]) * 1;
  934. $result = $db->db_query("UPDATE student_unassign_transfer_eqv
  935. SET `delete_flag`='1'
  936. WHERE `id`='?' ", $unassign_id);
  937. watchdog("restore_unassign_transfer", "$student_id,unassign_id:$unassign_id");
  938. }
  939. ////////////////////////////////////////////////////
  940. /////// Cleanup !////////////////////////////////
  941. ////////////////////////////////////////////////////
  942. // If any of the advisingSessions we created earlier
  943. // are blank, we should FLAG them, so they will not
  944. // show up under the student's history.
  945. // Only flag non-draft empty ones. If they are draft,
  946. // let them be.
  947. // We just look at $advising_session_id_array_count[] to see
  948. // if any of the counts are still 0. If they are, delete
  949. // that advisingSessionID from the table.
  950. if ($is_draft == 0)
  951. {
  952. foreach ($advising_session_id_array as $term_id => $advising_session_id)
  953. {
  954. if ($advising_session_id_array_count[$term_id] == 0)
  955. {
  956. // This one is blank! Delete it!
  957. $res = $db->db_query("UPDATE advising_sessions
  958. SET `is_empty`='1'
  959. WHERE `advising_session_id`='?' ", $advising_session_id);
  960. $advising_session_id_array[$term_id] = "";
  961. }
  962. }
  963. }
  964. watchdog("advising", "Student has been advised: @student", array("@student" => $student_id));
  965. return $advising_session_id_array;
  966. }
  967. function load_advising_session_from_database($faculty_id = 0, $term_id = "", $bool_what_if = false, $bool_draft = true, $advising_session_id = 0)
  968. {
  969. // This method will load an advising session for a particular
  970. // student, and modify the degree plan object to reflect
  971. // the advisings.
  972. $db = new DatabaseHandler();
  973. $is_what_if = "0";
  974. $is_draft = "0";
  975. if ($bool_what_if == true){$is_what_if = "1";}
  976. if ($bool_draft == true){$is_draft = "1";}
  977. $degree_id = $this->degree_plan->degree_id;
  978. $student_id = $this->student->student_id;
  979. $available_terms = variable_get("available_advising_term_ids", "0");
  980. $advising_session_line = " `advising_session_id`='$advising_session_id' ";
  981. // First, find the advising session id...
  982. if ($advising_session_id < 1 && $available_terms == "")
  983. {
  984. $advising_session_id = $this->db->get_advising_session_id($faculty_id,$student_id,$term_id,$degree_id,$bool_what_if,$bool_draft);
  985. $advising_session_line = " `advising_session_id`='$advising_session_id' ";
  986. } else if ($advising_session_id < 1 && $available_terms != "")
  987. {
  988. // Meaning, we are looking for more than one term.
  989. $advising_session_line = "(";
  990. $temp = explode(",",$available_terms);
  991. for ($t = 0; $t < count($temp); $t++)
  992. {
  993. $t_id = trim($temp[$t]);
  994. $asid = $this->db->get_advising_session_id($faculty_id,$student_id,$t_id,$degree_id,$bool_what_if,$bool_draft);
  995. if ($asid != 0)
  996. {
  997. $advising_session_line .= " advising_session_id='$asid' || ";
  998. }
  999. }
  1000. // Take off the last 3 chars...
  1001. $advising_session_line = substr($advising_session_line, 0, -3);
  1002. $advising_session_line .= ")";
  1003. if ($advising_session_line == ")")
  1004. { // Found NO previously advised semesters, so just
  1005. // use a dummy value which guarantees it pulls up nothing.
  1006. $advising_session_line = " advising_session_id='-99999'";
  1007. }
  1008. }
  1009. // Now, look up the courses they were advised to take.
  1010. $query = "SELECT * FROM advised_courses
  1011. WHERE
  1012. $advising_session_line
  1013. ORDER BY `id` ";
  1014. //fpm($query);
  1015. $result = $db->db_query($query);
  1016. while($cur = $db->db_fetch_array($result))
  1017. {
  1018. $course_id = trim($cur["course_id"]);
  1019. $semester_num = trim($cur["semester_num"]);
  1020. $group_id = trim($cur["group_id"]);
  1021. $var_hours = trim($cur["var_hours"]);
  1022. $advised_term_id = trim($cur["term_id"]);
  1023. $id = trim($cur["id"]);
  1024. //fpm("course $course_id sem:$semester_num group:$group_id $var_hours");
  1025. // Add this course to the generic list of advised courses. Useful
  1026. // if we are using this to pull up an advising summary.
  1027. $temp_course = new Course($course_id);
  1028. $temp_course->advised_hours = $var_hours;
  1029. $this->course_list_advised_courses->add($temp_course);
  1030. if ($semester_num == -88)
  1031. {
  1032. // This was a courses added by the advisor.
  1033. $this->assign_course_to_courses_added_list($course_id, $var_hours, $id, $advised_term_id);
  1034. continue;
  1035. }
  1036. // Now, we need to modify the degree_plan object to
  1037. // show these advisings.
  1038. if ($course_list = $this->degree_plan->find_courses($course_id, $group_id, $semester_num))
  1039. {
  1040. //fpm("I found course $course_id sem:$semester_num group:$group_id $var_hours");
  1041. //fpm($course_list);
  1042. // This course may exist in several different branches of a group, so we need
  1043. // to mark all the branches as having been advised to take. Usually, this CourseList
  1044. // will probably only have 1 course object in it. But, better safe than sorry.
  1045. $course_list->reset_counter();
  1046. if ($course = $course_list->get_next())
  1047. {
  1048. // make sure the hour count has been loaded correctly.
  1049. if ($course->get_catalog_hours() < 1)
  1050. {
  1051. $course->load_descriptive_data();
  1052. }
  1053. // Let's start by looking at the first course. Is it
  1054. // supposed to be repeated?
  1055. if ($course->bool_specified_repeat==true
  1056. && $course->specified_repeats >= 0 )
  1057. {
  1058. // This is a course which is supposed to be repeated.
  1059. // We need to cycle through and find an instance
  1060. // of this course which has not been advised yet.
  1061. $course_list->reset_counter();
  1062. while($course_list->has_more())
  1063. {
  1064. $course = $course_list->get_next();
  1065. // make sure the hour count has been loaded correctly.
  1066. if ($course->get_catalog_hours() < 1)
  1067. {
  1068. $course->load_descriptive_data();
  1069. }
  1070. //if ($course->bool_advised_to_take != true && !is_object($course->courseFulfilledBy))
  1071. if ($course->bool_advised_to_take != true && $course->course_list_fulfilled_by->is_empty == true)
  1072. {
  1073. // Okay, this course is supposed to be taken/advised
  1074. // more than once. So, I will mark this one as
  1075. // advised, and then break out of the loop, since
  1076. // I don't want to mark all occurances as advised.
  1077. $course->bool_advised_to_take = true;
  1078. $course->assigned_to_semester_num = $semester_num;
  1079. $course->assigned_to_group_id = $group_id;
  1080. // Make sure we assign the hours to the group, so this
  1081. // advised courses takes up a spot in the group. Otherwise
  1082. // it may be missed in later logic.
  1083. if ($g = $this->degree_plan->find_group($group_id)) {
  1084. $h = $var_hours;
  1085. if ($h == 0) {
  1086. $h = $course->get_catalog_hours();
  1087. if ($h == 0) {
  1088. $h = 1; // some problem occured. Just give it a token hour so it doesn't
  1089. // horribly break.
  1090. }
  1091. }
  1092. $g->hours_assigned += $h;
  1093. }
  1094. $course->advised_hours = $var_hours;
  1095. $course->advised_term_id = $advised_term_id;
  1096. $course->db_advised_courses_id = $id;
  1097. $course_list->dec_specified_repeats($course);
  1098. break;
  1099. }
  1100. }
  1101. continue; // Go to the next advised course.
  1102. }
  1103. }
  1104. //////////////////////////////
  1105. // We're here, because it was not a repeatable course.
  1106. // ** We should only go through THIS loop once! So,
  1107. // we will break after we make our assignment.
  1108. $course_list->reset_counter();
  1109. while($course_list->has_more())
  1110. {
  1111. $course = $course_list->get_next();
  1112. // make sure the hour count has been loaded correctly.
  1113. if ($course->get_catalog_hours() < 1)
  1114. {
  1115. $course->load_descriptive_data();
  1116. }
  1117. // make sure it has not already been advised to take.
  1118. // Would occur if the same course is specified more
  1119. // than once in a semester.
  1120. if ($course->bool_advised_to_take == true)
  1121. {
  1122. continue;
  1123. }
  1124. // Has this course already been fulfilled by something?
  1125. // If so, we cannot attempt to say it's been advised!
  1126. if (!$course->course_list_fulfilled_by->is_empty)
  1127. {
  1128. // meaning, this course HAS been fulfilled.
  1129. // So, let's move this advising to the "added by advisor"
  1130. // spot.
  1131. $this->assign_course_to_courses_added_list($course_id, $var_hours, $id, $advised_term_id);
  1132. break;
  1133. }
  1134. //fpm($course);
  1135. $course->bool_advised_to_take = true;
  1136. $course->assigned_to_semester_num = $semester_num;
  1137. $course->assigned_to_group_id = $group_id;
  1138. // Make sure we assign the hours to the group, so this
  1139. // advised courses takes up a spot in the group. Otherwise
  1140. // it may be missed in later logic.
  1141. if ($g = $this->degree_plan->find_group($group_id)) {
  1142. $h = $var_hours;
  1143. if ($h == 0) {
  1144. $h = $course->get_catalog_hours();
  1145. if ($h == 0) {
  1146. $h = 1; // some problem occured. Just give it a token hour so it doesn't
  1147. // horribly break.
  1148. }
  1149. }
  1150. $g->hours_assigned += $h;
  1151. }
  1152. $course->advised_hours = $var_hours;
  1153. $course->advised_term_id = $advised_term_id;
  1154. $course->db_advised_courses_id = $id;
  1155. if ($course->required_on_branch_id > 0)
  1156. {
  1157. // In other words, this course was found on a branch, so we need
  1158. // to increment that branch's count_of_matches.
  1159. if ($branch = $this->degree_plan->find_group($course->required_on_branch_id))
  1160. {
  1161. $branch->count_of_matches++;
  1162. } else {
  1163. fpm("Error: Could not find branch.");
  1164. }
  1165. }
  1166. // We should only be in this loop once, so let's
  1167. // break after we make our assignment.
  1168. break;
  1169. }
  1170. }
  1171. }
  1172. // Now, what we need to do is tell the DegreePlan to re-sort its
  1173. // group's course lists, so that the advised courses are lower
  1174. // than the fulfilled courses.
  1175. //$this->degree_plan->sortGroupsFulfilledFirst();
  1176. //print_pre($this->degree_plan->list_groups->toString());
  1177. } // function loadAdvisingSessionFromDatabase
  1178. function split_requirements_by_substitutions()
  1179. {
  1180. // Go through all the required courses on the degree plan,
  1181. // and if there is a partial substitution specified in the student's
  1182. // list of substitutions, then split that requirement into 2 courses,
  1183. // one with enough hours to satisfy the sub, and the remaining hours.
  1184. $degree_plan = $this->degree_plan;
  1185. $student = $this->student;
  1186. $student->list_substitutions->reset_counter();
  1187. while($student->list_substitutions->has_more())
  1188. {
  1189. $substitution = $student->list_substitutions->get_next();
  1190. $course_requirement = $substitution->course_requirement;
  1191. $course_sub = $substitution->course_list_substitutions->get_first();
  1192. // Check to see if the courseSub's hours_awarded are less than the
  1193. // course_requirement's min hours...
  1194. if ($course_requirement->min_hours > $course_sub->hours_awarded)
  1195. {
  1196. // Meaning the original course requirement is not being
  1197. // fully satisfied by this substitution! The original
  1198. // course requirement has hours left over which must be
  1199. // fulfilled somehow.
  1200. $remaining_hours = $course_requirement->min_hours - $course_sub->hours_awarded;
  1201. // This means that the course requirement needs to be split.
  1202. // So, find this course in the degree plan.
  1203. $required_course_id = $course_requirement->course_id;
  1204. $required_group_id = $course_requirement->assigned_to_group_id;
  1205. $required_semester_num = $course_requirement->assigned_to_semester_num;
  1206. }
  1207. }
  1208. }
  1209. function assign_course_to_courses_added_list($course_id, $var_hours = 0, $db_advised_courses_id = 0, $advised_term_id = 0)
  1210. {
  1211. // Set the supplied course as "advised to take" in the degree plan's
  1212. // special added courses group, which is number -88.
  1213. $course = new Course($course_id, false, $this->db);
  1214. $course->bool_advised_to_take = true;
  1215. $course->assigned_to_semester_num = -88;
  1216. $course->assigned_to_group_id = -88;
  1217. $course->advised_hours = $var_hours;
  1218. $course->db_advised_courses_id = $db_advised_courses_id;
  1219. $course->advised_term_id = $advised_term_id;
  1220. if ($group = $this->degree_plan->find_group(-88))
  1221. {
  1222. $group->list_courses->add($course);
  1223. }
  1224. // Done!
  1225. }
  1226. }