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 class ilCourseStart
00035 {
00036 var $db;
00037
00038 var $ref_id;
00039 var $id;
00040 var $start_objs = array();
00041
00048 function ilCourseStart($a_course_ref_id,$a_course_obj_id)
00049 {
00050 global $ilDB;
00051
00052 $this->db =& $ilDB;
00053
00054 $this->ref_id = $a_course_ref_id;
00055 $this->id = $a_course_obj_id;
00056
00057 $this->__read();
00058 }
00059 function setId($a_id)
00060 {
00061 $this->id = $a_id;
00062 }
00063 function getId()
00064 {
00065 return $this->id;
00066 }
00067 function setRefId($a_ref_id)
00068 {
00069 $this->ref_id = $a_ref_id;
00070 }
00071 function getRefId()
00072 {
00073 return $this->ref_id;
00074 }
00075 function getStartObjects()
00076 {
00077 return $this->start_objs ? $this->start_objs : array();
00078 }
00079
00080 function delete($a_crs_start_id)
00081 {
00082 $query = "DELETE FROM crs_start ".
00083 "WHERE crs_start_id = '".$a_crs_start_id."' ".
00084 "AND crs_id = '".$this->getId()."'";
00085
00086 $this->db->query($query);
00087
00088 return true;
00089 }
00090
00091 function exists($a_item_ref_id)
00092 {
00093 $query = "SELECT * FROM crs_start ".
00094 "WHERE crs_id = '".$this->getId()."' ".
00095 "AND item_ref_id = '".$a_item_ref_id."'";
00096
00097 $res = $this->db->query($query);
00098
00099 return $res->numRows() ? true : false;
00100 }
00101
00102 function add($a_item_ref_id)
00103 {
00104 if($a_item_ref_id)
00105 {
00106 $query = "INSERT INTO crs_start ".
00107 "SET crs_id = '".$this->getId()."', ".
00108 "item_ref_id = '".$a_item_ref_id."'";
00109
00110 $this->db->query($query);
00111
00112 return true;
00113 }
00114 return false;
00115 }
00116
00117 function __deleteAll()
00118 {
00119 $query = "DELETE FROM crs_start ".
00120 "WHERE crs_id = '".$this->getId()."'";
00121
00122
00123 $this->db->query($query);
00124
00125 return true;
00126 }
00127
00128 function getPossibleStarters(&$item_obj)
00129 {
00130 foreach($item_obj->getItems() as $node)
00131 {
00132 switch($node['type'])
00133 {
00134 case 'lm':
00135 case 'sahs':
00136 case 'svy':
00137 case 'tst':
00138 $poss_items[] = $node['ref_id'];
00139 break;
00140 }
00141 }
00142 return $poss_items ? $poss_items : array();
00143 }
00144
00145 function allFullfilled($user_id)
00146 {
00147 foreach($this->getStartObjects() as $item)
00148 {
00149 if(!$this->isFullfilled($user_id,$item['item_ref_id']))
00150 {
00151 return false;
00152 }
00153 }
00154 return true;
00155 }
00156
00157
00158 function isFullfilled($user_id,$item_id)
00159 {
00160 global $ilObjDataCache;
00161
00162 include_once './course/classes/class.ilCourseLMHistory.php';
00163 $lm_continue =& new ilCourseLMHistory($this->getRefId(),$user_id);
00164 $continue_data = $lm_continue->getLMHistory();
00165
00166 $obj_id = $ilObjDataCache->lookupObjId($item_id);
00167 $type = $ilObjDataCache->lookupType($obj_id);
00168
00169 switch($type)
00170 {
00171 case 'tst':
00172 include_once './assessment/classes/class.ilObjTestAccess.php';
00173
00174 if(!ilObjTestAccess::_checkCondition($obj_id,'finished',''))
00175 {
00176 return false;
00177 }
00178 break;
00179 case 'svy':
00180 include_once './survey/classes/class.ilObjSurveyAccess.php';
00181 if(!ilObjSurveyAccess::_lookupFinished($obj_id, $user_id))
00182 {
00183 return false;
00184 }
00185 break;
00186 case 'sahs':
00187 include_once 'Services/Tracking/classes/class.ilLPStatusWrapper.php';
00188 $completed = ilLPStatusWrapper::_getCompleted($obj_id);
00189 if(!in_array($user_id,$completed))
00190 {
00191 return false;
00192 }
00193 break;
00194
00195 default:
00196 if(!isset($continue_data[$item_id]))
00197 {
00198 return false;
00199 }
00200 }
00201 return true;
00202 }
00203
00204
00205
00206 function __read()
00207 {
00208 global $tree;
00209
00210 $this->start_objs = array();
00211
00212 $query = "SELECT * FROM crs_start ".
00213 "WHERE crs_id = '".$this->getId()."'";
00214
00215 $res = $this->db->query($query);
00216 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00217 {
00218 if($tree->isInTree($row->item_ref_id))
00219 {
00220 $this->start_objs[$row->crs_start_id]['item_ref_id'] = $row->item_ref_id;
00221 }
00222 else
00223 {
00224 $this->delete($row->item_ref_id);
00225 }
00226 }
00227 return true;
00228 }
00229
00230
00231
00232
00233 }
00234 ?>