Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 72... Línea 72...
72
     */
72
     */
73
    public function find_course_areas(int $courseid): ?\moodle_recordset {
73
    public function find_course_areas(int $courseid): ?\moodle_recordset {
74
        global $DB;
74
        global $DB;
75
        $coursecontext = \context_course::instance($courseid);
75
        $coursecontext = \context_course::instance($courseid);
76
        $param = [
76
        $param = [
77
            'ctxcourse' => CONTEXT_COURSE,
-
 
78
            'courseid' => $courseid,
-
 
79
            'module' => CONTEXT_MODULE,
77
            'module' => CONTEXT_MODULE,
80
            'coursecontextpath' => $DB->sql_like_escape($coursecontext->path) . '/%',
78
            'coursecontextpath' => $DB->sql_like_escape($coursecontext->path) . '/%',
81
        ];
79
        ];
Línea 82... Línea 80...
82
 
80
 
Línea 94... Línea 92...
94
                    ON qbe.id = qv.questionbankentryid
92
                    ON qbe.id = qv.questionbankentryid
95
            INNER JOIN {question_categories} qc
93
            INNER JOIN {question_categories} qc
96
                    ON qc.id = qbe.questioncategoryid
94
                    ON qc.id = qbe.questioncategoryid
97
            INNER JOIN {context} ctx
95
            INNER JOIN {context} ctx
98
                    ON ctx.id = qc.contextid
96
                    ON ctx.id = qc.contextid
99
                 WHERE (ctx.contextlevel = :ctxcourse
-
 
100
                   AND ctx.id = qc.contextid
-
 
101
                   AND ctx.instanceid = :courseid)
-
 
102
                    OR (ctx.contextlevel = :module
97
                 WHERE ctx.contextlevel = :module
103
                   AND {$DB->sql_like('ctx.path', ':coursecontextpath')})
98
                   AND {$DB->sql_like('ctx.path', ':coursecontextpath')}
104
              ORDER BY q.id ASC";
99
              ORDER BY q.id ASC";
Línea 105... Línea 100...
105
 
100
 
106
        return $DB->get_recordset_sql($sql, $param);
101
        return $DB->get_recordset_sql($sql, $param);
Línea 107... Línea 102...
107
    }
102
    }
108
 
103
 
109
    /**
104
    /**
110
     * Return an array of area objects that contain content at the site and system levels only. This would be question content from
105
     * Return an array of area objects that contain content at the site and system levels only. This would be question content from
111
     * question categories at the system context only.
106
     * question categories at the system context only.
-
 
107
     *
-
 
108
     * @return \moodle_recordset
112
     *
109
     * @deprecated since Moodle 5.0.
-
 
110
     * @todo MDL-82413 Final deprecation in Moodle 6.0.
113
     * @return \moodle_recordset
111
     */
-
 
112
    #[\core\attribute\deprecated(null, since: '5.0', reason: 'This method should not be used', mdl: 'MDL-71378')]
114
     */
113
    public function find_system_areas(): ?\moodle_recordset {
115
    public function find_system_areas(): ?\moodle_recordset {
114
        \core\deprecation::emit_deprecation([self::class, __FUNCTION__]);
116
        global $DB;
115
        global $DB;
117
        $params = [
116
        $params = [
118
            'syscontext' => CONTEXT_SYSTEM,
117
            'syscontext' => CONTEXT_SYSTEM,
Línea 173... Línea 172...
173
    protected function get_course_and_cat_sql(\core\event\base $event): string {
172
    protected function get_course_and_cat_sql(\core\event\base $event): string {
174
        $courseid = 'null';
173
        $courseid = 'null';
175
        $catid = 'null';
174
        $catid = 'null';
Línea 176... Línea 175...
176
 
175
 
177
        if ($record = self::get_course_and_category(CONTEXT_MODULE, $event->objectid)) {
-
 
178
            if ($record->contextlevel == CONTEXT_MODULE) {
176
        if ($record = self::get_course_and_category(CONTEXT_MODULE, $event->objectid)) {
179
                $courseid = $record->courseid;
-
 
180
            } else if ($record->contextlevel == CONTEXT_COURSE) {
-
 
181
                $courseid = $record->instanceid;
-
 
182
            } else if ($record->contextlevel == CONTEXT_COURSECAT) {
-
 
183
                $catid = $record->instanceid;
-
 
184
            } else if ($record->contextlevel == CONTEXT_SYSTEM) {
-
 
185
                $courseid = 1;
-
 
186
            }
177
            $courseid = $record->courseid;
Línea 187... Línea 178...
187
        }
178
        }
188
 
179
 
189
        return "
180
        return "
Línea 200... Línea 191...
200
     * @return \stdClass|false
191
     * @return \stdClass|false
201
     */
192
     */
202
    public static function get_course_and_category($coursemodule, $refid) {
193
    public static function get_course_and_category($coursemodule, $refid) {
203
        global $DB;
194
        global $DB;
Línea -... Línea 195...
-
 
195
 
-
 
196
        if ($coursemodule !== CONTEXT_MODULE) {
-
 
197
            debugging("Invalid contextlevel: ($coursemodule}", DEBUG_DEVELOPER);
-
 
198
        }
204
 
199
 
205
        $sql = 'SELECT ctx.instanceid,
200
        $sql = 'SELECT ctx.instanceid,
206
                       cm.course as courseid,
201
                       cm.course as courseid,
207
                       ctx.contextlevel
202
                       ctx.contextlevel
208
                  FROM {question} q
203
                  FROM {question} q
Línea 212... Línea 207...
212
                    ON qbe.id = qv.questionbankentryid
207
                    ON qbe.id = qv.questionbankentryid
213
            INNER JOIN {question_categories} qc
208
            INNER JOIN {question_categories} qc
214
                    ON qc.id = qbe.questioncategoryid
209
                    ON qc.id = qbe.questioncategoryid
215
            INNER JOIN {context} ctx
210
            INNER JOIN {context} ctx
216
                    ON ctx.id = qc.contextid
211
                    ON ctx.id = qc.contextid
217
             LEFT JOIN {course_modules} cm
212
            INNER JOIN {course_modules} cm
218
                    ON cm.id = ctx.instanceid
213
                    ON cm.id = ctx.instanceid
219
                   AND ctx.contextlevel = :coursemodule
214
                   AND ctx.contextlevel = :coursemodule
220
                 WHERE q.id = :refid';
215
                 WHERE q.id = :refid';
221
        $params = [
216
        $params = [
222
                'coursemodule' => $coursemodule,
217
                'coursemodule' => $coursemodule,