MDL-41421 tool_generator: Refactoring make_form to make_course_form
authorDavid Monllao <davidm@moodle.com>
Wed, 28 Aug 2013 02:09:05 +0000 (10:09 +0800)
committerDavid Monllao <davidm@moodle.com>
Mon, 16 Sep 2013 08:09:25 +0000 (16:09 +0800)
Also:
- Added a soft password for the
newly generated users so we can use
them to log in the site when running
performance tests.
- Added a method to see the courses-users
relation from outside course_backend class.

admin/tool/generator/classes/course_backend.php
admin/tool/generator/classes/make_course_form.php [moved from admin/tool/generator/classes/make_form.php with 88% similarity]
admin/tool/generator/maketestcourse.php

index 07e1e7b..5171b83 100644 (file)
@@ -111,6 +111,15 @@ class tool_generator_course_backend extends tool_generator_backend {
         parent::__construct($size, $fixeddataset, $progress);
     }
 
+    /**
+     * Returns the relation between users and course sizes.
+     *
+     * @return array
+     */
+    public static function get_users_per_size() {
+        return self::$paramusers;
+    }
+
     /**
      * Gets a list of size choices supported by this backend.
      *
@@ -280,6 +289,8 @@ class tool_generator_course_backend extends tool_generator_backend {
      * @param int $last Number of last user
      */
     private function create_user_accounts($first, $last) {
+        global $CFG;
+
         $this->log('createaccounts', (object)array('from' => $first, 'to' => $last), true);
         $count = $last - $first + 1;
         $done = 0;
@@ -294,6 +305,12 @@ class tool_generator_course_backend extends tool_generator_backend {
             // Create user account.
             $record = array('firstname' => get_string('firstname', 'tool_generator'),
                     'lastname' => $number, 'username' => $username);
+
+            // We add a user password if it has been specified.
+            if (!empty($CFG->tool_generator_users_password)) {
+                $record['password'] = $CFG->tool_generator_users_password;
+            }
+
             $user = $this->generator->create_user($record);
             $this->userids[$number] = (int)$user->id;
             $this->dot($done, $count);
@@ -25,8 +25,13 @@ require_once($CFG->libdir . '/formslib.php');
  * @copyright 2013 The Open University
  * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class tool_generator_make_form extends moodleform {
+class tool_generator_make_course_form extends moodleform {
 
+    /**
+     * Course generation tool form definition.
+     *
+     * @return void
+     */
     public function definition() {
         $mform = $this->_form;
 
@@ -41,6 +46,13 @@ class tool_generator_make_form extends moodleform {
         $mform->addElement('submit', 'submit', get_string('createcourse', 'tool_generator'));
     }
 
+    /**
+     * Form validation.
+     *
+     * @param array $data
+     * @param array $files
+     * @return void
+     */
     public function validation($data, $files) {
         global $DB;
         $errors = array();
index 82af097..c5f9c82 100644 (file)
@@ -32,7 +32,7 @@ require('../../../config.php');
 require_once($CFG->libdir . '/adminlib.php');
 
 // Initialise page and check permissions.
-admin_externalpage_setup('toolgenerator');
+admin_externalpage_setup('toolgeneratorcourse');
 
 // Start page.
 echo $OUTPUT->header();
@@ -40,7 +40,7 @@ echo $OUTPUT->heading(get_string('maketestcourse', 'tool_generator'));
 
 // Information message.
 $context = context_system::instance();
-echo $OUTPUT->box(format_text(get_string('explanation', 'tool_generator'),
+echo $OUTPUT->box(format_text(get_string('courseexplanation', 'tool_generator'),
         FORMAT_MARKDOWN, array('context' => $context)));
 
 // Check debugging is set to DEVELOPER.
@@ -51,7 +51,7 @@ if (!debugging('', DEBUG_DEVELOPER)) {
 }
 
 // Set up the form.
-$mform = new tool_generator_make_form('maketestcourse.php');
+$mform = new tool_generator_make_course_form('maketestcourse.php');
 if ($data = $mform->get_data()) {
     // Do actual work.
     echo $OUTPUT->heading(get_string('creating', 'tool_generator'));