ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilAsyncOutputHandler.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
23 
32 {
33  private const OUTPUT_MODAL = "output_modal";
34  private const OUTPUT_EMPTY = "output_empty";
35 
39  protected $content;
40 
44  protected $heading;
45 
46  protected array $window_properties;
47 
48  public function __construct($content = null, $heading = null, array $windows_properties = array())
49  {
50  $this->content = $content;
51  $this->heading = $heading;
52  $this->window_properties = $windows_properties;
53  }
54 
60  public function terminate(string $type = self::OUTPUT_MODAL): void
61  {
62  if ($type === self::OUTPUT_MODAL) {
63  $tpl = new ilTemplate('tpl.modal_content.html', false, false, 'Modules/StudyProgramme');
64  $tpl->setVariable('HEADING', $this->getHeading());
65  $tpl->setVariable('BODY', $this->getContent());
66 
67  //TODO: implement window properties
68  /*foreach($this->window_properties as $key => $value) {
69  if($value) {
70  $tpl->activeBlock($key);
71  } else {
72  $tpl->removeBlockData($key);
73  }
74  }*/
75 
76  echo $tpl->get();
77  exit();
78  }
79 
80  if ($type === self::OUTPUT_EMPTY) {
81  echo $this->getContent();// TODO PHP8-REVIEW I sugges to use the HTTP service instead of echo/exit
82  exit();
83  }
84  }
85 
89  public static function encodeAsyncResponse(array $data = array()): string
90  {
91  global $DIC;
92  $ilCtrl = $DIC['ilCtrl'];
93 
94  $data['cmd'] = $ilCtrl->getCmd();
95 
96  return json_encode($data, JSON_THROW_ON_ERROR);
97  }
98 
104  public static function handleAsyncOutput(
105  string $normal_content,
106  string $async_content = null,
107  bool $apply_to_tpl = true
108  ) {
109  global $DIC;
110  $ilCtrl = $DIC['ilCtrl'];
111  $tpl = $DIC['tpl'];
112  $http = $DIC['http'];
113 
114  $content = ($ilCtrl->isAsynch() && $async_content !== null) ? $async_content : $normal_content;
115 
116  if ($ilCtrl->isAsynch()) {
117  $http->saveResponse(
118  $http->response()
119  ->withHeader(ResponseHeader::CONTENT_TYPE, 'text/html')
120  ->withBody(Streams::ofString($content))
121  );
122  $http->sendResponse();
123  $http->close();
124  exit();
125  } elseif ($apply_to_tpl) {
126  $tpl->setContent($content);
127  } else {
128  return $content;
129  }
130  }
131 
137  public function getContent()
138  {
139  return $this->content;
140  }
141 
147  public function setContent($content): void
148  {
149  $this->content = $content;
150  }
151 
157  public function getHeading()
158  {
159  return $this->heading;
160  }
161 
167  public function setHeading($heading): void
168  {
169  $this->heading = $heading;
170  }
171 
175  public function getWindowProperties(): array
176  {
178  }
179 
183  public function setWindowProperties(array $window_properties): void
184  {
185  $this->window_properties = $window_properties;
186  }
187 }
getWindowProperties()
Return all window properties.
Class ilAsyncOutputHandler Handles the output for async-requests.
getHeading()
Return the heading of a modal.
exit
Definition: login.php:28
$type
static handleAsyncOutput(string $normal_content, string $async_content=null, bool $apply_to_tpl=true)
Handles async output.
__construct($content=null, $heading=null, array $windows_properties=array())
global $DIC
Definition: feed.php:28
setWindowProperties(array $window_properties)
Set windows properties.
static encodeAsyncResponse(array $data=array())
Encode data as json for async output.
setContent($content)
Sets the content of the modal output.
getContent()
Returns the content of the modal output.
$http
Definition: raiseError.php:7
terminate(string $type=self::OUTPUT_MODAL)
Output content in different ways self::OUTPUT_MODAL: Output as bootstrap modal self::OUTPUT_EMPTY: On...
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
setHeading($heading)
Sets the heading of a modal-output.