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

classes/class.ilExerciseMembers.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 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 
00024 
00034 class ilExerciseMembers
00035 {
00036         var $ilias;
00037 
00038         var $ref_id;
00039         var $obj_id;
00040         var $members;
00041         var $status_solved;
00042         var $status_sent;
00043         var $status_returned;
00044         var $notice;
00045 
00046         function ilExerciseMembers($a_obj_id,$a_ref_id)
00047         {
00048                 global $ilias;
00049 
00050                 $this->ilias =& $ilias;
00051                 $this->obj_id = $a_obj_id;
00052                 $this->ref_id = $a_ref_id;
00053         }
00054 
00055         // GET SET METHODS
00056         function getRefId()
00057         {
00058                 return $this->ref_id;
00059         }
00060         function getObjId()
00061         {
00062                 return $this->obj_id;
00063         }
00064         function setObjId($a_obj_id)
00065         {
00066                 $this->obj_id = $a_obj_id;
00067         }
00068         function getMembers()
00069         {
00070                 return $this->members ? $this->members : array();
00071         }
00072         function setMembers($a_members)
00073         {
00074                 $this->members = $a_members;
00075         }
00076         function assignMember($a_usr_id)
00077         {
00078                 $tmp_user = ilObjectFactory::getInstanceByObjId($a_usr_id);
00079                 $tmp_user->addDesktopItem($this->getRefId(),"exc");
00080 
00081 
00082                 $query = "REPLACE INTO exc_members ".
00083                         "SET obj_id = '".$this->getObjId()."', ".
00084                         "usr_id = '".$a_usr_id."', ".
00085                         "solved = '0', sent = '0'";
00086 
00087                 $res = $this->ilias->db->query($query);
00088                 $this->read();
00089 
00090                 return true;
00091         }
00092         function isAssigned($a_id)
00093         {
00094                 return in_array($a_id,$this->getMembers());
00095         }
00096 
00097         function assignMembers($a_members)
00098         {
00099                 $assigned = 0;
00100                 if(is_array($a_members))
00101                 {
00102                         foreach($a_members as $member)
00103                         {
00104                                 if(!$this->isAssigned($member))
00105                                 {
00106                                         $this->assignMember($member);
00107                                 }
00108                                 else
00109                                 {
00110                                         ++$assigned;
00111                                 }
00112                         }
00113                 }
00114                 if($assigned == count($a_members))
00115                 {
00116                         return false;
00117                 }
00118                 else
00119                 {
00120                         return true;
00121                 }
00122         }
00123         function deassignMember($a_usr_id)
00124         {
00125                 $tmp_user = ilObjectFactory::getInstanceByObjId($a_usr_id);
00126                 $tmp_user->dropDesktopItem($this->getRefId(),"exc");
00127 
00128                 $query = "DELETE FROM exc_members ".
00129                         "WHERE obj_id = '".$this->getObjId()." '".
00130                         "AND usr_id = '".$a_usr_id."'";
00131 
00132                 $this->ilias->db->query($query);
00133                 $this->read();
00134                 // delete all delivered files of the member
00135                 $delivered_files =& $this->getDeliveredFiles($a_usr_id);
00136                 $files_to_delete = array();
00137                 $userfile = "";
00138                 foreach ($delivered_files as $key => $value)
00139                 {
00140                         array_push($files_to_delete, $value["returned_id"]);
00141                         $userfile = $value["filename"];
00142                 }
00143                 $this->deleteDeliveredFiles($files_to_delete, $a_usr_id);
00144                 // delete the user directory if existing
00145                 if ($userfile)
00146                 {
00147                         $pathinfo = pathinfo($userfile);
00148                         $dir = $pathinfo["dirname"];
00149                 }
00150                 if (is_dir($dir))
00151                 {
00152                         rmdir($dir);
00153                 }
00154                 return false;
00155         }
00156         
00157         function deassignMembers($a_members)
00158         {
00159                 if(is_array($a_members))
00160                 {
00161                         foreach($a_members as $member)
00162                         {
00163                                 $this->deassignMember($member);
00164                         }
00165                 }
00166                 else
00167                 {
00168                         return false;
00169                 }
00170         }
00171         function setStatusSolved($a_status)
00172         {
00173                 if(is_array($a_status))
00174                 {
00175                         $this->status_solved = $a_status;
00176                         return true;
00177                 }
00178         }
00179         function getStatusSolved()
00180         {
00181                 return $this->status_solved ? $this->status_solved : array(0 => 0);
00182         }
00183         function getStatusSolvedByMember($a_member_id)
00184         {
00185                 if(isset($this->status_solved[$a_member_id]))
00186                 {
00187                         return $this->status_solved[$a_member_id];
00188                 }
00189                 return false;
00190         }
00191         function setStatusSolvedForMember($a_member_id,$a_status)
00192         {
00193                 $query = "UPDATE exc_members ".
00194                         "SET solved = '".($a_status ? 1 : 0)."' ".
00195                         "WHERE obj_id = '".$this->getObjId()."' ".
00196                         "AND usr_id = '".$a_member_id."'";
00197 
00198                 $this->ilias->db->query($query);
00199                 $this->read();
00200 
00201                 return true;
00202         }
00203 
00204         function setStatusSent($a_status)
00205         {
00206                 if(is_array($a_status))
00207                 {
00208                         $this->status_sent = $a_status;
00209                         return true;
00210                 }
00211         }
00212         function getStatusSent()
00213         {
00214                 return $this->status_sent ? $this->status_sent : array(0 => 0);
00215         }
00216         function getStatusSentByMember($a_member_id)
00217         {
00218                 if(isset($this->status_sent[$a_member_id]))
00219                 {
00220                         return $this->status_sent[$a_member_id];
00221                 }
00222                 return false;
00223         }
00224         function setStatusSentForMember($a_member_id,$a_status)
00225         {
00226                 $query = "UPDATE exc_members ".
00227                         "SET sent = '".($a_status ? 1 : 0)."' ".
00228                         "WHERE obj_id = '".$this->getObjId()."' ".
00229                         "AND usr_id = '".$a_member_id."'";
00230 
00231                 $this->ilias->db->query($query);
00232                 $this->read();
00233 
00234                 return true;
00235         }
00236 
00237         function getStatusReturned()
00238         {
00239                 return $this->status_returned ? $this->status_returned : array(0 => 0);
00240         }
00241         function setStatusReturned($a_status)
00242         {
00243                 if(is_array($a_status))
00244                 {
00245                         $this->status_returned = $a_status;
00246                         return true;
00247                 }
00248                 return false;
00249         }
00250 
00251         function getStatusReturnedByMember($a_member_id)
00252         {
00253                 if(isset($this->status_returned[$a_member_id]))
00254                 {
00255                         return $this->status_returned[$a_member_id];
00256                 }
00257                 return false;
00258         }
00259         function setStatusReturnedForMember($a_member_id,$a_status)
00260         {
00261                 $query = "UPDATE exc_members ".
00262                         "SET returned = '".($a_status ? 1 : 0)."' ".
00263                         "WHERE obj_id = '".$this->getObjId()."' ".
00264                         "AND usr_id = '".$a_member_id."'";
00265 
00266                 $this->ilias->db->query($query);
00267                 $this->read();
00268 
00269                 return true;
00270         }
00271 
00272         function getNotice()
00273         {
00274                 return $this->notice ? $this->notice : array(0 => 0);
00275         }
00276 
00277         function setNotice($a_notice)
00278         {
00279                 if(is_array($a_notice))
00280                 {
00281                         $this->notice = $a_notice;
00282                         return true;
00283                 }
00284                 return false;
00285         }
00286 
00287         function getNoticeByMember($a_member_id)
00288         {
00289                 if(isset($this->notice[$a_member_id]))
00290                 {
00291                         return $this->notice[$a_member_id];
00292                 }
00293                 else
00294                 {
00295                         return "";
00296                 }
00297         }
00298 
00299         function hasReturned($a_member_id)
00300         {
00301                 $query = sprintf("SELECT returned_id FROM exc_returned WHERE obj_id = %s AND user_id = %s",
00302                         $this->ilias->db->quote($this->getObjId() . ""),
00303                         $this->ilias->db->quote($a_member_id . "")
00304                 );
00305                 $result = $this->ilias->db->query($query);
00306                 return $result->numRows();
00307         }
00308 
00309         function getAllDeliveredFiles()
00310         {
00311                 $query = "SELECT * FROM exc_returned WHERE obj_id = '".$this->getObjId()."'";
00312 
00313                 $res = $this->ilias->db->query($query);
00314                 while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
00315                 {
00316                         $delivered[] = $row;
00317                 }
00318                 return $delivered ? $delivered : array();
00319         }
00320                         
00328         function &getDeliveredFiles($a_member_id)
00329         {
00330                 $query = sprintf("SELECT *, TIMESTAMP + 0 AS TIMESTAMP14 FROM exc_returned WHERE obj_id = %s AND user_id = %s ORDER BY TIMESTAMP14",
00331                         $this->ilias->db->quote($this->getObjId() . ""),
00332                         $this->ilias->db->quote($a_member_id . "")
00333                 );
00334                 $result = $this->ilias->db->query($query);
00335                 $delivered_files = array();
00336                 if ($result->numRows())
00337                 {
00338                         while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
00339                         {
00340                                 array_push($delivered_files, $row);
00341                         }
00342                 }
00343                 return $delivered_files;
00344         }
00345         
00352         function deleteDeliveredFiles($file_id_array, $a_member_id)
00353         {
00354                 if (count($file_id_array))
00355                 {
00356                         $query = sprintf("SELECT * FROM exc_returned WHERE user_id = %s AND returned_id IN (" . join($file_id_array, ",") . ")",
00357                                 $this->ilias->db->quote($a_member_id . "")
00358                         );
00359                         $result = $this->ilias->db->query($query);
00360                         if ($result->numRows())
00361                         {
00362                                 $result_array = array();
00363                                 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
00364                                 {
00365                                         array_push($result_array, $row);
00366                                 }
00367                                 // delete the entries in the database
00368                                 $query = sprintf("DELETE FROM exc_returned WHERE user_id = %s AND returned_id IN (" . join($file_id_array, ",") . ")",
00369                                         $this->ilias->db->quote($a_member_id . "")
00370                                 );
00371                                 $result = $this->ilias->db->query($query);
00372                                 // delete the files
00373                                 foreach ($result_array as $key => $value)
00374                                 {
00375                                         unlink($value["filename"]);
00376                                 }
00377                         }
00378                 }
00379         }
00380 
00386         function deliverReturnedFiles($a_member_id)
00387         {
00388                 $query = sprintf("SELECT * FROM exc_returned WHERE obj_id = %s AND user_id = %s",
00389                         $this->ilias->db->quote($this->getObjId() . ""),
00390                         $this->ilias->db->quote($a_member_id . "")
00391                 );
00392                 $result = $this->ilias->db->query($query);
00393                 $count = $result->numRows();
00394                 if ($count == 1)
00395                 {
00396                         $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
00397                         $this->downloadSingleFile($row["filename"], $row["filetitle"]);
00398                 }
00399                 else
00400                 {
00401                         $array_files = array();
00402                         $filename = "";
00403                         while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
00404                         {
00405                                 $filename = $row["filename"];
00406                                 $pathinfo = pathinfo($filename);
00407                                 $dir = $pathinfo["dirname"];
00408                                 $file = $pathinfo["basename"];
00409                                 array_push($array_files, $file);
00410                         }
00411                         $pathinfo = pathinfo($filename);
00412                         $dir = $pathinfo["dirname"];
00413                         $this->downloadMultipleFiles($array_files, $dir);
00414                 }
00415         }
00416         
00417         function downloadSelectedFiles($array_file_id)
00418         {
00419                 if (count($array_file_id))
00420                 {
00421                         $query = "SELECT * FROM exc_returned WHERE returned_id IN (" . join($array_file_id, ",") . ")";
00422                         $result = $this->ilias->db->query($query);
00423                         if ($result->numRows())
00424                         {
00425                                 $array_found = array();
00426                                 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
00427                                 {
00428                                         array_push($array_found, $row);
00429                                 }
00430                                 if (count($array_found) == 1)
00431                                 {
00432                                         $this->downloadSingleFile($array_found[0]["filename"], $array_found[0]["filetitle"]);
00433                                 }
00434                                 else
00435                                 {
00436                                         $filenames = array();
00437                                         $dir = "";
00438                                         $file = "";
00439                                         foreach ($array_found as $key => $value)
00440                                         {
00441                                                 $pathinfo = pathinfo($value["filename"]);
00442                                                 $dir = $pathinfo["dirname"];
00443                                                 $file = $pathinfo["basename"];
00444                                                 array_push($filenames, $file); 
00445                                         }
00446                                         $this->downloadMultipleFiles($filenames, $dir);
00447                                 }
00448                         }
00449                 }
00450         }
00451         
00452         function downloadSingleFile($filename, $filetitle)
00453         {
00454                 require_once "./classes/class.ilUtil.php";
00455                 ilUtil::deliverFile($filename, $filetitle);
00456         }
00457         
00458         function downloadMultipleFiles($array_filenames, $pathname)
00459         {
00460                 global $lng;
00461                 require_once "./classes/class.ilUtil.php";
00462                 $cdir = getcwd();
00463                 chdir($pathname);
00464                 $zip = PATH_TO_ZIP;
00465                 $tmpfile = ilUtil::ilTempnam();
00466                 $tmpzipfile = $tmpfile . ".zip";
00467                 foreach ($array_filenames as $key => $filename)
00468                 {
00469                         $array_filenames[$key] = ilUtil::escapeShellArg($array_filenames[$key]);
00470                 }
00471                 $zipcmd = $zip." ".ilUtil::escapeShellArg($tmpzipfile)." ".join($array_filenames, " ");
00472                 exec($zipcmd);
00473                 ilUtil::deliverFile($tmpzipfile, strtolower($lng->txt("excs")) . ".zip");
00474                 chdir($cdir);
00475                 unlink($tmpfile);
00476                 unlink($tmpzipfile);
00477         }
00478         
00479         function setNoticeForMember($a_member_id,$a_notice)
00480         {
00481 
00482                 $query = "UPDATE exc_members ".
00483                         "SET notice = '".addslashes($a_notice)."' ".
00484                         "WHERE obj_id = '".$this->getObjId()."' ".
00485                         "AND usr_id = '".$a_member_id."'";
00486 
00487                 $this->ilias->db->query($query);
00488                 $this->read();
00489 
00490                 return true;
00491         }
00492 /*
00493         function update()
00494         {
00495                 $save_members = $this->getMembers();
00496                 $save_notice = $this->getNotice();
00497                 $saved_st_solved = $this->getStatusSolved();
00498                 $saved_st_sent = $this->getStatusSent();
00499                 $saved_st_return = $this->getStatusReturned();
00500 
00501                 $this->read();
00502 
00503                 // UPDATE MEMBERS
00504                 foreach(array_diff($this->getMembers(),$save_members) as $member)
00505                 {
00506                         $query  = "DELETE FROM exc_members ".
00507                                 "WHERE obj_id = '".$this->getObjId()."' ".
00508                                 "AND usr_id = '".$member."'";
00509                         $this->ilias->db->query($query);
00510                 }
00511                 foreach(array_diff($save_members,$this->getMembers()) as $member)
00512                 {
00513                         $query  = "INSERT INTO exc_members ".
00514                                 "SET obj_id = '".$this->getObjId()."', ".
00515                                 "usr_id = '".$member."', ".
00516                                 "sent = '0', ".
00517                                 "solved = '0'";
00518                         $this->ilias->db->query($query);
00519                 }
00520                 $this->setMembers($save_members);
00521                 $this->setNotice($save_notice);
00522                 $this->setStatusSent($saved_st_sent);
00523                 $this->setStatusSolved($saved_st_solved);
00524                 $this->setStatusReturned($saved_st_return);
00525 
00526                 
00527                 // UPDATE SOLVED AND SENT
00528                 foreach($this->getMembers() as $member)
00529                 {
00530                         $query = "UPDATE exc_members ".
00531                                 "SET solved = '".$this->getStatusSolvedByMember($member)."', ".
00532                                 "notice = '".addslashes($this->getNoticeByMember($member))."', ".
00533                                 "returned = '".$this->getStatusReturnedByMember($member)."', ".
00534                             "sent = '".$this->getStatusSentByMember($member)."'";
00535                         $this->ilias->db->query($query);
00536                 }
00537                 return true;
00538         }
00539 */
00540         function read()
00541         {
00542                 $tmp_arr_members = array();
00543                 $tmp_arr_solved = array();
00544                 $tmp_arr_sent = array();
00545                 $tmp_arr_notice = array();
00546                 $tmp_arr_returned = array();
00547 
00548                 $query = "SELECT * FROM exc_members ".
00549                         "WHERE obj_id = '".$this->getObjId()."' ";
00550 
00551                 $res = $this->ilias->db->query($query);
00552                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00553                 {
00554                         $tmp_arr_members[] = $row->usr_id;
00555                         $tmp_arr_notice[$row->usr_id] = $row->notice;
00556                         $tmp_arr_returned[$row->usr_id] = $row->returned;
00557                         $tmp_arr_solved[$row->usr_id] = $row->solved;
00558                         $tmp_arr_sent[$row->usr_id] = $row->sent;
00559                 }
00560                 $this->setMembers($tmp_arr_members);
00561                 $this->setNotice($tmp_arr_notice);
00562                 $this->setStatusSolved($tmp_arr_solved);
00563                 $this->setStatusSent($tmp_arr_sent);
00564                 $this->setStatusReturned($tmp_arr_returned);
00565                 
00566                 return true;
00567         }
00568         function ilClone($a_new_id)
00569         {
00570                 $data = array();
00571 
00572                 $query = "SELECT * FROM exc_members ".
00573                         "WHERE obj_id = '".$this->getObjId()."'";
00574 
00575                 $res = $this->ilias->db->query($query);
00576                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00577                 {
00578                         $data[] = array("usr_id" => $row->usr_id,
00579                                                         "notice" => $row->notice,
00580                                                         "returned" => $row->returned,
00581                                                         "solved" => $row->solved,
00582                                                         "sent"   => $row->sent);
00583                 }
00584                 foreach($data as $row)
00585                 {
00586                         $query = "INSERT INTO exc_members ".
00587                                 "SET obj_id = '".$a_new_id."', ".
00588                                 "usr_id = '".$row["usr_id"]."', ".
00589                                 "notice = '".addslashes($row["notice"])."', ".
00590                                 "returned = '".$row["returned"]."', ".
00591                                 "solved = '".$row["solved"]."', ".
00592                                 "sent = '".$row["sent"]."'";
00593 
00594                         $res = $this->ilias->db->query($query);
00595                 }
00596                 return true;
00597         }
00598 
00599         function delete()
00600         {
00601                 $query = "DELETE FROM exc_members WHERE obj_id = '".$this->getObjId()."'";
00602                 $this->ilias->db->query($query);
00603 
00604                 return true;
00605         }
00606 
00607         function _hasSolved($a_exc_id,$a_usr_id)
00608         {
00609                 global $ilDB;
00610 
00611                 // check if user is owner
00612                 $query = "SELECT owner FROM object_data ".
00613                         "WHERE obj_id = '".$a_exc_id."'";
00614 
00615                 $res = $ilDB->query($query);
00616                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00617                 {
00618                         if($row->owner == $a_usr_id)
00619                         {
00620                                 return true;
00621                         }
00622                 }
00623 
00624                 // check if user has solved exercise
00625                 $query = "SELECT solved FROM exc_members ".
00626                         "WHERE obj_id = '".$a_exc_id."' ".
00627                         "AND usr_id = '".$a_usr_id."'";
00628 
00629                 $res = $ilDB->query($query);
00630                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00631                 {
00632                         if($row->solved == 1)
00633                         {
00634                                 return true;
00635                         }
00636                 }
00637                 return false;
00638         }
00639 
00640 } //END class.ilObjExercise
00641 ?>

Generated on Fri Dec 13 2013 11:57:53 for ILIAS Release_3_6_x_branch .rev 46809 by  doxygen 1.7.1