DegreePlan.php

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

File

classes/DegreePlan.php
View source
  1. <?php
  2. class DegreePlan extends stdClass
  3. {
  4. const DEGREE_ID_FOR_COMBINED_DEGREE = -1001;
  5. const SEMESTER_NUM_FOR_COURSES_ADDED = -88;
  6. const GROUP_ID_FOR_COURSES_ADDED = -88;
  7. const SEMESTER_NUM_FOR_DEVELOPMENTALS = -55;
  8. public $major_code, $title, $degree_type, $degree_level, $degree_class, $short_description, $long_description;
  9. public $list_semesters, $list_groups, $db, $degree_id, $catalog_year, $is_combined_dynamic_degree_plan, $combined_degree_ids_array;
  10. public $track_code, $track_title, $track_description, $student_array_significant_courses;
  11. public $bool_has_tracks, $array_semester_titles, $db_exclude, $db_allow_dynamic, $db_override_degree_hours, $db_advising_weight;
  12. public $public_notes_array, $school_id;
  13. public $total_major_hours, $total_core_hours, $total_degree_hours;
  14. public $fulfilled_major_hours, $fulfilled_core_hours, $fulfilled_degree_hours;
  15. public $major_qpts_hours, $core_qpts_hours, $degree_qpts_hours;
  16. public $major_qpts, $degree_qpts, $core_qpts;
  17. public $db_track_selection_config, $track_selection_config_array;
  18. public $required_course_id_array; // We will keep track of every course which this degree lists as a requirement, even in groups.
  19. // looks like: required_course_id_array[$course_id][$degree_id][$group_id] = TRUE;
  20. public $gpa_calculations, $bool_calculated_progess_hours;
  21. public $bool_use_draft, $bool_loaded_descriptive_data;
  22. public $extra_data_array; // This is an array meant for any generic "extra data" we want to include, from custom modules.
  23. /**
  24. * $major_code ACCT, CSCI, etc.
  25. * $title Accounting, Computer Science, etc.
  26. * $degree_type BBA, BS, AS, etc.
  27. * $short_description These are a text description of this degree plan. Useful
  28. * for descriptions of "Tracks" or "Options." The short
  29. * $long_description one appears in a pull down, the long one is a more
  30. * complete text description. Will probably be unused
  31. * by most degrees.
  32. * $list_semesters A list of semesters that this DegreePlan requires.
  33. * $list_degree_plans If this degree plan has multiple tracks or options, then
  34. * they would be spelled out as other degree plans, and listed
  35. * here. For example, Biology has multiple "tracks" which,
  36. * internally, should be treated as different degree plans.
  37. **/
  38. function __construct($degree_id = "", DatabaseHandler $db = NULL, $bool_load_minimal = FALSE, $array_significant_courses = FALSE, $bool_use_draft = FALSE) {
  39. $this->list_semesters = new ObjList();
  40. $this->list_groups = new GroupList();
  41. $this->bool_use_draft = $bool_use_draft;
  42. // Always override if the global variable is set.
  43. if (@$GLOBALS["fp_advising"]["bool_use_draft"] == true) {
  44. $this->bool_use_draft = true;
  45. }
  46. $this->school_id = 0; //default
  47. $this->required_course_id_array = array();
  48. $this->public_notes_array = array();
  49. $this->extra_data_array = array();
  50. $this->db_advising_weight = 0;
  51. $this->track_selection_config_array = array();
  52. $this->db = $db;
  53. if ($db == NULL)
  54. {
  55. $this->db = get_global_database_handler();
  56. }
  57. $this->student_array_significant_courses = $array_significant_courses;
  58. if ($degree_id != "")
  59. {
  60. $this->degree_id = $degree_id;
  61. $this->load_descriptive_data();
  62. if (!$bool_load_minimal)
  63. {
  64. $this->load_degree_plan();
  65. }
  66. // Add the "Add a Course" semester to the semester list.
  67. $this->add_semester_courses_added();
  68. }
  69. if ($this->degree_level == "") {
  70. $this->degree_level = "UG"; // undergrad by default
  71. }
  72. } // __construct
  73. /**
  74. * Given a group_id, find out if this group contains a course which appears in other degrees. Return the max number.
  75. */
  76. function get_max_course_appears_in_degrees_count($test_group_id) {
  77. // array is sectioned like: course_id | degree_id | group_id. Group id = 0 means "on the bare degree plan"
  78. // ex: $this->required_course_id_array[$course_c->course_id][$this->degree_id][0] = TRUE;
  79. $exclude_degree_ids = system_get_exclude_degree_ids_from_appears_in_counts($this->school_id);
  80. $courses = array();
  81. foreach ($this->required_course_id_array as $course_id => $temp1) {
  82. foreach ($this->required_course_id_array[$course_id] as $degree_id => $temp2) {
  83. // Is this an excluded degree? If so, skip it.
  84. if (in_array($degree_id, $exclude_degree_ids)) continue;
  85. foreach ($this->required_course_id_array[$course_id][$degree_id] as $group_id => $val) {
  86. // Is this the group we are looking for?
  87. if ($group_id != $test_group_id) continue;
  88. // Otherwise, yes, we are in the right group. Let's keep track of what courses we have in this group:
  89. $courses[$course_id] = TRUE;
  90. }
  91. }
  92. }
  93. $course_count = array();
  94. // Okay, now what we want to do is find out, how many different degrees do these courses appear in?
  95. foreach ($this->required_course_id_array as $course_id => $temp1) {
  96. if (!isset($courses[$course_id])) continue; // wasn't in our list, so skip.
  97. $course_count[$course_id] = 0;
  98. foreach ($this->required_course_id_array[$course_id] as $degree_id => $temp2) {
  99. $course_count[$course_id]++;
  100. }
  101. }
  102. // Okay, coming out of this, we can sort the courses_degrees array, and return the highest number.
  103. rsort($course_count);
  104. //fpm($course_count);
  105. return @$course_count[0]; // first element should be the highest value.
  106. } //get_max_course_appears_in_degrees_count
  107. /**
  108. * Calculate and store progress hour information. Stores in the $this->gpa_calculations array.
  109. *
  110. *
  111. * @param $bool_get_local_only_hours - If set to TRUE, then "local" courses (non-transfer) will be separated into their own indexes.
  112. * @param $types - the type codes we care about. If left as an emtpy array, it will get all the types defined + "degree" for degree total.
  113. * The array structure should be "code" => "code". Ex: array('a' => 'a')
  114. *
  115. */
  116. function calculate_progress_hours($bool_get_local_only_hours = FALSE, $types = array())
  117. {
  118. // Let's go through our requirement types by code, and collect calcuations on them
  119. // in the gpa_calculations array.
  120. if (count($types) == 0) {
  121. // Wasn't set, so use ALL of the known requirement types.
  122. $types = fp_get_requirement_types($this->school_id);
  123. }
  124. // Add a pseudo-code in for "degree", which the functions will convert into a blank.
  125. $types["degree"] = t("Degree (total)");
  126. // We want to do this for all possible degrees.
  127. $all_degree_ids = array();
  128. $all_degree_ids[0] = 0; // Add in the default "0" degree, meaning, don't look for a specific degree_id.
  129. if ($this->degree_id != DegreePlan::DEGREE_ID_FOR_COMBINED_DEGREE) {
  130. // Not a combined degree, just use the current degree_id.
  131. // $all_degree_ids[] = $this->degree_id; // comment out... not needed?
  132. }
  133. else {
  134. // Add in all the degrees we are combined with.
  135. $all_degree_ids = array_merge($all_degree_ids, $this->combined_degree_ids_array);
  136. }
  137. foreach ($all_degree_ids as $degree_id) {
  138. foreach ($types as $code => $desc) {
  139. // Make sure to skip appropriate codes we don't care about.
  140. if ($code == 'x') continue;
  141. $this->gpa_calculations[$degree_id][$code]["total_hours"] = $this->get_progress_hours($code, TRUE, FALSE, FALSE, $degree_id);
  142. $this->gpa_calculations[$degree_id][$code]["fulfilled_hours"] = $this->get_progress_hours($code, FALSE, FALSE, FALSE, $degree_id);
  143. $this->gpa_calculations[$degree_id][$code]["qpts_hours"] = $this->get_progress_hours($code, FALSE, TRUE, FALSE, $degree_id);
  144. if ($bool_get_local_only_hours) {
  145. // Get ONLY local hours, too....
  146. $this->gpa_calculations[$degree_id][$code . "_local"]["total_hours"] = $this->get_progress_hours($code, TRUE, FALSE, TRUE, $degree_id);
  147. $this->gpa_calculations[$degree_id][$code . "_local"]["fulfilled_hours"] = $this->get_progress_hours($code, FALSE, FALSE, TRUE, $degree_id);
  148. $this->gpa_calculations[$degree_id][$code . "_local"]["qpts_hours"] = $this->get_progress_hours($code, FALSE, TRUE, TRUE, $degree_id);
  149. }
  150. } // foreach types as code
  151. } //foreach all_degree_ids
  152. // Note that we have run this function for this degree.
  153. $this->bool_calculated_progess_hours = TRUE;
  154. }// calculate progress hours
  155. /**
  156. * Calculate the quality points of our completed courses, so we can use
  157. * that to figure out GPA.
  158. *
  159. */
  160. function calculate_progress_quality_points($bool_get_local_only_hours = FALSE, $types = array()) {
  161. // Let's go through our requirement types by code, and collect calcuations on them
  162. // in the gpa_calculations array.
  163. if (count($types) == 0) {
  164. $types = fp_get_requirement_types($this->school_id);
  165. }
  166. // Add a pseudo-code in for "degree", which the functions will convert into a blank.
  167. $types["degree"] = "Degree (total)";
  168. // We want to do this for all possible degrees.
  169. $all_degree_ids = array();
  170. $all_degree_ids[0] = 0; // Add in the default "0" degree, meaning, don't look for a specific degree_id.
  171. if ($this->degree_id != DegreePlan::DEGREE_ID_FOR_COMBINED_DEGREE) {
  172. // Not a combined degree, just use the current degree_id.
  173. // $all_degree_ids[] = $this->degree_id; // Not needed?
  174. }
  175. else {
  176. $all_degree_ids = array_merge($all_degree_ids, $this->combined_degree_ids_array);
  177. }
  178. foreach ($all_degree_ids as $degree_id) {
  179. foreach ($types as $code => $desc) {
  180. // Make sure to skip appropriate codes we don't care about.
  181. if ($code == 'x') continue;
  182. $this->gpa_calculations[$degree_id][$code]["qpts"] = $this->get_progress_quality_points($code, FALSE, $degree_id);
  183. if ($bool_get_local_only_hours) {
  184. // Get only local courses, too...
  185. $this->gpa_calculations[$degree_id][$code . "_local"]["qpts"] = $this->get_progress_quality_points($code, TRUE, $degree_id);
  186. }
  187. } //foreach types as code
  188. } //foreach all_degree_ids
  189. } // calculate progess quality points
  190. /**
  191. * Returns the number of hours required (or fulfilled) in a degree plan
  192. * for courses & groups with the specified requirement_type.
  193. * ex: "m", "s", etc. leave blank for ALL required hours.
  194. * if boolRequiredHours is FALSE, then we will only look for the courses
  195. * which got fulfilled.
  196. *
  197. *
  198. *
  199. */
  200. function get_progress_hours($requirement_type = "", $bool_required_hours_only = TRUE, $bool_qpts_grades_only = FALSE, $bool_exclude_all_transfer_credits = FALSE, $req_by_degree_id = 0)
  201. {
  202. if ($requirement_type == "degree") $requirement_type = "";
  203. $hours = 0;
  204. $this->list_semesters->reset_counter();
  205. while ($this->list_semesters->has_more())
  206. {
  207. $sem = $this->list_semesters->get_next();
  208. if ($bool_required_hours_only == TRUE)
  209. {
  210. $hours += $sem->list_courses->count_hours($requirement_type, TRUE, FALSE, FALSE, FALSE, $req_by_degree_id); // do not exclude transfer credits, since this is for required hours only.
  211. } else {
  212. $temp = $sem->list_courses->count_credit_hours($requirement_type, TRUE, TRUE, $bool_qpts_grades_only, $bool_exclude_all_transfer_credits, $req_by_degree_id);
  213. $hours += $temp;
  214. }
  215. }
  216. // Also, add in groups matching this requirement type.
  217. $this->list_groups->reset_counter();
  218. while ($this->list_groups->has_more())
  219. {
  220. $g = $this->list_groups->get_next();
  221. if ($g->group_id < 0)
  222. { // Skip Add a course group.
  223. continue;
  224. }
  225. // Make sure the group doesn't have a type of 'x' assigned to it, which means we should
  226. // skip it.
  227. if ($g->requirement_type == 'x') continue;
  228. // If req_by_degree_id is set, make sure this group is assigned to that degree.
  229. if ($req_by_degree_id != 0 && $g->req_by_degree_id != $req_by_degree_id) continue;
  230. $g_hours = $g->hours_required;
  231. // use the min hours if it is set.
  232. if ($g->min_hours_allowed > 0) {
  233. $g_hours = $g->min_hours_allowed;
  234. }
  235. if ($bool_required_hours_only == false)
  236. { // only count the fulfilled hours, then.
  237. $g_hours = $g->get_fulfilled_hours(true, false, true, -1, true, $bool_qpts_grades_only, $requirement_type, $bool_exclude_all_transfer_credits);
  238. }
  239. if ($requirement_type == "")
  240. {
  241. $hours += $g_hours;
  242. }
  243. else {
  244. // A requirement is specified, so make sure
  245. // the group is of this requirement.
  246. if (!isset($g->hours_required_by_type[$requirement_type])) $g->hours_required_by_type[$requirement_type] = 0;
  247. if ($bool_required_hours_only == true)
  248. { // make sure it's of the right type.
  249. //$g_hours = $g->hours_required_by_type[$requirement_type]*1;
  250. // it should just be any hours_required, instead of by type, since a group can only have 1 type.
  251. if ($g->requirement_type == $requirement_type) {
  252. $g_hours = $g->hours_required;
  253. // use the min hours if it is set.
  254. if ($g->min_hours_allowed > 0) {
  255. $g_hours = $g->min_hours_allowed;
  256. }
  257. $hours += $g_hours;
  258. continue;
  259. }
  260. }
  261. if ($g->requirement_type == $requirement_type)
  262. {
  263. $hours += $g_hours;
  264. }
  265. }
  266. }
  267. return $hours;
  268. }
  269. /**
  270. * Similar to get_progress_hours, this will return back the quality points a student has earned
  271. * towards this degree. It can then be used to calculate GPA.
  272. *
  273. * @param unknown_type $requirement_type
  274. * @param unknown_type $bool_required_hours_only
  275. * @return unknown
  276. */
  277. function get_progress_quality_points($requirement_type = "", $bool_exclude_all_transfer_credits = FALSE, $req_by_degree_id = 0) {
  278. // Returns the number of hours required (or fulfilled) in a degree plan
  279. // for courses & groups with the specified requirement_type.
  280. // ex: "m", "s", etc. leave blank for ALL required hours.
  281. // if boolRequiredHours is FALSE, then we will only look for the courses
  282. // which got fulfilled.
  283. if ($requirement_type == "degree") $requirement_type = "";
  284. $points = 0;
  285. $this->list_semesters->reset_counter();
  286. while ($this->list_semesters->has_more())
  287. {
  288. $sem = $this->list_semesters->get_next();
  289. $p = $sem->list_courses->count_credit_quality_points($requirement_type, true, true, $bool_exclude_all_transfer_credits, $req_by_degree_id);
  290. $points = $points + $p;
  291. }
  292. // Also, add in groups matching this requirement type.
  293. $this->list_groups->reset_counter();
  294. while ($this->list_groups->has_more())
  295. {
  296. $g = $this->list_groups->get_next();
  297. if ($g->group_id < 0)
  298. { // Skip Add a course group.
  299. continue;
  300. }
  301. // Make sure the group doesn't have a type of 'x' assigned to it, which means we should
  302. // skip it.
  303. if ($g->requirement_type == 'x') continue;
  304. // if req_by_degree_id is set, make sure the group belongs to that degree id!
  305. if ($req_by_degree_id != 0 && $g->req_by_degree_id != $req_by_degree_id) continue;
  306. $g_points = $g->get_fulfilled_quality_points(TRUE, -1, TRUE, TRUE, $requirement_type, $bool_exclude_all_transfer_credits);
  307. $points = $points + $g_points;
  308. }
  309. return $points;
  310. }
  311. /**
  312. * Loads the "ancillary" information about our degree plan, including advising weight, track selection config, etc.
  313. *
  314. */
  315. function load_degree_plan_ancillary() {
  316. $degree_id = $this->degree_id;
  317. $old_semester = "";
  318. $table_name1 = "degrees";
  319. $table_name2 = "degree_requirements";
  320. if ($this->bool_use_draft) {
  321. $table_name1 = "draft_$table_name1";
  322. $table_name2 = "draft_$table_name2";
  323. }
  324. // We want to get some of the data for this degree.
  325. $res = db_query("SELECT * FROM $table_name1 WHERE degree_id = ?", $this->degree_id);
  326. if ($res) {
  327. $cur = db_fetch_array($res);
  328. $this->title = @$cur["title"];
  329. $this->major_code = @$cur["major_code"];
  330. $this->degree_level = @strtoupper(trim($cur["degree_level"]));
  331. if ($this->degree_level == "") {
  332. $this->degree_level = "UG"; // undergrad by default
  333. }
  334. $this->degree_class = @$cur["degree_class"];
  335. $this->db_override_degree_hours = @$cur["override_degree_hours"];
  336. $this->db_advising_weight = @intval($cur["advising_weight"]);
  337. $data_entry_value = @trim($cur['data_entry_value']);
  338. $this->db_track_selection_config = @trim($cur["track_selection_config"]);
  339. $this->parse_track_selection_config(); // load into the track_selection_config_array as needed.
  340. }
  341. } // load_degree_plan_ancillary
  342. /**
  343. * Load our complete degree plan, including all courses and groups.
  344. *
  345. */
  346. function load_degree_plan() {
  347. // Load this degree plan from the database and fully
  348. // assemble it.
  349. $degree_id = $this->degree_id;
  350. $old_semester = "";
  351. $table_name1 = "degrees";
  352. $table_name2 = "degree_requirements";
  353. if ($this->bool_use_draft) {
  354. $table_name1 = "draft_$table_name1";
  355. $table_name2 = "draft_$table_name2";
  356. }
  357. // Degrees we should exclude from the "appears in" counts. Used later...
  358. $exclude_degree_ids = NULL;
  359. $res = $this->db->db_query("SELECT * FROM $table_name1 a, $table_name2 b
  360. WHERE a.degree_id = ?
  361. AND a.degree_id = b.degree_id
  362. ORDER BY semester_num ", array($this->degree_id));
  363. while ($cur = $this->db->db_fetch_array($res))
  364. {
  365. $this->title = $cur["title"];
  366. $this->major_code = $cur["major_code"];
  367. $this->school_id = intval($cur['school_id']);
  368. if (!$exclude_degree_ids) {
  369. $exclude_degree_ids = system_get_exclude_degree_ids_from_appears_in_counts($this->school_id);
  370. }
  371. $this->degree_level = strtoupper(trim($cur["degree_level"]));
  372. if ($this->degree_level == "") {
  373. $this->degree_level = "UG"; // undergrad by default
  374. }
  375. $this->degree_class = $cur["degree_class"];
  376. $this->db_override_degree_hours = $cur["override_degree_hours"];
  377. $this->db_advising_weight = intval($cur["advising_weight"]);
  378. $data_entry_value = trim($cur['data_entry_value']);
  379. $this->db_track_selection_config = trim($cur["track_selection_config"]);
  380. $this->parse_track_selection_config(); // load into the track_selection_config_array as needed.
  381. $semester_num = $cur["semester_num"];
  382. if ($semester_num != $old_semester)
  383. {
  384. // This is a new semester object we are dealing with.
  385. $old_semester = $semester_num;
  386. $obj_semester = new Semester($semester_num);
  387. $obj_semester->title = trim(@$this->array_semester_titles[$semester_num]);
  388. if ($obj_semester->title == "") {
  389. $obj_semester->assign_title();
  390. }
  391. $this->list_semesters->add($obj_semester);
  392. }
  393. if ($cur["course_id"]*1 > 0)
  394. {
  395. // A course is the next degree requirement.
  396. //if ($this->bool_use_draft) $cat_year = $this->catalog_year;
  397. $cat_year = $this->catalog_year;
  398. $course_c = new Course($cur["course_id"], false, $this->db, false, $cat_year, $this->bool_use_draft);
  399. $course_c->assigned_to_semester_num = $semester_num;
  400. $course_c->min_grade = trim(strtoupper($cur["course_min_grade"]));
  401. if ($course_c->min_grade == "")
  402. { // By default, all courses have a
  403. // min grade requirement of D.
  404. $course_c->min_grade = "D";
  405. }
  406. $course_c->requirement_type = trim($cur["course_requirement_type"]);
  407. // Set which degree_id this course is a requirement of (for multiple degrees)
  408. $course_c->req_by_degree_id = $this->degree_id;
  409. $course_c->db_degree_requirement_id = $cur['id'];
  410. //adminDebug($course_c->to_string() . $course_c->getCatalogHours());
  411. $obj_semester->list_courses->add($course_c);
  412. if (!in_array($this->degree_id, $exclude_degree_ids)) {
  413. // array is sectioned like: course_id | degree_id | group_id. Group id = 0 means "on the bare degree plan"
  414. $this->required_course_id_array[$course_c->course_id][$this->degree_id][0] = TRUE;
  415. }
  416. } // if course_id > 0
  417. if ($cur["group_id"]*1 > 0)
  418. {
  419. // A group is the next degree requirement.
  420. $title = "";
  421. $icon_filename = "";
  422. // Add the real Group (with all the courses, branches, etc)
  423. // to the DegreePlan's group list!
  424. // First, see if this group already exists. If it does,
  425. // simply add the number of hours required to it. If not,
  426. // create it fresh.
  427. if ($new_group = $this->find_group($cur["group_id"] . '_' . $this->degree_id)) // group_id's will always have db_group_id _ degree_id from now on...
  428. {
  429. // Was already there (probably in another semester),
  430. // so, just increment the required hours.
  431. if (!isset($new_group->hours_required_by_type[$cur["group_requirement_type"]])) {
  432. $new_group->hours_required_by_type[$cur["group_requirement_type"]] = 0;
  433. }
  434. $new_group->hours_required = $new_group->hours_required + ($cur["group_hours_required"] * 1);
  435. $new_group->hours_required_by_type[$cur["group_requirement_type"]] += ($cur["group_hours_required"] * 1);
  436. //Set which degree_id this is required by.
  437. $new_group->req_by_degree_id = $this->degree_id;
  438. $title = $new_group->title;
  439. $icon_filename = $new_group->icon_filename;
  440. }
  441. else {
  442. // Was not already there; insert it.
  443. $group_n = new Group($cur["group_id"] . '_' . $this->degree_id, $this->db, $semester_num, $this->student_array_significant_courses, $this->bool_use_draft, $cur["group_requirement_type"]);
  444. $group_n->hours_required = $cur["group_hours_required"] * 1;
  445. if (!isset($group_n->hours_required_by_type[$cur["group_requirement_type"]])) $group_n->hours_required_by_type[$cur["group_requirement_type"]] = 0;
  446. $group_n->hours_required_by_type[$cur["group_requirement_type"]] += $group_n->hours_required;
  447. $group_n->set_req_by_degree_id($this->degree_id);
  448. if (trim($cur["group_min_grade"]) != "")
  449. {
  450. $group_n->assign_min_grade(trim(strtoupper($cur["group_min_grade"])));
  451. }
  452. $title = $group_n->title;
  453. $icon_filename = $group_n->icon_filename;
  454. $this->list_groups->add($group_n);
  455. }
  456. // Add a placeholder to the Semester....
  457. $group_g = new Group();
  458. $group_g->bool_use_draft = $this->bool_use_draft;
  459. $group_g->group_id = $cur["group_id"] . '_' . $this->degree_id;
  460. $group_g->set_req_by_degree_id($this->degree_id);
  461. $group_g->load_descriptive_data();
  462. $group_g->set_requirement_type($cur["group_requirement_type"]);
  463. if (trim($cur["group_min_grade"]) != "")
  464. {
  465. $group_g->assign_min_grade(trim(strtoupper($cur["group_min_grade"])));
  466. }
  467. $group_g->assigned_to_semester_num = $semester_num;
  468. $group_g->title = "$title";
  469. $group_g->icon_filename = $icon_filename;
  470. $group_g->hours_required = floatval($cur["group_hours_required"]);
  471. $group_g->min_hours_allowed = floatval($cur["group_min_hours_allowed"]);
  472. $group_g->bool_placeholder = true;
  473. $obj_semester->list_groups->add($group_g);
  474. }// if group_id > 0
  475. } // while db results
  476. $this->list_groups->sort_priority();
  477. if (!is_array($exclude_degree_ids)) $exclude_degree_ids = array();
  478. if (!in_array($this->degree_id, $exclude_degree_ids)) {
  479. $group_course_id_array = $this->list_groups->get_group_course_id_array();
  480. // Add to our required_course_id_array.
  481. foreach($group_course_id_array as $group_id => $details) {
  482. foreach ($group_course_id_array[$group_id] as $course_id => $val) {
  483. $this->required_course_id_array[$course_id][$this->degree_id][$group_id] = $val;
  484. }
  485. }
  486. }
  487. // When we load this degree plan, let's also check for any hooks.
  488. // Since this class might be used outside of FP, only do this if we know
  489. // that the bootstrap.inc file has been executed.
  490. if ($GLOBALS["fp_bootstrap_loaded"] == TRUE) {
  491. invoke_hook("degree_plan_load", array(&$this));
  492. }
  493. } // load_degree_plan
  494. /**
  495. * Add another degree's required_course_id_array onto this one's.
  496. */
  497. function add_to_required_course_id_array($req_course_id_array) {
  498. foreach ($req_course_id_array as $course_id => $details) {
  499. foreach ($req_course_id_array[$course_id] as $degree_id => $details2) {
  500. foreach ($req_course_id_array[$course_id][$degree_id] as $group_id => $val) {
  501. $this->required_course_id_array[$course_id][$degree_id][$group_id] = $val;
  502. }
  503. }
  504. }
  505. } // add_to_required_course_id_array
  506. /**
  507. * This function will parse through the db_track_selection_config string and
  508. * populate the track_selection_config_array.
  509. *
  510. * We assume the string looks like this:
  511. *
  512. * CLASS ~ MIN ~ MAX ~ DEFAULT_CSV
  513. *
  514. * ex:
  515. * CONCENTRATION ~ 0 ~ 1 ~
  516. * EMPHASIS ~ 1 ~ 1 ~ ART|_SCULT, ART|_PAINT
  517. *
  518. *
  519. *
  520. */
  521. function parse_track_selection_config() {
  522. $lines = explode("\n", $this->db_track_selection_config);
  523. foreach ($lines as $line) {
  524. $line = trim($line);
  525. if ($line == "") continue; // blank line, skip it.
  526. if (substr($line, 0, 1) == "#") continue; // this is a comment, skip it.
  527. $temp = explode("~", $line);
  528. $machine_name = @trim($temp[0]);
  529. $min = @intval($temp[1]);
  530. $max = @intval($temp[2]);
  531. $default_csv = @trim($temp[3]);
  532. $this->track_selection_config_array[$machine_name] = array(
  533. "machine_name" => $machine_name,
  534. "min_tracks" => $min,
  535. "max_tracks" => $max,
  536. "default_tracks" => $default_csv,
  537. );
  538. }
  539. } // parse... config
  540. function get_title($bool_include_track = false)
  541. {
  542. // This will return the title of this degree, possibly
  543. // including the track's title as well.
  544. $rtn = $this->title;
  545. if ($bool_include_track == true)
  546. {
  547. if ($this->track_title != "")
  548. {
  549. $rtn .= " with " . $this->track_title . "";
  550. }
  551. }
  552. return $rtn;
  553. }
  554. /**
  555. * Returns back a CSV of all the major codes that this degree comprises
  556. */
  557. function get_major_code_csv() {
  558. if (!$this->is_combined_dynamic_degree_plan) return $this->major_code; // just a basic single non-combined degree.
  559. // Otherwise, we should assume this is a combined dynamic degree.
  560. $rtn = "";
  561. foreach ($this->combined_degree_ids_array as $degree_id) {
  562. $t_degree_plan = new DegreePlan($degree_id);
  563. $rtn .= $t_degree_plan->major_code . ",";
  564. }
  565. $rtn = rtrim($rtn, ","); // remove last comma, if its there.
  566. return $rtn;
  567. }
  568. function get_track_title($bool_include_classification = FALSE) {
  569. $this->load_descriptive_data();
  570. $ttitle = trim($this->track_title);
  571. if ($ttitle == "") return FALSE; // there is no track?
  572. if ($bool_include_classification) {
  573. $details = fp_get_degree_classification_details($this->degree_class);
  574. $ttitle .= " (" . $details["title"] . ")";
  575. }
  576. return $ttitle;
  577. }
  578. function get_title2($bool_include_classification = FALSE, $bool_include_track_title = FALSE, $bool_include_html = TRUE)
  579. {
  580. // This will simply return the degree's title. If it does not
  581. // exist, it will try to find another degree with the same major_code.
  582. // This is to fix the problem with students with catalog years outside
  583. // of FlightPath's database, but with major codes that have titles.
  584. if (!$this->bool_loaded_descriptive_data) {
  585. $this->load_descriptive_data();
  586. }
  587. $dtitle = "";
  588. if ($this->title) {
  589. $dtitle = $this->title;
  590. if ($bool_include_html) {
  591. $dtitle = "<span class='deg-title'>$this->title</span>";
  592. }
  593. }
  594. else {
  595. // Still no title? Try to load ANY degree title with this degree's
  596. // major_code.
  597. $this->title = '';
  598. $table_name = "degrees";
  599. if ($this->bool_use_draft) {$table_name = "draft_$table_name";}
  600. $res = $this->db->db_query("SELECT title FROM $table_name
  601. WHERE major_code = ?
  602. ORDER BY catalog_year DESC LIMIT 1", $this->major_code);
  603. $cur = $this->db->db_fetch_array($res);
  604. if ($cur) {
  605. $this->title = trim($cur["title"]);
  606. }
  607. if ($bool_include_html && $this->title) {
  608. $dtitle = "<span class='deg-title'>$this->title</span>";
  609. }
  610. else {
  611. $dtitle = $this->title;
  612. }
  613. }
  614. if ($bool_include_track_title && $this->track_title != "") {
  615. if ($bool_include_html && $this->title) {
  616. $dtitle .= "<span class='level-3-raquo'>&raquo;</span>";
  617. $dtitle .= "<span class='deg-track-title'>$this->track_title</span>";
  618. }
  619. else {
  620. $dtitle .= $this->track_title;
  621. }
  622. }
  623. if ($bool_include_classification && $this->degree_class != "") {
  624. $details = fp_get_degree_classification_details($this->degree_class);
  625. if ($bool_include_html) {
  626. $dtitle .= " <span class='deg-class-title'>(" . $details["title"] . ")</span>";
  627. }
  628. else {
  629. $dtitle .= " (" . $details["title"] . ")";
  630. }
  631. }
  632. return $dtitle;
  633. }
  634. function load_descriptive_data()
  635. {
  636. $this->bool_loaded_descriptive_data = TRUE;
  637. // If we already have this in our cache, then look there...
  638. $cache_name = 'degreeplan_cache';
  639. if ($this->bool_use_draft) {
  640. $cache_name = 'degreeplan_cache_draft';
  641. }
  642. if (isset($GLOBALS[$cache_name][$this->degree_id])) {
  643. $this->array_semester_titles = $GLOBALS[$cache_name][$this->degree_id]['array_semester_titles'];
  644. $this->bool_has_tracks = $GLOBALS[$cache_name][$this->degree_id]['bool_has_tracks'];
  645. $this->catalog_year = $GLOBALS[$cache_name][$this->degree_id]['catalog_year'];
  646. $this->db_advising_weight = $GLOBALS[$cache_name][$this->degree_id]['db_advising_weight'];
  647. $this->db_allow_dynamic = $GLOBALS[$cache_name][$this->degree_id]['db_allow_dynamic'];
  648. $this->db_exclude = $GLOBALS[$cache_name][$this->degree_id]['db_exclude'];
  649. $this->db_override_degree_hours = $GLOBALS[$cache_name][$this->degree_id]['db_override_degree_hours'];
  650. $this->degree_class = $GLOBALS[$cache_name][$this->degree_id]['degree_class'];
  651. $this->degree_level = $GLOBALS[$cache_name][$this->degree_id]['degree_level'];
  652. $this->school_id = $GLOBALS[$cache_name][$this->degree_id]['school_id'];
  653. if ($this->degree_level == "") {
  654. $this->degree_level = "UG"; // undergrad by default
  655. }
  656. $this->degree_type = $GLOBALS[$cache_name][$this->degree_id]['degree_type'];
  657. $this->major_code = $GLOBALS[$cache_name][$this->degree_id]['major_code'];
  658. $this->public_notes_array = $GLOBALS[$cache_name][$this->degree_id]['public_notes_array'];
  659. $this->title = $GLOBALS[$cache_name][$this->degree_id]['title'];
  660. $this->track_code = $GLOBALS[$cache_name][$this->degree_id]['track_code'];
  661. $this->track_description = $GLOBALS[$cache_name][$this->degree_id]['track_description'];
  662. $this->track_title = $GLOBALS[$cache_name][$this->degree_id]['track_title'];
  663. return;
  664. }
  665. $table_name = "degrees";
  666. if ($this->bool_use_draft) {$table_name = "draft_$table_name";}
  667. $res = $this->db->db_query("SELECT * FROM $table_name
  668. WHERE degree_id = ? ", $this->degree_id);
  669. if ($this->db->db_num_rows($res) > 0)
  670. {
  671. $cur = $this->db->db_fetch_array($res);
  672. $this->major_code = $cur["major_code"];
  673. $this->degree_level = strtoupper(trim($cur["degree_level"]));
  674. if ($this->degree_level == "") {
  675. $this->degree_level = "UG"; // undergrad by default
  676. }
  677. $this->degree_class = $cur["degree_class"];
  678. $this->db_override_degree_hours = $cur["override_degree_hours"];
  679. $this->title = $cur["title"];
  680. $this->school_id = intval($cur['school_id']);
  681. $this->public_notes_array[$this->degree_id] = $cur["public_note"];
  682. $this->catalog_year = $cur["catalog_year"];
  683. $this->degree_type = trim($cur["degree_type"]);
  684. $this->db_exclude = trim($cur["exclude"]);
  685. $this->db_allow_dynamic = trim($cur["allow_dynamic"]);
  686. $this->db_advising_weight = intval($cur["advising_weight"]);
  687. // Get the semester titles.
  688. $temp = trim($cur["semester_titles_csv"]);
  689. $this->array_semester_titles = explode(",",$temp);
  690. $just_major_code = $this->major_code;
  691. if (strstr($this->major_code, "_"))
  692. {
  693. // This means that there is a track. Get all the information
  694. // you can about it.
  695. $temp = explode("_", $this->major_code);
  696. $this->track_code = trim($temp[1]);
  697. $just_major_code = trim($temp[0]); // Don't change major_code value-- causes a bug in FP5
  698. // The major_code might now have a | at the very end. If so,
  699. // get rid of it.
  700. $just_major_code = rtrim($just_major_code, "|");
  701. // Now, look up information on the track.
  702. $table_name = "degree_tracks";
  703. if ($this->bool_use_draft) {$table_name = "draft_$table_name";}
  704. static $degree_track_cache = array();
  705. $cur = null;
  706. if (isset($degree_track_cache[$table_name][$this->major_code][$this->track_code][$this->catalog_year])) {
  707. $cur = $degree_track_cache[$table_name][$this->major_code][$this->track_code][$this->catalog_year];
  708. }
  709. else {
  710. $res = $this->db->db_query("SELECT track_title, track_description FROM $table_name
  711. WHERE major_code = ?
  712. AND track_code = ?
  713. AND catalog_year = ? ", $just_major_code, $this->track_code, $this->catalog_year);
  714. $cur = $this->db->db_fetch_array($res);
  715. $degree_track_cache[$table_name][$just_major_code][$this->track_code][$this->catalog_year] = $cur;
  716. }
  717. $this->track_title = $cur["track_title"];
  718. $this->track_description = $cur["track_description"];
  719. }
  720. // Does this major have any tracks at all? If so, set a bool.
  721. if ($this->db->get_degree_tracks($just_major_code, $this->catalog_year))
  722. {
  723. $this->bool_has_tracks = true;
  724. }
  725. }
  726. // Add to our GLOBALS cache for this degree's descriptive data.
  727. $GLOBALS[$cache_name][$this->degree_id] = array(
  728. 'array_semester_titles' => $this->array_semester_titles,
  729. 'bool_has_tracks' => $this->bool_has_tracks,
  730. 'catalog_year' => $this->catalog_year,
  731. 'db_advising_weight' => $this->db_advising_weight,
  732. 'db_allow_dynamic' => $this->db_allow_dynamic,
  733. 'db_exclude' => $this->db_exclude,
  734. 'db_override_degree_hours' => $this->db_override_degree_hours,
  735. 'degree_class' => $this->degree_class,
  736. 'degree_level' => $this->degree_level,
  737. 'degree_type' => $this->degree_type,
  738. 'major_code' => $this->major_code,
  739. 'public_notes_array' => $this->public_notes_array,
  740. 'title' => $this->title,
  741. 'track_code' => $this->track_code,
  742. 'track_description' => $this->track_description,
  743. 'track_title' => $this->track_title,
  744. 'school_id' => $this->school_id,
  745. );
  746. }
  747. function get_advised_courses_list()
  748. {
  749. // Return a courseList object containing every course
  750. // in this degreePlan which is marked as boolAdvisedToTake=true.
  751. $rtn_list = new CourseList();
  752. $this->list_semesters->reset_counter();
  753. while ($this->list_semesters->has_more())
  754. {
  755. $semester = $this->list_semesters->get_next();
  756. $rtn_list->add_list($semester->list_courses->get_advised_courses_list());
  757. }
  758. $rtn_list->add_list($this->list_groups->get_advised_courses_list());
  759. return $rtn_list;
  760. }
  761. /**
  762. * Look through our list of semesters for the one with this semester_num, and return it, or return FALSE
  763. */
  764. function get_semester($semester_num) {
  765. $this->list_semesters->reset_counter();
  766. while ($this->list_semesters->has_more()) {
  767. $sem = $this->list_semesters->get_next();
  768. if ($sem->semester_num == $semester_num) {
  769. return $sem;
  770. }
  771. }
  772. return FALSE;
  773. }
  774. /**
  775. * Returns a simple array with values seperated by " ~~ "
  776. * in this order: track_code ~~ track_title ~~ trackDesc ~~ track's degree id
  777. *
  778. * @return array
  779. */
  780. function get_available_tracks()
  781. {
  782. $rtn_array = array();
  783. $rtn_array[] = " ~~ None ~~ Select this option to display
  784. the base degree plan (may not be available for all majors).";
  785. $table_name = "degree_tracks";
  786. $table_name2 = "degrees";
  787. if ($this->bool_use_draft) {$table_name = "draft_$table_name";}
  788. if ($this->bool_use_draft) {$table_name2 = "draft_$table_name2";}
  789. $res = db_query("SELECT track_code, track_title, track_description FROM $table_name
  790. WHERE major_code = ?
  791. AND catalog_year = ?
  792. AND school_id = ?
  793. ORDER BY track_title ", $this->major_code, $this->catalog_year, $this->school_id);
  794. while($cur = db_fetch_array($res))
  795. {
  796. $track_code = $cur["track_code"];
  797. $track_title = $cur["track_title"];
  798. $track_description = $cur["track_description"];
  799. // Let's also get the degree_id for this particular track.
  800. $track_degree_id = $this->db->get_degree_id($this->major_code . "|_" . $track_code, $this->catalog_year, $this->bool_use_draft, $this->school_id);
  801. // Also find out what is the degree_class for this degree_id.
  802. $degree_class = @trim(db_result(db_query("SELECT degree_class FROM $table_name2
  803. WHERE degree_id = ?", $track_degree_id)));
  804. $rtn_array[] = "$track_code ~~ $track_title ~~ $track_description ~~ $track_degree_id ~~ $degree_class";
  805. }
  806. if (count($rtn_array) > 1) // we're going to have at least 1 because of the "none" option. Let's skip that one.
  807. {
  808. return $rtn_array;
  809. } else {
  810. return false;
  811. }
  812. }
  813. function add_semester_developmental($student_id)
  814. {
  815. // This will add the developmental courses in as
  816. // a semester. Will check the studentID to see if any
  817. // developmentals are required.
  818. // -55 is the developmental semester.
  819. $sem = new Semester(DegreePlan::SEMESTER_NUM_FOR_DEVELOPMENTALS);
  820. $sem->title = variable_get_for_school("developmentals_title", t("Developmental Requirements", $this->school_id));
  821. $is_empty = true;
  822. $temp_array = $this->db->get_developmental_requirements($student_id, $this->school_id);
  823. // We expect this to give us back an array like:
  824. // 0 => ART~101
  825. // 1 => MATH~090
  826. foreach($temp_array as $temp_course_name) {
  827. $temp = explode("~", $temp_course_name);
  828. $c = new Course($this->db->get_course_id($temp[0], $temp[1], '', FALSE, $this->school_id, TRUE));
  829. $c->min_grade = "C";
  830. $c->requirement_type = "dev";
  831. $sem->list_courses->add($c);
  832. $is_empty = false;
  833. }
  834. $sem->notice = variable_get_for_school("developmentals_notice", t("According to our records, you are required to complete the course(s) listed above. For some transfer students, your record may not be complete. If you have any questions, please ask your advisor.", $this->school_id));
  835. if (!$is_empty)
  836. {
  837. $this->list_semesters->add($sem);
  838. }
  839. }
  840. function add_semester_courses_added()
  841. {
  842. // The "Add a Course" box on screen is really just a
  843. // semester, with the number -88, with a single group,
  844. // also numbered -88.
  845. $semester_courses_added = new Semester(DegreePlan::SEMESTER_NUM_FOR_COURSES_ADDED);
  846. $semester_courses_added->title = t("Courses Added by Advisor");
  847. // Now, we want to add the Add a Course group...
  848. $g = new Group();
  849. $g->group_id = DegreePlan::GROUP_ID_FOR_COURSES_ADDED;
  850. // Since it would take a long time during page load, we will
  851. // leave this empty of courses for now. It doesn't matter anyway,
  852. // as we will not be checking this group for course membership
  853. // anyway. We only need to load it in the popup.
  854. $g->hours_required = 99999; // Nearly infinite selections may be made.
  855. $g->assigned_to_semester_num = DegreePlan::SEMESTER_NUM_FOR_COURSES_ADDED;
  856. $semester_courses_added->list_groups->add($g);
  857. $this->list_semesters->add($semester_courses_added);
  858. // Also, add it to the list of groups OUTSIDE of semesters.
  859. $this->list_groups->add($g);
  860. }
  861. function find_group($group_id)
  862. {
  863. // Locate the group with group_id in the
  864. // list of groups, and return it.
  865. $this->list_groups->reset_counter();
  866. while($this->list_groups->has_more())
  867. {
  868. $group = $this->list_groups->get_next();
  869. if ($group->group_id == $group_id)
  870. {
  871. return $group;
  872. }
  873. if (!$group->list_groups->is_empty)
  874. {
  875. $group->list_groups->reset_counter();
  876. while($group->list_groups->has_more())
  877. {
  878. $branch = $group->list_groups->get_next();
  879. if ($branch->group_id == $group_id)
  880. {
  881. return $branch;
  882. }
  883. }
  884. }
  885. }
  886. return false;
  887. }
  888. function find_placeholder_group($group_id, $semester_num)
  889. {
  890. // Locate the group within the semesters that matches
  891. // this group_id and semesterNum. The assumption here
  892. // is that no one semester will list the same
  893. // group twice. In other words, Core Fine Arts
  894. // can only have 1 entry for Freshman Year.
  895. // Create a dummy semester with the correct semesterNum...
  896. $new_semester = new Semester($semester_num);
  897. // Create dummy group as well... don't use the constructor, just
  898. // set the group_id manually to same time. (no DB calls)
  899. $new_group = new Group();
  900. $new_group->group_id = $group_id;
  901. //print_pre($this->list_semesters->to_string());
  902. // Find the semester in the list of semesters with this same semesterNum...
  903. if (!$semester = $this->list_semesters->find_match($new_semester))
  904. {
  905. // The semester wasn't found!
  906. return false;
  907. }
  908. // Okay, now go through $semester and find the group_id...
  909. if (!$group = $semester->list_groups->find_match($new_group))
  910. {
  911. // It wasn't found in the top-level groups. Look one deeper...
  912. if (!$semester->list_groups->is_empty)
  913. {
  914. $semester->list_groups->reset_counter();
  915. while($semester->list_groups->has_more())
  916. {
  917. $group = $semester->list_groups->get_next();
  918. if ($g = $group->list_groups->find_match($new_group))
  919. {
  920. //$g->assign_to_semester($semester_num);
  921. return $g;
  922. }
  923. }
  924. }
  925. } else {
  926. // Meaning, we found it!
  927. //$group->assign_to_semester($semester_num);
  928. return $group;
  929. }
  930. return false;
  931. }
  932. /**
  933. * If degree_id != 0, then we will remove any course from the finished list that is NOT in the degree plan.
  934. * 0 means "give me all of matches back"
  935. */
  936. function find_courses($course_id, $group_id = 0, $semester_num, $degree_id = 0)
  937. {
  938. // This will locate a course within the degree plan, and return
  939. // back either that course object, or FALSE.
  940. $new_course = new Course($course_id);
  941. $new_semester = new Semester($semester_num);
  942. $rtn_course_list = new CourseList();
  943. // Okay, if the course is within a group, then
  944. // we can first use the find_group method.
  945. if ($group_id != "" && $group_id != 0)
  946. {
  947. if ($group = $this->find_group($group_id))
  948. {
  949. if (!($group->list_courses->is_empty))
  950. {
  951. if ($cL = $group->find_courses($new_course))
  952. {
  953. $rtn_course_list->add_list($cL);
  954. }
  955. }
  956. if (!($group->list_groups->is_empty))
  957. {
  958. // Look within each sub group for the course...
  959. $group->list_groups->reset_counter();
  960. while($group->list_groups->has_more())
  961. {
  962. $branch = $group->list_groups->get_next();
  963. if (!$branch->list_courses->is_empty)
  964. {
  965. if ($cL = $branch->find_courses($new_course))
  966. {
  967. $rtn_course_list->add_list($cL);
  968. }
  969. }
  970. // Here we can look for groups within groups...
  971. }
  972. }
  973. }
  974. return $rtn_course_list;
  975. } else if ($semester_num != -1) {
  976. // No group specified. This course is on the
  977. // bare degree plan. We were given a specific semester,
  978. // so try to find it there...
  979. if ($semester = $this->list_semesters->find_match($new_semester))
  980. {
  981. if ($cL = $semester->list_courses->find_all_matches($new_course))
  982. {
  983. if ($degree_id != 0) {
  984. // Trim $cL of any courses NOT in our supplied degree_id.
  985. $cL->remove_courses_not_in_degree($degree_id);
  986. if ($cL->get_size() == 0) return FALSE; // we removed them all!
  987. }
  988. $rtn_course_list->add_list($cL);
  989. return $rtn_course_list;
  990. }
  991. }
  992. } else if ($semester_num == -1)
  993. {
  994. // Meaning, we do not know which semester it goes in, so
  995. // attempt all semesters, and return with the first instance.
  996. $this->list_semesters->reset_counter();
  997. while($this->list_semesters->has_more())
  998. {
  999. $sem = $this->list_semesters->get_next();
  1000. if ($cL = $sem->list_courses->find_all_matches($new_course))
  1001. {
  1002. $rtn_course_list->add_list($cL);
  1003. return $rtn_course_list;
  1004. }
  1005. }
  1006. }
  1007. return FALSE;
  1008. }
  1009. function to_string()
  1010. {
  1011. // Output this degree plan object in a helpful manner.
  1012. $rtn = "";
  1013. $rtn .= "Degree Plan: $this->title ($this->major_code) \n";
  1014. $rtn .= $this->list_semesters->to_string();
  1015. $rtn .= "----------------------------------------- \n";
  1016. $rtn .= "-- ALL GROUPS \n";
  1017. $rtn .= $this->list_groups->to_string();
  1018. return $rtn;
  1019. }
  1020. } // end class DegreePlan

Classes

Namesort descending Description
DegreePlan