Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 141... Línea 141...
141
     * Create a test user
141
     * Create a test user
142
     * @param array|stdClass $record
142
     * @param array|stdClass $record
143
     * @param array $options
143
     * @param array $options
144
     * @return stdClass user record
144
     * @return stdClass user record
145
     */
145
     */
146
    public function create_user($record=null, array $options=null) {
146
    public function create_user($record=null, ?array $options=null) {
147
        global $DB, $CFG;
147
        global $DB, $CFG;
148
        require_once($CFG->dirroot.'/user/lib.php');
148
        require_once($CFG->dirroot.'/user/lib.php');
Línea 149... Línea 149...
149
 
149
 
150
        $this->usercounter++;
150
        $this->usercounter++;
Línea 275... Línea 275...
275
     * Create a test course category
275
     * Create a test course category
276
     * @param array|stdClass $record
276
     * @param array|stdClass $record
277
     * @param array $options
277
     * @param array $options
278
     * @return core_course_category course category record
278
     * @return core_course_category course category record
279
     */
279
     */
280
    public function create_category($record=null, array $options=null) {
280
    public function create_category($record=null, ?array $options=null) {
281
        $this->categorycount++;
281
        $this->categorycount++;
282
        $i = $this->categorycount;
282
        $i = $this->categorycount;
Línea 283... Línea 283...
283
 
283
 
Línea 302... Línea 302...
302
     * Create test cohort.
302
     * Create test cohort.
303
     * @param array|stdClass $record
303
     * @param array|stdClass $record
304
     * @param array $options
304
     * @param array $options
305
     * @return stdClass cohort record
305
     * @return stdClass cohort record
306
     */
306
     */
307
    public function create_cohort($record=null, array $options=null) {
307
    public function create_cohort($record=null, ?array $options=null) {
308
        global $DB, $CFG;
308
        global $DB, $CFG;
309
        require_once("$CFG->dirroot/cohort/lib.php");
309
        require_once("$CFG->dirroot/cohort/lib.php");
Línea 310... Línea 310...
310
 
310
 
311
        $this->cohortcount++;
311
        $this->cohortcount++;
Línea 352... Línea 352...
352
     *      'initsections' => bool for section name initialization, renaming them to "Section X". Default value is 0 (false).
352
     *      'initsections' => bool for section name initialization, renaming them to "Section X". Default value is 0 (false).
353
     * @param array $options with keys:
353
     * @param array $options with keys:
354
     *      'createsections' => bool precreate all sections
354
     *      'createsections' => bool precreate all sections
355
     * @return stdClass course record
355
     * @return stdClass course record
356
     */
356
     */
357
    public function create_course($record=null, array $options=null) {
357
    public function create_course($record=null, ?array $options=null) {
358
        global $DB, $CFG;
358
        global $DB, $CFG;
359
        require_once("$CFG->dirroot/course/lib.php");
359
        require_once("$CFG->dirroot/course/lib.php");
Línea 360... Línea 360...
360
 
360
 
361
        $this->coursecount++;
361
        $this->coursecount++;
Línea 459... Línea 459...
459
     * @param array|stdClass $record must contain 'course' and 'section' attributes
459
     * @param array|stdClass $record must contain 'course' and 'section' attributes
460
     * @param array|null $options
460
     * @param array|null $options
461
     * @return section_info
461
     * @return section_info
462
     * @throws coding_exception
462
     * @throws coding_exception
463
     */
463
     */
464
    public function create_course_section($record = null, array $options = null) {
464
    public function create_course_section($record = null, ?array $options = null) {
465
        global $DB;
465
        global $DB;
Línea 466... Línea 466...
466
 
466
 
Línea 467... Línea 467...
467
        $record = (array)$record;
467
        $record = (array)$record;
Línea 517... Línea 517...
517
     * @param array|stdClass $record data, as if from the module edit settings form.
517
     * @param array|stdClass $record data, as if from the module edit settings form.
518
     * @param array $options additional data that may affect how the module is created.
518
     * @param array $options additional data that may affect how the module is created.
519
     * @return stdClass activity record new new record that was just inserted in the table
519
     * @return stdClass activity record new new record that was just inserted in the table
520
     *      like 'forum' or 'quiz', with a ->cmid field added.
520
     *      like 'forum' or 'quiz', with a ->cmid field added.
521
     */
521
     */
522
    public function create_module($modulename, $record=null, array $options=null) {
522
    public function create_module($modulename, $record=null, ?array $options=null) {
523
        $generator = $this->get_plugin_generator('mod_'.$modulename);
523
        $generator = $this->get_plugin_generator('mod_'.$modulename);
524
        return $generator->create_instance($record, $options);
524
        return $generator->create_instance($record, $options);
525
    }
525
    }
Línea 526... Línea 526...
526
 
526
 
Línea 692... Línea 692...
692
     * @param array|stdClass $record data to use to up set the instance.
692
     * @param array|stdClass $record data to use to up set the instance.
693
     * @param array $options options
693
     * @param array $options options
694
     * @return stdClass repository instance record
694
     * @return stdClass repository instance record
695
     * @since Moodle 2.5.1
695
     * @since Moodle 2.5.1
696
     */
696
     */
697
    public function create_repository($type, $record=null, array $options = null) {
697
    public function create_repository($type, $record=null, ?array $options = null) {
698
        $generator = $this->get_plugin_generator('repository_'.$type);
698
        $generator = $this->get_plugin_generator('repository_'.$type);
699
        return $generator->create_instance($record, $options);
699
        return $generator->create_instance($record, $options);
700
    }
700
    }
Línea 701... Línea 701...
701
 
701
 
Línea 706... Línea 706...
706
     * @param array|stdClass $record data to use to up set the instance.
706
     * @param array|stdClass $record data to use to up set the instance.
707
     * @param array $options options
707
     * @param array $options options
708
     * @return repository_type object
708
     * @return repository_type object
709
     * @since Moodle 2.5.1
709
     * @since Moodle 2.5.1
710
     */
710
     */
711
    public function create_repository_type($type, $record=null, array $options = null) {
711
    public function create_repository_type($type, $record=null, ?array $options = null) {
712
        $generator = $this->get_plugin_generator('repository_'.$type);
712
        $generator = $this->get_plugin_generator('repository_'.$type);
713
        return $generator->create_type($record, $options);
713
        return $generator->create_type($record, $options);
714
    }
714
    }
Línea 718... Línea 718...
718
     * Create a test scale
718
     * Create a test scale
719
     * @param array|stdClass $record
719
     * @param array|stdClass $record
720
     * @param array $options
720
     * @param array $options
721
     * @return stdClass block instance record
721
     * @return stdClass block instance record
722
     */
722
     */
723
    public function create_scale($record=null, array $options=null) {
723
    public function create_scale($record=null, ?array $options=null) {
724
        global $DB;
724
        global $DB;
Línea 725... Línea 725...
725
 
725
 
726
        $this->scalecount++;
726
        $this->scalecount++;
Línea 894... Línea 894...
894
     *
894
     *
895
     * @param int $roleid The Role to set capabilities for
895
     * @param int $roleid The Role to set capabilities for
896
     * @param array $rolecapabilities The list of capability =>permission to set for this role
896
     * @param array $rolecapabilities The list of capability =>permission to set for this role
897
     * @param null|context $context The context to apply this capability to
897
     * @param null|context $context The context to apply this capability to
898
     */
898
     */
899
    public function create_role_capability(int $roleid, array $rolecapabilities, context $context = null): void {
899
    public function create_role_capability(int $roleid, array $rolecapabilities, ?context $context = null): void {
900
        // Map the capabilities into human-readable names.
900
        // Map the capabilities into human-readable names.
901
        $allpermissions = [
901
        $allpermissions = [
902
            'inherit' => CAP_INHERIT,
902
            'inherit' => CAP_INHERIT,
903
            'allow' => CAP_ALLOW,
903
            'allow' => CAP_ALLOW,
904
            'prevent' => CAP_PREVENT,
904
            'prevent' => CAP_PREVENT,
Línea 999... Línea 999...
999
     * @return array updated $record.
999
     * @return array updated $record.
1000
     */
1000
     */
1001
    public function combine_defaults_and_record(array $defaults, $record) {
1001
    public function combine_defaults_and_record(array $defaults, $record) {
1002
        $record = (array) $record;
1002
        $record = (array) $record;
Línea 1003... Línea 1003...
1003
 
1003
 
1004
        foreach ($defaults as $key => $defaults) {
1004
        foreach ($defaults as $key => $default) {
1005
            if (!array_key_exists($key, $record)) {
1005
            if (!array_key_exists($key, $record)) {
-
 
1006
                $record[$key] = $default;
-
 
1007
            } else if (is_array($record[$key]) && is_array($default)) {
1006
                $record[$key] = $defaults;
1008
                $record[$key] = $this->combine_defaults_and_record($default, $record[$key]);
1007
            }
1009
            }
1008
        }
1010
        }
1009
        return $record;
1011
        return $record;
Línea 1529... Línea 1531...
1529
 
1531
 
1530
        return $DB->get_record('user_lastaccess', ['id' => $recordid], '*', MUST_EXIST);
1532
        return $DB->get_record('user_lastaccess', ['id' => $recordid], '*', MUST_EXIST);
Línea 1531... Línea 1533...
1531
    }
1533
    }
-
 
1534
 
-
 
1535
    /**
-
 
1536
     * Generate a stored_progress record and return the ID.
-
 
1537
     *
-
 
1538
     * All fields are optional, required fields will be generated if not supplied.
-
 
1539
     *
-
 
1540
     * @param ?string $idnumber The unique ID Number for this stored progress.
-
 
1541
     * @param ?int $timestart The time progress was started, defaults to now.
-
 
1542
     * @param ?int $lastupdate The time the progress was last updated.
-
 
1543
     * @param float $percent The percentage progress so far.
-
 
1544
     * @param ?string $message An error message.
-
 
1545
     * @param ?bool $haserrored Whether the process has encountered an error.
-
 
1546
     * @return stdClass The record including the inserted id.
-
 
1547
     * @throws dml_exception
-
 
1548
     */
-
 
1549
    public function create_stored_progress(
-
 
1550
        ?string $idnumber = null,
-
 
1551
        ?int $timestart = null,
-
 
1552
        ?int $lastupdate = null,
-
 
1553
        float $percent = 0.00,
-
 
1554
        ?string $message = null,
-
 
1555
        ?bool $haserrored = false,
-
 
1556
    ): stdClass {
-
 
1557
        global $DB;
-
 
1558
        $record = (object)[
-
 
1559
            'idnumber' => $idnumber ?? random_string(),
-
 
1560
            'timestart' => $timestart ?? time(),
-
 
1561
            'lastupdate' => $lastupdate,
-
 
1562
            'percentcompleted' => $percent,
-
 
1563
            'message' => $message,
-
 
1564
            'haserrored' => $haserrored,
-
 
1565
        ];
-
 
1566
        $record->id = $DB->insert_record('stored_progress', $record);
-
 
1567
        return $record;
-
 
1568
    }
-
 
1569
 
-
 
1570
    /**
-
 
1571
     * Generate a stored progress record from an array of fields.
-
 
1572
     *
-
 
1573
     * For use as a behat createable entity. Use {@see self::create_stored_progress()} if calling directly.
-
 
1574
     *
-
 
1575
     * @param array $data
-
 
1576
     * @return void
-
 
1577
     */
-
 
1578
    public function create_stored_progress_bar(array $data): void {
-
 
1579
        $this->create_stored_progress(
-
 
1580
            $data['idnumber'] ?? null,
-
 
1581
            $data['timestart'] ?? null,
-
 
1582
            $data['lastupdate'] ?? null,
-
 
1583
            $data['percent'] ?? 0.00,
-
 
1584
            $data['message'] ?? null,
-
 
1585
            $data['haserrored'] ?? false,
-
 
1586
        );
-
 
1587
    }
1532
 
1588
 
1533
    /**
1589
    /**
1534
     * Gets a default generator for a given component.
1590
     * Gets a default generator for a given component.
1535
     *
1591
     *
1536
     * @param string $component The component name, e.g. 'mod_forum' or 'core_question'.
1592
     * @param string $component The component name, e.g. 'mod_forum' or 'core_question'.