/** * add an File with id. * * @param string $session_id current session * @param int $target_id refid of parent in repository * @param string $file_xml qti xml description of test * * @return int reference id in the tree, 0 if not successful */ function addFile($sid, $target_id, $file_xml) { $this->initAuth($sid); $this->initIlias(); if (!$this->__checkSession($sid)) { return $this->__raiseError($this->__getMessage(), $this->__getMessageCode()); } global $rbacsystem, $tree, $ilLog, $ilAccess; if (!($target_obj =& ilObjectFactory::getInstanceByRefId($target_id, false))) { return $this->__raiseError('No valid target given.', 'Client'); } if (ilObject::_isInTrash($target_id)) { return $this->__raiseError("Parent with ID {$target_id} has been deleted.", 'CLIENT_TARGET_DELETED'); } // Check access $allowed_types = array('cat', 'grp', 'crs', 'fold', 'root'); if (!in_array($target_obj->getType(), $allowed_types)) { return $this->__raiseError('No valid target type. Target must be reference id of "course, group, category or folder"', 'Client'); } if (!$ilAccess->checkAccess('create', '', $target_id, "file")) { return $this->__raiseError('No permission to create Files in target ' . $target_id . '!', 'Client'); } // create object, put it into the tree and use the parser to update the settings include_once './Modules/File/classes/class.ilFileXMLParser.php'; include_once './Modules/File/classes/class.ilFileException.php'; include_once './Modules/File/classes/class.ilObjFile.php'; $file = new ilObjFile(); try { $fileXMLParser = new ilFileXMLParser($file, $file_xml); if ($fileXMLParser->start()) { global $ilLog; $ilLog->write(__METHOD__ . ': File type: ' . $file->getFileType()); $file->create(); $file->createReference(); $file->putInTree($target_id); $file->setPermissions($target_id); // we now can save the file contents since we know the obj id now. $fileXMLParser->setFileContents(); #$file->update(); return $file->getRefId(); } else { return $this->__raiseError("Could not add file", "Server"); } } catch (ilFileException $exception) { return $this->__raiseError($exception->getMessage(), $exception->getCode() == ilFileException::$ID_MISMATCH ? "Client" : "Server"); } }
/** * Import XML * * @param * @return */ function importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping) { include_once './Modules/File/classes/class.ilObjFile.php'; // case i container if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_id)) { $newObj = ilObjectFactory::getInstanceByObjId($new_id, false); } else { $newObj = new ilObjFile(); $newObj->create(true); } include_once "./Modules/File/classes/class.ilFileXMLParser.php"; $parser = new ilFileXMLParser($newObj, $a_xml); $parser->setImportDirectory($this->getImportDirectory()); $parser->startParsing(); $newObj->createProperties(false, false); $parser->setFileContents(); $this->current_obj = $newObj; $newObj->update(); // this is necessary for case ii (e.g. wiki import) $a_mapping->addMapping("Modules/File", "file", $a_id, $newObj->getId()); $a_mapping->addMapping("Services/MetaData", "md", $a_id . ":0:file", $newObj->getId() . ":0:file"); }