Skip to content

Commit 0930056

Browse files
committed
group letters by day
The letters are now grouped by the creation day and wrapped around a orientation marker.
1 parent 31f1b17 commit 0930056

File tree

10 files changed

+65
-39
lines changed

10 files changed

+65
-39
lines changed

classes/contentcontroller.php

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,15 @@ class contentcontroller {
3939
/** @var array events that are relevant for the townsquare */
4040
public array $events;
4141

42-
/** @var array letters and other content that will be shown to the user */
42+
/** @var array stores the letters in objects with the day the letters are from.
43+
* The content is structured in a way that mustache can parse it easily:
44+
*
45+
* ['Y-m-d'] => {
46+
* string $day: 'Y-m-d;
47+
* array $letters: key => $letterobject
48+
* }
49+
* At the end, the array is normalized with array_values so mustache can iterate over it.
50+
*/
4351
public array $content;
4452

4553
/** @var array courses that show content in townsquare (not the same as enrolled courses) */
@@ -66,13 +74,14 @@ public function build_content(): array {
6674

6775
$index = 0;
6876
$appearedcourses = [];
77+
6978
// Build a letter for each event.
7079
foreach ($this->events as $event) {
7180
match ($event->eventtype) {
72-
'post' => $templetter = new local\letter\post_letter($index, $event),
73-
'expectcompletionon' => $templetter = new local\letter\activitycompletion_letter($index, $event),
81+
'post' => $templetter = new local\letter\post_letter($index++, $event),
82+
'expectcompletionon' => $templetter = new local\letter\activitycompletion_letter($index++, $event),
7483
default => $templetter = new local\letter\letter(
75-
$index,
84+
$index++,
7685
$event->courseid,
7786
$event->modulename,
7887
$event->instancename,
@@ -82,17 +91,30 @@ public function build_content(): array {
8291
),
8392
};
8493
$templetter = $templetter->export_letter();
85-
$this->content[$index] = $templetter;
94+
95+
// Group the letters by its day.
96+
$day = date('d.m.Y', $templetter['createdtimestamp']);
97+
if (!isset($this->content[$day])) {
98+
$this->content[$day] = (object) [
99+
'day' => $day,
100+
'letters' => [],
101+
];
102+
$tempcontent = new orientation_marker($index++, $day);
103+
$this->content[$day]->letters[] = $tempcontent->export_data();
104+
105+
}
106+
$this->content[$day]->letters[] = $templetter;
86107

87108
// Collect the courses shown in the townsquare to be able to filter them afterwards.
88-
if (!array_key_exists($this->content[$index]['courseid'], $appearedcourses)) {
89-
$this->courses[] = ['courseid' => $this->content[$index]['courseid'],
90-
'coursename' => $this->content[$index]['coursename'], ];
109+
if (!array_key_exists($templetter['courseid'], $appearedcourses)) {
110+
$this->courses[] = [
111+
'courseid' => $templetter['courseid'],
112+
'coursename' => $templetter['coursename'],
113+
];
91114
$appearedcourses[$event->courseid] = true;
92115
}
93-
$index++;
94116
}
95-
return $this->content;
117+
return array_values($this->content);
96118
}
97119

98120
// Getter.

classes/orientation_marker.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
1616

1717
/**
18-
* Class to show information to the user
18+
* Class to show information to the user.
1919
*
2020
* @package block_townsquare
2121
* @copyright 2023 Tamaro Walter
@@ -30,7 +30,7 @@
3030
require_once($CFG->dirroot . '/blocks/townsquare/locallib.php');
3131

3232
/**
33-
* Class that represent a orientation marker.
33+
* Class that represent an orientation marker.
3434
*
3535
* @package block_townsquare
3636
* @copyright 2023 Tamaro Walter
@@ -42,8 +42,8 @@ class orientation_marker {
4242
/** @var int an ID to identify every content in townsquare */
4343
private int $contentid;
4444

45-
/** @var int The timestamp of the current day. */
46-
private int $today;
45+
/** @var string The day of the letters group */
46+
private string $date;
4747

4848
/** @var bool variable for the mustache template */
4949
public bool $isorientationmarker = true;
@@ -54,11 +54,11 @@ class orientation_marker {
5454
* Constructor for a letter
5555
*
5656
* @param int $contentid The ID to identify the orientation marker
57-
* @param int $time A Timestamp of the time that the orientation marker is created
57+
* @param string $time A Timestamp of the time that the orientation marker is created
5858
*/
59-
public function __construct(int $contentid, int $time) {
59+
public function __construct(int $contentid, string $time) {
6060
$this->contentid = $contentid;
61-
$this->today = $time;
61+
$this->date = $time;
6262
}
6363

6464
// Functions.
@@ -68,14 +68,10 @@ public function __construct(int $contentid, int $time) {
6868
* @return array
6969
*/
7070
public function export_data(): array {
71-
// Change the timestamp to a date.
72-
$date = date('d.m.Y', $this->today);
73-
7471
return [
7572
'contentid' => $this->contentid,
76-
'date' => $date,
73+
'date' => $this->date,
7774
'isorientationmarker' => $this->isorientationmarker,
78-
'orientationmarkercolor' => block_townsquare_get_colorsetting('orientationmarker'),
7975
];
8076
}
8177
}

locallib.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ function block_townsquare_get_colorsetting(string $lettertype): string {
3535
'basicletter' => get_config('block_townsquare', 'basiclettercolor'),
3636
'postletter' => get_config('block_townsquare', 'postlettercolor'),
3737
'completionletter' => get_config('block_townsquare', 'completionlettercolor'),
38-
'orientationmarker' => get_config('block_townsquare', 'orientationmarkercolor'),
3938
default => throw new moodle_exception('invalidlettertype', 'block_townsquare'),
4039
};
4140
}

settings.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,4 @@
6565
get_string('configcompletionlettercolor', 'block_townsquare'),
6666
BLOCK_TOWNSQUARE_COMPLETIONLETTER_DEFAULTCOLOR
6767
));
68-
69-
// Color setting for the orientation marker.
70-
$settings->add(new admin_setting_configcolourpicker(
71-
'block_townsquare/orientationmarkercolor',
72-
get_string('orientationmarkercolor', 'block_townsquare'),
73-
get_string('configorientationmarkercolor', 'block_townsquare'),
74-
BLOCK_TOWNSQUARE_ORIENTATIONMARKER_DEFAULTCOLOR
75-
));
7668
}

styles.css

Lines changed: 15 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/activitycompletionletter.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"completionlettercolor": "#ca3120"
4545
}
4646
}}
47-
<div class="townsquare_letter completionletter card mb-3" id="content-nr-{{contentid}}"
47+
<div class="townsquare_letter completionletter card mb-3 ml-3" id="content-nr-{{contentid}}"
4848
style="border-color: {{completionlettercolor}}">
4949
<div class="townsquareletter_header completionletter_header card-header" style="background-color: {{completionlettercolor}}">
5050
<div class = "townsquareletter_top completionletter_top">

templates/basicletter.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"basiclettercolor": "#0f6cbf"
4646
}
4747
}}
48-
<div class="townsquare_letter basicletter card mb-3" id="content-nr-{{contentid}}" style="border-color: {{basiclettercolor}}">
48+
<div class="townsquare_letter basicletter card mb-3 ml-3" id="content-nr-{{contentid}}" style="border-color: {{basiclettercolor}}">
4949
<div class="townsquareletter_header basicletter_header card-header" style="background-color: {{basiclettercolor}}">
5050
<div class = "townsquareletter_top basicletter_top">
5151
<div class = "townsquareletter_course basicletter_course" data-courseid="{{courseid}}" id="ts_letter_course_{{courseid}}">

templates/blockcontent.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
<div class=" col-md-9 townsquare_content">
8989
<div class="townsquare_letters">
9090
{{#content}}
91+
{{#letters}}
9192
{{#isorientationmarker}}
9293
{{> block_townsquare/orientationmarker}}
9394
{{/isorientationmarker}}
@@ -100,6 +101,7 @@
100101
{{#ispost}}
101102
{{> block_townsquare/postletter}}
102103
{{/ispost}}
104+
{{/letters}}
103105
{{/content}}
104106
</div>
105107
</div>

templates/orientationmarker.mustache

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@
3131
"orientationmarkercolor": "#6a737b"
3232
}
3333
}}
34-
<div class="orientationmarker card mb-3" id="content-nr-{{contentid}}"
35-
style="border-color: {{orientationmarkercolor}}; background-color: {{orientationmarkercolor}};">
36-
<div class="orientationmarker_body card-body">
34+
<div class="orientationmarker" id="content-nr-{{contentid}}">
35+
<div class="orientationmarker_body">
36+
<span class="orientationmarker_date">{{date}}</span>
37+
<span class="orientationmarker_line" aria-hidden="true"></span>
38+
<i class="orientationmarker_arrow fa fa-chevron-down ml-3 mr-2"></i>
3739
</div>
3840
</div>

templates/postletter.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"postlettercolor": "#f7634d"
5858
}
5959
}}
60-
<div class="townsquare_letter postletter card mb-3" id="content-nr-{{contentid}}" style="border-color: {{postlettercolor}}">
60+
<div class="townsquare_letter postletter card mb-3 ml-3" id="content-nr-{{contentid}}" style="border-color: {{postlettercolor}}">
6161
<div class="townsquareletter_header postletter_header card-header" style="background-color: {{postlettercolor}}">
6262
<div class = "townsquareletter_top postletter_top">
6363
<div class = "townsquareletter_course postletter_course" data-courseid="{{courseid}}" id="ts_letter_course_{{courseid}}">

0 commit comments

Comments
 (0)