ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilMDCopyrightSelectionEntry.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
33{
34 protected $logger = null;
35 protected $db;
36
37 private $entry_id;
38 private $title;
39 private $decription;
40 private $copyright;
41 private $costs;
42 private $language;
44
48 protected $outdated;
49
54 protected $order_position;
55
56
64 public function __construct($a_entry_id)
65 {
66 global $DIC;
67
68
69 $this->logger = $GLOBALS['DIC']->logger()->meta();
70 $this->db = $GLOBALS['DIC']->database();
71 $this->entry_id = $a_entry_id;
72 $this->read();
73 }
74
83 public static function _getEntries()
84 {
85 global $DIC;
86
87 $ilDB = $DIC['ilDB'];
88
89 $query = "SELECT entry_id FROM il_md_cpr_selections ORDER BY is_default DESC, position ASC";
90 $res = $ilDB->query($query);
91
92 $entries = [];
93 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
94 $entries[] = new ilMDCopyrightSelectionEntry($row->entry_id);
95 }
96 return $entries;
97 }
98
104 public static function lookupCopyyrightTitle($a_cp_string)
105 {
106 global $DIC;
107
108 $ilDB = $DIC['ilDB'];
109
110 if (!$entry_id = self::_extractEntryId($a_cp_string)) {
111 return $a_cp_string;
112 }
113
114 $query = "SELECT title FROM il_md_cpr_selections " .
115 "WHERE entry_id = " . $ilDB->quote($entry_id) . " ";
116 $res = $ilDB->query($query);
117 $row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
118 return $row->title ? $row->title : '';
119 }
120
121
130 public static function _lookupCopyright($a_cp_string)
131 {
132 global $DIC;
133
134 $ilDB = $DIC['ilDB'];
135
136 if (!$entry_id = self::_extractEntryId($a_cp_string)) {
137 return $a_cp_string;
138 }
139
140 $query = "SELECT copyright FROM il_md_cpr_selections " .
141 "WHERE entry_id = " . $ilDB->quote($entry_id) . " ";
142 $res = $ilDB->query($query);
143 $row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
144 return $row->copyright ? $row->copyright : '';
145 }
146
152 public static function lookupCopyrightByText($copyright_text)
153 {
154 global $DIC;
155
156 $db = $DIC->database();
157
158 $query = 'SELECT entry_id FROM il_md_cpr_selections ' .
159 'WHERE copyright = ' . $db->quote($copyright_text, 'text');
160 $res = $db->query($query);
161 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
162 return $row->entry_id;
163 }
164 return 0;
165 }
166
176 public static function _extractEntryId($a_cp_string)
177 {
178 if (!preg_match('/il_copyright_entry__([0-9]+)__([0-9]+)/', $a_cp_string, $matches)) {
179 return 0;
180 }
181 if ($matches[1] != IL_INST_ID) {
182 return 0;
183 }
184 return $matches[2] ? $matches[2] : 0;
185 }
186
194 public function getUsage()
195 {
196 return $this->usage;
197 }
198
206 public function getEntryId()
207 {
208 return $this->entry_id;
209 }
210
215 public function getIsDefault()
216 {
217 $query = "SELECT is_default FROM il_md_cpr_selections " .
218 "WHERE entry_id = " . $this->db->quote($this->entry_id, 'integer');
219
220 $res = $this->db->query($query);
221 $row = $res->fetchRow(ilDBConstants::FETCHMODE_DEFAULT);
222
223 return $row['is_default'];
224 }
225
230 public function setOutdated($a_value)
231 {
232 $this->outdated = (int) $a_value;
233 }
234
238 public function getOutdated()
239 {
240 return $this->outdated;
241 }
242
246 public static function getDefault()
247 {
248 global $DIC;
249
250 $db = $DIC->database();
251
252 $query = "SELECT entry_id FROM il_md_cpr_selections " .
253 "WHERE is_default = " . $db->quote(1, 'integer');
254
255 $res = $db->query($query);
256 $row = $res->fetchRow(ilDBConstants::FETCHMODE_DEFAULT);
257
258 return $row['entry_id'];
259 }
260
268 public function setTitle($a_title)
269 {
270 $this->title = $a_title;
271 }
272
279 public function getTitle()
280 {
281 return $this->title;
282 }
283
291 public function setDescription($a_desc)
292 {
293 $this->description = $a_desc;
294 }
295
301 public function getDescription()
302 {
303 return $this->description;
304 }
305
313 public function setCopyright($a_copyright)
314 {
315 $this->copyright = $a_copyright;
316 }
317
323 public function getCopyright()
324 {
325 return $this->copyright;
326 }
327
335 public function setCosts($a_costs)
336 {
337 $this->costs = $a_costs;
338 }
339
345 public function getCosts()
346 {
347 return $this->costs;
348 }
349
357 public function setLanguage($a_lang_key)
358 {
359 $this->language = $a_lang_key;
360 }
361
368 public function getLanguage()
369 {
370 return $this->language;
371 }
372
379 public function setCopyrightAndOtherRestrictions($a_status)
380 {
381 $this->copyright_and_other_restrictions = $a_status;
382 }
383
392 {
393 // Fixed
394 return true;
395 }
396
401 public function setOrderPosition($a_position)
402 {
403 $this->order_position = (int) $a_position;
404 }
405
410 public function getOrderPosition()
411 {
413 }
414
415 protected function getNextOrderPosition()
416 {
417 $query = "SELECT count(entry_id) total FROM il_md_cpr_selections";
418 $res = $this->db->query($query);
419 $row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC);
420
421 return $row['total'] + 1;
422 }
423
429 public function add()
430 {
431 global $DIC;
432
433 $ilDB = $DIC['ilDB'];
434
435 $next_id = $ilDB->nextId('il_md_cpr_selections');
436
437 $ilDB->insert('il_md_cpr_selections', array(
438 'entry_id' => array('integer',$next_id),
439 'title' => array('text',$this->getTitle()),
440 'description' => array('clob',$this->getDescription()),
441 'copyright' => array('clob',$this->getCopyright()),
442 'language' => array('text',$this->getLanguage()),
443 'costs' => array('integer',$this->getCosts()),
444 'cpr_restrictions' => array('integer',$this->getCopyrightAndOtherRestrictions()),
445 'position' => array('integer', $this->getNextOrderPosition())
446 ));
447 $this->entry_id = $next_id;
448 return true;
449 }
450
457 public function update()
458 {
459 global $DIC;
460
461 $ilDB = $DIC['ilDB'];
462
463 $ilDB->update('il_md_cpr_selections', array(
464 'title' => array('text',$this->getTitle()),
465 'description' => array('clob',$this->getDescription()),
466 'copyright' => array('clob',$this->getCopyright()),
467 'language' => array('text',$this->getLanguage()),
468 'costs' => array('integer',$this->getCosts()),
469 'cpr_restrictions' => array('integer',$this->getCopyrightAndOtherRestrictions()),
470 'outdated' => array('integer',$this->getOutdated()),
471 'position' => array('integer',$this->getOrderPosition())
472 ), array(
473 'entry_id' => array('integer',$this->getEntryId())
474 ));
475 return true;
476 }
477
484 public function delete()
485 {
486 global $DIC;
487
488 $ilDB = $DIC['ilDB'];
489
490 $query = "DELETE FROM il_md_cpr_selections " .
491 "WHERE entry_id = " . $this->db->quote($this->getEntryId(), 'integer') . " ";
492 $res = $ilDB->manipulate($query);
493 }
494
502 public function validate()
503 {
504 if (!strlen($this->getTitle())) {
505 return false;
506 }
507 return true;
508 }
509
517 private function read()
518 {
519 global $DIC;
520
521 $ilDB = $DIC['ilDB'];
522
523 $query = "SELECT * FROM il_md_cpr_selections " .
524 "WHERE entry_id = " . $this->db->quote($this->entry_id, 'integer') . " " .
525 "ORDER BY is_default DESC, position ASC ";
526
527 $res = $this->db->query($query);
528 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
529 $this->setTitle($row->title);
530 $this->setDescription($row->description);
531 $this->setCopyright($row->copyright);
532 $this->setLanguage($row->language);
533 $this->setCosts($row->costs);
534 $this->setOutdated($row->outdated);
535 $this->setOrderPosition($row->position);
536 // Fixed
538 }
539
540 $query = "SELECT count(meta_rights_id) used FROM il_meta_rights " .
541 "WHERE description = " . $ilDB->quote('il_copyright_entry__' . IL_INST_ID . '__' . $this->getEntryId(), 'text');
542
543 $res = $this->db->query($query);
544 $row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
545 $this->usage = $row->used;
546 }
547
553 public static function createIdentifier($a_entry_id)
554 {
555 return 'il_copyright_entry__' . IL_INST_ID . '__' . $a_entry_id;
556 }
557}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
An exception for terminatinating execution or to throw for unit testing.
static createIdentifier($a_entry_id)
Create identifier for entry id.
setOrderPosition($a_position)
Set the order position in the table of copyrights.
static _extractEntryId($a_cp_string)
extract entry id
getOrderPosition()
Get the order position in the table of copyrights.
setCopyrightAndOtherRestrictions($a_status)
set copyright and other restrictions
static lookupCopyyrightTitle($a_cp_string)
Lookup copyright title.
getCopyrightAndOtherRestrictions()
get copyright and other restrictions
static _lookupCopyright($a_cp_string)
lookup copyright by entry id
setOutdated($a_value)
Set copyright element as outdated and not usable anymore.
getIsDefault()
Get if the entry is default No setter for this.
language()
Definition: language.php:2
$query
foreach($_POST as $key=> $value) $res
global $ilDB
$DIC
Definition: xapitoken.php:46