00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00035 class ilFeedback {
00036 function ilFeedback($a_id = 0){
00037 if($a_id > 0){
00038 $this->id = $a_id;
00039 $this->getBarometer();
00040 }
00041
00042 }
00043
00044 function setId($a_id){
00045 $this->id = $a_id;
00046 }
00047 function getId(){
00048 return($this->id);
00049 }
00050 function setTitle($a_title){
00051 $this->title = $a_title;
00052 }
00053 function getTitle(){
00054 return($this->title);
00055 }
00056 function setDescription($a_description){
00057 $this->description = $a_description;
00058 }
00059 function getDescription(){
00060 return($this->description);
00061 }
00062 function setAnonymous($a_anonymous){
00063 $this->anonymous = $a_anonymous;
00064 }
00065
00066 function getAnonymous(){
00067 return($this->anonymous);
00068 }
00069 function setRequired($a_required){
00070 $this->required = $a_required;
00071 }
00072
00073 function getRequired(){
00074 return($this->required);
00075 }
00076 function setShowOn($a_show_location){
00077 $this->show_on = $a_show_location;
00078 }
00079
00080 function getShowOn(){
00081 return($this->show_on);
00082 }
00083 function setVotes($a_votes){
00084 $this->votes = $a_votes;
00085 }
00086
00087 function getVotes(){
00088 return($this->votes);
00089 }
00090 function setStarttime($a_starttime){
00091 $this->starttime = $a_starttime;
00092 }
00093
00094 function getStarttime(){
00095 return($this->starttime);
00096 }
00097 function setEndtime($a_endtime){
00098 $this->endtime = $a_endtime;
00099 }
00100
00101 function getEndtime(){
00102 return($this->endtime);
00103 }
00104 function setInterval($a_interval){
00105 $this->interval = $a_interval;
00106 }
00107
00108 function getInterval(){
00109 return($this->interval);
00110 }
00111 function setIntervalUnit($a_interval_unit){
00112 $this->interval_unit = $a_interval_unit;
00113 }
00114
00115 function getIntervalUnit(){
00116 return($this->interval_unit);
00117 }
00118 function setFirstVoteBest($a_first_vote_best){
00119 $this->first_vote_best = $a_first_vote_best;
00120 }
00121
00122 function getFirstVoteBest(){
00123 return($this->first_vote_best);
00124 }
00125 function setObjId($a_obj_id){
00126 $this->obj_id = $a_obj_id;
00127 }
00128
00129 function getObjId(){
00130 return($this->obj_id);
00131 }
00132 function setRefId($a_ref_id){
00133 $this->ref_id = $a_ref_id;
00134 }
00135 function getRefId(){
00136 return($this->ref_id);
00137 }
00138 function setTextAnswer($a_text_answer){
00139 $this->text_answer = $a_text_answer;
00140 }
00141
00142 function getTextAnswer(){
00143 return($this->text_answer);
00144 }
00145 function setIds($a_ids){
00146 $this->ids = $a_ids;
00147 }
00148 function setUserId($a_user_id){
00149 $this->user_id = $a_user_id;
00150 }
00151 function setVote($a_vote){
00152 $this->vote = $a_vote;
00153 }
00154 function setNote($a_note){
00155 $this->note = $a_note;
00156 }
00157
00161 function setAllData($a_barometer){
00162 $this->setId($a_barometer['fb_id']);
00163 $this->setTitle($a_barometer['title']);
00164 $this->setDescription($a_barometer['description']);
00165 $this->setAnonymous($a_barometer['anonymous']);
00166 $this->setRequired($a_barometer['required']);
00167 $this->setShowOn($a_barometer['show_on']);
00168 $this->setVotes($a_barometer['votes']);
00169 $this->setStarttime($a_barometer['starttime']);
00170 $this->setEndtime($a_barometer['endtime']);
00171 $this->setInterval($a_barometer['repeat_interval']);
00172 $this->setIntervalUnit($a_barometer['interval_unit']);
00173 $this->setFirstVoteBest($a_barometer['first_vote_best']);
00174 $this->setTextAnswer($a_barometer['text_answer']);
00175 $this->setObjId($a_barometer['obj_id']);
00176 $this->setRefId($a_barometer['ref_id']);
00177 }
00178
00182 function create(){
00183 global $ilDB;
00184 $q = "INSERT INTO feedback_items (title, description, anonymous,".
00185 "required, show_on, text_answer, votes, starttime, endtime, ".
00186 "repeat_interval, interval_unit, first_vote_best, ref_id,obj_id) VALUES(".
00187 $ilDB->quote($this->title).", ".
00188 $ilDB->quote($this->description).", ".
00189 $ilDB->quote($this->anonymous).", ".
00190 $ilDB->quote($this->required).", ".
00191 $ilDB->quote($this->show_on).", ".
00192 $ilDB->quote($this->text_answer).", ".
00193 $ilDB->quote($this->votes).", ".
00194 $ilDB->quote($this->starttime).", ".
00195 $ilDB->quote($this->endtime).", ".
00196 $ilDB->quote($this->interval).", ".
00197 $ilDB->quote($this->interval_unit).", ".
00198 $ilDB->quote($this->first_vote_best).", ".
00199 $ilDB->quote($this->ref_id).", ".
00200 $ilDB->quote($this->obj_id).")";
00201 $ilDB->query($q);
00202 $this->id = $ilDB->getLastInsertId();
00203
00204
00205 }
00206
00210 function update(){
00211 global $ilDB;
00212 $q = "UPDATE feedback_items set ".
00213 "title=".$ilDB->quote($this->title).", ".
00214 "description=".$ilDB->quote($this->description).", ".
00215 "anonymous=".$ilDB->quote($this->anonymous).", ".
00216 "required=".$ilDB->quote($this->required).", ".
00217 "show_on=".$ilDB->quote($this->show_on).", ".
00218 "text_answer=".$ilDB->quote($this->text_answer).", ".
00219 "votes=".$ilDB->quote($this->votes).", ".
00220 "starttime=".$ilDB->quote($this->starttime).", ".
00221 "endtime=".$ilDB->quote($this->endtime).", ".
00222 "repeat_interval=".$ilDB->quote($this->interval).", ".
00223 "interval_unit=".$ilDB->quote($this->interval_unit).", ".
00224 "first_vote_best=".$ilDB->quote($this->first_vote_best)." WHERE fb_id=".$ilDB->quote($this->id);
00225
00226 $ilDB->query($q);
00227 $this->id = $ilDB->getLastInsertId();
00228
00229
00230 }
00231
00235 function getBarometer(){
00236 global $ilDB;
00237 $q = "SELECT * FROM feedback_items WHERE fb_id=".$ilDB->quote($this->id);
00238 $res = $ilDB->query($q);
00239 if($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
00240 $this->setAllData($row);
00241
00242
00243 }
00247 function getBarometerByObjId(){
00248 global $ilDB;
00249 $q = "SELECT * FROM feedback_items WHERE obj_id=".$ilDB->quote($this->obj_id);
00250 $res = $ilDB->query($q);
00251 if($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
00252 $this->setAllData($row);
00253
00254 }
00255
00259 function getBarometerByRefId(){
00260 global $ilDB;
00261 $q = "SELECT * FROM feedback_items WHERE ref_id=".$ilDB->quote($this->ref_id);
00262 $res = $ilDB->query($q);
00263 if($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
00264 $this->setAllData($row);
00265
00266 }
00267
00271 function getFeedback($required=0){
00272 global $ilDB;
00273 $filter_req = ($required) ? ' required=1 AND ' : '';
00274 $q = "SELECT * FROM feedback_items WHERE ".
00275 $filter_req.
00276 " ((starttime<=UNIX_TIMESTAMP() AND".
00277 " endtime>=UNIX_TIMESTAMP()) OR(starttime<=0 AND endtime<=0))";
00278 $res = $ilDB->query($q);
00279 if($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
00280 $this->setAllData($row);
00281 }
00282
00288 function getAllBarometer($a_show_inactive=1,$a_only_req=0){
00289 global $ilDB;
00290
00291 if($this->ref_id)
00292 $where.=" ref_id=".$ilDB->quote($this->ref_id);
00293 if($a_only_req==1)
00294 if($where!='')
00295 $where .= ' AND required=1 ';
00296 else
00297 $where = ' required = 1 ';
00298 $q = "SELECT * FROM feedback_items WHERE ".$where;
00299
00300 if($a_show_inactive==0){
00301 if($where!='')
00302 $where = ' AND'.$where;
00303 $q = "SELECT * FROM feedback_items WHERE ".
00304 " ((starttime<=UNIX_TIMESTAMP() AND".
00305 " endtime>=UNIX_TIMESTAMP()) OR(starttime<=0 AND endtime<=0))".$where;
00306 }
00307 $res = $ilDB->query($q);
00308 $i = 0;
00309 while($row = $res->fetchRow(DB_FETCHMODE_ASSOC)){
00310 $barometers[$i] = new ilFeedback();
00311 $barometers[$i]->setAllData($row);
00312 $i++;
00313 }
00314
00315 return $barometers ? $barometers : array();
00316 }
00320 function delete(){
00321 global $ilDB;
00322 foreach ($this->ids as $k => $v)
00323 $this->ids[$k] = $ilDB->quote($v);
00324 $q = "DELETE FROM feedback_items WHERE ".
00325 "fb_id IN (".implode(',',$this->ids).")";
00326 $ilDB->query($q);
00327 $q = "DELETE FROM feedback_results WHERE ".
00328 "fb_id IN (".implode(',',$this->ids).")";
00329 $ilDB->query($q);
00330 }
00331
00335 function saveResult(){
00336 global $ilDB;
00337
00338
00339 if($this->canVote($this->user_id,$this->id)==1){
00340 $q = "INSERT INTO feedback_results (".
00341 "fb_id,user_id,vote,note,votetime) VALUES (".
00342 $ilDB->quote($this->id).", ".
00343 $ilDB->quote($this->user_id).", ".
00344 $ilDB->quote($this->vote).", ".
00345 $ilDB->quote($this->note).", UNIX_TIMESTAMP())";
00346 $ilDB->query($q);
00347 }
00348 }
00349
00353 function canVote($a_user_id,$a_fb_id){
00354 global $ilDB, $ilUser;
00355 include_once('course/classes/class.ilCourseMembers.php');
00356
00357 $q = "SELECT * FROM feedback_results WHERE ".
00358 "fb_id=".$ilDB->quote($a_fb_id)." AND ".
00359 "user_id=".$ilDB->quote($a_user_id)." ORDER BY votetime DESC";;
00360 $res = $ilDB->query($q);
00361
00362 $row_results = $res->fetchRow(DB_FETCHMODE_ASSOC);
00363 $q = "SELECT * FROM feedback_items WHERE ".
00364 "fb_id = ".$ilDB->quote($a_fb_id);
00365 $res1 = $ilDB->query($q);
00366 $row_items = $res1->fetchRow(DB_FETCHMODE_ASSOC);
00367
00368
00369 if (!($row_items["starttime"]<=time() && $row_items["endtime"]>=time()))
00370 {
00371 return (0);
00372 }
00373
00374
00375 if(($res->numRows()==0)&&ilCourseMembers::_isMember($ilUser->getId(),$row_items['obj_id']))
00376 return(1);
00377
00378 if(ilCourseMembers::_isMember($ilUser->getId(),$row_items['obj_id'])){
00379
00380 if($row_items['repeat_interval'] > 0){
00381 $interval = $this->interval2seconds($row_items['repeat_interval'], $row_items['interval_unit']);
00382 if((time() - $row_results['votetime']) >= $interval){
00383 return(1);
00384 }
00385 }
00386 }
00387
00388
00389 return(0);
00390 }
00391
00395 function getChartData(){
00396 global $ilDB;
00397 if($this->user_id!='')
00398 $user_filter = ' feedback_results.user_id='.$ilDB->quote($this->user_id).' AND ';
00399 $q='SELECT usr_data.login, feedback_results.user_id,feedback_results.vote, feedback_results.votetime, FROM_UNIXTIME(feedback_results.votetime,"%d.%m.%Y %H:%i") as timelabel FROM'.
00400 ' feedback_results LEFT JOIN usr_data ON usr_data.usr_id = feedback_results.user_id WHERE '.
00401 ' '.$user_filter.' feedback_results.fb_id='.$ilDB->quote($this->id).
00402 ' ORDER BY feedback_results.votetime,usr_data.login';
00403
00404 $res = $ilDB->query($q);
00405 $i=0;
00406 $j=1;
00407 $k=1;
00408 $n=0;
00409 $pvt='';
00410 $datapie[0][0] = 'Vote';
00411 while($row = $res->fetchRow(DB_FETCHMODE_ASSOC)){
00412
00413 if(!isset($tmp[$row['user_id']]))
00414 $tmp[$row['user_id']]=$j++;
00415 if(!isset($tmpv[$row['vote']]))
00416 $tmpv[$row['vote']] = $k++;
00417 $data[$i][0] = $row['timelabel'];
00418 $data[$i][$tmp[$row['user_id']]] = $row['vote'];
00419 $legend[$row['login']] = $row['login'];
00420 $legendpie[$row['vote']] = $row['vote'];
00421
00422
00423 $datapie[0][$tmpv[$row['vote']]]++;
00424 if($row['votetime']!=$pvt){
00425 $i++;
00426
00427 }
00428 $pvt=$row['votetime'];
00429
00430 $table[$n]['votetime'] = $row['timelabel'];
00431 $table[$n]['user'] = $row['login'];
00432 $table[$n]['vote'] = $row['vote'];
00433 $n++;
00434 }
00435 if(is_array($data)){
00436 foreach($data as $k => $v){
00437
00438
00439 if(count($v)<=count($tmp)){
00440 for($i=1;$i<=count($tmp);$i++)
00441 if(!isset($v[$i]))
00442 $data[$k][$i]='';
00443 }
00444 ksort($data[$k]);
00445 }
00446 }
00447 return(array('data' => $data,'legend' => $legend,'legendpie' => $legendpie, 'datapie' => $datapie, 'table' => $table));
00448
00449 }
00453 function getNotes(){
00454 global $ilDB;
00455 if($this->user_id!='')
00456 $user_filter = ' AND feedback_results.user_id='.$ilDB->quote($this->user_id);
00457 $q='SELECT usr_data.login, feedback_results.user_id,feedback_results.note,feedback_results.vote, feedback_results.votetime, FROM_UNIXTIME(feedback_results.votetime,"%d.%m.%Y %H:%i") as timelabel FROM'.
00458 ' feedback_results LEFT JOIN usr_data ON usr_data.usr_id = feedback_results.user_id'.
00459 ' WHERE feedback_results.note<>""'.
00460 ' '.$user_filter.' AND feedback_results.fb_id='.$ilDB->quote($this->id).
00461 ' ORDER BY feedback_results.votetime,usr_data.login';
00462
00463 $res = $ilDB->query($q);
00464 $i=0;
00465 while($row = $res->fetchRow(DB_FETCHMODE_ASSOC)){
00466 $data[$i]['user'] = $row['login'];
00467 $data[$i]['votetime'] = $row['timelabel'];
00468 $data[$i]['note'] = $row['note'];
00469 $i++;
00470 }
00471 return($data);
00472 }
00476 function getResultUsers(){
00477
00478 global $ilDB;
00479 $q='SELECT distinct(usr_data.login), feedback_results.user_id FROM'.
00480 ' feedback_results LEFT JOIN usr_data ON usr_data.usr_id = feedback_results.user_id'.
00481 ' WHERE feedback_results.fb_id='.$ilDB->quote($this->id).
00482 ' ORDER BY feedback_results.votetime,usr_data.login';
00483
00484 $res = $ilDB->query($q);
00485
00486 while($row = $res->fetchRow(DB_FETCHMODE_ASSOC)){
00487 $users[$row['user_id']] = $row['login'];
00488 }
00489 return($users);
00490 }
00491
00496 function interval2seconds($a_interval,$a_interval_unit){
00497 switch($a_interval_unit){
00498 case 1:
00499
00500 $multi_by = 24 * 60 * 60;
00501 break;
00502 case 2:
00503
00504 $mult_by = 7 * 24 * 60 * 60;
00505 break;
00506 case 3:
00507
00508 $mult_by = 30 * 24 * 60 *60;
00509 break;
00510
00511 default:
00512
00513 $mult_by = 60 * 60;
00514 break;
00515 }
00516 $seconds = $a_interval * $mult_by;
00517 return($seconds);
00518 }
00519 }
00520 ?>