ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ParagraphResponseFactory.php
Go to the documentation of this file.
1<?php
2
20
22
27{
28 protected \ilLogger $log;
29
30 public function __construct()
31 {
32 $this->log = \ilLoggerFactory::getLogger("copg");
33 }
34
40 public function getResponseObject(
41 \ilPageObjectGUI $page_gui,
42 $updated,
43 string $pcid
44 ): Response {
45 $error = null;
46 $rendered_content = null;
47 $last_change = null;
48
49 if ($updated !== true) {
50 $this->log->debug(print_r($updated, true));
51 if (is_array($updated)) {
52 $error = "";
53 foreach ($updated as $msg) {
54 if (is_array($msg)) {
55 $error .= implode("<br />", $msg);
56 } else {
57 $error .= $msg;
58 }
59 }
60 } elseif (is_string($updated)) {
61 $error = $updated;
62 } else {
63 $error = print_r($updated, true);
64 }
65 } else {
66 $page_gui->setDefaultLinkXml(); // fixes #31087
67 $rendered_content = $this->getParagraphOutput($page_gui, $pcid);
68 $last_change = $page_gui->getPageObject()->getLastChange();
69 }
70
71 $data = new \stdClass();
72 $data->renderedContent = $rendered_content;
73 $data->error = $error;
74 $data->last_update = null;
75 if ($last_change) {
76 $lu = new \ilDateTime($last_change, IL_CAL_DATETIME);
78 $data->last_update = \ilDatePresentation::formatDate($lu, true);
79 }
80
81 return new Response($data);
82 }
83
89 public function getResponseObjectMulti(
90 \ilPageObjectGUI $page_gui,
91 $updated,
92 array $pcids
93 ): Response {
94 $error = null;
95 $rendered_content = null;
96 $last_change = null;
97
98 if ($updated !== true) {
99 if (is_array($updated)) {
100 $error = implode("<br />", $updated);
101 } elseif (is_string($updated)) {
102 $error = $updated;
103 } else {
104 $error = print_r($updated, true);
105 }
106 } else {
107 foreach ($pcids as $pcid) {
108 $rendered_content[$pcid] = $this->getParagraphOutput($page_gui, $pcid);
109 }
110 $last_change = $page_gui->getPageObject()->getLastChange();
111 }
112
113 $data = new \stdClass();
114 $data->renderedContent = $rendered_content;
115 $data->error = $error;
116 $data->last_update = null;
117 if ($last_change) {
118 $lu = new \ilDateTime($last_change, IL_CAL_DATETIME);
120 $data->last_update = \ilDatePresentation::formatDate($lu, true);
121 }
122
123 return new Response($data);
124 }
125
126 protected function getParagraphOutput(
127 \ilPageObjectGUI $page_gui,
128 string $pcid
129 ): string {
131 global $DIC;
132
133 $page_gui->setRawPageContent(true);
134 $page_gui->setAbstractOnly(true, $pcid);
136 $page_gui->setEnabledHref(false);
137 //$html = $page_gui->showPage();
138 $html = $DIC->ctrl()->getHTML($page_gui);
139
140 $pos = strrpos($html, "<!--COPage-PageTop-->");
141 if ($pos > 0) {
142 $html = substr($html, $pos + 21);
143 }
144 return $html;
145 }
146}
getResponseObjectMulti(\ilPageObjectGUI $page_gui, $updated, array $pcids)
Get response data object for multi actions.
getResponseObject(\ilPageObjectGUI $page_gui, $updated, string $pcid)
Get response data object.
ilErrorHandling $error
Definition: class.ilias.php:69
const IL_CAL_DATETIME
static setUseRelativeDates(bool $a_status)
set use relative dates
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
static getLogger(string $a_component_id)
Get component logger.
Class ilPageObjectGUI.
setEnabledHref(bool $enable)
setAbstractOnly(bool $a_val, string $pcid="")
Get only abstract (first text paragraph)
setRawPageContent(bool $a_rawpagecontent)
Set Get raw page content only.
setOutputMode(string $a_mode=self::PRESENTATION)
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