ILIAS  release_7 Revision v7.30-3-g800a261c036
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
4include_once("./Services/DataSet/classes/class.ilDataSet.php");
5
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 {
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
131 protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
132 {
133 return false;
134 }
135
136
143 public function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
144 {
145 $a_rec = $this->stripTags($a_rec);
146
147 switch ($a_entity) {
148 case "news":
149 $mob_id = null;
150 if ($a_rec["MobId"] > 0) {
151 $mob_id = $a_mapping->getMapping("Services/MediaObjects", "mob", $a_rec["MobId"]);
152 }
153 $c = (int) $a_rec["ContextObjId"] . ":" . $a_rec["ContextObjType"] . ":" . (int) $a_rec["ContextSubObjId"] .
154 ":" . $a_rec["ContextSubObjType"];
155 $context = $a_mapping->getMapping("Services/News", "news_context", $c);
156 $context = explode(":", $context);
157//var_dump($c);
158//var_dump($a_mapping->mappings["Services/News"]["news_context"]);
159 include_once("./Services/News/classes/class.ilNewsItem.php");
160 $newObj = new ilNewsItem();
161 $newObj->setTitle($a_rec["Title"]);
162 $newObj->setContent($a_rec["Content"]);
163 $newObj->setPriority($a_rec["Priority"]);
164 $newObj->setContextObjId($context[0]);
165 $newObj->setContextObjType($context[1]);
166 $newObj->setContextSubObjId($context[2]);
167 $newObj->setContextSubObjType($context[3]);
168 $newObj->setContentType($a_rec["ContentType"]);
169 $newObj->setVisibility($a_rec["Visibility"]);
170 $newObj->setContentLong($a_rec["ContentLong"]);
171 $newObj->setContentIsLangVar($a_rec["ContentIsLangVar"]);
172 $newObj->setMobId($mob_id);
173 $newObj->setPlaytime($a_rec["Playtime"]);
174 $newObj->create();
175 $a_mapping->addMapping("Services/News", "news", $a_rec["Id"], $newObj->getId());
176 break;
177
178 case "news_settings":
179
180 $dummy_dataset = new ilObjectDataSet();
181 $new_obj_id = $dummy_dataset->getNewObjId($a_mapping, $a_rec["ObjId"]);
182
183 if ($new_obj_id > 0 && $a_schema_version == "5.4.0") {
184 foreach ([
185 "public_feed" => "PublicFeed",
186 "keep_rss_min" => "KeepRssMin",
187 "default_visibility" => "DefaultVisibility",
188 "hide_news_per_date" => "HideNewsPerDate",
189 "hide_news_date" => "HideNewsDate",
190 "public_notifications" => "PublicNotifications"
191 ] as $set => $field) {
193 "news",
194 $set,
195 $a_rec[$field],
196 0,
197 $new_obj_id
198 );
199 }
200 }
201 break;
202
203 }
204 }
205}
An exception for terminatinating execution or to throw for unit testing.
static _write($a_type, $a_setting, $a_value, $a_user=0, $a_block_id=0)
Write setting to database.
static _lookup($a_type, $a_setting, $a_user=0, $a_block_id=0)
Lookup setting from database.
A dataset contains in data in a common structure that can be shared and transformed for different pur...
stripTags(array $rec, array $omit_keys=[])
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 ...
News data set class.
readData($a_entity, $a_version, $a_ids, $a_field="")
Read data.
getTypes($a_entity, $a_version)
Get field types for entity.
getXmlNamespace($a_entity, $a_schema_version)
Get xml namespace.
getDependencies($a_entity, $a_version, $a_rec, $a_ids)
Determine the dependent sets of data.
importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
Import record.
getSupportedVersions()
Get supported versions.
Object data set class.
$c
Definition: cli.php:37
global $ilDB
$context
Definition: webdav.php:26