ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilWikiPagesTableGUI.php
Go to the documentation of this file.
1 <?php
2 
20 
21 const IL_WIKI_ALL_PAGES = "all";
22 const IL_WIKI_NEW_PAGES = "new";
23 const IL_WIKI_POPULAR_PAGES = "popular";
24 const IL_WIKI_WHAT_LINKS_HERE = "what_links";
25 const IL_WIKI_ORPHANED_PAGES = "orphaned";
26 
33 {
34  protected \ILIAS\Wiki\Links\LinkManager $link_manager;
35  protected string $requested_lang;
36  protected string $lang;
37  protected Translations $ot;
38  protected \ILIAS\Wiki\Page\PageManager $pm;
39  protected int $requested_ref_id;
40  protected int $page_id = 0;
41  protected int $wiki_id = 0;
42  protected string $pg_list_mode = "";
43 
44  public function __construct(
45  object $a_parent_obj,
46  string $a_parent_cmd,
47  int $a_wiki_id,
48  string $a_mode = IL_WIKI_ALL_PAGES,
49  int $a_page_id = 0,
50  string $lang = "-"
51  ) {
52  global $DIC;
53  $this->lang = ($lang == "")
54  ? "-"
55  : $lang;
56  $service = $DIC->wiki()->internal();
57  $gui = $service->gui();
58  $domain = $service->domain();
59  $this->ctrl = $gui->ctrl();
60  $this->lng = $domain->lng();
61  $this->requested_ref_id = $gui
62  ->request()
63  ->getRefId();
64  $this->requested_lang = $gui->request()->getTranslation();
65  $this->pm = $domain->page()->page($this->requested_ref_id);
66  $this->link_manager = $domain->links($this->requested_ref_id);
67  $this->ot = $domain->wiki()->translation($this->requested_ref_id);
68 
69  parent::__construct($a_parent_obj, $a_parent_cmd);
70  $this->pg_list_mode = $a_mode;
71  $this->wiki_id = $a_wiki_id;
72  $this->page_id = $a_page_id;
73 
74  switch ($this->pg_list_mode) {
75  case IL_WIKI_NEW_PAGES:
76  $this->addColumn($this->lng->txt("created"), "created");
77  $this->addColumn($this->lng->txt("wiki_page"), "title");
78  $this->addLanguageColumn();
79  $this->addColumn($this->lng->txt("wiki_created_by"), "user_sort");
80  $this->setRowTemplate(
81  "tpl.table_row_wiki_new_page.html",
82  "components/ILIAS/Wiki"
83  );
84  break;
85 
87  $this->addColumn($this->lng->txt("wiki_page"), "title");
88  $this->addLanguageColumn();
89  $this->addColumn($this->lng->txt("wiki_page_hits"), "cnt");
90  $this->setRowTemplate(
91  "tpl.table_row_wiki_popular_page.html",
92  "components/ILIAS/Wiki"
93  );
94  break;
95 
97  $this->addColumn($this->lng->txt("wiki_page"), "title");
98  $this->addLanguageColumn();
99  $this->setRowTemplate(
100  "tpl.table_row_wiki_orphaned_page.html",
101  "components/ILIAS/Wiki"
102  );
103  break;
104 
105  default:
106  $this->addColumn($this->lng->txt("wiki_page"), "title");
107  $this->addColumn($this->lng->txt("wiki_last_changed"), "date");
108  if ($this->pg_list_mode !== IL_WIKI_WHAT_LINKS_HERE) {
109  $this->addTranslationsColumn();
110  }
111  $this->addColumn($this->lng->txt("wiki_last_changed_by"), "user_sort");
112  $this->setRowTemplate(
113  "tpl.table_row_wiki_page.html",
114  "components/ILIAS/Wiki"
115  );
116  break;
117  }
118  $this->setEnableHeader(true);
119  $this->setFormAction($this->ctrl->getFormAction($a_parent_obj));
120  $this->getPages();
121 
122  $this->setShowRowsSelector(true);
123 
124  switch ($this->pg_list_mode) {
126  $this->setTitle(
127  sprintf(
128  $this->lng->txt("wiki_what_links_to_page"),
129  ilWikiPage::lookupTitle($this->page_id)
130  )
131  );
132  break;
133 
134  default:
135  $this->setTitle($this->lng->txt("wiki_" . $a_mode . "_pages"));
136  break;
137  }
138  }
139 
140  protected function addLanguageColumn(): void
141  {
142  if ($this->ot->getContentTranslationActivated()) {
143  $this->addColumn($this->lng->txt("language"));
144  }
145  }
146 
147  protected function addTranslationsColumn(): void
148  {
149  if ($this->ot->getContentTranslationActivated()) {
150  $this->addColumn($this->lng->txt("wiki_translations"));
151  }
152  }
153 
154  public function getPages(): void
155  {
156  $pages = array();
157  $this->setDefaultOrderField("title");
158 
159  switch ($this->pg_list_mode) {
161  foreach ($this->link_manager->getLinksToPage($this->page_id, $this->lang) as $pi) {
162  $pages[] = [
163  "date" => $pi->getLastChange(),
164  "id" => $pi->getId(),
165  "user" => $pi->getLastChangedUser(),
166  "title" => $pi->getTitle(),
167  "lang" => $pi->getLanguage()
168  ];
169  }
170  break;
171 
172  case IL_WIKI_ALL_PAGES:
173  foreach ($this->pm->getAllPagesInfo() as $pi) {
174  $pages[] = [
175  "date" => $pi->getLastChange(),
176  "id" => $pi->getId(),
177  "user" => $pi->getLastChangedUser(),
178  "title" => $pi->getTitle()
179  ];
180  }
181  break;
182 
183  case IL_WIKI_NEW_PAGES:
184  $this->setDefaultOrderField("created");
185  $this->setDefaultOrderDirection("desc");
186  //$pages = ilWikiPage::getNewWikiPages($this->wiki_id);
187  foreach ($this->pm->getNewPages() as $pi) {
188  $pages[] = [
189  "created" => $pi->getCreated(),
190  "id" => $pi->getId(),
191  "user" => $pi->getCreateUser(),
192  "title" => $pi->getTitle(),
193  "lang" => $pi->getLanguage()
194  ];
195  }
196  break;
197 
199  $this->setDefaultOrderField("cnt");
200  $this->setDefaultOrderDirection("desc");
201  //$pages = ilWikiPage::getPopularPages($this->wiki_id);
202  foreach ($this->pm->getPopularPages() as $pi) {
203  $pages[] = [
204  "id" => $pi->getId(),
205  "title" => $pi->getTitle(),
206  "lang" => $pi->getLanguage(),
207  "cnt" => $pi->getViewCnt(),
208  ];
209  }
210  break;
211 
213  foreach ($this->pm->getOrphanedPages() as $pi) {
214  $pages[] = [
215  "id" => $pi->getId(),
216  "title" => $pi->getTitle(),
217  "date" => $pi->getLastChange()
218  ];
219  }
220  break;
221  }
222 
223  if ($pages) {
224  // enable sorting
225  foreach (array_keys($pages) as $idx) {
226  if (isset($pages[$idx]["user"])) {
227  $pages[$idx]["user_sort"] = ilUserUtil::getNamePresentation($pages[$idx]["user"], false, false);
228  }
229  }
230  }
231 
232  $this->setData($pages);
233  }
234 
235  public function numericOrdering(string $a_field): bool
236  {
237  if ($a_field === "cnt") {
238  return true;
239  }
240  return false;
241  }
242 
243  protected function fillRow(array $a_set): void
244  {
245  $ilCtrl = $this->ctrl;
246 
247  if ($this->pg_list_mode === IL_WIKI_NEW_PAGES) {
248  if ($this->ot->getContentTranslationActivated() && $this->pg_list_mode !== IL_WIKI_WHAT_LINKS_HERE) {
249  $l = $a_set["lang"] === "-"
250  ? $this->ot->getBaseLanguage()
251  : $a_set["lang"];
252  $this->tpl->setCurrentBlock("lang");
253  $this->tpl->setVariable("LANG", $this->lng->txt("meta_l_" . $l));
254  $this->tpl->parseCurrentBlock();
255  }
256  $this->tpl->setVariable("TXT_PAGE_TITLE", $a_set["title"]);
257  $this->tpl->setVariable(
258  "DATE",
260  );
261  } elseif ($this->pg_list_mode === IL_WIKI_POPULAR_PAGES) {
262  if ($this->ot->getContentTranslationActivated()) {
263  $l = $a_set["lang"] === "-"
264  ? $this->ot->getBaseLanguage()
265  : $a_set["lang"];
266  $this->tpl->setCurrentBlock("lang");
267  $this->tpl->setVariable("LANG", $this->lng->txt("meta_l_" . $l));
268  $this->tpl->parseCurrentBlock();
269  }
270  $this->tpl->setVariable("TXT_PAGE_TITLE", $a_set["title"]);
271  $this->tpl->setVariable("HITS", $a_set["cnt"]);
272  } else {
273  $this->tpl->setVariable("TXT_PAGE_TITLE", $a_set["title"]);
274  $this->tpl->setVariable(
275  "DATE",
277  );
278  if ($this->ot->getContentTranslationActivated() && $this->pg_list_mode !== IL_WIKI_WHAT_LINKS_HERE) {
279  $this->tpl->setCurrentBlock("lang");
280  $this->tpl->setVariable("LANG", implode(", ", $this->pm->getLanguages($a_set["id"])));
281  $this->tpl->parseCurrentBlock();
282  }
283  }
284  $this->tpl->setVariable(
285  "HREF_PAGE",
286  $this->pm->getPermaLink($a_set["id"], $a_set["lang"] ?? "")
287  );
288 
289  // user name
290  $this->tpl->setVariable(
291  "TXT_USER",
293  $a_set["user"] ?? 0,
294  true,
295  true,
296  $ilCtrl->getLinkTarget($this->getParentObject(), $this->getParentCmd())
297  )
298  );
299  }
300 }
setData(array $a_data)
ILIAS Wiki Links LinkManager $link_manager
const IL_CAL_DATETIME
const IL_WIKI_POPULAR_PAGES
setFormAction(string $a_form_action, bool $a_multipart=false)
static lookupTitle(int $a_page_id, string $lang="-")
Class handles translation mode for an object.
TableGUI class for wiki pages table.
setShowRowsSelector(bool $a_value)
Toggle rows-per-page selector.
static getNamePresentation( $a_user_id, bool $a_user_image=false, bool $a_profile_link=false, string $a_profile_back_link='', bool $a_force_first_lastname=false, bool $a_omit_login=false, bool $a_sortable=true, bool $a_return_data_array=false, $a_ctrl_path='ilpublicuserprofilegui')
Default behaviour is:
setDefaultOrderField(string $a_defaultorderfield)
ILIAS Wiki Page PageManager $pm
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
global $DIC
Definition: shib_login.php:26
setDefaultOrderDirection(string $a_defaultorderdirection)
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
const IL_WIKI_WHAT_LINKS_HERE
const IL_WIKI_ALL_PAGES
__construct(Container $dic, ilPlugin $plugin)
__construct(object $a_parent_obj, string $a_parent_cmd, int $a_wiki_id, string $a_mode=IL_WIKI_ALL_PAGES, int $a_page_id=0, string $lang="-")
const IL_WIKI_ORPHANED_PAGES
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
$service
Definition: ltiservices.php:40
setEnableHeader(bool $a_enableheader)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const IL_WIKI_NEW_PAGES