Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 88... Línea 88...
88
    public $origin;
88
    public $origin;
Línea 89... Línea 89...
89
 
89
 
90
    /** @var int group id */
90
    /** @var int group id */
Línea -... Línea 91...
-
 
91
    public $groupid;
-
 
92
 
-
 
93
    /** @var int forces the use of a course filter in site context */
91
    public $groupid;
94
    public $sitecoursefilter;
92
 
95
 
Línea 93... Línea -...
93
    /** @var table_log table log which will be used for rendering logs */
-
 
94
    public $tablelog;
96
    /** @var table_log table log which will be used for rendering logs */
95
 
97
    public $tablelog;
-
 
98
 
96
    /**
99
    /** @var array Index of delegated sections (indexed by component and itemid) */
97
     * @var array group ids
-
 
98
     * @deprecated since Moodle 4.4 - please do not use this public property
100
    protected $delegatedbycm;
Línea 99... Línea 101...
99
     * @todo MDL-81155 remove this property as it is not used anymore.
101
 
100
     */
102
    /** @var bool if the page is activity page */
101
    public $grouplist;
103
    public $isactivitypage;
102
 
104
 
Línea 118... Línea 120...
118
     * @param int $date date (optional) timestamp of start of the day for which logs will be displayed.
120
     * @param int $date date (optional) timestamp of start of the day for which logs will be displayed.
119
     * @param string $logformat log format.
121
     * @param string $logformat log format.
120
     * @param int $page (optional) page number.
122
     * @param int $page (optional) page number.
121
     * @param int $perpage (optional) number of records to show per page.
123
     * @param int $perpage (optional) number of records to show per page.
122
     * @param string $order (optional) sortorder of fetched records
124
     * @param string $order (optional) sortorder of fetched records
-
 
125
     * @param string $origin (optional) origin of the event.
-
 
126
     * @param bool $isactivitypage (optional) if the page is activity page.
-
 
127
     * @param int $sitecoursefilter (optional) use a course filter in site context.
123
     */
128
     */
124
    public function __construct($logreader = "", $course = 0, $userid = 0, $modid = 0, $action = "", $groupid = 0, $edulevel = -1,
129
    public function __construct(
-
 
130
        $logreader = "",
-
 
131
        $course = 0,
-
 
132
        $userid = 0,
-
 
133
        $modid = 0,
-
 
134
        $action = "",
-
 
135
        $groupid = 0,
-
 
136
        $edulevel = -1,
-
 
137
        $showcourses = false,
-
 
138
        $showusers = false,
-
 
139
        $showreport = true,
125
            $showcourses = false, $showusers = false, $showreport = true, $showselectorform = true, $url = "", $date = 0,
140
        $showselectorform = true,
-
 
141
        $url = "",
-
 
142
        $date = 0,
-
 
143
        $logformat='showashtml',
-
 
144
        $page = 0,
-
 
145
        $perpage = 100,
126
            $logformat='showashtml', $page = 0, $perpage = 100, $order = "timecreated ASC", $origin ='') {
146
        $order = "timecreated ASC",
-
 
147
        $origin ='',
-
 
148
        bool $isactivitypage = false,
-
 
149
        $sitecoursefilter = 0,
-
 
150
    ) {
Línea 127... Línea 151...
127
 
151
 
Línea 128... Línea 152...
128
        global $PAGE;
152
        global $PAGE, $SITE;
129
 
153
 
130
        // Use first reader as selected reader, if not passed.
154
        // Use first reader as selected reader, if not passed.
131
        if (empty($logreader)) {
155
        if (empty($logreader)) {
Línea 146... Línea 170...
146
        $this->selectedlogreader = $logreader;
170
        $this->selectedlogreader = $logreader;
147
        $url->param('logreader', $logreader);
171
        $url->param('logreader', $logreader);
Línea 148... Línea 172...
148
 
172
 
149
        // Use site course id, if course is empty.
173
        // Use site course id, if course is empty.
-
 
174
        if (!empty($course) && is_int($course)) {
-
 
175
            $courseid = $course;
150
        if (!empty($course) && is_int($course)) {
176
            try {
-
 
177
                $course = get_course($courseid);
-
 
178
            } catch (dml_missing_record_exception) {
-
 
179
                // Missing courses may have be deleted, so display them in site context.
-
 
180
                $course = $SITE;
-
 
181
                $sitecoursefilter = $courseid;
151
            $course = get_course($course);
182
            }
152
        }
183
        }
Línea 153... Línea 184...
153
        $this->course = $course;
184
        $this->course = $course;
154
 
185
 
Línea 166... Línea 197...
166
        $this->showusers = $showusers;
197
        $this->showusers = $showusers;
167
        $this->showreport = $showreport;
198
        $this->showreport = $showreport;
168
        $this->showselectorform = $showselectorform;
199
        $this->showselectorform = $showselectorform;
169
        $this->logformat = $logformat;
200
        $this->logformat = $logformat;
170
        $this->origin = $origin;
201
        $this->origin = $origin;
-
 
202
        $this->isactivitypage = $isactivitypage;
-
 
203
        $this->sitecoursefilter = $sitecoursefilter;
171
    }
204
    }
Línea 172... Línea 205...
172
 
205
 
173
    /**
206
    /**
174
     * Get a list of enabled sql_reader objects/name
207
     * Get a list of enabled sql_reader objects/name
Línea 194... Línea 227...
194
     * Helper function to return list of activities to show in selection filter.
227
     * Helper function to return list of activities to show in selection filter.
195
     *
228
     *
196
     * @return array list of activities.
229
     * @return array list of activities.
197
     */
230
     */
198
    public function get_activities_list() {
231
    public function get_activities_list() {
199
        $activities = array();
232
        $activities = [];
-
 
233
        $disabled = [];
Línea 200... Línea 234...
200
 
234
 
201
        // For site just return site errors option.
235
        // For site just return site errors option.
202
        $sitecontext = context_system::instance();
236
        $sitecontext = context_system::instance();
203
        if ($this->course->id == SITEID && has_capability('report/log:view', $sitecontext)) {
237
        if ($this->course->id == SITEID && has_capability('report/log:view', $sitecontext)) {
204
            $activities["site_errors"] = get_string("siteerrors");
238
            $activities["site_errors"] = get_string("siteerrors");
205
            return $activities;
239
            return [$activities, $disabled];
Línea 206... Línea 240...
206
        }
240
        }
-
 
241
 
-
 
242
        $modinfo = get_fast_modinfo($this->course);
-
 
243
        if (!$this->delegatedbycm) {
-
 
244
            $this->delegatedbycm = $modinfo->get_sections_delegated_by_cm();
207
 
245
        }
208
        $modinfo = get_fast_modinfo($this->course);
246
 
209
        if (!empty($modinfo->cms)) {
247
        if (!empty($modinfo->cms)) {
210
            $section = 0;
248
            $section = 0;
211
            $thissection = array();
-
 
212
            foreach ($modinfo->cms as $cm) {
249
            $thissection = array();
213
                // Exclude activities that aren't visible or have no view link (e.g. label). Account for folders displayed inline.
250
            foreach ($modinfo->cms as $cm) {
214
                if (!$cm->uservisible || (!$cm->has_view() && strcmp($cm->modname, 'folder') !== 0)) {
251
                if (!$modname = $this->get_activity_name($cm)) {
-
 
252
                    continue;
215
                    continue;
253
                }
-
 
254
 
-
 
255
                if ($cm->sectionnum > 0 and $section <> $cm->sectionnum) {
-
 
256
                    $sectioninfo = $modinfo->get_section_info($cm->sectionnum);
-
 
257
 
-
 
258
                    // Don't show subsections here. We are showing them in the corresponding module.
-
 
259
                    if ($sectioninfo->get_component_instance()) {
-
 
260
                        continue;
216
                }
261
                    }
217
                if ($cm->sectionnum > 0 and $section <> $cm->sectionnum) {
262
 
218
                    $activities[] = $thissection;
263
                    $activities[] = $thissection;
219
                    $thissection = array();
264
                    $thissection = array();
220
                }
-
 
221
                $section = $cm->sectionnum;
-
 
222
                $modname = strip_tags($cm->get_formatted_name());
-
 
223
                if (core_text::strlen($modname) > 55) {
-
 
224
                    $modname = core_text::substr($modname, 0, 50)."...";
-
 
225
                }
-
 
226
                if (!$cm->visible) {
-
 
227
                    $modname = "(".$modname.")";
265
                }
228
                }
266
                $section = $cm->sectionnum;
229
                $key = get_section_name($this->course, $cm->sectionnum);
267
                $key = get_section_name($this->course, $cm->sectionnum);
230
                if (!isset($thissection[$key])) {
268
                if (!isset($thissection[$key])) {
231
                    $thissection[$key] = array();
269
                    $thissection[$key] = [];
-
 
270
                }
-
 
271
                $thissection[$key][$cm->id] = $modname;
-
 
272
                // Check if the module is delegating a section.
-
 
273
                if (array_key_exists($cm->id, $this->delegatedbycm)) {
-
 
274
                    $delegated = $this->delegatedbycm[$cm->id];
-
 
275
                    $modules = (empty($delegated->sequence)) ? [] : explode(',', $delegated->sequence);
-
 
276
                    $thissection[$key] = $thissection[$key] + $this->get_delegated_section_activities($modinfo, $modules);
232
                }
277
                    $disabled[] = $cm->id;
233
                $thissection[$key][$cm->id] = $modname;
278
                }
234
            }
279
            }
235
            if (!empty($thissection)) {
280
            if (!empty($thissection)) {
236
                $activities[] = $thissection;
281
                $activities[] = $thissection;
-
 
282
            }
-
 
283
        }
-
 
284
        return [$activities, $disabled];
-
 
285
    }
-
 
286
 
-
 
287
    /**
-
 
288
     * Helper function to return list of activities in a delegated section.
-
 
289
     *
-
 
290
     * @param course_modinfo $modinfo
-
 
291
     * @param array $cms List of cm ids in the section.
-
 
292
     * @return array list of activities.
-
 
293
     */
-
 
294
    protected function get_delegated_section_activities(course_modinfo $modinfo, array $cmids): array {
-
 
295
        $activities = [];
-
 
296
        $indenter = '&nbsp;&nbsp;&nbsp;&nbsp;';
-
 
297
        foreach ($cmids as $cmid) {
-
 
298
            $cm = $modinfo->cms[$cmid];
-
 
299
            if ($modname = $this->get_activity_name($cm)) {
-
 
300
                $activities[$cmid] = $indenter.$modname;
237
            }
301
            }
238
        }
302
        }
Línea 239... Línea 303...
239
        return $activities;
303
        return $activities;
-
 
304
    }
-
 
305
 
-
 
306
    /**
-
 
307
     * Helper function to return the name to show in the dropdown.
-
 
308
     *
-
 
309
     * @param cm_info $cm
-
 
310
     * @return string The name.
-
 
311
     */
-
 
312
    private function get_activity_name(cm_info $cm): string {
-
 
313
        // Exclude activities that aren't visible or have no view link (e.g. label). Account for folders displayed inline.
-
 
314
        // Activities delegating sections might not have a URL, but should be return a name to be shown.
-
 
315
        $tobeshown = (strcmp($cm->modname, 'folder') == 0) || array_key_exists($cm->id, $this->delegatedbycm);
-
 
316
        if (!$cm->uservisible || (!$cm->has_view() && !$tobeshown)) {
-
 
317
            return '';
-
 
318
        }
-
 
319
        $modname = strip_tags($cm->get_formatted_name());
-
 
320
        if (core_text::strlen($modname) > 55) {
-
 
321
            $modname = core_text::substr($modname, 0, 50)."...";
-
 
322
        }
-
 
323
        if (!$cm->visible) {
-
 
324
            $modname = "(".$modname.")";
-
 
325
        }
-
 
326
 
-
 
327
        return $modname;
240
    }
328
    }
241
 
329
 
242
    /**
330
    /**
243
     * Helper function to get selected group.
331
     * Helper function to get selected group.
244
     *
332
     *
Línea 330... Línea 418...
330
                    } else {
418
                    } else {
331
                        $courses[$course->id] = format_string(get_course_display_name_for_list($course));
419
                        $courses[$course->id] = format_string(get_course_display_name_for_list($course));
332
                    }
420
                    }
333
                }
421
                }
334
            }
422
            }
-
 
423
            // If filtering by a missing course, add a placeholder.
-
 
424
            if (!empty($this->sitecoursefilter)) {
-
 
425
                $courses[$this->sitecoursefilter] = get_string('missingcourse', 'report_log', [
-
 
426
                    'instanceid' => $this->sitecoursefilter,
-
 
427
                ]);
-
 
428
            }
335
            core_collator::asort($courses);
429
            core_collator::asort($courses);
336
        }
430
        }
337
        return $courses;
431
        return $courses;
338
    }
432
    }
Línea 363... Línea 457...
363
        }
457
        }
364
        $cgroups = groups_get_all_groups($this->course->id, $userid);
458
        $cgroups = groups_get_all_groups($this->course->id, $userid);
365
        if (!empty($cgroups)) {
459
        if (!empty($cgroups)) {
366
            $grouplist = array_column($cgroups, 'name', 'id');
460
            $grouplist = array_column($cgroups, 'name', 'id');
367
        }
461
        }
368
        $this->grouplist = $grouplist; // Keep compatibility with MDL-41465.
-
 
369
        return $grouplist;
462
        return $grouplist;
370
    }
463
    }
Línea 371... Línea 464...
371
 
464
 
372
    /**
465
    /**
Línea 520... Línea 613...
520
        $filter->edulevel = $this->edulevel;
613
        $filter->edulevel = $this->edulevel;
521
        $filter->action = $this->action;
614
        $filter->action = $this->action;
522
        $filter->date = $this->date;
615
        $filter->date = $this->date;
523
        $filter->orderby = $this->order;
616
        $filter->orderby = $this->order;
524
        $filter->origin = $this->origin;
617
        $filter->origin = $this->origin;
-
 
618
        $filter->sitecoursefilter = $this->sitecoursefilter;
525
        // If showing site_errors.
619
        // If showing site_errors.
526
        if ('site_errors' === $this->modid) {
620
        if ('site_errors' === $this->modid) {
527
            $filter->siteerrors = true;
621
            $filter->siteerrors = true;
528
            $filter->modid = 0;
622
            $filter->modid = 0;
529
        }
623
        }