ILIAS  release_8 Revision v8.23
class.ilMDDescription.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 /*
5  +-----------------------------------------------------------------------------+
6  | ILIAS open source |
7  +-----------------------------------------------------------------------------+
8  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
9  | |
10  | This program is free software; you can redistribute it and/or |
11  | modify it under the terms of the GNU General Public License |
12  | as published by the Free Software Foundation; either version 2 |
13  | of the License, or (at your option) any later version. |
14  | |
15  | This program is distributed in the hope that it will be useful, |
16  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
17  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18  | GNU General Public License for more details. |
19  | |
20  | You should have received a copy of the GNU General Public License |
21  | along with this program; if not, write to the Free Software |
22  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
23  +-----------------------------------------------------------------------------+
24 */
25 
32 {
33  private string $description = '';
35 
36  // SET/GET
37  public function setDescription(string $a_description): void
38  {
39  $this->description = $a_description;
40  }
41 
42  public function getDescription(): string
43  {
44  return $this->description;
45  }
46 
47  public function setDescriptionLanguage(ilMDLanguageItem $lng_obj): void
48  {
49  $this->description_language = $lng_obj;
50  }
51 
53  {
54  return is_object($this->description_language) ? $this->description_language : null;
55  }
56 
57  public function getDescriptionLanguageCode(): string
58  {
59  return is_object($this->description_language) ? $this->description_language->getLanguageCode() : '';
60  }
61 
62  public function save(): int
63  {
64  $fields = $this->__getFields();
65  $fields['meta_description_id'] = array('integer', $next_id = $this->db->nextId('il_meta_description'));
66 
67  if ($this->db->insert('il_meta_description', $fields)) {
68  $this->setMetaId($next_id);
69  return $this->getMetaId();
70  }
71  return 0;
72  }
73 
74  public function update(): bool
75  {
76  return $this->getMetaId() && $this->db->update(
77  'il_meta_description',
78  $this->__getFields(),
79  array("meta_description_id" => array('integer', $this->getMetaId()))
80  );
81  }
82 
83  public function delete(): bool
84  {
85  if ($this->getMetaId()) {
86  $query = "DELETE FROM il_meta_description " .
87  "WHERE meta_description_id = " . $this->db->quote($this->getMetaId(), 'integer');
88  $res = $this->db->manipulate($query);
89 
90  return true;
91  }
92  return false;
93  }
94 
98  public function __getFields(): array
99  {
100  return array(
101  'rbac_id' => array('integer', $this->getRBACId()),
102  'obj_id' => array('integer', $this->getObjId()),
103  'obj_type' => array('text', $this->getObjType()),
104  'parent_type' => array('text', $this->getParentType()),
105  'parent_id' => array('integer', $this->getParentId()),
106  'description' => array('clob', $this->getDescription()),
107  'description_language' => array('text', $this->getDescriptionLanguageCode())
108  );
109  }
110 
111  public function read(): bool
112  {
113  if ($this->getMetaId()) {
114  $query = "SELECT * FROM il_meta_description " .
115  "WHERE meta_description_id = " . $this->db->quote($this->getMetaId(), 'integer');
116 
117  $res = $this->db->query($query);
118  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
119  $this->setRBACId((int) $row->rbac_id);
120  $this->setObjId((int) $row->obj_id);
121  $this->setObjType($row->obj_type);
122  $this->setParentId((int) $row->parent_id);
123  $this->setParentType($row->parent_type);
124  $this->setDescription((string) $row->description);
125  $this->setDescriptionLanguage(new ilMDLanguageItem((string) $row->description_language));
126  }
127  }
128  return true;
129  }
130 
131  public function toXML(ilXmlWriter $writer): void
132  {
133  $writer->xmlElement(
134  'Description',
135  array(
136  'Language' => $this->getDescriptionLanguageCode() ?: 'en'
137  ),
138  $this->getDescription()
139  );
140  }
141 
142  // STATIC
143 
147  public static function _getIds(int $a_rbac_id, int $a_obj_id, int $a_parent_id, string $a_parent_type): array
148  {
149  global $DIC;
150 
151  $ilDB = $DIC->database();
152 
153  $query = "SELECT meta_description_id FROM il_meta_description " .
154  "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, ilDBConstants::T_INTEGER) . " " .
155  "AND obj_id = " . $ilDB->quote($a_obj_id, ilDBConstants::T_INTEGER) . " " .
156  "AND parent_id = " . $ilDB->quote($a_parent_id, ilDBConstants::T_INTEGER) . " " .
157  "AND parent_type = " . $ilDB->quote($a_parent_type, ilDBConstants::T_INTEGER) . " " .
158  "ORDER BY meta_description_id";
159 
160  $res = $ilDB->query($query);
161  $ids = [];
162  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
163  $ids[] = (int) $row->meta_description_id;
164  }
165  return $ids;
166  }
167 }
$res
Definition: ltiservices.php:69
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getIds(int $a_rbac_id, int $a_obj_id, int $a_parent_id, string $a_parent_type)
setRBACId(int $a_id)
setDescriptionLanguage(ilMDLanguageItem $lng_obj)
toXML(ilXmlWriter $writer)
global $DIC
Definition: feed.php:28
setObjId(int $a_id)
ilMDLanguageItem $description_language
setDescription(string $a_description)
$query
setParentId(int $a_id)
setParentType(string $a_parent_type)
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
setMetaId(int $a_meta_id, bool $a_read_data=true)
setObjType(string $a_type)