ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilNewsDataSet.php
Go to the documentation of this file.
1<?php
2
24{
25 public function getSupportedVersions(): array
26 {
27 return ["5.4.0", "4.1.0"];
28 }
29
30 protected function getXmlNamespace(string $a_entity, string $a_schema_version): string
31 {
32 return "https://www.ilias.de/xml/Services/News/" . $a_entity;
33 }
34
35 protected function getTypes(string $a_entity, string $a_version): array
36 {
37 if ($a_entity === "news") {
38 switch ($a_version) {
39 case "4.1.0":
40 case "5.4.0":
41 return [
42 "Id" => "integer",
43 "Title" => "text",
44 "Content" => "text",
45 "Priority" => "integer",
46 "ContextObjId" => "integer",
47 "ContextObjType" => "text",
48 "ContextSubObjId" => "integer",
49 "ContextSubObjType" => "text",
50 "ContentType" => "text",
51 "Visibility" => "text",
52 "ContentLong" => "text",
53 "ContentIsLangVar" => "integer",
54 "MobId" => "integer",
55 "Playtime" => "text"
56 ];
57 }
58 }
59 if ($a_entity === "news_settings") {
60 switch ($a_version) {
61 case "5.4.0":
62 return [
63 "ObjId" => "integer",
64 "PublicFeed" => "integer",
65 "DefaultVisibility" => "text",
66 "KeepRssMin" => "integer",
67 "HideNewsPerDate" => "integer",
68 "HideNewsDate" => "text",
69 "PublicNotifications" => "integer"
70 ];
71 }
72 }
73 return [];
74 }
75
76 public function readData(string $a_entity, string $a_version, array $a_ids): void
77 {
79
80 if (!is_array($a_ids)) {
81 $a_ids = [$a_ids];
82 }
83
84 if ($a_entity === "news") {
85 switch ($a_version) {
86 case "4.1.0":
87 case "5.4.0":
88 $this->getDirectDataFromQuery("SELECT id, title, content, priority," .
89 " context_obj_id, context_obj_type, context_sub_obj_id, context_sub_obj_type, " .
90 " content_type, visibility, content_long, content_is_lang_var, mob_id, playtime" .
91 " FROM il_news_item " .
92 "WHERE " .
93 $ilDB->in("id", $a_ids, false, "integer"));
94 break;
95 }
96 }
97
98 if ($a_entity === "news_settings") {
99 switch ($a_version) {
100 case "5.4.0":
101 foreach ($a_ids as $obj_id) {
102 $this->data[$obj_id]["ObjId"] = $obj_id;
103 $this->data[$obj_id]["PublicFeed"] = ilBlockSetting::_lookup("news", "public_feed", 0, $obj_id);
104 $this->data[$obj_id]["KeepRssMin"] = (int) ilBlockSetting::_lookup("news", "keep_rss_min", 0, $obj_id);
105 $this->data[$obj_id]["DefaultVisibility"] = ilBlockSetting::_lookup("news", "default_visibility", 0, $obj_id);
106 $this->data[$obj_id]["HideNewsPerDate"] = (int) ilBlockSetting::_lookup("news", "hide_news_per_date", 0, $obj_id);
107 $this->data[$obj_id]["HideNewsDate"] = ilBlockSetting::_lookup("news", "hide_news_date", 0, $obj_id);
108 $this->data[$obj_id]["PublicNotifications"] = (int) ilBlockSetting::_lookup("news", "public_notifications", 0, $obj_id);
109 }
110 break;
111 }
112 }
113 }
114
115 public function importRecord(string $a_entity, array $a_types, array $a_rec, ilImportMapping $a_mapping, string $a_schema_version): void
116 {
117 $a_rec = $this->stripTags($a_rec);
118 switch ($a_entity) {
119 case "news":
120 $mob_id = null;
121 if ($a_rec["MobId"] > 0) {
122 $mob_id = $a_mapping->getMapping("components/ILIAS/MediaObjects", "mob", $a_rec["MobId"]);
123 }
124 $c = (int) $a_rec["ContextObjId"] . ":" . $a_rec["ContextObjType"] . ":" . (int) $a_rec["ContextSubObjId"] .
125 ":" . $a_rec["ContextSubObjType"];
126 $context = $a_mapping->getMapping("components/ILIAS/News", "news_context", $c);
127 $context = explode(":", $context);
128
129 $newObj = new ilNewsItem();
130 $newObj->setTitle($a_rec["Title"]);
131 $newObj->setContent($a_rec["Content"]);
132 $newObj->setPriority($a_rec["Priority"]);
133 $newObj->setContextObjId((int) $context[0]);
134 $newObj->setContextObjType($context[1]);
135 $newObj->setContextSubObjId((int) $context[2]);
136 $newObj->setContextSubObjType($context[3]);
137 $newObj->setContentType($a_rec["ContentType"]);
138 $newObj->setVisibility($a_rec["Visibility"]);
139 $newObj->setContentLong($a_rec["ContentLong"]);
140 $newObj->setContentIsLangVar($a_rec["ContentIsLangVar"]);
141 $newObj->setMobId((int) $mob_id);
142 $newObj->setPlaytime($a_rec["Playtime"]);
143 $newObj->create();
144 $a_mapping->addMapping("components/ILIAS/News", "news", $a_rec["Id"], (string) $newObj->getId());
145 break;
146
147 case "news_settings":
148
149 $dummy_dataset = new ilObjectDataSet();
150 $new_obj_id = $dummy_dataset->getNewObjId($a_mapping, $a_rec["ObjId"]);
151
152 if ($new_obj_id > 0 && $a_schema_version === "5.4.0") {
153 foreach ([
154 "public_feed" => "PublicFeed",
155 "keep_rss_min" => "KeepRssMin",
156 "default_visibility" => "DefaultVisibility",
157 "hide_news_per_date" => "HideNewsPerDate",
158 "hide_news_date" => "HideNewsDate",
159 "public_notifications" => "PublicNotifications"
160 ] as $set => $field) {
162 "news",
163 $set,
164 $a_rec[$field],
165 0,
166 $new_obj_id
167 );
168 }
169 }
170 break;
171 }
172 }
173}
static _write(string $a_type, string $a_setting, string $a_value, int $a_user=0, int $a_block_id=0)
Write setting to database.
static _lookup(string $a_type, string $a_setting, int $a_user=0, int $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(string $a_query, bool $a_convert_to_leading_upper=true, bool $a_set=true)
Get data from query.This is a standard procedure, all db field names are directly mapped to abstract ...
ilDBInterface $db
addMapping(string $a_comp, string $a_entity, string $a_old_id, string $a_new_id)
getMapping(string $a_comp, string $a_entity, string $a_old_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
readData(string $a_entity, string $a_version, array $a_ids)
Read data from DB.
importRecord(string $a_entity, array $a_types, array $a_rec, ilImportMapping $a_mapping, string $a_schema_version)
Needs to be overwritten for import use case.
getXmlNamespace(string $a_entity, string $a_schema_version)
getTypes(string $a_entity, string $a_version)
Get (abstract) types for (abstract) field names.
A news item can be created by different sources.
Object data set class.
$c
Definition: deliver.php:25
$context
Definition: webdav.php:31