ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
class.ReadingTimeManager.php
Go to the documentation of this file.
1<?php
2
20
25{
26 protected \ILIAS\Refinery\Factory $refinery;
28
29 public function __construct()
30 {
31 global $DIC;
32
33 $this->refinery = $DIC->refinery();
34 $this->repo = new ReadingTimeDBRepo();
35 }
36
37 public function saveTime(\ilPageObject $page): void
38 {
39 $minutes = 0;
40
41 $page->buildDom();
42 $xml = $page->getXMLFromDom();
43
44 $transf = $this->refinery->string()->estimatedReadingTime(true);
45 $minutes = $transf->transform(strip_tags($xml));
46 $minutes = max($minutes, 1);
47
48 $this->repo->saveTime(
49 $page->getId(),
50 $page->getParentType(),
51 $page->getLanguage(),
52 $minutes
53 );
54 }
55
56 public function getTime(\ilPageObject $page): int
57 {
58 return $this->repo->getTime(
59 $page->getId(),
60 $page->getParentType(),
61 $page->getLanguage()
62 );
63 }
64
65 public function getTimeForId(
66 string $parent_type,
67 int $page_id,
68 string $lang = "-"
69 ): int {
70 return $this->repo->getTime(
71 $page_id,
72 $parent_type,
73 $lang
74 );
75 }
76
77 public function setMissingReadingTimes(string $parent_type, int $parent_id): void
78 {
79 $pages = $this->repo->getPagesWithMissingReadingTime($parent_type, $parent_id);
80 foreach ($pages as $p) {
82 $p["parent_type"],
83 (int) $p["page_id"],
84 0,
85 $p["lang"]
86 );
87 $this->saveTime($page);
88 }
89 }
90
91 public function getParentReadingTime(
92 string $a_parent_type,
93 int $a_parent_id
94 ): int {
95 return $this->repo->getParentReadingTime($a_parent_type, $a_parent_id);
96 }
97}
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)
static getInstance(string $a_parent_type, int $a_id=0, int $a_old_nr=0, string $a_lang="-")
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