-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
114 lines (94 loc) · 3.51 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
*
* @package local_wb_news
* @copyright 2024 Thomas Winkler
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_wb_news;
use context_system;
use local_wb_news\event\overview_viewed;
use local_wb_news\output\wb_news;
use stdClass;
use context;
// @codingStandardsIgnoreStart
require('../../config.php');
// @codingStandardsIgnoreEnd
require_once($CFG->libdir.'/formslib.php');
require_once($CFG->libdir.'/datalib.php');
$context = \context_system::instance();
$PAGE->set_context($context);
$id = optional_param('id', 0, PARAM_INT);
$pageurl = new \moodle_url('/local/wb_news/index.php?id=' . $id);
$PAGE->set_url($pageurl);
$record = $DB->get_record("local_wb_news", ["id" => $id], '*');
$event = overview_viewed::create([
'context' => context_system::instance(),
'userid' => $USER->id,
]);
$event->trigger();
if ($id == 0) {
$record = new stdClass();
$record->title = get_string('wb_news', 'local_wb_news');
}
$PAGE->set_title($record->title ?? 'title');
$PAGE->set_heading($record->title ?? 'title');
$PAGE->set_pagelayout('base');
echo $OUTPUT->header();
require_capability('local/wb_news:editinstances', context_system::instance());
$news = new wb_news($id);
$data = $news->return_list();
// phpcs:ignore
// Here, we want the information how to include the instance:
foreach ($data['instances'] as $key => $value) {
if (!empty($data['instances'][$key]['contextids'])) {
$contextids = explode(',', $data['instances'][$key]['contextids']);
$hasaccess = false;
foreach ($contextids as $contextid) {
if (!empty($contextid)) {
try {
$context = context::instance_by_id($contextid);
if (has_capability('local/wb_news:manage', $context)) {
$hasaccess = true;
$data['instances'][$key]['editmode'] = true;
}
} catch (\Exception $e) {
// Do nothing, we will skip this entry.
if (is_siteadmin()) {
$hasaccess = true;
}
}
} else {
$hasaccess = true;
}
}
if (!$hasaccess) {
unset($data['instances'][$key]);
continue;
}
} else {
$data['instances'][$key]['editmode'] = true;
}
$data['instances'][$key]['instancenameonindex'] = empty($value["name"])
? get_string('noname', 'local_wb_news') : $value["name"];
$data['instances'][$key]['shortcode'] = "[wbnews instance=" . $value["instanceid"] . "]";
$data['instances'][$key]['isadminpage'] = true;
}
$data['instances'] = array_values($data['instances']);
$data['editmode'] = true;
echo $OUTPUT->render_from_template('local_wb_news/wb_news_container', $data);
echo $OUTPUT->footer();