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

classes/class.ilObjExercise.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 
00035 require_once "class.ilObject.php";
00036 require_once "./classes/class.ilFileDataExercise.php";
00037 require_once "./classes/class.ilExerciseMembers.php";
00038 
00039 
00040 class ilObjExercise extends ilObject
00041 {
00042         var $file_obj;
00043         var $members_obj;
00044         var $files;
00045 
00046         var $timestamp;
00047         var $hour;
00048         var $minutes;
00049         var $day;
00050         var $month;
00051         var $year;
00052         var $instruction;
00053 
00060         function ilObjExercise($a_id = 0,$a_call_by_reference = true)
00061         {
00062                 $this->type = "exc";
00063                 $this->ilObject($a_id,$a_call_by_reference);
00064         }
00065 
00066         // SET, GET METHODS
00067         function setDate($a_hour,$a_minutes,$a_day,$a_month,$a_year)
00068         {
00069                 $this->hour = (int) $a_hour;
00070                 $this->minutes = (int) $a_minutes;
00071                 $this->day = (int) $a_day;
00072                 $this->month = (int) $a_month;
00073                 $this->year = (int) $a_year;
00074                 $this->timestamp = mktime($this->hour,$this->minutes,0,$this->month,$this->day,$this->year);
00075                 return true;
00076         }
00077         function getTimestamp()
00078         {
00079                 return $this->timestamp;
00080         }
00081         function setTimestamp($a_timestamp)
00082         {
00083                 $this->timestamp = $a_timestamp;
00084         }
00085         function setInstruction($a_instruction)
00086         {
00087                 $this->instruction = $a_instruction;
00088         }
00089         function getInstruction()
00090         {
00091                 return $this->instruction;
00092         }
00093         function getFiles()
00094         {
00095                 return $this->files;
00096         }
00097 
00098         function checkDate()
00099         {
00100                 return  $this->hour == (int) date("H",$this->timestamp) and
00101                         $this->minutes == (int) date("i",$this->timestamp) and
00102                         $this->day == (int) date("d",$this->timestamp) and
00103                         $this->month == (int) date("m",$this->timestamp) and
00104                         $this->year == (int) date("Y",$this->timestamp);
00105 
00106         }
00107 
00108         function deliverFile($a_http_post_files, $user_id)
00109         {
00110                 $deliver_result = $this->file_obj->deliverFile($a_http_post_files, $user_id);
00111                 if ($deliver_result)
00112                 {
00113                         $query = sprintf("INSERT INTO exc_returned ".
00114                                                          "(returned_id, obj_id, user_id, filename, filetitle, mimetype, TIMESTAMP) ".
00115                                                          "VALUES (NULL, %s, %s, %s, %s, %s, NULL)",
00116                                 $this->ilias->db->quote($this->getId() . ""),
00117                                 $this->ilias->db->quote($user_id . ""),
00118                                 $this->ilias->db->quote($deliver_result["fullname"]),
00119                                 $this->ilias->db->quote($a_http_post_files["name"]),
00120                                 $this->ilias->db->quote($deliver_result["mimetype"])
00121                         );
00122                         $this->ilias->db->query($query);
00123                         if (!$this->members_obj->isAssigned($user_id))
00124                         {
00125                                 $this->members_obj->assignMember($user_id);
00126                         }
00127                         $this->members_obj->setStatusReturnedForMember($user_id, 1);
00128                 }
00129                 return true;
00130         }
00131 
00132         function addUploadedFile($a_http_post_files)
00133         {
00134                 $this->file_obj->storeUploadedFile($a_http_post_files, true);
00135                 
00136                 return true;
00137         }
00138         function deleteFiles($a_files)
00139         {
00140                 $this->file_obj->unlinkFiles($a_files);
00141         }
00142 
00143         function saveData()
00144         {
00145                 
00146                 // SAVE ONLY EXERCISE SPECIFIC DATA
00147                 $query = "INSERT INTO exc_data SET ".
00148                         "obj_id = '".$this->getId()."', ".
00149                         "instruction = '".addslashes($this->getInstruction())."', ".
00150                         "time_stamp = ".$this->getTimestamp();
00151                 $this->ilias->db->query($query);
00152                 return true;
00153         }
00154 
00161         function ilClone($a_parent_ref)
00162         {               
00163                 global $rbacadmin;
00164 
00165                 // always call parent ilClone function first!!
00166                 $new_ref_id = parent::ilClone($a_parent_ref);
00167                 
00168                 // put here exc specific stuff
00169                 $tmp_obj =& $this->ilias->obj_factory->getInstanceByRefId($new_ref_id);
00170                 $tmp_obj->setInstruction($this->getInstruction());
00171                 $tmp_obj->setTimestamp($this->getTimestamp());
00172                 $tmp_obj->saveData();
00173 
00174                 // CLONE FILES
00175                 $tmp_file_obj =& new ilFileDataExercise($this->getId());
00176                 $tmp_file_obj->ilClone($tmp_obj->getId());
00177 
00178                 // CLONE MEMBERS
00179                 $tmp_members_obj =& new ilExerciseMembers($this->getId(),$new_ref_id);
00180                 $tmp_members_obj->ilClone($tmp_obj->getId());
00181 
00182                 // ... and finally always return new reference ID!!
00183                 return $new_ref_id;
00184         }
00185 
00192         function &getDeliveredFiles($user_id)
00193         {
00194                 $delivered_files =& $this->members_obj->getDeliveredFiles($user_id);
00195                 return $delivered_files;
00196         }
00197 
00204         function deleteDeliveredFiles($file_id_array, $user_id)
00205         {
00206                 $this->members_obj->deleteDeliveredFiles($file_id_array, $user_id);
00207 
00208                 // Finally update status 'returned' of member if no file exists
00209                 if(!count($this->members_obj->getDeliveredFiles($user_id)))
00210                 {
00211                         $this->members_obj->setStatusReturnedForMember($user_id,0);
00212                 }
00213 
00214         }
00215         
00221         function deliverReturnedFiles($user_id)
00222         {
00223                 require_once "./classes/class.ilUtil.php";
00224         }
00225 
00232         function delete()
00233         {               
00234                 // always call parent delete function first!!
00235                 if (!parent::delete())
00236                 {
00237                         return false;
00238                 }       
00239                 // put here course specific stuff
00240                 $query = "DELETE FROM exc_data ".
00241                         "WHERE obj_id = '".$this->getId()."'";
00242                 
00243                 $this->ilias->db->query($query);
00244 
00245                 $this->file_obj->delete();
00246                 $this->members_obj->delete();
00247 
00248                 return true;
00249         }
00250 
00261         function notify($a_event,$a_ref_id,$a_node_id,$a_params = 0)
00262         {
00263                 // object specific event handling
00264                 
00265                 parent::notify($a_event,$a_ref_id,$a_node_id,$a_params);
00266         }
00267 
00268         function read()
00269         {
00270                 parent::read();
00271 
00272                 $query = "SELECT * FROM exc_data ".
00273                         "WHERE obj_id = '".$this->getId()."'";
00274 
00275                 $res = $this->ilias->db->query($query);
00276                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00277                 {
00278                         $this->setInstruction($row->instruction);
00279                         $this->setTimestamp($row->time_stamp);
00280                 }
00281                 $this->members_obj =& new ilExerciseMembers($this->getId(),$this->getRefId());
00282                 $this->members_obj->read();
00283 
00284                 // GET FILE ASSIGNED TO EXERCISE
00285                 $this->file_obj = new ilFileDataExercise($this->getId());
00286                 $this->files = $this->file_obj->getFiles();
00287 
00288                 return true;
00289         }
00290 
00291         function update()
00292         {
00293                 parent::update();
00294 
00295                 $query = "UPDATE exc_data SET ".
00296                         "instruction = '".addslashes($this->getInstruction())."', ".
00297                         "time_stamp = '".$this->getTimestamp()."' ".
00298                         "WHERE obj_id = '".$this->getId()."'";
00299 
00300                 $res = $this->ilias->db->query($query);
00301 
00302                 #$this->members_obj->update();
00303                 return true;
00304         }
00305 
00306         function send($a_members)
00307         {
00308                 $files = $this->file_obj->getFiles();
00309                 if(count($files))
00310                 {
00311                         include_once "./classes/class.ilFileDataMail.php";
00312 
00313                         $mfile_obj = new ilFileDataMail($_SESSION["AccountId"]);
00314                         foreach($files as $file)
00315                         {
00316                                 $mfile_obj->copyAttachmentFile($this->file_obj->getAbsolutePath($file["name"]),$file["name"]);
00317                                 $file_names[] = $file["name"];
00318                         }
00319                 }
00320 
00321                 include_once "./classes/class.ilMail.php";
00322 
00323                 $tmp_mail_obj = new ilMail($_SESSION["AccountId"]);
00324                 $message = $tmp_mail_obj->sendMail($this->__formatRecipients($a_members),"","",$this->__formatSubject(),$this->__formatBody(),
00325                                                                                    count($file_names) ? $file_names : array(),array("normal"));
00326 
00327                 unset($tmp_mail_obj);
00328 
00329                 if(count($file_names))
00330                 {
00331                         $mfile_obj->unlinkFiles($file_names);
00332                         unset($mfile_obj);
00333                 }
00334 
00335 
00336                 // SET STATUS SENT FOR ALL RECIPIENTS
00337                 foreach($a_members as $member_id => $value)
00338                 {
00339                         $this->members_obj->setStatusSentForMember($member_id,1);
00340                 }
00341 
00342                 return true;
00343         }
00344 
00345 
00346         // PRIVATE METHODS
00347         function __formatBody()
00348         {
00349                 global $lng;
00350                 
00351                 $body = $this->getInstruction();
00352                 $body .= "\n";
00353                 $body .= $lng->txt("exc_edit_until") . ": ".date("Y-m-d",$this->getTimestamp());
00354 
00355                 return $body;
00356         }
00357 
00358         function __formatSubject()
00359         {
00360                 return $subject = $this->getTitle()." (".$this->getDescription().")";
00361         }
00362 
00363         function __formatRecipients($a_members)
00364         {
00365                 foreach($a_members as $member_id => $value)
00366                 {
00367                         $tmp_obj = ilObjectFactory::getInstanceByObjId($member_id); 
00368                         $tmp_members[] = $tmp_obj->getLogin();
00369 
00370                         unset($tmp_obj);
00371                 }
00372 
00373                 return implode(',',$tmp_members ? $tmp_members : array());
00374         }
00375 
00376         function _checkCondition($a_exc_id,$a_operator,$a_value)
00377         {
00378                 global $ilias;
00379 
00380                 switch($a_operator)
00381                 {
00382                         case 'passed':
00383                                 return ilExerciseMembers::_hasSolved($a_exc_id,$ilias->account->getId());
00384 
00385                         default:
00386                                 return true;
00387                 }
00388                 return true;
00389         }
00390                 
00396         function _goto($a_target)
00397         {
00398                 global $rbacsystem, $ilErr, $lng, $ilAccess;
00399 
00400                 include_once 'classes/class.ilSearch.php';
00401                         
00402                 // Added this additional check (ParentConditions) to avoid calls of objects inside e.g courses.
00403                 // Will be replaced in future releases by ilAccess::checkAccess()
00404                 //if ($rbacsystem->checkAccess("read", $a_target) and ilSearch::_checkParentConditions($a_target))
00405                 if ($ilAccess->checkAccess("read", "", $a_target))
00406                 {
00407                         ilUtil::redirect("exercise.php?ref_id=$a_target");
00408                 }
00409                 else
00410                 {
00411                         $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
00412                 }
00413         }               
00414 } //END class.ilObjExercise
00415 ?>

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