ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilForumThreadObjectTableGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 {
23  private ilForum $mapper;
24  private bool $is_moderator = false;
25  private int $ref_id = 0;
28  private readonly bool $is_post_draft_allowed;
30  private readonly ilObjUser $user;
31  private readonly ilSetting $settings;
32 
33  public function __construct(
34  ilObjForumGUI $a_parent_obj,
35  string $a_parent_cmd,
36  int $ref_id,
37  ForumDto $topicData,
38  bool $is_moderator = false
39  ) {
40  global $DIC;
41 
42  $this->lng = $DIC->language();
43  $this->mainTemplate = $DIC->ui()->mainTemplate();
44  $this->user = $DIC->user();
45  $this->settings = $DIC->settings();
46 
47  $this->parent_cmd = $a_parent_cmd;
48  $this->setIsModerator($is_moderator);
49  $this->setRefId($ref_id);
50  $this->setTopicData($topicData);
51 
52  $id = 'frm_tt_' . substr(md5($this->parent_cmd), 0, 3) . '_' . $this->getRefId();
53  $this->setId($id);
54 
55  $this->setDefaultOrderDirection('DESC');
56  $this->setDefaultOrderField('lp_date');
57  $this->setExternalSorting(true);
58  $this->setExternalSegmentation(true);
59 
60  parent::__construct($a_parent_obj, $a_parent_cmd);
61  $this->mainTemplate->addCss('./assets/css/forum_table.css');
62  $this->is_post_draft_allowed = ilForumPostDraft::isSavePostDraftAllowed();
63  }
64 
65  public function fetchDataAnReturnObject(): array
66  {
67  $excluded_ids = [];
68  if ($this->parent_cmd === 'mergeThreads' &&
69  $this->getSelectedThread() instanceof ilForumTopic) {
70  $excluded_ids[] = $this->getSelectedThread()->getId();
71  }
72 
73  $params = [
74  'is_moderator' => $this->getIsModerator(),
75  'excluded_ids' => $excluded_ids,
76  'order_column' => $this->getOrderField(),
77  'order_direction' => $this->getOrderDirection()
78  ];
79 
80  $data = $this->getMapper()->getAllThreads(
81  $this->topicData->getTopPk(),
82  $params,
83  $this->getLimit(),
84  $this->getOffset()
85  );
86  if ($data['items'] === [] && $this->getOffset() > 0) {
87  $this->resetOffset();
88  $data = $this->getMapper()->getAllThreads(
89  $this->topicData->getTopPk(),
90  $params,
91  $this->getLimit(),
92  $this->getOffset()
93  );
94  }
95 
96  $this->setMaxCount($data['cnt']);
97  $temp_data = (array_map(static function (ilForumTopic $thread): array {
98  return ['thread' => $thread];
99  }, $data['items']));
100 
101  $thread_ids = [];
102  $user_ids = [];
103  foreach ($data['items'] as $thread) {
105  $thread_ids[] = $thread->getId();
106  if ($thread->getDisplayUserId() > 0) {
107  $user_ids[$thread->getDisplayUserId()] = $thread->getDisplayUserId();
108  }
109  }
110 
111  $user_ids = array_merge(
113  $user_ids
114  );
115 
116  ilForumAuthorInformationCache::preloadUserObjects(array_unique($user_ids));
117 
118  return $temp_data;
119  }
120 
121  public function setMapper(ilForum $mapper): self
122  {
123  $this->mapper = $mapper;
124  return $this;
125  }
126 
127  public function getMapper(): ilForum
128  {
129  return $this->mapper;
130  }
131 
132  public function setRefId(int $ref_id): self
133  {
134  $this->ref_id = $ref_id;
135  return $this;
136  }
137 
138  public function getRefId(): int
139  {
140  return $this->ref_id;
141  }
142 
143  public function setIsModerator(bool $is_moderator): self
144  {
145  $this->is_moderator = $is_moderator;
146  return $this;
147  }
148 
149  public function getIsModerator(): bool
150  {
151  return $this->is_moderator;
152  }
153 
154  public function setTopicData(ForumDto $topicData): self
155  {
156  $this->topicData = $topicData;
157  return $this;
158  }
159 
160  public function getSelectedThread(): ?ilForumTopic
161  {
163  }
164 }
Class Forum core functions for forum.
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:31
static getUserIdsOfLastPostsByRefIdAndThreadIds(int $ref_id, array $thread_ids)
setId(string $a_val)
resetOffset(bool $a_in_determination=false)
setExternalSorting(bool $a_val)
setDefaultOrderField(string $a_defaultorderfield)
readonly ilGlobalTemplateInterface $mainTemplate
global $DIC
Definition: shib_login.php:25
setDefaultOrderDirection(string $a_defaultorderdirection)
__construct(Container $dic, ilPlugin $plugin)
__construct(ilObjForumGUI $a_parent_obj, string $a_parent_cmd, int $ref_id, ForumDto $topicData, bool $is_moderator=false)
setMaxCount(int $a_max_count)
set max.
setExternalSegmentation(bool $a_val)