array('short'=>'mods', 'long' => 'modules_list',
'help' => 'The list of modules you want to generate', 'default' => $this->modules_list,
'type' => 'mod1,mod2...'),
+ array('short'=>'at', 'long' => 'assignment_type',
+ 'help' => 'The specific type of assignment you want to generate. Defaults to random', 'default' => 'random'),
array('short'=>'ag', 'long' => 'assignment_grades',
'help' => 'Generate random grades for each student/assignment tuple', 'default' => true),
array('short'=>'qg', 'long' => 'quiz_grades',
public function generate_courses() {
global $DB;
- $this->verbose("Generating {$this->get('number_of_courses')} courses...");
+ $this->verbose("Generating " . $this->get('number_of_courses')." courses...");
$base_course = new stdClass();
$next_course_id = $DB->get_field_sql("SELECT MAX(id) FROM {course}") + 1;
$newcourse->fullname = "Test course $next_course_id";
$newcourse->shortname = "Test $next_course_id";
$newcourse->idnumber = $this->get('data_prefix') . $next_course_id;
-
if (!$course = create_course($newcourse)) {
$this->verbose("Error inserting a new course in the database!");
if (!$this->get('ignore_errors')) {
switch ($moduledata->name) {
case 'assignment':
$module->description = $description;
- $module->assignmenttype = $assignment_types[rand(0, count($assignment_types) - 1)];
+ if ($this->get('assignment_type') == 'random') {
+ $module->assignmenttype = $assignment_types[rand(0, count($assignment_types) - 1)];
+ } else {
+ $module->assignmenttype = $this->get('assignment_type');
+ }
+
$module->timedue = mktime() + 89487321;
$module->grade = rand(50,100);
break;
if (!quiz_add_quiz_question($questions[$quiz->course][$random]->id, $quiz)) {
// Could not add question to quiz!! report error
- echo "WARNING: Could not add question id $random to quiz id $quiz->id{$this->eolchar}";
+ if (!$this->get('quiet')) {
+ echo "WARNING: Could not add question id $random to quiz id $quiz->id{$this->eolchar}";
+ }
} else {
$this->verbose("Adding question id $random to quiz id $quiz->id.");
$questions_added[] = $random;
}
public function generate_grades($course_users, $courses, $modules) {
- global $CFG, $DB;
+ global $CFG, $DB, $USER;
/**
* ASSIGNMENT GRADES GENERATION
*/
if ($this->get('assignment_grades') && isset($modules['assignment'])) {
$grades_count = 0;
- foreach ($course_users as $userid => $courses) {
- foreach ($modules['assignment'] as $assignment) {
- if (in_array($assignment->course, $courses)) {
- $maxgrade = $assignment->grade;
- $random_grade = rand(0, $maxgrade);
- $grade = new stdClass();
- $grade->assignment = $assignment->id;
- $grade->userid = $userid;
- $grade->grade = $random_grade;
- $grade->rawgrade = $random_grade;
- $grade->teacher = $USER->id;
- $DB->insert_record('assignment_submissions', $grade);
- grade_update('mod/assignment', $courseid, 'mod', 'assignment', $assignment->id, 0, $grade);
- $this->verbose("A grade ($random_grade) has been given to user $userid for assignment $assignment->id");
- $grades_count++;
+ foreach ($course_users as $courseid => $userid_array) {
+ foreach ($userid_array as $userid) {
+ foreach ($modules['assignment'] as $assignment) {
+ if (in_array($assignment->course, $courses)) {
+ $maxgrade = $assignment->grade;
+ $random_grade = rand(0, $maxgrade);
+ $grade = new stdClass();
+ $grade->assignment = $assignment->id;
+ $grade->userid = $userid;
+ $grade->grade = $random_grade;
+ $grade->rawgrade = $random_grade;
+ $grade->teacher = $USER->id;
+ $DB->insert_record('assignment_submissions', $grade);
+ grade_update('mod/assignment', $assignment->course, 'mod', 'assignment', $assignment->id, 0, $grade);
+ $this->verbose("A grade ($random_grade) has been given to user $userid "
+ . "for assignment $assignment->id");
+ $grades_count++;
+ }
}
}
}
if ($grades_count > 0) {
- echo "$grades_count assignment grades have been generated.{$this->eolchar}";
+ $this->verbose("$grades_count assignment grades have been generated.{$this->eolchar}");
}
}
}
}
}
- if ($grades_count > 0) {
+ if ($grades_count > 0 && !$this->get('quiet')) {
echo "$grades_count quiz grades have been generated.{$this->eolchar}";
}
}
public function prepare_package() {
global $CFG;
if (is_callable(array($this->assignment, 'portfolio_prepare_package'))) {
- return $this->assignment->portfolio_prepare_package($this->exporter);
+ return $this->assignment->portfolio_prepare_package($this->exporter, $this->user->id);
}
$fs = get_file_storage();
$status = true;
public function get_sha1() {
global $CFG;
if (is_callable(array($this->assignment, 'portfolio_get_sha1'))) {
- return $this->assignment->portfolio_get_sha1();
+ return $this->assignment->portfolio_get_sha1($this->user->id);
}
// default ...
if ($this->file) {
return $fs->get_file_by_id($this->file)->get_contenthash();
}
- if ($files = $fs->get_area_files($this->assignment->context->id, 'assignment_submission', $this->user->id, '', false)) {
+ if ($files = $fs->get_area_files($this->assignment->context->id,
+ 'assignment_submission', $this->user->id, '', false)) {
$sha1s = array();
foreach ($files as $file) {
$sha1s[] = $file->get_contenthash();
--- /dev/null
+<?php // $Id$
+require_once($CFG->libdir.'/simpletest/testportfoliolib.php');
+require_once($CFG->dirroot.'/mod/assignment/lib.php');
+require_once($CFG->dirroot.'/admin/generator.php');
+
+Mock::generate('assignment_portfolio_caller', 'mock_caller');
+Mock::generate('portfolio_exporter', 'mock_exporter');
+
+class testAssignmentPortfolioCallers extends portfoliolib_test {
+ public $module_type = 'assignment';
+ public $modules = array();
+ public $entries = array();
+ public $caller;
+
+ public function setUp() {
+ global $DB, $USER;
+
+ parent::setUp();
+
+ $settings = array('quiet' => 1, 'database_prefix' => 'tst_', 'pre_cleanup' => 1,
+ 'modules_list' => array($this->module_type), 'assignment_grades' => true,
+ 'assignment_type' => 'online',
+ 'number_of_students' => 5, 'students_per_course' => 5, 'number_of_sections' => 1,
+ 'number_of_modules' => 1, 'questions_per_course' => 0);
+ generator_generate_data($settings);
+
+ $this->modules = $DB->get_records($this->module_type);
+ $first_module = reset($this->modules);
+ $cm = get_coursemodule_from_instance($this->module_type, $first_module->id);
+ $submissions = $DB->get_records('assignment_submissions', array('assignment' => $first_module->id));
+ $first_submission = reset($submissions);
+
+ $callbackargs = array('assignmentid' => $cm->id, 'userid' => $USER->id);
+ $this->caller = new assignment_portfolio_caller($callbackargs);
+ $this->caller->set('exporter', new mock_exporter());
+ $user = $DB->get_record('user', array('id' => $first_submission->userid));
+ $this->caller->set('user', $user);
+ }
+
+ public function tearDown() {
+ parent::tearDown();
+ }
+
+ public function test_caller_sha1() {
+ $sha1 = $this->caller->get_sha1();
+ $this->caller->prepare_package();
+ $this->assertEqual($sha1, $this->caller->get_sha1());
+ }
+
+}
+?>