ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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 $db;
35 
36  private $entry_id;
37  private $title;
38  private $decription;
39  private $copyright;
40  private $costs;
41  private $language;
43 
44 
52  public function __construct($a_entry_id)
53  {
54  global $ilDB;
55 
56  $this->db = $ilDB;
57  $this->entry_id = $a_entry_id;
58  $this->read();
59  }
60 
68  public static function _getEntries()
69  {
70  global $ilDB;
71 
72  $query = "SELECT entry_id FROM il_md_cpr_selections ";
73  $res = $ilDB->query($query);
74  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
75  {
76  $entries[] = new ilMDCopyrightSelectionEntry($row->entry_id);
77  }
78  return $entries ? $entries : array();
79  }
80 
86  public static function lookupCopyyrightTitle($a_cp_string)
87  {
88  global $ilDB;
89 
90  if(!$entry_id = self::_extractEntryId($a_cp_string))
91  {
92  return $a_cp_string;
93  }
94 
95  $query = "SELECT title FROM il_md_cpr_selections ".
96  "WHERE entry_id = ".$ilDB->quote($entry_id)." ";
97  $res = $ilDB->query($query);
98  $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
99  return $row->title ? $row->title : '';
100  }
101 
102 
111  public static function _lookupCopyright($a_cp_string)
112  {
113  global $ilDB;
114 
115  if(!$entry_id = self::_extractEntryId($a_cp_string))
116  {
117  return $a_cp_string;
118  }
119 
120  $query = "SELECT copyright FROM il_md_cpr_selections ".
121  "WHERE entry_id = ".$ilDB->quote($entry_id)." ";
122  $res = $ilDB->query($query);
123  $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
124  return $row->copyright ? $row->copyright : '';
125  }
126 
135  public static function _extractEntryId($a_cp_string)
136  {
137  if(!preg_match('/il_copyright_entry__([0-9]+)__([0-9]+)/',$a_cp_string,$matches))
138  {
139  return 0;
140  }
141  if($matches[1] != IL_INST_ID)
142  {
143  return 0;
144  }
145  return $matches[2] ? $matches[2] : 0;
146  }
147 
155  public function getUsage()
156  {
157  return $this->usage;
158  }
159 
167  public function getEntryId()
168  {
169  return $this->entry_id;
170  }
171 
179  public function setTitle($a_title)
180  {
181  $this->title = $a_title;
182  }
183 
190  public function getTitle()
191  {
192  return $this->title;
193  }
194 
202  public function setDescription($a_desc)
203  {
204  $this->description = $a_desc;
205  }
206 
212  public function getDescription()
213  {
214  return $this->description;
215  }
216 
224  public function setCopyright($a_copyright)
225  {
226  $this->copyright = $a_copyright;
227  }
228 
234  public function getCopyright()
235  {
236  return $this->copyright;
237  }
238 
246  public function setCosts($a_costs)
247  {
248  $this->costs = $a_costs;
249  }
250 
256  public function getCosts()
257  {
258  return $this->costs;
259  }
260 
268  public function setLanguage($a_lang_key)
269  {
270  $this->language = $a_lang_key;
271  }
272 
279  public function getLanguage()
280  {
281  return $this->language;
282  }
283 
290  public function setCopyrightAndOtherRestrictions($a_status)
291  {
292  $this->copyright_and_other_restrictions = $a_status;
293  }
294 
303  {
304  // Fixed
305  return true;
306  }
307 
313  public function add()
314  {
315  global $ilDB;
316 
317  $next_id = $ilDB->nextId('il_md_cpr_selections');
318 
319  $ilDB->insert('il_md_cpr_selections',array(
320  'entry_id' => array('integer',$next_id),
321  'title' => array('text',$this->getTitle()),
322  'description' => array('clob',$this->getDescription()),
323  'copyright' => array('clob',$this->getCopyright()),
324  'language' => array('text',$this->getLanguage()),
325  'costs' => array('integer',$this->getCosts()),
326  'cpr_restrictions' => array('integer',$this->getCopyrightAndOtherRestrictions())
327  ));
328  $this->entry_id = $next_id;
329  return true;
330  }
331 
338  public function update()
339  {
340  global $ilDB;
341 
342  $ilDB->update('il_md_cpr_selections',array(
343  'title' => array('text',$this->getTitle()),
344  'description' => array('clob',$this->getDescription()),
345  'copyright' => array('clob',$this->getCopyright()),
346  'language' => array('text',$this->getLanguage()),
347  'costs' => array('integer',$this->getCosts()),
348  'cpr_restrictions' => array('integer',$this->getCopyrightAndOtherRestrictions())
349  ),array(
350  'entry_id' => array('integer',$this->getEntryId())
351  ));
352  return true;
353  }
354 
361  public function delete()
362  {
363  global $ilDB;
364 
365  $query = "DELETE FROM il_md_cpr_selections ".
366  "WHERE entry_id = ".$this->db->quote($this->getEntryId() ,'integer')." ";
367  $res = $ilDB->manipulate($query);
368 
369  }
370 
378  public function validate()
379  {
380  if(!strlen($this->getTitle()))
381  {
382  return false;
383  }
384  return true;
385  }
386 
394  private function read()
395  {
396  global $ilDB;
397 
398  $query = "SELECT * FROM il_md_cpr_selections ".
399  "WHERE entry_id = ".$this->db->quote($this->entry_id ,'integer')." ";
400  $res = $this->db->query($query);
401  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
402  {
403  $this->setTitle($row->title);
404  $this->setDescription($row->description);
405  $this->setCopyright($row->copyright);
406  $this->setLanguage($row->language);
407  $this->setCosts($row->costs);
408  // Fixed
410  }
411 
412  $desc = $ilDB->quote('il_copyright_entry__'.IL_INST_ID.'__'.$this->getEntryId(),'text');
413  $query = "SELECT count(meta_rights_id) used FROM il_meta_rights ".
414  "WHERE description = ".$ilDB->quote($desc ,'text');
415  $res = $this->db->query($query);
416  $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
417  $this->usage = $row->used;
418  }
419 }
420 ?>
getCopyrightAndOtherRestrictions()
get copyright and other restrictions
setCopyrightAndOtherRestrictions($a_status)
set copyright and other restrictions
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
static _extractEntryId($a_cp_string)
extract entry id
static _lookupCopyright($a_cp_string)
lookup copyright by entry id
global $ilDB
static lookupCopyyrightTitle($a_cp_string)
Lookup copyright title.