summaryrefslogtreecommitdiff
path: root/includes/ical/src/EventsList.php
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-08-31 22:03:07 +0200
committerMinteck <contact@minteck.org>2022-08-31 22:03:07 +0200
commitb5f589c323f415bb42ea7069cb4d1a8a2233dd69 (patch)
treec3b80234ab7f463a2e7b8b672ceff57422b3496b /includes/ical/src/EventsList.php
parent09bd0164ebc020a54b944b7326dcba496fb5d82c (diff)
downloadpluralconnect-b5f589c323f415bb42ea7069cb4d1a8a2233dd69.tar.gz
pluralconnect-b5f589c323f415bb42ea7069cb4d1a8a2233dd69.tar.bz2
pluralconnect-b5f589c323f415bb42ea7069cb4d1a8a2233dd69.zip
Update I guess - Stuffie
Diffstat (limited to 'includes/ical/src/EventsList.php')
-rw-r--r--includes/ical/src/EventsList.php54
1 files changed, 54 insertions, 0 deletions
diff --git a/includes/ical/src/EventsList.php b/includes/ical/src/EventsList.php
new file mode 100644
index 0000000..3325368
--- /dev/null
+++ b/includes/ical/src/EventsList.php
@@ -0,0 +1,54 @@
+<?php
+
+namespace om;
+
+/**
+ * Copyright (c) 2004-2022 Roman Ožana (https://ozana.cz)
+ *
+ * @license BSD-3-Clause
+ * @author Roman Ožana <roman@ozana.cz>
+ */
+class EventsList extends \ArrayObject {
+
+ /**
+ * Return array of Events
+ *
+ * @return array
+ */
+ public function getArrayCopy(): array {
+ return array_values(parent::getArrayCopy());
+ }
+
+ /**
+ * Return sorted EventList (the newest dates are first)
+ *
+ * @return $this
+ */
+ public function sorted(): EventsList {
+ $this->uasort(static function ($a, $b): int {
+ if ($a['DTSTART'] === $b['DTSTART']) {
+ return 0;
+ }
+ return ($a['DTSTART'] < $b['DTSTART']) ? -1 : 1;
+ });
+
+ return $this;
+ }
+
+ /**
+ * Return reversed sorted EventList (the oldest dates are first)
+ *
+ * @return $this
+ */
+ public function reversed(): EventsList {
+ $this->uasort(static function ($a, $b): int {
+ if ($a['DTSTART'] === $b['DTSTART']) {
+ return 0;
+ }
+ return ($a['DTSTART'] > $b['DTSTART']) ? -1 : 1;
+ });
+
+ return $this;
+ }
+
+} \ No newline at end of file