]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-15666 MDL-16486
authornicolasconnault <nicolasconnault>
Tue, 16 Sep 2008 07:33:16 +0000 (07:33 +0000)
committernicolasconnault <nicolasconnault>
Tue, 16 Sep 2008 07:33:16 +0000 (07:33 +0000)
admin/generator.php
mod/assignment/simpletest/test_assignment_portfolio_callers.php
mod/resource/simpletest/test_resource_portfolio_callers.php

index d49639a82e7a509f68f0b8633d37fd204e2bfe64..445528d5aed497897945aa51390c4e3a1d805799 100755 (executable)
@@ -3,6 +3,10 @@ require_once(dirname(__FILE__).'/../config.php');
 require_once($CFG->libdir . '/formslib.php');
 require_once($CFG->dirroot .'/course/lib.php');
 require_once($CFG->dirroot .'/mod/resource/lib.php');
+
+define('GENERATOR_RANDOM', 0);
+define('GENERATOR_SEQUENCE', 1);
+
 /**
  * Controller class for data generation
  */
@@ -25,6 +29,15 @@ class generator {
                                  'wiki' => 'wiki',
                                  'workshop' => 'workshop');
 
+    public $resource_types = array('text', 'file', 'html', 'repository', 'directory', 'ims');
+    public $glossary_formats = array('continuous', 'encyclopedia', 'entrylist', 'faq', 'fullwithauthor', 'fullwithoutauthor', 'dictionary');
+    public $assignment_types = array('upload', 'uploadsingle', 'online', 'offline');
+    public $forum_types = array('single', 'eachuser', 'qanda', 'general');
+
+    public $resource_type_counter = 0;
+    public $assignment_type_counter = 0;
+    public $forum_type_counter = 0;
+
     public $settings = array();
     public $eolchar = '<br />';
     public $do_generation = false;
@@ -76,13 +89,21 @@ class generator {
                    'help' => 'The list of modules you want to generate', 'default' => $this->modules_list,
                    'type' => 'mod1,mod2...'),
              array('short'=>'rt', 'long' => 'resource_type',
-                   'help' => 'The specific type of resource you want to generate. Defaults to random',
-                   'default' => 'random',
-                   'type' => 'STRING'),
+                   'help' => 'The specific type of resource you want to generate. Defaults to all',
+                   'default' => $this->resource_types,
+                   'type' => 'SELECT'),
              array('short'=>'at', 'long' => 'assignment_type',
-                   'help' => 'The specific type of assignment you want to generate. Defaults to random',
-                   'default' => 'random',
-                   'type' => 'STRING'),
+                   'help' => 'The specific type of assignment you want to generate. Defaults to all',
+                   'default' => $this->assignment_types,
+                   'type' => 'SELECT'),
+             array('short'=>'ft', 'long' => 'forum_type',
+                   'help' => 'The specific type of forum you want to generate. Defaults to all',
+                   'default' => $this->forum_types,
+                   'type' => 'SELECT'),
+             array('short'=>'gf', 'long' => 'glossary_format',
+                   'help' => 'The specific format of glossary you want to generate. Defaults to all',
+                   'default' => $this->glossary_formats,
+                   'type' => 'SELECT'),
              array('short'=>'ag', 'long' => 'assignment_grades',
                    'help' => 'Generate random grades for each student/assignment tuple', 'default' => true),
              array('short'=>'qg', 'long' => 'quiz_grades',
@@ -360,12 +381,6 @@ class generator {
         array_shift($modules);
         array_unshift($modules, $first_module);
 
-        $resource_types = array('text', 'file', 'html', 'repository', 'directory', 'ims');
-        $glossary_formats = array('continuous', 'encyclopedia', 'entrylist', 'faq', 'fullwithauthor',
-            'fullwithoutauthor', 'dictionary');
-        $assignment_types = array('upload', 'uploadsingle', 'online', 'offline');
-        $forum_types = array('single', 'eachuser', 'qanda', 'general');
-
         $modules_array = array();
 
         if (count($courses) > 0) {
@@ -409,16 +424,13 @@ class generator {
                                      . "its speed and ease of use being affected dramatically.";
                         $content = 'Very useful content, I am sure you would agree';
 
+                        $module_type_index = 0;
+
                         // Special module-specific config
                         switch ($moduledata->name) {
                             case 'assignment':
                                 $module->description = $description;
-                                if ($this->get('assignment_type') == 'random') {
-                                    $module->assignmenttype = $assignment_types[rand(0, count($assignment_types) - 1)];
-                                } else {
-                                    $module->assignmenttype = $this->get('assignment_type');
-                                }
-
+                                $module->assignmenttype = $this->get_module_type('assignment');
                                 $module->timedue = mktime() + 89487321;
                                 $module->grade = rand(50,100);
                                 break;
@@ -446,13 +458,13 @@ class generator {
                                 break;
                             case 'forum':
                                 $module->intro = $description;
-                                $module->type = $forum_types[rand(0, count($forum_types) - 1)];
+                                $module->type = $this->get_module_type('forum');
                                 $module->forcesubscribe = rand(0, 1);
                                 $module->format = 1;
                                 break;
                             case 'glossary':
                                 $module->intro = $description;
-                                $module->displayformat = $glossary_formats[rand(0, count($glossary_formats) - 1)];
+                                $module->displayformat = $this->glossary_formats[rand(0, count($this->glossary_formats) - 1)];
                                 $module->cmidnumber = rand(0,999999);
                                 break;
                             case 'label':
@@ -477,12 +489,7 @@ class generator {
                                 $module->quizpassword = '';
                                 break;
                             case 'resource':
-                                if ($this->get('resource_type') == 'random') {
-                                    $module->type = $resource_types[rand(0, count($resource_types) - 1)];
-                                } else {
-                                    $module->type = $this->get('resource_type');
-                                }
-
+                                $module->type = $this->get_module_type('resource');
                                 $module->alltext = $content;
                                 $module->summary = $description;
                                 $module->windowpopup = rand(0,1);
@@ -994,6 +1001,35 @@ class generator {
             return false;
         }
     }
+
+    public function get_module_type($modulename) {
+        $return_val = false;
+
+        $type = $this->get($modulename.'_type');
+
+        if (is_object($type) && isset($type->type) && isset($type->options)) {
+
+            if ($type->type == GENERATOR_RANDOM) {
+                $return_val = $type->options[array_rand($type->options)];
+
+            } elseif ($type->type == GENERATOR_SEQUENCE) {
+                $return_val = $type->options[$this->{$modulename.'_type_counter'}];
+                $this->{$modulename.'_type_counter'}++;
+
+                if ($this->{$modulename.'_type_counter'} == count($type->options)) {
+                    $this->{$modulename.'_type_counter'} = 0;
+                }
+            }
+
+        } elseif (is_array($type)) {
+            $return_val = $type[array_rand($type)];
+
+        } elseif (is_string($type)) {
+            $return_val = $type;
+        }
+
+        return $return_val;
+    }
 }
 
 class generator_argument {
@@ -1070,7 +1106,7 @@ class generator_cli extends generator {
 
                 if (!is_null($value)) {
 
-                    if (!empty($argument->type) && $argument->type == 'mod1,mod2...') {
+                    if (!empty($argument->type) && ($argument->type == 'mod1,mod2...' || $argument->type == 'SELECT')) {
                         $value = explode(',', $value);
                     }
 
@@ -1203,6 +1239,13 @@ class generator_form extends moodleform {
                 $type = 'select';
                 $options = $generator->modules_list;
                 $htmloptions = array('multiple' => 'multiple');
+            } elseif (!empty($setting->type) && $setting->type == 'SELECT') {
+                $type = 'select';
+                $options = array();
+                foreach ($setting->default as $option) {
+                    $options[$option] = $option;
+                }
+                $htmloptions = array('multiple' => 'multiple');
             } elseif (!empty($setting->type)) {
                 $type = 'text';
             }
index bb47d8cd59239a4d2c182740baf250f5d982c6cf..e9b93240a7efe1ff62485925ffc2eba3c8961d61 100644 (file)
@@ -16,12 +16,16 @@ class testAssignmentPortfolioCallers extends portfoliolib_test {
         global $DB, $USER;
 
         parent::setUp();
+        $assignment_types = new stdClass();
+        $assignment_types->type = GENERATOR_SEQUENCE;
+        $assignment_types->options = array('upload');
 
-        $settings = array('quiet' => 1, 'pre_cleanup' => 1,
+        $settings = array('quiet' => 1,
                           'modules_list' => array($this->module_type), 'assignment_grades' => true,
-                          'assignment_type' => 'online',
+                          'assignment_type' => $assignment_types,
                           'number_of_students' => 5, 'students_per_course' => 5, 'number_of_sections' => 1,
-                          'number_of_modules' => 1, 'questions_per_course' => 0);
+                          'number_of_modules' => 3, 'questions_per_course' => 0);
+
         generator_generate_data($settings);
 
         $this->modules = $DB->get_records($this->module_type);
index 08e6de96d21e295c67d25f4bacc6b6041d9a2afd..992ba35740c6d8af6b4463ca67e831a3e6cb10fa 100644 (file)
@@ -1,5 +1,5 @@
 <?php // $Id$
-require_once($CFG->libdir.'/simpletest/testportfoliolib.php');
+require_once($CFG->libdir.'/simpletest/portfolio_testclass.php');
 require_once($CFG->dirroot.'/mod/resource/lib.php');
 require_once($CFG->dirroot.'/admin/generator.php');
 
@@ -17,10 +17,15 @@ class testResourcePortfolioCallers extends portfoliolib_test {
 
         parent::setUp();
 
+        $resource_type = new stdClass();
+        $resource_type->type = GENERATOR_SEQUENCE;
+        $resource_type->options = array('file', 'text', 'html');
+
         $settings = array('quiet' => 1, 'pre_cleanup' => 1,
                           'modules_list' => array($this->module_type),
+                          'resource_type' => $resource_type,
                           'number_of_students' => 15, 'students_per_course' => 15, 'number_of_sections' => 1,
-                          'number_of_modules' => 1, 'messages_per_resource' => 15);
+                          'number_of_modules' => 3);
 
         generator_generate_data($settings);