ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilForumDraftsHistory.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2016 ILIAS open source, Extended GPL, see docs/LICENSE */
8{
9 const MEDIAOBJECT_TYPE = 'frm~h:html';
10
14 protected $history_id = 0;
18 protected $draft_id = 0;
22 protected $post_subject = '';
26 protected $post_message = '';
27
31 protected $draft_date = '0000-00-00 00:00:00';
32
36 public function getHistoryId()
37 {
38 return $this->history_id;
39 }
40
44 public function setHistoryId($history_id)
45 {
46 $this->history_id = $history_id;
47 }
48
52 public function getDraftId()
53 {
54 return $this->draft_id;
55 }
56
60 public function setDraftId($draft_id)
61 {
62 $this->draft_id = $draft_id;
63 }
64
68 public function getPostSubject()
69 {
71 }
72
77 {
78 $this->post_subject = $post_subject;
79 }
80
84 public function getPostMessage()
85 {
87 }
88
93 {
94 $this->post_message = $post_message;
95 }
96
100 public function getDraftDate()
101 {
102 return $this->draft_date;
103 }
104
108 public function setDraftDate($draft_date)
109 {
110 $this->draft_date = $draft_date;
111 }
112
117 public function __construct($history_id = 0)
118 {
119 if(isset($history_id) && $history_id > 0 )
120 {
122 }
123 }
124
129 private function readByHistoryId($history_id)
130 {
131 global $ilDB;
132
133 $res = $ilDB->queryF('SELECT * FROM frm_drafts_history WHERE history_id = %s',
134 array('integer'), array((int)$history_id));
135
136 while($row = $ilDB->fetchAssoc($res))
137 {
138 $this->setHistoryId($row['history_id']);
139 $this->setDraftId($row['draft_id']);
140 $this->setPostMessage($row['post_message']);
141 $this->setPostSubject($row['post_subject']);
142 $this->setDraftDate($row['draft_date']);
143 }
144 }
145
146 public static function getInstancesByDraftId($draft_id)
147 {
148 global $ilDB;
149
150 $res = $ilDB->queryF('SELECT * FROM frm_drafts_history WHERE draft_id = %s ORDER BY draft_date DESC',
151 array('integer'), array((int) $draft_id));
152 $instances = array();
153 while($row = $ilDB->fetchAssoc($res))
154 {
155 $tmp_obj = new self;
156 $tmp_obj = self::populateWithDatabaseRecord($tmp_obj, $row);
157
158 $instances[] = $tmp_obj;
159 }
160 unset($tmp_obj);
161 return $instances;
162 }
163
168 protected static function populateWithDatabaseRecord(ilForumDraftsHistory $history_draft, array $row)
169 {
170 $history_draft->setHistoryId($row['history_id']);
171 $history_draft->setDraftId($row['draft_id']);
172 $history_draft->setPostMessage($row['post_message']);
173 $history_draft->setPostSubject($row['post_subject']);
174 $history_draft->setDraftDate($row['draft_date']);
175
176 return $history_draft;
177 }
178
179 public function delete()
180 {
181 global $ilDB;
182
183 $ilDB->manipulatef('DELETE FROM frm_drafts_history WHERE history_id = %s',
184 array('integer'), array($this->getHistoryId()));
185 }
186
191 {
192 global $ilDB;
193
194 $res = $ilDB->queryF('SELECT * FROM frm_drafts_history WHERE draft_id = %s
195 ORDER BY history_id ASC',
196 array('integer'), array((int)$draft_id));
197
198 if($row = $ilDB->fetchAssoc($res))
199 {
200 $this->setHistoryId($row['history_id']);
201 $this->setDraftId($row['draft_id']);
202 $this->setPostSubject($row['post_subject']);
203 $this->setPostMessage($row['post_message']);
204 }
205 }
210 {
211 global $ilDB;
212
213 $res = $ilDB->queryF('SELECT * FROM frm_drafts_history WHERE draft_id = %s
214 ORDER BY history_id DESC',
215 array('integer'), array($draft_id));
216
217 while($row = $ilDB->fetchAssoc($res))
218 {
219 $this->setHistoryId($row['history_id']);
220 $this->setDraftId($row['draft_id']);
221 $this->setPostSubject($row['post_subject']);
222 $this->setPostMessage($row['post_message']);
223 }
224 }
225
226 public function addDraftToHistory()
227 {
228 global $ilDB;
229
230 $next_id = $ilDB->nextId('frm_drafts_history');
231 $ilDB->insert('frm_drafts_history',
232 array('history_id' => array('integer', $next_id),
233 'draft_id' => array('integer', $this->getDraftId()),
234 'post_subject' => array('text', $this->getPostSubject()),
235 'post_message' => array('text', $this->getPostMessage()),
236 'draft_date' => array('timestamp', date("Y-m-d H:i:s"))
237 ));
238 $this->setHistoryId($next_id);
239 }
240
241 public function addMobsToDraftsHistory($message)
242 {
243 // copy temporary media objects (frm~)
244 include_once 'Services/MediaObjects/classes/class.ilObjMediaObject.php';
245 $mediaObjects = ilRTE::_getMediaObjects($this->getPostMessage(), 0);
246
247 $myMediaObjects = ilObjMediaObject::_getMobsOfObject('frm~h:html', $this->getHistoryId());
248 foreach($mediaObjects as $mob)
249 {
250 foreach($myMediaObjects as $myMob)
251 {
252 if($mob == $myMob)
253 {
254 // change usage
255 ilObjMediaObject::_removeUsage($mob, 'frm~h:html', $this->getHistoryId());
256 break;
257 }
258 }
259 ilObjMediaObject::_saveUsage($mob, 'frm~h:html', $this->getHistoryId());
260 }
261 }
262
263 public function deleteMobs()
264 {
265 require_once 'Services/MediaObjects/classes/class.ilObjMediaObject.php';
266 // delete mobs of draft history
267 $oldMediaObjects = ilObjMediaObject::_getMobsOfObject('frm~h:html', $this->getHistoryId());
268 foreach($oldMediaObjects as $oldMob)
269 {
270 if(ilObjMediaObject::_exists($oldMob))
271 {
272 ilObjMediaObject::_removeUsage($oldMob, 'frm~h:html', $this->getHistoryId());
273 $mob_obj = new ilObjMediaObject($oldMob);
274 $mob_obj->delete();
275 }
276 }
277 }
278
279 public function rollbackAutosave()
280 {
281 $draft = ilForumPostDraft::newInstanceByDraftId($this->getDraftId());
282 $draft->setPostSubject($this->getPostSubject());
283 $draft->setPostMessage($this->getPostMessage());
284
286 self::MEDIAOBJECT_TYPE, $this->getHistoryId(),
287 ilForumPostDraft::MEDIAOBJECT_TYPE, $draft->getDraftId());
288
289 $draft->updateDraft();
290 $this->deleteHistoryByDraftIds(array($draft->getDraftId()));
291
292 return $draft;
293 }
294
298 public function deleteHistoryByPostIds($post_ids = array())
299 {
300 $draft_ids = array();
301 if(count($post_ids) > 0)
302 {
303 global $ilDB;
304
305 $res = $ilDB->query('
306 SELECT frm_drafts_history.history_id, frm_drafts_history.draft_id
307 FROM frm_posts_drafts
308 INNER JOIN frm_drafts_history ON frm_posts_drafts.draft_id
309 WHERE ' . $ilDB->in('post_id', $post_ids, false, 'integer'));
310
311 while($row = $ilDB->fetchAssoc($res))
312 {
313 $draft_ids[] = $row['draft_id'];
314 }
315
316 $this->deleteHistoryByDraftIds($draft_ids);
317 }
318 return $draft_ids;
319 }
320
321 public function deleteHistoryByDraftIds($draft_ids = array())
322 {
323 global $ilDB;
324
325 if(count($draft_ids) > 0)
326 {
327 $res = $ilDB->query('SELECT history_id FROM frm_drafts_history
328 WHERE ' . $ilDB->in('draft_id', $draft_ids, false, 'integer'));
329
330 while($row = $ilDB->fetchAssoc($res))
331 {
332 $this->setHistoryId($row['history_id']);
333 $this->deleteMobs();
334 }
335
336 $ilDB->manipulate('DELETE FROM frm_drafts_history WHERE '
337 . $ilDB->in('draft_id', $draft_ids, false, 'integer'));
338 }
339 }
340}
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
An exception for terminatinating execution or to throw for unit testing.
Class ilForumDraftHistory.
deleteHistoryByDraftIds($draft_ids=array())
static populateWithDatabaseRecord(ilForumDraftsHistory $history_draft, array $row)
deleteHistoryByPostIds($post_ids=array())
__construct($history_id=0)
ilForumDraftsHistory constructor.
static getInstancesByDraftId($draft_id)
static moveMediaObjects($post_message, $source_type, $source_id, $target_type, $target_id, $direction=0)
Class ilObjMediaObject.
static _saveUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
Save usage of mob within another container (e.g.
static _getMobsOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
get mobs of object
static _removeUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
Remove usage of mob in another container.
static _exists($a_id, $a_reference=false, $a_type=NULL)
checks wether a lm content object with specified id exists or not
static _getMediaObjects($a_text, $a_direction=0)
Returns all media objects found in the passed string.
global $ilDB