ILIAS  release_7 Revision v7.30-3-g800a261c036
PageMetricsService.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2/* Copyright (c) 1998-2020 ILIAS open source, Extended GPL, see docs/LICENSE */
3
5
12use ilException;
15
21{
25 private $refinery;
26
33 {
34 $this->pageMetricsRepository = $pageMetricsRepository;
35 $this->refinery = $refinery;
36 }
37
43 protected function doesPageExistsForLanguage(int $contentPageId, string $language) : bool
44 {
45 return ilContentPagePage::_exists(self::OBJ_TYPE, $contentPageId, $language, true);
46 }
47
52 protected function ensurePageObjectExists(int $contentPageId, string $language) : void
53 {
54 if (!$this->doesPageExistsForLanguage($contentPageId, $language)) {
55 $pageObject = new ilContentPagePage();
56 $pageObject->setParentId($contentPageId);
57 $pageObject->setId($contentPageId);
58 $pageObject->setLanguage($language);
59 $pageObject->createFromXML();
60 }
61 }
62
67 public function store(StorePageMetricsCommand $command) : void
68 {
69 $this->ensurePageObjectExists($command->getContentPageId(), $command->getLanguage());
70
71 $pageObjectGUI = new ilContentPagePageGUI($command->getContentPageId(), 0, false, $command->getLanguage());
72 $pageObjectGUI->setEnabledTabs(false);
73 $pageObjectGUI->setFileDownloadLink(ILIAS_HTTP_PATH);
74 $pageObjectGUI->setFullscreenLink(ILIAS_HTTP_PATH);
75 $pageObjectGUI->setSourcecodeDownloadScript(ILIAS_HTTP_PATH);
76 $pageObjectGUI->setProfileBackUrl(ILIAS_HTTP_PATH);
77 $text = $pageObjectGUI->getHTML();
78
79 $readingTimeTransformation = $this->refinery->string()->estimatedReadingTime();
80 $readingTime = new PageReadingTime($readingTimeTransformation->transform($text));
81
82 $pageMetrics = new PageMetrics(
83 $command->getContentPageId(),
84 $command->getContentPageId(),
85 $command->getLanguage(),
86 $readingTime
87 );
88 $this->pageMetricsRepository->store($pageMetrics);
89 }
90
96 public function get(GetPageMetricsCommand $command) : PageMetrics
97 {
98 return $this->pageMetricsRepository->findBy(
99 $command->getContentPageId(),
100 $command->getContentPageId(),
101 $command->getLanguage()
102 );
103 }
104}
An exception for terminatinating execution or to throw for unit testing.
__construct(PageMetricsRepository $pageMetricsRepository, Factory $refinery)
PageMetricsService constructor.
ensurePageObjectExists(int $contentPageId, string $language)
doesPageExistsForLanguage(int $contentPageId, string $language)
Builds data types.
Definition: Factory.php:20
Class ilContentPagePageGUI @ilCtrl_Calls ilContentPagePageGUI: ilPageEditorGUI, ilEditClipboardGUI,...
Class ilContentPagePage.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _exists($a_parent_type, $a_id, $a_lang="", $a_no_cache=false)
Checks whether page exists.
Interface ilContentPageObjectConstants.