_Course.php

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

Classes

Namesort descending Description
_Course