From 89a79552974ced80189899e798fe8e2aaebbf0f2 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 29 Jan 2017 19:06:59 +0100 Subject: [PATCH] Implement task navigation info --- Controller.php | 9 ++++++++- Models/TaskMapper.php | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/Controller.php b/Controller.php index fe599d4..8f6ba14 100644 --- a/Controller.php +++ b/Controller.php @@ -75,7 +75,9 @@ class Controller extends ModuleAbstract implements WebInterface * @var string * @since 1.0.0 */ - protected static $providing = []; + protected static $providing = [ + 'Navigation' + ]; /** * Dependencies. @@ -183,6 +185,11 @@ class Controller extends ModuleAbstract implements WebInterface return []; } + public function openNav(int $account) : int + { + return TaskMapper::countUnread($account); + } + /** * @param RequestAbstract $request Request * @param ResponseAbstract $response Response diff --git a/Models/TaskMapper.php b/Models/TaskMapper.php index d2e84b2..e850db2 100644 --- a/Models/TaskMapper.php +++ b/Models/TaskMapper.php @@ -157,6 +157,30 @@ class TaskMapper extends DataMapperAbstract return $objId; } + public static function countUnread(int $user) : int + { + try { + $query = new Builder(self::$db); + + $query->prefix(self::$db->getPrefix()) + ->count() + ->from(self::$table) + ->where(self::$table . '.task_created_by', '=', $user) + ->where(self::$table . '.task_status', '=', TaskStatus::OPEN, 'and'); + + $sth = self::$db->con->prepare($query->toSql()); + $sth->execute(); + + $count = $sth->fetchAll()[0][0] ?? 0; + } catch (\Exception $e) { + var_dump($e->getMessage()); + + return false; + } + + return $count; + } + /** * Find. *