ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilNewsItemGen.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 define("NEWS_TEXT", "text");
25 define("NEWS_HTML", "html");
26 define("NEWS_AUDIO", "audio");
27 define("NEWS_USERS", "users");
28 define("NEWS_PUBLIC", "public");
29 
39 {
40 
41  protected $id;
42  protected $title;
43  protected $content;
44  protected $context_obj_id;
45  protected $context_obj_type;
48  protected $content_type = "text";
49  protected $creation_date;
50  protected $update_date;
51  protected $user_id;
52  protected $visibility = "users";
53  protected $content_long;
54  protected $priority = 1;
55  protected $content_is_lang_var = 0;
56  protected $mob_id;
57  protected $playtime;
58 
64  public function __construct($a_id = 0)
65  {
66  if ($a_id > 0)
67  {
68  $this->setId($a_id);
69  $this->read();
70  }
71 
72  }
73 
79  public function setId($a_id)
80  {
81  $this->id = $a_id;
82  }
83 
89  public function getId()
90  {
91  return $this->id;
92  }
93 
99  public function setTitle($a_title)
100  {
101  $this->title = $a_title;
102  }
103 
109  public function getTitle()
110  {
111  return $this->title;
112  }
113 
119  public function setContent($a_content)
120  {
121  $this->content = $a_content;
122  }
123 
129  public function getContent()
130  {
131  return $this->content;
132  }
133 
139  public function setContextObjId($a_context_obj_id)
140  {
141  $this->context_obj_id = $a_context_obj_id;
142  }
143 
149  public function getContextObjId()
150  {
151  return $this->context_obj_id;
152  }
153 
159  public function setContextObjType($a_context_obj_type)
160  {
161  $this->context_obj_type = $a_context_obj_type;
162  }
163 
169  public function getContextObjType()
170  {
172  }
173 
179  public function setContextSubObjId($a_context_sub_obj_id)
180  {
181  $this->context_sub_obj_id = $a_context_sub_obj_id;
182  }
183 
189  public function getContextSubObjId()
190  {
192  }
193 
199  public function setContextSubObjType($a_context_sub_obj_type)
200  {
201  $this->context_sub_obj_type = $a_context_sub_obj_type;
202  }
203 
209  public function getContextSubObjType()
210  {
212  }
213 
219  public function setContentType($a_content_type = "text")
220  {
221  $this->content_type = $a_content_type;
222  }
223 
229  public function getContentType()
230  {
231  return $this->content_type;
232  }
233 
239  public function setCreationDate($a_creation_date)
240  {
241  $this->creation_date = $a_creation_date;
242  }
243 
249  public function getCreationDate()
250  {
251  return $this->creation_date;
252  }
253 
259  public function setUpdateDate($a_update_date)
260  {
261  $this->update_date = $a_update_date;
262  }
263 
269  public function getUpdateDate()
270  {
271  return $this->update_date;
272  }
273 
279  public function setUserId($a_user_id)
280  {
281  $this->user_id = $a_user_id;
282  }
283 
289  public function getUserId()
290  {
291  return $this->user_id;
292  }
293 
299  public function setVisibility($a_visibility = "users")
300  {
301  $this->visibility = $a_visibility;
302  }
303 
309  public function getVisibility()
310  {
311  return $this->visibility;
312  }
313 
319  public function setContentLong($a_content_long)
320  {
321  $this->content_long = $a_content_long;
322  }
323 
329  public function getContentLong()
330  {
331  return $this->content_long;
332  }
333 
339  public function setPriority($a_priority = 1)
340  {
341  $this->priority = $a_priority;
342  }
343 
349  public function getPriority()
350  {
351  return $this->priority;
352  }
353 
359  public function setContentIsLangVar($a_content_is_lang_var = 0)
360  {
361  $this->content_is_lang_var = $a_content_is_lang_var;
362  }
363 
369  public function getContentIsLangVar()
370  {
372  }
373 
379  public function setMobId($a_mob_id)
380  {
381  $this->mob_id = $a_mob_id;
382  }
383 
389  public function getMobId()
390  {
391  return $this->mob_id;
392  }
393 
399  public function setPlaytime($a_playtime)
400  {
401  $this->playtime = $a_playtime;
402  }
403 
409  public function getPlaytime()
410  {
411  return $this->playtime;
412  }
413 
418  public function create()
419  {
420  global $ilDB;
421 
422  $query = "INSERT INTO il_news_item (".
423  " title".
424  ", content".
425  ", context_obj_id".
426  ", context_obj_type".
427  ", context_sub_obj_id".
428  ", context_sub_obj_type".
429  ", content_type".
430  ", creation_date".
431  ", update_date".
432  ", user_id".
433  ", visibility".
434  ", content_long".
435  ", priority".
436  ", content_is_lang_var".
437  ", mob_id".
438  ", playtime".
439  " ) VALUES (".
440  $ilDB->quote($this->getTitle())
441  .",".$ilDB->quote($this->getContent())
442  .",".$ilDB->quote($this->getContextObjId())
443  .",".$ilDB->quote($this->getContextObjType())
444  .",".$ilDB->quote($this->getContextSubObjId())
445  .",".$ilDB->quote($this->getContextSubObjType())
446  .",".$ilDB->quote($this->getContentType())
447  .","."now()"
448  .","."now()"
449  .",".$ilDB->quote($this->getUserId())
450  .",".$ilDB->quote($this->getVisibility())
451  .",".$ilDB->quote($this->getContentLong())
452  .",".$ilDB->quote($this->getPriority())
453  .",".$ilDB->quote($this->getContentIsLangVar())
454  .",".$ilDB->quote($this->getMobId())
455  .",".$ilDB->quote($this->getPlaytime()).")";
456  $ilDB->query($query);
457  $this->setId($ilDB->getLastInsertId());
458 
459 
460  }
461 
466  public function read()
467  {
468  global $ilDB;
469 
470  $query = "SELECT * FROM il_news_item WHERE id = ".
471  $ilDB->quote($this->getId());
472  $set = $ilDB->query($query);
473  $rec = $set->fetchRow(DB_FETCHMODE_ASSOC);
474 
475  $this->setTitle($rec["title"]);
476  $this->setContent($rec["content"]);
477  $this->setContextObjId($rec["context_obj_id"]);
478  $this->setContextObjType($rec["context_obj_type"]);
479  $this->setContextSubObjId($rec["context_sub_obj_id"]);
480  $this->setContextSubObjType($rec["context_sub_obj_type"]);
481  $this->setContentType($rec["content_type"]);
482  $this->setCreationDate($rec["creation_date"]);
483  $this->setUpdateDate($rec["update_date"]);
484  $this->setUserId($rec["user_id"]);
485  $this->setVisibility($rec["visibility"]);
486  $this->setContentLong($rec["content_long"]);
487  $this->setPriority($rec["priority"]);
488  $this->setContentIsLangVar($rec["content_is_lang_var"]);
489  $this->setMobId($rec["mob_id"]);
490  $this->setPlaytime($rec["playtime"]);
491 
492  }
493 
498  public function update()
499  {
500  global $ilDB;
501 
502  $query = "UPDATE il_news_item SET ".
503  " title = ".$ilDB->quote($this->getTitle()).
504  ", content = ".$ilDB->quote($this->getContent()).
505  ", context_obj_id = ".$ilDB->quote($this->getContextObjId()).
506  ", context_obj_type = ".$ilDB->quote($this->getContextObjType()).
507  ", context_sub_obj_id = ".$ilDB->quote($this->getContextSubObjId()).
508  ", context_sub_obj_type = ".$ilDB->quote($this->getContextSubObjType()).
509  ", content_type = ".$ilDB->quote($this->getContentType()).
510  ", creation_date = ".$ilDB->quote($this->getCreationDate()).
511  ", update_date = now()".
512  ", user_id = ".$ilDB->quote($this->getUserId()).
513  ", visibility = ".$ilDB->quote($this->getVisibility()).
514  ", content_long = ".$ilDB->quote($this->getContentLong()).
515  ", priority = ".$ilDB->quote($this->getPriority()).
516  ", content_is_lang_var = ".$ilDB->quote($this->getContentIsLangVar()).
517  ", mob_id = ".$ilDB->quote($this->getMobId()).
518  ", playtime = ".$ilDB->quote($this->getPlaytime()).
519  " WHERE id = ".$ilDB->quote($this->getId());
520 
521  $ilDB->query($query);
522 
523  }
524 
529  public function delete()
530  {
531  global $ilDB;
532 
533  $query = "DELETE FROM il_news_item".
534  " WHERE id = ".$ilDB->quote($this->getId());
535 
536  $ilDB->query($query);
537 
538  }
539 
544  public function queryNewsForContext()
545  {
546  global $ilDB;
547 
548  $query = "SELECT id, title, content, context_obj_id, context_obj_type, context_sub_obj_id, context_sub_obj_type, content_type, creation_date, update_date, user_id, visibility, content_long, priority, content_is_lang_var, mob_id, playtime ".
549  "FROM il_news_item ".
550  "WHERE ".
551  "context_obj_id = ".$ilDB->quote($this->getContextObjId()).
552  " AND context_obj_type = ".$ilDB->quote($this->getContextObjType()).
553  " AND context_sub_obj_id = ".$ilDB->quote($this->getContextSubObjId()).
554  " AND context_sub_obj_type = ".$ilDB->quote($this->getContextSubObjType()).
555  " ORDER BY creation_date DESC ".
556  "";
557 
558  $set = $ilDB->query($query);
559  $result = array();
560  while($rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
561  {
562  $result[] = $rec;
563  }
564 
565  return $result;
566 
567  }
568 
573  public function queryNewsForVisibility()
574  {
575  global $ilDB;
576 
577  $query = "SELECT id, title, content, context_obj_id, context_obj_type, context_sub_obj_id, context_sub_obj_type, content_type, creation_date, update_date, user_id, visibility, content_long, priority, content_is_lang_var, mob_id, playtime ".
578  "FROM il_news_item ".
579  "WHERE ".
580  "context_obj_id = ".$ilDB->quote($this->getContextObjId()).
581  " AND context_obj_type = ".$ilDB->quote($this->getContextObjType()).
582  " AND context_sub_obj_id = ".$ilDB->quote($this->getContextSubObjId()).
583  " AND context_sub_obj_type = ".$ilDB->quote($this->getContextSubObjType()).
584  " AND visibility = ".$ilDB->quote($this->getVisibility()).
585  " ORDER BY creation_date DESC ".
586  "";
587 
588  $set = $ilDB->query($query);
589  $result = array();
590  while($rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
591  {
592  $result[] = $rec;
593  }
594 
595  return $result;
596 
597  }
598 
599 
600 }
601 ?>