Skip to content

Commit 83a2d28

Browse files
author
David Castro
committed
INT-16319: New block for rendering Snap feeds and task for populating deadlines.
0 parents  commit 83a2d28

File tree

9 files changed

+632
-0
lines changed

9 files changed

+632
-0
lines changed

block_snapfeeds.php

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?php
2+
// This file is part of Moodle - http://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+
* Snap feeds.
19+
*
20+
* @package block_snapfeeds
21+
* @copyright Copyright (c) 2021 Open LMS (https://www.openlms.net)
22+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23+
*/
24+
25+
use theme_snap\output\ce_render_helper;
26+
27+
defined('MOODLE_INTERNAL') || die();
28+
29+
/**
30+
* Snap feeds block class.
31+
*
32+
* @package block_snapfeeds
33+
* @copyright Copyright (c) 2021 Open LMS (https://www.openlms.net)
34+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35+
*/
36+
class block_snapfeeds extends block_base {
37+
public function init() {
38+
$this->title = get_string('snapfeeds', 'block_snapfeeds');
39+
}
40+
41+
/**
42+
* By all means, be our guest.
43+
* @return bool
44+
*/
45+
public function instance_allow_multiple() {
46+
return true;
47+
}
48+
49+
/**
50+
* No header.
51+
* @return bool
52+
*/
53+
public function hide_header() {
54+
return true;
55+
}
56+
57+
/**
58+
* Custom element bliss.
59+
* @return stdClass|null
60+
* @throws coding_exception
61+
*/
62+
public function get_content() {
63+
global $CFG, $PAGE, $COURSE;
64+
if ($this->content !== null) {
65+
return $this->content;
66+
}
67+
68+
if (empty($this->config)) {
69+
$this->config = new stdClass();
70+
$this->config->feedtype = '';
71+
}
72+
73+
if ($this->context->get_course_context(false)) {
74+
if (is_guest($this->context)) {
75+
return $this->content; // Course guests don't see the checklist block.
76+
}
77+
} else if (isguestuser()) {
78+
return $this->content; // Site guests don't see the checklist block.
79+
}
80+
81+
// Custom elements JS library load.
82+
$paths['theme_snap/snapce'] = [
83+
$CFG->wwwroot . '/pluginfile.php/' . $PAGE->context->id . '/theme_snap/vendorjs/snap-custom-elements/snap-ce'
84+
];
85+
$PAGE->requires->js_call_amd('theme_snap/wcloader', 'init', [
86+
'componentPaths' => json_encode($paths)
87+
]);
88+
89+
// Should we get data for a specific course.
90+
$courseid = 0;
91+
if ($COURSE->id != SITEID) {
92+
$courseid = $COURSE->id;
93+
}
94+
$this->content = new stdClass;
95+
switch ($this->config->feedtype) {
96+
case 'forumposts':
97+
case 'deadlines':
98+
$feedtype = $this->config->feedtype;
99+
$heading = get_string($feedtype, 'theme_snap');
100+
$virtualpaging = true; // Web service retrieves all elements, need to do virtual paging.
101+
$nocontentstr = get_string('no' . $feedtype, 'theme_snap');
102+
$showreload = true;
103+
$waitforpm = false; // We are out of Snap, we don't need to wait for the PM to open.
104+
$this->content->text = ce_render_helper::get_instance()
105+
->render_feed_web_component($feedtype, $heading,
106+
$nocontentstr, $virtualpaging, $showreload, $waitforpm, $courseid);
107+
break;
108+
default:
109+
$this->content->text = get_string('nofeedconfigured', 'block_snapfeeds');
110+
break;
111+
}
112+
113+
return $this->content;
114+
}
115+
}

classes/privacy/provider.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
// This file is part of Moodle - http://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+
* Privacy Subsystem implementation for block_stream.
19+
*
20+
* @package block_snapfeeds
21+
* @copyright Copyright (c) 2021 Open LMS (https://www.openlms.net)
22+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23+
*/
24+
25+
namespace block_snapfeeds\privacy;
26+
27+
defined('MOODLE_INTERNAL') || die();
28+
29+
/**
30+
* Privacy Subsystem for block_snapfeeds implementing null_provider.
31+
*
32+
* @copyright Copyright (c) 2021 Open LMS (https://www.openlms.net)
33+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34+
*/
35+
class provider implements \core_privacy\local\metadata\null_provider {
36+
37+
/**
38+
* Get the language string identifier with the component's language
39+
* file to explain why this plugin stores no data.
40+
*
41+
* @return string
42+
*/
43+
public static function get_reason() : string {
44+
return 'privacy:metadata';
45+
}
46+
}

db/access.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
// This file is part of Moodle - http://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+
* Snap feeds capabilities.
19+
*
20+
* @package block_snapfeeds
21+
* @copyright Copyright (c) 2021 Open LMS (https://www.openlms.net)
22+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23+
*/
24+
25+
defined('MOODLE_INTERNAL') || die();
26+
27+
$capabilities = [
28+
'block/snapfeeds:myaddinstance' => [
29+
'captype' => 'write',
30+
'contextlevel' => CONTEXT_SYSTEM,
31+
'archetypes' => [
32+
'user' => CAP_ALLOW,
33+
],
34+
'clonepermissionsfrom' => 'moodle/my:manageblocks',
35+
],
36+
37+
'block/snapfeeds:addinstance' => [
38+
'riskbitmask' => RISK_SPAM | RISK_XSS,
39+
'captype' => 'write',
40+
'contextlevel' => CONTEXT_BLOCK,
41+
'archetypes' => [
42+
'editingteacher' => CAP_ALLOW,
43+
'manager' => CAP_ALLOW,
44+
],
45+
'clonepermissionsfrom' => 'moodle/site:manageblocks',
46+
],
47+
];

edit_form.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
// This file is part of Moodle - http://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+
* Form for editing settings.
19+
*
20+
* @package block_snapfeeds
21+
* @copyright Copyright (c) 2021 Open LMS (https://www.openlms.net)
22+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23+
*/
24+
25+
defined('MOODLE_INTERNAL') || die();
26+
27+
/**
28+
* Form for Snap feeds instances.
29+
*
30+
* @package block_snapfeeds
31+
* @copyright Copyright (c) 2021 Open LMS (https://www.openlms.net)
32+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
33+
*/
34+
class block_snapfeeds_edit_form extends block_edit_form {
35+
/**
36+
* @param MoodleQuickForm $mform
37+
* @throws coding_exception
38+
*/
39+
protected function specific_definition($mform) {
40+
global $COURSE;
41+
$feedtypes = [
42+
'deadlines' => get_string('deadlines', 'theme_snap'),
43+
];
44+
if ($COURSE->id == SITEID) {
45+
$feedtypes['forumposts'] = get_string('forumposts', 'theme_snap');
46+
}
47+
$mform->addElement('select', 'config_feedtype', get_string('feedtype', 'block_snapfeeds'), $feedtypes);
48+
$mform->setDefault('config_feedtype', 'deadlines');
49+
$mform->setType('config_feedtype', PARAM_ALPHAEXT);
50+
}
51+
}

lang/en/block_snapfeeds.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
// This file is part of Moodle - http://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+
* Snap feeds language file.
19+
*
20+
* @package block_snapfeeds
21+
* @copyright Copyright (c) 2021 Open LMS (https://www.openlms.net)
22+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23+
*/
24+
defined('MOODLE_INTERNAL') || die();
25+
$string['pluginname'] = 'Snap feeds';
26+
$string['snapfeeds'] = 'Snap feeds';
27+
$string['snapfeeds:addinstance'] = 'Add a new Snap feeds block';
28+
$string['snapfeeds:myaddinstance'] = 'Add a new Snap feeds block to the My Moodle page';
29+
$string['feedtype'] = 'Snap feed type';
30+
$string['nofeedconfigured'] = 'This Snap feed has not been configured';
31+
$string['privacy:metadata'] = 'Snap feeds doesn\'t store any user data';

0 commit comments

Comments
 (0)