ILIAS  eassessment Revision 61809
 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 
38 {
39 
40  protected $id;
41  protected $title;
42  protected $content;
43  protected $context_obj_id;
44  protected $context_obj_type;
47  protected $content_type = "text";
48  protected $creation_date;
49  protected $update_date;
50  protected $user_id;
51  protected $visibility = "users";
52  protected $content_long;
53  protected $priority = 1;
54  protected $content_is_lang_var = 0;
55  protected $mob_id;
56  protected $playtime;
57 
63  public function __construct($a_id = 0)
64  {
65  if ($a_id > 0)
66  {
67  $this->setId($a_id);
68  $this->read();
69  }
70 
71  }
72 
78  public function setId($a_id)
79  {
80  $this->id = $a_id;
81  }
82 
88  public function getId()
89  {
90  return $this->id;
91  }
92 
98  public function setTitle($a_title)
99  {
100  $this->title = $a_title;
101  }
102 
108  public function getTitle()
109  {
110  return $this->title;
111  }
112 
118  public function setContent($a_content)
119  {
120  $this->content = $a_content;
121  }
122 
128  public function getContent()
129  {
130  return $this->content;
131  }
132 
138  public function setContextObjId($a_context_obj_id)
139  {
140  $this->context_obj_id = $a_context_obj_id;
141  }
142 
148  public function getContextObjId()
149  {
150  return $this->context_obj_id;
151  }
152 
158  public function setContextObjType($a_context_obj_type)
159  {
160  $this->context_obj_type = $a_context_obj_type;
161  }
162 
168  public function getContextObjType()
169  {
171  }
172 
178  public function setContextSubObjId($a_context_sub_obj_id)
179  {
180  $this->context_sub_obj_id = $a_context_sub_obj_id;
181  }
182 
188  public function getContextSubObjId()
189  {
191  }
192 
198  public function setContextSubObjType($a_context_sub_obj_type)
199  {
200  $this->context_sub_obj_type = $a_context_sub_obj_type;
201  }
202 
208  public function getContextSubObjType()
209  {
211  }
212 
218  public function setContentType($a_content_type = "text")
219  {
220  $this->content_type = $a_content_type;
221  }
222 
228  public function getContentType()
229  {
230  return $this->content_type;
231  }
232 
238  public function setCreationDate($a_creation_date)
239  {
240  $this->creation_date = $a_creation_date;
241  }
242 
248  public function getCreationDate()
249  {
250  return $this->creation_date;
251  }
252 
258  public function setUpdateDate($a_update_date)
259  {
260  $this->update_date = $a_update_date;
261  }
262 
268  public function getUpdateDate()
269  {
270  return $this->update_date;
271  }
272 
278  public function setUserId($a_user_id)
279  {
280  $this->user_id = $a_user_id;
281  }
282 
288  public function getUserId()
289  {
290  return $this->user_id;
291  }
292 
298  public function setVisibility($a_visibility = "users")
299  {
300  $this->visibility = $a_visibility;
301  }
302 
308  public function getVisibility()
309  {
310  return $this->visibility;
311  }
312 
318  public function setContentLong($a_content_long)
319  {
320  $this->content_long = $a_content_long;
321  }
322 
328  public function getContentLong()
329  {
330  return $this->content_long;
331  }
332 
338  public function setPriority($a_priority = 1)
339  {
340  $this->priority = $a_priority;
341  }
342 
348  public function getPriority()
349  {
350  return $this->priority;
351  }
352 
358  public function setContentIsLangVar($a_content_is_lang_var = 0)
359  {
360  $this->content_is_lang_var = $a_content_is_lang_var;
361  }
362 
368  public function getContentIsLangVar()
369  {
371  }
372 
378  public function setMobId($a_mob_id)
379  {
380  $this->mob_id = $a_mob_id;
381  }
382 
388  public function getMobId()
389  {
390  return $this->mob_id;
391  }
392 
398  public function setPlaytime($a_playtime)
399  {
400  $this->playtime = $a_playtime;
401  }
402 
408  public function getPlaytime()
409  {
410  return $this->playtime;
411  }
412 
417  public function create()
418  {
419  global $ilDB;
420 
421  $this->setId($ilDB->nextId("il_news_item"));
422  $ilDB->insert("il_news_item", array(
423  "id" => array("integer", $this->getId()),
424  "title" => array("text", $this->getTitle()),
425  "content" => array("clob", $this->getContent()),
426  "context_obj_id" => array("integer", (int) $this->getContextObjId()),
427  "context_obj_type" => array("text", $this->getContextObjType()),
428  "context_sub_obj_id" => array("integer", (int) $this->getContextSubObjId()),
429  "context_sub_obj_type" => array("text", $this->getContextSubObjType()),
430  "content_type" => array("text", $this->getContentType()),
431  "creation_date" => array("timestamp", ilUtil::now()),
432  "update_date" => array("timestamp", ilUtil::now()),
433  "user_id" => array("integer", $this->getUserId()),
434  "visibility" => array("text", $this->getVisibility()),
435  "content_long" => array("clob", $this->getContentLong()),
436  "priority" => array("integer", $this->getPriority()),
437  "content_is_lang_var" => array("integer", $this->getContentIsLangVar()),
438  "mob_id" => array("integer", $this->getMobId()),
439  "playtime" => array("text", $this->getPlaytime())
440  ));
441  }
442 
447  public function read()
448  {
449  global $ilDB;
450 
451  $query = "SELECT * FROM il_news_item WHERE id = ".
452  $ilDB->quote($this->getId(), "integer");
453  $set = $ilDB->query($query);
454  $rec = $ilDB->fetchAssoc($set);
455 
456  $this->setTitle($rec["title"]);
457  $this->setContent($rec["content"]);
458  $this->setContextObjId((int) $rec["context_obj_id"]);
459  $this->setContextObjType($rec["context_obj_type"]);
460  $this->setContextSubObjId((int) $rec["context_sub_obj_id"]);
461  $this->setContextSubObjType($rec["context_sub_obj_type"]);
462  $this->setContentType($rec["content_type"]);
463  $this->setCreationDate($rec["creation_date"]);
464  $this->setUpdateDate($rec["update_date"]);
465  $this->setUserId($rec["user_id"]);
466  $this->setVisibility($rec["visibility"]);
467  $this->setContentLong($rec["content_long"]);
468  $this->setPriority($rec["priority"]);
469  $this->setContentIsLangVar($rec["content_is_lang_var"]);
470  $this->setMobId($rec["mob_id"]);
471  $this->setPlaytime($rec["playtime"]);
472 
473  }
474 
479  public function update()
480  {
481  global $ilDB;
482 
483  $ilDB->update("il_news_item", array(
484  "title" => array("text", $this->getTitle()),
485  "content" => array("clob", $this->getContent()),
486  "context_obj_id" => array("integer", $this->getContextObjId()),
487  "context_obj_type" => array("text", $this->getContextObjType()),
488  "context_sub_obj_id" => array("integer", $this->getContextSubObjId()),
489  "context_sub_obj_type" => array("text", $this->getContextSubObjType()),
490  "content_type" => array("text", $this->getContentType()),
491  "update_date" => array("timestamp", ilUtil::now()),
492  "user_id" => array("integer", $this->getUserId()),
493  "visibility" => array("text", $this->getVisibility()),
494  "content_long" => array("clob", $this->getContentLong()),
495  "priority" => array("integer", $this->getPriority()),
496  "content_is_lang_var" => array("integer", $this->getContentIsLangVar()),
497  "mob_id" => array("integer", $this->getMobId()),
498  "playtime" => array("text", $this->getPlaytime())
499  ), array(
500  "id" => array("integer", $this->getId())
501  ));
502 
503  }
504 
509  public function delete()
510  {
511  global $ilDB;
512 
513  $query = "DELETE FROM il_news_item".
514  " WHERE id = ".$ilDB->quote($this->getId(), "integer");
515 
516  $ilDB->manipulate($query);
517 
518  }
519 
524  public function queryNewsForContext()
525  {
526  global $ilDB;
527 
528  $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 ".
529  "FROM il_news_item ".
530  "WHERE ".
531  "context_obj_id = ".$ilDB->quote($this->getContextObjId(), "integer").
532  " AND context_obj_type = ".$ilDB->quote($this->getContextObjType(), "text").
533  " AND context_sub_obj_id = ".$ilDB->quote($this->getContextSubObjId(), "integer").
534  " AND ".$ilDB->equals("context_sub_obj_type", $this->getContextSubObjType(), "text", true).
535  " ORDER BY creation_date DESC ".
536  "";
537  $set = $ilDB->query($query);
538  $result = array();
539  while($rec = $ilDB->fetchAssoc($set))
540  {
541  $result[] = $rec;
542  }
543 
544  return $result;
545 
546  }
547 
552  public function queryNewsForVisibility()
553  {
554  global $ilDB;
555 
556  $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 ".
557  "FROM il_news_item ".
558  "WHERE ".
559  "context_obj_id = ".$ilDB->quote($this->getContextObjId(), "integer").
560  " AND context_obj_type = ".$ilDB->quote($this->getContextObjType(), "text").
561  " AND context_sub_obj_id = ".$ilDB->quote($this->getContextSubObjId(), "integer").
562  " AND ".$ilDB->equals("context_sub_obj_type", $this->getContextSubObjType(), "text", true).
563  " AND visibility = ".$ilDB->quote($this->getVisibility(), "text").
564  " ORDER BY creation_date DESC ".
565  "";
566 
567  $set = $ilDB->query($query);
568  $result = array();
569  while($rec = $ilDB->fetchAssoc($set))
570  {
571  $result[] = $rec;
572  }
573 
574  return $result;
575 
576  }
577 
578 
579 }
580 ?>