ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilMDCreator.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  +-----------------------------------------------------------------------------+
7  | ILIAS open source |
8  +-----------------------------------------------------------------------------+
9  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
10  | |
11  | This program is free software; you can redistribute it and/or |
12  | modify it under the terms of the GNU General Public License |
13  | as published by the Free Software Foundation; either version 2 |
14  | of the License, or (at your option) any later version. |
15  | |
16  | This program is distributed in the hope that it will be useful, |
17  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
18  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19  | GNU General Public License for more details. |
20  | |
21  | You should have received a copy of the GNU General Public License |
22  | along with this program; if not, write to the Free Software |
23  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
24  +-----------------------------------------------------------------------------+
25 */
26 
36 {
37  protected ilMD $md_obj;
38 
39  /*
40  * rbac_id ref_id of rbac object (e.g for page objects the obj_id of the content object)
41  */
42  private int $rbac_id;
43 
44  /*
45  * obj_id (e.g for structure objects the obj_id of the structure object)
46  */
47  private int $obj_id;
48 
49  /*
50  * type of the object (e.g st,pg,crs ...)
51  */
52  public string $obj_type;
53 
54  private string $structure = '';
55  private string $catalog = '';
56  private string $entry = '';
57  private string $keyword = '';
58  private string $title = '';
59  private string $description = '';
60  private string $title_lng = '';
61 
62  public function __construct(int $a_rbac_id, int $a_obj_id, string $a_type)
63  {
64  if ($a_obj_id === 0) {
65  $a_obj_id = $a_rbac_id;
66  }
67 
68  $this->rbac_id = $a_rbac_id;
69  $this->obj_id = $a_obj_id;
70  $this->obj_type = $a_type;
71 
72  $this->md_obj = new ilMD($a_rbac_id, $a_obj_id, $a_type);
73  }
74 
75  // SET/GET
76  public function setTitle(string $a_title): void
77  {
78  $this->title = $a_title;
79  }
80 
81  public function getTitle(): string
82  {
83  return $this->title;
84  }
85 
86  public function setDescription(string $a_desc): void
87  {
88  $this->description = $a_desc;
89  }
90 
91  public function getDescription(): string
92  {
93  return $this->description;
94  }
95 
96  public function setTitleLanguage(string $a_lng): void
97  {
98  $this->title_lng = $a_lng;
99  }
100 
102  {
103  return new ilMDLanguageItem($this->title_lng);
104  }
105 
106  public function setDescriptionLanguage(string $a_lng): void
107  {
108  $this->title_lng = $a_lng;
109  }
110 
112  {
113  return new ilMDLanguageItem($this->title_lng);
114  }
115 
116  public function setLanguage(string $a_lng): void
117  {
118  $this->title_lng = $a_lng;
119  }
120 
121  public function getLanguage(): ilMDLanguageItem
122  {
123  return new ilMDLanguageItem($this->title_lng);
124  }
125 
126  public function setKeyword(string $a_key): void
127  {
128  $this->keyword = $a_key;
129  }
130 
131  public function getKeyword(): string
132  {
133  return $this->keyword;
134  }
135 
136  public function getRBACId(): int
137  {
138  return $this->rbac_id;
139  }
140 
141  public function getObjId(): int
142  {
143  return $this->obj_id;
144  }
145 
146  public function getObjType(): string
147  {
148  return $this->obj_type;
149  }
150 
151  public function setKeywordLanguage(string $a_lng): void
152  {
153  $this->title_lng = $a_lng;
154  }
155 
157  {
158  return new ilMDLanguageItem($this->title_lng);
159  }
160 
161  public function setCatalog(string $a_cat): void
162  {
163  $this->catalog = $a_cat;
164  }
165 
166  public function getCatalog(): string
167  {
168  return $this->catalog ?: 'ILIAS';
169  }
170 
171  public function setEntry(string $a_entry): void
172  {
173  $this->entry = $a_entry;
174  }
175 
176  public function getEntry(): string
177  {
178  return $this->entry ?: 'il__' . $this->getObjType() . '_' . $this->getObjId();
179  }
180 
181  public function setStructure(string $a_structure): void
182  {
183  $this->structure = $a_structure;
184  }
185 
186  public function getStructure(): string
187  {
188  return $this->structure ?: 'Hierarchical';
189  }
190 
191  public function create(): void
192  {
193  $this->__createGeneral();
194  }
195 
196  // PROTECTED
197  public function __createGeneral(): bool
198  {
199  $md_gen = $this->md_obj->addGeneral();
200 
201  $md_gen->setStructure($this->getStructure());
202  $md_gen->setTitle($this->getTitle());
203  $md_gen->setTitleLanguage($this->getTitleLanguage());
204  $md_gen->save();
205 
206  $md_ide = $md_gen->addIdentifier();
207  $md_ide->setCatalog($this->getCatalog());
208  $md_ide->setEntry($this->getEntry());
209  $md_ide->save();
210 
211  $md_lng = $md_gen->addLanguage();
212  $md_lng->setLanguage($this->getLanguage());
213  $md_lng->save();
214 
215  $md_des = $md_gen->addDescription();
216  $md_des->setDescription($this->getDescription());
217  $md_des->setDescriptionLanguage($this->getDescriptionLanguage());
218  $md_des->save();
219 
220  $md_key = $md_gen->addKeyword();
221  $md_key->setKeyword($this->getKeyword());
222  $md_key->setKeywordLanguage($this->getKeywordLanguage());
223  $md_key->save();
224 
225  return true;
226  }
227 }
setKeywordLanguage(string $a_lng)
__construct(int $a_rbac_id, int $a_obj_id, string $a_type)
setStructure(string $a_structure)
setDescription(string $a_desc)
setDescriptionLanguage(string $a_lng)
setCatalog(string $a_cat)
setEntry(string $a_entry)
setTitle(string $a_title)
setLanguage(string $a_lng)
setKeyword(string $a_key)
setTitleLanguage(string $a_lng)