_FlightPath.php

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

File

classes/_FlightPath.php
View source
  1. <?php
  2. class _FlightPath extends stdClass
  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, $student;
  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_csv = $GLOBALS["fp_advising"]["advising_major_code"];
  42. //$track_code = $GLOBALS["fp_advising"]["advising_track_code"];
  43. $track_degree_ids = $GLOBALS["fp_advising"]["advising_track_degree_ids"];
  44. $student_id = $GLOBALS["fp_advising"]["advising_student_id"];
  45. $advising_term_id = $GLOBALS["fp_advising"]["advising_term_id"];
  46. @$available_terms = $GLOBALS["fp_advising"]["available_advising_term_ids"];
  47. // Keep in mind-- at this point, major_coe might be a CSV of major codes.
  48. $this->bool_what_if = false;
  49. // Are we in WhatIf mode?
  50. if ($GLOBALS["fp_advising"]["advising_what_if"] == "yes")
  51. {
  52. $major_code_csv = $GLOBALS["fp_advising"]["what_if_major_code"];
  53. $track_degree_ids = $GLOBALS["fp_advising"]["what_if_track_degree_ids"];
  54. $this->bool_what_if = true;
  55. }
  56. if ($bool_load_full == false)
  57. { // not trying to load anything, so return.
  58. return;
  59. }
  60. $db = $this->db;
  61. if ($bool_load_full == true)
  62. {
  63. $student = new Student($student_id);
  64. } else {
  65. $student = new Student();
  66. $student->student_id = $student_id;
  67. }
  68. $settings = fp_get_system_settings();
  69. $catalog_year = $student->catalog_year;
  70. if ($this->bool_what_if)
  71. {
  72. // We need to look at a "what_if_catalog_year" value.
  73. $catalog_year = $GLOBALS["fp_advising"]["what_if_catalog_year"];
  74. if ($catalog_year == "" || $catalog_year == 0) {
  75. // Some problem, default to current cat year.
  76. $catalog_year = $settings["current_catalog_year"];
  77. }
  78. }
  79. // make sure their catalog year is not past the system's current
  80. // year setting.
  81. if ($catalog_year > $settings["current_catalog_year"] && $settings["current_catalog_year"] > $settings["earliest_catalog_year"])
  82. { // Make sure degree plan is blank if it is!
  83. $catalog_year = 99999;
  84. }
  85. if ($GLOBALS["fp_advising"]["advising_update_student_settings_flag"] != "")
  86. {
  87. // TODO: This is used in What If mode. We need to make sure that these track_degree_ids
  88. // actually do match to the selected majors. If not, then we should remove them. This
  89. // is to make sure that when we switch What If settings, these get cleared.
  90. $wi = "";
  91. if ($this->bool_what_if) {
  92. $wi = "what_if_";
  93. }
  94. //$student->array_settings["track_code"] = $track_code;
  95. $student->array_settings[$wi . "track_degree_ids"] = $track_degree_ids;
  96. $student->array_settings[$wi . "major_code_csv"] = $major_code_csv;
  97. }
  98. // Let's add the track_degree_ids to the major_code_csv...
  99. $major_code_csv .= "," . $track_degree_ids;
  100. ///////////////////////////////
  101. // Okay folks. So this is basically where we will be iterating through all
  102. // of the student's major_codes (if they have more than one), and squishing them together,
  103. // to create a single DegreePlan object, made out of all the options.
  104. // We need like a loop here.
  105. $degree_plans = array();
  106. $temparr = explode(",", $major_code_csv);
  107. foreach ($temparr as $major_code) {
  108. $t_major_code = $major_code;
  109. if (trim($major_code) == "") continue;
  110. // If we are dealing with a track, then just get the degree_id directly, else, figure out the
  111. // degree_id from the t_major_code.
  112. if (is_numeric($t_major_code)) {
  113. $degree_id = $t_major_code;
  114. }
  115. else {
  116. $degree_id = $db->get_degree_id($t_major_code, $catalog_year);
  117. }
  118. // If we couldn't find the degree_id, then we should just skip it.
  119. if (!$degree_id || $degree_id == 0) {
  120. if (variable_get("warning_on_view_if_degree_not_found", "yes") == 'yes') {
  121. fp_add_message(t("Could not find degree %maj in catalog year %cat. FlightPath will
  122. skip loading this degree for now. If this message continues to appear,
  123. contact your advisor.", array("%maj" => $t_major_code, "%cat" => $student->catalog_year . "-" . ($student->catalog_year + 1))), "error", TRUE);
  124. }
  125. continue;
  126. }
  127. /* // NO LONGER NEEDED?
  128. if (@$student->array_settings["track_code"] != "" && $this->bool_what_if == false
  129. && @$student->array_settings["major_code"] == $major_code)
  130. {
  131. // The student has a selected track in their settings,
  132. // so use that (but only if it is for their current major-- settings
  133. // could be old!)
  134. $t_major_code = $student->get_major_and_track_code();
  135. $temp_degree_id = $db->get_degree_id($t_major_code, $student->catalog_year);
  136. if ($temp_degree_id) {
  137. $degree_id = $temp_degree_id;
  138. }
  139. }
  140. */
  141. if ($bool_load_full == true)
  142. {
  143. $this->student = $student;
  144. $degree_plan = fp_load_degree($degree_id, $db, FALSE, $student->array_significant_courses);
  145. $degree_plan->add_semester_developmental($student->student_id);
  146. //$this->degree_plan = $degree_plan;
  147. $degree_plans[$degree_plan->degree_id] = $degree_plan;
  148. }
  149. } // foreach temparr as major_code. The foreach loop through all our major codes.
  150. // Okay, coming out of this, we have an array of degree_plans (maybe). If it's just one, then set it to that one.
  151. if (count($degree_plans) == 1) {
  152. $this->degree_plan = $degree_plan;
  153. }
  154. else if (count($degree_plans) > 1) {
  155. // Okay folks, here's the magic. We need to combine the degree plans in this array
  156. // into 1 generated degree plan.
  157. $combined_degree_plan = $this->combine_degree_plans($degree_plans, $student_id);
  158. $combined_degree_plan->db_allow_dynamic = 1; // since they are combined, we must be allowing dynamic.
  159. $this->degree_plan = $combined_degree_plan;
  160. } // else if count(degree_plans) > 1
  161. else if (count($degree_plans) < 1) {
  162. // Meaning, we couldn't find any degree plans for this student! Let's just load some blank objects.
  163. $this->degree_plan = new DegreePlan();
  164. $this->student = $student;
  165. }
  166. $wi = "";
  167. if ($this->bool_what_if) $wi = "_what_if";
  168. if (isset($this->degree_plan) && $this->degree_plan != null) {
  169. // Add degree_plan to a simple cache to make our lives easier later on.
  170. $_SESSION["fp_simple_degree_plan_cache_for_student" . $wi] = array(
  171. "cwid" => $student_id,
  172. "degree_id" => $this->degree_plan->degree_id,
  173. "combined_degree_ids_array" => $this->degree_plan->combined_degree_ids_array,
  174. "is_combined_dynamic_degree_plan" => $this->degree_plan->is_combined_dynamic_degree_plan,
  175. );
  176. }
  177. } // end of function fp_init
  178. /**
  179. * This function is responsible for combining multiple degree plans into a single unified degree plan,
  180. * then returning it.
  181. */
  182. function combine_degree_plans($degree_plans, $student_id) {
  183. //DEV: // return $degree_plans[0];
  184. $new_degree_plan = new DegreePlan();
  185. // Loop through the degree plans one at a time...
  186. foreach ($degree_plans as $degree_plan) {
  187. $new_degree_plan->combined_degree_ids_array[] = $degree_plan->degree_id;
  188. $new_degree_plan->add_to_required_course_id_array($degree_plan->required_course_id_array);
  189. // Is there a public note to copy over?
  190. if (isset($degree_plan->public_notes_array[$degree_plan->degree_id])) {
  191. $new_degree_plan->public_notes_array[$degree_plan->degree_id] = $degree_plan->public_notes_array[$degree_plan->degree_id];
  192. }
  193. if ($degree_plan->catalog_year == "" || $degree_plan->catalog_year == 0) {
  194. $degree_plan->load_descriptive_data();
  195. }
  196. $new_degree_plan->catalog_year = $degree_plan->catalog_year;
  197. // Okay, now copy whatever we need to into the new_degree_plan.
  198. // First, go through its list of semesters, and copy out all the courses and groups
  199. $degree_plan->list_semesters->reset_counter();
  200. while ($degree_plan->list_semesters->has_more()) {
  201. $sem = $degree_plan->list_semesters->get_next();
  202. // If the semester is the Added by Advisor (-88), or the developmental block (-55) then skip for now.
  203. if ($sem->semester_num == DegreePlan::SEMESTER_NUM_FOR_COURSES_ADDED || $sem->semester_num == DegreePlan::SEMESTER_NUM_FOR_DEVELOPMENTALS) {
  204. // This is the special one that is "added by advisor". Skip it. But remember to add it later to the finished product.
  205. // Or, it's the developmentals block. Add that later too.
  206. continue;
  207. }
  208. // Okay, the semester contains a CourseList called list_courses, and a GroupList caled list_groups.
  209. $new_list_courses = $sem->list_courses->get_clone();
  210. // Now, let's add them to the new_degree_plan's semester...
  211. // if the new degree plan already has this semester, get that instead.
  212. $the_semester = $new_degree_plan->get_semester($sem->semester_num);
  213. if (!$the_semester) {
  214. $the_semester = new Semester($sem->semester_num);
  215. $new_degree_plan->list_semesters->add($the_semester);
  216. }
  217. // Should we rename the_semester's title (because the semester we are grabbing is overriding?)
  218. //$degree_plan->load_descriptive_data(); // Doesn't appear to be necessary at this stage.
  219. $stitle = trim(@$degree_plan->array_semester_titles[$sem->semester_num]);
  220. if ($stitle != "") {
  221. // Meaning we should overwrite the semester title, because this degree isn't using the default title
  222. $the_semester->title = $stitle;
  223. $the_semester->bool_using_default_title = FALSE;
  224. }
  225. // Okay, now add the courses to the_semester
  226. $the_semester->list_courses->add_list($new_list_courses);
  227. ////////////////////////////
  228. // Getting the list of groups is going to be similar to getting our list of courses.
  229. // Go through the list of groups for this semester.
  230. $new_list_groups = $sem->list_groups->get_clone(FALSE, FALSE, FALSE);
  231. // Okay, now we can add to our semester
  232. $the_semester->list_groups->add_list($new_list_groups);
  233. // Also add this group list to the degree plan's list_groups.
  234. $new_degree_plan->list_groups->add_list($new_list_groups);
  235. } // while, listing semesters in degree plan.
  236. } // foreach degree_plans
  237. //////////////////////////////
  238. // Okay, now to put the finishing touches on the $new_degree_plan
  239. // Add in the "Developmental Req's" if required for this student.
  240. $new_degree_plan->add_semester_developmental($student_id);
  241. // Add in the "Courses added by advisor"
  242. $new_degree_plan->add_semester_courses_added();
  243. if (count($degree_plans) > 1) {
  244. $new_degree_plan->is_combined_dynamic_degree_plan = TRUE;
  245. $new_degree_plan->degree_id = DegreePlan::DEGREE_ID_FOR_COMBINED_DEGREE; // use constant to make it easier later on.
  246. }
  247. // Make sure all of our groups have reloaded any missing courses.
  248. $new_degree_plan->list_semesters->reset_counter();
  249. while ($new_degree_plan->list_semesters->has_more()) {
  250. $sem = $new_degree_plan->list_semesters->get_next();
  251. $sem->list_groups->reload_missing_courses();
  252. }
  253. return $new_degree_plan;
  254. } // combine_degree_plans
  255. /**
  256. * This function will check to see if we are trying to save
  257. * the draft from a tab change. It should be near the top
  258. * of all of FP's "tab" pages, like Main, Comments, etc.
  259. *
  260. */
  261. function process_request_save_draft()
  262. {
  263. /////////////////////////////////////
  264. /// Are we trying to save the draft
  265. /// from a tab change?
  266. /////////////////////////////////////
  267. if ($_REQUEST["save_draft"] == "yes")
  268. {
  269. $this->init(true, false, false);
  270. // If we are coming from the WhatIf tab, we need to save
  271. // as WhatIf. Else, save as normal.
  272. if ($_REQUEST["from_w_i"] == "yes")
  273. {
  274. // Yes, we are coming from WhatIf mode, so
  275. // save under WhatIf.
  276. $GLOBALS["advising_what_if"] = "yes";
  277. $this->init(false);
  278. } else {
  279. // NOT coming from WhatIf mode. Save as a normal draft.
  280. $GLOBALS["advising_what_if"] = "no";
  281. $this->init(true, true);
  282. }
  283. $this->save_advising_session_from_post(0,true);
  284. }
  285. }
  286. function assign_courses_to_groups() {
  287. // This method will look at the student's courses
  288. // and decide which groups they should be fit into.
  289. // We will be going through the degree plan's master list
  290. // of groups to decide this.
  291. $student = $this->student;
  292. $this->degree_plan->list_groups->sort_priority();
  293. // Now, sort by the advising weight of the degree itself.
  294. $this->degree_plan->list_groups->sort_degree_advising_weight();
  295. $this->degree_plan->list_groups->reset_counter();
  296. while($this->degree_plan->list_groups->has_more())
  297. {
  298. $g = $this->degree_plan->list_groups->get_next();
  299. if ($g->group_id == DegreePlan::GROUP_ID_FOR_COURSES_ADDED)
  300. {
  301. // Add a course group. Skip.
  302. continue;
  303. }
  304. // Does the student have any group additions for this
  305. // group? Technically it is a substitution.
  306. // We will add them in now, because we do not take additions
  307. // into consideration when figuring out branches.
  308. if ($course_list_additions = $student->list_substitutions->find_group_additions($g))
  309. {
  310. $course_list_additions->reset_counter();
  311. while($course_list_additions->has_more())
  312. {
  313. $cA = $course_list_additions->get_next();
  314. $new_course = new Course();
  315. $new_course->course_id = $cA->course_id;
  316. if ($cA->bool_transfer == true)
  317. {
  318. if ($cA->course_id == 0 && is_object($cA->course_transfer))
  319. { // This is a transfer course which has been added.
  320. $new_course->course_id = $cA->course_transfer->course_id;
  321. }
  322. $new_course->bool_transfer = true;
  323. }
  324. $new_course->assigned_to_semester_num = $g->assigned_to_semester_num;
  325. $new_course->requirement_type = $g->requirement_type;
  326. // Add this course as a requirement.
  327. //$new_course->load_descriptive_data();
  328. $g->list_courses->add($new_course, true);
  329. // Later on, when we do assign_courses_to_list, it
  330. // will automatically find this course and apply the
  331. // substitution.
  332. }
  333. }
  334. // First we see if there are any bare courses at this level. If there
  335. // are, then this group has NO branches! Otherwise, the courses must
  336. // always be contained in a branch!
  337. if (!$g->list_courses->is_empty)
  338. {
  339. // Yes, there are courses here. So, assign them at this level.
  340. $this->assign_courses_to_list($g->list_courses, $this->student, true, $g, true);
  341. // Okay, if we have fulfilled our courses at this level.
  342. // then we can continue on to the next "top level" group.
  343. //continue;
  344. }
  345. if (!$g->list_groups->is_empty)
  346. {
  347. /*
  348. Now we've got some trouble. This is our first level of groups.
  349. If this object exists, then it means that this group branches off
  350. at its first level. So, instead of actually assigning courses to
  351. groups, we need to find out which group has the most matches, and THEN
  352. we will assign them.
  353. */
  354. $g->reload_missing_courses();
  355. $high_count = -1;
  356. $best_branch = -1;
  357. // Sort our list of groups by student's grades, if applicable.
  358. $sort_policy = variable_get("initial_student_course_sort_policy", "alpha"); // will either be "alpha" or "grade"
  359. if ($sort_policy == "grade") {
  360. $g->list_groups->sort_best_grade_first_by_student_grades($student);
  361. }
  362. $g->list_groups->reset_counter();
  363. while($g->list_groups->has_more())
  364. {
  365. $branch_one = $g->list_groups->get_next();
  366. if (!$branch_one->list_courses->is_empty)
  367. {
  368. // This does not actually assign. Just counts.
  369. $count = $this->get_count_of_matches($branch_one, $this->student, $g);
  370. $branch_one->count_of_matches = $count;
  371. if ($count > $high_count)
  372. {
  373. $high_count = $count;
  374. $best_branch = $g->list_groups->object_index_of($branch_one);
  375. }
  376. }
  377. }
  378. // Okay, coming out of that, we should know which branch has the best count (number
  379. // of matches). So, let's assign courses to that branch.
  380. if ($best_branch != -1)
  381. {
  382. $winning_branch = $g->list_groups->get_element($best_branch);
  383. $winning_branch->bool_winning_branch = TRUE;
  384. $this->assign_courses_to_list($winning_branch->list_courses, $this->student, TRUE, $g, TRUE);
  385. }
  386. }
  387. } // while
  388. }
  389. function get_count_of_matches($branch, $student, $group)
  390. {
  391. return $this->assign_courses_to_list($branch->list_courses, $student, FALSE, $group, TRUE);
  392. }
  393. function flag_outdated_substitutions()
  394. {
  395. // Go through the student's substitutions and flag ones that
  396. // do not apply to this degree plan. Also, unset any bool_substitution
  397. // variables which were set.
  398. $this->student->list_substitutions->reset_counter();
  399. while ($this->student->list_substitutions->has_more())
  400. {
  401. $substitution = $this->student->list_substitutions->get_next();
  402. ////////////////////////////
  403. // Ticket #2316, from Logan Buth, this is to better detect outdated subs for combined degrees.
  404. $bool_sub_valid = true;
  405. $outdated_note = "";
  406. if ($this->degree_plan->degree_id == DegreePlan::DEGREE_ID_FOR_COMBINED_DEGREE &&
  407. !in_array($substitution->db_required_degree_id, $this->degree_plan->combined_degree_ids_array)) {
  408. //combined degree plan, degree id not in it.
  409. $bool_sub_valid = false;
  410. $sub_degree_title = fp_get_degree_title($substitution->db_required_degree_id, TRUE, TRUE, FALSE, TRUE);
  411. $outdated_note = t("This substitution is for the degree %did
  412. which is no longer in the student's degrees.", array("%did" => $sub_degree_title));
  413. }
  414. else if ($this->degree_plan->degree_id != DegreePlan::DEGREE_ID_FOR_COMBINED_DEGREE &&
  415. $this->degree_plan->degree_id != $substitution->db_required_degree_id) {
  416. $bool_sub_valid = false;
  417. $sub_degree_title = fp_get_degree_title($substitution->db_required_degree_id, TRUE, TRUE, FALSE, TRUE);
  418. $outdated_note = t("This substitution is for the degree %did
  419. which is no longer the student's degree", array("%did" => $sub_degree_title));
  420. }
  421. //////////////
  422. //$required_group_id = $substitution->course_requirement->assigned_to_group_id;
  423. $required_group_id = $substitution->course_requirement->get_first_assigned_to_group_id(); // we assume there's only one group to get
  424. // First check-- does this degree even have this group ID?
  425. if ($bool_sub_valid && $required_group_id == 0) {
  426. // bare degree plan.
  427. // Does the bare degree plan list the course_requirement
  428. // anywhere?
  429. $bool_sub_valid = false;
  430. $this->degree_plan->list_semesters->reset_counter();
  431. while($this->degree_plan->list_semesters->has_more() && $bool_sub_valid == false)
  432. {
  433. $sem = $this->degree_plan->list_semesters->get_next();
  434. if ($sem->list_courses->find_match($substitution->course_requirement))
  435. {
  436. $bool_sub_valid = true;
  437. } else {
  438. // Could not find the course requirement in question.
  439. $bool_sub_valid = false;
  440. $scr = $substitution->course_requirement;
  441. $scr->load_descriptive_data();
  442. $outdated_note = t("This substitution is for the course %info on the
  443. bare degree plan, but the student's current degree does
  444. not specify this course.", array("%info" => "$scr->subject_id $scr->course_num (id: $scr->course_id)"));
  445. }
  446. }
  447. }
  448. else if ($bool_sub_valid && $required_group_id != 0) {
  449. // required_group_id != 0, meaning, NOT the bare degree plan.
  450. // So, does this degree plan have a group with this id (required_group_id)?
  451. $bool_sub_valid = false;
  452. if ($g = $this->degree_plan->find_group($required_group_id)) {
  453. $bool_sub_valid = true;
  454. }
  455. else {
  456. // Could not find the group in question. Add an "outdated_note"
  457. // to the sub...
  458. $bool_sub_valid = false;
  459. $new_group = new Group();
  460. $new_group->group_id = $required_group_id;
  461. $new_group->load_descriptive_data();
  462. $group_name = "";
  463. if (user_has_permission("can_access_data_entry")) {
  464. // only show if we are a data entry administrator.
  465. $group_name = "<i>$new_group->group_name,</i>";
  466. }
  467. $outdated_note = t("This substitution is for the group %info,
  468. but the student's current degree does not call for this
  469. specific group.", array("%info" => "$new_group->title (id: $new_group->group_id, $group_name $new_group->catalog_year)"));
  470. }
  471. }
  472. if ($bool_sub_valid == false) {
  473. // Couldn't find a match, so remove this sub!
  474. $substitution->bool_outdated = true;
  475. $substitution->outdated_note = $outdated_note;
  476. $substitution->course_list_substitutions->get_first()->bool_outdated_sub = true;
  477. $substitution->course_list_substitutions->get_first()->set_bool_outdated_sub(0, TRUE);
  478. //$substitution->course_list_substitutions->get_first()->bool_substitution = false;
  479. $substitution->course_list_substitutions->get_first()->set_bool_substitution(0, FALSE);
  480. if ($substitution->course_list_substitutions->get_first()->temp_old_course_id > 0)
  481. { // Restore the course_id *if* it was set to 0 on purpose. (happens
  482. // when there is a sub of a transfer to kill the transfer eqv. This will
  483. // restore it).
  484. $substitution->course_list_substitutions->get_first()->course_id = $substitution->course_list_substitutions->get_first()->temp_old_course_id;
  485. }
  486. }
  487. }
  488. }
  489. function assign_courses_to_list(ObjList $list_requirements, Student $student, $bool_perform_assignment = true, Group $group = null, $bool_check_significant_courses = false)
  490. {
  491. $count = 0;
  492. if ($group == null)
  493. {
  494. $group = new Group();
  495. $group->group_id = 0;
  496. }
  497. else if ($group->min_grade != "") {
  498. $group->assign_min_grade($group->min_grade); // If this is a group with a min grade value, let's make sure we assign all the courses in it to this min grade.
  499. }
  500. $sort_policy = variable_get("initial_student_course_sort_policy", "alpha"); // will either be "alpha" or "grade"
  501. $bool_disallow_graduate_credits = (variable_get("disallow_graduate_credits", "yes") == "yes") ? TRUE : FALSE;
  502. $graduate_level_codes_array = csv_to_array(variable_get("graduate_level_codes", "GR"));
  503. // Get the course repeat policy.
  504. $course_repeat_policy = variable_get("course_repeat_policy", "most_recent_exclude_previous");
  505. // Set the $bool_mark_repeats_exclude variable based on the course_repeat_policy.
  506. $bool_mark_repeats_exclude = ($course_repeat_policy == "most_recent_exclude_previous" || $course_repeat_policy == "best_grade_exclude_others");
  507. $group_id = $group->group_id;
  508. // If the group_id == 0, we may be talking about the bare degree plan.
  509. $hours_required = $group->hours_required*1;
  510. $hours_assigned = $group->hours_assigned;
  511. $meet_min_hours = 999999; // effectively infinite by default, to make logic easier later on.
  512. // If the group has min_hours, then we should allow the user to get at least the min hours before we stop trying to fill.
  513. if ($group->has_min_hours_allowed() && variable_get("group_full_at_min_hours", "yes") == "yes") {
  514. $meet_min_hours = $group->min_hours_allowed;
  515. }
  516. if ($hours_required <= 0 || $hours_required == "")
  517. {
  518. $hours_required = 999999;
  519. }
  520. $list_requirements->sort_smallest_hours_first();
  521. // sort the requirement list by the best grades that the student has made? Similar to the substitutions?
  522. if ($sort_policy == "grade") {
  523. $list_requirements->sort_best_grade_first($student);
  524. }
  525. else if ($sort_policy == "alpha") {
  526. $list_requirements->sort_alphabetical_order();
  527. }
  528. $list_requirements->sort_substitutions_first($student->list_substitutions, $group_id);
  529. $list_requirements->reset_counter();
  530. while($list_requirements->has_more())
  531. {
  532. $course_requirement = $list_requirements->get_next();
  533. $req_by_degree_id = $course_requirement->req_by_degree_id; // what degree is requiring this course?
  534. // If we're dealing with a group, use it's required by degree id.
  535. if ($group->group_id != "" && $group->req_by_degree_id > 0) {
  536. $req_by_degree_id = $group->req_by_degree_id;
  537. }
  538. if ($bool_check_significant_courses == true)
  539. {
  540. // Only look for the course_requirement if it is in the student's
  541. // array_significant_courses array.
  542. if (isset($student->array_significant_courses[$course_requirement->course_id]) && $student->array_significant_courses[$course_requirement->course_id] != true)
  543. {// course was not in there, so skip!
  544. continue;
  545. }
  546. }
  547. if ($course_requirement->bool_specified_repeat == true)
  548. {
  549. // Since this requirement has specified repeats, we want
  550. // to make all of the student's taken courses (for this course)
  551. // also have specified repeats.
  552. $student->list_courses_taken->set_specified_repeats($course_requirement, $course_requirement->specified_repeats);
  553. }
  554. // Does the student have any substitutions for this requirement?
  555. if ($substitution = $student->list_substitutions->find_requirement($course_requirement, true, $group_id, $req_by_degree_id))
  556. {
  557. // Since the substitution was made, I don't really care about
  558. // min grades or the like. Let's just put it in.
  559. if ($bool_perform_assignment == TRUE)
  560. {
  561. // Check to see if this course requirement has "infinite repeats". If it does, then we want to
  562. // clone it and add it back into our list of requirements.
  563. if ($course_requirement->specified_repeats == Group::GROUP_COURSE_INFINITE_REPEATS) {
  564. $temp_ds = $course_requirement->to_data_string();
  565. $new_course = new Course();
  566. $new_course->load_course_from_data_string_for_requirement_clone($temp_ds);
  567. $new_course->min_grade = $course_requirement->min_grade;
  568. $list_requirements->add($new_course);
  569. }
  570. // Make sure this isn't a group addition and we are *currently*
  571. // NOT looking at the group it is being added to. This is to
  572. // correct a bug.
  573. if ($substitution->bool_group_addition == true)
  574. {
  575. if ($substitution->course_requirement->get_first_assigned_to_group_id() != $group_id)
  576. {
  577. continue;
  578. }
  579. }
  580. // If the course_requirement's min_hours are greater than
  581. // the substitution's hours, then we have to split the
  582. // coureRequirement into 2 pieces, and add the second piece just
  583. // after this one in the list.
  584. $course_sub = $substitution->course_list_substitutions->get_first();
  585. if ($course_requirement->min_hours*1 > $course_sub->get_hours_awarded($req_by_degree_id))
  586. {
  587. // Because float math can create some very strange results, we must
  588. // perform some rounding. We will round to 6 decimal places, which should
  589. // provide us the accuracy w/o losing precision (since we can only represent a max
  590. // of 4 decimals in the database anyway.
  591. $remaining_hours = round($course_requirement->min_hours - $course_sub->get_hours_awarded($req_by_degree_id), 6);
  592. $new_course_string = $course_requirement->to_data_string();
  593. $new_course = new Course();
  594. $new_course->load_course_from_data_string($new_course_string);
  595. $new_course->min_hours = $new_course->max_hours = $remaining_hours;
  596. $new_course->set_bool_substitution_split($req_by_degree_id, TRUE);
  597. $new_course->set_bool_substitution_new_from_split($req_by_degree_id, TRUE);
  598. $new_course->requirement_type = $course_requirement->requirement_type;
  599. $new_course->min_grade = $course_requirement->min_grade;
  600. $new_course->req_by_degree_id = $req_by_degree_id;
  601. $new_course->assigned_to_degree_ids_array[$req_by_degree_id] = $req_by_degree_id;
  602. $course_requirement->set_bool_substitution_split($req_by_degree_id, TRUE);
  603. // I am commenting this out-- if we split up a sub multiple times, then we shouldn't
  604. // set the old course requirement to say it WASN'T from a split. This was causing a bug
  605. // where the pie charts got weird if you did more than 1 split. Was counting total
  606. // hours as more, in CourseList->count_hours().
  607. //$course_requirement->bool_substitution_new_from_split = false;
  608. // Only do this if we are NOT in a group! This is to correct a bug where split additions to groups wound up
  609. // being displayed like available selections in the group. It was like, weird man.
  610. if ($group_id == 0) {
  611. // Now, add this into the list, right after the course_requirement.
  612. $current_i = $list_requirements->i;
  613. $list_requirements->insert_after_index($current_i, $new_course);
  614. }
  615. } // if min_hours > sub's awarded hours
  616. $course_requirement->course_list_fulfilled_by = $substitution->course_list_substitutions;
  617. $substitution->course_list_substitutions->assign_group_id($group_id);
  618. $substitution->course_list_substitutions->set_has_been_assigned(true);
  619. $substitution->course_list_substitutions->set_bool_substitution($req_by_degree_id, TRUE);
  620. $course_requirement->db_substitution_id_array[] = $substitution->db_substitution_id;
  621. $substitution->course_list_substitutions->set_course_substitution($course_requirement, $substitution->remarks, $req_by_degree_id);
  622. $substitution->bool_has_been_applied = TRUE;
  623. if ($group_id != "" && intval($group_id) > 0) {
  624. // We are going to add the course_sub's hours in as being assigned to this list, if this is for a group.
  625. // I am surprised this wasn't already here. This fixes a bug with groups that allow min hours.
  626. $hours_assigned += $course_sub->get_hours_awarded($req_by_degree_id);
  627. }
  628. }
  629. $count++;
  630. continue;
  631. } // if student has any substitutions for this requirement
  632. // Has the student taken this course requirement?
  633. if ($c = $student->list_courses_taken->find_best_match($course_requirement, $course_requirement->min_grade, $bool_mark_repeats_exclude, $req_by_degree_id, TRUE, TRUE, $group_id))
  634. {
  635. $h_get_hours = $c->get_hours();
  636. if ($c->bool_ghost_hour) {
  637. // If this is a ghost hour, then $h_get_hours would == 0 right now,
  638. // instead, use the the adjusted value (probably 1).
  639. $h_get_hours = $c->get_hours_awarded($req_by_degree_id);
  640. }
  641. // Can we assign any more hours to this group? Are we
  642. // out of hours, and should stop?
  643. if ($hours_assigned >= $hours_required || $hours_assigned >= $meet_min_hours)
  644. {
  645. continue;
  646. }
  647. $c_hours_awarded = $c->get_hours_awarded($req_by_degree_id);
  648. // Will the hours of this course put us over the hours_required limit? NOTE: We don't care if it puts us over the min_hours, in fact, we want that.
  649. if ($hours_assigned + $c_hours_awarded > $hours_required )
  650. {
  651. continue;
  652. }
  653. // Do not apply substitution new_from_split courses to anything automatically. (from any degree!)
  654. // They must be applied by substitutions.
  655. if ($c->get_bool_substitution_new_from_split() == TRUE)
  656. {
  657. continue;
  658. }
  659. // Make sure the course meets min grade requirements.
  660. if (!$c->meets_min_grade_requirement_of($course_requirement))
  661. {
  662. continue;
  663. }
  664. // Has the course been unassigned from this group?
  665. if ($c->group_list_unassigned->find_match_with_degree_id($group, $req_by_degree_id))
  666. {
  667. continue;
  668. }
  669. // Make sure $c is not being used in a substitution (for this degree)
  670. if ($c->get_bool_substitution($req_by_degree_id) == TRUE) {
  671. continue;
  672. }
  673. // If this is a graduate level course, and we are not allowing grad credits, then skip!
  674. if ($c->level_code != "" && in_array($c->level_code, $graduate_level_codes_array)) {
  675. if ($bool_disallow_graduate_credits) {
  676. continue;
  677. }
  678. }
  679. // Check hooks to see if this course is allowed to be assigned to the GROUP in question.
  680. if ($group_id != "" && $group_id != 0) {
  681. $bool_can_proceed = TRUE;
  682. $result = invoke_hook("flightpath_can_assign_course_to_group", array($group, $c));
  683. foreach ($result as $m => $val) {
  684. // If *any* module said FALSE, then we must skip this course and not assign it to this degree.
  685. if ($val === FALSE) $bool_can_proceed = $val;
  686. }
  687. if (!$bool_can_proceed) {
  688. continue; // don't assign!
  689. }
  690. } // if group_id != ""
  691. // We want to see if this course has already been assigned to THIS degree...
  692. if (!in_array($req_by_degree_id, $c->assigned_to_degree_ids_array))
  693. {//Don't count courses which have already been placed in other groups.
  694. // Check hooks to see if this course is allowed to be assigned to the degree in question.
  695. $bool_can_proceed = TRUE;
  696. $result = invoke_hook("flightpath_can_assign_course_to_degree_id", array($req_by_degree_id, $c));
  697. foreach ($result as $m => $val) {
  698. // If *any* module said FALSE, then we must skip this course and not assign it to this degree.
  699. if ($val === FALSE) $bool_can_proceed = $val;
  700. }
  701. if (!$bool_can_proceed) {
  702. continue; // don't assign!
  703. }
  704. // Has another version of this course already been
  705. // assigned? And if so, are repeats allowed for this
  706. // course? And if so, then how many hours of the
  707. // repeat_hours have I used up? If I cannot do any more
  708. // repeats, then quit. Otherwise, let it continue...
  709. $course_list_repeats = $student->list_courses_taken->get_previous_assignments($c->course_id);
  710. if ($course_list_repeats->get_size() > 0)
  711. {
  712. // So, a copy of this course has been assigned more than once...
  713. // Get the total number of hours taken up by this course.
  714. $cc = $course_list_repeats->count_hours();
  715. // have we exceeded the number of available repeat_hours
  716. // for this course?
  717. if ($course_requirement->repeat_hours <= 0)
  718. {
  719. $course_requirement->load_descriptive_data();
  720. }
  721. if (($course_requirement->bool_ghost_hour != TRUE || $c->bool_ghost_hour != TRUE)
  722. && $cc + $h_get_hours > $course_requirement->repeat_hours*1)
  723. {
  724. // Do not allow the repeat, unless we are talking about courses worth zero hours.
  725. // meaning, they have a ghost hour. In which case, allow it.
  726. continue;
  727. }
  728. }
  729. // Basically--- if the most recent attempt fails
  730. // a min grade check, then tag all attempts as "unuseable"
  731. // so that they can't be used in other groups. --
  732. // unless they are able to be repeated. BARF!
  733. // Inc hours_assigned, even if we aren't actually
  734. // performing an assignment. This helps us accurately
  735. // calculate the count.
  736. $hours_assigned = $hours_assigned + $h_get_hours;
  737. if ($bool_perform_assignment == TRUE)
  738. {
  739. // If this course has an "infinite" number of specified repeats, then
  740. // let's actually clone the course and insert it as a new requirement, to replace
  741. // the one we're about to use.
  742. if ($course_requirement->specified_repeats == Group::GROUP_COURSE_INFINITE_REPEATS) {
  743. $temp_ds = $course_requirement->to_data_string();
  744. $new_course = new Course();
  745. $new_course->load_course_from_data_string_for_requirement_clone($temp_ds);
  746. $new_course->min_grade = $course_requirement->min_grade;
  747. $list_requirements->add($new_course);
  748. }
  749. // Which degree is this coming from?
  750. //$req_by_degree_id = $course_requirement->req_by_degree_id;
  751. $c->assigned_to_degree_ids_array[$req_by_degree_id] = $req_by_degree_id;
  752. // Go ahead and state that the requirement was fulfilled.
  753. $course_requirement->course_list_fulfilled_by->add($c);
  754. $course_requirement->grade = $c->grade;
  755. $course_requirement->set_hours_awarded($req_by_degree_id, $c->get_hours_awarded($req_by_degree_id));
  756. $course_requirement->bool_ghost_hour = $c->bool_ghost_hour;
  757. // No longer using... using the assigned_to_degree_ids_array instead. // $c->bool_has_been_assigned = true;
  758. //$c->requirement_type = $course_requirement->requirement_type;
  759. if ($c->requirement_type == "") {
  760. // No requirement type given? Perhaps we are part of a group. If so, use that.
  761. //$c->requirement_type = $group->requirement_type;
  762. //$course_requirement->requirement_type = $group->requirement_type;
  763. }
  764. // Check what groups it has been assigned to already.
  765. //$c->assigned_to_group_id = $group_id;
  766. if ($group_id > 0) {
  767. $c->assigned_to_group_ids_array[$group_id . "_" . $req_by_degree_id] = $group_id;
  768. }
  769. $group->hours_assigned = $hours_assigned;
  770. // Should check for:
  771. // Can it be assigned, based on the number of allowed course repeats?
  772. if ($course_requirement->bool_specified_repeat == true)
  773. {
  774. // $c is what they actually took.
  775. $c->bool_specified_repeat = true;
  776. $c->specified_repeats = $course_requirement->specified_repeats;
  777. $list_requirements->dec_specified_repeats($c);
  778. }
  779. }
  780. $count++;
  781. }
  782. }
  783. }
  784. return $count;
  785. }
  786. function assign_courses_to_semesters()
  787. {
  788. // This method will look at the student's courses
  789. // and decide if they should be assigned to degree requirements
  790. // which have been spelled out in each semester. This
  791. // is not where it looks into groups.
  792. $this->degree_plan->list_semesters->reset_counter();
  793. while($this->degree_plan->list_semesters->has_more())
  794. {
  795. $semester = $this->degree_plan->list_semesters->get_next();
  796. // Okay, let's look at the courses (not groups) in this
  797. // semester...
  798. $this->assign_courses_to_list($semester->list_courses, $this->student);
  799. }
  800. }
  801. /**
  802. * Get the plain English title of a subject, from
  803. * subject_id. Ex: COSC = Computer Science.
  804. *
  805. * @param unknown_type $subject_id
  806. * @return unknown
  807. */
  808. function get_subject_title($subject_id)
  809. {
  810. // From the subject_id, get the title.
  811. // Example: COSC = Computer Science.
  812. $res = $this->db->db_query("SELECT title FROM subjects
  813. WHERE subject_id = '?' LIMIT 1 ", $subject_id);
  814. $cur = $this->db->db_fetch_array($res);
  815. return trim($cur["title"]);
  816. }
  817. function get_all_courses_in_catalog_year($catalog_year = "2006", $bool_load_descriptive_data = false, $limit_start = 0, $limit_size = 0)
  818. {
  819. // Returns a CourseList object of all the
  820. // undergraduate courses in the
  821. // supplied catalog_year.
  822. $lim_line = "";
  823. if ($limit_size > 0)
  824. {
  825. $lim_line = " limit $limit_start, $limit_size ";
  826. }
  827. $rtn_list = new CourseList();
  828. $c_array = array();
  829. $result = $this->db->db_query("SELECT * FROM courses
  830. WHERE
  831. catalog_year = '?'
  832. AND course_num < '{$GLOBALS["fp_system_settings"]["graduate_level_course_num"]}'
  833. ORDER BY subject_id, course_num
  834. $lim_line
  835. ", $catalog_year);
  836. while($cur = $this->db->db_fetch_array($result))
  837. {
  838. $course = new Course();
  839. $course->course_id = $cur["course_id"];
  840. $course->subject_id = $cur["subject_id"];
  841. $course->course_num = $cur["course_num"];
  842. $course->min_hours = $cur["min_hours"];
  843. $course->max_hours = $cur["max_hours"];
  844. if ($bool_load_descriptive_data == true)
  845. {
  846. $course->load_descriptive_data();
  847. }
  848. $rtn_list->add($course);
  849. }
  850. return $rtn_list;
  851. }
  852. function cache_course_inventory($limit_start = 0, $limit_size = 4000)
  853. {
  854. // Load courses from the inventory into the inventory cache...
  855. // Attempt to load the course inventory cache...
  856. if ($course_inventory = unserialize(@$_SESSION["fp_cache_course_inventory"]))
  857. {
  858. $GLOBALS["fp_course_inventory"] = $course_inventory;
  859. }
  860. $result = $this->db->db_query("SELECT DISTINCT course_id FROM courses
  861. WHERE
  862. course_num < '{$GLOBALS["fp_system_settings"]["graduate_level_course_num"]}'
  863. LIMIT $limit_start, $limit_size
  864. ");
  865. while($cur = $this->db->db_fetch_array($result))
  866. {
  867. $course_id = $cur["course_id"];
  868. $this->db->load_course_descriptive_data(null, $course_id);
  869. }
  870. // Should we re-cache the course inventory? If there have been any changes
  871. // to it, then we will see that in a GLOBALS variable...
  872. if ($GLOBALS["cache_course_inventory"] == true)
  873. {
  874. $_SESSION["fp_cache_course_inventory"] = serialize($GLOBALS["fp_course_inventory"]);
  875. }
  876. }
  877. function replace_missing_course_in_group($course_id, $group_id)
  878. {
  879. // Given a group in the degree plan, this will
  880. // make sure that course is actually in the group. If it
  881. // is not, then it will add it in where it should be.
  882. // This is necessary because we have previously removed
  883. // courses which the student hadn't taken. Well, if the
  884. // student was advised for a particular course in a group,
  885. // then that course probably was originally removed
  886. // from the group. So, put it back in.
  887. // First, find the group.
  888. if (!$group = $this->degree_plan->find_group($group_id))
  889. {
  890. fpm(" ~~ could not find group $group_id for replacemMissingCourseInGroup");
  891. return;
  892. }
  893. // Okay, now tell the group to replace the instance of this course
  894. // in the group. This is made easy, because we have
  895. // the dbGroupRequirementID, which is the actual id from the
  896. // row in group_requirements that this course was advised from.
  897. $group->replace_missing_course($course_id);
  898. }
  899. function save_advising_session_from_post($faculty_id = 0, $bool_draft = true)
  900. {
  901. global $user;
  902. $catalog_year = 0;
  903. $bool_fp_goto_at_end = FALSE;
  904. // This method will, only by looking at variables in the
  905. // POST, save an advising session into the database.
  906. $db = get_global_database_handler();
  907. if ($faculty_id == 0) {
  908. // if none supplied, use the one from the session of
  909. // whomever is currently logged in.
  910. $faculty_id = $user->cwid;
  911. }
  912. // It's possible the user has simply pressed "refresh" after submitting the form. If so,
  913. // there is no reason to re-submit everything, creating duplicate data in some situations.
  914. $post_md5 = md5(serialize($_POST));
  915. if (@$_SESSION["fp_previous_advising_post_md5"] == $post_md5) {
  916. return array();
  917. }
  918. // We may proceed, but save the POST md5 for next time.
  919. $_SESSION["fp_previous_advising_post_md5"] = $post_md5;
  920. $bool_found_update_match = false;
  921. $student_id = $this->student->student_id;
  922. $degree_id = $this->degree_plan->degree_id;
  923. $major_code_csv = $this->degree_plan->get_major_code_csv();
  924. $catalog_year = $this->degree_plan->catalog_year;
  925. $available_terms = variable_get("available_advising_term_ids", "0");
  926. // Do we need to update the student's settings?
  927. if (trim($_POST["advising_update_student_settings_flag"]) != "")
  928. {
  929. // We are to assume that the student's array_settings
  930. // have already been updated by this point, so we will
  931. // simply convert them to XML and store in the database.
  932. $result = $db->db_query("REPLACE INTO student_settings
  933. (student_id, settings, posted)
  934. VALUES ('?','?', '?' ) ", $student_id, serialize($this->student->array_settings), time());
  935. watchdog("update_student_settings", "Settings updated for this student.");
  936. }
  937. //var_dump($_POST);
  938. // die;
  939. // We have changed tracks, so we are to edit the student degrees table.
  940. if ($_POST["advising_update_student_degrees_flag"] == "true") {
  941. // Begin by deleting all the "editable" rows for this student
  942. // in student_degrees.
  943. db_query("DELETE FROM student_degrees
  944. WHERE student_id = '?'
  945. AND is_editable = '1' ", $student_id);
  946. // Now, go through our list of degree tracks ids we're adding back in, and add to the table.
  947. $temp = explode(",", $_POST["advising_track_degree_ids"]);
  948. foreach ($temp as $tdegree_id) {
  949. if (trim($tdegree_id) == "") continue;
  950. if (!is_numeric($tdegree_id)) continue;
  951. $tdegree_plan = fp_load_degree($tdegree_id, NULL, TRUE);
  952. $tmajor_code = $tdegree_plan->major_code;
  953. /* // shouldn't need this anymore, as the major_code will contain both the major and track in one.
  954. $tmajor_code = $tdegree_plan->major_code;
  955. if (!strstr($tmajor_code, "|")) {
  956. $tmajor_code .= "|";
  957. }
  958. $tmajor_code .= "_" . $tdegree_plan->track_code;
  959. */
  960. db_query("INSERT INTO student_degrees
  961. (student_id, major_code, is_editable)
  962. VALUES ('?', '?', '1')", $student_id, $tmajor_code);
  963. }
  964. // Reset the SESSION variables and re-init, so we get the correct
  965. // major codes and track codes for this student.
  966. $_SESSION["advising_track_degree_ids$student_id"] = "";
  967. $_SESSION["advising_major_code$student_id"] = "";
  968. $_REQUEST["advising_major_code"] = "";
  969. $_REQUEST["advising_track_degree_ids"] = "";
  970. $this->student->load_student_data();
  971. // force re-build of cache
  972. //$_REQUEST["load_from_cache"] = "no";
  973. //$_SESSION["cache_fp$student_id"] = "";
  974. //$_SESSION["cache_what_if$student_id"] = "";
  975. $GLOBALS["fp_advising"]["load_from_cache"] = "no";
  976. $this->init(TRUE);
  977. $bool_fp_goto_at_end = TRUE;
  978. } // editing degrees?
  979. // Is there anything in "log_addition" which we should write to the log?
  980. if ($_POST["log_addition"] != "")
  981. {
  982. $temp = explode("~",$_POST["log_addition"]);
  983. if ($temp[0] == "change_term") {
  984. watchdog("change_term", "$student_id," . $temp[1]);
  985. }
  986. if ($temp[0] == "change_track"){
  987. watchdog("change_track", "$student_id," . $temp[1]);
  988. }
  989. }
  990. // If this user cannot advise, then just return right now.
  991. if (!user_has_permission("can_advise_students")) {
  992. return;
  993. }
  994. // First, create a new entry in the advising_sessions table,
  995. // so we can get the advisingSessionID.
  996. // But before we can do that, we look for an existing entry
  997. // which matches this. If we find it, we delete it so the
  998. // new one will display instead.
  999. // Only delete if its a draft copy!
  1000. $is_draft = intval($bool_draft);
  1001. $is_what_if = intval($this->bool_what_if);
  1002. // Since we only want one draft copy per term/per student and faculty,
  1003. // let's delete
  1004. // any draft copies already in existence, if we are saving a draft.
  1005. $result = $db->db_query("DELETE FROM advising_sessions
  1006. WHERE student_id = ?
  1007. AND is_draft = 1
  1008. AND faculty_id = ?
  1009. AND degree_id = ?
  1010. AND is_whatif = ? ", $student_id, $faculty_id, $degree_id, $is_what_if);
  1011. // The first thing we need to do is go through the availableTerms,
  1012. // create new entries for them in the table, and store what their
  1013. // session ID's are in an array.
  1014. $advising_session_id_array = array();
  1015. $advising_session_id_array_count = array();
  1016. $temp = explode(",",$available_terms);
  1017. foreach ($temp as $term_id)
  1018. {
  1019. $term_id = trim($term_id);
  1020. if ($term_id == "") { continue; }
  1021. // Okay, now create a new entry in the system for that term.
  1022. // We create entries for all available terms, whether we
  1023. // are going to use them later or not.
  1024. $result = $db->db_query("INSERT INTO advising_sessions
  1025. (student_id, faculty_id, term_id, degree_id,
  1026. major_code_csv,
  1027. catalog_year, posted, is_whatif, is_draft)
  1028. VALUES
  1029. ('?', '?','?','?','?','?','?','?','?')
  1030. ", $student_id, $faculty_id,$term_id,$degree_id, $major_code_csv, $catalog_year, time(), $is_what_if, $is_draft);
  1031. $advising_session_id = db_insert_id();
  1032. $advising_session_id_array[$term_id] = $advising_session_id;
  1033. $advising_session_id_array_count[$term_id] = 0;
  1034. }
  1035. $wi = "";
  1036. if ($is_what_if == "1"){$wi = "_whatif";}
  1037. if ($bool_draft) {
  1038. watchdog("save_adv_draft$wi", "$student_id,major_code_csv:$major_code_csv");
  1039. }
  1040. else {
  1041. watchdog("save_adv_active$wi", "$student_id,major_code_csv:$major_code_csv");
  1042. }
  1043. // Go through the POST, looking for the
  1044. // phrase "advisecourse_" in the name of the variables.
  1045. // There should be one of these for every course that was
  1046. // on the page. It looks like this:
  1047. // advisecourse_course_id_semesterNum_group_id_varHours_randomID
  1048. foreach($_POST as $key => $value)
  1049. {
  1050. if (!strstr($key,"advisecourse_") && !(strstr($key, "advcr_")))
  1051. { // Skip vars which don't have this as part of the name.
  1052. // We accept either advisecourse_ or advcr_ for short. advisecourse_ is the old way.
  1053. // I changed to use advcr_ to save space, because some browsers will not allow long input names.
  1054. continue;
  1055. }
  1056. if ($value != "true")
  1057. { // This means the course was *not* advised to be taken,
  1058. // so, skip it.
  1059. continue;
  1060. }
  1061. // The key might contain a DoT (dot placeholder) instead of a period. If so, let's
  1062. // add the period back in. This was to correct a bug where courses with dots couldn't
  1063. // be advised.
  1064. if (strstr($key, "DoT")) {
  1065. $key = str_replace("DoT", ".", $key);
  1066. }
  1067. $temp = explode("_",$key);
  1068. $course_id = trim($temp[1]);
  1069. $semester_num = trim($temp[2]);
  1070. $group_id = str_replace("U", "_", trim($temp[3])); // replace U with _, which was required for the submission to work (couldn't use the _ in group_id.)
  1071. $var_hours = trim($temp[4]) * 1;
  1072. $random_id = trim($temp[5]);
  1073. $advised_term_id = trim($temp[6]);
  1074. //$db_group_requirement_id = trim($temp[7]);
  1075. $degree_id = trim($temp[7]);
  1076. if ($degree_id == "group") {
  1077. // Get degree_id from the group_id.
  1078. $tt = explode("_", $group_id);
  1079. $degree_id = $tt[1];
  1080. }
  1081. $advising_session_id = $advising_session_id_array[$advised_term_id];
  1082. $new_course = new Course($course_id);
  1083. $new_course->load_descriptive_data();
  1084. $entry_value = "$new_course->subject_id~$new_course->course_num";
  1085. // Some particular course should be updated. Possibly this one.
  1086. // Updates happen because of a student changing the
  1087. // variable hours, for example.
  1088. if (trim(@$_POST["updatecourse"]) != "")
  1089. {
  1090. $temp2 = explode("~",trim($_POST["updatecourse"]));
  1091. $tcourse_id = $temp2[0];
  1092. $tgroup_id = $temp2[1] * 1;
  1093. $tsemester_num = $temp2[2] * 1;
  1094. $tvar_hours = $temp2[3];
  1095. $trandom_id = $temp2[4];
  1096. $tadvised_term_id = $temp2[5];
  1097. $tdegree_id = $temp2[6];
  1098. // Do we have a match?
  1099. if ($course_id == $tcourse_id && $random_id == $trandom_id)
  1100. {
  1101. // We have a match, so update with the new information.
  1102. $var_hours = $tvar_hours;
  1103. $degree_id = $tdegree_id;
  1104. $new_course = new Course($tcourse_id);
  1105. $new_course->load_descriptive_data();
  1106. $entry_value = "$new_course->subject_id~$new_course->course_num";
  1107. $bool_found_update_match = true;
  1108. }
  1109. }
  1110. if ($group_id != 0)
  1111. {
  1112. $this->replace_missing_course_in_group($course_id, $group_id);
  1113. }
  1114. // Make sure degree_id is a valid number for the database.
  1115. if (!is_numeric($degree_id) || intval($degree_id) < 0) {
  1116. $degree_id = 0;
  1117. }
  1118. // Okay, write it to the table...
  1119. $result = $db->db_query("INSERT INTO advised_courses
  1120. (`advising_session_id`,`course_id`,
  1121. `entry_value`,`semester_num`,
  1122. `group_id`,`var_hours`,`term_id`, `degree_id`)
  1123. VALUES
  1124. ('?','?','?','?','?','?','?','?')
  1125. ", $advising_session_id, $course_id, $entry_value, $semester_num, $group_id, $var_hours, $advised_term_id, $degree_id);
  1126. $advising_session_id_array_count[$advised_term_id]++;
  1127. }
  1128. // Did we have to perform an update-- but no course was found?
  1129. if (trim(@$_POST["updatecourse"]) != "" && $bool_found_update_match == false)
  1130. {
  1131. // This means that the course was probably on the bare
  1132. // degree program, and not already checked for advising. So,
  1133. // let's add it to the advised_courses table, so it DOES
  1134. // get checked for advising.
  1135. $temp2 = explode("~",trim($_POST["updatecourse"]));
  1136. $course_id = $temp2[0];
  1137. $group_id = $temp2[1] * 1;
  1138. $semester_num = $temp2[2] * 1;
  1139. $var_hours = $temp2[3];
  1140. $advised_term_id = $temp2[5];
  1141. $degree_id = $temp2[6];
  1142. $new_course = new Course($course_id);
  1143. $new_course->load_descriptive_data();
  1144. $entry_value = "$new_course->subject_id~$new_course->course_num";
  1145. $advising_session_id = $advising_session_id_array[$advised_term_id];
  1146. $result = $db->db_query("INSERT INTO advised_courses
  1147. (`advising_session_id`,`course_id`,`entry_value`,`semester_num`,
  1148. `group_id`,`var_hours`,`term_id`,`degree_id`)
  1149. VALUES
  1150. ('?','?','?','?','?','?','?','?')
  1151. ", $advising_session_id,$course_id,$entry_value,$semester_num,$group_id,$var_hours,$advised_term_id,$degree_id);
  1152. $advising_session_id_array_count[$advised_term_id]++;
  1153. if ($group_id != 0)
  1154. {
  1155. $this->replace_missing_course_in_group($course_id, $group_id);
  1156. }
  1157. }
  1158. //------------------------------------------------------
  1159. //
  1160. // Substitutions...
  1161. //
  1162. //-------------------------------------------------------
  1163. // check permissions for substitutions before saving
  1164. if (trim(@$_POST["savesubstitution"]) != "" && user_has_permission("can_substitute")) {
  1165. $temp = explode("~",trim($_POST["savesubstitution"]));
  1166. $course_id = $temp[0]; // required course
  1167. $group_id = trim($temp[1]);
  1168. $req_by_degree_id = $temp[2];
  1169. $semester_num = $temp[3] * 1;
  1170. $sub_course_id = $temp[4];
  1171. $sub_term_id = $temp[5];
  1172. $sub_transfer_flag = $temp[6];
  1173. $sub_hours = $temp[7] * 1;
  1174. $sub_addition = $temp[8];
  1175. $sub_remarks = urldecode($temp[9]);
  1176. if ($sub_addition == "true")
  1177. {
  1178. $course_id = 0;
  1179. }
  1180. // Figure out the entry values for the required course & sub course...
  1181. $required_entry_value = $sub_entry_value = "";
  1182. if ($course_id > 0)
  1183. {
  1184. $new_course = new Course($course_id);
  1185. $new_course->load_descriptive_data();
  1186. $required_entry_value = "$new_course->subject_id~$new_course->course_num";
  1187. }
  1188. if ($sub_transfer_flag != 1)
  1189. {
  1190. $new_course = new Course($sub_course_id);
  1191. $new_course->load_descriptive_data();
  1192. $sub_entry_value = "$new_course->subject_id~$new_course->course_num";
  1193. }
  1194. if ($group_id != 0 && $course_id != 0)
  1195. {
  1196. $this->replace_missing_course_in_group($course_id, $group_id);
  1197. }
  1198. // Make sure the sub_hours aren't larger than the sub_course_id's awarded hours.
  1199. // This is to stop a bug from happening where sometimes, some people are able to substitute
  1200. // a course for larger than the awarded hours. I believe it is a javascript bug.
  1201. if ($test_c = $this->student->list_courses_taken->find_specific_course($sub_course_id, $sub_term_id, (bool) $sub_transfer_flag, true)) {
  1202. // Are the hours out of whack?
  1203. if (floatval($sub_hours) > floatval($test_c->get_hours_awarded($req_by_degree_id))) {
  1204. // Yes! Set it to the value of the hours_awarded.
  1205. $sub_hours = floatval($test_c->get_hours_awarded($req_by_degree_id));
  1206. }
  1207. }
  1208. $result = $db->db_query("INSERT INTO student_substitutions
  1209. (`student_id`,`faculty_id`,`required_course_id`,`required_entry_value`,
  1210. `required_group_id`,`required_degree_id`,`required_semester_num`,`sub_course_id`,`sub_entry_value`,
  1211. `sub_term_id`,`sub_transfer_flag`,`sub_hours`,`sub_remarks`,`posted`)
  1212. VALUES
  1213. ('?','?','?','?','?','?','?','?','?','?','?','?','?','?')
  1214. ", $student_id,$faculty_id,$course_id,$required_entry_value,$group_id,$req_by_degree_id,$semester_num,$sub_course_id,$sub_entry_value,$sub_term_id,$sub_transfer_flag,$sub_hours,$sub_remarks, time());
  1215. watchdog("save_substitution", "$student_id,group_id:$group_id,insert_id:" . db_insert_id());
  1216. }
  1217. if (trim(@$_POST["removesubstitution"]) != "")
  1218. {
  1219. $temp = explode("~",trim($_POST["removesubstitution"]));
  1220. $sub_id = trim($temp[0]) * 1;
  1221. $result = $db->db_query("UPDATE student_substitutions
  1222. SET `delete_flag`='1'
  1223. WHERE `id`='?' ", $sub_id);
  1224. watchdog("remove_substitution", "$student_id,sub_id:$sub_id");
  1225. }
  1226. //------------------------------------------------------
  1227. //
  1228. // Group Unassignments
  1229. //
  1230. //-------------------------------------------------------
  1231. if (trim(@$_POST["unassign_group"]) != "")
  1232. {
  1233. $temp = explode("~",trim($_POST["unassign_group"]));
  1234. $course_id = $temp[0];
  1235. $term_id = $temp[1];
  1236. $transfer_flag = $temp[2];
  1237. $group_id = $temp[3];
  1238. $degree_id = $temp[4];
  1239. $result = db_query("INSERT INTO student_unassign_group
  1240. (`student_id`,`faculty_id`,`course_id`,
  1241. `term_id`,`transfer_flag`,`group_id`,`degree_id`,
  1242. `posted`)
  1243. VALUES
  1244. ('?','?','?','?','?','?','?','?')
  1245. ", $student_id,$faculty_id,$course_id,$term_id,$transfer_flag,$group_id,$degree_id,time());
  1246. watchdog("save_unassign_group", "$student_id,group_id:$group_id,degree_id:$degree_id");
  1247. }
  1248. if (trim(@$_POST["restore_unassign_group"]) != "")
  1249. {
  1250. $temp = explode("~",trim($_POST["restore_unassign_group"]));
  1251. $unassign_id = trim($temp[0]) * 1;
  1252. $result = $db->db_query("UPDATE student_unassign_group
  1253. SET `delete_flag`='1'
  1254. WHERE `id`='?' ", $unassign_id);
  1255. watchdog("restore_unassign_group", "$student_id,unassign_id:$unassign_id");
  1256. }
  1257. //------------------------------------------------------
  1258. //
  1259. // Transfer EQV Unassignments
  1260. //
  1261. //-------------------------------------------------------
  1262. if (trim(@$_POST["unassign_transfer_eqv"]) != "")
  1263. {
  1264. $temp = explode("~",trim($_POST["unassign_transfer_eqv"]));
  1265. $course_id = $temp[0];
  1266. $result = $db->db_query("INSERT INTO student_unassign_transfer_eqv
  1267. (`student_id`,`faculty_id`,`transfer_course_id`,
  1268. `posted`)
  1269. VALUES
  1270. ('?','?','?','?')
  1271. ", $student_id, $faculty_id, $course_id, time());
  1272. watchdog("save_unassign_transfer", "$student_id,course_id:$course_id");
  1273. }
  1274. if (trim(@$_POST["restore_transfer_eqv"]) != "")
  1275. {
  1276. $temp = explode("~",trim($_POST["restore_transfer_eqv"]));
  1277. $unassign_id = trim($temp[0]) * 1;
  1278. $result = $db->db_query("UPDATE student_unassign_transfer_eqv
  1279. SET `delete_flag`='1'
  1280. WHERE `id`='?' ", $unassign_id);
  1281. watchdog("restore_unassign_transfer", "$student_id,unassign_id:$unassign_id");
  1282. }
  1283. ////////////////////////////////////////////////////
  1284. /////// Cleanup !////////////////////////////////
  1285. ////////////////////////////////////////////////////
  1286. // If any of the advisingSessions we created earlier
  1287. // are blank, we should FLAG them, so they will not
  1288. // show up under the student's history.
  1289. // Only flag non-draft empty ones. If they are draft,
  1290. // let them be.
  1291. // We just look at $advising_session_id_array_count[] to see
  1292. // if any of the counts are still 0. If they are, delete
  1293. // that advisingSessionID from the table.
  1294. if ($is_draft == 0)
  1295. {
  1296. foreach ($advising_session_id_array as $term_id => $advising_session_id)
  1297. {
  1298. if ($advising_session_id_array_count[$term_id] == 0)
  1299. {
  1300. // This one is blank! Delete it!
  1301. $res = $db->db_query("UPDATE advising_sessions
  1302. SET `is_empty`='1'
  1303. WHERE `advising_session_id`='?' ", $advising_session_id);
  1304. $advising_session_id_array[$term_id] = "";
  1305. }
  1306. }
  1307. }
  1308. watchdog("advising", "Student has been advised: @student", array("@student" => $student_id));
  1309. // Call a hook so other modules can act when the advising session gets saved.
  1310. invoke_hook('save_advising_session_from_post', array($student_id, $is_draft, $advising_session_id_array));
  1311. // Instead of executing the page, we will issue a redirect using fp_goto.
  1312. // This makes it so if the user hits "refresh", it will not re-submit a POST request.
  1313. if ($bool_fp_goto_at_end) {
  1314. // Goto the same page we are already on. This mimics Drupal's Form API behavior.
  1315. $q = $_REQUEST['q'];
  1316. fp_goto($q, "advising_major_code=&load_from_cache=no&advising_student_id=$student_id");
  1317. }
  1318. return $advising_session_id_array;
  1319. }
  1320. function load_advising_session_from_database($faculty_id = 0, $term_id = "", $bool_what_if = false, $bool_draft = true, $advising_session_id = 0, $duplicate_for_faculty_id = 0)
  1321. {
  1322. global $user;
  1323. // This method will load an advising session for a particular
  1324. // student, and modify the degree plan object to reflect
  1325. // the advisings.
  1326. $db = get_global_database_handler();
  1327. $is_what_if = "0";
  1328. $is_draft = "0";
  1329. if ($bool_what_if == true){$is_what_if = "1";}
  1330. if ($bool_draft == true){$is_draft = "1";}
  1331. $degree_id = $this->degree_plan->degree_id;
  1332. $student_id = $this->student->student_id;
  1333. $available_terms = variable_get("available_advising_term_ids", "0");
  1334. // If we are pulling up an active student record, then let's
  1335. // delete any draft sessions for this faculty user and student, so as not to cause
  1336. // a bug later on when changing tabs. We don't care if $faculty_id is set or not, just
  1337. // the current user's CWID.
  1338. if ($bool_draft == FALSE && $user->cwid != 0) {
  1339. $res = db_query("DELETE FROM advising_sessions
  1340. WHERE student_id = ?
  1341. AND faculty_id = ?
  1342. AND is_draft = 1
  1343. ", $student_id, $user->cwid);
  1344. }
  1345. $advising_session_line = " `advising_session_id`='$advising_session_id' ";
  1346. // First, find the advising session id...
  1347. if ($advising_session_id < 1 && $available_terms == "")
  1348. {
  1349. $advising_session_id = $this->db->get_advising_session_id($faculty_id, $student_id, $term_id, $degree_id, $bool_what_if, $bool_draft, TRUE);
  1350. $advising_session_line = " `advising_session_id`='$advising_session_id' ";
  1351. // Create a duplicate of this session as a draft...
  1352. if ($bool_draft == FALSE) {
  1353. $db->duplicate_advising_session($advising_session_id, $duplicate_for_faculty_id, "", "", "", "", 1);
  1354. }
  1355. } else if ($advising_session_id < 1 && $available_terms != "")
  1356. {
  1357. // Meaning, we are looking for more than one term.
  1358. $advising_session_line = "(";
  1359. $temp = explode(",",$available_terms);
  1360. for ($t = 0; $t < count($temp); $t++)
  1361. {
  1362. $t_id = trim($temp[$t]);
  1363. $asid = $this->db->get_advising_session_id($faculty_id, $student_id, $t_id,$degree_id, $bool_what_if, $bool_draft, TRUE);
  1364. if ($asid != 0)
  1365. {
  1366. $advising_session_line .= " advising_session_id='$asid' || ";
  1367. // Create a duplicate of this session as a draft...
  1368. if ($bool_draft == FALSE) {
  1369. $db->duplicate_advising_session($asid, $duplicate_for_faculty_id, "", "", "", "", 1);
  1370. }
  1371. }
  1372. }
  1373. // Take off the last 3 chars...
  1374. $advising_session_line = substr($advising_session_line, 0, -3);
  1375. $advising_session_line .= ")";
  1376. if ($advising_session_line == ")")
  1377. { // Found NO previously advised semesters, so just
  1378. // use a dummy value which guarantees it pulls up nothing.
  1379. $advising_session_line = " advising_session_id='-99999'";
  1380. }
  1381. }
  1382. // Now, look up the courses they were advised to take.
  1383. $query = "SELECT * FROM advised_courses
  1384. WHERE
  1385. $advising_session_line
  1386. ORDER BY `id` ";
  1387. $result = $db->db_query($query);
  1388. while($cur = $db->db_fetch_array($result))
  1389. {
  1390. $course_id = trim($cur["course_id"]);
  1391. $semester_num = trim($cur["semester_num"]);
  1392. $group_id = trim($cur["group_id"]);
  1393. $degree_id = $cur["degree_id"];
  1394. $var_hours = trim($cur["var_hours"]);
  1395. $advised_term_id = trim($cur["term_id"]);
  1396. $id = trim($cur["id"]);
  1397. // Add this course to the generic list of advised courses. Useful
  1398. // if we are using this to pull up an advising summary.
  1399. $temp_course = new Course($course_id);
  1400. $temp_course->advised_hours = $var_hours;
  1401. $this->course_list_advised_courses->add($temp_course);
  1402. if ($semester_num == DegreePlan::SEMESTER_NUM_FOR_COURSES_ADDED)
  1403. {
  1404. // This was a courses added by the advisor.
  1405. $this->assign_course_to_courses_added_list($course_id, $var_hours, $id, $advised_term_id);
  1406. continue;
  1407. }
  1408. // Now, we need to modify the degree_plan object to
  1409. // show these advisings.
  1410. if ($course_list = $this->degree_plan->find_courses($course_id, $group_id, $semester_num, $degree_id))
  1411. {
  1412. // This course may exist in several different branches of a group, so we need
  1413. // to mark all the branches as having been advised to take. Usually, this CourseList
  1414. // will probably only have 1 course object in it. But, better safe than sorry.
  1415. $course_list->reset_counter();
  1416. if ($course = $course_list->get_next())
  1417. {
  1418. // make sure the hour count has been loaded correctly.
  1419. if ($course->get_catalog_hours() < 1)
  1420. {
  1421. $course->load_descriptive_data();
  1422. }
  1423. // Let's start by looking at the first course. Is it
  1424. // supposed to be repeated?
  1425. if ($course->bool_specified_repeat==true
  1426. && $course->specified_repeats >= 0 )
  1427. {
  1428. // This is a course which is supposed to be repeated.
  1429. // We need to cycle through and find an instance
  1430. // of this course which has not been advised yet.
  1431. $course_list->reset_counter();
  1432. while($course_list->has_more())
  1433. {
  1434. $course = $course_list->get_next();
  1435. // make sure the hour count has been loaded correctly.
  1436. if ($course->get_catalog_hours() < 1)
  1437. {
  1438. $course->load_descriptive_data();
  1439. }
  1440. ////////////////////
  1441. // Logan's change: https://bytetask.com/node/2455
  1442. // If we have the setting which says we should skip if it's already been completed/enrolled for this term,
  1443. // then we should do that.
  1444. if (variable_get("remove_advised_when_course_taken", "no") == "yes") {
  1445. // First, see if this advised course has been attempted already.
  1446. if ($this->student->list_courses_taken->find_specific_course($course->course_id, $advised_term_id)) {
  1447. // Yep, found it! So, skip this one.
  1448. continue;
  1449. }
  1450. }
  1451. //////////////////////////
  1452. //if ($course->bool_advised_to_take != true && !is_object($course->courseFulfilledBy))
  1453. if ($course->bool_advised_to_take != true && $course->course_list_fulfilled_by->is_empty == true)
  1454. {
  1455. // Okay, this course is supposed to be taken/advised
  1456. // more than once. So, I will mark this one as
  1457. // advised, and then break out of the loop, since
  1458. // I don't want to mark all occurances as advised.
  1459. $course->bool_advised_to_take = true;
  1460. $course->assigned_to_semester_num = $semester_num;
  1461. //$course->assigned_to_group_id = $group_id;
  1462. $course->assigned_to_group_ids_array[$group_id] = $group_id;
  1463. // Make sure we assign the hours to the group, so this
  1464. // advised courses takes up a spot in the group. Otherwise
  1465. // it may be missed in later logic.
  1466. if ($g = $this->degree_plan->find_group($group_id)) {
  1467. $h = $var_hours;
  1468. if ($h == 0) {
  1469. $h = $course->get_catalog_hours();
  1470. if ($h == 0) {
  1471. $h = 1; // some problem occured. Just give it a token hour so it doesn't
  1472. // horribly break.
  1473. }
  1474. }
  1475. $g->hours_assigned += $h;
  1476. }
  1477. $course->advised_hours = $var_hours;
  1478. $course->advised_term_id = $advised_term_id;
  1479. $course->db_advised_courses_id = $id;
  1480. $course_list->dec_specified_repeats($course);
  1481. break;
  1482. }
  1483. }
  1484. continue; // Go to the next advised course.
  1485. }
  1486. } // if $course = $course_list->get_next();
  1487. //////////////////////////////
  1488. // We're here, because it was not a repeatable course.
  1489. // ** We should only go through THIS loop once! So,
  1490. // we will break after we make our assignment.
  1491. $course_list->reset_counter();
  1492. while($course_list->has_more())
  1493. {
  1494. $course = $course_list->get_next();
  1495. // make sure the hour count has been loaded correctly.
  1496. if ($course->get_catalog_hours() < 1)
  1497. {
  1498. $course->load_descriptive_data();
  1499. }
  1500. // make sure it has not already been advised to take.
  1501. // Would occur if the same course is specified more
  1502. // than once in a semester.
  1503. if ($course->bool_advised_to_take == true)
  1504. {
  1505. continue;
  1506. }
  1507. // If we have the setting which says we should skip if it's already been completed/enrolled for this term,
  1508. // then we should do that.
  1509. if (variable_get("remove_advised_when_course_taken", "no") == "yes") {
  1510. // First, see if this advised course has been attempted already.
  1511. if ($taken_course = $this->student->list_courses_taken->find_specific_course($course->course_id, $advised_term_id)) {
  1512. // Yep, found it! So, skip this one.
  1513. continue;
  1514. }
  1515. }
  1516. // Has this course already been fulfilled by something?
  1517. // If so, we cannot attempt to say it's been advised!
  1518. if (!$course->course_list_fulfilled_by->is_empty)
  1519. {
  1520. // meaning, this course HAS been fulfilled.
  1521. // So, let's move this advising to the "added by advisor"
  1522. // spot.
  1523. /* This is the original bit of code here. It is causing a problem when there are courses which are supposed to be
  1524. * repeated. Example: MUSC courses which are advised one term at a time.
  1525. *
  1526. *
  1527. $this->assign_course_to_courses_added_list($course_id, $var_hours, $id, $advised_term_id);
  1528. break;
  1529. *
  1530. * Strategy: Find out how many courses are in this course_list by looking at the size of the list. If it's > 1, then just continue. If it == 1, then
  1531. * do the original logic.
  1532. *
  1533. */
  1534. if ($course_list->get_size() > 1) {
  1535. continue;
  1536. }
  1537. else {
  1538. $this->assign_course_to_courses_added_list($course_id, $var_hours, $id, $advised_term_id);
  1539. break;
  1540. }
  1541. }
  1542. $course->bool_advised_to_take = true;
  1543. $course->assigned_to_semester_num = $semester_num;
  1544. //$course->assigned_to_group_id = $group_id;
  1545. $course->assigned_to_group_ids_array[$group_id] = $group_id;
  1546. // Make sure we assign the hours to the group, so this
  1547. // advised courses takes up a spot in the group. Otherwise
  1548. // it may be missed in later logic.
  1549. if ($g = $this->degree_plan->find_group($group_id)) {
  1550. $h = $var_hours;
  1551. if ($h == 0) {
  1552. $h = $course->get_catalog_hours();
  1553. if ($h == 0) {
  1554. $h = 1; // some problem occured. Just give it a token hour so it doesn't
  1555. // horribly break.
  1556. }
  1557. }
  1558. $g->hours_assigned += $h;
  1559. }
  1560. $course->advised_hours = $var_hours;
  1561. $course->advised_term_id = $advised_term_id;
  1562. $course->db_advised_courses_id = $id;
  1563. if ($course->required_on_branch_id > 0)
  1564. {
  1565. // In other words, this course was found on a branch, so we need
  1566. // to increment that branch's count_of_matches.
  1567. if ($branch = $this->degree_plan->find_group($course->required_on_branch_id))
  1568. {
  1569. $branch->count_of_matches++;
  1570. } else {
  1571. fpm("Error: Could not find branch.");
  1572. }
  1573. }
  1574. // We should only be in this loop once, so let's
  1575. // break after we make our assignment.
  1576. break;
  1577. }
  1578. }
  1579. }
  1580. // Now, what we need to do is tell the DegreePlan to re-sort its
  1581. // group's course lists, so that the advised courses are lower
  1582. // than the fulfilled courses.
  1583. //$this->degree_plan->sortGroupsFulfilledFirst();
  1584. //print_pre($this->degree_plan->list_groups->toString());
  1585. } // function loadAdvisingSessionFromDatabase
  1586. function split_requirements_by_substitutions()
  1587. {
  1588. // Go through all the required courses on the degree plan,
  1589. // and if there is a partial substitution specified in the student's
  1590. // list of substitutions, then split that requirement into 2 courses,
  1591. // one with enough hours to satisfy the sub, and the remaining hours.
  1592. $degree_plan = $this->degree_plan;
  1593. $student = $this->student;
  1594. $student->list_substitutions->reset_counter();
  1595. while($student->list_substitutions->has_more())
  1596. {
  1597. $substitution = $student->list_substitutions->get_next();
  1598. $course_requirement = $substitution->course_requirement;
  1599. $course_sub = $substitution->course_list_substitutions->get_first();
  1600. // TODO: This could be an important part right here
  1601. // Check to see if the courseSub's hours_awarded are less than the
  1602. // course_requirement's min hours...
  1603. if ($course_requirement->min_hours > $course_sub->get_hours_awarded())
  1604. {
  1605. // Meaning the original course requirement is not being
  1606. // fully satisfied by this substitution! The original
  1607. // course requirement has hours left over which must be
  1608. // fulfilled somehow.
  1609. $remaining_hours = round($course_requirement->min_hours - $course_sub->get_hours_awarded(), 6);
  1610. // This means that the course requirement needs to be split.
  1611. // So, find this course in the degree plan.
  1612. $required_course_id = $course_requirement->course_id;
  1613. //$required_group_id = $course_requirement->assigned_to_group_id;
  1614. $required_group_id = $course_requirement->get_first_assigned_to_group_id(); // we assume a course requirement is only assigned to 1 group.
  1615. $required_semester_num = $course_requirement->assigned_to_semester_num;
  1616. }
  1617. }
  1618. } // split_requirements_by_substitution
  1619. function assign_course_to_courses_added_list($course_id, $var_hours = 0, $db_advised_courses_id = 0, $advised_term_id = 0)
  1620. {
  1621. // Set the supplied course as "advised to take" in the degree plan's
  1622. // special added courses group, which is number -88.
  1623. $course = new Course($course_id, false, $this->db);
  1624. $course->bool_advised_to_take = true;
  1625. $course->assigned_to_semester_num = DegreePlan::SEMESTER_NUM_FOR_COURSES_ADDED;
  1626. //$course->assigned_to_group_id = -88;
  1627. $course->assigned_to_group_ids_array[DegreePlan::GROUP_ID_FOR_COURSES_ADDED] = DegreePlan::GROUP_ID_FOR_COURSES_ADDED;
  1628. $course->advised_hours = $var_hours;
  1629. $course->db_advised_courses_id = $db_advised_courses_id;
  1630. $course->advised_term_id = $advised_term_id;
  1631. if ($group = $this->degree_plan->find_group(DegreePlan::GROUP_ID_FOR_COURSES_ADDED))
  1632. {
  1633. $group->list_courses->add($course);
  1634. }
  1635. // Done!
  1636. }
  1637. }

Classes

Namesort descending Description
_FlightPath