From 23116a41c9e944512eb21be84b694d889dc14650 Mon Sep 17 00:00:00 2001 From: Michael Grace <56653532+michael-grace@users.noreply.github.com> Date: Wed, 29 May 2024 15:37:29 +0100 Subject: [PATCH] Terms API --- src/Classes/ServiceAPI/MyRadio_Term.php | 19 +++++++++++++------ src/Public/js/myradio.scheduler.termlist.js | 2 +- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/Classes/ServiceAPI/MyRadio_Term.php b/src/Classes/ServiceAPI/MyRadio_Term.php index edfda89c2..fb23483cb 100644 --- a/src/Classes/ServiceAPI/MyRadio_Term.php +++ b/src/Classes/ServiceAPI/MyRadio_Term.php @@ -40,6 +40,9 @@ public function __construct($term_id) { $this->descr = $result['descr'] . date(" Y", strtotime($this->start_date)); $this->num_weeks = (int) $result['weeks']; $this->week_names = json_decode($result['week_names']); + if ($this->week_names == null) { + $this->week_names = []; + } } @@ -80,9 +83,13 @@ public static function addTerm($start, $descr, $num_weeks) */ public static function getAllTerms($currentOnly = false) { - $query = 'SELECT termid, EXTRACT(EPOCH FROM start) AS start FROM terms WHERE '; - $query .= $currentOnly ? 'start <= now() AND ' : ''; - $query .= 'finish > now() ORDER BY start ASC'; + if ($currentOnly == "false") { + $currentOnly = false; + } + + $query = 'SELECT termid, EXTRACT(EPOCH FROM start) AS start FROM terms '; + $query .= $currentOnly ? 'WHERE start <= now() AND finish > now() ' : ''; + $query .= 'ORDER BY start ASC'; $result = self::$db->fetchAll($query); $terms = []; @@ -202,10 +209,10 @@ public static function getTermForm() public function toDataSource($mixins = []) { return [ "term_id" => $this->getID(), - "descr" => $this->getTermDescr(), + "start" => $this->getTermStartDate(), + "descr" => $this->getTermDescr(), "num_weeks" => $this->getTermWeeks(), - "week_names" => $this->getTermWeekNames(), - "start" => $this->getTermStartDate() + "week_names" => $this->getTermWeekNames() ]; } } diff --git a/src/Public/js/myradio.scheduler.termlist.js b/src/Public/js/myradio.scheduler.termlist.js index d0982fcaa..b5c4c5754 100644 --- a/src/Public/js/myradio.scheduler.termlist.js +++ b/src/Public/js/myradio.scheduler.termlist.js @@ -1,7 +1,7 @@ $(".twig-datatable").dataTable({ "aaSorting": [[2, "desc"]], "aoColumns": [ - //termid + //term_id { "bVisible": false },