ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups 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_copyright_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 
89  public static function _lookupCopyright($a_cp_string)
90  {
91  global $ilDB;
92 
93  if(!$entry_id = self::_extractEntryId($a_cp_string))
94  {
95  return $a_cp_string;
96  }
97 
98  $query = "SELECT copyright FROM il_md_copyright_selections ".
99  "WHERE entry_id = ".$ilDB->quote($entry_id)." ";
100  $res = $ilDB->query($query);
101  $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
102  return $row->copyright ? $row->copyright : '';
103  }
104 
113  public static function _extractEntryId($a_cp_string)
114  {
115  if(!preg_match('/il_copyright_entry__([0-9]+)__([0-9]+)/',$a_cp_string,$matches))
116  {
117  return 0;
118  }
119  if($matches[1] != IL_INST_ID)
120  {
121  return 0;
122  }
123  return $matches[2] ? $matches[2] : 0;
124  }
125 
133  public function getUsage()
134  {
135  return $this->usage;
136  }
137 
145  public function getEntryId()
146  {
147  return $this->entry_id;
148  }
149 
157  public function setTitle($a_title)
158  {
159  $this->title = $a_title;
160  }
161 
168  public function getTitle()
169  {
170  return $this->title;
171  }
172 
180  public function setDescription($a_desc)
181  {
182  $this->description = $a_desc;
183  }
184 
190  public function getDescription()
191  {
192  return $this->description;
193  }
194 
202  public function setCopyright($a_copyright)
203  {
204  $this->copyright = $a_copyright;
205  }
206 
212  public function getCopyright()
213  {
214  return $this->copyright;
215  }
216 
224  public function setCosts($a_costs)
225  {
226  $this->costs = $a_costs;
227  }
228 
234  public function getCosts()
235  {
236  return $this->costs;
237  }
238 
246  public function setLanguage($a_lang_key)
247  {
248  $this->language = $a_lang_key;
249  }
250 
257  public function getLanguage()
258  {
259  return $this->language;
260  }
261 
268  public function setCopyrightAndOtherRestrictions($a_status)
269  {
270  $this->copyright_and_other_restrictions = $a_status;
271  }
272 
281  {
282  // Fixed
283  return true;
284  }
285 
291  public function add()
292  {
293  $query = "INSERT INTO il_md_copyright_selections ".
294  "SET title = ".$this->db->quote($this->getTitle()).", ".
295  "description = ".$this->db->quote($this->getDescription()).", ".
296  "copyright = ".$this->db->quote($this->getCopyright()).", ".
297  "language = ".$this->db->quote($this->getLanguage()).", ".
298  "costs = ".$this->db->quote($this->getCosts()).", ".
299  "copyright_and_other_restrictions = ".$this->db->quote($this->getCopyrightAndOtherRestrictions())." ";
300  $this->db->query($query);
301  $this->entry_id = $this->db->getLastInsertId();
302 
303  return true;
304  }
305 
312  public function update()
313  {
314  $query = "UPDATE il_md_copyright_selections ".
315  "SET title = ".$this->db->quote($this->getTitle()).", ".
316  "description = ".$this->db->quote($this->getDescription()).", ".
317  "copyright = ".$this->db->quote($this->getCopyright()).", ".
318  "language = ".$this->db->quote($this->getLanguage()).", ".
319  "costs = ".$this->db->quote($this->getCosts()).", ".
320  "copyright_and_other_restrictions = ".$this->db->quote($this->getCopyrightAndOtherRestrictions())." ".
321  "WHERE entry_id = ".$this->db->quote($this->getEntryId())." ";
322 
323  $this->db->query($query);
324  }
325 
332  public function delete()
333  {
334  $query = "DELETE FROM il_md_copyright_selections ".
335  "WHERE entry_id = ".$this->db->quote($this->getEntryId())." ";
336  $this->db->query($query);
337 
338  }
339 
347  public function validate()
348  {
349  if(!strlen($this->getTitle()))
350  {
351  return false;
352  }
353  return true;
354  }
355 
363  private function read()
364  {
365  $query = "SELECT * FROM il_md_copyright_selections ".
366  "WHERE entry_id = ".$this->db->quote($this->entry_id)." ";
367  $res = $this->db->query($query);
368  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
369  {
370  $this->setTitle($row->title);
371  $this->setDescription($row->description);
372  $this->setCopyright($row->copyright);
373  $this->setLanguage($row->language);
374  $this->setCosts($row->costs);
375  // Fixed
377  }
378 
379  $query = "SELECT count(meta_rights_id) as used FROM il_meta_rights ".
380  "WHERE description = 'il_copyright_entry__".IL_INST_ID.'__'.$this->getEntryId()."'";
381  $res = $this->db->query($query);
382  $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
383  $this->usage = $row->used;
384  }
385 }
386 ?>