[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/mod/workshop/tests/generator/ -> lib.php (source)

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * mod_workshop data generator.
  19   *
  20   * @package    mod_workshop
  21   * @category   test
  22   * @copyright  2013 Marina Glancy
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  /**
  29   * mod_workshop data generator class.
  30   *
  31   * @package    mod_workshop
  32   * @category   test
  33   * @copyright  2013 Marina Glancy
  34   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  35   */
  36  class mod_workshop_generator extends testing_module_generator {
  37  
  38      public function create_instance($record = null, array $options = null) {
  39          global $CFG;
  40          require_once($CFG->libdir.'/filelib.php');
  41  
  42          $workshopconfig = get_config('workshop');
  43  
  44          // Add default values for workshop.
  45          $record = (array)$record + array(
  46              'strategy' => $workshopconfig->strategy,
  47              'grade' => $workshopconfig->grade,
  48              'gradinggrade' => $workshopconfig->gradinggrade,
  49              'gradedecimals' => $workshopconfig->gradedecimals,
  50              'nattachments' => 1,
  51              'maxbytes' => $workshopconfig->maxbytes,
  52              'latesubmissions' => 0,
  53              'useselfassessment' => 0,
  54              'overallfeedbackmode' => 1,
  55              'overallfeedbackfiles' => 0,
  56              'overallfeedbackmaxbytes' => $workshopconfig->maxbytes,
  57              'useexamples' => 0,
  58              'examplesmode' => $workshopconfig->examplesmode,
  59              'submissionstart' => 0,
  60              'submissionend' => 0,
  61              'phaseswitchassessment' => 0,
  62              'assessmentstart' => 0,
  63              'assessmentend' => 0,
  64          );
  65          if (!isset($record['gradecategory']) || !isset($record['gradinggradecategory'])) {
  66              require_once($CFG->libdir.'/gradelib.php');
  67              $courseid = is_object($record['course']) ? $record['course']->id : $record['course'];
  68              $gradecategories = grade_get_categories_menu($courseid);
  69              reset($gradecategories);
  70              $defaultcategory = key($gradecategories);
  71              $record += array(
  72                  'gradecategory' => $defaultcategory,
  73                  'gradinggradecategory' => $defaultcategory
  74              );
  75          }
  76          if (!isset($record['instructauthorseditor'])) {
  77              $record['instructauthorseditor'] = array(
  78                  'text' => 'Instructions for submission '.($this->instancecount+1),
  79                  'format' => FORMAT_MOODLE,
  80                  'itemid' => file_get_unused_draft_itemid()
  81              );
  82          }
  83          if (!isset($record['instructreviewerseditor'])) {
  84              $record['instructreviewerseditor'] = array(
  85                  'text' => 'Instructions for assessment '.($this->instancecount+1),
  86                  'format' => FORMAT_MOODLE,
  87                  'itemid' => file_get_unused_draft_itemid()
  88              );
  89          }
  90          if (!isset($record['conclusioneditor'])) {
  91              $record['conclusioneditor'] = array(
  92                  'text' => 'Conclusion '.($this->instancecount+1),
  93                  'format' => FORMAT_MOODLE,
  94                  'itemid' => file_get_unused_draft_itemid()
  95              );
  96          }
  97  
  98          return parent::create_instance($record, (array)$options);
  99      }
 100  
 101      /**
 102       * Generates a submission authored by the given user.
 103       *
 104       * @param int $workshopid Workshop instance id.
 105       * @param int $authorid Author user id.
 106       * @param stdClass|array $options Optional explicit properties.
 107       * @return int The new submission id.
 108       */
 109      public function create_submission($workshopid, $authorid, $options = null) {
 110          global $DB;
 111  
 112          $timenow = time();
 113          $options = (array)$options;
 114  
 115          $record = $options + array(
 116              'workshopid' => $workshopid,
 117              'example' => 0,
 118              'authorid' => $authorid,
 119              'timecreated' => $timenow,
 120              'timemodified' => $timenow,
 121              'title' => 'Generated submission',
 122              'content' => 'Generated content',
 123              'contentformat' => FORMAT_MARKDOWN,
 124              'contenttrust' => 0,
 125          );
 126  
 127          $id = $DB->insert_record('workshop_submissions', $record);
 128  
 129          return $id;
 130      }
 131  
 132      /**
 133       * Generates an allocation of the given submission for peer-assessment by the given user
 134       *
 135       * @param int $submissionid Submission id.
 136       * @param int $reviewerid Reviewer's user id.
 137       * @param stdClass|array $options Optional explicit properties.
 138       * @return int The new assessment id.
 139       */
 140      public function create_assessment($submissionid, $reviewerid, $options = null) {
 141          global $DB;
 142  
 143          $timenow = time();
 144          $options = (array)$options;
 145  
 146          $record = $options + array(
 147              'submissionid' => $submissionid,
 148              'reviewerid' => $reviewerid,
 149              'weight' => 1,
 150              'timecreated' => $timenow,
 151              'timemodified' => $timenow,
 152              'grade' => null,
 153          );
 154  
 155          $id = $DB->insert_record('workshop_assessments', $record);
 156  
 157          return $id;
 158      }
 159  }


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1