Skip to content

Commit b5b5f3b

Browse files
committed
Add working version of managing own non-global notifs - #24
1 parent cab9551 commit b5b5f3b

File tree

7 files changed

+46
-16
lines changed

7 files changed

+46
-16
lines changed

.travis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@ php:
1111
- 7.4
1212
- 7.3
1313
- 7.2
14-
- 7.1
15-
- 7.0
1614

1715
addons:
1816
postgresql: "9.6"
1917

2018
env:
2119
global:
20+
- MOODLE_BRANCH=MOODLE_310_STABLE
2221
- MOODLE_BRANCH=MOODLE_39_STABLE
2322
- MOODLE_BRANCH=MOODLE_38_STABLE
2423
- MOODLE_BRANCH=MOODLE_37_STABLE
@@ -39,7 +38,7 @@ before_install:
3938
- nvm install 14.0.0
4039
- nvm use 14.0.0
4140
- cd ../..
42-
- composer create-project -n --no-dev --prefer-dist blackboard-open-source/moodle-plugin-ci ci ^2
41+
- composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3
4342
- export PATH="$(cd ci/bin; pwd):$(cd ci/vendor/bin; pwd):$PATH"
4443

4544
install:
@@ -72,4 +71,5 @@ script:
7271
- moodle-plugin-ci codechecker
7372
- moodle-plugin-ci phpdoc
7473
- moodle-plugin-ci validate
75-
- moodle-plugin-ci savepoints
74+
- moodle-plugin-ci savepoints
75+
- moodle-plugin-ci grunt

lang/en/block_advnotifications.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
$string['advnotifications_enabled'] = 'Enabled?';
7070
$string['advnotifications_global'] = 'Global notification?';
7171
$string['add_notification_global_notice'] = 'This notification will be displayed globally/site-wide!';
72+
$string['add_notif_local_notice'] = 'This notification will <em>only</em> be displayed on the page you\'re managing this block from!';
7273
$string['advnotifications_title'] = 'Title';
7374
$string['advnotifications_message'] = 'Message';
7475
$string['advnotifications_type'] = 'Type';

pages/notifications.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,15 @@
6565
$ownnotifs = false;
6666

6767
if (!$allnotifs) {
68+
if (empty($blockinstance) || !isset($blockinstance) || $blockinstance === -1) {
69+
throw new moodle_exception('advnotifications_err_nocapability', 'block_advnotifications');
70+
}
6871
$bcontext = context_block::instance($blockinstance);
6972
$ownnotifs = has_capability('block/advnotifications:manageownnotifications', $bcontext);
7073
}
7174

7275
if (!$allnotifs && !$ownnotifs) {
73-
throw new moodle_exception('advnotifications_err_nocapability', 'enrol_selma');
76+
throw new moodle_exception('advnotifications_err_nocapability', 'block_advnotifications');
7477
}
7578

7679
// Set PAGE variables.
@@ -128,6 +131,8 @@
128131
$CFG->wwwroot . '/admin/settings.php?section=blocksettingadvnotifications' . $xparam . '">' .
129132
get_string('advnotifications_nav_settings', 'block_advnotifications') .
130133
'</a>';
134+
135+
$params['global'] = true;
131136
}
132137

133138
// Add navigation controls before the table.

pages/process.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@
141141
}
142142

143143
if (!$allnotifs && !$ownnotifs) {
144-
throw new moodle_exception('advnotifications_err_nocapability', 'enrol_selma');
144+
throw new moodle_exception('advnotifications_err_nocapability', 'block_advnotifications');
145145
}
146146
}
147147

@@ -227,6 +227,11 @@
227227
// Only check for id parameter when updating.
228228
$id = optional_param('id', null, PARAM_INT);
229229

230+
// Prevent users from making notifications global if they aren't allowed to.
231+
if (!$allnotifs) {
232+
$global = 0;
233+
}
234+
230235
// Update an existing notification.
231236
$urow = new stdClass();
232237

@@ -288,6 +293,10 @@
288293
}
289294
}
290295

296+
// Prevent users from making notifications global if they aren't allowed to.
297+
if (!$allnotifs) {
298+
$global = 0;
299+
}
291300

292301
// Create a new notification - Used for both Ajax Calls & NON-JS calls.
293302
$row = new stdClass();

pages/restore.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,15 @@
7070
$ownnotifs = false;
7171

7272
if (!$allnotifs) {
73+
if (empty($blockid) || !isset($blockid) || $blockid === -1) {
74+
throw new moodle_exception('advnotifications_err_nocapability', 'block_advnotifications');
75+
}
7376
$bcontext = context_block::instance($blockid);
7477
$ownnotifs = has_capability('block/advnotifications:manageownnotifications', $bcontext);
7578
}
7679

7780
if (!$allnotifs && !$ownnotifs) {
78-
throw new moodle_exception('advnotifications_err_nocapability', 'enrol_selma');
81+
throw new moodle_exception('advnotifications_err_nocapability', 'block_advnotifications');
7982
}
8083

8184
// Set PAGE variables.

renderer.php

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ public function add_notification($params) {
9999
get_string('advnotifications_enabled', 'block_advnotifications') .
100100
'</label>
101101
</div>' .
102-
((array_key_exists('blockid', $params)) ?
102+
((array_key_exists('blockid', $params) &&
103+
array_key_exists('global', $params) &&
104+
$params['global'] === true) ?
103105
'<div class="form-check">
104106
<input type="checkbox" id="add_notification_global" class="form-check-input" name="global"/>
105107
<label for="add_notification_global" class="form-check-label">' .
@@ -108,12 +110,18 @@ public function add_notification($params) {
108110
<input type="hidden" id="add_notification_blockid" name="blockid" value="' . $params['blockid'] .
109111
'"/>
110112
</div>' :
111-
'<div class="form-group">
112-
<strong>
113-
<em>' . get_string('add_notification_global_notice', 'block_advnotifications') . '</em>
114-
</strong>
115-
<input type="hidden" id="add_notification_global" name="global" value="1"/>
116-
</div>') .
113+
((array_key_exists('global', $params) &&
114+
$params['global'] === true) ?
115+
'<div class="form-group">
116+
<strong>
117+
<em>' . get_string('add_notification_global_notice', 'block_advnotifications') . '</em>
118+
</strong>
119+
<input type="hidden" id="add_notification_global" name="global" value="1"/>
120+
</div>' :
121+
'<div class="form-group">
122+
<strong>' . get_string('add_notif_local_notice', 'block_advnotifications') . '</strong>
123+
<input type="hidden" id="add_notification_global" name="global" value="0"/>
124+
</div>')) .
117125
'<div class="form-group row">
118126
<input type="text" id="add_notification_title" class="form-control" name="title" placeholder="' .
119127
get_string('advnotifications_title', 'block_advnotifications') . '"/>
@@ -202,6 +210,10 @@ class="form-control"
202210
</div>
203211
<input type="hidden" id="add_notification_sesskey" name="sesskey" value="' . sesskey() . '"/>
204212
<input type="hidden" id="add_notification_purpose" name="purpose" value="add"/>
213+
<input type="hidden" id="add_notification_blockid" name="blockid" value="' .
214+
(array_key_exists('blockid', $params) ?
215+
$params['blockid'] :
216+
'-1') . '"/>
205217
<div class="form-group">
206218
<input type="submit"
207219
id="add_notification_save"

version.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
defined('MOODLE_INTERNAL') || die;
2727

2828
$plugin->component = 'block_advnotifications'; // Recommended since 2.0.2 (MDL-26035). Required since 3.0 (MDL-48494).
29-
$plugin->version = 2020101319; // YYYYMMDDHH (year, month, day, 24-hr format hour).
29+
$plugin->version = 2020101320; // YYYYMMDDHH (year, month, day, 24-hr format hour).
3030
$plugin->requires = 2018051703; // YYYYMMDDHH (Version number for Moodle 3.5.3 as at 21/01/2019).
3131
$plugin->maturity = MATURITY_STABLE; // Code maturity/stability.
32-
$plugin->release = 'v1.3.13'; // Human-readable release version.
32+
$plugin->release = 'v1.3.14'; // Human-readable release version.

0 commit comments

Comments
 (0)