ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
class.ilObjEmployeeTalk.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
24
25final class ilObjEmployeeTalk extends ilObject
26{
27 public const string TYPE = 'etal';
28
29 private static int $root_ref_id = -1;
30 private static int $root_id = -1;
31
34
39 public function __construct(int $a_id = 0, bool $a_call_by_reference = true)
40 {
41 $this->setType(self::TYPE);
42
45 $this->data = new EmployeeTalk(
46 -1,
49 false,
50 '',
51 '',
52 -1,
53 false,
54 false,
55 0
56 );
57
58 parent::__construct($a_id, $a_call_by_reference);
59 }
60
61 public function read(): void
62 {
63 parent::read();
64 $this->data = $this->repository->findByObjectId($this->getId());
65 }
66
67 public function create(): int
68 {
69 parent::create();
70
71 $this->data->setObjectId($this->getId());
72 $this->repository->create($this->data);
73
74 $app = new ilCalendarAppointmentTemplate($this->getId());
75 $app->setTitle($this->getTitle());
76 $app->setSubtitle('');
77 $app->setFullday($this->data->isAllDay());
78 $app->setTranslationType(ilCalendarEntry::TRANSLATION_NONE);
79 $app->setDescription($this->getLongDescription());
80 $app->setStart($this->data->getStartDate());
81 $app->setEnd($this->data->getEndDate());
82 $app->setLocation($this->data->getLocation());
83 $apps[] = $app;
84
88 $container = $GLOBALS['DIC'];
89
90 $container->event()->raise(
91 'components/ILIAS/EmployeeTalk',
92 'create',
93 ['object' => $this,
94 'obj_id' => $this->getId(),
95 'appointments' => $apps
96 ]
97 );
98
99 return $this->getId();
100 }
101
102
103
104 public function update(): bool
105 {
106 parent::update();
107 $this->repository->update($this->data);
108
109 if (!$this->getRefId()) {
110 /*
111 * During cloning, update is sometimes called before
112 * the newly created object has any references. In these
113 * cases we skip the updating the calendar.
114 */
115 return true;
116 }
117
118 $app = new ilCalendarAppointmentTemplate($this->getParent()->getId());
119 $app->setTitle($this->getTitle());
120 $app->setSubtitle($this->getParent()->getTitle());
121 $app->setFullday($this->data->isAllDay());
122 $app->setTranslationType(ilCalendarEntry::TRANSLATION_NONE);
123 $app->setDescription($this->getLongDescription());
124 $app->setStart($this->data->getStartDate());
125 $app->setEnd($this->data->getEndDate());
126 $app->setLocation($this->data->getLocation());
127 $apps[] = $app;
128
132 $container = $GLOBALS['DIC'];
133
134 $container->event()->raise(
135 'components/ILIAS/EmployeeTalk',
136 'update',
137 ['object' => $this,
138 'obj_id' => $this->getId(),
139 'appointments' => $apps
140 ]
141 );
142
143 return true;
144 }
145
149 public static function getRootOrgRefId(): int
150 {
152
153 return self::$root_ref_id;
154 }
155
159 public static function getRootOrgId(): int
160 {
162
163 return self::$root_id;
164 }
165
166 private static function loadRootOrgRefIdAndId(): void
167 {
168 if (self::$root_ref_id === -1 || self::$root_id === -1) {
169 global $DIC;
170 $ilDB = $DIC['ilDB'];
171 $q = "SELECT o.obj_id, r.ref_id FROM object_data o
172 INNER JOIN object_reference r ON r.obj_id = o.obj_id
173 WHERE title = " . $ilDB->quote('__TalkTemplateAdministration', 'text');
174 $set = $ilDB->query($q);
175 $res = $ilDB->fetchAssoc($set);
176 self::$root_id = (int) $res["obj_id"];
177 self::$root_ref_id = (int) $res["ref_id"];
178 }
179 }
180
182 {
183 return new ilObjEmployeeTalkSeries($this->tree->getParentId($this->getRefId()), true);
184 }
185
186 public static function _exists(int $id, bool $reference = false, ?string $type = null): bool
187 {
188 return parent::_exists($id, $reference, "etal");
189 }
190
196 public function delete(): bool
197 {
201 $container = $GLOBALS['DIC'];
202
203 $container->event()->raise(
204 'components/ILIAS/EmployeeTalk',
205 'delete',
206 [
207 'object' => $this,
208 'obj_id' => $this->getId(),
209 'appointments' => []
210 ]
211 );
212
213 $parent_series = $this->getParent();
214
215 $this->repository->delete($this->getData());
216
217 $result = parent::delete();
218
219 if (!$parent_series->hasChildren()) {
220 $parent_series->delete();
221 }
222
223 return $result;
224 }
225
229 public function getData(): EmployeeTalk
230 {
231 return clone $this->data;
232 }
233
239 {
240 $this->data = clone $data;
241 return $this;
242 }
243
244 public function cloneObject(int $target_id, int $copy_id = 0, bool $omit_tree = false): ilObjEmployeeTalk
245 {
249 $talkClone = parent::cloneObject($target_id, $copy_id, $omit_tree);
250 $data = $this->getData()->setObjectId($talkClone->getId());
251 $this->repository->update($data);
252 $talkClone->setData($data);
253
254 return $talkClone;
255 }
256}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$datetime
const IL_CAL_UNIX
Apointment templates are used for automatic generated apointments.
@classDescription Date and time handling
EmployeeTalkRepository $repository
__construct(int $a_id=0, bool $a_call_by_reference=true)
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
setData(EmployeeTalk $data)
Class ilObject Basic functions for all objects.
setType(string $type)
getLongDescription()
get object long description (stored in object_description)
create()
note: title, description and type should be set when this function is called
string $type
$res
Definition: ltiservices.php:69
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26
$q
Definition: shib_logout.php:23
$container
@noRector
Definition: wac.php:37
$GLOBALS["DIC"]
Definition: wac.php:54