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
00036 class ilLPMarks
00037 {
00038 var $db = null;
00039
00040 var $obj_id = null;
00041 var $usr_id = null;
00042 var $obj_type = null;
00043
00044 var $completed = false;
00045 var $comment = '';
00046 var $mark = '';
00047
00048 var $has_entry = false;
00049
00050
00051
00052 function ilLPMarks($a_obj_id,$a_usr_id)
00053 {
00054 global $ilObjDataCache,$ilDB;
00055
00056 $this->db =& $ilDB;
00057
00058 $this->obj_id = $a_obj_id;
00059 $this->usr_id = $a_usr_id;
00060 $this->obj_type = $ilObjDataCache->lookupType($this->obj_id);
00061
00062 $this->__read();
00063 }
00064
00065 function getUserId()
00066 {
00067 return $this->usr_id;
00068 }
00069
00070 function setMark($a_mark)
00071 {
00072 $this->mark = $a_mark;
00073 }
00074 function getMark()
00075 {
00076 return $this->mark;
00077 }
00078 function setComment($a_comment)
00079 {
00080 $this->comment = $a_comment;
00081 }
00082 function getComment()
00083 {
00084 return $this->comment;
00085 }
00086 function setCompleted($a_status)
00087 {
00088 $this->completed = (bool) $a_status;
00089 }
00090 function getCompleted()
00091 {
00092 return $this->completed;
00093 }
00094
00095 function getObjId()
00096 {
00097 return (int) $this->obj_id;
00098 }
00099
00100 function update()
00101 {
00102 if(!$this->has_entry)
00103 {
00104 $this->__add();
00105 }
00106 $query = "UPDATE ut_lp_marks ".
00107 "SET mark = '".ilUtil::prepareDBString($this->getMark())."', ".
00108 "comment = '".ilUtil::prepareDBString($this->getComment())."', ".
00109 "completed = '".(int) $this->getCompleted()."' ".
00110 "WHERE obj_id = '".$this->getObjId()."' ".
00111 "AND usr_id = '".$this->getUserId()."'";
00112
00113 $this->db->query($query);
00114
00115 return true;
00116 }
00117
00118
00119 function _hasCompleted($a_usr_id,$a_obj_id)
00120 {
00121 global $ilDB;
00122
00123 $query = "SELECT * FROM ut_lp_marks ".
00124 "WHERE usr_id = '".$a_usr_id."' ".
00125 "AND obj_id = '".$a_obj_id."'";
00126
00127 $res = $ilDB->query($query);
00128 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00129 {
00130 return (bool) $row->completed;
00131 }
00132 return false;
00133 }
00134
00135 function _lookupMark($a_usr_id,$a_obj_id)
00136 {
00137 global $ilDB;
00138
00139 $query = "SELECT * FROM ut_lp_marks ".
00140 "WHERE usr_id = '".$a_usr_id."' ".
00141 "AND obj_id = '".$a_obj_id."'";
00142
00143 $res = $ilDB->query($query);
00144 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00145 {
00146 return $row->mark;
00147 }
00148 return '';
00149 }
00150
00151
00152 function _lookupComment($a_usr_id,$a_obj_id)
00153 {
00154 global $ilDB;
00155
00156 $query = "SELECT * FROM ut_lp_marks ".
00157 "WHERE usr_id = '".$a_usr_id."' ".
00158 "AND obj_id = '".$a_obj_id."'";
00159
00160 $res = $ilDB->query($query);
00161 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00162 {
00163 return $row->comment;
00164 }
00165 return '';
00166 }
00167
00168
00169 function __read()
00170 {
00171 $res = $this->db->query("SELECT * FROM ut_lp_marks ".
00172 "WHERE obj_id = ".$this->db->quote($this->obj_id)." ".
00173 "AND usr_id = '".(int) $this->usr_id."'");
00174 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00175 {
00176 $this->has_entry = true;
00177 $this->completed = (int) $row->completed;
00178 $this->comment = $row->comment;
00179 $this->mark = $row->mark;
00180
00181 return true;
00182 }
00183
00184 return false;
00185 }
00186
00187 function __add()
00188 {
00189 $query = "INSERT INTO ut_lp_marks ".
00190 "SET mark = '".ilUtil::prepareDBString($this->getMark())."', ".
00191 "comment = '".ilUtil::prepareDBString($this->getComment())."', ".
00192 "completed = '".(int) $this->getCompleted()."', ".
00193 "obj_id = '".$this->getObjId()."', ".
00194 "usr_id = '".$this->getUserId()."'";
00195
00196 $this->db->query($query);
00197
00198 $this->has_entry = true;
00199
00200 return true;
00201 }
00202 }
00203 ?>