ILIAS  Release_4_0_x_branch Revision 61816
 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  $this->setId($ilDB->nextId("il_news_item"));
423  $ilDB->insert("il_news_item", array(
424  "id" => array("integer", $this->getId()),
425  "title" => array("text", $this->getTitle()),
426  "content" => array("clob", $this->getContent()),
427  "context_obj_id" => array("integer", (int) $this->getContextObjId()),
428  "context_obj_type" => array("text", $this->getContextObjType()),
429  "context_sub_obj_id" => array("integer", (int) $this->getContextSubObjId()),
430  "context_sub_obj_type" => array("text", $this->getContextSubObjType()),
431  "content_type" => array("text", $this->getContentType()),
432  "creation_date" => array("timestamp", ilUtil::now()),
433  "update_date" => array("timestamp", ilUtil::now()),
434  "user_id" => array("integer", $this->getUserId()),
435  "visibility" => array("text", $this->getVisibility()),
436  "content_long" => array("clob", $this->getContentLong()),
437  "priority" => array("integer", $this->getPriority()),
438  "content_is_lang_var" => array("integer", $this->getContentIsLangVar()),
439  "mob_id" => array("integer", $this->getMobId()),
440  "playtime" => array("text", $this->getPlaytime())
441  ));
442  }
443 
448  public function read()
449  {
450  global $ilDB;
451 
452  $query = "SELECT * FROM il_news_item WHERE id = ".
453  $ilDB->quote($this->getId(), "integer");
454  $set = $ilDB->query($query);
455  $rec = $ilDB->fetchAssoc($set);
456 
457  $this->setTitle($rec["title"]);
458  $this->setContent($rec["content"]);
459  $this->setContextObjId((int) $rec["context_obj_id"]);
460  $this->setContextObjType($rec["context_obj_type"]);
461  $this->setContextSubObjId((int) $rec["context_sub_obj_id"]);
462  $this->setContextSubObjType($rec["context_sub_obj_type"]);
463  $this->setContentType($rec["content_type"]);
464  $this->setCreationDate($rec["creation_date"]);
465  $this->setUpdateDate($rec["update_date"]);
466  $this->setUserId($rec["user_id"]);
467  $this->setVisibility($rec["visibility"]);
468  $this->setContentLong($rec["content_long"]);
469  $this->setPriority($rec["priority"]);
470  $this->setContentIsLangVar($rec["content_is_lang_var"]);
471  $this->setMobId($rec["mob_id"]);
472  $this->setPlaytime($rec["playtime"]);
473 
474  }
475 
480  public function update()
481  {
482  global $ilDB;
483 
484  $ilDB->update("il_news_item", array(
485  "title" => array("text", $this->getTitle()),
486  "content" => array("clob", $this->getContent()),
487  "context_obj_id" => array("integer", $this->getContextObjId()),
488  "context_obj_type" => array("text", $this->getContextObjType()),
489  "context_sub_obj_id" => array("integer", $this->getContextSubObjId()),
490  "context_sub_obj_type" => array("text", $this->getContextSubObjType()),
491  "content_type" => array("text", $this->getContentType()),
492  "update_date" => array("timestamp", ilUtil::now()),
493  "user_id" => array("integer", $this->getUserId()),
494  "visibility" => array("text", $this->getVisibility()),
495  "content_long" => array("clob", $this->getContentLong()),
496  "priority" => array("integer", $this->getPriority()),
497  "content_is_lang_var" => array("integer", $this->getContentIsLangVar()),
498  "mob_id" => array("integer", $this->getMobId()),
499  "playtime" => array("text", $this->getPlaytime())
500  ), array(
501  "id" => array("integer", $this->getId())
502  ));
503 
504  }
505 
510  public function delete()
511  {
512  global $ilDB;
513 
514  $query = "DELETE FROM il_news_item".
515  " WHERE id = ".$ilDB->quote($this->getId(), "integer");
516 
517  $ilDB->manipulate($query);
518 
519  }
520 
525  public function queryNewsForContext()
526  {
527  global $ilDB;
528 
529  $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 ".
530  "FROM il_news_item ".
531  "WHERE ".
532  "context_obj_id = ".$ilDB->quote($this->getContextObjId(), "integer").
533  " AND context_obj_type = ".$ilDB->quote($this->getContextObjType(), "text").
534  " AND context_sub_obj_id = ".$ilDB->quote($this->getContextSubObjId(), "integer").
535  " AND ".$ilDB->equals("context_sub_obj_type", $this->getContextSubObjType(), "text", true).
536  " ORDER BY creation_date DESC ".
537  "";
538  $set = $ilDB->query($query);
539  $result = array();
540  while($rec = $ilDB->fetchAssoc($set))
541  {
542  $result[] = $rec;
543  }
544 
545  return $result;
546 
547  }
548 
553  public function queryNewsForVisibility()
554  {
555  global $ilDB;
556 
557  $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 ".
558  "FROM il_news_item ".
559  "WHERE ".
560  "context_obj_id = ".$ilDB->quote($this->getContextObjId(), "integer").
561  " AND context_obj_type = ".$ilDB->quote($this->getContextObjType(), "text").
562  " AND context_sub_obj_id = ".$ilDB->quote($this->getContextSubObjId(), "integer").
563  " AND ".$ilDB->equals("context_sub_obj_type", $this->getContextSubObjType(), "text", true).
564  " AND visibility = ".$ilDB->quote($this->getVisibility(), "text").
565  " ORDER BY creation_date DESC ".
566  "";
567 
568  $set = $ilDB->query($query);
569  $result = array();
570  while($rec = $ilDB->fetchAssoc($set))
571  {
572  $result[] = $rec;
573  }
574 
575  return $result;
576 
577  }
578 
579 
580 }
581 ?>