Skip to content

Commit 29e7156

Browse files
committed
CTP-3220 Single alert
Remove functionality for multiple alerts and carousel.
1 parent 21fd1d0 commit 29e7156

File tree

5 files changed

+62
-200
lines changed

5 files changed

+62
-200
lines changed

block_alerts.php

+15-42
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,14 @@ public function get_content(): stdClass {
6363
$this->content->footer = '';
6464

6565
$template = new stdClass();
66-
$template->alerts = $this->fetch_alerts();
67-
$itemcount = count($template->alerts);
66+
$template->alert = $this->fetch_alert();
67+
$itemcount = count($template->alert);
6868

6969
// Hide the block when no content.
7070
if (!$itemcount) {
7171
return $this->content;
7272
}
7373

74-
// Set flag if we need to show navigation (when more than one alert).
75-
if ($itemcount > 1) {
76-
$template->nav = true;
77-
}
78-
7974
// Render from template.
8075
$this->content->text = $OUTPUT->render_from_template('block_alerts/content', $template);
8176

@@ -87,49 +82,27 @@ public function get_content(): stdClass {
8782
*
8883
* @return array alerts items.
8984
*/
90-
public function fetch_alerts(): array {
85+
public function fetch_alert(): array {
9186
// Template data for mustache.
9287
$template = new stdClass();
9388

94-
// Get alerts items.
95-
for ($i = 1; $i < 4; $i++) {
96-
$alerts = new stdClass();
97-
$alerts->description = get_config('block_alerts', 'description'.$i);
98-
$alerts->title = get_config('block_alerts', 'title'.$i);
99-
$alerts->date = get_config('block_alerts', 'date'.$i);
100-
$alerts->link = get_config('block_alerts', 'link'.$i);
101-
$alerts->linktext = get_config('block_alerts', 'linktext'.$i);
102-
103-
// Check alerts is populated.
104-
if ($alerts->title) {
105-
// Format the date for display.
106-
if ($alerts->date) {
107-
$alerts->displaydate = date_format(date_create($alerts->date), "jS M Y");
108-
}
109-
110-
// Make a temp key value array to sort.
111-
// NOTE - index added to make keys unique.
112-
$template->tempalerts[$alerts->date.'-'.$i] = $alerts;
113-
}
89+
// Get alert content.
90+
$alert = new stdClass();
91+
$alert->description = get_config('block_alerts', 'description');
92+
$alert->title = get_config('block_alerts', 'title');
93+
$alert->link = get_config('block_alerts', 'link');
94+
$alert->linktext = get_config('block_alerts', 'linktext');
95+
96+
// Check alerts is populated.
97+
if ($alert->title) {
98+
$template->alert[] = $alert;
99+
return $template->alert;
114100
}
115101

116102
// Return if no alerts.
117-
if (!isset($template->tempalerts)) {
103+
if (!isset($template->alert)) {
118104
return [];
119105
}
120-
121-
// Sort alerts items by date for output.
122-
krsort($template->tempalerts);
123-
124-
// Add sorted array to template.
125-
foreach ($template->tempalerts as $alerts) {
126-
$template->alerts[] = $alerts;
127-
}
128-
129-
// Set first element as active for carousel version.
130-
$template->alerts[0]->active = true;
131-
132-
return $template->alerts;
133106
}
134107

135108
/**

classes/admin_setting_date.php

-59
This file was deleted.

lang/en/block_alerts.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,9 @@
2727
$string['alerts:myaddinstance'] = 'Add alerts block';
2828
$string['privacy:metadata'] = 'Alerts does not store any personal data.';
2929

30-
$string['blocktitle'] = 'Alerts block title';
30+
$string['blocktitle'] = 'Alert block title';
3131
$string['configurealerts'] = "Edit global alert posts";
3232
$string['title'] = 'Title';
33-
$string['alertsitem'] = 'Alerts post';
34-
$string['date'] = 'Post date';
35-
$string['date_help'] = 'Post date sets the order of display, not the date it becomes visible.';
3633
$string['description'] = 'Description';
3734
$string['description_help'] = 'Short text, no more that 140 characters.';
3835
$string['link'] = 'Link';

settings.php

+32-51
Original file line numberDiff line numberDiff line change
@@ -24,65 +24,46 @@
2424

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

27-
use block_alerts\admin_setting_date;
28-
2927
if ($hassiteconfig) {
3028
if ($ADMIN->fulltree) {
3129

3230
$default = '';
3331

34-
// Add 3 slots for alerts.
35-
for ($i = 1; $i < 4; $i++) {
36-
// Heading.
37-
$setting = new admin_setting_heading('h'.$i,
38-
get_string('alertsitem', 'block_alerts'),
39-
''
40-
);
41-
$settings->add($setting);
42-
43-
// Date.
44-
$setting = new admin_setting_date('block_alerts/date'.$i,
45-
get_string('date', 'block_alerts'),
46-
get_string('date_help', 'block_alerts'),
47-
$default
48-
);
49-
$settings->add($setting);
32+
// Title.
33+
$setting = new admin_setting_configtext('block_alerts/title',
34+
get_string('title', 'block_alerts'),
35+
'',
36+
$default,
37+
PARAM_RAW
38+
);
39+
$settings->add($setting);
5040

51-
// Title.
52-
$setting = new admin_setting_configtext('block_alerts/title'.$i,
53-
get_string('title', 'block_alerts'),
54-
'',
55-
$default,
56-
PARAM_RAW
57-
);
58-
$settings->add($setting);
41+
// Description.
42+
$setting = new admin_setting_configtext('block_alerts/description',
43+
get_string('description', 'block_alerts'),
44+
get_string('description_help', 'block_alerts'),
45+
$default,
46+
PARAM_RAW
47+
);
48+
$settings->add($setting);
5949

60-
// Description.
61-
$setting = new admin_setting_configtext('block_alerts/description'.$i,
62-
get_string('description', 'block_alerts'),
63-
get_string('description_help', 'block_alerts'),
64-
$default,
65-
PARAM_RAW
66-
);
67-
$settings->add($setting);
50+
// Link.
51+
$setting = new admin_setting_configtext('block_alerts/link',
52+
get_string('link', 'block_alerts'),
53+
get_string('link_help', 'block_alerts'),
54+
$default,
55+
PARAM_RAW
56+
);
57+
$settings->add($setting);
6858

69-
// Link.
70-
$setting = new admin_setting_configtext('block_alerts/link'.$i,
71-
get_string('link', 'block_alerts'),
72-
get_string('link_help', 'block_alerts'),
73-
$default,
74-
PARAM_RAW
75-
);
76-
$settings->add($setting);
59+
// Link text.
60+
$setting = new admin_setting_configtext('block_alerts/linktext',
61+
get_string('linktext', 'block_alerts'),
62+
get_string('linktext_help', 'block_alerts'),
63+
$default,
64+
PARAM_RAW
65+
);
66+
$settings->add($setting);
7767

78-
// Link text.
79-
$setting = new admin_setting_configtext('block_alerts/linktext'.$i,
80-
get_string('linktext', 'block_alerts'),
81-
get_string('linktext_help', 'block_alerts'),
82-
$default,
83-
PARAM_RAW
84-
);
85-
$settings->add($setting);
86-
}
8768
}
8869
}

templates/content.mustache

+14-44
Original file line numberDiff line numberDiff line change
@@ -16,60 +16,30 @@
1616
@template blocks_alerts/content
1717
Example context (json):
1818
{
19-
"nav": 1,
20-
"alerts": [
19+
"alert": [
2120
{
2221
"title": "This is the alert title",
2322
"description": "This is the news description",
2423
"link": "https://moodle.com/",
25-
"linktext": "Visit moodle.com",
26-
"active": 1
27-
},
28-
{
29-
"title": "This is the alert title",
30-
"description": "This is the news description",
31-
"link": "https://moodle.com/",
32-
"linktext": "Visit moodle.com",
33-
"active": 0
24+
"linktext": "Visit moodle.com"
3425
}
3526
]
36-
3727
}
3828
}}
3929

40-
<div class="alert alert-info px-2 border-info d-flex d-flex align-items-center justify-content-center"
41-
style="border: none; border-left: .5rem solid;">
42-
<!-- Alerts icon. -->
30+
<div role="alert" class="alert alert-info px-2 border-info d-flex align-items-center"
31+
style="border: none; border-left: .5rem solid;" >
32+
<!-- Alert icon. -->
4333
<i class="fa-solid fa-triangle-exclamation fa-2xl text-primary ml-2"></i>
44-
45-
<!-- Alerts carosel. -->
46-
<div class="mx-3 flex-fill text-body">
47-
<div id="block-alert-carousel" class="carousel slide" data-ride="carousel">
48-
<div class="carousel-inner">
49-
50-
{{#alerts}}
51-
<div class="carousel-item {{#active}} active {{/active}}">
52-
<strong>{{title}}</strong>
53-
<div>{{description}}
54-
{{#linktext}}
55-
<a href="{{link}}" target="_blank">{{linktext}}</a>
56-
{{/linktext}}
57-
</div>
34+
<!-- Alert content. -->
35+
{{#alert}}
36+
<div class="ml-3">
37+
<strong>{{title}}</strong>
38+
<div>{{description}}
39+
{{#linktext}}
40+
<a href="{{link}}" target="_blank">{{linktext}}</a>
41+
{{/linktext}}
5842
</div>
59-
{{/alerts}}
60-
61-
</div>
62-
</div>
6343
</div>
64-
65-
{{#nav}}
66-
<!-- Alerts next. -->
67-
<div>
68-
<a href="#block-alert-carousel" role="button" data-slide="next" class="btn btn-primary mr-2">
69-
<i class="fa fa-chevron-right text-white" aria-hidden="true"></i>
70-
<span class="sr-only">{{#str}} next {{/str}}</span>
71-
</a>
72-
</div>
73-
{{/nav}}
74-
44+
{{/alert}}
7545
</div>

0 commit comments

Comments
 (0)