ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ParagraphResponseFactory.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2020 ILIAS open source, Extended GPL, see docs/LICENSE */
4
6
8
14{
18 protected $log;
22 public function __construct()
23 {
24 $this->log = \ilLoggerFactory::getLogger("copg");
25 }
26
34 public function getResponseObject(\ilPageObjectGUI $page_gui, $updated, string $pcid) : Server\Response
35 {
36 $error = null;
37 $rendered_content = null;
38 $last_change = null;
39
40 if ($updated !== true) {
41 $this->log->debug(print_r($updated, true));
42 if (is_array($updated)) {
43 $error = "";
44 foreach ($updated as $msg) {
45 if (is_array($msg)) {
46 $error.= implode("<br />", $msg);
47 } else {
48 $error.= (string) $msg;
49 }
50 }
51 } elseif (is_string($updated)) {
52 $error = $updated;
53 } else {
54 $error = print_r($updated, true);
55 }
56 } else {
57 $page_gui->setDefaultLinkXml(); // fixes #31087
58 $rendered_content = $this->getParagraphOutput($page_gui, $pcid);
59 $last_change = $page_gui->getPageObject()->getLastChange();
60 }
61
62 $data = new \stdClass();
63 $data->renderedContent = $rendered_content;
64 $data->error = $error;
65 $data->last_update = null;
66 if ($last_change) {
67 $lu = new \ilDateTime($last_change, IL_CAL_DATETIME);
69 $data->last_update = \ilDatePresentation::formatDate($lu, true);
70 }
71
72 return new Server\Response($data);
73 }
74
82 public function getResponseObjectMulti(\ilPageObjectGUI $page_gui, $updated, array $pcids) : Server\Response
83 {
84 $error = null;
85 $rendered_content = null;
86 $last_change = null;
87
88 if ($updated !== true) {
89 if (is_array($updated)) {
90 $error = implode("<br />", $updated);
91 } elseif (is_string($updated)) {
92 $error = $updated;
93 } else {
94 $error = print_r($updated, true);
95 }
96 } else {
97 foreach ($pcids as $pcid) {
98 $rendered_content[$pcid] = $this->getParagraphOutput($page_gui, $pcid);
99 }
100 $last_change = $page_gui->getPageObject()->getLastChange();
101 }
102
103 $data = new \stdClass();
104 $data->renderedContent = $rendered_content;
105 $data->error = $error;
106 $data->last_update = null;
107 if ($last_change) {
108 $lu = new \ilDateTime($last_change, IL_CAL_DATETIME);
110 $data->last_update = \ilDatePresentation::formatDate($lu, true);
111 }
112
113 return new Server\Response($data);
114 }
115
121 protected function getParagraphOutput(\ilPageObjectGUI $page_gui, $pcid)
122 {
124 global $DIC;
125
126 $page_gui->setRawPageContent(true);
127 $page_gui->setAbstractOnly(true, $pcid);
129 $page_gui->setEnabledHref(false);
130 //$html = $page_gui->showPage();
131 $html = $DIC->ctrl()->getHTML($page_gui);
132
133 $pos = strrpos($html, "<!--COPage-PageTop-->");
134 if ($pos > 0) {
135 $html = substr($html, $pos + 21);
136 }
137 return $html;
138 }
139}
An exception for terminatinating execution or to throw for unit testing.
getResponseObject(\ilPageObjectGUI $page_gui, $updated, string $pcid)
Get reponse data object.
getResponseObjectMulti(\ilPageObjectGUI $page_gui, $updated, array $pcids)
Get reponse data object.
Page editor json server.
const IL_CAL_DATETIME
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
static setUseRelativeDates($a_status)
set use relative dates
static getLogger($a_component_id)
Get component logger.
Class ilPageObjectGUI.
setEnabledHref(bool $enable)
setRawPageContent($a_rawpagecontent)
Set Get raw page content only.
setOutputMode($a_mode=self::PRESENTATION)
Set Output Mode.
setAbstractOnly($a_val, $pcid="")
Set abstract only.
getPageObject()
Get Page Object.
setDefaultLinkXml()
Set standard link xml.
global $DIC
Definition: goto.php:24
$data
Definition: storeScorm.php:23