Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00034 require_once "./classes/class.ilObject.php";
00035
00036 class ilObjCourseGrouping
00037 {
00038 var $db;
00039
00046 function ilObjCourseGrouping($a_id = 0)
00047 {
00048 global $ilDB;
00049
00050 $this->setType('crsg');
00051 $this->db =& $ilDB;
00052
00053 $this->setId($a_id);
00054
00055 if($a_id)
00056 {
00057 $this->read();
00058 }
00059 }
00060 function setId($a_id)
00061 {
00062 $this->id = $a_id;
00063 }
00064 function getId()
00065 {
00066 return $this->id;
00067 }
00068 function setCourseRefId($a_ref_id)
00069 {
00070 $this->ref_id = $a_ref_id;
00071 }
00072 function getCourseRefId()
00073 {
00074 return $this->ref_id;
00075 }
00076 function setCourseObjId($a_obj_id)
00077 {
00078 $this->obj_id = $a_obj_id;
00079 }
00080 function getCourseObjId()
00081 {
00082 return $this->obj_id;
00083 }
00084 function setType($a_type)
00085 {
00086 $this->type = $a_type;
00087 }
00088 function getType()
00089 {
00090 return $this->type;
00091 }
00092
00093 function setTitle($a_title)
00094 {
00095 $this->title = $a_title;
00096 }
00097 function getTitle()
00098 {
00099 return $this->title;
00100 }
00101 function setDescription($a_desc)
00102 {
00103 $this->description = $a_desc;
00104 }
00105 function getDescription()
00106 {
00107 return $this->description;
00108 }
00109 function setUniqueField($a_uni)
00110 {
00111 $this->unique_field = $a_uni;
00112 }
00113 function getUniqueField()
00114 {
00115 return $this->unique_field;
00116 }
00117
00118 function getCountAssignedCourses()
00119 {
00120 return count($this->getAssignedCourses());
00121 }
00122
00123 function getAssignedCourses()
00124 {
00125 include_once './classes/class.ilConditionHandler.php';
00126
00127 return ilConditionHandler::_getConditionsOfTrigger($this->getType(),$this->getId());
00128 }
00129
00130
00131 function delete()
00132 {
00133 include_once './classes/class.ilConditionHandler.php';
00134
00135 if($this->getId() and $this->getType() === 'crsg')
00136 {
00137 $query = "DELETE FROM object_data WHERE obj_id = '".$this->getId()."'";
00138 $this->db->query($query);
00139
00140 $query = "DELETE FROM crs_groupings ".
00141 "WHERE crs_grp_id = '".$this->getId()."'";
00142 $this->db->query($query);
00143
00144
00145 $condh =& new ilConditionHandler();
00146 $condh->deleteByObjId($this->getId());
00147
00148 return true;
00149 }
00150 return false;
00151 }
00152
00153 function create($a_course_ref_id,$a_course_id)
00154 {
00155 global $ilUser;
00156
00157
00158 $query = "INSERT INTO object_data ".
00159 "(type,title,description,owner,create_date,last_update,import_id) ".
00160 "VALUES ".
00161 "('".$this->type."',".$this->db->quote($this->getTitle()).",'".ilUtil::prepareDBString($this->getDescription())."',".
00162 "'".$ilUser->getId()."',now(),now(),'')";
00163
00164 $this->db->query($query);
00165
00166
00167 $query = "SELECT LAST_INSERT_ID() as last";
00168 $res = $this->db->query($query);
00169 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00170 {
00171 $this->setId($row->last);
00172 }
00173
00174
00175
00176 $query = "INSERT INTO crs_groupings ".
00177 "SET crs_ref_id = '".$a_course_ref_id."', ".
00178 "crs_id = '".$a_course_id."',".
00179 "crs_grp_id = '".$this->getId()."', ".
00180 "unique_field = '".$this->getUniqueField()."'";
00181
00182 $this->db->query($query);
00183
00184 return $this->getId();
00185 }
00186
00187 function update()
00188 {
00189 if($this->getId() and $this->getType() === 'crsg')
00190 {
00191
00192 $query = "UPDATE object_data ".
00193 "SET title = '".ilUtil::prepareDBString($this->getTitle())."', ".
00194 "description = '".ilUtil::prepareDBString($this->getDescription())."' ".
00195 "WHERE obj_id = '".$this->getId()."' ".
00196 "AND type = '".$this->getType()."'";
00197
00198 $this->db->query($query);
00199
00200
00201 $query = "UPDATE crs_groupings ".
00202 "SET unique_field = '".$this->getUniqueField()."' ".
00203 "WHERE crs_grp_id = '".$this->getId()."'";
00204
00205 $this->db->query($query);
00206
00207
00208 $query = "UPDATE conditions ".
00209 "SET value = '".$this->getUniqueField()."' ".
00210 "WHERE trigger_obj_id = '".$this->getId()."' ".
00211 "AND trigger_type = 'crsg'";
00212 $this->db->query($query);
00213
00214 return true;
00215 }
00216 return false;
00217 }
00218
00219 function isAssigned($a_course_id)
00220 {
00221 foreach($this->getAssignedCourses() as $condition_data)
00222 {
00223 if($a_course_id == $condition_data['target_obj_id'])
00224 {
00225 return true;
00226 }
00227 }
00228 return false;
00229 }
00230
00231 function read()
00232 {
00233 $query = "SELECT * FROM object_data ".
00234 "WHERE obj_id = '".$this->getId()."'";
00235
00236 $res = $this->db->query($query);
00237 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00238 {
00239 $this->setTitle($row->title);
00240 $this->setDescription($row->description);
00241 }
00242
00243 $query = "SELECT * FROM crs_groupings ".
00244 "WHERE crs_grp_id = '".$this->getId()."'";
00245 $res = $this->db->query($query);
00246
00247 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00248 {
00249 $this->setUniqueField($row->unique_field);
00250 $this->setCourseRefId($row->crs_ref_id);
00251 $this->setCourseObjId($row->crs_id);
00252 }
00253
00254 return true;
00255 }
00256
00257 function _getAllGroupings($a_crs_ref_id,$a_check_write = true)
00258 {
00259 if($a_check_write)
00260 {
00261 $courses = ilUtil::getObjectsByOperations('crs','write',false);
00262 }
00263 else
00264 {
00265 $courses = ilUtil::getObjectsByOperations('crs','visible',false);
00266 }
00267
00268 $groupings = array();
00269 foreach($courses as $crs_data)
00270 {
00271 if($a_crs_ref_id != $crs_data['ref_id'])
00272 {
00273 $groupings = array_merge($groupings,ilObjCourseGrouping::_getGroupings($crs_data['obj_id']));
00274 }
00275 }
00276 return $groupings ? $groupings : array();
00277 }
00278
00279 function assign($a_crs_ref_id,$a_course_id)
00280 {
00281
00282 $this->__addCondition($this->getCourseRefId(),$this->getCourseObjId());
00283 $this->__addCondition($a_crs_ref_id,$a_course_id);
00284
00285 return true;
00286 }
00287
00288 function deassign($a_crs_ref_id,$a_course_id)
00289 {
00290 include_once './classes/class.ilConditionHandler.php';
00291
00292
00293 $condh =& new ilConditionHandler();
00294
00295
00296 if($this->getCountAssignedCourses() == 2)
00297 {
00298 $condh->deleteByObjId($this->getId());
00299
00300 return true;
00301 }
00302
00303 foreach(ilConditionHandler::_getConditionsOfTrigger('crsg',$this->getId()) as $cond_data)
00304 {
00305
00306 if($cond_data['target_ref_id'] == $a_crs_ref_id and
00307 $cond_data['target_obj_id'] == $a_course_id)
00308 {
00309 $condh->deleteCondition($cond_data['id']);
00310 }
00311 }
00312
00313 return true;
00314
00315 }
00316
00317 function __addCondition($a_target_ref_id,$a_target_obj_id)
00318 {
00319 include_once './classes/class.ilConditionHandler.php';
00320
00321 $tmp_condh =& new ilConditionHandler();
00322 $tmp_condh->enableAutomaticValidation(false);
00323
00324 $tmp_condh->setTargetRefId($a_target_ref_id);
00325 $tmp_condh->setTargetObjId($a_target_obj_id);
00326 $tmp_condh->setTargetType('crs');
00327 $tmp_condh->setTriggerRefId(0);
00328 $tmp_condh->setTriggerObjId($this->getId());
00329 $tmp_condh->setTriggerType('crsg');
00330 $tmp_condh->setOperator('not_member');
00331 $tmp_condh->setValue($this->getUniqueField());
00332
00333 if(!$tmp_condh->checkExists())
00334 {
00335 $tmp_condh->storeCondition();
00336
00337 return true;
00338 }
00339 return false;
00340 }
00341
00342
00343 function _deleteAll($a_course_id)
00344 {
00345 global $ilDB;
00346
00347
00348 foreach($groupings = ilObjCourseGrouping::_getGroupings($a_course_id) as $grouping_id)
00349 {
00350 include_once './classes/class.ilConditionHandler.php';
00351
00352 $condh =& new ilConditionHandler();
00353 $condh->deleteByObjId($grouping_id);
00354 }
00355
00356 $query = "DELETE FROM crs_groupings ".
00357 "WHERE crs_id = '".$a_course_id."'";
00358
00359 $ilDB->query($query);
00360
00361 return true;
00362 }
00363
00364 function _getGroupings($a_course_id)
00365 {
00366 global $ilDB;
00367
00368 $query = "SELECT * FROM crs_groupings ".
00369 "WHERE crs_id = '".$a_course_id."'";
00370
00371 $res = $ilDB->query($query);
00372 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00373 {
00374 $groupings[] = $row->crs_grp_id;
00375 }
00376 return $groupings ? $groupings : array();
00377 }
00378
00379 function _isInGrouping($a_crs_id)
00380 {
00381 include_once './classes/class.ilConditionHandler.php';
00382
00383 foreach(ilConditionHandler::_getConditionsOfTarget($a_crs_id,'crs') as $cond)
00384 {
00385 if($cond['operator'] == 'not_member')
00386 {
00387 return true;
00388 }
00389 }
00390 return false;
00391 }
00392
00393 function _checkCondition($trigger_obj_id,$operator,$value)
00394 {
00395
00396
00397 return true;
00398 }
00399
00400 }
00401 ?>