Course.php

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

Classes

Namesort descending Description
Course