Course.php

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

File

classes/Course.php
View source
  1. <?php
  2. /*
  3. Class definition for the Course object.
  4. */
  5. class Course extends stdClass
  6. {
  7. // Some public variables and what they are used for.
  8. const COURSE_UNKNOWN_TERM_ID = 11111;
  9. // Database & misc related:
  10. public $random_id, $db_advised_courses_id;
  11. public $bool_placeholder, $db, $db_substitution_id_array, $db_unassign_transfer_id;
  12. public $db_exclude, $data_entry_comment, $array_index, $data_entry_value, $db_group_attributes;
  13. public $db_group_requirement_id; // the id from the group_requirements table where this was specified.
  14. public $db_degree_requirement_id; // the id from the degree_requirements table where this was specified.
  15. public $extra_attribs;
  16. // Course catalog data related:
  17. public $subject_id, $course_num, $course_id, $requirement_type, $catalog_year;
  18. public $min_hours, $max_hours, $list_prereqs, $repeat_hours;
  19. public $array_valid_names, $school_id;
  20. // Student record related:
  21. public $bool_taken, $term_id, $section_number, $quality_points, $grade, $db_grade, $level_code;
  22. public $bool_transfer, $institution_id, $institution_name, $course_transfer;
  23. public $transfer_eqv_text, $transfer_footnote;
  24. public $details_by_degree_array; // meant to hold all details about a substitution, or anything else, keyed by degree id.
  25. // Major/Degree or Group Requirement related:
  26. public $min_grade, $specified_repeats, $bool_specified_repeat, $required_on_branch_id;
  27. public $assigned_to_semester_num, $appears_in_semester_nums, $req_by_degree_id;
  28. public $assigned_to_degree_ids_array, $assigned_to_group_ids_array;
  29. // advising & in-system logic related:
  30. public $advised_hours, $bool_selected, $bool_advised_to_take;
  31. public $course_list_fulfilled_by;
  32. public $bool_added_course, $group_list_unassigned;
  33. public $advised_term_id, $temp_old_course_id;
  34. public $bool_use_draft;
  35. // Display related:
  36. public $display_status, $icon_filename, $description, $title;
  37. public $title_text, $temp_flag, $disp_for_group_id;
  38. public $bool_unselectable;
  39. public $bool_hide_grade, $bool_ghost_hour, $bool_ghost_min_hour;
  40. /**
  41. * The constructor for a Course object.
  42. *
  43. * @param int $course_id
  44. * - Numeric course_id of the course to try to load. Leave blank
  45. * if you simply wish to instantiate a course object.
  46. *
  47. * @param bool $is_transfer
  48. * - Is this course a transfer course? Meaning, from another
  49. * school.
  50. *
  51. * @param DatabaseHandler $db
  52. * @param bool $is_blank
  53. * @param int $catalog_year
  54. * - What catalog_year does this Course belong to? This is
  55. * used later when we call load_descriptive_data() to get its
  56. * description, hour count, etc.
  57. *
  58. * @param bool $bool_use_draft
  59. */
  60. function __construct($course_id = "", $is_transfer = false, DatabaseHandler $db = NULL, $is_blank = false, $catalog_year = "", $bool_use_draft = false)
  61. {
  62. $this->advised_hours = -1;
  63. if ($is_blank == true)
  64. { // Do nothing if this is a "blank" course.
  65. return;
  66. }
  67. $array_valid_names = array(); // will hold all "valid" names for this course (non excluded names).
  68. $this->course_id = intval($course_id); // Force it to be numeric.
  69. $this->appears_in_semester_nums = array(); // for combo-degrees
  70. $this->temp_old_course_id = 0; // Used in case we delete the course_id, we can get it back (good with substitutions of transfers that are outdated).
  71. $this->catalog_year = $catalog_year;
  72. $this->assigned_to_semester_num = -1;
  73. //$this->assigned_to_group_id = 0; // deprecated
  74. $this->assigned_to_group_ids_array = array();
  75. $this->bool_advised_to_take = false;
  76. $this->bool_added_course = false;
  77. $this->specified_repeats = 0;
  78. $this->bool_specified_repeat = false;
  79. // Give this course instance a "random" numeric id, meaning, it doesn't really mean anything.
  80. // It used to actually be random, but we will use a simple increment instead to ensure it is unique.
  81. if (!isset($GLOBALS['fp_courses_random_ids'])) {
  82. $GLOBALS['fp_courses_random_ids'] = 10;
  83. }
  84. $this->random_id = $GLOBALS['fp_courses_random_ids']++;
  85. $this->display_status = "eligible";
  86. $this->course_list_fulfilled_by = new CourseList();
  87. $this->group_list_unassigned = new GroupList();
  88. $this->bool_use_draft = $bool_use_draft;
  89. $this->disp_for_group_id = "";
  90. $this->req_by_degree_id = 0;
  91. //$this->bool_has_been_displayed_by_degree_array = array();
  92. //$this->bool_substitution_by_degree_array = array();
  93. $this->db_substitution_id_array = array();
  94. //$this->course_substitution_by_degree_array = array();
  95. $this->details_by_degree_array = array();
  96. $this->details_by_degree_array[-1] = array(); // to keep notices from showing up.
  97. $this->assigned_to_degree_ids_array = array();
  98. // Always override if the global variable is set.
  99. if (@$GLOBALS["fp_advising"]["bool_use_draft"] == true) {
  100. $this->bool_use_draft = true;
  101. }
  102. $this->db = $db;
  103. if ($db == NULL)
  104. {
  105. $this->db = get_global_database_handler();;
  106. }
  107. if ($course_id != "")
  108. {
  109. $this->load_course($course_id, $is_transfer);
  110. }
  111. }
  112. function set_bool_substitution_split($degree_id = 0, $val) {
  113. // If degree_id is zero, then use the course's currently req_by_degree_id.
  114. if ($degree_id == 0) $degree_id = $this->req_by_degree_id;
  115. $this->set_details_by_degree($degree_id, "bool_substitution_split", $val);
  116. }
  117. function get_bool_substitution_split($degree_id = 0) {
  118. // If degree_id is zero, then use the course's currently req_by_degree_id.
  119. if ($degree_id == 0) $degree_id = $this->req_by_degree_id;
  120. if ($degree_id > 0) {
  121. //return $this->bool_substitution_by_degree_array[$degree_id];
  122. return $this->get_details_by_degree($degree_id, "bool_substitution_split");
  123. }
  124. else {
  125. // Any degree?
  126. if ($this->get_count_details_by_degree("bool_substitution_split", TRUE) > 0) {
  127. return TRUE;
  128. }
  129. }
  130. return FALSE;
  131. }
  132. function set_bool_outdated_sub($degree_id = 0, $val) {
  133. // If degree_id is zero, then use the course's currently req_by_degree_id.
  134. if ($degree_id == 0) $degree_id = $this->req_by_degree_id;
  135. $this->set_details_by_degree($degree_id, "bool_outdated_sub", $val);
  136. }
  137. function get_bool_outdated_sub($degree_id = 0) {
  138. // If degree_id is zero, then use the course's currently req_by_degree_id.
  139. if ($degree_id == 0) $degree_id = $this->req_by_degree_id;
  140. if ($degree_id > 0) {
  141. //return $this->bool_substitution_by_degree_array[$degree_id];
  142. return $this->get_details_by_degree($degree_id, "bool_outdated_sub");
  143. }
  144. else {
  145. // how about for ANY degree?
  146. if ($this->get_count_details_by_degree("bool_outdated_sub", TRUE) > 0) {
  147. return TRUE;
  148. }
  149. }
  150. return FALSE;
  151. }
  152. function set_bool_substitution_new_from_split($degree_id = 0, $val) {
  153. // If degree_id is zero, then use the course's currently req_by_degree_id.
  154. if ($degree_id == 0) $degree_id = $this->req_by_degree_id;
  155. $this->set_details_by_degree($degree_id, "bool_substitution_new_from_split", $val);
  156. }
  157. function get_bool_substitution_new_from_split($degree_id = 0) {
  158. // If degree_id is zero, then use the course's currently req_by_degree_id.
  159. if ($degree_id == 0) $degree_id = $this->req_by_degree_id;
  160. if ($degree_id > 0) {
  161. //return $this->bool_substitution_by_degree_array[$degree_id];
  162. return $this->get_details_by_degree($degree_id, "bool_substitution_new_from_split");
  163. }
  164. else {
  165. // how about for ANY degree?
  166. if ($this->get_count_details_by_degree("bool_substitution_new_from_split", TRUE) > 0) {
  167. return TRUE;
  168. }
  169. }
  170. return FALSE;
  171. }
  172. function set_substitution_hours($degree_id = 0, $val) {
  173. // If degree_id is zero, then use the course's currently req_by_degree_id.
  174. if ($degree_id == 0) $degree_id = $this->req_by_degree_id;
  175. $this->set_details_by_degree($degree_id, "substitution_hours", $val);
  176. }
  177. /**
  178. * Similar to the functions regarding display-- get the course substitution based on supplied degree_id.
  179. * Set degree_id to -1 to just get the first one, if available.
  180. */
  181. function get_substitution_hours($degree_id = 0) {
  182. // If degree_id is zero, then use the course's currently req_by_degree_id.
  183. if ($degree_id == 0) $degree_id = $this->req_by_degree_id;
  184. if ($degree_id > 0) {
  185. return $this->get_details_by_degree($degree_id, "substitution_hours");
  186. }
  187. else {
  188. if (isset($this->details_by_degree_array[$degree_id]["substitution_hours"])) {
  189. $x = $this->details_by_degree_array[$degree_id]["substitution_hours"];
  190. if ($x) return $x;
  191. }
  192. }
  193. // Else, return boolean FALSE
  194. return FALSE;
  195. }
  196. function set_hours_awarded($degree_id = 0, $val) {
  197. // If degree_id is zero, then use the course's currently req_by_degree_id.
  198. if ($degree_id == 0) $degree_id = $this->req_by_degree_id;
  199. $this->set_details_by_degree($degree_id, "hours_awarded", $val*1); // *1 to force integer and to trim extra zeroes.
  200. }
  201. function set_course_substitution($degree_id = 0, Course $course) {
  202. // If degree_id is zero, then use the course's currently req_by_degree_id.
  203. if ($degree_id == 0) $degree_id = $this->req_by_degree_id;
  204. //$this->course_substitution_by_degree_array[$degree_id] = $course;
  205. $this->set_details_by_degree($degree_id, "course_substitution", $course);
  206. }
  207. /**
  208. * Similar to the functions regarding display-- get the course substitution based on supplied degree_id.
  209. * Set degree_id to -1 to just get the first one, if available.
  210. */
  211. function get_course_substitution($degree_id = 0) {
  212. // If degree_id is zero, then use the course's currently req_by_degree_id.
  213. if ($degree_id == 0) $degree_id = $this->req_by_degree_id;
  214. if ($degree_id > 0) {
  215. //return $this->course_substitution_by_degree_array[$degree_id];
  216. return $this->get_details_by_degree($degree_id, "course_substitution");
  217. }
  218. else {
  219. //$x = reset($this->course_substitution_by_degree_array);
  220. if (isset($this->details_by_degree_array[$degree_id]["course_substitution"])) {
  221. $x = reset($this->details_by_degree_array[$degree_id]["course_substitution"]);
  222. if ($x) return $x;
  223. }
  224. }
  225. // Else, return boolean FALSE
  226. return FALSE;
  227. }
  228. /**
  229. * If the boolean is set, it means if the supplied degree_id isn't set, then use the first found value.
  230. */
  231. function get_hours_awarded($degree_id = 0, $bool_use_first_found_if_not_found_by_degree = TRUE) {
  232. // If degree_id is zero, then use the course's currently req_by_degree_id.
  233. if ($degree_id == 0) $degree_id = $this->req_by_degree_id;
  234. if ($degree_id > 0) {
  235. //return $this->course_substitution_by_degree_array[$degree_id];
  236. if (isset($this->details_by_degree_array[$degree_id]["hours_awarded"])) {
  237. $x = floatval($this->get_details_by_degree($degree_id, "hours_awarded")) * 1; // *1 forces numeric and trimes extra zeroes.
  238. }
  239. else if ($bool_use_first_found_if_not_found_by_degree) {
  240. // It wasn't set, so get the first value that WAS set.
  241. $x = floatval($this->get_first_value_from_any_degree("hours_awarded"));
  242. }
  243. if ($x) return $x;
  244. }
  245. else {
  246. // We just want the first value of ANY degree returned.
  247. $x = floatval($this->get_first_value_from_any_degree("hours_awarded"));
  248. if ($x) return $x;
  249. }
  250. // Else, return zero
  251. return 0;
  252. }
  253. /**
  254. * Goes through the details_by_degree array and returns the first
  255. * valid value for the supplied key, any degree., or return NULL if not found.
  256. */
  257. function get_first_value_from_any_degree($key) {
  258. foreach ($this->details_by_degree_array as $d => $v) {
  259. if (isset($v[$key])) return $v[$key];
  260. }
  261. // Found nothing, return null
  262. return NULL;
  263. }
  264. /**
  265. * Similar to the functions regarding display, these will say if this course has been used in a substitution
  266. * for a particular degree.
  267. */
  268. function get_bool_substitution($degree_id = 0) {
  269. // If degree_id is zero, then use the course's currently req_by_degree_id.
  270. if ($degree_id == 0) $degree_id = $this->req_by_degree_id;
  271. if ($degree_id > 0) {
  272. //return $this->bool_substitution_by_degree_array[$degree_id];
  273. return $this->get_details_by_degree($degree_id, "bool_substitution");
  274. }
  275. else {
  276. // has the course been substituted by ANY degree?
  277. if ($this->get_count_details_by_degree("bool_substitution", TRUE) > 0) {
  278. return TRUE;
  279. }
  280. }
  281. return FALSE;
  282. }
  283. /**
  284. * Return back a count from ANY degree for this property name.
  285. */
  286. function get_count_details_by_degree($property_name, $check_for_specific_value = NULL) {
  287. $c = 0;
  288. foreach ($this->details_by_degree_array as $degree_id => $temp) {
  289. if (isset($temp[$property_name])) {
  290. if ($check_for_specific_value !== NULL) {
  291. // We want to SKIP if this property does not have this specific value
  292. if ($temp[$property_name] !== $check_for_specific_value) continue;
  293. }
  294. $c++;
  295. }
  296. }
  297. return $c;
  298. }
  299. function set_bool_substitution($degree_id = 0, $val = TRUE) {
  300. // If degree_id is zero, then use the course's currently req_by_degree_id.
  301. if ($degree_id == 0) $degree_id = $this->req_by_degree_id;
  302. //$this->bool_substitution_by_degree_array[$degree_id] = $val;
  303. $this->set_details_by_degree($degree_id, "bool_substitution", $val);
  304. }
  305. /**
  306. * Returns TRUE or FALSE if this course has been displayed. Specify a degree_id to be more specific.
  307. * Use -1 to mean "ANY" degree?
  308. */
  309. function get_has_been_displayed($degree_id = 0) {
  310. // If degree_id is zero, then use the course's currently req_by_degree_id.
  311. if ($degree_id == 0) $degree_id = $this->req_by_degree_id;
  312. if ($degree_id > 0) {
  313. //return $this->bool_has_been_displayed_by_degree_array[$degree_id];
  314. return $this->get_details_by_degree($degree_id, "bool_has_been_displayed");
  315. }
  316. else {
  317. // has the course been displayed by ANY degree?
  318. if ($this->get_count_details_by_degree("bool_has_been_displayed", TRUE) > 0) {
  319. return TRUE;
  320. }
  321. }
  322. return FALSE;
  323. }
  324. /**
  325. * Counterpart to get_has_been_displayed.
  326. * @see get_has_been_displayed()
  327. */
  328. function set_has_been_displayed($degree_id = 0, $val = TRUE) {
  329. // If degree_id is zero, then use the course's currently req_by_degree_id.
  330. if ($degree_id == 0) $degree_id = $this->req_by_degree_id;
  331. //$this->bool_has_been_displayed_by_degree_array[$degree_id] = $val;
  332. $this->set_details_by_degree($degree_id, "bool_has_been_displayed", $val);
  333. }
  334. function set_bool_exclude_repeat($degree_id = 0, $val = TRUE) {
  335. // If degree_id is zero, then use the course's currently req_by_degree_id.
  336. if ($degree_id == 0) $degree_id = $this->req_by_degree_id;
  337. //$this->bool_has_been_displayed_by_degree_array[$degree_id] = $val;
  338. $this->set_details_by_degree($degree_id, "bool_exclude_repeat", $val);
  339. }
  340. /**
  341. * Returns TRUE or FALSE if this course has been marked as exclude_repeat. Specify a degree_id to be more specific.
  342. * Use -1 to mean "ANY" degree?
  343. */
  344. function get_bool_exclude_repeat($degree_id = 0) {
  345. // If degree_id is zero, then use the course's currently req_by_degree_id.
  346. if ($degree_id == 0) $degree_id = $this->req_by_degree_id;
  347. if ($degree_id > 0) {
  348. //return $this->bool_has_been_displayed_by_degree_array[$degree_id];
  349. return $this->get_details_by_degree($degree_id, "bool_exclude_repeat");
  350. }
  351. else {
  352. // has the course been displayed by ANY degree?
  353. if ($this->get_count_details_by_degree("bool_exclude_repeat", TRUE) > 0) {
  354. return TRUE;
  355. }
  356. }
  357. return FALSE;
  358. }
  359. /**
  360. * Convenience function to set a value into our details_by_degree_array.
  361. */
  362. function set_details_by_degree($degree_id, $key, $val) {
  363. $this->details_by_degree_array[$degree_id][$key] = $val;
  364. }
  365. /**
  366. * @see set_details_by_degree()
  367. */
  368. function get_details_by_degree($degree_id, $key) {
  369. return @$this->details_by_degree_array[$degree_id][$key];
  370. }
  371. /**
  372. * This function will create a "data string" of the course.
  373. * Think of it as a poor man's serialize. I can't actually use
  374. * serialize, as I have to call this for every course on the screen,
  375. * and the page load time was too long when using serialize, probably
  376. * because of all the extra fields which I did not need.
  377. *
  378. * The string returned will be used to send information about this
  379. * course to a popup window.
  380. *
  381. * Important details about the course are put into a particular order,
  382. * separated by commas. Booleans are converted to either 1 or 0.
  383. *
  384. * This function is the mirror of load_course_from_data_string().
  385. *
  386. * @return string
  387. */
  388. function to_data_string()
  389. {
  390. $rtn = "";
  391. $rtn .= $this->course_id . "~";
  392. $rtn .= $this->assigned_to_semester_num . "~";
  393. $rtn .= fp_join_assoc($this->assigned_to_group_ids_array) . "~";
  394. $rtn .= intval($this->bool_advised_to_take) . "~";
  395. $rtn .= $this->specified_repeats . "~";
  396. $rtn .= intval($this->bool_specified_repeat) . "~";
  397. $grd = $this->grade;
  398. if (strstr($grd, "+")) {
  399. $grd = str_replace("+", "_pls_", $grd);
  400. }
  401. $rtn .= $grd . "~";
  402. $rtn .= $this->get_hours_awarded() * 1 . "~";
  403. $rtn .= $this->term_id . "~";
  404. $rtn .= $this->advised_hours * 1 . "~";
  405. $rtn .= intval($this->bool_transfer) . "~";
  406. // If this is a transfer, then we will put in various information
  407. // about the original transfer course...
  408. if ($this->bool_transfer == true)
  409. {
  410. $rtn .= $this->course_transfer->course_id . "~";
  411. } else {
  412. // Just enter blank.
  413. $rtn .= "~";
  414. }
  415. $rtn .= intval($this->bool_added_course) . "~";
  416. $rtn .= $this->db_advised_courses_id . "~";
  417. $rtn .= $this->random_id . "~";
  418. $rtn .= fp_join_assoc($this->get_degree_details_data_string("bool_substitution")) . "~";
  419. // If this is a substitution, what is the original requirement?
  420. if ($this->get_bool_substitution(-1))
  421. {
  422. // Create a simple assoc array for our course substitutions, where all we need to keep track of
  423. // is their course_id, not the entire course object.
  424. $temp = $this->get_degree_details_data_string("course_substitution");
  425. $arr = array();
  426. foreach ($temp as $key => $c) {
  427. $arr[$key] = $c->course_id;
  428. }
  429. //$rtn .= $this->course_substitution->course_id . "," . $this->req_by_degree_id . "~";
  430. $rtn .= fp_join_assoc($arr) . "~";
  431. }
  432. else {
  433. // Just enter blank.
  434. $rtn .= "~";
  435. }
  436. ///////////////////
  437. $rtn .= fp_join_assoc($this->db_substitution_id_array) . "~";
  438. $rtn .= $this->min_hours * 1 . "~";
  439. $rtn .= $this->max_hours *1 . "~";
  440. //$rtn .= intval($this->get_bool_substitution_new_from_split()) . "~";
  441. $rtn .= fp_join_assoc($this->get_degree_details_data_string("bool_substitution_new_from_split")) . "~";
  442. //$rtn .= intval($this->get_bool_substitution_split()) . "~";
  443. $rtn .= fp_join_assoc($this->get_degree_details_data_string("bool_substitution_split")) . "~";
  444. // no longer used
  445. //$rtn .= intval($this->bool_has_been_assigned) . "~";
  446. $rtn .= "0~"; // temporary just to keep place. Should probably just be removed.
  447. $rtn .= $this->display_status . "~";
  448. $rtn .= intval($this->bool_ghost_hour) . "~";
  449. $rtn .= fp_join_assoc($this->assigned_to_degree_ids_array) . "~";
  450. $rtn .= $this->req_by_degree_id . "~";
  451. $rtn .= $this->disp_for_group_id . "~";
  452. $rtn .= $this->school_id . "~";
  453. $rtn .= $this->db_grade . "~";
  454. $rtn .= $this->extra_attribs . "~";
  455. return $rtn;
  456. }
  457. /**
  458. * Returns back an array from our details_by_degree array, for a given property name,
  459. * like: $arr[DEGREE_ID] = $val
  460. * Useful in the to_data_string function
  461. */
  462. function get_degree_details_data_string($property_name) {
  463. $arr = array();
  464. foreach ($this->details_by_degree_array as $degree_id => $temp) {
  465. if (isset($temp[$property_name])) {
  466. $arr[$degree_id] = $temp[$property_name];
  467. }
  468. }
  469. return $arr;
  470. }
  471. /**
  472. * This is the reverse function of:
  473. * @see get_degree_details_data_string
  474. */
  475. function set_degree_details_from_data_array($arr, $property_name) {
  476. foreach ($arr as $degree_id => $val) {
  477. $this->details_by_degree_array[$degree_id][$property_name] = $val;
  478. }
  479. }
  480. /**
  481. * This function uses load_course_from_data_string, but it removes any elements which might interfere with
  482. * the course object then being used as a requirement. This is used specifically by the FlightPath object,
  483. * when creating a clone of a repeatable course.
  484. */
  485. function load_course_from_data_string_for_requirement_clone($str) {
  486. // Begin by loading THIS course from the supplied data string.
  487. $this->load_course_from_data_string($str);
  488. // Now, let's overwrite the values we don't need, since this is to be used as
  489. // a course requirement.
  490. $this->random_id = $GLOBALS['fp_courses_random_ids']++;
  491. $this->set_hours_awarded(0, 0);
  492. $this->grade = "";
  493. $this->advised_hours = 0;
  494. $this->bool_added_course = FALSE;
  495. $this->db_advised_courses_id = 0;
  496. $this->details_by_degree_array = array();
  497. $this->assigned_to_degree_ids_array = array();
  498. $this->db_substitution_id_array = array();
  499. $this->display_status = "eligible"; // match the default constructor so we don't cause issues.
  500. $this->disp_for_group_id = "";
  501. }
  502. /**
  503. * This will take a data string, as created by
  504. * the function to_data_string(), and make $this object
  505. * match the original object. It is a poor man's
  506. * unserialize. See to_data_string()'s description for a fuller
  507. * picture of what is going on.
  508. *
  509. * To use:
  510. * - $newCourse = new Course();
  511. * - $newCourse->load_course_from_data_string($data);
  512. *
  513. *
  514. * @param string $str
  515. */
  516. function load_course_from_data_string($str)
  517. {
  518. $temp = explode("~",$str);
  519. $this->course_id = $temp[0];
  520. $this->load_course($this->course_id);
  521. $this->assigned_to_semester_num = $temp[1];
  522. $this->assigned_to_group_ids_array = fp_explode_assoc($temp[2]);
  523. $this->bool_advised_to_take = (bool) $temp[3];
  524. $this->specified_repeats = $temp[4];
  525. $this->bool_specified_repeat = (bool) $temp[5];
  526. $this->grade = $temp[6];
  527. if (strstr($this->grade, "_pls_")) {
  528. $this->grade = str_replace("_pls_", "+", $this->grade);
  529. }
  530. $this->set_hours_awarded(0,$temp[7] * 1); // *1 to force numeric, and trim extra zeros.
  531. $this->term_id = $temp[8];
  532. $this->advised_hours = $temp[9] * 1;
  533. $this->bool_transfer = (bool) $temp[10];
  534. // Was this a transfer course?
  535. if ($this->bool_transfer == true)
  536. {
  537. $t_course = new Course($temp[11], true);
  538. $t_course->term_id = $this->term_id;
  539. $this->course_transfer = $t_course;
  540. }
  541. $this->bool_added_course = (bool) $temp[12];
  542. $this->db_advised_courses_id = $temp[13];
  543. $this->random_id = $temp[14];
  544. //$this->bool_substitution_by_degree_array = fp_explode_assoc($temp[15]);
  545. $this->set_degree_details_from_data_array(fp_explode_assoc($temp[15]), "bool_substitution");
  546. // Was this a substitution course?
  547. if (trim($temp[16]) != "")
  548. {
  549. $arr = fp_explode_assoc($temp[16]);
  550. foreach ($arr as $did => $cid) {
  551. $t_course = new Course($cid); // original course requirement.
  552. $t_course->req_by_degree_id = $did;
  553. $this->set_course_substitution($did, $t_course);
  554. }
  555. /*
  556. $temp2 = explode(",", $temp[16]); // contains course_id,req_by_degree_id. Need to split the values up.
  557. $t_course = new Course($temp2[0]); // original course requirement.
  558. $t_course->req_by_degree_id = $temp2[1];
  559. $this->course_substitution = $t_course;
  560. */
  561. }
  562. $this->db_substitution_id_array = fp_explode_assoc($temp[17]);
  563. $this->min_hours = $temp[18] * 1;
  564. $this->max_hours = $temp[19] * 1;
  565. //$this->bool_substitution_new_from_split = (bool) $temp[20];
  566. $this->set_degree_details_from_data_array(fp_explode_assoc($temp[20]), "bool_substitution_new_from_split");
  567. //$this->bool_substitution_split = (bool) $temp[21];
  568. $this->set_degree_details_from_data_array(fp_explode_assoc($temp[21]), "bool_substitution_split");
  569. // No longer used. Using assigned_to_degree_ids instead.
  570. //$this->bool_has_been_assigned = (bool) $temp[22];
  571. $throw_away = $temp[22]; // throw-away value. Can probably just remove entirely.
  572. $this->display_status = $temp[23];
  573. $this->bool_ghost_hour = (bool) $temp[24];
  574. $this->assigned_to_degree_ids_array = fp_explode_assoc($temp[25]);
  575. $this->req_by_degree_id = intval($temp[26]);
  576. $this->disp_for_group_id = trim($temp[27]);
  577. $this->school_id = trim($temp[28]);
  578. $this->db_grade = trim($temp[29]);
  579. $this->extra_attribs = trim($temp[30]);
  580. }
  581. /**
  582. * This function will return a CSV string of all the possible
  583. * names for this course, in alphabetical order.
  584. *
  585. * This function is used by DataEntry primarily.
  586. *
  587. * @param bool $bool_add_white_space
  588. * @param bool $bool_add_exclude
  589. * @return string
  590. */
  591. function get_all_names($bool_add_white_space = false, $bool_add_exclude = true)
  592. {
  593. $rtn = "";
  594. $used_array = array();
  595. $table_name = "courses";
  596. if ($this->bool_use_draft) {$table_name = "draft_$table_name";}
  597. // took out: and `catalog_year`='$this->catalog_year'
  598. // because we don't care what catalog year it comes from...
  599. $res = $this->db->db_query("SELECT * FROM $table_name
  600. WHERE course_id = ?
  601. AND delete_flag = '0'
  602. ORDER BY subject_id, course_num ", $this->course_id);
  603. while($cur = $this->db->db_fetch_array($res))
  604. {
  605. if (in_array($cur["subject_id"] . "~" . $cur["course_num"], $used_array))
  606. { // skip ones we have already seen.
  607. continue;
  608. }
  609. $used_array[] = $cur["subject_id"] . "~" . $cur["course_num"];
  610. $rtn .= $cur["subject_id"] . " " . $cur["course_num"];
  611. if ($cur["exclude"] != '0' && $bool_add_exclude == true)
  612. {
  613. $rtn .= " exclude";
  614. }
  615. $rtn .= ",";
  616. if ($bool_add_white_space == true)
  617. {
  618. $rtn .= " ";
  619. }
  620. }
  621. $rtn = trim($rtn);
  622. // remove last comma.
  623. $rtn = substr($rtn,0,-1);
  624. return $rtn;
  625. }
  626. /**
  627. * The function returns either an integer of the the number of
  628. * hours the course is worth, or, a range in the form of
  629. * min-max (if the course has variable hours)
  630. *
  631. * Examples: 3 or 1-6
  632. *
  633. * @return string
  634. */
  635. function get_catalog_hours()
  636. {
  637. if (!$this->has_variable_hours())
  638. {
  639. // Normal course, no var hours.
  640. $h = $this->min_hours * 1;
  641. // check for ghost hours.
  642. if ($this->bool_ghost_min_hour) {
  643. $h = 0;
  644. }
  645. return $h;
  646. } else {
  647. // Meaning this does course have variable hours.
  648. $min_h = $this->min_hours*1;
  649. $max_h = $this->max_hours*1;
  650. // Convert back from ghosthours.
  651. if ($this->bool_ghost_min_hour) {
  652. $min_h = 0;
  653. }
  654. if ($this->bool_ghost_hour) {
  655. $max_h = 0;
  656. }
  657. return "$min_h-$max_h";
  658. }
  659. }
  660. /**
  661. * Returns how many hours this course has been advised for.
  662. * This is used with courses which have variable hours. If
  663. * the course has not been advised for any particular number
  664. * of hours, then it's min_hours are returned.
  665. *
  666. * @return unknown
  667. */
  668. function get_advised_hours()
  669. {
  670. if ($this->advised_hours > -1)
  671. {
  672. return $this->advised_hours * 1;
  673. } else {
  674. // No, the user has not selected any hours yet. So,
  675. // just display the min_hours.
  676. // Correct for ghost hours, if any.
  677. $min_h = $this->min_hours * 1;
  678. if ($this->bool_ghost_min_hour) {
  679. $min_h = 0;
  680. }
  681. return $min_h;
  682. }
  683. }
  684. /**
  685. * This will assign the $this->display_status string
  686. * based on the grade the student has made on the course.
  687. * The display_status is used by other display functions to decide
  688. * what color the course should show up as.
  689. *
  690. */
  691. function assign_display_status()
  692. {
  693. // Assigns the display status, based on grade.
  694. $grade = $this->grade;
  695. // Get these grade definitions from our system settings
  696. // Configure them in custom/settings.php
  697. $retake_grades = csv_to_array(variable_get_for_school("retake_grades", 'F,W,I', $this->school_id));
  698. $enrolled_grades = csv_to_array(variable_get_for_school("enrolled_grades",'E', $this->school_id));
  699. if (in_array($grade, $retake_grades))
  700. {
  701. $this->display_status = "retake";
  702. }
  703. if (in_array($grade, $enrolled_grades))
  704. {
  705. $this->display_status = "enrolled";
  706. }
  707. }
  708. /**
  709. * Returns TRUE if the student has completed the course
  710. * (and did not make a failing grade on it).
  711. *
  712. *
  713. *
  714. * @return bool
  715. */
  716. function is_completed()
  717. {
  718. // returns true if the course has been completed.
  719. $grade = $this->grade;
  720. // Get these grade definitions from our system settings
  721. // Configure them in custom/settings.php
  722. $retake_grades = csv_to_array(variable_get_for_school("retake_grades", 'F,W,I', $this->school_id));
  723. $enrolled_grades = csv_to_array(variable_get_for_school("enrolled_grades",'E', $this->school_id));
  724. if ($grade == "") {
  725. return false;
  726. }
  727. if (in_array($grade, $enrolled_grades)) {
  728. return false;
  729. }
  730. if (in_array($grade, $retake_grades)) {
  731. return false;
  732. }
  733. return true;
  734. }
  735. /**
  736. * Does $this meed the minimum grade requirement of the
  737. * supplied course requirement? You may specify either
  738. * a Course object, or just enter the min_grade in the mGrade
  739. * variable.
  740. *
  741. * @param Course $course_req
  742. * - The Course object who has the min grade requirement.
  743. * Set to NULL if using $m_grade.
  744. *
  745. * @param string $m_grade
  746. * - The min grade which $this must meet. Do not use if using
  747. * $course_req.
  748. *
  749. * @return bool
  750. */
  751. function meets_min_grade_requirement_of(Course $course_req = NULL, $m_grade = "")
  752. {
  753. // Does $this course meet the min grade requirement
  754. // of the supplied course requirement?
  755. // Get these grade definitions from our system settings
  756. // Configure them in custom/settings.php
  757. $enrolled_grades = csv_to_array(variable_get_for_school("enrolled_grades", 'E', $this->school_id));
  758. if ($course_req != null) {
  759. $min_grade = $course_req->min_grade;
  760. } else {
  761. $min_grade = $m_grade;
  762. }
  763. if ($min_grade == "")
  764. { // There is no min grade requirement for this course.
  765. return true;
  766. }
  767. // If the student is currently enrolled, return true.
  768. if (in_array($this->grade, $enrolled_grades))
  769. {
  770. return true;
  771. }
  772. // Okay, let's check those min grade requirements...
  773. $grade_order = csv_to_array(strtoupper(variable_get_for_school("grade_order", "E,AMID,BMID,CMID,DMID,FMID,A,B,C,D,F,W,I", $this->school_id)));
  774. // Make it so the indexes are the grades, their numeric values are values.
  775. $grade_order = array_flip($grade_order);
  776. // Get the "weight" of the min_grade_requirement, and $this->grade
  777. $req_weight = intval(@$grade_order[$min_grade]);
  778. $this_weight = intval(@$grade_order[$this->grade]);
  779. if ($this_weight <= $req_weight) return TRUE; // yay, we have the min grade!
  780. return false;
  781. }
  782. /**
  783. * Simply returns TRUE if $this has variable hours.
  784. *
  785. * @return bool
  786. */
  787. function has_variable_hours()
  788. {
  789. $min_h = $this->min_hours;
  790. $max_h = $this->max_hours;
  791. // Convert back from ghosthours, for the comparison.
  792. if ($this->bool_ghost_min_hour) {
  793. $min_h = 0;
  794. }
  795. if ($this->bool_ghost_hour) {
  796. $max_h = 0;
  797. }
  798. if ($min_h == $max_h)
  799. {
  800. return false;
  801. } else {
  802. return true;
  803. }
  804. }
  805. /**
  806. * Figure out the number of hours this particular
  807. * instance of the course is worth. In the case
  808. * of variable hours, it will return the number
  809. * of hours selected. If that does not exist,
  810. * it will return the MIN HOURS.
  811. *
  812. * @return int
  813. */
  814. function get_hours($degree_id = 0)
  815. {
  816. if ($degree_id == 0) $degree_id = $this->req_by_degree_id;
  817. // This course might be set to 1 hour, but be a "ghost hour",
  818. // meaning the student actually earned 0 hours, but we recorded 1
  819. // to make FP's math work out. So, let's return back 0 hours.
  820. if ($this->bool_ghost_hour)
  821. {
  822. $h = 0;
  823. return $h;
  824. }
  825. // Was this course used in a substitution? If so, use the substitution hours.
  826. if ($this->get_substitution_hours($degree_id) > 0) {
  827. return floatval($this->get_substitution_hours($degree_id));
  828. }
  829. // Do they have any hours_awarded? (because they completed
  830. // the course)
  831. if ($this->get_hours_awarded($degree_id) > 0)
  832. {
  833. $h = $this->get_hours_awarded($degree_id);
  834. return floatval($h);
  835. }
  836. if ($this->has_variable_hours() && $this->advised_hours > -1) {
  837. return floatval($this->advised_hours);
  838. }
  839. // No selected hours, but it's a variable hour course.
  840. // So, return the min_hours for this course.
  841. return floatval($this->min_hours);
  842. }
  843. /**
  844. * Calculate the quality points for this course's grade and hours.
  845. *
  846. * @param string $grade
  847. * @param int $hours
  848. * @return int
  849. */
  850. function get_quality_points($degree_id = 0){
  851. $hours = $this->get_hours($degree_id);
  852. $grade = $this->grade;
  853. $pts = 0;
  854. $qpts_grades = array();
  855. // Let's find out what our quality point grades & values are...
  856. if (isset($GLOBALS["qpts_grades"])) {
  857. // have we already cached this?
  858. $qpts_grades = $GLOBALS["qpts_grades"];
  859. }
  860. else {
  861. $tlines = explode("\n", variable_get_for_school("quality_points_grades", "A ~ 4\nB ~ 3\nC ~ 2\nD ~ 1\nF ~ 0\nI ~ 0", $this->school_id));
  862. foreach ($tlines as $tline) {
  863. $temp = explode("~", trim($tline));
  864. if (trim($temp[0]) != "") {
  865. $qpts_grades[trim($temp[0])] = trim($temp[1]);
  866. }
  867. }
  868. $GLOBALS["qpts_grades"] = $qpts_grades; // save to cache
  869. }
  870. // Okay, find out what the points are by multiplying value * hours...
  871. if (isset($qpts_grades[$grade])) {
  872. $pts = $qpts_grades[$grade] * $hours;
  873. }
  874. return $pts;
  875. }
  876. /**
  877. * This function is used for comparing a course name to the subject_id
  878. * and course_num of $this.
  879. * We expect a space between the subject_id and CourseNum in $str.
  880. *
  881. * For example: MATH 1010
  882. *
  883. * You may also ONLY specify a subject, ex: BIOL. If you do that,
  884. * then only the subject will be compared.
  885. *
  886. * Example of use: if ($c->name_equals("ART 101")) then do this etc.
  887. *
  888. * @param string $str
  889. * @return bool
  890. */
  891. function name_equals($str)
  892. {
  893. // We expect the str to be given to us
  894. // with a space b/t the subject_id and course_num.
  895. // ex: MATH 111
  896. // may also ONLY specify the subject. ex: BIOL
  897. // If our $subject_id is not populated, then call load_descriptive_data()
  898. if ($this->subject_id == "") {
  899. $this->load_descriptive_data();
  900. }
  901. // TODO: We should check ALL names for this course. Use get_all_names to do that.
  902. $temp = explode(" ",$str);
  903. if ($this->subject_id == $temp[0] && ($this->course_num == $temp[1] || trim($temp[1]) == ""))
  904. {
  905. return TRUE;
  906. }
  907. return FALSE;
  908. }
  909. /**
  910. * Convienience function. Simply compare the course_id of
  911. * another course to $this to see if they are equal.
  912. *
  913. * This is also used by CourseList and ObjList to determine
  914. * matches.
  915. *
  916. * Usage: if ($newCourse.equals($otherCourse)) { ... }
  917. *
  918. * @param Course $course_c
  919. * @return bool
  920. */
  921. function equals(Course $course_c = null)
  922. {
  923. if ($course_c != null && $this->course_id == $course_c->course_id)
  924. {
  925. return true;
  926. }
  927. return false;
  928. }
  929. /**
  930. * Loads $this as a new course, based on course_id.
  931. *
  932. * @param int $course_id
  933. * @param bool $is_transfer
  934. */
  935. function load_course($course_id, $is_transfer = false)
  936. {
  937. if ($this->db == NULL)
  938. {
  939. $this->db = get_global_database_handler();
  940. }
  941. $catalog_line = "";
  942. if ($this->catalog_year != "") {
  943. $catalog_line = " AND catalog_year = '$this->catalog_year' ";
  944. }
  945. if ($is_transfer == false) {
  946. $this->load_descriptive_data();
  947. }
  948. else {
  949. // This is a transfer course.
  950. $res = $this->db->db_query("SELECT * FROM
  951. transfer_courses a,
  952. transfer_institutions b
  953. WHERE
  954. a.transfer_course_id = '?'
  955. AND a.institution_id = b.institution_id ", $course_id);
  956. $cur = $this->db->db_fetch_array($res);
  957. $this->subject_id = $cur["subject_id"];
  958. $this->course_num = $cur["course_num"];
  959. $this->course_id = $course_id;
  960. $this->school_id = $cur['school_id'];
  961. $this->bool_transfer = true;
  962. $this->institution_id = $cur["institution_id"];
  963. $this->institution_name = $cur["name"];
  964. }
  965. $this->assign_display_status();
  966. // When we load this course, let's also check for any hooks.
  967. // Since this class might be used outside of FP, only do this if we know
  968. // that the bootstrap.inc file has been executed.
  969. if ($GLOBALS["fp_bootstrap_loaded"] == TRUE) {
  970. invoke_hook("course_load", array(&$this));
  971. }
  972. } // load_course
  973. /**
  974. * This function will correct capitalization problems in course titles.
  975. *
  976. * @param string $str
  977. *
  978. * @return string
  979. *
  980. */
  981. function fix_title($str = "")
  982. {
  983. if ($str == "")
  984. {
  985. $str = $this->title;
  986. }
  987. // Should we do this at all? We will look at the "autocapitalize_course_titles" setting.
  988. $auto = variable_get_for_school("autocapitalize_course_titles", 'yes', $this->school_id);
  989. if ($auto == "no") {
  990. // Nope! Just return.
  991. $this->title = $str;
  992. return $str;
  993. }
  994. // Otherwise, we may continue with the capitalization scheme:
  995. $str = str_replace("/", " / ", $str);
  996. $str = str_replace("/", " / ", $str);
  997. $str = str_replace("-", " - ", $str);
  998. $str = str_replace(":", ": ", $str);
  999. $str = str_replace("(", "( ", $str);
  1000. // Only pad an ampersand if we are not talking about
  1001. // an HTML character.
  1002. if (!strstr($str,"&#"))
  1003. {
  1004. $str = str_replace("&", " & ", $str);
  1005. }
  1006. // Let's also get rid of extra spaces.
  1007. $str = str_replace(" ", " ", $str);
  1008. $str = str_replace(" ", " ", $str);
  1009. // convert to ucwords and fix some problems introduced by that.
  1010. $str = trim(ucwords(strtolower($str)));
  1011. $str = str_replace("Iii", "III", $str);
  1012. $str = str_replace("Ii", "II", $str);
  1013. $str = str_replace(" Iv"," IV",$str);
  1014. $str = str_replace(" Vi"," VI",$str);
  1015. $str = str_replace(" Of "," of ",$str);
  1016. $str = str_replace(" The "," the ",$str);
  1017. $str = str_replace(" In "," in ",$str);
  1018. $str = str_replace(" And "," and ",$str);
  1019. $str = str_replace(" An "," an ",$str);
  1020. $str = str_replace(" A "," a ",$str);
  1021. $str = str_replace(" To "," to ",$str);
  1022. $str = str_replace(" For "," for ",$str);
  1023. // Strange words and abreviations which should be changed.
  1024. $str = str_replace("Afrotc","AFROTC",$str);
  1025. $str = str_replace("Gis","GIS",$str);
  1026. $str = str_replace("Dna","DNA",$str);
  1027. $str = str_replace(" Cpr","CPR",$str);
  1028. $str = str_replace(" Rn"," RN",$str);
  1029. $str = str_replace(" Micu"," MICU",$str);
  1030. $str = str_replace(" Sicu"," SICU",$str);
  1031. $str = str_replace(" Picu"," PICU",$str);
  1032. $str = str_replace(" Nicu"," NICU",$str);
  1033. $str = str_replace("Uas ","UAS ",$str);
  1034. $str = str_replace(" Uas"," UAS",$str);
  1035. // Cleanup
  1036. $str = str_replace("( ", "(", $str);
  1037. $str = str_replace(" - ", "-", $str);
  1038. // Is this just a course name by itself? If so, it should
  1039. // all be capitalized.
  1040. $temp = explode(" ", $str);
  1041. if (count($temp) == 2
  1042. && strlen($temp[0]) <= 4
  1043. && strlen($temp[1]) <= 4)
  1044. {// We could also test to see if there are numbers starting the
  1045. // second token.
  1046. $str = strtoupper($str);
  1047. }
  1048. // If this contains the word "formerly" then we need to pull out what's
  1049. // there and make it all uppercase, except for the word Formerly.
  1050. if (strstr(strtolower($str), strtolower("formerly ")))
  1051. {
  1052. $formline = preg_replace("/.*\((formerly .*)\).*/i", "$1", $str);
  1053. $str = str_replace($formline, strtoupper($formline), $str);
  1054. $str = str_replace("FORMERLY ", "Formerly ", $str);
  1055. }
  1056. $this->title = $str;
  1057. return $str;
  1058. }
  1059. /**
  1060. * This function will load $this will all sorts of descriptive data
  1061. * from the database. For example, hours, title, description, etc.
  1062. *
  1063. * It must be called before any attempts at sorting (by alphabetical order)
  1064. * are made on lists of courses.
  1065. *
  1066. * It will by default try to load this information from cache. If it cannot
  1067. * find it in the cache, it will query the database, and then add what it finds
  1068. * to the cache.
  1069. *
  1070. *
  1071. * @param bool $bool_load_from_global_cache
  1072. * - If set to TRUE, this will attempt to load the course data
  1073. * from the "global cache", that is, the cache which is held in the
  1074. * GLOBALS array. This should usually be set to TRUE, since this is
  1075. * much faster than querying the database.
  1076. *
  1077. * @param bool $bool_ignore_catalog_year_in_cache
  1078. * - If set to TRUE, we will grab whatever is in the cache for this
  1079. * course's course_id, regardless of if the catalog years match.
  1080. * If set to FALSE, we will try to match the course's catalog year
  1081. * in the cache as well.
  1082. *
  1083. * @param bool $bool_limit_current_catalog_year
  1084. * - If set to TRUE, then we will only *query* for the course's
  1085. * catalog_year in the db, and those before it (if we do not find
  1086. * the exact catalog_year). We will not look for any catalog years
  1087. * after it. If set to FALSE, we will look through any
  1088. * valid catalog year.
  1089. *
  1090. * @param bool $bool_force_catalog_year
  1091. * - If set to TRUE, we will only look for the course's catalog
  1092. * year in the database.
  1093. *
  1094. * @param bool $bool_ignore_exclude
  1095. * - If set to TRUE, we will ignore courses marked as "exclude" in the
  1096. * database.
  1097. *
  1098. */
  1099. function load_descriptive_data($bool_load_from_global_cache = true, $bool_ignore_catalog_year_in_cache = true, $bool_limit_current_catalog_year = true, $bool_force_catalog_year = false, $bool_ignore_exclude = false, $bool_reset_ghost_hours = TRUE)
  1100. {
  1101. if ($this->db == null)
  1102. {
  1103. $this->db = get_global_database_handler();
  1104. }
  1105. $db = $this->db;
  1106. if ($this->catalog_year == "")
  1107. {
  1108. $this->catalog_year = variable_get_for_school("current_catalog_year", 2006, $this->school_id); // current catalog_year.
  1109. }
  1110. $setting_current_catalog_year = variable_get_for_school("current_catalog_year", 2006, $this->school_id) * 1;
  1111. if ($this->bool_use_draft) {
  1112. $setting_current_catalog_year = variable_get_for_school("current_draft_catalog_year", 2006, $this->school_id) * 1;
  1113. }
  1114. $earliest_catalog_year = variable_get_for_school("earliest_catalog_year", 2006, $this->school_id);
  1115. if ($setting_current_catalog_year < $earliest_catalog_year)
  1116. { // If it has not been set, assume the default.
  1117. $setting_current_catalog_year = $earliest_catalog_year;
  1118. }
  1119. if ($bool_limit_current_catalog_year == true && $setting_current_catalog_year > $earliest_catalog_year)
  1120. {
  1121. if ($this->catalog_year*1 > $setting_current_catalog_year)
  1122. {
  1123. $this->catalog_year = $setting_current_catalog_year; // current catalog_year.
  1124. }
  1125. }
  1126. if ($this->catalog_year < $earliest_catalog_year && $this->catalog_year != 1900)
  1127. {
  1128. // Out of range, so set to default
  1129. $this->catalog_year = $earliest_catalog_year;
  1130. }
  1131. $cat_line = "";
  1132. if ($bool_force_catalog_year == true)
  1133. {
  1134. $cat_line = " AND catalog_year = '$this->catalog_year' ";
  1135. }
  1136. $cache_catalog_year = $this->catalog_year;
  1137. if ($bool_ignore_catalog_year_in_cache == true)
  1138. {
  1139. $cache_catalog_year = 0;
  1140. }
  1141. if (!isset($this->array_valid_names))
  1142. {
  1143. $this->array_valid_names = array();
  1144. }
  1145. // First-- is this course in our GLOBALS cache for courses?
  1146. // If it is, then load from that.
  1147. if ($bool_load_from_global_cache == true && $this->course_id != 0 &&
  1148. @$GLOBALS["fp_course_inventory"][$this->course_id][$cache_catalog_year]["subject_id"] != "")
  1149. {
  1150. $this->subject_id = $GLOBALS["fp_course_inventory"][$this->course_id][$cache_catalog_year]["subject_id"];
  1151. $this->course_num = $GLOBALS["fp_course_inventory"][$this->course_id][$cache_catalog_year]["course_num"];
  1152. $this->title = $GLOBALS["fp_course_inventory"][$this->course_id][$cache_catalog_year]["title"];
  1153. $this->description = $GLOBALS["fp_course_inventory"][$this->course_id][$cache_catalog_year]["description"];
  1154. $this->min_hours = $GLOBALS["fp_course_inventory"][$this->course_id][$cache_catalog_year]["min_hours"];
  1155. $this->school_id = $GLOBALS["fp_course_inventory"][$this->course_id][$cache_catalog_year]["school_id"];
  1156. if ($bool_reset_ghost_hours) {
  1157. // Reset the ghosthours to default.
  1158. $this->bool_ghost_hour = $this->bool_ghost_min_hour = FALSE;
  1159. }
  1160. if ($this->min_hours <= 0) {
  1161. $this->min_hours = 1;
  1162. if ($bool_reset_ghost_hours) {
  1163. $this->bool_ghost_min_hour = TRUE;
  1164. }
  1165. }
  1166. $this->max_hours = $GLOBALS["fp_course_inventory"][$this->course_id][$cache_catalog_year]["max_hours"];
  1167. if ($this->max_hours <= 0) {
  1168. $this->max_hours = 1;
  1169. if ($bool_reset_ghost_hours) {
  1170. $this->bool_ghost_hour = TRUE;
  1171. }
  1172. }
  1173. $this->repeat_hours = $GLOBALS["fp_course_inventory"][$this->course_id][$cache_catalog_year]["repeat_hours"];
  1174. $this->db_exclude = $GLOBALS["fp_course_inventory"][$this->course_id][$cache_catalog_year]["db_exclude"];
  1175. $this->array_valid_names = $GLOBALS["fp_course_inventory"][$this->course_id][$cache_catalog_year]["array_valid_names"];
  1176. return;
  1177. }
  1178. if ($this->course_id != 0)
  1179. {
  1180. $exclude_line = " AND exclude = '0' ";
  1181. if ($bool_ignore_exclude) {
  1182. $exclude_line = "";
  1183. }
  1184. $table_name = "courses";
  1185. if ($this->bool_use_draft) {$table_name = "draft_$table_name";}
  1186. $res = $this->db->db_query("SELECT * FROM $table_name
  1187. WHERE course_id = ?
  1188. AND catalog_year = ?
  1189. AND delete_flag = 0
  1190. $exclude_line ", $this->course_id, $this->catalog_year);
  1191. $cur = $this->db->db_fetch_array($res);
  1192. if ($this->db->db_num_rows($res) < 1)
  1193. {
  1194. // No results found, so instead pick the most recent
  1195. // entry.
  1196. $table_name = "courses";
  1197. if ($this->bool_use_draft) {$table_name = "draft_$table_name";}
  1198. $res2 = $db->db_query("SELECT * FROM $table_name
  1199. WHERE course_id = ?
  1200. AND subject_id != ''
  1201. AND delete_flag = 0
  1202. $exclude_line
  1203. AND catalog_year <= '$setting_current_catalog_year'
  1204. $cat_line
  1205. ORDER BY `catalog_year` DESC LIMIT 1", $this->course_id);
  1206. $cur = $db->db_fetch_array($res2);
  1207. if ($db->db_num_rows($res2) < 1)
  1208. {
  1209. // Meaning, there were no results found that didn't have
  1210. // the exclude flag set.
  1211. // So, try to retrieve any course, even if it has
  1212. // been excluded (but within our catalog year range)
  1213. //$db3 = new DatabaseHandler();
  1214. $table_name = "courses";
  1215. if ($this->bool_use_draft) {$table_name = "draft_$table_name";}
  1216. $res3 = $db->db_query("SELECT * FROM $table_name
  1217. WHERE course_id = ?
  1218. AND subject_id != ''
  1219. AND delete_flag = 0
  1220. AND catalog_year <= '$setting_current_catalog_year'
  1221. $cat_line
  1222. ORDER BY `catalog_year` DESC LIMIT 1", $this->course_id);
  1223. $cur = $db->db_fetch_array($res3);
  1224. }
  1225. }
  1226. $this->title = $this->fix_title($cur["title"]);
  1227. $this->description = trim($cur["description"]);
  1228. $this->subject_id = trim(strtoupper($cur["subject_id"]));
  1229. $this->course_num = trim(strtoupper($cur["course_num"]));
  1230. $this->school_id = intval($cur["school_id"]);
  1231. $this->min_hours = $cur["min_hours"] * 1; //*1 will trim extra zeros from end of decimals
  1232. $this->max_hours = $cur["max_hours"] * 1;
  1233. if ($bool_reset_ghost_hours) {
  1234. // Reset the ghosthours to default.
  1235. $this->bool_ghost_hour = $this->bool_ghost_min_hour = FALSE;
  1236. }
  1237. if ($this->min_hours <= 0) {
  1238. $this->min_hours = 1;
  1239. if ($bool_reset_ghost_hours) {
  1240. $this->bool_ghost_min_hour = TRUE;
  1241. }
  1242. }
  1243. if ($this->max_hours <= 0) {
  1244. $this->max_hours = 1;
  1245. if ($bool_reset_ghost_hours) {
  1246. $this->bool_ghost_hour = TRUE;
  1247. }
  1248. }
  1249. $this->repeat_hours = $cur["repeat_hours"] * 1;
  1250. if ($this->repeat_hours <= 0)
  1251. {
  1252. $this->repeat_hours = $this->max_hours;
  1253. }
  1254. $this->db_exclude = $cur["exclude"];
  1255. $this->data_entry_comment = $cur["data_entry_comment"];
  1256. // Now, lets get a list of all the valid names for this course.
  1257. // In other words, all the non-excluded names. For most
  1258. // courses, this will just be one name. But for cross-listed
  1259. // courses, this will be 2 or more (probably just 2 though).
  1260. // Example: MATH 373 and CSCI 373 are both valid names for that course.
  1261. $table_name = "courses";
  1262. if ($this->bool_use_draft) {$table_name = "draft_$table_name";}
  1263. $res = $this->db->db_query("SELECT * FROM $table_name
  1264. WHERE course_id = ?
  1265. AND exclude = 0 ", $this->course_id);
  1266. while($cur = $this->db->db_fetch_array($res))
  1267. {
  1268. $si = $cur["subject_id"];
  1269. $cn = $cur["course_num"];
  1270. if (in_array("$si~$cn", $this->array_valid_names))
  1271. {
  1272. continue;
  1273. }
  1274. $this->array_valid_names[] = "$si~$cn";
  1275. }
  1276. } else if ($this->bool_transfer == true)
  1277. {
  1278. // This is a transfer credit which did not have a local
  1279. // course eqv. At the moment, the subject_id and
  1280. // course_num are empty. So, let's fill them in with the
  1281. // transfer credit's information.
  1282. if ($this->course_transfer != null)
  1283. {
  1284. $this->subject_id = $this->course_transfer->subject_id;
  1285. $this->course_num = $this->course_transfer->course_num;
  1286. if ($this->course_transfer->get_hours_awarded() > 0)
  1287. {
  1288. $this->set_hours_awarded(0, $this->course_transfer->get_hours_awarded());
  1289. }
  1290. }
  1291. }
  1292. if ($this->description == "")
  1293. {
  1294. $this->description = "There is no course description available at this time.";
  1295. }
  1296. if ($this->title == "")
  1297. {
  1298. $this->title = "$this->subject_id $this->course_num";
  1299. }
  1300. // Now, to reduce the number of database calls in the future, save this
  1301. // to our GLOBALS cache...
  1302. // We do need to go back and correct the ghost hours, setting them
  1303. // back to 0 hrs, or else this will be a problem.
  1304. $min_hours = $this->min_hours;
  1305. $max_hours = $this->max_hours;
  1306. if ($bool_reset_ghost_hours) {
  1307. if ($this->bool_ghost_min_hour) $min_hours = 0;
  1308. if ($this->bool_ghost_hour) $max_hours = 0;
  1309. }
  1310. // Since we may have trouble characters in the description (like smart quotes) let's
  1311. // do our best to try to clean it up a little.
  1312. $this->description = utf8_encode($this->description);
  1313. $GLOBALS["fp_course_inventory"][$this->course_id][$cache_catalog_year]["subject_id"] = $this->subject_id;
  1314. $GLOBALS["fp_course_inventory"][$this->course_id][$cache_catalog_year]["course_num"] = $this->course_num;
  1315. $GLOBALS["fp_course_inventory"][$this->course_id][$cache_catalog_year]["title"] = $this->title;
  1316. $GLOBALS["fp_course_inventory"][$this->course_id][$cache_catalog_year]["description"] = $this->description;
  1317. $GLOBALS["fp_course_inventory"][$this->course_id][$cache_catalog_year]["school_id"] = $this->school_id;
  1318. $GLOBALS["fp_course_inventory"][$this->course_id][$cache_catalog_year]["min_hours"] = $min_hours;
  1319. $GLOBALS["fp_course_inventory"][$this->course_id][$cache_catalog_year]["max_hours"] = $max_hours;
  1320. $GLOBALS["fp_course_inventory"][$this->course_id][$cache_catalog_year]["repeat_hours"] = $this->repeat_hours;
  1321. $GLOBALS["fp_course_inventory"][$this->course_id][$cache_catalog_year]["db_exclude"] = $this->db_exclude;
  1322. $GLOBALS["fp_course_inventory"][$this->course_id][$cache_catalog_year]["array_valid_names"] = $this->array_valid_names;
  1323. $GLOBALS["cache_course_inventory"] = true; // rebuild this cache before it closes.
  1324. }
  1325. /**
  1326. * Similar to load_descriptive_data(), this will load whatever we have
  1327. * for $this transfer course.
  1328. *
  1329. * @param int $student_id
  1330. * - If > 0, we will look for the course data which has been
  1331. * assigned for this particular student. If it == 0, we will
  1332. * just use the first bit of data we find.
  1333. *
  1334. */
  1335. function load_descriptive_transfer_data($student_id = "", $term_id = NULL)
  1336. {
  1337. // This method should be called to load transfer course data
  1338. // into THIS object. It assumes that $this->course_id is a transfer
  1339. // course's ID, which can be looked up in flightpath.transfer_courses.
  1340. // If a student_id is specified, it will load eqv information.
  1341. if ($this->db == null)
  1342. {
  1343. $this->db = get_global_database_handler();
  1344. }
  1345. $res = $this->db->db_query("SELECT * FROM transfer_courses
  1346. WHERE transfer_course_id = ? ", $this->course_id);
  1347. $cur = $this->db->db_fetch_array($res);
  1348. $this->subject_id = $cur["subject_id"];
  1349. $this->course_num = $cur['course_num'];
  1350. $this->title = $this->fix_title($cur['title']);
  1351. $this->min_hours = $cur["min_hours"] * 1;
  1352. $this->max_hours = $cur["max_hours"] * 1;
  1353. $this->institution_id = $cur["institution_id"];
  1354. $this->school_id = intval($cur['school_id']);
  1355. // Try to figure out the institution name for this course...
  1356. $this->institution_name = $this->db->get_institution_name($this->institution_id);
  1357. if ($student_id != "")
  1358. {
  1359. // Because transfer credit titles may differ from student
  1360. // to student, let's look up the title in the per-student transfer courses table...
  1361. $res = $this->db->db_query("SELECT * FROM student_transfer_courses
  1362. WHERE student_id = ?
  1363. AND transfer_course_id = ?
  1364. ", $student_id, $this->course_id);
  1365. $cur = $this->db->db_fetch_array($res);
  1366. if ($cur) {
  1367. if (trim(@$cur["student_specific_course_title"]) != "") {
  1368. $this->title = trim($cur["student_specific_course_title"]);
  1369. }
  1370. // Also assign hours_awarded and other values while we are here
  1371. $this->set_hours_awarded(0, floatval($cur["hours_awarded"]));
  1372. $this->grade = $cur["grade"];
  1373. $this->term_id = $cur["term_id"];
  1374. ///////////////////
  1375. // If a term_id was specified, then let's try to see if we can get more specific information for this course.
  1376. if ($term_id != NULL) {
  1377. $res = $this->db->db_query("SELECT * FROM student_transfer_courses
  1378. WHERE student_id = ?
  1379. AND transfer_course_id = ?
  1380. AND term_id = ?
  1381. ", $student_id, $this->course_id, $term_id);
  1382. if ($res) {
  1383. $cur = $this->db->db_fetch_array($res);
  1384. if ($cur) {
  1385. if (trim($cur["student_specific_course_title"]) != "") {
  1386. $this->title = trim($cur["student_specific_course_title"]);
  1387. }
  1388. // Also assign hours_awarded and other values while we are here
  1389. if ($cur["grade"] != "" || $cur["hours_awarded"] != "") {
  1390. $this->set_hours_awarded(0, $cur["hours_awarded"] * 1);
  1391. $this->grade = $cur["grade"];
  1392. }
  1393. $this->term_id = $cur["term_id"];
  1394. }
  1395. }
  1396. } // if term_id != NULL
  1397. $already = array(); // to prevent duplicates from showing up, keep up with
  1398. // eqv's we've already recorded.
  1399. $res2 = $this->db->db_query("SELECT * FROM transfer_eqv_per_student
  1400. WHERE student_id = ?
  1401. AND transfer_course_id = ?
  1402. ", $student_id, $this->course_id);
  1403. while($cur2 = $this->db->db_fetch_array($res2))
  1404. {
  1405. if (!in_array($cur2["local_course_id"], $already)) {
  1406. $c = new Course($cur2["local_course_id"]);
  1407. $this->transfer_eqv_text .= "$c->subject_id $c->course_num
  1408. (" . $c->get_catalog_hours() . " " . t("hrs") . ") ";
  1409. $already[] = $cur2["local_course_id"];
  1410. }
  1411. }
  1412. } // if cur
  1413. } // if student_id
  1414. }
  1415. /**
  1416. * Based on $this->term_id, set what catalog year should go with
  1417. * the course.
  1418. *
  1419. */
  1420. function set_catalog_year_from_term_id()
  1421. {
  1422. if ($this->db == null)
  1423. {
  1424. $this->db = get_global_database_handler();
  1425. }
  1426. if (strstr($this->term_id, "1111"))
  1427. {
  1428. $this->catalog_year = variable_get_for_school("earliest_catalog_year", 2006, $this->school_id);
  1429. }
  1430. $this->catalog_year = trim(substr($this->term_id,0,4));
  1431. // If the catalog year is greater than the currentCatalogYear
  1432. // setting, then set it to that.
  1433. if ($this->catalog_year > variable_get_for_school("current_catalog_year","", $this->school_id))
  1434. {
  1435. $this->catalog_year = variable_get_for_school("current_catalog_year","", $this->school_id);
  1436. }
  1437. }
  1438. /**
  1439. * Based on $this->term_id, returns a plain english description
  1440. * of the term. For example, 20061 would return "Spring of 2006".
  1441. *
  1442. * @param bool $bool_abbreviate
  1443. * - If set to TRUE, abbreviations will be used. For example,
  1444. * Spring will be "Spr" and 2006 will be '06.
  1445. *
  1446. *
  1447. * @return unknown
  1448. */
  1449. function get_term_description($bool_abbreviate = FALSE)
  1450. {
  1451. // Let's use the built-in FP function
  1452. return get_term_description($this->term_id, $bool_abbreviate, $this->school_id);
  1453. }
  1454. /**
  1455. * Basically, this is a comparator function that will return true
  1456. * if $this equals many of the attributes of $course_c. Useful for
  1457. * seeing if $this is an "instance of" a particular course, but not
  1458. * necessairily the course that the student took. Example: if you want
  1459. * to test if MATH 101 is part of a group. You wouldn't use ==, since
  1460. * all the attributes might not be the same.
  1461. *
  1462. * @param Course $course_c
  1463. *
  1464. * @return bool
  1465. */
  1466. function equals_placeholder(Course $course_c)
  1467. {
  1468. // First, see if the courses are identical.
  1469. if ($this->equals($course_c))
  1470. {
  1471. return true;
  1472. }
  1473. // Okay, now we go through and test for particular attributes
  1474. // to be equal.
  1475. if ($this->subject_id == $course_c->subject_id
  1476. && $this->course_num == $course_c->course_num
  1477. && $this->institution == $course_c->institution)
  1478. {
  1479. return true;
  1480. }
  1481. return false;
  1482. }
  1483. /**
  1484. * This is the to_string method for Course. Because we want to pass it
  1485. * values, we are not using the magic method of "__to_string". So, to use,
  1486. * invoke this method directly. Ex:
  1487. *
  1488. * $x = $newCourse->to_string("", true);
  1489. *
  1490. * @param string $pad
  1491. * - How much padding to use. Specified in the form of a string
  1492. * of spaces. Ex: " "
  1493. *
  1494. * @param bool $bool_show_random
  1495. * - Display the randomly assigned number which goes with
  1496. * this course.
  1497. *
  1498. * @return string
  1499. */
  1500. function to_string($pad = " ", $bool_show_random = false)
  1501. {
  1502. $rtn = "";
  1503. if ($this->subject_id == "") {
  1504. $this->load_descriptive_data();
  1505. }
  1506. if ($bool_show_random) {$x = "rnd:$this->random_id -";}
  1507. $rtn = $pad . "$this->course_id $x- $this->subject_id $this->course_num (" . $this->get_hours_awarded() . ") $this->grade $this->term_id";
  1508. if ($this->course_list_fulfilled_by->is_empty != true) {
  1509. // In other words, if this is a requirement, and it is
  1510. // being fulfilled by one of the student's courses,
  1511. // then let's see it.
  1512. $rtn .= " ->fulfilled by " . $this->course_list_fulfilled_by->get_first()->to_string("");
  1513. }
  1514. if ($this->bool_transfer == true && is_object($this->course_transfer))
  1515. {
  1516. $rtn .= " - XFER eqv to " . $this->course_transfer->to_string("");
  1517. } else if ($this->bool_transfer == true){
  1518. $rtn .= " - XFER no eqv ";
  1519. }
  1520. if ($this->bool_advised_to_take) {
  1521. $rtn .= " - adv in sem " . $this->assigned_to_semester_num . ".";
  1522. }
  1523. if ($this->bool_substitution) {
  1524. $rtn .= " - substitution.";
  1525. }
  1526. if ($this->db_exclude > 0) {
  1527. $rtn .= " - db_exclude = $this->db_exclude";
  1528. }
  1529. if ($this->specified_repeats > 0) {
  1530. $rtn .= " reps: $this->specified_repeats";
  1531. }
  1532. $rtn .= "\n";
  1533. return $rtn;
  1534. }
  1535. /**
  1536. * Return TRUE or FALSE if this this course was ever assigned to the supplied group_id.
  1537. * if $group_id == -1, then return TRUE if it was assigned to ANY group.
  1538. */
  1539. function get_bool_assigned_to_group_id($group_id) {
  1540. $bool_yes_specific_group = FALSE;
  1541. $bool_yes_any_group = FALSE;
  1542. foreach ($this->assigned_to_group_ids_array as $k => $v) {
  1543. if (intval($v) > 0) {
  1544. $bool_yes_any_group = TRUE;
  1545. }
  1546. if ($group_id == $v) {
  1547. $bool_yes_specific_group = TRUE;
  1548. }
  1549. }
  1550. if ($group_id == -1) {
  1551. return $bool_yes_any_group;
  1552. }
  1553. // Else...
  1554. return $bool_yes_specific_group;
  1555. }
  1556. /**
  1557. * Return the first element in our assigned_to_group_ids_array, or FALSE
  1558. */
  1559. function get_first_assigned_to_group_id() {
  1560. if (count($this->assigned_to_group_ids_array) < 1) return FALSE;
  1561. // Otherwise, get it.
  1562. $x = reset($this->assigned_to_group_ids_array); // returns the first element.
  1563. if ($x == 0) { // not a valid group_id number
  1564. return FALSE;
  1565. }
  1566. // Otherwise, return x
  1567. return $x;
  1568. }
  1569. /**
  1570. * Has the course been assigned to ANY degree?
  1571. */
  1572. function get_has_been_assigned_to_any_degree() {
  1573. if (isset($this->assigned_to_degree_ids_array) && count($this->assigned_to_degree_ids_array) > 0) return TRUE;
  1574. return FALSE;
  1575. }
  1576. function get_has_been_assigned_to_degree_id($degree_id = 0) {
  1577. if ($degree_id == 0) $degree_id = $this->req_by_degree_id;
  1578. if (in_array($degree_id, $this->assigned_to_degree_ids_array)) {
  1579. return TRUE;
  1580. }
  1581. return FALSE;
  1582. }
  1583. /**
  1584. * This is the magic method __sleep(). PHP will call this method any time
  1585. * this object is being serialized. It is supposed to return an array of
  1586. * all the variables which need to be serialized.
  1587. *
  1588. * What we are doing in it is skipping
  1589. * any variables which we are not using or which do not need to be
  1590. * serialized. This will greatly reduce the size of the final serialized
  1591. * string.
  1592. *
  1593. * It may not seem worth it at first, but consider that we may be serializing
  1594. * an entire degree plan, with a dozen groups, each with every course in the
  1595. * catalog. That could easily be 10,000+ courses which get serialized!
  1596. *
  1597. * @return array
  1598. */
  1599. function __sleep()
  1600. {
  1601. // This is supposed to return an array with the names
  1602. // of the variables which are supposed to be serialized.
  1603. $arr = array(
  1604. "db_advised_courses_id", "random_id",
  1605. "db_substitution_id_array", "db_unassign_transfer_id",
  1606. "db_exclude", "array_index", "db_group_requirement_id", "db_degree_requirement_id", "array_valid_names",
  1607. "data_entry_value", "db_group_attributes", "appears_in_semester_nums", "extra_attribs",
  1608. "subject_id", "course_num", "course_id", "requirement_type", "catalog_year",
  1609. "min_hours", "max_hours", "repeat_hours", "bool_outdated_sub",
  1610. "bool_taken", "term_id", "section_number", "grade", "db_grade", "quality_points",
  1611. "bool_transfer", "institution_id", "institution_name", "course_transfer", "transfer_footnote",
  1612. "substitution_footnote",
  1613. "min_grade", "specified_repeats", "bool_specified_repeat", "required_on_branch_id",
  1614. "assigned_to_group_id", "assigned_to_semester_num", "level_code", "req_by_degree_id",
  1615. "assigned_to_degree_ids_array", "assigned_to_group_ids_array", "school_id",
  1616. "advised_hours", "bool_selected", "bool_advised_to_take", "bool_use_draft",
  1617. "course_list_fulfilled_by",
  1618. "bool_added_course", "group_list_unassigned",
  1619. "details_by_degree_array",
  1620. "display_status", "disp_for_group_id",
  1621. "bool_hide_grade", "bool_ghost_hour",
  1622. "bool_ghost_min_hour",
  1623. );
  1624. // Okay, remove any variables we are not using
  1625. // from the array.
  1626. $rtn = array();
  1627. foreach($arr as $var)
  1628. {
  1629. if (isset($this->$var)) // This checks to see if we are using
  1630. { // the variable or not.
  1631. $rtn[] = $var;
  1632. }
  1633. }
  1634. return $rtn;
  1635. }
  1636. } // end of Course class.

Classes

Namesort descending Description
Course