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

webservice/soap/classes/class.ilSoapObjectAdministration.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 
00033 include_once './webservice/soap/classes/class.ilSoapAdministration.php';
00034 
00035 class ilSoapObjectAdministration extends ilSoapAdministration
00036 {
00037         function ilSoapObjectAdministration()
00038         {
00039                 parent::ilSoapAdministration();
00040         }
00041 
00042         function getObjIdByImportId($sid,$import_id)
00043         {
00044                 if(!$this->__checkSession($sid))
00045                 {
00046                         return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
00047                 }
00048                 if(!$import_id)
00049                 {
00050                         return $this->__raiseError('No import id given.',
00051                                                                            'Client');
00052                 }
00053 
00054                 // Include main header
00055                 include_once './include/inc.header.php';
00056                 global $ilLog;
00057 
00058                 $obj_id = ilObject::_lookupObjIdByImportId($import_id);
00059                 $ilLog->write("SOAP getObjIdByImportId(): import_id = ".$import_id.' obj_id = '.$obj_id);
00060 
00061                 return $obj_id ? $obj_id : "0";
00062         }
00063 
00064         function getRefIdsByImportId($sid,$import_id)
00065         {
00066                 global $tree;
00067 
00068                 if(!$this->__checkSession($sid))
00069                 {
00070                         return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
00071                 }
00072                 if(!$import_id)
00073                 {
00074                         return $this->__raiseError('No import id given.',
00075                                                                            'Client');
00076                 }
00077 
00078                 // Include main header
00079                 include_once './include/inc.header.php';
00080                 global $tree;
00081 
00082                 $obj_id = ilObject::_lookupObjIdByImportId($import_id);
00083 
00084 
00085                 $ref_ids = ilObject::_getAllReferences($obj_id);
00086 
00087                 foreach($ref_ids as $ref_id)
00088                 {
00089                         // only get non deleted reference ids
00090                         if ($tree->isInTree($ref_id))
00091                         {
00092                                 $new_refs[] = $ref_id;
00093                         }
00094                 }
00095                 return $new_refs ? $new_refs : array();
00096         }
00097 
00098         function getRefIdsByObjId($sid,$obj_id)
00099         {
00100                 if(!$this->__checkSession($sid))
00101                 {
00102                         return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
00103                 }
00104                 if(!$obj_id)
00105                 {
00106                         return $this->__raiseError('No object id given.',
00107                                                                            'Client');
00108                 }
00109 
00110                 // Include main header
00111                 include_once './include/inc.header.php';
00112 
00113                 $ref_ids = ilObject::_getAllReferences($obj_id);
00114                 foreach($ref_ids as $ref_id)
00115                 {
00116                         $new_refs[] = $ref_id;
00117                 }
00118                 return $new_refs ? $new_refs : array();
00119         }
00120 
00129         function getObjIdsByRefIds($sid, $ref_ids)
00130         {
00131                 if(!$this->__checkSession($sid))
00132                 {
00133                         return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
00134                 }
00135 
00136 
00137                 // Include main header
00138                 include_once './include/inc.header.php';
00139 
00140                 if(!count($ref_ids) || !is_array ($ref_ids))
00141                 {
00142                         return $this->__raiseError('No reference id(s) given.', 'Client');
00143                 }
00144 
00145                 $obj_ids = array();
00146                 if (count($ref_ids)) {
00147                         foreach ($ref_ids as $ref_id)
00148                         {
00149                                 $ref_id = trim($ref_id);
00150                                 if (!is_numeric($ref_id)){
00151                                         return $this->__raiseError('Reference ID has to be numeric. Value: '.$ref_id, 'Client');
00152                                 }
00153 
00154                                 $obj_id = ilObject::_lookupObjectId($ref_id);
00155                                 if (!$obj_id){
00156                                         return $this->__raiseError('No object found for reference ID. Value: '.$ref_id, 'Client');
00157                                 }
00158                                 if (!ilObject::_hasUntrashedReference($obj_id)){
00159                                         return $this->__raiseError('No untrashed reference found for reference ID. Value: '.$ref_id, 'Client');
00160                                 }
00161                                 $obj_ids[] = $obj_id;
00162                         }
00163                 }
00164                 return $obj_ids;
00165         }
00166 
00167 
00168 
00169         function getObjectByReference($sid,$a_ref_id,$user_id)
00170         {
00171                 if(!$this->__checkSession($sid))
00172                 {
00173                         return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
00174                 }
00175                 if(!is_numeric($a_ref_id))
00176                 {
00177                         return $this->__raiseError('No valid reference id given. Please choose an existing reference id of an ILIAS object',
00178                                                                            'Client');
00179                 }
00180 
00181                 // Include main header
00182                 include_once './include/inc.header.php';
00183 
00184                 if(!$tmp_obj = ilObjectFactory::getInstanceByRefId($a_ref_id,false))
00185                 {
00186                         return $this->__raiseError('Cannot create object instance!','Server');
00187                 }
00188 
00189 
00190                 if(ilObject::_isInTrash($a_ref_id))
00191                 {
00192                         return $this->__raiseError("Object with ID $a_ref_id has been deleted.", 'Client');
00193                 }
00194 
00195                 include_once './webservice/soap/classes/class.ilObjectXMLWriter.php';
00196 
00197                 $xml_writer = new ilObjectXMLWriter();
00198                 if($user_id)
00199                 {
00200                         $xml_writer->setUserId($user_id);
00201                         $xml_writer->enableOperations(true);
00202                 }
00203                 $xml_writer->setObjects(array($tmp_obj));
00204                 if($xml_writer->start())
00205                 {
00206                         return $xml_writer->getXML();
00207                 }
00208 
00209                 return $this->__raiseError('Cannot create object xml !','Server');
00210         }
00211 
00212         function getObjectsByTitle($sid,$a_title,$user_id)
00213         {
00214                 if(!$this->__checkSession($sid))
00215                 {
00216                         return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
00217                 }
00218                 if(!strlen($a_title))
00219                 {
00220                         return $this->__raiseError('No valid query string given.',
00221                                                                            'Client');
00222                 }
00223 
00224                 // Include main header
00225                 include_once './include/inc.header.php';
00226 
00227                 include_once './Services/Search/classes/class.ilQueryParser.php';
00228 
00229                 $query_parser =& new ilQueryParser($a_title);
00230                 $query_parser->setMinWordLength(0);
00231                 $query_parser->setCombination(QP_COMBINATION_AND);
00232                 $query_parser->parse();
00233                 if(!$query_parser->validate())
00234                 {
00235                         return $this->__raiseError($query_parser->getMessage(),
00236                                                                            'Client');
00237                 }
00238 
00239                 include_once './Services/Search/classes/class.ilObjectSearchFactory.php';
00240 
00241                 $object_search =& ilObjectSearchFactory::_getObjectSearchInstance($query_parser);
00242                 $object_search->setFields(array('title'));
00243                 $object_search->appendToFilter('role');
00244                 $object_search->appendToFilter('rolt');
00245                 $res =& $object_search->performSearch();
00246                 if($user_id)
00247                 {
00248                         $res->setUserId($user_id);
00249                 }
00250 
00251                 $res->filter(ROOT_FOLDER_ID,true);
00252 
00253                 $objs = array();
00254                 foreach($res->getUniqueResults() as $entry)
00255                 {
00256                         $objs[] = ilObjectFactory::getInstanceByObjId($entry['obj_id'],false);
00257                 }
00258                 if(!count($objs))
00259                 {
00260                         return '';
00261                 }
00262 
00263                 include_once './webservice/soap/classes/class.ilObjectXMLWriter.php';
00264 
00265                 $xml_writer = new ilObjectXMLWriter();
00266                 if($user_id)
00267                 {
00268                         $xml_writer->setUserId($user_id);
00269                         $xml_writer->enableOperations(true);
00270                 }
00271                 $xml_writer->setObjects($objs);
00272                 if($xml_writer->start())
00273                 {
00274                         return $xml_writer->getXML();
00275                 }
00276 
00277                 return $this->__raiseError('Cannot create object xml !','Server');
00278         }
00279 
00280         function searchObjects($sid,$types,$key,$combination,$user_id)
00281         {
00282                 if(!$this->__checkSession($sid))
00283                 {
00284                         return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
00285                 }
00286                 if(!is_array($types))
00287                 {
00288                         return $this->__raiseError('Types must be an array of object types.',
00289                                                                            'Client');
00290                 }
00291                 if($combination != 'and' and $combination != 'or')
00292                 {
00293                         return $this->__raiseError('No valid combination given. Must be "and" or "or".',
00294                                                                            'Client');
00295                 }
00296 
00297 
00298                 // Include main header
00299                 include_once './include/inc.header.php';
00300 
00301                 include_once './Services/Search/classes/class.ilQueryParser.php';
00302 
00303                 $query_parser =& new ilQueryParser($key);
00304                 $query_parser->setMinWordLength(3);
00305                 $query_parser->setCombination($combination == 'and' ? QP_COMBINATION_AND : QP_COMBINATION_OR);
00306                 $query_parser->parse();
00307                 if(!$query_parser->validate())
00308                 {
00309                         return $this->__raiseError($query_parser->getMessage(),
00310                                                                            'Client');
00311                 }
00312 
00313                 include_once './Services/Search/classes/class.ilObjectSearchFactory.php';
00314 
00315                 $object_search =& ilObjectSearchFactory::_getObjectSearchInstance($query_parser);
00316                 $object_search->setFilter($types);
00317 
00318                 $res =& $object_search->performSearch();
00319                 if($user_id)
00320                 {
00321                         $res->setUserId($user_id);
00322                 }
00323                 $res->setMaxHits(999999);
00324                 $res->filter(ROOT_FOLDER_ID,$combination == 'and' ? true : false);
00325 
00326 
00327                 // Limit to 30 objects
00328                 $counter = 0;
00329                 $objs = array();
00330                 foreach($res->getUniqueResults() as $entry)
00331                 {
00332                         /*if(++$counter == 30)
00333                         {
00334                                 break;
00335                         }*/
00336                         $objs[] = ilObjectFactory::getInstanceByObjId($entry['obj_id'],false);
00337                 }
00338                 if(!count($objs))
00339                 {
00340                         return '';
00341                 }
00342 
00343                 include_once './webservice/soap/classes/class.ilObjectXMLWriter.php';
00344 
00345                 $xml_writer = new ilObjectXMLWriter();
00346 
00347                 if($user_id)
00348                 {
00349                         $xml_writer->setUserId($user_id);
00350                         $xml_writer->enableOperations(true);
00351                 }
00352                 $xml_writer->setObjects($objs);
00353                 if($xml_writer->start())
00354                 {
00355                         return $xml_writer->getXML();
00356                 }
00357 
00358                 return $this->__raiseError('Cannot create object xml !','Server');
00359         }
00360 
00361         function getTreeChilds($sid,$ref_id,$types,$user_id)
00362         {
00363                 $all = false;
00364 
00365                 if(!$this->__checkSession($sid))
00366                 {
00367                         return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
00368                 }
00369 
00370                 // Include main header
00371                 include_once './include/inc.header.php';
00372                 global $tree;
00373 
00374                 if(!$target_obj =& ilObjectFactory::getInstanceByRefId($ref_id,false))
00375                 {
00376                         return $this->__raiseError('No valid reference id given.',
00377                                                                            'Client');
00378                 }
00379                 if (intval($ref_id) == SYSTEM_FOLDER_ID) {
00380                     return $this->__raiseError('No valid reference id given.',
00381                                                                            'Client');
00382                 }
00383 
00384                 if(!$types)
00385                 {
00386                         $all = true;
00387                 }
00388                 $filter = is_array($types) ? $types : array();
00389 
00390                 $objs = array();
00391                 foreach($tree->getChilds($ref_id,'title') as $child)
00392                 {
00393                         if($all or in_array($child['type'],$types))
00394                         {
00395                                 if($tmp = ilObjectFactory::getInstanceByRefId($child['ref_id'],false))
00396                                 {
00397                                         $objs[] = $tmp;
00398                                 }
00399                         }
00400                 }
00401 
00402                 /*if(!$objs)
00403                 {
00404                         return '';
00405                 }*/
00406 
00407                 include_once './webservice/soap/classes/class.ilObjectXMLWriter.php';
00408 
00409                 $xml_writer = new ilObjectXMLWriter();
00410                 $xml_writer->setObjects($objs);
00411                 $xml_writer->enableOperations(true);
00412                 if($user_id)
00413                 {
00414                         $xml_writer->setUserId($user_id);
00415                 }
00416 
00417                 if($xml_writer->start())
00418                 {
00419                         return $xml_writer->getXML();
00420                 }
00421 
00422                 return $this->__raiseError('Cannot create object xml !','Server');
00423         }
00424 
00425         function getXMLTree($sid,$ref_id,$types,$user_id) {
00426 
00427           if(!$this->__checkSession($sid))
00428             {
00429               return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
00430             }
00431 
00432           include_once './include/inc.header.php';
00433 
00434           global $tree;
00435 
00436           $nodedata  = $tree->getNodeData($ref_id);
00437 
00438           $nodearray = $tree->getSubTree($nodedata);
00439 
00440           $filter = is_array($types) ? $types :  array("0" => "root","adm","lngf","mail",
00441                             "usrf","rolf","taxf","trac","pays",
00442                             "auth","chac","objf","recf","assf",
00443                             "stys","seas","extt");
00444 
00445           foreach($nodearray as $node) {
00446             if (!in_array($node['type'], $filter)) {
00447               if ($tmp = ilObjectFactory::getInstanceByRefId($node['ref_id'],false)) {
00448                 $nodes[] = $tmp;
00449               }
00450             }
00451           }
00452 
00453 
00454           include_once './webservice/soap/classes/class.ilObjectXMLWriter.php';
00455 
00456           $xml_writer = new ilObjectXMLWriter();
00457           $xml_writer->setObjects($nodes);
00458           $xml_writer->enableOperations(false);
00459 
00460           if($user_id)
00461             {
00462               $xml_writer->setUserId($user_id);
00463             }
00464 
00465           if($xml_writer->start())
00466             {
00467               return $xml_writer->getXML();
00468             }
00469 
00470           return $this->__raiseError('Cannot create object xml !','Server');
00471         }
00472 
00473 
00474         function addObject($sid,$a_target_id,$a_xml)
00475         {
00476                 if(!$this->__checkSession($sid))
00477                 {
00478                         return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
00479                 }
00480                 if(!strlen($a_xml))
00481                 {
00482                         return $this->__raiseError('No valid xml string given.',
00483                                                                            'Client');
00484                 }
00485 
00486                 // Include main header
00487                 include_once './include/inc.header.php';
00488                 global $rbacsystem, $objDefinition,$ilUser, $lng;
00489 
00490                 if(!$target_obj =& ilObjectFactory::getInstanceByRefId($a_target_id,false))
00491                 {
00492                         return $this->__raiseError('No valid target given.',
00493                                                                            'Client');
00494                 }
00495 
00496                 if(ilObject::_isInTrash($a_target_id))
00497                 {
00498                         return $this->__raiseError("Parent with ID $a_target_id has been deleted.", 'Client');
00499                 }
00500 
00501                 $allowed_types = array('root','cat','grp','crs','fold');
00502                 if(!in_array($target_obj->getType(),$allowed_types))
00503                 {
00504                         return $this->__raiseError('No valid target type. Target must be reference id of "course, group, category or folder"',
00505                                                                            'Client');
00506                 }
00507 
00508                 $allowed_subtypes = $objDefinition->getSubObjects($target_obj->getType());
00509 
00510                 foreach($allowed_subtypes as $row)
00511                 {
00512                         if($row['name'] != 'rolf')
00513                         {
00514                                 $allowed[] = $row['name'];
00515                         }
00516                 }
00517 
00518                 include_once './webservice/soap/classes/class.ilObjectXMLParser.php';
00519                 
00520                 $xml_parser =& new ilObjectXMLParser($a_xml, true);
00521                 try {
00522                         $xml_parser->startParsing();
00523                 } catch (ilSaxParserException $se){
00524                         return $this->__raiseError($se->getMessage(), $se->getCode());
00525                 }
00526 
00527                 foreach($xml_parser->getObjectData() as $object_data)
00528                 {
00529                         // Check possible subtype
00530                         if(!in_array($object_data['type'],$allowed))
00531                         {
00532                                 return $this->__raiseError('Objects of type: '.$object_data['type'].' are not allowed to be subobjects of type '.
00533                                                                                    $target_obj->getType().'!',
00534                                                                                    'Client');
00535                         }
00536                         if(!$rbacsystem->checkAccess('create',$a_target_id,$object_data['type']))
00537                         {
00538                                 return $this->__raiseError('No permission to create objects of type '.$object_data['type'].'!',
00539                                                                                    'Client');
00540                         }
00541                         if($object_data['type'] == 'crs')
00542                         {
00543                                 return $this->__raiseError('Cannot create course objects. Use method addCourse() ',
00544                                                                                    'Client');
00545                         }
00546 
00547                         // It's not possible to add objects with non unique import ids
00548                         if(strlen($object_data['import_id']) and ilObject::_lookupObjIdByImportId($object_data['import_id']))
00549                         {
00550                                 return $this->__raiseError('An object with import id '.$object_data['import_id'].' already exists!',
00551                                                                                    'Server');
00552                         }
00553 
00554 
00555 
00556                         // call gui object method
00557                         $class_name = $objDefinition->getClassName($object_data['type']);
00558                         $module = $objDefinition->getModule($object_data['type']);
00559                         $module_dir = ($module == "")
00560                                 ? ""
00561                                 : $module."/";
00562 
00563                         $class_constr = "ilObj".$class_name;
00564                         require_once("./".$module_dir."classes/class.ilObj".$class_name.".php");
00565 
00566                         $newObj = new $class_constr();
00567 
00568                         $newObj->setType($object_data['type']);
00569                         if(strlen($object_data['import_id']))
00570                         {
00571                                 $newObj->setImportId($object_data['import_id']);
00572                         }
00573                         $newObj->setTitle($object_data['title']);
00574                         $newObj->setDescription($object_data['description']);
00575                         $newObj->create(); // true for upload
00576                         $newObj->createReference();
00577                         $newObj->putInTree($a_target_id);
00578                         $newObj->setPermissions($a_target_id);
00579                         $newObj->initDefaultRoles();
00580 
00581                         switch($object_data['type'])
00582                         {
00583                                 case 'grp':
00584                                         // Add member
00585                                         $newObj->addMember($object_data['owner'] ? $object_data['owner'] : $ilUser->getId(),
00586                                                                            $newObj->getDefaultAdminRole());
00587                                         break;
00588 
00589                                 case 'lm':
00590                                 case 'dbk':
00591                                         $newObj->createLMTree();
00592                                         break;
00593                                 case 'cat':
00594                                         $newObj->addTranslation($object_data["title"],$object_data["description"], $lng->getLangKey(), $lng->getLangKey());
00595                                         break;
00596                         }
00597 
00598                 }
00599                 $ref_id = $newObj->getRefId();
00600                 return  $ref_id  ? $ref_id : "0";               
00601         }
00602 
00603         function addReference($sid,$a_source_id,$a_target_id)
00604         {
00605                 if(!$this->__checkSession($sid))
00606                 {
00607                         return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
00608                 }
00609                 if(!is_numeric($a_source_id))
00610                 {
00611                         return $this->__raiseError('No source id given.',
00612                                                                            'Client');
00613                 }
00614                 if(!is_numeric($a_target_id))
00615                 {
00616                         return $this->__raiseError('No target id given.',
00617                                                                            'Client');
00618                 }
00619 
00620                 include_once './include/inc.header.php';
00621                 global $objDefinition, $rbacsystem, $tree;
00622 
00623                 if(!$source_obj =& ilObjectFactory::getInstanceByRefId($a_source_id,false))
00624                 {
00625                         return $this->__raiseError('No valid source id given.',
00626                                                                            'Client');
00627                 }
00628                 if(!$target_obj =& ilObjectFactory::getInstanceByRefId($a_target_id,false))
00629                 {
00630                         return $this->__raiseError('No valid target id given.',
00631                                                                            'Client');
00632                 }
00633 
00634                 if(!$objDefinition->allowLink($source_obj->getType()))
00635                 {
00636                         return $this->__raiseError('Linking of object type: '.$source_obj->getType().' is not allowed',
00637                                                                            'Client');
00638                 }
00639 
00640                 $allowed_subtypes = $objDefinition->getSubObjects($target_obj->getType());
00641                 foreach($allowed_subtypes as $row)
00642                 {
00643                         if($row['name'] != 'rolf')
00644                         {
00645                                 $allowed[] = $row['name'];
00646                         }
00647                 }
00648                 if(!in_array($source_obj->getType(),$allowed))
00649                 {
00650                         return $this->__raiseError('Objects of type: '.$source_obj->getType().' are not allowed to be subobjects of type '.
00651                                                                            $target_obj->getType().'!',
00652                                                                            'Client');
00653                 }
00654 
00655                 // Permission checks
00656                 if(!$rbacsystem->checkAccess('create',$target_obj->getRefId(),$source_obj->getType()))
00657                 {
00658                         return $this->__raiseError('No permission to create objects of type '.$source_obj->getType().'!',
00659                                                                            'Client');
00660                 }
00661                 if(!$rbacsystem->checkAccess('delete',$source_obj->getRefId()))
00662                 {
00663                         return $this->__raiseError('No permission to link object with id: '.$source_obj->getRefId().'!',
00664                                                                            'Client');
00665                 }
00666                 // check if object already linked to target
00667                 $possibleChilds = $tree->getChildsByType($target_obj->getRefId(), $source_obj->getType());
00668                 foreach ($possibleChilds as $child) 
00669                 {
00670                         if ($child["obj_id"] == $source_obj->getId())
00671                                 return $this->__raiseError("Object already linked to target.","Client");
00672                 }
00673                 
00674                 // Finally link it to target position
00675 
00676                 $new_ref_id = $source_obj->createReference();
00677                 $source_obj->putInTree($target_obj->getRefId());
00678                 $source_obj->setPermissions($target_obj->getRefId());
00679                 $source_obj->initDefaultRoles();
00680 
00681                 return $new_ref_id ? $new_ref_id : "0";
00682         }
00683 
00684         function deleteObject($sid,$reference_id)
00685         {
00686                 global $tree;
00687 
00688                 if(!$this->__checkSession($sid))
00689                 {
00690                         return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
00691                 }
00692                 if(!is_numeric($reference_id))
00693                 {
00694                         return $this->__raiseError('No reference id given.',
00695                                                                            'Client');
00696                 }
00697                 include_once './include/inc.header.php';
00698                 global $tree, $rbacsystem, $rbacadmin;
00699 
00700                 if(!$del_obj =& ilObjectFactory::getInstanceByRefId($reference_id,false))
00701                 {
00702                         return $this->__raiseError('No valid reference id given.',
00703                                                                            'Client');
00704                 }
00705                 if(!$rbacsystem->checkAccess('delete',$del_obj->getRefId()))
00706                 {
00707                         return $this->__raiseError('No permission to delete object with id: '.$del_obj->getRefId().'!',
00708                                                                            'Client');
00709                 }
00710                 
00711                 if($del_obj->getType() == 'rolf')
00712                 {
00713                         return $this->__raiseError('Delete is not available for role folders.','Client');
00714                 }
00715 
00716                 // Delete tree
00717                 if($tree->isDeleted($reference_id))
00718                 {
00719                         return $this->__raiseError('Node already deleted','Server');
00720                 }
00721 
00722                 $subnodes = $tree->getSubtree($tree->getNodeData($reference_id));
00723                 foreach($subnodes as $subnode)
00724                 {
00725                         $rbacadmin->revokePermission($subnode["child"]);
00726                         // remove item from all user desktops
00727                         $affected_users = ilUtil::removeItemFromDesktops($subnode["child"]);
00728                 }
00729                 if(!$tree->saveSubTree($reference_id))
00730                 {
00731                         return $this->__raiseError('Node already deleted','Client');
00732                 }
00733 
00734                 return true;
00735         }
00736 
00737         function removeFromSystemByImportId($sid,$import_id)
00738         {
00739                 if(!$this->__checkSession($sid))
00740                 {
00741                         return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
00742                 }
00743                 if(!strlen($import_id))
00744                 {
00745                         return $this->__raiseError('No import id given. Aborting!',
00746                                                                            'Client');
00747                 }
00748                 include_once './include/inc.header.php';
00749                 global $rbacsystem, $tree, $ilLog;
00750 
00751                 // get obj_id
00752                 if(!$obj_id = ilObject::_lookupObjIdByImportId($import_id))
00753                 {
00754                         return $this->__raiseError('No object found with import id: '.$import_id,
00755                                                                            'Client');
00756                 }
00757 
00758                 // Check access
00759                 $permission_ok = false;
00760                 foreach($ref_ids = ilObject::_getAllReferences($obj_id) as $ref_id)
00761                 {
00762                         if($rbacsystem->checkAccess('delete',$ref_id))
00763                         {
00764                                 $permission_ok = true;
00765                                 break;
00766                         }
00767                 }
00768                 if(!$permission_ok)
00769                 {
00770                         return $this->__raiseError('No permission to delete the object with import id: '.$import_id,
00771                                                                            'Server');
00772                 }
00773 
00774                 // Delete all references (delete permssions and entries in object_reference)
00775                 foreach($ref_ids as $ref_id)
00776                 {
00777                         // All subnodes
00778                         $node_data = $tree->getNodeData($ref_id);
00779                         $subtree_nodes = $tree->getSubtree($node_data);
00780 
00781                         foreach($subtree_nodes as $node)
00782                         {
00783                                 $ilLog->write('Soap: removeFromSystemByImportId(). Deleting object with title id: '.$node['title']);
00784                                 $tmp_obj = ilObjectFactory::getInstanceByRefId($node['ref_id']);
00785                                 if(!is_object($tmp_obj))
00786                                 {
00787                                         return $this->__raiseError('Cannot create instance of reference id: '.$node['ref_id'],
00788                                                                                            'Server');
00789                                 }
00790                                 $tmp_obj->delete();
00791                         }
00792                         // Finally delete tree
00793                         $tree->deleteTree($node_data);
00794 
00795                 }
00796 
00797                 return true;
00798         }
00799 
00800 
00801         function updateObjects($sid,$a_xml)
00802         {
00803                 if(!$this->__checkSession($sid))
00804                 {
00805                         return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
00806                 }
00807                 if(!strlen($a_xml))
00808                 {
00809                         return $this->__raiseError('No valid xml string given.',
00810                                                                            'Client');
00811                 }
00812 
00813                 // Include main header
00814                 include_once './include/inc.header.php';
00815                 global $rbacreview, $rbacsystem, $lng;
00816 
00817                 include_once './webservice/soap/classes/class.ilObjectXMLParser.php';
00818                 $xml_parser =& new ilObjectXMLParser($a_xml, true);
00819                 try {
00820                         $xml_parser->startParsing();
00821                 } catch (ilSaxParserException $se){
00822                         return $this->__raiseError($se->getMessage(), $se->getCode());
00823                 }
00824 
00825 
00826                 // Validate incoming data
00827                 $object_datas = $xml_parser->getObjectData();
00828                 foreach($object_datas as & $object_data)
00829                 {
00830                         if(!$object_data["obj_id"])
00831                         {
00832                                 return $this->__raiseError('No obj_id in xml found.', 'Client');
00833                         }
00834                         elseif ((int) $object_data["obj_id"] == -1 && count($object_data["references"])>0)
00835                         {
00836                                 // object id might be unknown, resolve references instead to determine object id
00837                                 // all references should point to the same object, so using the first one is ok.
00838                                 foreach ($object_data["references"] as $refid) 
00839                                 {
00840                                         if(ilObject::_isInTrash($refid))
00841                                         {
00842                                                 continue;
00843                                         }
00844                                         break;
00845                                 }       
00846                                 
00847                                 $obj_id_from_refid = ilObject::_lookupObjectId($object_data["references"][0], false);
00848                                 if (!$obj_id_from_refid)
00849                                 {
00850                                         return $this->__raiseError('No obj_id found for reference id '.$object_data["references"][0], 'CLIENT_OBJECT_NOT_FOUND');
00851                                 } else
00852                                 {
00853                                         $tmp_obj = ilObjectFactory::getInstanceByObjId($object_data['obj_id'], false);
00854                                         $object_data["obj_id"] = $obj_id_from_refid;
00855                                 }
00856                         }
00857                         
00858                         $tmp_obj = ilObjectFactory::getInstanceByObjId($object_data['obj_id'], false);
00859                         if ($tmp_obj == null)
00860                         {
00861                                 return $this->__raiseError('No object for id '.$object_data['obj_id'].'!', 'CLIENT_OBJECT_NOT_FOUND');
00862                         } 
00863                         else 
00864                         {
00865                                 $object_data["instance"] = $tmp_obj;
00866                         }
00867                         
00868                         if($object_data['type'] == 'role')
00869                         {
00870                                 $rolf_ids = $rbacreview->getFoldersAssignedToRole($object_data['obj_id'],true);
00871                                 $rolf_id = $rolf_ids[0];
00872 
00873                                 if(!$rbacsystem->checkAccess('write',$rolf_id))
00874                                 {
00875                                         return $this->__raiseError('No write permission for object with id '.$object_data['obj_id'].'!', 'Client');
00876                                 }
00877                         }
00878                         else
00879                         {
00880                                 $permission_ok = false;
00881                                 foreach(ilObject::_getAllReferences($object_data['obj_id']) as $ref_id)
00882                                 {
00883                                         if($rbacsystem->checkAccess('write',$object_data['obj_id']))
00884                                         {
00885                                                 $permission_ok = true;
00886                                                 break;
00887                                         }
00888                                 }
00889                                 if(!$permission_ok)
00890                                 {
00891                                         return $this->__raiseError('No write permission for object with id '.$object_data['obj_id'].'!', 'Client');
00892                                 }
00893                         }
00894                 }
00895                 // perform update
00896                 if (count ($object_datas) > 0)
00897                 {
00898                         foreach($object_datas as $object_data)
00899                         {
00900                                 $tmp_obj = $object_data["instance"];
00901                                 $tmp_obj->setTitle($object_data['title']);
00902                                 $tmp_obj->setDescription($object_data['description']);
00903                                 switch ($object_data['type']) {
00904                                         case 'cat':
00905                                                 $tmp_obj->updateTranslation($object_data["title"],$object_data["description"], $lng->getLangKey(), $lng->getLangKey());
00906                                                 break;
00907                                 }
00908                                 $tmp_obj->update();
00909                                 if(strlen($object_data['owner']) && is_numeric($object_data['owner']))
00910                                 {
00911                                     $tmp_obj->setOwner($object_data['owner']);
00912                                         $tmp_obj->updateOwner();
00913                                 }
00914                                 
00915                         }
00916                         return true;
00917                 }
00918                 return false;
00919 
00920         }
00921 
00922 
00923 }
00924 ?>

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