Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 97... Línea 97...
97
                                        WHERE qc.id {$usql} {$npsql} {$version}
97
                                        WHERE qc.id {$usql} {$npsql} {$version}
98
                                     ORDER BY qc.id, q.qtype, q.name", $params);
98
                                     ORDER BY qc.id, q.qtype, q.name", $params);
Línea 99... Línea 99...
99
 
99
 
100
    // Iterate through questions, getting stuff we need.
100
    // Iterate through questions, getting stuff we need.
101
    $qresults = [];
101
    $qresults = [];
102
    foreach($questions as $key => $question) {
102
    foreach ($questions as $question) {
-
 
103
        $question->export_process = $export;
103
        $question->export_process = $export;
104
        $question->categoryobject = $category;
104
        $qtype = question_bank::get_qtype($question->qtype, false);
105
        $qtype = question_bank::get_qtype($question->qtype, false);
105
        if ($export && $qtype->name() === 'missingtype') {
106
        if ($export && $qtype->name() === 'missingtype') {
106
            // Unrecognised question type. Skip this question when exporting.
107
            // Unrecognised question type. Skip this question when exporting.
107
            continue;
108
            continue;
Línea 115... Línea 116...
115
 
116
 
116
/**
117
/**
117
 * Common setup for all pages for editing questions.
118
 * Common setup for all pages for editing questions.
118
 * @param string $baseurl the name of the script calling this funciton. For examle 'qusetion/edit.php'.
119
 * @param string $baseurl the name of the script calling this funciton. For examle 'qusetion/edit.php'.
119
 * @param string $edittab code for this edit tab
120
 * @param string $edittab code for this edit tab
120
 * @param bool $requirecmid require cmid? default false
121
 * @param bool $requirecmid This parameter has been deprecated since 4.5 and should not be used anymore.
121
 * @param bool $unused no longer used, do no pass
122
 * @param bool $unused no longer used, do no pass
122
 * @return array $thispageurl, $contexts, $cmid, $cm, $module, $pagevars
123
 * @return array $thispageurl, $contexts, $cmid, $cm, $module, $pagevars
123
 */
124
 */
124
function question_edit_setup($edittab, $baseurl, $requirecmid = false, $unused = null) {
125
function question_edit_setup($edittab, $baseurl, $requirecmid = null, $unused = null) {
Línea 125... Línea 126...
125
    global $PAGE;
126
    global $PAGE;
126
 
127
 
127
    if ($unused !== null) {
128
    if ($unused !== null || $requirecmid !== null) {
Línea 128... Línea 129...
128
        debugging('Deprecated argument passed to question_edit_setup()', DEBUG_DEVELOPER);
129
        debugging('Deprecated argument passed to question_edit_setup()', DEBUG_DEVELOPER);
Línea 129... Línea -...
129
    }
-
 
130
 
130
    }
131
    $params = [];
-
 
132
 
-
 
133
    if ($requirecmid) {
-
 
134
        $params['cmid'] = required_param('cmid', PARAM_INT);
-
 
135
    } else {
-
 
136
        $params['cmid'] = optional_param('cmid', null, PARAM_INT);
-
 
137
    }
-
 
138
 
-
 
139
    if (!$params['cmid']) {
131
 
Línea 140... Línea 132...
140
        $params['courseid'] = required_param('courseid', PARAM_INT);
132
    $params = [];
141
    }
133
 
142
 
134
    $params['cmid'] = required_param('cmid', PARAM_INT);
Línea 165... Línea 157...
165
 
157
 
166
/**
158
/**
167
 * Common function for building the generic resources required by the
159
 * Common function for building the generic resources required by the
168
 * editing questions pages.
160
 * editing questions pages.
169
 *
-
 
170
 * Either a cmid or a course id must be provided as keys in $params or
161
 *
171
 * an exception will be thrown. All other params are optional and will have
162
 * A cmid must be provided as a key in $params or an exception will be thrown.
172
 * sane default applied if not provided.
163
 * All other params are optional and will have sane default applied if not provided.
173
 *
164
 *
174
 * The acceptable keys for $params are:
165
 * The acceptable keys for $params are:
175
 * [
166
 * [
176
 *      'cmid' => PARAM_INT,
-
 
177
 *      'courseid' => PARAM_INT,
167
 *      'cmid' => PARAM_INT,
178
 *      'qpage' => PARAM_INT,
168
 *      'qpage' => PARAM_INT,
179
 *      'cat' => PARAM_SEQUENCE,
169
 *      'cat' => PARAM_SEQUENCE,
180
 *      'category' => PARAM_SEQUENCE,
170
 *      'category' => PARAM_SEQUENCE,
181
 *      'qperpage' => PARAM_INT,
171
 *      'qperpage' => PARAM_INT,
Línea 207... Línea 197...
207
        'sortdata' => [],
197
        'sortdata' => [],
208
        'filter' => null
198
        'filter' => null
209
    ];
199
    ];
210
    $paramtypes = [
200
    $paramtypes = [
211
        'cmid' => PARAM_INT,
201
        'cmid' => PARAM_INT,
212
        'courseid' => PARAM_INT,
-
 
213
        'qpage' => PARAM_INT,
202
        'qpage' => PARAM_INT,
214
        'cat' => PARAM_SEQUENCE,
203
        'cat' => PARAM_SEQUENCE,
215
        'category' => PARAM_SEQUENCE,
204
        'category' => PARAM_SEQUENCE,
216
        'qperpage' => PARAM_INT,
205
        'qperpage' => PARAM_INT,
217
        'cpage' => PARAM_INT,
206
        'cpage' => PARAM_INT,
Línea 227... Línea 216...
227
 
216
 
228
    if (!empty($params['filter'])) {
217
    if (!empty($params['filter'])) {
229
        if (!is_array($params['filter'])) {
218
        if (!is_array($params['filter'])) {
230
            $params['filter'] = json_decode($params['filter'], true);
219
            $params['filter'] = json_decode($params['filter'], true);
231
        }
220
        }
-
 
221
        $cleanparams['filter'] = [];
-
 
222
        foreach ($params['filter'] as $filterkey => $filtervalue) {
-
 
223
            if ($filterkey == 'jointype') {
-
 
224
                $cleanparams['filter']['jointype'] = clean_param($filtervalue, PARAM_INT);
-
 
225
            } else {
-
 
226
                if (!array_key_exists('name', $filtervalue)) {
-
 
227
                    $filtervalue['name'] = $filterkey;
-
 
228
                }
-
 
229
                $cleanfilter = [
-
 
230
                    'name' => clean_param($filtervalue['name'], PARAM_ALPHANUM),
-
 
231
                    'jointype' => clean_param($filtervalue['jointype'], PARAM_INT),
-
 
232
                    'values' => $filtervalue['values'],
-
 
233
                    'filteroptions' => $filtervalue['filteroptions'] ?? [],
-
 
234
                ];
-
 
235
                $cleanparams['filter'][$filterkey] = $cleanfilter;
-
 
236
            }
232
        $cleanparams['filter'] = $params['filter'];
237
        }
Línea 233... Línea 238...
233
    }
238
    }
234
 
239
 
235
    if (isset($params['sortdata'])) {
240
    if (isset($params['sortdata'])) {
Línea 236... Línea 241...
236
        $cleanparams['sortdata'] = clean_param_array($params['sortdata'], PARAM_INT);
241
        $cleanparams['sortdata'] = clean_param_array($params['sortdata'], PARAM_INT);
237
    }
-
 
238
 
242
    }
239
    $cmid = $cleanparams['cmid'];
243
 
240
    $courseid = $cleanparams['courseid'];
244
    $cmid = $cleanparams['cmid'];
241
    $qpage = $cleanparams['qpage'] ?: -1;
245
    $qpage = $cleanparams['qpage'] ?: -1;
242
    $cat = $cleanparams['cat'] ?: 0;
246
    $cat = $cleanparams['cat'] ?: 0;
Línea 243... Línea 247...
243
    $category = $cleanparams['category'] ?: 0;
247
    $category = $cleanparams['category'] ?: 0;
244
    $qperpage = $cleanparams['qperpage'];
248
    $qperpage = $cleanparams['qperpage'];
245
    $cpage = $cleanparams['cpage'] ?: 1;
249
    $cpage = $cleanparams['cpage'] ?: 1;
Línea 246... Línea -...
246
 
-
 
247
    if (is_null($cmid) && is_null($courseid)) {
250
 
248
        throw new \moodle_exception('Must provide a cmid or courseid');
251
    if (is_null($cmid)) {
249
    }
252
        throw new \moodle_exception('Must provide a cmid');
250
 
253
    }
251
    if ($cmid) {
-
 
252
        list($module, $cm) = get_module_from_cmid($cmid);
-
 
253
        $courseid = $cm->course;
-
 
254
        $thispageurl->params(compact('cmid'));
-
 
255
        $thiscontext = context_module::instance($cmid);
-
 
256
    } else {
-
 
Línea 257... Línea 254...
257
        $module = null;
254
 
258
        $cm = null;
255
    list($module, $cm) = get_module_from_cmid($cmid);
259
        $thispageurl->params(compact('courseid'));
256
    $courseid = $cm->course;
260
        $thiscontext = context_course::instance($courseid);
257
    $thispageurl->params(compact('cmid'));
Línea 305... Línea 302...
305
                'qperpage', $qperpage, DEFAULT_QUESTIONS_PER_PAGE, $thispageurl);
302
                'qperpage', $qperpage, DEFAULT_QUESTIONS_PER_PAGE, $thispageurl);
306
    } else {
303
    } else {
307
        $pagevars['qperpage'] = $qperpage ?? $defaultquestionsperpage;
304
        $pagevars['qperpage'] = $qperpage ?? $defaultquestionsperpage;
308
    }
305
    }
Línea 309... Línea 306...
309
 
306
 
Línea 310... Línea 307...
310
    $defaultcategory = question_make_default_categories($contexts->all());
307
    $defaultcategory = question_get_default_category($contexts->lowest()->id, true);
311
 
308
 
312
    $contextlistarr = [];
309
    $contextlistarr = [];
313
    foreach ($contexts->having_one_edit_tab_cap($edittab) as $context){
310
    foreach ($contexts->having_one_edit_tab_cap($edittab) as $context){