ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
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 
187  public static function isEntry($a_cp_string) : bool
188  {
189  if (!preg_match('/il_copyright_entry__([0-9]+)__([0-9]+)/', $a_cp_string)) {
190  return false;
191  }
192  return true;
193  }
194 
202  public function getUsage()
203  {
204  return $this->usage;
205  }
206 
214  public function getEntryId()
215  {
216  return $this->entry_id;
217  }
218 
223  public function getIsDefault()
224  {
225  $query = "SELECT is_default FROM il_md_cpr_selections " .
226  "WHERE entry_id = " . $this->db->quote($this->entry_id, 'integer');
227 
228  $res = $this->db->query($query);
229  $row = $res->fetchRow(ilDBConstants::FETCHMODE_DEFAULT);
230 
231  return $row['is_default'];
232  }
233 
238  public function setOutdated($a_value)
239  {
240  $this->outdated = (int) $a_value;
241  }
242 
246  public function getOutdated()
247  {
248  return $this->outdated;
249  }
250 
254  public static function getDefault()
255  {
256  global $DIC;
257 
258  $db = $DIC->database();
259 
260  $query = "SELECT entry_id FROM il_md_cpr_selections " .
261  "WHERE is_default = " . $db->quote(1, 'integer');
262 
263  $res = $db->query($query);
264  $row = $res->fetchRow(ilDBConstants::FETCHMODE_DEFAULT);
265 
266  return $row['entry_id'];
267  }
268 
276  public function setTitle($a_title)
277  {
278  $this->title = $a_title;
279  }
280 
287  public function getTitle()
288  {
289  return $this->title;
290  }
291 
299  public function setDescription($a_desc)
300  {
301  $this->description = $a_desc;
302  }
303 
309  public function getDescription()
310  {
311  return $this->description;
312  }
313 
321  public function setCopyright($a_copyright)
322  {
323  $this->copyright = $a_copyright;
324  }
325 
331  public function getCopyright()
332  {
333  return $this->copyright;
334  }
335 
343  public function setCosts($a_costs)
344  {
345  $this->costs = $a_costs;
346  }
347 
353  public function getCosts()
354  {
355  return $this->costs;
356  }
357 
365  public function setLanguage($a_lang_key)
366  {
367  $this->language = $a_lang_key;
368  }
369 
376  public function getLanguage()
377  {
378  return $this->language;
379  }
380 
387  public function setCopyrightAndOtherRestrictions($a_status)
388  {
389  $this->copyright_and_other_restrictions = $a_status;
390  }
391 
400  {
401  // Fixed
402  return true;
403  }
404 
409  public function setOrderPosition($a_position)
410  {
411  $this->order_position = (int) $a_position;
412  }
413 
418  public function getOrderPosition()
419  {
420  return $this->order_position;
421  }
422 
423  protected function getNextOrderPosition()
424  {
425  $query = "SELECT count(entry_id) total FROM il_md_cpr_selections";
426  $res = $this->db->query($query);
427  $row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC);
428 
429  return $row['total'] + 1;
430  }
431 
437  public function add()
438  {
439  global $DIC;
440 
441  $ilDB = $DIC['ilDB'];
442 
443  $next_id = $ilDB->nextId('il_md_cpr_selections');
444 
445  $ilDB->insert('il_md_cpr_selections', array(
446  'entry_id' => array('integer',$next_id),
447  'title' => array('text',$this->getTitle()),
448  'description' => array('clob',$this->getDescription()),
449  'copyright' => array('clob',$this->getCopyright()),
450  'language' => array('text',$this->getLanguage()),
451  'costs' => array('integer',$this->getCosts()),
452  'cpr_restrictions' => array('integer',$this->getCopyrightAndOtherRestrictions()),
453  'position' => array('integer', $this->getNextOrderPosition())
454  ));
455  $this->entry_id = $next_id;
456  return true;
457  }
458 
465  public function update()
466  {
467  global $DIC;
468 
469  $ilDB = $DIC['ilDB'];
470 
471  $ilDB->update('il_md_cpr_selections', array(
472  'title' => array('text',$this->getTitle()),
473  'description' => array('clob',$this->getDescription()),
474  'copyright' => array('clob',$this->getCopyright()),
475  'language' => array('text',$this->getLanguage()),
476  'costs' => array('integer',$this->getCosts()),
477  'cpr_restrictions' => array('integer',$this->getCopyrightAndOtherRestrictions()),
478  'outdated' => array('integer',$this->getOutdated()),
479  'position' => array('integer',$this->getOrderPosition())
480  ), array(
481  'entry_id' => array('integer',$this->getEntryId())
482  ));
483  return true;
484  }
485 
492  public function delete()
493  {
494  global $DIC;
495 
496  $ilDB = $DIC['ilDB'];
497 
498  $query = "DELETE FROM il_md_cpr_selections " .
499  "WHERE entry_id = " . $this->db->quote($this->getEntryId(), 'integer') . " ";
500  $res = $ilDB->manipulate($query);
501  }
502 
510  public function validate()
511  {
512  if (!strlen($this->getTitle())) {
513  return false;
514  }
515  return true;
516  }
517 
525  private function read()
526  {
527  global $DIC;
528 
529  $ilDB = $DIC['ilDB'];
530 
531  $query = "SELECT * FROM il_md_cpr_selections " .
532  "WHERE entry_id = " . $this->db->quote($this->entry_id, 'integer') . " " .
533  "ORDER BY is_default DESC, position ASC ";
534 
535  $res = $this->db->query($query);
536  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
537  $this->setTitle($row->title);
538  $this->setDescription($row->description);
539  $this->setCopyright($row->copyright);
540  $this->setLanguage($row->language);
541  $this->setCosts($row->costs);
542  $this->setOutdated($row->outdated);
543  $this->setOrderPosition($row->position);
544  // Fixed
546  }
547 
548  $query = "SELECT count(meta_rights_id) used FROM il_meta_rights " .
549  "WHERE description = " . $ilDB->quote('il_copyright_entry__' . IL_INST_ID . '__' . $this->getEntryId(), 'text');
550 
551  $res = $this->db->query($query);
552  $row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
553  $this->usage = $row->used;
554  }
555 
561  public static function createIdentifier($a_entry_id)
562  {
563  return 'il_copyright_entry__' . IL_INST_ID . '__' . $a_entry_id;
564  }
565 }
const IL_INST_ID
Definition: constants.php:38
getCopyrightAndOtherRestrictions()
get copyright and other restrictions
setCopyrightAndOtherRestrictions($a_status)
set copyright and other restrictions
setOrderPosition($a_position)
Set the order position in the table of copyrights.
foreach($_POST as $key=> $value) $res
getOrderPosition()
Get the order position in the table of copyrights.
global $DIC
Definition: goto.php:24
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
static _extractEntryId($a_cp_string)
extract entry id
$query
static _lookupCopyright($a_cp_string)
lookup copyright by entry id
static createIdentifier($a_entry_id)
Create identifier for entry id.
setOutdated($a_value)
Set copyright element as outdated and not usable anymore.
global $ilDB
static lookupCopyyrightTitle($a_cp_string)
Lookup copyright title.
getIsDefault()
Get if the entry is default No setter for this.
language()
Definition: language.php:2