ILIAS  trunk Revision v13.0_alpha-52-g21c366bbdd4
class.ilObjBlogListGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
28{
29 private ?Modal $comment_modal = null;
30 protected \ILIAS\Blog\InternalService $blog_service;
31
32 public function __construct(int $context = self::CONTEXT_REPOSITORY)
33 {
34 global $DIC;
36 $this->blog_service = $DIC->blog()->internal();
37 }
38
39 public function init(): void
40 {
41 $this->copy_enabled = true;
42 $this->delete_enabled = true;
43 $this->cut_enabled = true;
44 $this->subscribe_enabled = true;
45 $this->link_enabled = true; // #10498
46 $this->info_screen_enabled = true;
47 $this->type = "blog";
48 $this->gui_class_name = "ilobjbloggui";
49
50 // general commands array
51 $this->commands = ilObjBlogAccess::_getCommands();
52 }
53
54 public function getCommands(): array
55 {
56 $commands = parent::getCommands();
57
58 // #10182 - handle edit and contribute
59 $permissions = array();
60 foreach ($commands as $idx => $item) {
61 if ($item["lang_var"] === "edit" && $item["granted"]) {
62 $permissions[$item["permission"]] = $idx;
63 }
64 }
65 if (count($permissions) === 2) {
66 unset($commands[$permissions["contribute"]]);
67 }
68
69 return $commands;
70 }
71
72 public function insertCommand(
73 string $href,
74 string $text,
75 string $frame = "",
76 string $img = "",
77 string $cmd = "",
78 string $onclick = ""
79 ): void {
80 $blog_service = $this->blog_service;
81
82 $tpl = $this->ui->mainTemplate();
83 $export_possible = $blog_service->domain()
84 ->export()
85 ->manager()
86 ->isCommentsExportPossible($this->obj_id);
87 if ($cmd === "export"
88 && $export_possible
89 && (bool) $this->settings->get('item_cmd_asynch')) {
90 $href = $this->getCommandLink("forwardExport");
91 $cmd = "forwardExport";
92 $onclick = "";
93 }
94 if ($cmd !== "export" || !$export_possible) {
95 parent::insertCommand($href, $text, $frame, $img, $cmd, $onclick);
96 return;
97 }
98
99 // #11099
100 $chksum = md5($href . $text);
101 if ($href === "#" ||
102 !in_array($chksum, $this->prevent_duplicate_commands)) {
103 if ($href !== "#") {
104 $this->prevent_duplicate_commands[] = $chksum;
105 }
106
107 $prevent_background_click = false;
108
109 if ($export_possible) {
110
111 $modal = $this->getModalTemplate();
112 $signal = $modal["show"];
113 $tpl->addJavaScript('assets/js/blog.js');
114 $tpl->addOnLoadCode('il.blog.setModalTemplate("' . $signal . '", "' . addslashes(json_encode($modal["template"])) . '");');
115
116
117 $action = $this->ui->factory()
118 ->button()
119 ->shy($text, "#");
120
121 $action = $action->withOnLoadCode(function ($id) use ($onclick, $signal): string {
122 return "document.getElementById('$id').addEventListener('click', (event) => {event.preventDefault(); il.blog.showModal('$signal');});";
123 });
124 $this->current_actions[] = $action;
125 }
126 }
127 }
128
129
130 public function getModalTemplate(): array
131 {
132 $ui = $this->ui;
133
134 $comment_export_helper = new \ILIAS\Notes\Export\ExportHelperGUI();
135 $this->lng->loadLanguageModule("note");
136 $modal = $comment_export_helper->getCommentIncludeModalDialog(
137 'HTML Export',
138 $this->lng->txt("note_html_export_include_comments"),
139 $this->getCommandLink("export"),
140 $this->getCommandLink("exportWithComments")
141 );
142
143 $modalt["show"] = $modal->getShowSignal()->getId();
144 $modalt["close"] = $modal->getCloseSignal()->getId();
145 $modalt["template"] = $ui->renderer()->renderAsync($modal);
146
147 return $modalt;
148 }
149
150 public function getCommandLink(string $cmd): string
151 {
152 if ($this->context == self::CONTEXT_REPOSITORY || $this->context == self::CONTEXT_SEARCH) {
153 $id_par = "ref_id";
154 } else {
155 $id_par = "wsp_id";
156 }
157 switch ($cmd) {
158 case "export":
159 case "exportWithComments":
160 $this->ctrl->setParameterByClass(ilObjBlogGUI::class, $id_par, $this->ref_id);
161 return $this->ctrl->getLinkTargetByClass(
162 [ilObjBlogGUI::class, \ILIAS\Blog\Export\ExportGUI::class],
163 $cmd
164 );
165 case "render":
166 $this->ctrl->setParameterByClass(ilObjBlogGUI::class, $id_par, $this->ref_id);
167 return $this->ctrl->getLinkTargetByClass(
168 [ilObjBlogGUI::class, \ILIAS\Blog\Editing\EditingGUI::class],
169 ""
170 );
171 break;
172 case "preview":
173 $this->ctrl->setParameterByClass(ilObjBlogGUI::class, $id_par, $this->ref_id);
174 return $this->ctrl->getLinkTargetByClass(
175 [ilObjBlogGUI::class, \ILIAS\Blog\Presentation\PresentationGUI::class],
176 ""
177 );
178 break;
179 }
180 return parent::getCommandLink($cmd);
181 }
182
183
184}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static _getCommands()
get commands
Class ilObjBlogListGUI.
insertCommand(string $href, string $text, string $frame="", string $img="", string $cmd="", string $onclick="")
insert command button
__construct(int $context=self::CONTEXT_REPOSITORY)
ILIAS Blog InternalService $blog_service
getCommands()
get all current commands for a specific ref id (in the permission context of the current user)
This describes commonalities between the different modals.
Definition: Modal.php:35
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $DIC
Definition: shib_login.php:26
$text
Definition: xapiexit.php:21