ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ReadingTimeManager.php
Go to the documentation of this file.
1<?php
2
20
25{
29 protected $refinery;
30
34 protected $repo;
35
36 public function __construct()
37 {
39 global $DIC;
40
41 $this->refinery = $DIC->refinery();
42 $this->repo = new ReadingTimeDBRepo();
43 }
44
45 public function saveTime(\ilPageObject $page): void
46 {
47 $minutes = 0;
48
49 $page->buildDom();
50 $xml = $page->getXMLFromDom();
51
52 $transf = $this->refinery->string()->estimatedReadingTime(true);
53 $minutes = $transf->transform(strip_tags($xml));
54 $minutes = max($minutes, 1);
55
56 $this->repo->saveTime(
57 $page->getId(),
58 $page->getParentType(),
59 $page->getLanguage(),
60 $minutes
61 );
62 }
63
64 public function getTime(\ilPageObject $page): int
65 {
66 return $this->repo->getTime(
67 $page->getId(),
68 $page->getParentType(),
69 $page->getLanguage()
70 );
71 }
72
73 public function getTimeForId(
74 string $parent_type,
75 int $page_id,
76 string $lang = "-"
77 ): int {
78 return $this->repo->getTime(
79 $page_id,
80 $parent_type,
81 $lang
82 );
83 }
84
85 public function setMissingReadingTimes(string $parent_type, int $parent_id): void
86 {
87 $pages = $this->repo->getPagesWithMissingReadingTime($parent_type, $parent_id);
88 foreach ($pages as $p) {
90 $p["parent_type"],
91 (int) $p["page_id"],
92 0,
93 $p["lang"]
94 );
95 $this->saveTime($page);
96 }
97 }
98
99 public function getParentReadingTime(
100 string $a_parent_type,
101 int $a_parent_id
102 ): int {
103 return $this->repo->getParentReadingTime($a_parent_type, $a_parent_id);
104 }
105}
getTimeForId(string $parent_type, int $page_id, string $lang="-")
getParentReadingTime(string $a_parent_type, int $a_parent_id)
setMissingReadingTimes(string $parent_type, int $parent_id)
__construct()
Constructor setup ILIAS global object @access public.
Definition: class.ilias.php:76
static getInstance(string $a_parent_type, int $a_id=0, int $a_old_nr=0, string $a_lang="-")
Get page object instance.
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
getXMLFromDom(bool $a_incl_head=false, bool $a_append_mobs=false, bool $a_append_bib=false, string $a_append_str="", bool $a_omit_pageobject_tag=false, int $style_id=0, bool $offline=false)
get xml content of page from dom (use this, if any changes are made to the document)
buildDom(bool $a_force=false)
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:26
$lang
Definition: xapiexit.php:25