/** * Performs the bulk report function. * * @param array $formdata the form data * @return bool False on failure * @uses $DB */ function report_ncccscensus_generate_bulk_report($formdata) { global $DB; $courses = report_ncccscensus_get_courses($formdata); if (!(is_array($courses) && count($courses) > 0)) { return false; } // Generate random batch id. $report = new stdClass(); $report->starttime = usertime(time(), get_user_timezone()); $batchid = $DB->insert_record('report_ncccscensus_batch', $report); foreach ($courses as $course) { $report = new stdClass(); $report->batchid = $batchid; $report->course = $course; $report->starttime = usertime(time(), get_user_timezone()); $report->reportstartdate = $formdata->startdate; $report->reportenddate = $formdata->enddate; $DB->insert_record('report_ncccscensus', $report); } return $batchid; }
/** * Test of courses and teachers selected. * * @return void */ public function test_coursesteachers() { global $CFG; require_once $CFG->dirroot . '/report/ncccscensus/lib.php'; $data = $this->createdata(); $formdata = new stdClass(); // Teacher with two courses and only show one. $courses = array($data['course1']->id); $formdata->courses = $data['course1']->id; $formdata->teachers = join(',', array($data['user1']->id)); $this->check_arrays_equivalent(report_ncccscensus_get_courses($formdata), $courses); // Two teacher with two courses and only show one. $courses = array($data['course1']->id); $formdata->courses = $data['course1']->id; $formdata->teachers = join(',', array($data['user1']->id, $data['user2']->id)); $this->check_arrays_equivalent(report_ncccscensus_get_courses($formdata), $courses); // Teacher with two courses and show none as teacher is not enrolled. $courses = false; $formdata->courses = $data['course4']->id; $formdata->teachers = join(',', array($data['user1']->id)); $this->check_arrays_equivalent(report_ncccscensus_get_courses($formdata), $courses); // Setting categories with courses selected should not change result. // Selected courses are assumed to be from selected categories. $formdata->categories = $data['category2']->id; // Teacher with two courses and only show one. $courses = array($data['course1']->id); $formdata->courses = $data['course1']->id; $formdata->teachers = join(',', array($data['user1']->id)); $this->check_arrays_equivalent(report_ncccscensus_get_courses($formdata), $courses); // Two teacher with two courses and only show one. $courses = array($data['course1']->id); $formdata->courses = $data['course1']->id; $formdata->teachers = join(',', array($data['user1']->id, $data['user2']->id)); $this->check_arrays_equivalent(report_ncccscensus_get_courses($formdata), $courses); // Teacher with two courses and show none as teacher is not enrolled. $courses = false; $formdata->courses = $data['course4']->id; $formdata->teachers = join(',', array($data['user1']->id)); $this->check_arrays_equivalent(report_ncccscensus_get_courses($formdata), $courses); }