ILIAS  release_7 Revision v7.30-3-g800a261c036
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
33 public $db;
34
38 public function getHistoryId()
39 {
40 return $this->history_id;
41 }
42
46 public function setHistoryId($history_id)
47 {
48 $this->history_id = $history_id;
49 }
50
54 public function getDraftId()
55 {
56 return $this->draft_id;
57 }
58
62 public function setDraftId($draft_id)
63 {
64 $this->draft_id = $draft_id;
65 }
66
70 public function getPostSubject()
71 {
73 }
74
79 {
80 $this->post_subject = $post_subject;
81 }
82
86 public function getPostMessage()
87 {
89 }
90
95 {
96 $this->post_message = $post_message;
97 }
98
102 public function getDraftDate()
103 {
104 return $this->draft_date;
105 }
106
110 public function setDraftDate($draft_date)
111 {
112 $this->draft_date = $draft_date;
113 }
114
119 public function __construct($history_id = 0)
120 {
121 global $DIC;
122 $this->db = $DIC->database();
123
124 if (isset($history_id) && $history_id > 0) {
126 }
127 }
128
133 private function readByHistoryId($history_id)
134 {
135 $res = $this->db->queryF(
136 'SELECT * FROM frm_drafts_history WHERE history_id = %s',
137 array('integer'),
138 array((int) $history_id)
139 );
140
141 while ($row = $this->db->fetchAssoc($res)) {
142 $this->setHistoryId($row['history_id']);
143 $this->setDraftId($row['draft_id']);
144 $this->setPostMessage($row['post_message']);
145 $this->setPostSubject($row['post_subject']);
146 $this->setDraftDate($row['draft_date']);
147 }
148 }
149
150 public static function getInstancesByDraftId($draft_id)
151 {
152 global $DIC;
153 $ilDB = $DIC->database();
154
155 $res = $ilDB->queryF(
156 'SELECT * FROM frm_drafts_history WHERE draft_id = %s ORDER BY draft_date DESC',
157 array('integer'),
158 array((int) $draft_id)
159 );
160 $instances = array();
161 while ($row = $ilDB->fetchAssoc($res)) {
162 $tmp_obj = new self;
163 $tmp_obj = self::populateWithDatabaseRecord($tmp_obj, $row);
164
165 $instances[] = $tmp_obj;
166 }
167 unset($tmp_obj);
168 return $instances;
169 }
170
176 protected static function populateWithDatabaseRecord(ilForumDraftsHistory $history_draft, array $row)
177 {
178 $history_draft->setHistoryId($row['history_id']);
179 $history_draft->setDraftId($row['draft_id']);
180 $history_draft->setPostMessage($row['post_message']);
181 $history_draft->setPostSubject($row['post_subject']);
182 $history_draft->setDraftDate($row['draft_date']);
183
184 return $history_draft;
185 }
186
187 public function delete()
188 {
189 $this->db->manipulatef(
190 'DELETE FROM frm_drafts_history WHERE history_id = %s',
191 array('integer'),
192 array($this->getHistoryId())
193 );
194 }
195
200 {
201 $res = $this->db->queryF(
202 'SELECT * FROM frm_drafts_history WHERE draft_id = %s
203 ORDER BY history_id ASC',
204 array('integer'),
205 array((int) $draft_id)
206 );
207
208 if ($row = $this->db->fetchAssoc($res)) {
209 $this->setHistoryId($row['history_id']);
210 $this->setDraftId($row['draft_id']);
211 $this->setPostSubject($row['post_subject']);
212 $this->setPostMessage($row['post_message']);
213 }
214 }
219 {
220 $res = $this->db->queryF(
221 'SELECT * FROM frm_drafts_history WHERE draft_id = %s
222 ORDER BY history_id DESC',
223 array('integer'),
224 array($draft_id)
225 );
226
227 while ($row = $this->db->fetchAssoc($res)) {
228 $this->setHistoryId($row['history_id']);
229 $this->setDraftId($row['draft_id']);
230 $this->setPostSubject($row['post_subject']);
231 $this->setPostMessage($row['post_message']);
232 }
233 }
234
235 public function addDraftToHistory()
236 {
237 $next_id = $this->db->nextId('frm_drafts_history');
238 $this->db->insert(
239 'frm_drafts_history',
240 array('history_id' => array('integer', $next_id),
241 'draft_id' => array('integer', $this->getDraftId()),
242 'post_subject' => array('text', $this->getPostSubject()),
243 'post_message' => array('text', $this->getPostMessage()),
244 'draft_date' => array('timestamp', date("Y-m-d H:i:s"))
245 )
246 );
247 $this->setHistoryId($next_id);
248 }
249
251 {
252 // copy temporary media objects (frm~)
253 $mediaObjects = ilRTE::_getMediaObjects($this->getPostMessage(), 0);
254
255 $myMediaObjects = ilObjMediaObject::_getMobsOfObject('frm~h:html', $this->getHistoryId());
256 foreach ($mediaObjects as $mob) {
257 foreach ($myMediaObjects as $myMob) {
258 if ($mob == $myMob) {
259 // change usage
260 ilObjMediaObject::_removeUsage($mob, 'frm~h:html', $this->getHistoryId());
261 break;
262 }
263 }
264 ilObjMediaObject::_saveUsage($mob, 'frm~h:html', $this->getHistoryId());
265 }
266 }
267
268 public function deleteMobs()
269 {
270 // delete mobs of draft history
271 $oldMediaObjects = ilObjMediaObject::_getMobsOfObject('frm~h:html', $this->getHistoryId());
272 foreach ($oldMediaObjects as $oldMob) {
273 if (ilObjMediaObject::_exists($oldMob)) {
274 ilObjMediaObject::_removeUsage($oldMob, 'frm~h:html', $this->getHistoryId());
275 $mob_obj = new ilObjMediaObject($oldMob);
276 $mob_obj->delete();
277 }
278 }
279 }
280
281 public function rollbackAutosave()
282 {
284 $draft->setPostSubject($this->getPostSubject());
285 $draft->setPostMessage($this->getPostMessage());
286
288 $this->getPostMessage(),
289 self::MEDIAOBJECT_TYPE,
290 $this->getHistoryId(),
292 $draft->getDraftId()
293 );
294
295 $draft->updateDraft();
296 $this->deleteHistoryByDraftIds(array($draft->getDraftId()));
297
298 return $draft;
299 }
300
304 public function deleteHistoryByPostIds($post_ids = array())
305 {
306 $draft_ids = array();
307 if (count($post_ids) > 0) {
308 $res = $this->db->query('
309 SELECT frm_drafts_history.history_id, frm_drafts_history.draft_id
310 FROM frm_posts_drafts
311 INNER JOIN frm_drafts_history ON frm_posts_drafts.draft_id
312 WHERE ' . $this->db->in('post_id', $post_ids, false, 'integer'));
313
314 while ($row = $this->db->fetchAssoc($res)) {
315 $draft_ids[] = $row['draft_id'];
316 }
317
318 $this->deleteHistoryByDraftIds($draft_ids);
319 }
320 return $draft_ids;
321 }
322
323 public function deleteHistoryByDraftIds($draft_ids = array())
324 {
325 if (count($draft_ids) > 0) {
326 $res = $this->db->query('SELECT history_id FROM frm_drafts_history
327 WHERE ' . $this->db->in('draft_id', $draft_ids, false, 'integer'));
328
329 while ($row = $this->db->fetchAssoc($res)) {
330 $this->setHistoryId($row['history_id']);
331 $this->deleteMobs();
332 }
333
334 $this->db->manipulate('DELETE FROM frm_drafts_history WHERE '
335 . $this->db->in('draft_id', $draft_ids, false, 'integer'));
336 }
337 }
338}
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 newInstanceByDraftId($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 $DIC
Definition: goto.php:24
foreach($_POST as $key=> $value) $res
global $ilDB
$message
Definition: xapiexit.php:14