ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilPortfolioDataSet.php
Go to the documentation of this file.
1<?php
2
31{
33 protected \ILIAS\Notes\Service $notes;
34
35 public function __construct()
36 {
37 global $DIC;
38
40 $this->notes = $DIC->notes();
41 }
42
43
44 public function getSupportedVersions(): array
45 {
46 return array("4.4.0", "5.0.0", "10.0");
47 }
48
49 protected function getXmlNamespace(string $a_entity, string $a_schema_version): string
50 {
51 return "https://www.ilias.de/xml/Modules/Portfolio/" . $a_entity;
52 }
53
54 protected function getTypes(string $a_entity, string $a_version): array
55 {
56 if ($a_entity === "prtt") {
57 switch ($a_version) {
58 case "4.4.0":
59 case "5.0.0":
60 return array(
61 "Id" => "integer",
62 "Title" => "text",
63 "Description" => "text",
64 "Comments" => "integer",
65 "BgColor" => "text",
66 "FontColor" => "text",
67 "Img" => "text",
68 "Ppic" => "integer",
69 "Dir" => "directory"
70 );
71 case "10.0":
72 return array(
73 "Id" => "integer",
74 "Title" => "text",
75 "Description" => "text",
76 "Comments" => "integer",
77 "BgColor" => "text",
78 "FontColor" => "text",
79 "Ppic" => "integer"
80 );
81 }
82 }
83
84 if ($a_entity === "portfolio_page") {
85 switch ($a_version) {
86 case "4.4.0":
87 case "5.0.0":
88 case "10.0":
89 return array(
90 "Id" => "integer",
91 "PortfolioId" => "integer",
92 "Title" => "integer",
93 "OrderNr" => "integer",
94 "Type" => "text"
95 );
96 }
97 }
98 return [];
99 }
100
101 public function readData(string $a_entity, string $a_version, array $a_ids): void
102 {
104
105 if (!is_array($a_ids)) {
106 $a_ids = array($a_ids);
107 }
108
109 if ($a_entity === "prtt") {
110 switch ($a_version) {
111 case "4.4.0":
112 $this->getDirectDataFromQuery("SELECT prtf.id,od.title,od.description," .
113 "prtf.comments,prtf.bg_color,prtf.font_color,prtf.img,prtf.ppic" .
114 " FROM usr_portfolio prtf" .
115 " JOIN object_data od ON (od.obj_id = prtf.id)" .
116 " WHERE " . $ilDB->in("prtf.id", $a_ids, false, "integer") .
117 " AND od.type = " . $ilDB->quote("prtt", "text"));
118 break;
119
120 case "5.0.0":
121 case "10.0":
122 $this->getDirectDataFromQuery("SELECT prtf.id,od.title,od.description," .
123 "prtf.bg_color,prtf.font_color,prtf.ppic" .
124 " FROM usr_portfolio prtf" .
125 " JOIN object_data od ON (od.obj_id = prtf.id)" .
126 " WHERE " . $ilDB->in("prtf.id", $a_ids, false, "integer") .
127 " AND od.type = " . $ilDB->quote("prtt", "text"));
128 break;
129 }
130 }
131
132 if ($a_entity === "portfolio_page") {
133 switch ($a_version) {
134 case "4.4.0":
135 case "5.0.0":
136 case "10.0":
137 $this->getDirectDataFromQuery("SELECT id,portfolio_id,title,order_nr,type" .
138 " FROM usr_portfolio_page" .
139 " WHERE " . $ilDB->in("portfolio_id", $a_ids, false, "integer"));
140 break;
141 }
142 }
143 }
144
145 protected function getDependencies(
146 string $a_entity,
147 string $a_version,
148 ?array $a_rec = null,
149 ?array $a_ids = null
150 ): array {
151 if ($a_entity === "prtt") {
152 return array(
153 "portfolio_page" => array("ids" => $a_rec["Id"] ?? null)
154 );
155 }
156 return [];
157 }
158
159 public function getXmlRecord(
160 string $a_entity,
161 string $a_version,
162 array $a_set
163 ): array {
164 if ($a_entity === "prtt") {
165 $a_set["Comments"] = $this->notes->domain()->commentsActive((int) $a_set["Id"]);
166 }
167
168 return $a_set;
169 }
170
171
172 public function importRecord(
173 string $a_entity,
174 array $a_types,
175 array $a_rec,
176 ilImportMapping $a_mapping,
177 string $a_schema_version
178 ): void {
179 $a_rec = $this->stripTags($a_rec);
180 switch ($a_entity) {
181 case "prtt":
182
183 // container copy
184 if ($new_id = $a_mapping->getMapping("components/ILIAS/Container", "objs", $a_rec["Id"])) {
185 $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
186 } else {
187 $newObj = new ilObjPortfolioTemplate();
188 $newObj->create();
189 }
190
191 $newObj->setTitle($a_rec["Title"]);
192 $newObj->setDescription($a_rec["Description"]);
193 $newObj->setPublicComments($a_rec["Comments"]);
194 $newObj->setBackgroundColor($a_rec["BgColor"]);
195 $newObj->setFontColor($a_rec["FontColor"]);
196 $newObj->setProfilePicture($a_rec["Ppic"]);
197 $newObj->update();
198
199 $a_mapping->addMapping("components/ILIAS/Portfolio", "prtt", $a_rec["Id"], $newObj->getId());
200 $a_mapping->addMapping("components/ILIAS/ILIASObject", "obj", $a_rec["Id"], $newObj->getId());
201 break;
202
203 case "portfolio_page":
204 $prtt_id = (int) $a_mapping->getMapping("components/ILIAS/Portfolio", "prtt", $a_rec["PortfolioId"]);
205 if ($prtt_id) {
206 if ((int) $a_rec["Type"] != ilPortfolioTemplatePage::TYPE_PAGE) {
207 return;
208 }
209 $newObj = new ilPortfolioTemplatePage();
210 $newObj->setPortfolioId($prtt_id);
211 $newObj->setTitle($a_rec["Title"]);
212 $newObj->setType($a_rec["Type"]);
213 $newObj->setOrderNr($a_rec["OrderNr"]);
214 $newObj->create(true);
215
216 $a_mapping->addMapping("components/ILIAS/COPage", "pg", "prtt:" . $a_rec["Id"], "prtt:" . $newObj->getId());
217 }
218 break;
219 }
220 }
221}
A dataset contains in data in a common structure that can be shared and transformed for different pur...
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object 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.
getTypes(string $a_entity, string $a_version)
Get (abstract) types for (abstract) field names.
getDependencies(string $a_entity, string $a_version, ?array $a_rec=null, ?array $a_ids=null)
ILIAS Notes Service $notes
getXmlNamespace(string $a_entity, string $a_schema_version)
getXmlRecord(string $a_entity, string $a_version, array $a_set)
Get xml record for version.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26