Skip to content

Commit ae8e49e

Browse files
committed
Add view and activity box content.
1 parent 4187889 commit ae8e49e

File tree

9 files changed

+156
-12
lines changed

9 files changed

+156
-12
lines changed

classes/local/lib.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use mod_cms\local\model\cms;
2222
use mod_cms\local\model\cms_types;
2323
use moodle_url;
24+
use moodleform_mod;
2425
use stdClass;
2526

2627
/**
@@ -44,7 +45,7 @@ class lib {
4445
* @return array
4546
*/
4647
public static function get_course_content_items(content_item $defaultmodulecontentitem, stdClass $user,
47-
stdClass $course) : array {
48+
stdClass $course): array {
4849
global $COURSE;
4950

5051
$items = [];
@@ -77,10 +78,11 @@ public static function get_course_content_items(content_item $defaultmoduleconte
7778
/**
7879
* Adds an instance of a CMS activity.
7980
*
80-
* @param stdClass $data Data to populate the instance.
81+
* @param stdClass $instancedata Data to populate the instance.
82+
* @param moodleform_mod|null $mform Not used.
8183
* @return int The ID of the newly crated instance.
8284
*/
83-
public static function add_instance(stdClass $data): int {
85+
public static function add_instance(stdClass $instancedata, $mform = null): int {
8486
// TODO: This is a stub.
8587
$cms = new cms();
8688
$cms->set('name', $data->name);

classes/privacy/provider.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class provider implements
4242
* @param collection $collection An object for storing metadata.
4343
* @return collection The metadata.
4444
*/
45-
public static function get_metadata(collection $collection) : collection {
45+
public static function get_metadata(collection $collection): collection {
4646
$collection->add_database_table(
4747
'cms',
4848
[
@@ -68,7 +68,7 @@ public static function get_metadata(collection $collection) : collection {
6868
*
6969
* @return contextlist
7070
*/
71-
public static function get_contexts_for_userid(int $userid) : contextlist {
71+
public static function get_contexts_for_userid(int $userid): contextlist {
7272
// Just enough to pass unit tests.
7373
return new contextlist();
7474
}

db/access.php

+12
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,16 @@
3737
],
3838
'clonepermissionsfrom' => 'moodle/course:manageactivities'
3939
],
40+
41+
// View an activity instance.
42+
'mod/cms:view' => [
43+
'captype' => 'read',
44+
'contextlevel' => CONTEXT_MODULE,
45+
'archetypes' => [
46+
'student' => CAP_ALLOW,
47+
'teacher' => CAP_ALLOW,
48+
'editingteacher' => CAP_ALLOW,
49+
'manager' => CAP_ALLOW
50+
]
51+
],
4052
];

index.php

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
// This file is part of Moodle - https://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+
/**
18+
* Index page for custom content types.
19+
*
20+
* @package mod_cms
21+
* @author Jason den Dulk <[email protected]>
22+
* @copyright 2023, Catalyst IT
23+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24+
*/
25+
require_once('../../config.php');
26+
27+
// TODO: This is a stub.
28+
29+
$id = required_param('id', PARAM_INT); // Course id.
30+
31+
$course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST);
32+
33+
require_login($course);

lang/en/cms.php

+1
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@
4747
$string['settings'] = 'Custom content type settings';
4848
$string['table:name'] = 'Custom content type';
4949
$string['cms:addinstance'] = 'Add a new custom content instance';
50+
$string['pluginadministration'] = 'Plugin administration';

lib.php

+44-4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
use core_course\local\entity\content_item;
2727
use mod_cms\local\lib;
28+
use mod_cms\local\model\cms;
2829

2930
/**
3031
* Returns whether a feature is supported or not.
@@ -78,13 +79,52 @@ function cms_get_course_content_items(content_item $defaultmodulecontentitem, st
7879
/**
7980
* Adds an instance of a CMS activity.
8081
*
81-
* @param stdClass $data Data to populate the instance.
82+
* @param stdClass $instancedata Data to populate the instance.
83+
* @param moodleform_mod|null $mform
8284
* @return int The ID of the newly crated instance.
8385
*/
84-
function cms_add_instance($data) {
85-
return lib::add_instance($data);
86+
function cms_add_instance(stdClass $instancedata, $mform = null): int {
87+
return lib::add_instance($instancedata, $mform);
8688
}
8789

88-
function cms_update_instance($data) {
90+
/**
91+
* Updates an activity instance.
92+
*
93+
* @param stdClass $instancedata
94+
* @param moodleform_mod $mform
95+
* @return bool
96+
*/
97+
function cms_update_instance(stdClass $instancedata, $mform): bool {
8998
// TODO stub.
99+
return false;
100+
}
101+
102+
/**
103+
* Removes an instance of an activity.
104+
*
105+
* @param int $id
106+
* @return bool
107+
*/
108+
function cms_delete_instance(int $id): bool {
109+
// TODO stub.
110+
return false;
111+
}
112+
113+
/**
114+
* Obtains info on course module.
115+
*
116+
* @param stdClass $coursemodule
117+
* @return cached_cm_info
118+
* @throws coding_exception
119+
* @throws moodle_exception
120+
*/
121+
function cms_get_coursemodule_info($coursemodule) {
122+
// TODO This is a stub to provide minimum functionality.
123+
$cms = new cms($coursemodule->instance);
124+
125+
$info = new cached_cm_info();
126+
$info->name = $cms->get('name');
127+
$link = new moodle_url('/mod/cms/view.php', ['id' => $coursemodule->id, 'forcedview' => 1]);
128+
$info->content = html_writer::link($link, $info->name);
129+
return $info;
90130
}

tests/get_course_content_items_test.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ public function create_default_item(): content_item {
5151
$mod = $DB->get_record('modules', ['name' => 'cms']);
5252

5353
$archetype = plugin_supports('mod', $mod->name, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER);
54-
$purpose = plugin_supports('mod', $mod->name, FEATURE_MOD_PURPOSE, MOD_PURPOSE_OTHER);
5554

5655
$icon = 'monologo';
5756

@@ -64,7 +63,7 @@ public function create_default_item(): content_item {
6463
'help',
6564
$archetype,
6665
'mod_' . $mod->name,
67-
$purpose
66+
'other'
6867
);
6968
}
7069

version.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
defined('MOODLE_INTERNAL') || die();
2727

28-
$plugin->version = 2023060400;
28+
$plugin->version = 2023060600;
2929
$plugin->requires = 2020061500; // Moodle 3.9.0 and above.
3030
$plugin->supported = [39, 401]; // Moodle 3.9 to 4.1 inclusive.
3131
$plugin->component = 'mod_cms';

view.php

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
// This file is part of Moodle - https://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+
/**
18+
* Viewing a custom content instance
19+
*
20+
* @package mod_cms
21+
* @author Jason den Dulk <[email protected]>
22+
* @copyright 2023, Catalyst IT
23+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24+
*/
25+
use mod_cms\local\model\cms;
26+
require_once('../../config.php');
27+
28+
// TODO This is a stub.
29+
30+
$id = optional_param('id', 0, PARAM_INT); // Course Module ID.
31+
$action = optional_param('action', '', PARAM_TEXT);
32+
$foruserid = optional_param('user', 0, PARAM_INT);
33+
$forceview = optional_param('forceview', 0, PARAM_BOOL);
34+
35+
$cm = get_coursemodule_from_id('cms', $id, 0, false, MUST_EXIST);
36+
37+
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
38+
$cms = new cms($cm->instance);
39+
40+
$PAGE->set_cm($cm, $course); // Set's up global $COURSE.
41+
$context = context_module::instance($cm->id);
42+
$PAGE->set_context($context);
43+
44+
require_login($course, true, $cm);
45+
require_capability('mod/cms:view', $context);
46+
47+
$url = new moodle_url('/mod/cms/view.php', array('id' => $cm->id));
48+
$PAGE->set_url($url);
49+
50+
// Print the page header.
51+
echo $OUTPUT->header();
52+
53+
// TODO: Replace the following line with the full content.
54+
echo html_writer::tag('h2', $cms->get('name'));
55+
56+
// Finish the page.
57+
echo $OUTPUT->footer();

0 commit comments

Comments
 (0)