php 5.2.5 I wrote the function to get modules by courseid from MySQL database.
function getModules($courses, $mod) {
global $DB;
$result = array();
foreach ($courses as $value) {
$value->mods = array();
$value->count = 0;
$temp = $DB->get_records_sql("
SELECT q.*, cm.idnumber as cmidnumber, q.course as courseid
FROM {modules} m
JOIN {course_modules} cm ON m.id = cm.module
JOIN {".$mod."} q ON cm.instance = q.id
WHERE m.name = '".$mod."' AND cm.course = ?", array($value->id));
foreach ($temp as $vS) {
$value->mods[] = $vS;
$value->count++;
}
$result[] = $value;
}
return $result;
}
Try to get some type of modules (to_debug just kind of wrapper about var_dump)
$learningScorm = getModules($learning, 'scorm');
to_debug($learningScorm); // in debug I can see right values.
echo '<br><br><br>';
$learningLesson = getModules($learning, 'lesson');
to_debug($learningScorm);// in debug I see what value of $learningScorm is replaced by value of $learningLesson
$testingQuiz = getModules($testing, 'quiz');
$labAssignment = getModules($lab, 'assignment');
I cannot understand why this replacing is happening If you have some hints about such behaviour, please give me it.
If I comment these lines
$value->mods = array();
$value->count = 0;
then $learningScorm is summing modules from $learningScorm and $learningLesson. It seems... Seems what $courses is not local during function O_O. I do not know what to think already.