ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilObjItemGroup.php
Go to the documentation of this file.
1 <?php
2 
20 
26 {
28  protected int $access_type;
29  protected int $access_begin;
30  protected int $access_end;
31  protected bool $access_visibility;
33 
34  public function __construct(
35  int $a_id = 0,
36  bool $a_reference = true
37  ) {
38  global $DIC;
39 
40  $this->log = $DIC["ilLog"];
41  $tree = $DIC->repositoryTree();
42  $objDefinition = $DIC["objDefinition"];
43  $ilDB = $DIC->database();
44 
45  $this->tree = $tree;
46  $this->obj_def = $objDefinition;
47  $this->db = $ilDB;
48 
49  $this->item_data_ar = new ilItemGroupAR();
50 
51  parent::__construct($a_id, $a_reference);
52  }
53 
54  public function setId($a_id): void
55  {
56  parent::setId($a_id);
57  $this->item_data_ar->setId($a_id);
58  }
59 
60  public function initType(): void
61  {
62  $this->type = "itgr";
63  }
64 
65  public function setHideTitle(bool $a_val): void
66  {
67  $this->item_data_ar->setHideTitle($a_val);
68  }
69 
70  public function getHideTitle(): bool
71  {
72  return $this->item_data_ar->getHideTitle();
73  }
74 
78  public function setBehaviour(int $a_val): void
79  {
80  $this->item_data_ar->setBehaviour($a_val);
81  }
82 
83  public function getListPresentation(): string
84  {
85  return $this->item_data_ar->getListPresentation();
86  }
87 
88  public function setListPresentation(string $a_val): void
89  {
90  $this->item_data_ar->setListPresentation($a_val);
91  }
92 
93  public function getTileSize(): int
94  {
95  return $this->item_data_ar->getTileSize();
96  }
97 
98  public function setTileSize(int $a_val): void
99  {
100  $this->item_data_ar->setTileSize($a_val);
101  }
102 
103  public function getBehaviour(): int
104  {
105  return $this->item_data_ar->getBehaviour();
106  }
107 
108  protected function doRead(): void
109  {
110  $this->item_data_ar = new ilItemGroupAR($this->getId());
111  }
112 
113  protected function doCreate(bool $clone_mode = false): void
114  {
115  global $DIC;
116 
117  if ($this->getId()) {
118  $this->item_data_ar->setId($this->getId());
119  $this->item_data_ar->create();
120  }
121 
122  $lng = $DIC->language();
123 
124  // add default translation
125  $obj_trans = $this->getObjectProperties()->getPropertyTranslations();
126  $this->getObjectProperties()->storePropertyTranslations(
127  $obj_trans->withLanguage(
128  new Language(
130  $this->getTitle(),
131  $this->getDescription(),
132  true
133  )
134  )
135  );
136  }
137 
138  protected function doUpdate(): void
139  {
140  if ($this->getId()) {
141  $this->item_data_ar->update();
142 
143  $this->getObjectProperties()->storePropertyTranslations(
144  $this->getObjectProperties()->getPropertyTranslations()
145  ->withDefaultTitle($this->getTitle())
146  ->withDefaultDescription($this->getLongDescription())
147  );
148  }
149  }
150 
151  protected function doDelete(): void
152  {
153  if ($this->getId()) {
154  $this->item_data_ar->delete();
155  }
156  }
157 
158  protected function doCloneObject(ilObject2 $new_obj, int $a_target_id, ?int $a_copy_id = null): void
159  {
160  assert($new_obj instanceof ilObjItemGroup);
161  $new_obj->setHideTitle($this->getHideTitle());
162  $new_obj->setBehaviour($this->getBehaviour());
163  $new_obj->setListPresentation($this->getListPresentation());
164  $new_obj->setTileSize($this->getTileSize());
165 
166 
167  // translations
168  $ot = $this->getObjectProperties()->clonePropertyTranslations($new_obj->getId());
169  if ($ot->getDefaultTitle() !== "") {
170  $new_obj->setTitle($ot->getDefaultTitle());
171  }
172  if ($ot->getDefaultDescription() !== "") {
173  $new_obj->setDescription($ot->getDefaultDescription());
174  }
175 
176  $new_obj->update();
177  }
178 
179  public function cloneDependencies(int $a_target_id, int $a_copy_id): bool
180  {
181  parent::cloneDependencies($a_target_id, $a_copy_id);
182 
183  $ig_items = new ilItemGroupItems($a_target_id);
184  $ig_items->cloneItems($this->getRefId(), $a_copy_id);
185 
186  return true;
187  }
188 
190  ilContainer $a_source_container,
191  int $a_copy_id
192  ): void {
193  global $DIC;
194 
195  $ilLog = $DIC["ilLog"];
196 
197  $ilLog->write(__METHOD__ . ': Fix item group references in ' . $a_source_container->getType());
198 
199  $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
200  $mappings = $cwo->getMappings();
201 
202  $new_container_ref_id = $mappings[$a_source_container->getRefId()];
203  $ilLog->write(__METHOD__ . ': 2-' . $new_container_ref_id . '-');
204  $new_container_obj_id = ilObject::_lookupObjId($new_container_ref_id);
205 
206  $ilLog->write(__METHOD__ . ': 3' . $new_container_obj_id . '-');
207  if (ilPageObject::_exists("cont", $new_container_obj_id)) {
208  $ilLog->write(__METHOD__ . ': 4');
209  $new_page = new ilContainerPage($new_container_obj_id);
210  $new_page->buildDom();
211  ilPCResources::modifyItemGroupRefIdsByMapping($new_page, $mappings);
212  $new_page->update();
213  }
214  $ilLog->write(__METHOD__ . ': 5');
215  }
216 
217  public static function lookupHideTitle(int $a_id): bool
218  {
219  return (bool) self::lookup($a_id, "hide_title");
220  }
221 
222  public static function lookupBehaviour(int $a_id): int
223  {
224  return (int) self::lookup($a_id, "behaviour");
225  }
226 
227  protected static function lookup(int $a_id, string $a_key): string
228  {
229  global $DIC;
230 
231  $ilDB = $DIC->database();
232 
233  $set = $ilDB->query(
234  "SELECT " . $a_key . " FROM itgr_data " .
235  " WHERE id = " . $ilDB->quote($a_id, "integer")
236  );
237  $rec = $ilDB->fetchAssoc($set);
238  return $rec[$a_key];
239  }
240 }
setBehaviour(int $a_val)
Set behaviour (see ilItemGroupBehaviour)
getDefaultLanguage()
Return default language.
setListPresentation(string $a_val)
ilTree $tree
static lookupHideTitle(int $a_id)
setTitle(string $title)
static modifyItemGroupRefIdsByMapping(ilPageObject $a_page, array $mappings)
static _lookupObjId(int $ref_id)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
setHideTitle(bool $a_val)
Container page object.
static _exists(string $a_parent_type, int $a_id, string $a_lang="", bool $a_no_cache=false)
Checks whether page exists.
ilLanguage $lng
ilObjectDefinition $obj_def
global $DIC
Definition: shib_login.php:26
cloneDependencies(int $a_target_id, int $a_copy_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilContainer.
static lookupBehaviour(int $a_id)
doCreate(bool $clone_mode=false)
static fixContainerItemGroupRefsAfterCloning(ilContainer $a_source_container, int $a_copy_id)
Class ilObjItemGroup.
__construct(int $a_id=0, bool $a_reference=true)
__construct(Container $dic, ilPlugin $plugin)
getLongDescription()
get object long description (stored in object_description)
doCloneObject(ilObject2 $new_obj, int $a_target_id, ?int $a_copy_id=null)
static _getInstance(int $a_copy_id)
ilItemGroupAR $item_data_ar
static lookup(int $a_id, string $a_key)
setDescription(string $description)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...