function admin_get_courses_from_definition
Search API
7.x admin.groups.inc | admin_get_courses_from_definition($definition, $catalog_year = "", $school_id = 0) |
6.x admin.groups.inc | admin_get_courses_from_definition($definition, $catalog_year = "", |
4.x admin.groups.inc | admin_get_courses_from_definition($definition, $catalog_year = "") |
5.x admin.groups.inc | admin_get_courses_from_definition($definition, $catalog_year = "") |
3 calls to admin_get_courses_from_definition()
- admin_display_groups_popup_edit_definition in modules/
admin/ admin.groups.inc - admin_edit_group_form_submit in modules/
admin/ admin.groups.inc - admin_process_all_definitions_perform_batch_operation in modules/
admin/ admin.groups.inc - This actually is the batch operation for processing all of our group definitions.
File
- modules/
admin/ admin.groups.inc, line 769
Code
function admin_get_courses_from_definition($definition, $catalog_year = "") {
$group_array = array();
// Okay, first things first, let's trim this sucker and remove extra whitespace.
$definition = trim($definition);
$definition = str_replace(" ", " ", $definition);
$definition = str_replace(" ", " ", $definition);
$definition = str_replace(" ", " ", $definition);
// Okay, now let's break this up into lines...
$d_lines = explode("\n", $definition);
foreach ($d_lines as $line)
{
$line = trim($line);
// Let's get each of the parts... the instruction, and the course data.
$tokens = explode(" ", $line);
$instruction = strtolower(trim($tokens [0]));
@$course_data = trim($tokens [1]);
// We know that the course data can also be broken up, by the .
$c_tokens = explode(".", $course_data);
$subject_data = trim(strtoupper($c_tokens [0]));
@$course_numData = trim(strtoupper($c_tokens [1]));
// Okay, so now, for this line, we have an instruction,
// and some course data (possibly wild cards) to act on.
//debugCT("$instruction $subject_data $course_numData");
$t_array = admin_get_course_array_from_definition_data($subject_data, $course_numData, $catalog_year);
// Okay, we got our list. Now what do we do with them?
if ($instruction == "add" || $instruction == "+")
{
$group_array = array_merge($group_array, $t_array);
$group_array = array_unique($group_array);
}
if ($instruction == "remove" || $instruction == "rem" || $instruction == "-" || $instruction == "del")
{
//print "<pre>" . print_r($t_array) . "</pre>";
//debug_c_t(count($group_array));
//$group_array = array_diff($group_array, $t_array);
$group_array = admin_array_diff($group_array, $t_array);
$group_array = array_unique($group_array);
//debug_c_t(count($group_array));
}
}
// Here's what we need to do:
// In groupArray, we have the subject_id and course_num of every course in this definition.
// We need to convert them to course_id's from the table,
// and make sure we do not have duplicates.
// First, get an array of course_id from the groupArray...
$course_idArray = $group_array;
// Take out duplicate entries (caused by eqv courses)...
$course_idArray = array_unique($course_idArray);
//print_r($course_idArray);
//debugCT(sizeof($course_idArray));
// Now, convert BACK into the "groupArray" structure (subject_id and course_num)...
$group_array2 = admin_get_course_array_from_course_id_array($course_idArray);
//print_r($group_array);
// Place in alphabetical order.
sort($group_array2);
//var_dump($group_array2);
$rtn = array();
$rtn ["text"] = "";
$count = 1;
// Now that we have the groupArray, we will turn it into a string...
for ($t = 0; $t < count($group_array2); $t++)
{
$line = trim($group_array2 [$t]);
if ($line == "~~" || $line == "") {
continue;
}
$count++;
$temp = explode(" ~~ ", $line);
$si = trim($temp [0]);
$cn = trim($temp [1]);
@$rtn ["text"] .= "$si $cn\n";
}
$rtn ["text"] = str_replace("&", "_A_", $rtn ["text"]);
//debug_c_t(count($group_array));
$rtn ["count"] = $count;
return $rtn;
}