ILIAS  release_8 Revision v8.24
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");
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 }
72 }
73
74 if ($a_entity === "portfolio_page") {
75 switch ($a_version) {
76 case "4.4.0":
77 case "5.0.0":
78 return array(
79 "Id" => "integer",
80 "PortfolioId" => "integer",
81 "Title" => "integer",
82 "OrderNr" => "integer",
83 "Type" => "text"
84 );
85 }
86 }
87 return [];
88 }
89
90 public function readData(string $a_entity, string $a_version, array $a_ids): void
91 {
93
94 if (!is_array($a_ids)) {
95 $a_ids = array($a_ids);
96 }
97
98 if ($a_entity === "prtt") {
99 switch ($a_version) {
100 case "4.4.0":
101 $this->getDirectDataFromQuery("SELECT prtf.id,od.title,od.description," .
102 "prtf.comments,prtf.bg_color,prtf.font_color,prtf.img,prtf.ppic" .
103 " FROM usr_portfolio prtf" .
104 " JOIN object_data od ON (od.obj_id = prtf.id)" .
105 " WHERE " . $ilDB->in("prtf.id", $a_ids, false, "integer") .
106 " AND od.type = " . $ilDB->quote("prtt", "text"));
107 break;
108
109 case "5.0.0":
110 $this->getDirectDataFromQuery("SELECT prtf.id,od.title,od.description," .
111 "prtf.bg_color,prtf.font_color,prtf.img,prtf.ppic" .
112 " FROM usr_portfolio prtf" .
113 " JOIN object_data od ON (od.obj_id = prtf.id)" .
114 " WHERE " . $ilDB->in("prtf.id", $a_ids, false, "integer") .
115 " AND od.type = " . $ilDB->quote("prtt", "text"));
116 break;
117 }
118 }
119
120 if ($a_entity === "portfolio_page") {
121 switch ($a_version) {
122 case "4.4.0":
123 case "5.0.0":
124 $this->getDirectDataFromQuery("SELECT id,portfolio_id,title,order_nr,type" .
125 " FROM usr_portfolio_page" .
126 " WHERE " . $ilDB->in("portfolio_id", $a_ids, false, "integer"));
127 break;
128 }
129 }
130 }
131
132 protected function getDependencies(
133 string $a_entity,
134 string $a_version,
135 ?array $a_rec = null,
136 ?array $a_ids = null
137 ): array {
138 if ($a_entity === "prtt") {
139 return array(
140 "portfolio_page" => array("ids" => $a_rec["Id"] ?? null)
141 );
142 }
143 return [];
144 }
145
146 public function getXmlRecord(
147 string $a_entity,
148 string $a_version,
149 array $a_set
150 ): array {
151 if ($a_entity === "prtt") {
152 $dir = ilObjPortfolioTemplate::initStorage($a_set["Id"]);
153 $a_set["Dir"] = $dir;
154
155 $a_set["Comments"] = $this->notes->domain()->commentsActive((int) $a_set["Id"]);
156 }
157
158 return $a_set;
159 }
160
161
162 public function importRecord(
163 string $a_entity,
164 array $a_types,
165 array $a_rec,
166 ilImportMapping $a_mapping,
167 string $a_schema_version
168 ): void {
169 $a_rec = $this->stripTags($a_rec);
170 switch ($a_entity) {
171 case "prtt":
172
173 // container copy
174 if ($new_id = $a_mapping->getMapping("Services/Container", "objs", $a_rec["Id"])) {
175 $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
176 } else {
177 $newObj = new ilObjPortfolioTemplate();
178 $newObj->create();
179 }
180
181 $newObj->setTitle($a_rec["Title"]);
182 $newObj->setDescription($a_rec["Description"]);
183 $newObj->setPublicComments($a_rec["Comments"]);
184 $newObj->setBackgroundColor($a_rec["BgColor"]);
185 $newObj->setFontColor($a_rec["FontColor"]);
186 $newObj->setProfilePicture($a_rec["Ppic"]);
187 $newObj->setImage($a_rec["Img"]);
188 $newObj->update();
189
190 // handle image(s)
191 if ($a_rec["Img"]) {
192 $dir = str_replace("..", "", $a_rec["Dir"]);
193 if ($dir !== "" && $this->getImportDirectory() !== "") {
194 $source_dir = $this->getImportDirectory() . "/" . $dir;
195 $target_dir = ilObjPortfolioTemplate::initStorage($newObj->getId());
196 ilFileUtils::rCopy($source_dir, $target_dir);
197 }
198 }
199
200 $a_mapping->addMapping("Modules/Portfolio", "prtt", $a_rec["Id"], $newObj->getId());
201 $a_mapping->addMapping("Services/Object", "obj", $a_rec["Id"], $newObj->getId());
202 break;
203
204 case "portfolio_page":
205 $prtt_id = (int) $a_mapping->getMapping("Modules/Portfolio", "prtt", $a_rec["PortfolioId"]);
206 if ($prtt_id) {
207 $newObj = new ilPortfolioTemplatePage();
208 $newObj->setPortfolioId($prtt_id);
209 $newObj->setTitle($a_rec["Title"]);
210 $newObj->setType($a_rec["Type"]);
211 $newObj->setOrderNr($a_rec["OrderNr"]);
212 $newObj->create(true);
213
214 $a_mapping->addMapping("Services/COPage", "pg", "prtt:" . $a_rec["Id"], "prtt:" . $newObj->getId());
215 }
216 break;
217 }
218 }
219}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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
static rCopy(string $a_sdir, string $a_tdir, bool $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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)
static initStorage(int $a_id, string $a_subdir=null)
Init file system storage.
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...
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
global $DIC
Definition: feed.php:28
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc