ILIAS  eassessment Revision 61809
 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_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 
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_cpr_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  global $ilDB;
294 
295  $next_id = $ilDB->nextId('il_md_cpr_selections');
296 
297  $ilDB->insert('il_md_cpr_selections',array(
298  'entry_id' => array('integer',$next_id),
299  'title' => array('text',$this->getTitle()),
300  'description' => array('clob',$this->getDescription()),
301  'copyright' => array('clob',$this->getCopyright()),
302  'language' => array('text',$this->getLanguage()),
303  'costs' => array('integer',$this->getCosts()),
304  'cpr_restrictions' => array('integer',$this->getCopyrightAndOtherRestrictions())
305  ));
306  $this->entry_id = $next_id;
307  return true;
308  }
309 
316  public function update()
317  {
318  global $ilDB;
319 
320  $ilDB->update('il_md_cpr_selections',array(
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  ),array(
328  'entry_id' => array('integer',$this->getEntryId())
329  ));
330  return true;
331  }
332 
339  public function delete()
340  {
341  global $ilDB;
342 
343  $query = "DELETE FROM il_md_cpr_selections ".
344  "WHERE entry_id = ".$this->db->quote($this->getEntryId() ,'integer')." ";
345  $res = $ilDB->manipulate($query);
346 
347  }
348 
356  public function validate()
357  {
358  if(!strlen($this->getTitle()))
359  {
360  return false;
361  }
362  return true;
363  }
364 
372  private function read()
373  {
374  global $ilDB;
375 
376  $query = "SELECT * FROM il_md_cpr_selections ".
377  "WHERE entry_id = ".$this->db->quote($this->entry_id ,'integer')." ";
378  $res = $this->db->query($query);
379  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
380  {
381  $this->setTitle($row->title);
382  $this->setDescription($row->description);
383  $this->setCopyright($row->copyright);
384  $this->setLanguage($row->language);
385  $this->setCosts($row->costs);
386  // Fixed
388  }
389 
390  $desc = $ilDB->quote('il_copyright_entry__'.IL_INST_ID.'__'.$this->getEntryId(),'text');
391  $query = "SELECT count(meta_rights_id) used FROM il_meta_rights ".
392  "WHERE description = ".$ilDB->quote($desc ,'text');
393  $res = $this->db->query($query);
394  $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
395  $this->usage = $row->used;
396  }
397 }
398 ?>