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
00024
00035 class ilCourseWaitingList
00036 {
00037 var $db = null;
00038 var $course_id = 0;
00039
00040
00041
00042 function ilCourseWaitingList($a_course_id)
00043 {
00044 global $ilDB;
00045
00046 $this->db = $ilDB;
00047 $this->course_id = $a_course_id;
00048
00049 $this->__read();
00050 }
00051
00052 function getCourseId()
00053 {
00054 return $this->course_id;
00055 }
00056
00057 function addToList($a_usr_id)
00058 {
00059 if($this->isOnList($a_usr_id))
00060 {
00061 return false;
00062 }
00063 $query = "INSERT INTO crs_waiting_list ".
00064 "SET obj_id = '".$this->getCourseId()."', ".
00065 "usr_id = '".$a_usr_id."', ".
00066 "sub_time = '".time()."'";
00067
00068 $this->db->query($query);
00069 $this->__read();
00070
00071 return false;
00072 }
00073
00074 function updateSubscriptionTime($a_usr_id,$a_subtime)
00075 {
00076 $query = "UPDATE crs_waiting_list ".
00077 "SET sub_time = '".ilUtil::prepareDBString($a_subtime)."' ".
00078 "WHERE usr_id = '".ilUtil::prepareDBString($a_usr_id)."' ".
00079 "AND obj_id = '".$this->getCourseId()."'";
00080
00081 $this->db->query($query);
00082
00083 return true;
00084 }
00085
00086 function removeFromList($a_usr_id)
00087 {
00088 $query = "DELETE FROM crs_waiting_list ".
00089 " WHERE obj_id = '".$this->getCourseId()."' ".
00090 " AND usr_id = '".$a_usr_id."'";
00091
00092 $this->db->query($query);
00093 $this->__read();
00094
00095 return true;
00096 }
00097
00098 function isOnList($a_usr_id)
00099 {
00100 return isset($this->users[$a_usr_id]) ? true : false;
00101 }
00102
00103 function getCountUsers()
00104 {
00105 return count($this->users);
00106 }
00107
00108 function getPosition($a_usr_id)
00109 {
00110 return isset($this->users[$a_usr_id]) ? $this->users[$a_usr_id]['position'] : -1;
00111 }
00112
00113 function getAllUsers()
00114 {
00115 return $this->users ? $this->users : array();
00116 }
00117
00118 function getUser($a_usr_id)
00119 {
00120 return isset($this->users[$a_usr_id]) ? $this->users[$a_usr_id] : false;
00121 }
00122
00123
00124
00125 function __read()
00126 {
00127 $this->users = array();
00128
00129 $query = "SELECT * FROM crs_waiting_list ".
00130 "WHERE obj_id = '".$this->getCourseId()."' ORDER BY sub_time";
00131
00132 $res = $this->db->query($query);
00133 $counter = 0;
00134 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00135 {
00136 ++$counter;
00137 $this->users[$row->usr_id]['position'] = $counter;
00138 $this->users[$row->usr_id]['time'] = $row->sub_time;
00139 $this->users[$row->usr_id]['usr_id'] = $row->usr_id;
00140
00141 }
00142 return true;
00143 }
00144
00145
00146 function _deleteAll($a_course_id)
00147 {
00148 global $ilDB;
00149
00150 $query = "DELETE FROM crs_waiting_list WHERE obj_id = '".$a_course_id."'";
00151 $ilDB->query($query);
00152
00153 return true;
00154 }
00155 function _deleteUser($a_usr_id)
00156 {
00157 global $ilDB;
00158
00159 $query = "DELETE FROM crs_waiting_list WHERE usr_id = '".$a_usr_id."'";
00160 $ilDB->query($query);
00161
00162 return true;
00163 }
00164 }
00165 ?>