Example #1
0
 /**
  * Adds a new discussion to the specified forum.
  *
  * @return the discussion id
  */
 public function execute()
 {
     // Forum functions needed.
     global $CFG;
     require_once $CFG->dirroot . '/mod/forum/lib.php';
     // Getting moodle's data generator.
     $generator = get_data_generator();
     // Compulsory and optional attrs.
     $discussiondata = new \stdClass();
     $discussiondata->course = $this->arguments[0];
     $discussiondata->forum = $this->arguments[1];
     $discussiondata->userid = $this->arguments[2];
     foreach ($this->discussionoptions as $key => $values) {
         if (!empty($this->expandedOptions[$key])) {
             $discussiondata->{$key} = $this->expandedOptions[$key];
         }
     }
     $discussiondata->name = $discussiondata->subject;
     $forumgenerator = $generator->get_plugin_generator('mod_forum');
     $record = $forumgenerator->create_discussion($discussiondata);
     if ($this->verbose) {
         echo "Discussion {$record->name} successfully added\n";
     }
     echo "{$record->id}\n";
 }
Example #2
0
 /**
  * Uses the data generator to create module instances.
  *
  * @return Displays the activity id (not the course module, it depends on the activity type).
  */
 public function execute()
 {
     // Getting moodle's data generator.
     $generator = get_data_generator();
     // All data provided by the data generator.
     /*
             * @param array|stdClass $record data for module being generated. Requires 'course' key
             *     (an id or the full object). Also can have any fields from add module form.
             * @param null|array $options general options for course module. Since 2.6 it is
             *     possible to omit this argument by merging options into $record
     */
     $moduledata = new \stdClass();
     $moduledata->course = $this->arguments[1];
     $moduledata->requiresubmissionstatement = 1;
     // $options are course module options.
     $options = $this->expandedOptions;
     if (!empty($options['name'])) {
         $moduledata->name = $options['name'];
     }
     if (!empty($options['idnumber'])) {
         $moduledata->idnumber = $options['idnumber'];
     }
     $moduledata->section = $options['section'];
     $record = $generator->create_module($this->arguments[0], $moduledata);
     if ($this->verbose) {
         echo "Activity {$this->arguments[0]} created successfully\n";
     }
     // Return the activity id.
     echo "{$record->id}\n";
 }
Example #3
0
 /**
  * Uses the data generator to create module instances.
  *
  * @return Displays the activity id (not the course module, it depends on the activity type).
  */
 public function execute()
 {
     // Getting moodle's data generator.
     $generator = get_data_generator();
     // All data provided by the data generator.
     $moduledata = new \stdClass();
     $moduledata->course = $this->arguments[1];
     // $options are course module options.
     $options = $this->expandedOptions;
     // Name is a module instance attr.
     if (!empty($options['name'])) {
         $moduledata->name = $options['name'];
         unset($options['name']);
     }
     $record = $generator->create_module($this->arguments[0], $moduledata, $options);
     if ($this->verbose) {
         echo "Activity {$this->arguments[0]} created successfully\n";
     }
     // Return the activity id.
     echo "{$record->id}\n";
 }