• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Services/Feedback/classes/class.ilFeedback.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2006 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
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         /* Set / Get Methods */
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                 //Save Only if there is not already a result from this user for this barometer
00338 
00339                 if($this->canVote($this->user_id,$this->id)==1 || $this->user_id == 0){
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('Modules/Course/classes/class.ilCourseParticipants.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                 // check end time
00369                 if (!($row_items["starttime"]<=time() && $row_items["endtime"]>=time()))
00370                 {
00371                         return (0);
00372                 }
00373                 
00374                 $members_obj = ilCourseParticipants::_getInstanceByObjId($row_items['obj_id']);
00375                 
00376                 //Check if the user is Member of that course, otherwise its not necessary that he votes
00377                 if(($res->numRows()==0) && $members_obj->isAssigned($ilUser->getId()))
00378                         return(1);
00379 
00380                 if($members_obj->isAssigned($ilUser->getId()))
00381                 {
00382                         if($row_items['repeat_interval'] > 0){
00383                                 $interval = $this->interval2seconds($row_items['repeat_interval'], $row_items['interval_unit']);
00384                                 if((time() - $row_results['votetime']) >= $interval){
00385                                         return(1);
00386                                 }
00387                         }
00388                 }
00389 
00390 
00391                 return(0);
00392         }
00393 
00397         function getChartData(){
00398                 global $ilDB;
00399                 if($this->user_id!='')
00400                         $user_filter = ' feedback_results.user_id='.$ilDB->quote($this->user_id).' AND ';
00401                 $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'.
00402                         ' feedback_results LEFT JOIN usr_data ON usr_data.usr_id = feedback_results.user_id WHERE '.
00403                         ' '.$user_filter.' feedback_results.fb_id='.$ilDB->quote($this->id).
00404                         ' ORDER BY feedback_results.votetime,usr_data.login';
00405 
00406                 $res = $ilDB->query($q);
00407                 $i=0;
00408                 $j=1;
00409                 $k=1;
00410                 $n=0;
00411                 $pvt='';
00412                 $datapie[0][0] = 'Vote';
00413                 while($row = $res->fetchRow(DB_FETCHMODE_ASSOC)){
00414 
00415                         if(!isset($tmp[$row['user_id']]))
00416                                 $tmp[$row['user_id']]=$j++;
00417                         if(!isset($tmpv[$row['vote']]))
00418                                 $tmpv[$row['vote']] = $k++;
00419                         $data[$i][0] = $row['timelabel'];
00420                         $data[$i][$tmp[$row['user_id']]] = $row['vote'];
00421                         $legend[$row['login']] = $row['login'];
00422                         $legendpie[$row['vote']] = $row['vote'];
00423 
00424 
00425                         $datapie[0][$tmpv[$row['vote']]]++;
00426                         if($row['votetime']!=$pvt){
00427                                 $i++;
00428 
00429                         }
00430                         $pvt=$row['votetime'];
00431 
00432                         $table[$n]['votetime'] = $row['timelabel'];
00433                         $table[$n]['user'] = $row['login'];
00434                         $table[$n]['vote'] = $row['vote'];
00435                         $n++;
00436                 }
00437                 if(is_array($data)){
00438                         foreach($data as $k => $v){
00439                                 /* Look if there are set all Y-values. If a user has no Y value for a certain date, the Y value has to be set to something otherwise PHPlot will not work correctly.
00440                                 The array keys have also to be sorted for PHPlot */
00441                                 if(count($v)<=count($tmp)){
00442                                         for($i=1;$i<=count($tmp);$i++)
00443                                                 if(!isset($v[$i]))
00444                                                         $data[$k][$i]='';
00445                                 }
00446                                 ksort($data[$k]);
00447                         }
00448                 }
00449                 return(array('data' => $data,'legend' => $legend,'legendpie' => $legendpie, 'datapie' => $datapie, 'table' => $table));
00450 
00451         }
00455         function getNotes(){
00456         global $ilDB;
00457                 if($this->user_id!='')
00458                         $user_filter = ' AND feedback_results.user_id='.$ilDB->quote($this->user_id);
00459                 $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'.
00460                         ' feedback_results LEFT JOIN usr_data ON usr_data.usr_id = feedback_results.user_id'.
00461                         ' WHERE  feedback_results.note<>""'.
00462                         ' '.$user_filter.' AND feedback_results.fb_id='.$ilDB->quote($this->id).
00463                         ' ORDER BY feedback_results.votetime,usr_data.login';
00464 
00465                 $res = $ilDB->query($q);
00466                 $i=0;
00467                 while($row = $res->fetchRow(DB_FETCHMODE_ASSOC)){
00468                         $data[$i]['user'] = $row['login'];
00469                         $data[$i]['votetime'] = $row['timelabel'];
00470                         $data[$i]['note'] = $row['note'];
00471                         $i++;
00472                 }
00473                 return($data);
00474         }
00478         function getResultUsers(){
00479 
00480                 global $ilDB;
00481                 $q='SELECT distinct(usr_data.login), feedback_results.user_id  FROM'.
00482                         ' feedback_results LEFT JOIN usr_data ON usr_data.usr_id = feedback_results.user_id'.
00483                         ' WHERE feedback_results.fb_id='.$ilDB->quote($this->id).
00484                         ' ORDER BY feedback_results.votetime,usr_data.login';
00485 
00486                 $res = $ilDB->query($q);
00487 
00488                 while($row = $res->fetchRow(DB_FETCHMODE_ASSOC)){
00489                         $users[$row['user_id']] = $row['login'];
00490                 }
00491                 return($users);
00492         }
00493 
00498         function interval2seconds($a_interval,$a_interval_unit){
00499                 switch($a_interval_unit){
00500                         case 1:
00501                                 //Days
00502                                 $multi_by = 24 * 60 * 60;
00503                                 break;
00504                         case 2:
00505                                 //Weeks
00506                                 $mult_by = 7 * 24 * 60 * 60;
00507                                 break;
00508                         case 3:
00509                                 // Months
00510                                 $mult_by = 30 *  24 * 60 *60;
00511                                 break;
00512 
00513                         default:
00514                                 //Hours
00515                                 $mult_by = 60 * 60;
00516                                 break;
00517                 }
00518                 $seconds = $a_interval * $mult_by;
00519                 return($seconds);
00520         }
00521 }
00522 ?>

Generated on Fri Dec 13 2013 17:56:57 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1