Skip to content
This repository has been archived by the owner on Dec 2, 2022. It is now read-only.

Commit

Permalink
refine response for documents and news refs #112
Browse files Browse the repository at this point in the history
  • Loading branch information
André committed May 27, 2015
1 parent 80bae5b commit ec38255
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
tests/junit_log.xml

.idea
*.patch
6 changes: 4 additions & 2 deletions routes/documents.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand Down
13 changes: 9 additions & 4 deletions routes/news.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);

Expand Down Expand Up @@ -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;
Expand All @@ -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) {

This comment has been minimized.

Copy link
@rockihack

rockihack May 30, 2015

Contributor

Man könnte hier Referenzen benutzen anstatt ein neues Array anzulegen.

$ne['new'] = ($ne['chdate'] >= $last_visit) ? true : false;
$news[] = $ne;
}
$news = array_map('self::adjust', $news);

return $news;
Expand Down

0 comments on commit ec38255

Please sign in to comment.