ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilObjectFactory.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 
21 {
28  function ObjectIdExists($a_obj_id)
29  {
30  global $ilias, $ilDB;
31 
32  $query = "SELECT * FROM object_data ".
33  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer');
34 
35  $res = $ilias->db->query($query);
36 
37  return $res->numRows() ? true : false;
38  }
39 
47  function getObjectsForOwner ($object_type, $owner_id)
48  {
49  global $ilias, $ilDB;
50 
51  $query = "SELECT * FROM object_data,object_reference ".
52  "WHERE object_reference.obj_id = object_data.obj_id ".
53  " AND object_data.type=".$ilDB->quote($object_type,'text').
54  " AND object_data.owner = ".$ilDB->quote($owner_id,'integer');
55  $res = $ilDB->query($query);
56 
57  $obj_ids = array();
58  while($object_rec = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
59  $obj_ids [] = $object_rec["obj_id"];
60  }
61 
62  return $obj_ids;
63 
64  }
65 
72  static function getInstanceByObjId($a_obj_id,$stop_on_error = true)
73  {
74  global $ilias, $objDefinition, $ilDB;
75 
76  // check object id
77  if (!isset($a_obj_id))
78  {
79  $message = "ilObjectFactory::getInstanceByObjId(): No obj_id given!";
80  if ($stop_on_error === true)
81  {
82  $ilias->raiseError($message,$ilias->error_obj->WARNING);
83  exit();
84  }
85  #var_dump("<pre>",$message,"<pre>");
86 
87  return false;
88  }
89 
90  // read object data
91  $q = "SELECT * FROM object_data ".
92  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer');
93  $object_set = $ilias->db->query($q);
94  // check number of records
95  if ($object_set->numRows() == 0)
96  {
97  $message = "ilObjectFactory::getInstanceByObjId(): Object with obj_id: ".$a_obj_id." not found!";
98  if ($stop_on_error === true)
99  {
100  $ilias->raiseError($message,$ilias->error_obj->WARNING);
101  exit();
102  }
103  #var_dump("<pre>",$message,"<pre>");
104  return false;
105  }
106 
107  $object_rec = $object_set->fetchRow(ilDBConstants::FETCHMODE_ASSOC);
108  $class_name = "ilObj".$objDefinition->getClassName($object_rec["type"]);
109 
110  // check class
111  if ($class_name == "ilObj")
112  {
113  $message = "ilObjectFactory::getInstanceByObjId(): Not able to determine object ".
114  "class for type".$object_rec["type"].".";
115  if ($stop_on_error === true)
116  {
117  $ilias->raiseError($message,$ilias->error_obj->WARNING);
118  exit();
119  }
120  return false;
121  }
122 
123  // get location
124  $location = $objDefinition->getLocation($object_rec["type"]);
125 
126  // create instance
127  include_once($location."/class.".$class_name.".php");
128  $obj = new $class_name(0, false); // this avoids reading of data
129  $obj->setId($a_obj_id);
130  $obj->read();
131 
132  return $obj;
133  }
134 
135 
142  static function getInstanceByRefId($a_ref_id,$stop_on_error = true)
143  {
144  global $ilias, $objDefinition, $ilDB;
145 
146  // check reference id
147  if (!isset($a_ref_id))
148  {
149  if ($stop_on_error === true)
150  {
151  $message = "ilObjectFactory::getInstanceByRefId(): No ref_id given!";
152  $ilias->raiseError($message,$ilias->error_obj->WARNING);
153  exit();
154  }
155 
156  return false;
157  }
158 
159  // read object data
160 
161  $query = "SELECT * FROM object_data,object_reference ".
162  "WHERE object_reference.obj_id = object_data.obj_id ".
163  "AND object_reference.ref_id = ".$ilDB->quote($a_ref_id,'integer');
164  $object_set = $ilDB->query($query);
165 
166  // check number of records
167  if ($object_set->numRows() == 0)
168  {
169  if ($stop_on_error === true)
170  {
171  $message = "ilObjectFactory::getInstanceByRefId(): Object with ref_id ".$a_ref_id." not found!";
172  $ilias->raiseError($message,$ilias->error_obj->WARNING);
173  exit();
174  }
175 
176  return false;
177  }
178 
179  $object_rec = $object_set->fetchRow(ilDBConstants::FETCHMODE_ASSOC);
180  $class_name = "ilObj".$objDefinition->getClassName($object_rec["type"]);
181 
182  // check class
183  if ($class_name == "ilObj")
184  {
185  if ($stop_on_error === true)
186  {
187  $message = "ilObjectFactory::getInstanceByRefId(): Not able to determine object ".
188  "class for type".$object_rec["type"].".";
189  $ilias->raiseError($message,$ilias->error_obj->WARNING);
190  exit();
191  }
192 
193  return false;
194  }
195 
196  // get location
197  $location = $objDefinition->getLocation($object_rec["type"]);
198 
199  // create instance
200  include_once($location."/class.".$class_name.".php");
201  $obj = new $class_name(0, false); // this avoids reading of data
202  $obj->setId($object_rec["obj_id"]);
203  $obj->setRefId($a_ref_id);
204  $obj->read();
205  return $obj;
206  }
207 
216  public static function getTypeByRefId($a_ref_id, $stop_on_error = true)
217  {
218  global $ilias, $objDefinition, $ilDB;
219 
220  // check reference id
221  if (!isset($a_ref_id))
222  {
223  if ($stop_on_error === true)
224  {
225  $message = "ilObjectFactory::getTypeByRefId(): No ref_id given!";
226  $ilias->raiseError($message,$ilias->error_obj->WARNING);
227  exit();
228  }
229 
230  return false;
231  }
232 
233  // read object data
234  $q = "SELECT * FROM object_data ".
235  "LEFT JOIN object_reference ON object_data.obj_id=object_reference.obj_id ".
236  "WHERE object_reference.ref_id=".$ilDB->quote($a_ref_id,'integer');
237  $object_set = $ilias->db->query($q);
238 
239  if ($object_set->numRows() == 0)
240  {
241  if ($stop_on_error === true)
242  {
243  $message = "ilObjectFactory::getTypeByRefId(): Object with ref_id ".$a_ref_id." not found!";
244  $ilias->raiseError($message,$ilias->error_obj->WARNING);
245  exit();
246  }
247 
248  return false;
249  }
250 
251  $object_rec = $object_set->fetchRow(ilDBConstants::FETCHMODE_ASSOC);
252  return $object_rec["type"];
253  }
254 
260  public static function getClassByType($a_obj_type)
261  {
262  global $objDefinition;
263 
264  $location = $objDefinition->getLocation($a_obj_type);
265  $class_name = "ilObj".$objDefinition->getClassName($a_obj_type);
266 
267  // create instance
268  include_once($location."/class.".$class_name.".php");
269  return $class_name;
270  }
271 }
272 ?>
static getClassByType($a_obj_type)
Get class by type.
ObjectIdExists($a_obj_id)
check if obj_id exists.
Class ilObjectFactory.
$location
Definition: buildRTE.php:44
getObjectsForOwner($object_type, $owner_id)
returns all objects of an owner, filtered by type, objects are not deleted!
static getTypeByRefId($a_ref_id, $stop_on_error=true)
get object type by reference id
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
Create styles array
The data for the language used.
global $ilDB
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id