Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions classes/observers/events/UsageEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use APP\core\Application;
use APP\core\PageRouter;
use APP\monograph\Chapter;
use APP\publication\Publication;
use APP\section\Section;
use APP\submission\Submission;
use Exception;
Expand All @@ -32,11 +33,11 @@ class UsageEvent extends \PKP\observers\events\UsageEvent
public ?Chapter $chapter;
public ?Section $series;

public function __construct(int $assocType, Context $context, ?Submission $submission = null, ?Representation $publicationFormat = null, ?SubmissionFile $submissionFile = null, ?Chapter $chapter = null, ?Section $series = null)
public function __construct(int $assocType, Context $context, ?Submission $submission = null, ?Representation $publicationFormat = null, ?SubmissionFile $submissionFile = null, ?Chapter $chapter = null, ?Section $series = null, ?Publication $publication = null)
{
$this->chapter = $chapter;
$this->series = $series;
parent::__construct($assocType, $context, $submission, $publicationFormat, $submissionFile);
parent::__construct($assocType, $context, $submission, $publicationFormat, $submissionFile, $publication);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/ui-library
25 changes: 22 additions & 3 deletions pages/catalog/CatalogBookHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,20 @@ public function book($args, $request)
if (!Hook::call('CatalogBookHandler::book', [&$request, &$submission, &$this->publication, &$this->chapter])) {
$templateMgr->display('frontend/pages/book.tpl');
if ($this->isChapterRequest) {
event(new UsageEvent(Application::ASSOC_TYPE_CHAPTER, $request->getContext(), $submission, null, null, $this->chapter));
event(new UsageEvent(
assocType: Application::ASSOC_TYPE_CHAPTER,
context: $request->getContext(),
submission: $submission,
chapter: $this->chapter,
publication: $this->publication,
));
} else {
event(new UsageEvent(Application::ASSOC_TYPE_SUBMISSION, $request->getContext(), $submission));
event(new UsageEvent(
assocType: Application::ASSOC_TYPE_SUBMISSION,
context: $request->getContext(),
submission: $submission,
publication: $this->publication,
));
}
return;
}
Expand Down Expand Up @@ -512,7 +523,15 @@ public function download($args, $request, $view = false)
if ($genre->getCategory() != Genre::GENRE_CATEGORY_DOCUMENT || $genre->getSupplementary() || $genre->getDependent()) {
$assocType = Application::ASSOC_TYPE_SUBMISSION_FILE_COUNTER_OTHER;
}
event(new UsageEvent($assocType, $request->getContext(), $submission, $publicationFormat, $submissionFile, $chapter));
event(new UsageEvent(
assocType: $assocType,
context: $request->getContext(),
submission: $submission,
publicationFormat: $publicationFormat,
submissionFile: $submissionFile,
chapter: $chapter,
publication: $this->publication,
));
}
$returner = true;
Hook::call('FileManager::downloadFileFinished', [&$returner]);
Expand Down
4 changes: 2 additions & 2 deletions pages/catalog/CatalogHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function page($args, $request, $isFirstPage = false)
]);

$templateMgr->display('frontend/pages/catalog.tpl');
event(new UsageEvent(Application::ASSOC_TYPE_PRESS, $context));
event(new UsageEvent(assocType: Application::ASSOC_TYPE_PRESS, context: $context));
return;
}

Expand Down Expand Up @@ -200,7 +200,7 @@ public function series($args, $request)
]);

$templateMgr->display('frontend/pages/catalogSeries.tpl');
event(new UsageEvent(Application::ASSOC_TYPE_SERIES, $context, null, null, null, null, $series));
event(new UsageEvent(assocType: Application::ASSOC_TYPE_SERIES, context: $context, series: $series));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion pages/index/IndexHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function _displayPressIndexPage($press, $request)
}

$templateMgr->display('frontend/pages/index.tpl');
event(new UsageEvent(Application::ASSOC_TYPE_PRESS, $press));
event(new UsageEvent(assocType: Application::ASSOC_TYPE_PRESS, context: $press));
return;
}
}
19 changes: 18 additions & 1 deletion plugins/generic/htmlMonographFile/HtmlMonographFilePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,24 @@ public function downloadCallback($hookName, $params)
$chapterDao = DAORegistry::getDAO('ChapterDAO'); /** @var ChapterDAO $chapterDao */
$chapterId = $submissionFile->getData('chapterId');
$chapter = $chapterId ? $chapterDao->getChapter((int) $chapterId) : null;
event(new UsageEvent(Application::ASSOC_TYPE_SUBMISSION_FILE, $request->getContext(), $submission, $publicationFormat, $submissionFile, $chapter));

/** @var ?Publication */
$filePublication = null;
foreach ($submission->getData('publications') as $publication) {
if ($publication->getId() === $publicationFormat->getData('publicationId')) {
$filePublication = $publication;
break;
}
}
event(new UsageEvent(
assocType: Application::ASSOC_TYPE_SUBMISSION_FILE,
context: $request->getContext(),
submission: $submission,
publicationFormat: $publicationFormat,
submissionFile: $submissionFile,
chapter: $chapter,
publication: $filePublication,
));
return true;
}
}
Expand Down
Loading