From 223f3110bdbfa4cddf4821beaf22dbf8ae069343 Mon Sep 17 00:00:00 2001 From: Cris Date: Tue, 24 Sep 2019 16:06:50 +0200 Subject: [PATCH] Added method getLast() This method gets latest (active) Verwendung of the user. --- .../models/codex/Bisverwendung_model.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/application/models/codex/Bisverwendung_model.php b/application/models/codex/Bisverwendung_model.php index fa2cf84d0..20f942865 100644 --- a/application/models/codex/Bisverwendung_model.php +++ b/application/models/codex/Bisverwendung_model.php @@ -11,4 +11,34 @@ class Bisverwendung_model extends DB_Model $this->dbTable = 'bis.tbl_bisverwendung'; $this->pk = 'bisverwendung_id'; } + + /** + * Get latest (active) Verwendung of the user. + * @param string $uid + * @param bool $active If false, returns latest Verwendung no matter if actual or not (ignores ending/beginning date). + * @return array + */ + public function getLast($uid, $active = true) + { + $this->addLimit(1); + + if ($active) + { + $condition = ' + mitarbeiter_uid = '. $this->escape($uid). ' + AND ( beginn <= NOW() OR beginn IS NULL ) + AND ( ende >= NOW() OR ende IS NULL ) + ORDER BY ende DESC NULLS LAST, beginn DESC NULLS LAST + '; + } + else + { + $condition = ' + mitarbeiter_uid = '. $this->escape($uid). ' + ORDER BY ende DESC NULLS LAST, beginn DESC NULLS LAST + '; + } + + return $this->loadWhere($condition); + } }