ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilNewsDataSet.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("./Services/DataSet/classes/class.ilDataSet.php");
5 
13 class ilNewsDataSet extends ilDataSet
14 {
21  public function getSupportedVersions()
22  {
23  return array("5.4.0", "4.1.0");
24  }
25 
32  public function getXmlNamespace($a_entity, $a_schema_version)
33  {
34  return "http://www.ilias.de/xml/Services/News/" . $a_entity;
35  }
36 
43  protected function getTypes($a_entity, $a_version)
44  {
45  if ($a_entity == "news") {
46  switch ($a_version) {
47  case "4.1.0":
48  case "5.4.0":
49  return array(
50  "Id" => "integer",
51  "Title" => "text",
52  "Content" => "text",
53  "Priority" => "integer",
54  "ContextObjId" => "integer",
55  "ContextObjType" => "text",
56  "ContextSubObjId" => "integer",
57  "ContextSubObjType" => "text",
58  "ContentType" => "text",
59  "Visibility" => "text",
60  "ContentLong" => "text",
61  "ContentIsLangVar" => "integer",
62  "MobId" => "integer",
63  "Playtime" => "text"
64  );
65  }
66  }
67  if ($a_entity == "news_settings") {
68  switch ($a_version) {
69  case "5.4.0":
70  return array(
71  "ObjId" => "integer",
72  "PublicFeed" => "integer",
73  "DefaultVisibility" => "text",
74  "KeepRssMin" => "integer",
75  "HideNewsPerDate" => "integer",
76  "HideNewsDate" => "text",
77  "PublicNotifications" => "integer"
78  );
79  }
80  }
81  }
82 
89  public function readData($a_entity, $a_version, $a_ids, $a_field = "")
90  {
91  $ilDB = $this->db;
92 
93  if (!is_array($a_ids)) {
94  $a_ids = array($a_ids);
95  }
96 
97  if ($a_entity == "news") {
98  switch ($a_version) {
99  case "4.1.0":
100  case "5.4.0":
101  $this->getDirectDataFromQuery("SELECT id, title, content, priority," .
102  " context_obj_id, context_obj_type, context_sub_obj_id, context_sub_obj_type, " .
103  " content_type, visibility, content_long, content_is_lang_var, mob_id, playtime" .
104  " FROM il_news_item " .
105  "WHERE " .
106  $ilDB->in("id", $a_ids, false, "integer"));
107  break;
108  }
109  }
110 
111  if ($a_entity == "news_settings") {
112  switch ($a_version) {
113  case "5.4.0":
114  foreach ($a_ids as $obj_id) {
115  $this->data[$obj_id]["ObjId"] = $obj_id;
116  $this->data[$obj_id]["PublicFeed"] = ilBlockSetting::_lookup("news", "public_feed", 0, $obj_id);
117  $this->data[$obj_id]["KeepRssMin"] = (int) ilBlockSetting::_lookup("news", "keep_rss_min", 0, $obj_id);
118  $this->data[$obj_id]["DefaultVisibility"] = ilBlockSetting::_lookup("news", "default_visibility", 0, $obj_id);
119  $this->data[$obj_id]["HideNewsPerDate"] = (int) ilBlockSetting::_lookup("news", "hide_news_per_date", 0, $obj_id);
120  $this->data[$obj_id]["HideNewsDate"] = ilBlockSetting::_lookup("news", "hide_news_date", 0, $obj_id);
121  $this->data[$obj_id]["PublicNotifications"] = (int) ilBlockSetting::_lookup("news", "public_notifications", 0, $obj_id);
122  }
123  break;
124  }
125  }
126 
127  }
128 
132  protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
133  {
134  return false;
135  }
136 
137 
144  public function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
145  {
146  //echo $a_entity;
147  //var_dump($a_rec);
148 
149  switch ($a_entity) {
150  case "news":
151  $mob_id = null;
152  if ($a_rec["MobId"] > 0) {
153  $mob_id = $a_mapping->getMapping("Services/MediaObjects", "mob", $a_rec["MobId"]);
154  }
155  $c = (int) $a_rec["ContextObjId"] . ":" . $a_rec["ContextObjType"] . ":" . (int) $a_rec["ContextSubObjId"] .
156  ":" . $a_rec["ContextSubObjType"];
157  $context = $a_mapping->getMapping("Services/News", "news_context", $c);
158  $context = explode(":", $context);
159 //var_dump($c);
160 //var_dump($a_mapping->mappings["Services/News"]["news_context"]);
161  include_once("./Services/News/classes/class.ilNewsItem.php");
162  $newObj = new ilNewsItem();
163  $newObj->setTitle($a_rec["Title"]);
164  $newObj->setContent($a_rec["Content"]);
165  $newObj->setPriority($a_rec["Priority"]);
166  $newObj->setContextObjId($context[0]);
167  $newObj->setContextObjType($context[1]);
168  $newObj->setContextSubObjId($context[2]);
169  $newObj->setContextSubObjType($context[3]);
170  $newObj->setContentType($a_rec["ContentType"]);
171  $newObj->setVisibility($a_rec["Visibility"]);
172  $newObj->setContentLong($a_rec["ContentLong"]);
173  $newObj->setContentIsLangVar($a_rec["ContentIsLangVar"]);
174  $newObj->setMobId($mob_id);
175  $newObj->setPlaytime($a_rec["Playtime"]);
176  $newObj->create();
177  $a_mapping->addMapping("Services/News", "news", $a_rec["Id"], $newObj->getId());
178  break;
179 
180  case "news_settings":
181 
182  $dummy_dataset = new ilObjectDataSet();
183  $new_obj_id = $dummy_dataset->getNewObjId($a_mapping, $a_rec["ObjId"]);
184 
185  if ($new_obj_id > 0 && $a_schema_version == "5.4.0") {
186  foreach ([
187  "public_feed" => "PublicFeed",
188  "keep_rss_min" => "KeepRssMin",
189  "default_visibility" => "DefaultVisibility",
190  "hide_news_per_date" => "HideNewsPerDate",
191  "hide_news_date" => "HideNewsDate",
192  "public_notifications" => "PublicNotifications"
193  ] as $set => $field) {
195  "news",
196  $set,
197  $a_rec[$field],
198  0,
199  $new_obj_id
200  );
201  }
202  }
203  break;
204 
205  }
206  }
207 }
readData($a_entity, $a_version, $a_ids, $a_field="")
Read data.
static _write($a_type, $a_setting, $a_value, $a_user=0, $a_block_id=0)
Write setting to database.
$context
Definition: webdav.php:25
getDirectDataFromQuery($a_query, $a_convert_to_leading_upper=true, $a_set=true)
Get data from query.This is a standard procedure, all db field names are directly mapped to abstract ...
getXmlNamespace($a_entity, $a_schema_version)
Get xml namespace.
Object data set class.
getSupportedVersions()
Get supported versions.
getTypes($a_entity, $a_version)
Get field types for entity.
static _lookup($a_type, $a_setting, $a_user=0, $a_block_id=0)
Lookup setting from database.
News data set class.
getDependencies($a_entity, $a_version, $a_rec, $a_ids)
Determine the dependent sets of data.
$this data['403_header']
global $ilDB
A dataset contains in data in a common structure that can be shared and transformed for different pur...
importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
Import record.