Exemplo n.º 1
0
 /**
  * Get data generator
  * @static
  * @return testing_data_generator
  */
 public static function getDataGenerator() {
     return phpunit_util::get_data_generator();
 }
Exemplo n.º 2
0
 /**
  * Runs the entire 'make' process.
  *
  * @return int Course id
  */
 public function make()
 {
     global $DB, $CFG;
     require_once $CFG->dirroot . '/lib/phpunit/classes/util.php';
     raise_memory_limit(MEMORY_EXTRA);
     if ($this->progress && !CLI_SCRIPT) {
         echo html_writer::start_tag('ul');
     }
     $entirestart = microtime(true);
     // Start transaction.
     $transaction = $DB->start_delegated_transaction();
     // Get generator.
     $this->generator = phpunit_util::get_data_generator();
     // Make course.
     $this->course = $this->create_course();
     $this->create_users();
     $this->create_pages();
     $this->create_small_files();
     $this->create_big_files();
     $this->create_forum();
     // Log total time.
     $this->log('coursecompleted', round(microtime(true) - $entirestart, 1));
     if ($this->progress && !CLI_SCRIPT) {
         echo html_writer::end_tag('ul');
     }
     // Commit transaction and finish.
     $transaction->allow_commit();
     return $this->course->id;
 }
Exemplo n.º 3
0
 private function create_marker_module($markerid)
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/lib/phpunit/classes/util.php';
     // Start transaction.
     $transaction = $DB->start_delegated_transaction();
     try {
         // Get generator.
         $generator = phpunit_util::get_data_generator();
         /**@var mod_emarking_generator $emarking_generator*/
         $emarking_generator = $generator->get_plugin_generator('mod_emarking');
         $blueprint = $DB->get_record('emarking', array("id" => $this->cm->instance));
         $blueprint->timecreated = time();
         $originalname = $blueprint->name;
         $markers = get_users_by_capability($this->context, 'mod/emarking:grade', 'u.id,u.username');
         $marker = $markers[$markerid];
         if (!$marker) {
             throw new Exception("Marker not found");
         }
         $previous = $DB->get_record('emarking_markers', array('masteractivity' => $this->parentcm->instance, 'markerid' => $markerid));
         if ($previous) {
             throw new Exception("Delete previous marker record before assigning a new one");
         }
         $submissions = $DB->get_records('emarking_submission', array("emarking" => $this->cm->instance));
         $pages = array();
         foreach ($submissions as $sub) {
             $pages[$sub->id] = $DB->get_records('emarking_page', array("submission" => $sub->id));
         }
         unset($blueprint->id);
         $blueprint->name = $originalname . " -- " . $marker->username;
         $inserted = $emarking_generator->create_instance($blueprint, array("visible" => 0));
         $markermap = new stdClass();
         $markermap->masteractivity = $this->parentcm->instance;
         $markermap->markerid = $marker->id;
         $markermap->activityid = $inserted->id;
         $DB->insert_record('emarking_markers', $markermap);
         // se agrega el grading method correcto.
         require_once $CFG->dirroot . '/grade/grading/lib.php';
         $gradingman = get_grading_manager(context_module::instance($inserted->cmid), 'mod_emarking');
         $gradingman->set_area("attempt");
         $gradingman->set_active_method("rubric");
         emarking_grade_item_update($inserted);
         //Now replicate submissions
         foreach ($submissions as $sub) {
             $insertable = clone $sub;
             unset($insertable->id);
             $insertable->emarking = $inserted->id;
             $id = $DB->insert_record('emarking_submission', $insertable);
             foreach ($pages[$sub->id] as $subpage) {
                 $insertablepage = clone $subpage;
                 unset($insertablepage->id);
                 $insertablepage->submission = $id;
                 $DB->insert_record('emarking_page', $insertablepage);
             }
             // Update the raw grade of the user
             $grade_item = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => 'emarking', 'iteminstance' => $inserted->id));
             $grade = $grade_item->get_grade($insertable->student, true);
             $grade_item->update_final_grade($insertable->student, null, 'upload', '', FORMAT_HTML, $marker->id);
             // grade
         }
         $transaction->allow_commit();
     } catch (Exception $e) {
         $transaction->rollback($e);
     }
 }
Exemplo n.º 4
0
 * @copyright  2015 Skylar Kelty <*****@*****.**>
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
define('CLI_SCRIPT', true);
require __DIR__ . '/../../../../config.php';
require_once $CFG->libdir . '/clilib.php';
require_once $CFG->libdir . '/coursecatlib.php';
require_once $CFG->dirroot . '/lib/phpunit/classes/util.php';
cli_writeln('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~');
cli_writeln('Welcome to the school generator!');
cli_writeln('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~');
cli_writeln('');
$category = $DB->get_record('course_categories', array('name' => 'School of Witchcraft and Wizardry'));
if (!$category) {
    cli_writeln('Creating category...');
    $category = \coursecat::create(array('name' => 'School of Witchcraft and Wizardry', 'description' => 'A school like no other!', 'descriptionformat' => 1, 'parent' => 0, 'sortorder' => 520000, 'coursecount' => 0, 'visible' => 1, 'visibleold' => 1, 'timemodified' => 0, 'depth' => 1, 'path' => '/2', 'theme' => ''));
} else {
    cli_writeln('Using existing category.');
}
$courses = array('Astronomy', 'Charms', 'Dark Arts', 'Defence Against the Dark Arts', 'Flying', 'Herbology', 'History of Magic', 'Muggle Studies', 'Potions', 'Transfiguration', 'Alchemy', 'Apparition', 'Arithmancy', 'Care of Magical Creatures', 'Divination', 'Study of Ancient Runes', 'Extra-curricular subjects', 'Ancient Studies', 'Art', 'Frog Choir', 'Ghoul Studies', 'Magical Theory', 'Muggle Art', 'Music', 'Muggle Music', 'Orchestra', 'Xylomancy');
cli_writeln('Creating courses...');
$generator = \phpunit_util::get_data_generator();
$id = 1000;
foreach ($courses as $course) {
    if ($DB->record_exists('course', array('fullname' => $course))) {
        continue;
    }
    $courserecord = array('shortname' => "WZ{$id}", 'fullname' => $course, 'numsections' => 10, 'startdate' => usergetmidnight(time()), 'category' => $category->id);
    $generator->create_course($courserecord, array('createsections' => true));
    $id += 100;
}
Exemplo n.º 5
0
 /**
  * Create a new framework.
  *
  * @param array|stdClass $record
  * @return competency_framework
  */
 public function create_framework($record = null)
 {
     $generator = phpunit_util::get_data_generator();
     $this->frameworkcount++;
     $i = $this->frameworkcount;
     $record = (object) $record;
     if (!isset($record->shortname)) {
         $record->shortname = "Framework shortname {$i}";
     }
     if (!isset($record->idnumber)) {
         $record->idnumber = "frm{$i}";
     }
     if (!isset($record->description)) {
         $record->description = "Framework {$i} description ";
     }
     if (!isset($record->descriptionformat)) {
         $record->descriptionformat = FORMAT_HTML;
     }
     if (!isset($record->visible)) {
         $record->visible = 1;
     }
     if (!isset($record->scaleid)) {
         if (isset($record->scaleconfiguration)) {
             throw new coding_exception('Scale configuration must be provided with a scale.');
         }
         if (!$this->scale) {
             $this->scale = $generator->create_scale(array('scale' => 'A,B,C,D'));
         }
         $record->scaleid = $this->scale->id;
     }
     if (!isset($record->scaleconfiguration)) {
         $scale = grade_scale::fetch(array('id' => $record->scaleid));
         $values = $scale->load_items();
         foreach ($values as $key => $value) {
             // Add a key (make the first value 1).
             $values[$key] = array('id' => $key + 1, 'name' => $value);
         }
         if (count($values) < 2) {
             throw new coding_exception('Please provide the scale configuration for one-item scales.');
         }
         $scaleconfig = array();
         // Last item is proficient.
         $item = array_pop($values);
         array_unshift($scaleconfig, array('id' => $item['id'], 'proficient' => 1));
         // Second-last item is default and proficient.
         $item = array_pop($values);
         array_unshift($scaleconfig, array('id' => $item['id'], 'scaledefault' => 1, 'proficient' => 1));
         array_unshift($scaleconfig, array('scaleid' => $record->scaleid));
         $record->scaleconfiguration = json_encode($scaleconfig);
     }
     if (is_array($record->scaleconfiguration) || is_object($record->scaleconfiguration)) {
         // Conveniently encode the config.
         $record->scaleconfiguration = json_encode($record->scaleconfiguration);
     }
     if (!isset($record->contextid)) {
         $record->contextid = context_system::instance()->id;
     }
     $framework = new competency_framework(0, $record);
     $framework->create();
     return $framework;
 }
Exemplo n.º 6
0
 /**
  * Runs the entire 'make' process.
  *
  * @return int Course id
  */
 public function make()
 {
     global $DB, $CFG;
     require_once $CFG->dirroot . '/lib/phpunit/classes/util.php';
     raise_memory_limit(MEMORY_EXTRA);
     if ($this->progress && !CLI_SCRIPT) {
         echo html_writer::start_tag('ul');
     }
     $entirestart = microtime(true);
     // Get generator.
     $this->generator = phpunit_util::get_data_generator();
     // Make course.
     $this->course = $this->create_course();
     $this->create_assignments();
     $this->create_pages();
     $this->create_small_files();
     $this->create_big_files();
     // Create users as late as possible to reduce regarding in the gradebook.
     $this->create_users();
     $this->create_forum();
     // Log total time.
     $this->log('coursecompleted', round(microtime(true) - $entirestart, 1));
     if ($this->progress && !CLI_SCRIPT) {
         echo html_writer::end_tag('ul');
     }
     return $this->course->id;
 }