ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCustomBlock.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 
24 
32 {
33 
34  protected $id;
35  protected $context_obj_id;
36  protected $context_obj_type;
39  protected $type;
40  protected $title;
41 
47  public function __construct($a_id = 0)
48  {
49  if ($a_id > 0)
50  {
51  $this->setId($a_id);
52  $this->read();
53  }
54 
55  }
56 
62  public function setId($a_id)
63  {
64  $this->id = $a_id;
65  }
66 
72  public function getId()
73  {
74  return $this->id;
75  }
76 
82  public function setContextObjId($a_context_obj_id)
83  {
84  $this->context_obj_id = $a_context_obj_id;
85  }
86 
92  public function getContextObjId()
93  {
94  return $this->context_obj_id;
95  }
96 
102  public function setContextObjType($a_context_obj_type)
103  {
104  $this->context_obj_type = $a_context_obj_type;
105  }
106 
112  public function getContextObjType()
113  {
115  }
116 
122  public function setContextSubObjId($a_context_sub_obj_id)
123  {
124  $this->context_sub_obj_id = $a_context_sub_obj_id;
125  }
126 
132  public function getContextSubObjId()
133  {
135  }
136 
142  public function setContextSubObjType($a_context_sub_obj_type)
143  {
144  $this->context_sub_obj_type = $a_context_sub_obj_type;
145  }
146 
152  public function getContextSubObjType()
153  {
155  }
156 
162  public function setType($a_type)
163  {
164  $this->type = $a_type;
165  }
166 
172  public function getType()
173  {
174  return $this->type;
175  }
176 
182  public function setTitle($a_title)
183  {
184  $this->title = $a_title;
185  }
186 
192  public function getTitle()
193  {
194  return $this->title;
195  }
196 
201  public function create()
202  {
203  global $ilDB;
204 
205  $query = "INSERT INTO il_custom_block (".
206  " context_obj_id".
207  ", context_obj_type".
208  ", context_sub_obj_id".
209  ", context_sub_obj_type".
210  ", type".
211  ", title".
212  " ) VALUES (".
213  $ilDB->quote($this->getContextObjId())
214  .",".$ilDB->quote($this->getContextObjType())
215  .",".$ilDB->quote($this->getContextSubObjId())
216  .",".$ilDB->quote($this->getContextSubObjType())
217  .",".$ilDB->quote($this->getType())
218  .",".$ilDB->quote($this->getTitle()).")";
219  $ilDB->query($query);
220  $this->setId($ilDB->getLastInsertId());
221 
222 
223  }
224 
229  public function read()
230  {
231  global $ilDB;
232 
233  $query = "SELECT * FROM il_custom_block WHERE id = ".
234  $ilDB->quote($this->getId());
235  $set = $ilDB->query($query);
236  $rec = $set->fetchRow(DB_FETCHMODE_ASSOC);
237 
238  $this->setContextObjId($rec["context_obj_id"]);
239  $this->setContextObjType($rec["context_obj_type"]);
240  $this->setContextSubObjId($rec["context_sub_obj_id"]);
241  $this->setContextSubObjType($rec["context_sub_obj_type"]);
242  $this->setType($rec["type"]);
243  $this->setTitle($rec["title"]);
244 
245  }
246 
251  public function update()
252  {
253  global $ilDB;
254 
255  $query = "UPDATE il_custom_block SET ".
256  " context_obj_id = ".$ilDB->quote($this->getContextObjId()).
257  ", context_obj_type = ".$ilDB->quote($this->getContextObjType()).
258  ", context_sub_obj_id = ".$ilDB->quote($this->getContextSubObjId()).
259  ", context_sub_obj_type = ".$ilDB->quote($this->getContextSubObjType()).
260  ", type = ".$ilDB->quote($this->getType()).
261  ", title = ".$ilDB->quote($this->getTitle()).
262  " WHERE id = ".$ilDB->quote($this->getId());
263 
264  $ilDB->query($query);
265 
266  }
267 
272  public function delete()
273  {
274  global $ilDB;
275 
276  $query = "DELETE FROM il_custom_block".
277  " WHERE id = ".$ilDB->quote($this->getId());
278 
279  $ilDB->query($query);
280 
281  }
282 
287  public function querygetBlocksForContext()
288  {
289  global $ilDB;
290 
291  $query = "SELECT id, context_obj_id, context_obj_type, context_sub_obj_id, context_sub_obj_type, type, title ".
292  "FROM il_custom_block ".
293  "WHERE ".
294  "context_obj_id = ".$ilDB->quote($this->getContextObjId()).
295  " AND context_obj_type = ".$ilDB->quote($this->getContextObjType()).
296  " AND context_sub_obj_id = ".$ilDB->quote($this->getContextSubObjId()).
297  " AND context_sub_obj_type = ".$ilDB->quote($this->getContextSubObjType())."";
298 
299  $set = $ilDB->query($query);
300  $result = array();
301  while($rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
302  {
303  $result[] = $rec;
304  }
305 
306  return $result;
307 
308  }
309 
314  public function queryBlocksForContext()
315  {
316  global $ilDB;
317 
318  $query = "SELECT id, context_obj_id, context_obj_type, context_sub_obj_id, context_sub_obj_type, type, title ".
319  "FROM il_custom_block ".
320  "WHERE ".
321  "context_obj_id = ".$ilDB->quote($this->getContextObjId()).
322  " AND context_obj_type = ".$ilDB->quote($this->getContextObjType()).
323  " AND context_sub_obj_id = ".$ilDB->quote($this->getContextSubObjId()).
324  " AND context_sub_obj_type = ".$ilDB->quote($this->getContextSubObjType())."";
325 
326  $set = $ilDB->query($query);
327  $result = array();
328  while($rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
329  {
330  $result[] = $rec;
331  }
332 
333  return $result;
334 
335  }
336 
341  public function queryTitleForId()
342  {
343  global $ilDB;
344 
345  $query = "SELECT id ".
346  "FROM il_custom_block ".
347  "WHERE "."";
348 
349  $set = $ilDB->query($query);
350  $result = array();
351  while($rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
352  {
353  $result[] = $rec;
354  }
355 
356  return $result;
357 
358  }
359 
364  public function queryCntBlockForContext()
365  {
366  global $ilDB;
367 
368  $query = "SELECT count(*) as cnt ".
369  "FROM il_custom_block ".
370  "WHERE ".
371  "context_obj_id = ".$ilDB->quote($this->getContextObjId()).
372  " AND context_obj_type = ".$ilDB->quote($this->getContextObjType()).
373  " AND context_sub_obj_id = ".$ilDB->quote($this->getContextSubObjId()).
374  " AND context_sub_obj_type = ".$ilDB->quote($this->getContextSubObjType()).
375  " AND type = ".$ilDB->quote($this->getType())."";
376 
377  $set = $ilDB->query($query);
378  $result = array();
379  while($rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
380  {
381  $result[] = $rec;
382  }
383 
384  return $result;
385 
386  }
387 
388 
389 }
390 ?>