00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 define("NEWS_TEXT", "text");
00025 define("NEWS_HTML", "html");
00026 define("NEWS_AUDIO", "audio");
00027 define("NEWS_USERS", "users");
00028 define("NEWS_PUBLIC", "public");
00029
00038 class ilNewsItemGen
00039 {
00040
00041 protected $id;
00042 protected $title;
00043 protected $content;
00044 protected $context_obj_id;
00045 protected $context_obj_type;
00046 protected $context_sub_obj_id;
00047 protected $context_sub_obj_type;
00048 protected $content_type = "text";
00049 protected $creation_date;
00050 protected $update_date;
00051 protected $user_id;
00052 protected $visibility = "users";
00053 protected $content_long;
00054 protected $priority = 1;
00055 protected $content_is_lang_var = 0;
00056 protected $mob_id;
00057 protected $playtime;
00058
00064 public function __construct($a_id = 0)
00065 {
00066 if ($a_id > 0)
00067 {
00068 $this->setId($a_id);
00069 $this->read();
00070 }
00071
00072 }
00073
00079 public function setId($a_id)
00080 {
00081 $this->id = $a_id;
00082 }
00083
00089 public function getId()
00090 {
00091 return $this->id;
00092 }
00093
00099 public function setTitle($a_title)
00100 {
00101 $this->title = $a_title;
00102 }
00103
00109 public function getTitle()
00110 {
00111 return $this->title;
00112 }
00113
00119 public function setContent($a_content)
00120 {
00121 $this->content = $a_content;
00122 }
00123
00129 public function getContent()
00130 {
00131 return $this->content;
00132 }
00133
00139 public function setContextObjId($a_context_obj_id)
00140 {
00141 $this->context_obj_id = $a_context_obj_id;
00142 }
00143
00149 public function getContextObjId()
00150 {
00151 return $this->context_obj_id;
00152 }
00153
00159 public function setContextObjType($a_context_obj_type)
00160 {
00161 $this->context_obj_type = $a_context_obj_type;
00162 }
00163
00169 public function getContextObjType()
00170 {
00171 return $this->context_obj_type;
00172 }
00173
00179 public function setContextSubObjId($a_context_sub_obj_id)
00180 {
00181 $this->context_sub_obj_id = $a_context_sub_obj_id;
00182 }
00183
00189 public function getContextSubObjId()
00190 {
00191 return $this->context_sub_obj_id;
00192 }
00193
00199 public function setContextSubObjType($a_context_sub_obj_type)
00200 {
00201 $this->context_sub_obj_type = $a_context_sub_obj_type;
00202 }
00203
00209 public function getContextSubObjType()
00210 {
00211 return $this->context_sub_obj_type;
00212 }
00213
00219 public function setContentType($a_content_type = "text")
00220 {
00221 $this->content_type = $a_content_type;
00222 }
00223
00229 public function getContentType()
00230 {
00231 return $this->content_type;
00232 }
00233
00239 public function setCreationDate($a_creation_date)
00240 {
00241 $this->creation_date = $a_creation_date;
00242 }
00243
00249 public function getCreationDate()
00250 {
00251 return $this->creation_date;
00252 }
00253
00259 public function setUpdateDate($a_update_date)
00260 {
00261 $this->update_date = $a_update_date;
00262 }
00263
00269 public function getUpdateDate()
00270 {
00271 return $this->update_date;
00272 }
00273
00279 public function setUserId($a_user_id)
00280 {
00281 $this->user_id = $a_user_id;
00282 }
00283
00289 public function getUserId()
00290 {
00291 return $this->user_id;
00292 }
00293
00299 public function setVisibility($a_visibility = "users")
00300 {
00301 $this->visibility = $a_visibility;
00302 }
00303
00309 public function getVisibility()
00310 {
00311 return $this->visibility;
00312 }
00313
00319 public function setContentLong($a_content_long)
00320 {
00321 $this->content_long = $a_content_long;
00322 }
00323
00329 public function getContentLong()
00330 {
00331 return $this->content_long;
00332 }
00333
00339 public function setPriority($a_priority = 1)
00340 {
00341 $this->priority = $a_priority;
00342 }
00343
00349 public function getPriority()
00350 {
00351 return $this->priority;
00352 }
00353
00359 public function setContentIsLangVar($a_content_is_lang_var = 0)
00360 {
00361 $this->content_is_lang_var = $a_content_is_lang_var;
00362 }
00363
00369 public function getContentIsLangVar()
00370 {
00371 return $this->content_is_lang_var;
00372 }
00373
00379 public function setMobId($a_mob_id)
00380 {
00381 $this->mob_id = $a_mob_id;
00382 }
00383
00389 public function getMobId()
00390 {
00391 return $this->mob_id;
00392 }
00393
00399 public function setPlaytime($a_playtime)
00400 {
00401 $this->playtime = $a_playtime;
00402 }
00403
00409 public function getPlaytime()
00410 {
00411 return $this->playtime;
00412 }
00413
00418 public function create()
00419 {
00420 global $ilDB;
00421
00422 $query = "INSERT INTO il_news_item (".
00423 " title".
00424 ", content".
00425 ", context_obj_id".
00426 ", context_obj_type".
00427 ", context_sub_obj_id".
00428 ", context_sub_obj_type".
00429 ", content_type".
00430 ", creation_date".
00431 ", update_date".
00432 ", user_id".
00433 ", visibility".
00434 ", content_long".
00435 ", priority".
00436 ", content_is_lang_var".
00437 ", mob_id".
00438 ", playtime".
00439 " ) VALUES (".
00440 $ilDB->quote($this->getTitle())
00441 .",".$ilDB->quote($this->getContent())
00442 .",".$ilDB->quote($this->getContextObjId())
00443 .",".$ilDB->quote($this->getContextObjType())
00444 .",".$ilDB->quote($this->getContextSubObjId())
00445 .",".$ilDB->quote($this->getContextSubObjType())
00446 .",".$ilDB->quote($this->getContentType())
00447 .","."now()"
00448 .","."now()"
00449 .",".$ilDB->quote($this->getUserId())
00450 .",".$ilDB->quote($this->getVisibility())
00451 .",".$ilDB->quote($this->getContentLong())
00452 .",".$ilDB->quote($this->getPriority())
00453 .",".$ilDB->quote($this->getContentIsLangVar())
00454 .",".$ilDB->quote($this->getMobId())
00455 .",".$ilDB->quote($this->getPlaytime()).")";
00456 $ilDB->query($query);
00457 $this->setId($ilDB->getLastInsertId());
00458
00459
00460 }
00461
00466 public function read()
00467 {
00468 global $ilDB;
00469
00470 $query = "SELECT * FROM il_news_item WHERE id = ".
00471 $ilDB->quote($this->getId());
00472 $set = $ilDB->query($query);
00473 $rec = $set->fetchRow(DB_FETCHMODE_ASSOC);
00474
00475 $this->setTitle($rec["title"]);
00476 $this->setContent($rec["content"]);
00477 $this->setContextObjId($rec["context_obj_id"]);
00478 $this->setContextObjType($rec["context_obj_type"]);
00479 $this->setContextSubObjId($rec["context_sub_obj_id"]);
00480 $this->setContextSubObjType($rec["context_sub_obj_type"]);
00481 $this->setContentType($rec["content_type"]);
00482 $this->setCreationDate($rec["creation_date"]);
00483 $this->setUpdateDate($rec["update_date"]);
00484 $this->setUserId($rec["user_id"]);
00485 $this->setVisibility($rec["visibility"]);
00486 $this->setContentLong($rec["content_long"]);
00487 $this->setPriority($rec["priority"]);
00488 $this->setContentIsLangVar($rec["content_is_lang_var"]);
00489 $this->setMobId($rec["mob_id"]);
00490 $this->setPlaytime($rec["playtime"]);
00491
00492 }
00493
00498 public function update()
00499 {
00500 global $ilDB;
00501
00502 $query = "UPDATE il_news_item SET ".
00503 " title = ".$ilDB->quote($this->getTitle()).
00504 ", content = ".$ilDB->quote($this->getContent()).
00505 ", context_obj_id = ".$ilDB->quote($this->getContextObjId()).
00506 ", context_obj_type = ".$ilDB->quote($this->getContextObjType()).
00507 ", context_sub_obj_id = ".$ilDB->quote($this->getContextSubObjId()).
00508 ", context_sub_obj_type = ".$ilDB->quote($this->getContextSubObjType()).
00509 ", content_type = ".$ilDB->quote($this->getContentType()).
00510 ", creation_date = ".$ilDB->quote($this->getCreationDate()).
00511 ", update_date = now()".
00512 ", user_id = ".$ilDB->quote($this->getUserId()).
00513 ", visibility = ".$ilDB->quote($this->getVisibility()).
00514 ", content_long = ".$ilDB->quote($this->getContentLong()).
00515 ", priority = ".$ilDB->quote($this->getPriority()).
00516 ", content_is_lang_var = ".$ilDB->quote($this->getContentIsLangVar()).
00517 ", mob_id = ".$ilDB->quote($this->getMobId()).
00518 ", playtime = ".$ilDB->quote($this->getPlaytime()).
00519 " WHERE id = ".$ilDB->quote($this->getId());
00520
00521 $ilDB->query($query);
00522
00523 }
00524
00529 public function delete()
00530 {
00531 global $ilDB;
00532
00533 $query = "DELETE FROM il_news_item".
00534 " WHERE id = ".$ilDB->quote($this->getId());
00535
00536 $ilDB->query($query);
00537
00538 }
00539
00544 public function queryNewsForContext()
00545 {
00546 global $ilDB;
00547
00548 $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 ".
00549 "FROM il_news_item ".
00550 "WHERE ".
00551 "context_obj_id = ".$ilDB->quote($this->getContextObjId()).
00552 " AND context_obj_type = ".$ilDB->quote($this->getContextObjType()).
00553 " AND context_sub_obj_id = ".$ilDB->quote($this->getContextSubObjId()).
00554 " AND context_sub_obj_type = ".$ilDB->quote($this->getContextSubObjType()).
00555 " ORDER BY creation_date DESC ".
00556 "";
00557
00558 $set = $ilDB->query($query);
00559 $result = array();
00560 while($rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
00561 {
00562 $result[] = $rec;
00563 }
00564
00565 return $result;
00566
00567 }
00568
00573 public function queryNewsForVisibility()
00574 {
00575 global $ilDB;
00576
00577 $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 ".
00578 "FROM il_news_item ".
00579 "WHERE ".
00580 "context_obj_id = ".$ilDB->quote($this->getContextObjId()).
00581 " AND context_obj_type = ".$ilDB->quote($this->getContextObjType()).
00582 " AND context_sub_obj_id = ".$ilDB->quote($this->getContextSubObjId()).
00583 " AND context_sub_obj_type = ".$ilDB->quote($this->getContextSubObjType()).
00584 " AND visibility = ".$ilDB->quote($this->getVisibility()).
00585 " ORDER BY creation_date DESC ".
00586 "";
00587
00588 $set = $ilDB->query($query);
00589 $result = array();
00590 while($rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
00591 {
00592 $result[] = $rec;
00593 }
00594
00595 return $result;
00596
00597 }
00598
00599
00600 }
00601 ?>