ILIAS  release_7 Revision v7.30-3-g800a261c036
PageMetricsRepositoryImpl.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
9
16{
18 private $db;
19
24 public function __construct(ilDBInterface $db)
25 {
26 $this->db = $db;
27 }
28
32 public function store(PageMetrics $pageMetrics) : void
33 {
34 $this->db->replace(
35 'content_page_metrics',
36 [
37 'content_page_id' => ['integer', $pageMetrics->contentPageId()],
38 'page_id' => ['integer', $pageMetrics->pageId()],
39 'lang' => ['text', $pageMetrics->language()],
40 ],
41 [
42 'reading_time' => ['integer', $pageMetrics->readingTime()->minutes()],
43 ]
44 );
45 }
46
50 public function delete(PageMetrics $pageMetrics) : void
51 {
52 $this->db->queryF(
53 "DELETE FROM content_page_metrics WHERE content_page_id = %s AND page_id = %s AND lang = %s",
54 ['integer', 'integer', 'text'],
55 [$pageMetrics->contentPageId(), $pageMetrics->pageId(), $pageMetrics->language()]
56 );
57 }
58
62 public function findBy(int $contentPageId, int $pageId, string $language) : PageMetrics
63 {
64 $res = $this->db->queryF(
65 "SELECT * FROM content_page_metrics WHERE content_page_id = %s AND page_id = %s AND lang = %s",
66 ['integer', 'integer', 'text'],
67 [$contentPageId, $pageId, $language]
68 );
69 $row = $this->db->fetchAssoc($res);
70 if (is_array($row) && isset($row['content_page_id'])) {
71 return new PageMetrics(
72 (int) $row['content_page_id'],
73 (int) $row['page_id'],
74 $row['lang'],
75 new PageReadingTime((int) $row['reading_time'])
76 );
77 }
78
79 throw CouldNotFindPageMetrics::by($contentPageId, $pageId, $language);
80 }
81}
An exception for terminatinating execution or to throw for unit testing.
static by(int $contentPageId, int $pageId, string $language)
__construct(ilDBInterface $db)
PageMetricsRepositoryImp constructor.
findBy(int $contentPageId, int $pageId, string $language)
@inheritDoc
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
foreach($_POST as $key=> $value) $res