Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
namespace core_courseformat\local;
18
 
19
use core_courseformat\base as course_format;
20
use section_info;
21
use cm_info;
22
use stdClass;
23
 
24
/**
25
 * Format base actions.
26
 *
27
 * This class defined the format actions base class extended by the course, section and cm actions.
28
 *
29
 * It also provides helpers to get the most recent modinfo and format information. Those
30
 * convenience methods are meant to improve the actions readability and prevent excessive
31
 * message chains.
32
 *
33
 * @package    core_courseformat
34
 * @copyright  2023 Ferran Recio <ferran@moodle.com>
35
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36
 */
37
class baseactions {
38
    /**
39
     * @var stdClass the course object.
40
     */
41
    protected stdClass $course;
42
 
43
    /**
44
     * Constructor.
45
     * @param stdClass $course the course object.
46
     */
47
    public function __construct(stdClass $course) {
48
        $this->course = $course;
49
    }
50
 
51
    /**
52
     * Get the course.
53
     * @return stdClass the course object.
54
     */
55
    protected function get_course(): stdClass {
56
        return $this->course;
57
    }
58
 
59
    /**
60
     * Get the course format.
61
     * @return course_format the course format.
62
     */
63
    protected function get_format(): course_format {
64
        return course_format::instance($this->course);
65
    }
66
 
67
    /**
68
     * Get the section info.
69
     * @param int $sectionid the section id.
70
     * @param int $strictness Use MUST_EXIST to throw exception if it doesn't
71
     * @return section_info|null Information for numbered section or null if not found
72
     */
73
    protected function get_section_info($sectionid, int $strictness = IGNORE_MISSING): ?section_info {
74
        // Course actions must always get the most recent version of the section info.
75
        return get_fast_modinfo($this->course->id)->get_section_info_by_id($sectionid, $strictness);
76
    }
77
 
78
    /**
79
     * Get the cm info.
80
     * @param int $cmid the cm id.
81
     * @return cm_info|null Information for numbered cm or null if not found
82
     */
83
    protected function get_cm_info($cmid): ?cm_info {
84
        // Course actions must always get the most recent version of the cm info.
85
        return get_fast_modinfo($this->course->id)->get_cm($cmid);
86
    }
87
}