From ec38255acbd37319d74aa9565e33864d5e773cc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81?= Date: Wed, 27 May 2015 18:55:25 +0200 Subject: [PATCH] refine response for documents and news refs #112 --- .gitignore | 2 +- routes/documents.php | 6 ++++-- routes/news.php | 13 +++++++++---- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 3d4ca62..441acfb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ tests/junit_log.xml - +.idea *.patch diff --git a/routes/documents.php b/routes/documents.php index f530a2e..c435f2e 100644 --- a/routes/documents.php +++ b/routes/documents.php @@ -39,8 +39,9 @@ function routes(&$router) $router->halt(404, sprintf('No folder %s for range %s', $folder_id, $range_id)); } + $last_visit = object_get_visit($range_id, "documents"); $folders = Document::loadFolders($folder_id); - $documents = Document::loadFiles($folder_id, 'folder'); + $documents = Document::loadFiles($folder_id, 'folder', $last_visit); if ($router->compact()) { $router->render(compact('folders', 'documents')); @@ -238,7 +239,7 @@ static function loadFolders($folder_id) return $folders; } - static function loadFiles($id, $type = 'file') + static function loadFiles($id, $type = 'file', $last_visit = 7776000) { if ($type === 'folder') { $query = "SELECT dokument_id AS document_id, user_id, name, @@ -265,6 +266,7 @@ static function loadFiles($id, $type = 'file') $file['protected'] = !empty($file['protected']); $file['mime_type'] = get_mime_type($file['filename']); $file['icon'] = Assets::image_path(GetFileIcon(getFileExtension($file['filename']))); + $file['new'] = ($file['chdate'] >= $last_visit) ? true : false; } return ($type !== 'folder' && !is_array($id)) ? reset($files) : $files; diff --git a/routes/news.php b/routes/news.php index 0a6ef18..3ffe503 100644 --- a/routes/news.php +++ b/routes/news.php @@ -38,9 +38,9 @@ public function routes(&$router) if (!Helper::UserHasAccessToRange($range_id)) { $router->halt(403, sprintf('User may not access range "%s"', $range_id)); } - + $last_visit = object_get_visit($range_id, "news"); $result = array( - 'news' => News::loadRange($range_id, $offset, $limit), + 'news' => News::loadRange($range_id, $offset, $limit, $last_visit), 'pagination' => $router->paginate($total, $offset, $limit, '/news/range', $range_id), ); @@ -203,7 +203,7 @@ public static function countRange($range_id) return $statement->fetchColumn(); } - public static function loadRange($range_id, $offset = 0, $limit = 10) + public static function loadRange($range_id, $offset = 0, $limit = 10, $last_visit = 7776000) { $offset = (int) $offset; $limit = (int) $limit; @@ -220,7 +220,12 @@ public static function loadRange($range_id, $offset = 0, $limit = 10) $statement->bindValue(':range_id', $range_id); $statement->execute(); - $news = $statement->fetchAll(PDO::FETCH_ASSOC); + $result = $statement->fetchAll(PDO::FETCH_ASSOC); + + foreach($result as $ne) { + $ne['new'] = ($ne['chdate'] >= $last_visit) ? true : false; + $news[] = $ne; + } $news = array_map('self::adjust', $news); return $news;