Skip to content

Commit

Permalink
[notes] add view note history page
Browse files Browse the repository at this point in the history
  • Loading branch information
discomrade authored and shish committed Sep 7, 2024
1 parent 505d08a commit 0e47a5e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
31 changes: 31 additions & 0 deletions ext/notes/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ public function onPageRequest(PageRequestEvent $event): void
if ($event->page_matches("note/history/{note_id}", paged: true)) {
$this->get_history($event->get_iarg('note_id'), $event->get_iarg('page_num', 1) - 1);
}
if ($event->page_matches("note_history/{image_id}", paged: true)) {
$this->get_image_history($event->get_iarg('image_id'), $event->get_iarg('page_num', 1) - 1);
}
if ($event->page_matches("note/revert/{noteID}/{reviewID}", permission: Permissions::NOTES_EDIT)) {
$noteID = $event->get_iarg('noteID');
$reviewID = $event->get_iarg('reviewID');
Expand Down Expand Up @@ -152,6 +155,11 @@ public function onPageRequest(PageRequestEvent $event): void
}
}

public function onRobotsBuilding(RobotsBuildingEvent $event): void
{
$event->add_disallow("note_history");
}


/*
* HERE WE LOAD THE NOTES IN THE IMAGE
Expand Down Expand Up @@ -183,6 +191,8 @@ public function onImageAdminBlockBuilding(ImageAdminBlockBuildingEvent $event):
if ($user->can(Permissions::NOTES_REQUEST)) {
$event->add_part($this->theme->request_button($event->image->id));
}

$event->add_button("View Note History", "note_history/{$event->image->id}", 20);
}


Expand Down Expand Up @@ -471,6 +481,27 @@ private function get_history(int $noteID, int $pageNumber): void
$this->theme->display_history($histories, $pageNumber + 1, $totalPages);
}

private function get_image_history(int $imageID, int $pageNumber): void
{
global $config, $database;

$historiesPerPage = $config->get_int('notesHistoriesPerPage');

$histories = $database->get_all(
"SELECT h.note_id, h.review_id, h.image_id, h.date, h.note, u.name AS user_name " .
"FROM note_histories AS h " .
"INNER JOIN users AS u " .
"ON u.id = h.user_id " .
"WHERE image_id = :image_id " .
"ORDER BY date DESC, note_id DESC LIMIT :limit OFFSET :offset",
['image_id' => $imageID, 'offset' => $pageNumber * $historiesPerPage, 'limit' => $historiesPerPage]
);

$totalPages = (int) ceil($database->get_one("SELECT COUNT(*) FROM note_histories WHERE image_id = :image_id", ['image_id' => $imageID]) / $historiesPerPage);

$this->theme->display_image_history($histories, $imageID, $pageNumber + 1, $totalPages);
}

/**
* HERE GO BACK IN HISTORY AND SET THE OLD NOTE. IF WAS REMOVED WE RE-ADD IT.
*/
Expand Down
16 changes: 16 additions & 0 deletions ext/notes/theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,22 @@ public function display_history(array $histories, int $pageNumber, int $totalPag
$this->display_paginator($page, "note/updated", null, $pageNumber, $totalPages);
}

/**
* @param NoteHistory[] $histories
*/
public function display_image_history(array $histories, int $imageID, int $pageNumber, int $totalPages): void
{
global $page;

$html = $this->get_history($histories);

$page->set_title("Note History #$imageID");
$page->set_heading("Note History #$imageID");
$page->add_block(new Block("Note History #$imageID", $html, "main", 10));

$this->display_paginator($page, "note_history/$imageID", null, $pageNumber, $totalPages);
}

public function get_help_html(): string
{
return '<p>Search for posts with notes.</p>
Expand Down

0 comments on commit 0e47a5e

Please sign in to comment.