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

webservice/soap/classes/class.ilSoapExerciseAdministration.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 
00024 
00033 include_once './webservice/soap/classes/class.ilSoapAdministration.php';
00034 
00035 class ilSoapExerciseAdministration extends ilSoapAdministration
00036 {
00037         function ilSoapExerciseAdministration()
00038         {
00039                 parent::ilSoapAdministration();
00040         }
00041 
00051         function addExercise ($sid, $target_id, $exercise_xml) {
00052                 if(!$this->__checkSession($sid))
00053                 {
00054                         return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
00055                 }
00056                 include_once './include/inc.header.php';
00057                 global $rbacsystem, $tree, $ilLog;
00058 
00059                 if(!$target_obj =& ilObjectFactory::getInstanceByRefId($target_id,false))
00060                 {
00061                         return $this->__raiseError('No valid target given.', 'Client');
00062                 }
00063 
00064                 if(ilObject::_isInTrash($target_id))
00065                 {
00066                         return $this->__raiseError("Parent with ID $target_id has been deleted.", 'CLIENT_OBJECT_DELETED');
00067                 }
00068 
00069                 // Check access
00070                 $allowed_types = array('cat','grp','crs','fold');
00071                 if(!in_array($target_obj->getType(), $allowed_types))
00072                 {
00073                         return $this->__raiseError('No valid target type. Target must be reference id of "course, group, category or folder"', 'Client');
00074                 }
00075 
00076                 if(!$rbacsystem->checkAccess('create',$target_id,"exc"))
00077                 {
00078                         return $this->__raiseError('No permission to create exercises in target  '.$target_id.'!', 'Client');
00079                 }
00080 
00081                 // create object, put it into the tree and use the parser to update the settings
00082                 include_once './Modules/Exercise/classes/class.ilObjExercise.php';
00083                 include_once './Modules/Exercise/classes/class.ilExerciseXMLParser.php';
00084                 include_once './Modules/Exercise/classes/class.ilExerciseException.php';
00085 
00086 
00087                 $exercise = new ilObjExercise();
00088                 $exercise->create();
00089                 $exercise->createReference();
00090                 $exercise->putInTree($target_id);
00091                 $exercise->setPermissions($target_id);
00092                 $exercise->saveData();
00093 
00094                 // we need this as workaround because file and member objects need to be initialised
00095                 $exercise->read();
00096 
00097                 $exerciseXMLParser = new ilExerciseXMLParser($exercise, $exercise_xml);
00098                 try
00099                 {
00100                         return $exerciseXMLParser->start() &&  $exercise->update() ? $exercise->getRefId() : -1;
00101                 } catch(ilExerciseException $exception) {
00102                         return $this->__raiseError($exception->getMessage(),
00103                                                                         $exception->getCode() == ilExerciseException::$ID_MISMATCH ? "Client" : "Server");
00104                 }
00105         }
00106 
00107 
00117         function updateExercise ($sid, $ref_id, $exercise_xml) {
00118                 if(!$this->__checkSession($sid))
00119                 {
00120                         return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
00121                 }
00122                 include_once './include/inc.header.php';
00123                 global $rbacsystem, $tree, $ilLog;
00124 
00125                 if(ilObject::_isInTrash($ref_id))
00126                 {
00127                         return $this->__raiseError('Cannot perform update since exercise has been deleted.', 'CLIENT_OBJECT_DELETED');
00128                 }
00129                 // get obj_id
00130                 if(!$obj_id = ilObject::_lookupObjectId($ref_id))
00131                 {
00132                         return $this->__raiseError('No exercise found for id: '.$ref_id,
00133                                                                            'CLIENT_OBJECT_NOT_FOUND');
00134                 }
00135 
00136                 // Check access
00137                 $permission_ok = false;
00138                 foreach($ref_ids = ilObject::_getAllReferences($obj_id) as $ref_id)
00139                 {
00140                         if($rbacsystem->checkAccess('edit',$ref_id))
00141                         {
00142                                 $permission_ok = true;
00143                                 break;
00144                         }
00145                 }
00146 
00147                 if(!$permission_ok)
00148                 {
00149                         return $this->__raiseError('No permission to edit the exercise with id: '.$ref_id,
00150                                                                         'Server');
00151                 }
00152 
00153 
00154                 $exercise = ilObjectFactory::getInstanceByObjId($obj_id, false);
00155 
00156                 if (!is_object($exercise) || $exercise->getType()!= "exc")
00157                 {
00158                         return $this->__raiseError('Wrong obj id or type for exercise with id '.$ref_id,
00159                                                                         'CLIENT_OBJECT_NOI_FOUND');
00160                 }
00161 
00162                 include_once './Modules/Exercise/classes/class.ilExerciseXMLParser.php';
00163                 include_once './Modules/Exercise/classes/class.ilExerciseException.php';
00164                 $exerciseXMLParser = new ilExerciseXMLParser($exercise, $exercise_xml, $obj_id);
00165 
00166                 try
00167                 {
00168                         return $exerciseXMLParser->start() && $exercise->update();
00169                 } catch(ilExerciseException $exception) {
00170                         return $this->__raiseError($exception->getMessage(),
00171                                                                            $exception->getCode() == ilExerciseException::$ID_MISMATCH ? "Client" : "Server");
00172                 }
00173                 return false;
00174         }
00175 
00186         function getExerciseXML ($sid, $ref_id, $attachFileContentsMode) {
00187                 if(!$this->__checkSession($sid))
00188                 {
00189                         return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
00190                 }
00191                 if(!strlen($ref_id))
00192                 {
00193                         return $this->__raiseError('No ref id given. Aborting!',
00194                                                                            'Client');
00195                 }
00196                 include_once './include/inc.header.php';
00197                 global $rbacsystem, $tree, $ilLog;
00198 
00199                 // get obj_id
00200                 if(!$obj_id = ilObject::_lookupObjectId($ref_id))
00201                 {
00202                         return $this->__raiseError('No exercise found for id: '.$ref_id,
00203                                                                            'Client');
00204                 }
00205 
00206                 if(ilObject::_isInTrash($ref_id))
00207                 {
00208                         return $this->__raiseError("Parent with ID $ref_id has been deleted.", 'Client');
00209                 }
00210 
00211 
00212 
00213                 // Check access
00214                 $permission_ok = false;
00215                 foreach($ref_ids = ilObject::_getAllReferences($obj_id) as $ref_id)
00216                 {
00217                         if($rbacsystem->checkAccess('read',$ref_id))
00218                         {
00219                                 $permission_ok = true;
00220                                 break;
00221                         }
00222                 }
00223 
00224                 if(!$permission_ok)
00225                 {
00226                         return $this->__raiseError('No permission to edit the object with id: '.$ref_id,
00227                                                                            'Server');
00228                 }
00229 
00230                 $exercise = ilObjectFactory::getInstanceByObjId($obj_id, false);
00231 
00232                 if (!is_object($exercise) || $exercise->getType()!= "exc")
00233                 {
00234                         return $this->__raiseError('Wrong obj id or type for exercise with id '.$ref_id,
00235                                                                            'Server');
00236                 }
00237                 // store into xml result set
00238                 include_once './Modules/Exercise/classes/class.ilExerciseXMLWriter.php';
00239 
00240                 // create writer
00241                 $xmlWriter = new ilExerciseXMLWriter();
00242                 $xmlWriter->setExercise($exercise);
00243                 $xmlWriter->setAttachFileContents($attachFileContentsMode);
00244                 $xmlWriter->start();
00245 
00246                 return $xmlWriter->getXML();
00247         }
00248 }
00249 ?>

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