summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeldakatze <coffee@zeldakatze.de>2025-10-27 01:23:58 +0100
committerzeldakatze <coffee@zeldakatze.de>2025-10-27 01:23:58 +0100
commit607411f406a1bbbd90e0559de29116ccc8d2e0f2 (patch)
tree91f3cf29c13af7aebcc7dae5a68b3326af988e96
parent4c71a67bbb00c136c39900afaa79d3c1933d710d (diff)
downloadinfoCalendar-607411f406a1bbbd90e0559de29116ccc8d2e0f2.tar.gz
infoCalendar-607411f406a1bbbd90e0559de29116ccc8d2e0f2.zip
sort events by their start dateHEADmain
-rwxr-xr-xadminPanel.php9
-rwxr-xr-xcalenderRenderer.php18
-rw-r--r--infoCalendar-admin.css3
-rwxr-xr-xinfoCalendar.php8
4 files changed, 34 insertions, 4 deletions
diff --git a/adminPanel.php b/adminPanel.php
index a45b75c..d0bd859 100755
--- a/adminPanel.php
+++ b/adminPanel.php
@@ -214,6 +214,7 @@ function infocalendar_options_page_html() {
$wpdb->show_errors = true;
?>
+ <div id="infocal_adm">
<script>
function cal_toggleOldEventsVisibility() {
var btn = document.getElementById('cal_hideOldEventsBtn');
@@ -347,7 +348,8 @@ function infocalendar_options_page_html() {
WHERE event.id = eventCalendarMap.eventID AND
calendar.id = eventCalendarMap.calendarID AND
repeatingEvent=0 AND icalImported=0 AND
- (startDate > NOW() OR endDate > NOW()) GROUP BY event.id",
+ (startDate > NOW() OR endDate > NOW()) GROUP BY event.id
+ ORDER BY startDate",
'ARRAY_A');
foreach($result as $row) {
@@ -401,7 +403,7 @@ function infocalendar_options_page_html() {
event.id = repeatingEvent.id AND
repeatingEvent=1 AND icalImported=0 AND
(repeatEndTime > NOW() OR startDate > NOW())
- GROUP BY event.id", 'ARRAY_A');
+ GROUP BY event.id ORDER BY startDate", 'ARRAY_A');
foreach($result as $row) {
/* get the creator's name */
@@ -462,7 +464,7 @@ function infocalendar_options_page_html() {
calendar.id = eventCalendarMap.calendarID AND
repeatingEvent=0 AND icalImported=0 AND
(startDate < NOW() AND endDate < NOW())
- GROUP BY event.id", 'ARRAY_A');
+ GROUP BY event.id ORDER BY startDate", 'ARRAY_A');
foreach($result as $row) {
/* get the creator's name */
$creator = get_username_from_id($row['creator']);
@@ -543,6 +545,7 @@ function infocalendar_options_page_html() {
?>
</table>
</div>
+ </div>
<?php
}
diff --git a/calenderRenderer.php b/calenderRenderer.php
index e3d30fb..6e2e81e 100755
--- a/calenderRenderer.php
+++ b/calenderRenderer.php
@@ -5,6 +5,7 @@ class SimpleEvent {
public $title;
public $location;
public $startDate;
+ public $startDateTimestamp;
public $endDate;
public $creator;
public $creationDate;
@@ -33,6 +34,9 @@ class SimpleEvent {
/* hackily align the dates to the start and ends of a day */
$this->dayAlignedStartTime = new DateTime($startDate->format("Y-m-d")." 0:00:00");
$this->dayAlignedEndTime = new DateTime($endDate->format("Y-m-d")." 23:59:59");
+
+ /* precompute timestamps */
+ $this->startDateTimestamp = (int) $startDate->format("U");
}
public function setDates($newStart, $newEnd) {
@@ -42,6 +46,9 @@ class SimpleEvent {
/* hackily align the dates to the start and ends of a day */
$this->dayAlignedStartTime = new DateTime($newStart->format("Y-m-d")." 0:00:00");
$this->dayAlignedEndTime = new DateTime($newEnd->format("Y-m-d")." 23:59:59");
+
+ /* precompute timestamps */
+ $this->startDateTimestamp = (int) $newStart->format("U");
}
public function eventHappensAtDay(DateTime $dt) {
@@ -64,6 +71,14 @@ class SimpleEvent {
}
}
+function SimpleEvent_cmp($a, $b) {
+ if($a->startDateTimestamp == $b->startDateTimestamp) {
+ return 0;
+ }
+
+ return ($a->startDateTimestamp < $b->startDateTimestamp) ? -1 : 1;
+}
+
/* Get the repetitions of a date $datetime in a window defined by
* $startDate and $endDate.
* $type defines the repetition type
@@ -248,6 +263,9 @@ function getSingleEventsInTimeRange($view, $start, $end) {
/* merge $r1 and $r2 into $ret */
$ret = array_merge($r1, $r2);
+ /* sort the array */
+ usort($ret, "SimpleEvent_cmp");
+
return $ret;
}
diff --git a/infoCalendar-admin.css b/infoCalendar-admin.css
new file mode 100644
index 0000000..636d3bf
--- /dev/null
+++ b/infoCalendar-admin.css
@@ -0,0 +1,3 @@
+#infocal_adm table tr:nth-child(even) {
+ background: #d1d1d1;
+}
diff --git a/infoCalendar.php b/infoCalendar.php
index e4525d0..c1fcd48 100755
--- a/infoCalendar.php
+++ b/infoCalendar.php
@@ -3,7 +3,7 @@
* Plugin Name: infoCalendar
* Plugin URI: https://cgit.zeldakatze.de/infoCalendar/
* Description: the infoCalendar Plugin
-* Version: 0.4.1
+* Version: 0.4.2
* Author: zeldakatze
* Author URI: http://zeldakatze.de
**/
@@ -90,8 +90,14 @@ function infocalendar_enqueue() {
plugin_dir_url( __FILE__ ) . "/infoCalendar.css");
}
+function infocalendar_admin_enqueue() {
+ wp_enqueue_style('admin-styles',
+ plugin_dir_url( __FILE__ ) . "/infoCalendar-admin.css");
+}
+
add_action( 'init', 'infocalendar_init' );
add_action( 'wp_enqueue_scripts', 'infocalendar_enqueue');
+add_action('admin_enqueue_scripts', 'infocalendar_admin_enqueue');
add_action( 'rest_api_init', function () {
register_rest_route( 'infocalendar', '/calendar/(?P<slug>[a-zA-Z0-9-ÖöÄäÜüß]+)', array(