ILIAS  release_8 Revision v8.24
PageMetricsService.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
29use ilException;
32
38{
41
43 {
44 $this->pageMetricsRepository = $pageMetricsRepository;
45 $this->refinery = $refinery;
46 }
47
48 protected function doesPageExistsForLanguage(int $contentPageId, string $language): bool
49 {
50 return ilContentPagePage::_exists(self::OBJ_TYPE, $contentPageId, $language, true);
51 }
52
53 protected function ensurePageObjectExists(int $contentPageId, string $language): void
54 {
55 if (!$this->doesPageExistsForLanguage($contentPageId, $language)) {
56 $pageObject = new ilContentPagePage();
57 $pageObject->setParentId($contentPageId);
58 $pageObject->setId($contentPageId);
59 $pageObject->setLanguage($language);
60 $pageObject->createFromXML();
61 }
62 }
63
68 public function store(StorePageMetricsCommand $command): void
69 {
70 $this->ensurePageObjectExists($command->getContentPageId(), $command->getLanguage());
71
72 $pageObjectGUI = new ilContentPagePageGUI($command->getContentPageId(), 0, false, $command->getLanguage());
73 $pageObjectGUI->setEnabledTabs(false);
74 $pageObjectGUI->setFileDownloadLink(ILIAS_HTTP_PATH);
75 $pageObjectGUI->setFullscreenLink(ILIAS_HTTP_PATH);
76 $pageObjectGUI->setSourcecodeDownloadScript(ILIAS_HTTP_PATH);
77 $pageObjectGUI->setProfileBackUrl(ILIAS_HTTP_PATH);
78 $text = $pageObjectGUI->getHTML();
79
80 $readingTimeTransformation = $this->refinery->string()->estimatedReadingTime();
81 $readingTime = new PageReadingTime($readingTimeTransformation->transform($text));
82
83 $pageMetrics = new PageMetrics(
84 $command->getContentPageId(),
85 $command->getContentPageId(),
86 $command->getLanguage(),
88 );
89 $this->pageMetricsRepository->store($pageMetrics);
90 }
91
97 public function get(GetPageMetricsCommand $command): PageMetrics
98 {
99 return $this->pageMetricsRepository->findBy(
100 $command->getContentPageId(),
101 $command->getContentPageId(),
102 $command->getLanguage()
103 );
104 }
105}
__construct(PageMetricsRepository $pageMetricsRepository, Factory $refinery)
ensurePageObjectExists(int $contentPageId, string $language)
doesPageExistsForLanguage(int $contentPageId, string $language)
Builds data types.
Definition: Factory.php:21
@ilCtrl_Calls ilContentPagePageGUI: ilPageEditorGUI, ilEditClipboardGUI, ilMDEditorGUI @ilCtrl_Calls ...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _exists(string $a_parent_type, int $a_id, string $a_lang="", bool $a_no_cache=false)
Checks whether page exists.
Interface ilContentPageObjectConstants.