function prereqs_get_prereq_array_from_string
Search API
7.x prereqs.module | prereqs_get_prereq_array_from_string($prereqs_str, $school_id = 0) |
6.x prereqs.module | prereqs_get_prereq_array_from_string($prereqs_str, $school_id = 0) |
Assumes prereqs are written in this format: ACCT 101 (C) & ACCT 103 ACCT 102 (B)
Returns back a friendly array that makes everything easier to read.
2 calls to prereqs_get_prereq_array_from_string()
- prereqs_edit_course_form_validate in modules/
prereqs/ prereqs.module - validate for the edit course form, from admin.courses.inc.
- prereqs_get_prereq_array_for_course in modules/
prereqs/ prereqs.module - Return back a friendly array of prereq courses that are required for THIS course_id.
File
- modules/
prereqs/ prereqs.module, line 400 - This is the module file for the prereqs module.
Code
function prereqs_get_prereq_array_from_string($prereqs_str, $school_id = 0) {
$rtn = array();
$db = get_global_database_handler();
$c = 0;
$lines = explode("\n", $prereqs_str);
foreach ($lines as $line) {
$line = fp_reduce_whitespace($line);
$line = trim($line);
if ($line == "") {
continue; // skip blanks.
}
$courses = explode(" or ", $line);
foreach ($courses as $course_line) {
$course_line = trim(fp_reduce_whitespace($course_line));
$temp = explode(" ", $course_line);
$subject_id = trim($temp [0]);
$course_num = trim($temp [1]);
$min_grade = @trim(str_replace("(", "", $temp [2]));
$min_grade = @trim(str_replace(")", "", $min_grade));
// Was there a min grade stuck with the course_num?
if (strstr($course_num, "(")) {
$temp2 = explode("(", $course_num);
$course_num = trim($temp2 [0]);
$min_grade = trim(str_replace(")", "", $temp2 [1]));
}
// Okay, now that we have the subject_id and course_num, let's find the course_id (if it exists).
$course_id = $db->get_course_id($subject_id, $course_num, '', FALSE, $school_id, TRUE);
// Okay, add to our return array.
$rtn [$c][] = array(
"subject_id" => $subject_id,
"course_num" => $course_num,
"course_id" => $course_id,
"min_grade" => $min_grade,
);
} //foreach courses
$c++;
} // foreach line
return $rtn;
}