/** * Uploads a new rooms agreement by using the ILIAS MediaObject Service. * If the old file id is given, the old file will be deleted. * * @param array $a_newfile an array containing the input values of the form * @param string $a_oldFileId to delete trash * * @return string uploaded file id */ public function uploadRoomsAgreement($a_newfile, $a_oldFileId = "0") { if (!empty($a_oldFileId) && $a_oldFileId != "0") { $agreementFile = new ilObjMediaObject($a_oldFileId); $agreementFile->delete(); } $mediaObj = new ilObjMediaObject(); $mediaObj->setTitle("RoomSharingRoomsAgreement"); $mediaObj->setDescription("RoomSharingRoomsAgreement"); $mediaObj->create(); $mob_dir = ilObjMediaObject::_getDirectory($mediaObj->getId()); if (!is_dir($mob_dir)) { $mediaObj->createDirectory(); } $file_name = ilUtil::getASCIIFilename($a_newfile["name"]); $file_name_mod = str_replace(" ", "_", $file_name); $file = $mob_dir . "/" . $file_name_mod; ilUtil::moveUploadedFile($a_newfile["tmp_name"], $file_name_mod, $file); ilUtil::renameExecutables($mob_dir); $format = ilObjMediaObject::getMimeType($file); $media_item = new ilMediaItem(); $mediaObj->addMediaItem($media_item); $media_item->setPurpose("Standard"); $media_item->setFormat($format); $media_item->setLocation($file_name_mod); $media_item->setLocationType("LocalFile"); $mediaObj->update(); return $mediaObj->getId(); }
/** * Duplicate media object, return new media object */ function duplicate() { $new_obj = new ilObjMediaObject(); $new_obj->setTitle($this->getTitle()); $new_obj->setDescription($this->getDescription()); // media items foreach ($this->getMediaItems() as $key => $val) { $new_obj->addMediaItem($val); } $new_obj->create(false, true); // files $new_obj->createDirectory(); self::_createThumbnailDirectory($new_obj->getId()); ilUtil::rCopy(ilObjMediaObject::_getDirectory($this->getId()), ilObjMediaObject::_getDirectory($new_obj->getId())); ilUtil::rCopy(ilObjMediaObject::_getThumbnailDirectory($this->getId()), ilObjMediaObject::_getThumbnailDirectory($new_obj->getId())); // meta data include_once "Services/MetaData/classes/class.ilMD.php"; $md = new ilMD(0, $this->getId(), "mob"); $new_md = $md->cloneMD(0, $new_obj->getId(), "mob"); return $new_obj; }
/** * Function to parse incoming data from form input value $value. returns the strin/number/etc. to store in the database. * @param $value * @param ilDataCollectionRecordField $record_field * @return int|string */ public function parseValue($value, ilDataCollectionRecordField $record_field) { $return = false; if ($this->id == ilDataCollectionDatatype::INPUTFORMAT_FILE) { $file = $value; if ($file['tmp_name']) { $file_obj = new ilObjFile(); $file_obj->setType("file"); $file_obj->setTitle($file["name"]); $file_obj->setFileName($file["name"]); $file_obj->setFileType(ilMimeTypeUtil::getMimeType("", $file["name"], $file["type"])); $file_obj->setFileSize($file["size"]); $file_obj->setMode("object"); $file_obj->create(); $file_obj->getUploadFile($file["tmp_name"], $file["name"]); $file_id = $file_obj->getId(); $return = $file_id; } else { $return = $record_field->getValue(); } } elseif ($this->id == ilDataCollectionDatatype::INPUTFORMAT_MOB) { if ($value == -1) { //marked for deletion. return 0; } $media = $value; if ($media['tmp_name']) { $mob = new ilObjMediaObject(); $mob->setTitle($media['name']); $mob->create(); $mob_dir = ilObjMediaObject::_getDirectory($mob->getId()); if (!is_dir($mob_dir)) { $mob->createDirectory(); } $media_item = new ilMediaItem(); $mob->addMediaItem($media_item); $media_item->setPurpose("Standard"); $file_name = ilUtil::getASCIIFilename($media['name']); $file_name = str_replace(" ", "_", $file_name); $file = $mob_dir . "/" . $file_name; $title = $file_name; ilUtil::moveUploadedFile($media['tmp_name'], $file_name, $file); ilUtil::renameExecutables($mob_dir); list($width, $height, $type, $attr) = getimagesize($file); $arr_properties = $record_field->getField()->getProperties(); $new_width = $arr_properties[ilDataCollectionField::PROPERTYID_WIDTH]; $new_height = $arr_properties[ilDataCollectionField::PROPERTYID_HEIGHT]; if ($new_width || $new_height) { //only resize if it is bigger, not if it is smaller if ($new_height < $height && $new_width < $width) { //resize proportional if (!$new_height || !$new_width) { $format = ilObjMediaObject::getMimeType($file); $wh = ilObjMediaObject::_determineWidthHeight("", "", $format, "File", $file, "", true, false, $arr_properties[ilDataCollectionField::PROPERTYID_WIDTH], (int) $arr_properties[ilDataCollectionField::PROPERTYID_HEIGHT]); } else { $wh['width'] = (int) $arr_properties[ilDataCollectionField::PROPERTYID_WIDTH]; $wh['height'] = (int) $arr_properties[ilDataCollectionField::PROPERTYID_HEIGHT]; } } $location = ilObjMediaObject::_resizeImage($file, $wh['width'], $wh['height'], false); } else { $location = $title; } ilObjMediaObject::_saveUsage($mob->getId(), "dcl:html", $record_field->getRecord()->getTable()->getCollectionObject()->getId()); $format = ilObjMediaObject::getMimeType($file); $media_item->setFormat($format); $media_item->setLocation($location); $media_item->setLocationType("LocalFile"); $mob->update(); $return = $mob->getId(); } else { $return = $record_field->getValue(); } } elseif ($this->id == ilDataCollectionDatatype::INPUTFORMAT_DATETIME) { return $value["date"] . " " . $value["time"]; } elseif ($this->id == ilDataCollectionDatatype::INPUTFORMAT_BOOLEAN) { $return = $value ? 1 : 0; } elseif ($this->id == ilDataCollectionDatatype::INPUTFORMAT_TEXT) { $arr_properties = $record_field->getField()->getProperties(); if ($arr_properties[ilDataCollectionField::PROPERTYID_TEXTAREA]) { $return = nl2br($value); } else { $return = $value; } } else { if ($this->id == ilDataCollectionDatatype::INPUTFORMAT_NUMBER) { $return = $value == '' ? null : $value; //SW, Ilias Mantis #0011799: Return null otherwise '' is casted to 0 in DB } else { $return = $value; } } return $return; }
/** * Create media object from upload directory */ function createMediaFromUploadDir() { $mset = new ilSetting("mobs"); $upload_dir = trim($mset->get("upload_dir")); include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php"; if (is_array($_POST["file"]) && ilMainMenuGUI::_checkAdministrationPermission()) { foreach ($_POST["file"] as $f) { $f = str_replace("..", "", $f); $fullpath = $upload_dir . "/" . $f; $mob = new ilObjMediaObject(); $mob->setTitle(basename($fullpath)); $mob->setDescription(""); $mob->create(); // determine and create mob directory, move uploaded file to directory //$mob_dir = ilUtil::getWebspaceDir()."/mobs/mm_".$a_mob->getId(); $mob->createDirectory(); $mob_dir = ilObjMediaObject::_getDirectory($mob->getId()); $media_item = new ilMediaItem(); $mob->addMediaItem($media_item); $media_item->setPurpose("Standard"); $file = $mob_dir . "/" . basename($fullpath); ilUtil::moveUploadedFile($fullpath, basename($fullpath), $file, false, $_POST["action"]); // get mime type $format = ilObjMediaObject::getMimeType($file); $location = basename($fullpath); // set real meta and object data $media_item->setFormat($format); $media_item->setLocation($location); $media_item->setLocationType("LocalFile"); $mob->setDescription($format); // determine width and height of known image types $wh = ilObjMediaObject::_determineWidthHeight(500, 400, $format, "File", $mob_dir . "/" . $location, $media_item->getLocation(), true, true, "", ""); $media_item->setWidth($wh["width"]); $media_item->setHeight($wh["height"]); if ($wh["info"] != "") { // ilUtil::sendInfo($wh["info"], true); } $media_item->setHAlign("Left"); ilUtil::renameExecutables($mob_dir); $mob->update(); // put it into current folder $mep_item = new ilMediaPoolItem(); $mep_item->setTitle($mob->getTitle()); $mep_item->setType("mob"); $mep_item->setForeignId($mob->getId()); $mep_item->create(); $tree = $this->object->getTree(); $parent = $_GET["mepitem_id"] == "" ? $tree->getRootId() : $_GET["mepitem_id"]; $tree->insertNode($mep_item->getId(), $parent); } } ilUtil::redirect("ilias.php?baseClass=ilMediaPoolPresentationGUI&cmd=listMedia&ref_id=" . $_GET["ref_id"] . "&mepitem_id=" . $_GET["mepitem_id"]); }
/** * Configures the file for the updateFloorPlanInfosWithFile and addFloorPlan function. * * @param ilObjMediaObject $a_mediaObj * @param array $a_newfile * * @return array with format and filename */ private function configureFile($a_mediaObj, $a_newfile = NULL) { if ($this->mobjMock) { return $a_newfile; } $mob_dir = ilObjMediaObject::_getDirectory($a_mediaObj->getId()); if (!is_dir($mob_dir)) { $a_mediaObj->createDirectory(); } $file_name = ilUtil::getASCIIFilename($a_newfile["name"]); $file_name_mod = str_replace(" ", "_", $file_name); $file = $mob_dir . "/" . $file_name_mod; // construct file path ilUtil::moveUploadedFile($a_newfile["tmp_name"], $file_name_mod, $file); ilUtil::renameExecutables($mob_dir); $format = ilObjMediaObject::getMimeType($file); return array("format" => $format, "filename" => $file_name_mod); }
public function dbImportSco($slm, $sco, $asset = false) { $qtis = array(); $d = ilUtil::getDir($this->packageFolder); foreach ($d as $f) { //continue; if ($f[type] == 'file' && substr($f[entry], 0, 4) == 'qti_') { include_once "./Services/QTI/classes/class.ilQTIParser.php"; include_once "./Modules/Test/classes/class.ilObjTest.php"; $qtiParser = new ilQTIParser($this->packageFolder . "/" . $f[entry], IL_MO_VERIFY_QTI, 0, ""); $result = $qtiParser->startParsing(); $founditems =& $qtiParser->getFoundItems(); // die(print_r($founditems)); foreach ($founditems as $qp) { $newObj = new ilObjTest(0, true); // This creates a lot of invalid repository objects for each question // question are not repository objects (see e.g. table object_data), alex 29 Sep 2009 // $newObj->setType ( $qp ['type'] ); // $newObj->setTitle ( $qp ['title'] ); // $newObj->create ( true ); // $newObj->createReference (); // $newObj->putInTree ($_GET ["ref_id"]); // $newObj->setPermissions ( $sco->getId ()); // $newObj->notify ("new", $_GET["ref_id"], $sco->getId (), $_GET["ref_id"], $newObj->getRefId () ); // $newObj->mark_schema->flush (); $qtiParser = new ilQTIParser($this->packageFolder . "/" . $f[entry], IL_MO_PARSE_QTI, 0, ""); $qtiParser->setTestObject($newObj); $result = $qtiParser->startParsing(); // $newObj->saveToDb (); $qtis = array_merge($qtis, $qtiParser->getImportMapping()); } } } //exit; include_once 'Modules/Scorm2004/classes/class.ilSCORM2004Page.php'; $doc = new SimpleXMLElement($this->imsmanifest->saveXml()); $l = $doc->xpath("/ContentObject/MetaData"); if ($l[0]) { include_once 'Services/MetaData/classes/class.ilMDXMLCopier.php'; $mdxml =& new ilMDXMLCopier($l[0]->asXML(), $slm->getId(), $sco->getId(), $sco->getType()); $mdxml->startParsing(); $mdxml->getMDObject()->update(); } $l = $doc->xpath("/ContentObject/PageObject"); foreach ($l as $page_xml) { $tnode = $page_xml->xpath('MetaData/General/Title'); $page = new ilSCORM2004PageNode($slm); $page->setTitle($tnode[0]); $page->setSLMId($slm->getId()); $page->create(true); ilSCORM2004Node::putInTree($page, $sco->getId(), $target); $pmd = $page_xml->xpath("MetaData"); if ($pmd[0]) { include_once 'Services/MetaData/classes/class.ilMDXMLCopier.php'; $mdxml =& new ilMDXMLCopier($pmd[0]->asXML(), $slm->getId(), $page->getId(), $page->getType()); $mdxml->startParsing(); $mdxml->getMDObject()->update(); } $tnode = $page_xml->xpath("//MediaObject/MediaAlias | //InteractiveImage/MediaAlias"); foreach ($tnode as $ttnode) { include_once './Services/MediaObjects/classes/class.ilObjMediaObject.php'; $OriginId = $ttnode[OriginId]; $medianodes = $doc->xpath("//MediaObject[MetaData/General/Identifier/@Entry='" . $OriginId . "']"); $medianode = $medianodes[0]; if ($medianode) { $media_object = new ilObjMediaObject(); $media_object->setTitle($medianode->MetaData->General->Title); $media_object->setDescription($medianode->MetaData->General->Description); $media_object->create(false); $mmd = $medianode->xpath("MetaData"); if ($mmd[0]) { include_once 'Services/MetaData/classes/class.ilMDXMLCopier.php'; $mdxml =& new ilMDXMLCopier($mmd[0]->asXML(), 0, $media_object->getId(), $media_object->getType()); $mdxml->startParsing(); $mdxml->getMDObject()->update(); } // determine and create mob directory, move uploaded file to directory $media_object->createDirectory(); $mob_dir = ilObjMediaObject::_getDirectory($media_object->getId()); foreach ($medianode->MediaItem as $xMediaItem) { $media_item =& new ilMediaItem(); $media_object->addMediaItem($media_item); $media_item->setPurpose($xMediaItem[Purpose]); $media_item->setFormat($xMediaItem->Format); $media_item->setLocation($xMediaItem->Location); $media_item->setLocationType($xMediaItem->Location[Type]); $media_item->setWidth($xMediaItem->Layout[Width]); $media_item->setHeight($xMediaItem->Layout[Height]); $media_item->setHAlign($xMediaItem->Layout[HorizontalAlign]); $media_item->setCaption($xMediaItem->Caption); $media_item->setTextRepresentation($xMediaItem->TextRepresentation); $nr = 0; // add map areas (external links only) foreach ($xMediaItem->MapArea as $n => $v) { if ($v->ExtLink[Href] != "") { include_once "./Services/MediaObjects/classes/class.ilMapArea.php"; $ma = new ilMapArea(); $map_area = new ilMapArea(); $map_area->setShape($v[Shape]); $map_area->setCoords($v[Coords]); $map_area->setLinkType(IL_EXT_LINK); $map_area->setTitle($v->ExtLink); $map_area->setHref($v->ExtLink[Href]); $media_item->addMapArea($map_area); } } if ($media_item->getLocationType() == "LocalFile") { // $tmp_name = $this->packageFolder."/objects/".$OriginId."/".$xMediaItem->Location; // copy($tmp_name, $mob_dir."/".$xMediaItem->Location); } } // copy whole directory ilUtil::rCopy($this->packageFolder . "/objects/" . $OriginId, $mob_dir); // alex: fixed media import: these lines have been // behind the next curly bracket which makes it fail // when no medianode is given. (id=0 -> fatal error) ilUtil::renameExecutables($mob_dir); $media_object->update(true); $ttnode[OriginId] = "il__mob_" . $media_object->getId(); } } include_once "./Modules/File/classes/class.ilObjFile.php"; include_once "./Services/Utilities/classes/class.ilFileUtils.php"; include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php"; $intlinks = $page_xml->xpath("//IntLink"); foreach ($intlinks as $intlink) { if ($intlink[Type] != "File") { continue; } $path = $this->packageFolder . "/objects/" . str_replace('dfile', 'file', $intlink[Target]); if (!is_dir($path)) { continue; } $ffiles = array(); ilFileUtils::recursive_dirscan($path, $ffiles); $filename = $ffiles[file][0]; $fileObj = new ilObjFile(); $fileObj->setType("file"); $fileObj->setTitle(ilFileUtils::utf8_encode(ilUtil::stripSlashes($filename))); $fileObj->setFileName(ilFileUtils::utf8_encode(ilUtil::stripSlashes($filename))); // better use this, mime_content_type is deprecated $fileObj->setFileType(ilObjMediaObject::getMimeType($path . "/" . $filename)); $fileObj->setFileSize(filesize($path . "/" . $filename)); $fileObj->create(); $fileObj->createReference(); //$fileObj->putInTree($_GET["ref_id"]); //$fileObj->setPermissions($slm->getId ()); $fileObj->createDirectory(); $fileObj->storeUnzipedFile($path . "/" . $filename, ilFileUtils::utf8_encode(ilUtil::stripSlashes($filename))); $intlink[Target] = "il__dfile_" . $fileObj->getId(); } $fileitems = $page_xml->xpath("//FileItem/Identifier"); foreach ($fileitems as $fileitem) { $path = $this->packageFolder . "/objects/" . $fileitem[Entry]; if (!is_dir($path)) { continue; } $ffiles = array(); ilFileUtils::recursive_dirscan($path, $ffiles); $filename = $ffiles[file][0]; $fileObj = new ilObjFile(); $fileObj->setType("file"); $fileObj->setTitle(ilFileUtils::utf8_encode(ilUtil::stripSlashes($filename))); $fileObj->setFileName(ilFileUtils::utf8_encode(ilUtil::stripSlashes($filename))); // better use this, mime_content_type is deprecated $fileObj->setFileType(ilObjMediaObject::getMimeType($path . "/" . $filename)); $fileObj->setFileSize(filesize($path . "/" . $filename)); $fileObj->create(); $fileObj->createReference(); //$fileObj->putInTree($_GET["ref_id"]); //$fileObj->setPermissions($slm->getId ()); $fileObj->createDirectory(); $fileObj->storeUnzipedFile($path . "/" . $filename, ilFileUtils::utf8_encode(ilUtil::stripSlashes($filename))); $fileitem[Entry] = "il__file_" . $fileObj->getId(); } $pagex = new ilSCORM2004Page($page->getId()); $ddoc = new DOMDocument(); $ddoc->async = false; $ddoc->preserveWhiteSpace = false; $ddoc->formatOutput = false; $ddoc->loadXML($page_xml->asXML()); $xpath = new DOMXPath($ddoc); $tnode = $xpath->query('PageContent'); $t = "<PageObject>"; foreach ($tnode as $ttnode) { $t .= $ddoc->saveXML($ttnode); } $t .= "</PageObject>"; foreach ($qtis as $old => $q) { $t = str_replace($old, 'il__qst_' . $q['pool'], $t); } $pagex->setXMLContent($t); $pagex->updateFromXML(); } }
/** * Import record * * @param * @return */ function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version) { //echo $a_entity; //var_dump($a_rec); switch ($a_entity) { case "mob": //var_dump($a_rec); include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php"; $newObj = new ilObjMediaObject(); $newObj->setType("mob"); $newObj->setTitle($a_rec["Title"]); $newObj->setDescription($a_rec["Description"]); $newObj->create(); $newObj->createDirectory(); ilObjMediaObject::_createThumbnailDirectory($newObj->getId()); $this->current_mob = $newObj; $dir = str_replace("..", "", $a_rec["Dir"]); if ($dir != "" && $this->getImportDirectory() != "") { $source_dir = $this->getImportDirectory() . "/" . $dir; $target_dir = $dir = ilObjMediaObject::_getDirectory($newObj->getId()); ilUtil::rCopy($source_dir, $target_dir); } $a_mapping->addMapping("Services/MediaObjects", "mob", $a_rec["Id"], $newObj->getId()); //echo "<br>++add++"."0:".$a_rec["Id"].":mob+0:".$newObj->getId().":mob"."+"; $a_mapping->addMapping("Services/MetaData", "md", "0:" . $a_rec["Id"] . ":mob", "0:" . $newObj->getId() . ":mob"); break; case "mob_media_item": // determine parent mob include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php"; $mob_id = (int) $a_mapping->getMapping("Services/MediaObjects", "mob", $a_rec["MobId"]); if (is_object($this->current_mob) && $this->current_mob->getId() == $mob_id) { $mob = $this->current_mob; } else { $mob = new ilObjMediaObject($mob_id); } include_once "./Services/MediaObjects/classes/class.ilMediaItem.php"; $newObj = new ilMediaItem(); $newObj->setMobId($mob_id); $newObj->setWidth($a_rec["Width"]); $newObj->setHeight($a_rec["Height"]); $newObj->setCaption($a_rec["Caption"]); $newObj->setNr($a_rec["Nr"]); $newObj->setPurpose($a_rec["Purpose"]); $newObj->setLocation($a_rec["Location"]); $newObj->setLocationType($a_rec["LocationType"]); $newObj->setFormat($a_rec["Format"]); $newObj->setTextRepresentation($a_rec["TextRepresentation"]); $newObj->create(); $this->current_media_item = $newObj; $a_mapping->addMapping("Services/MediaObjects", "mob_media_item", $a_rec["Id"], $newObj->getId()); break; case "mob_mi_parameter": // get media item include_once "./Services/MediaObjects/classes/class.ilMediaItem.php"; $med_id = (int) $a_mapping->getMapping("Services/MediaObjects", "mob_media_item", $a_rec["MiId"]); if (is_object($this->current_media_item) && $this->current_media_item->getId() == $med_id) { $med = $this->current_media_item; } else { $med = new ilMediaItem($med_id); } $med->writeParameter($a_rec["Name"], $a_rec["Value"]); break; case "mob_mi_map_area": // get media item include_once "./Services/MediaObjects/classes/class.ilMediaItem.php"; $med_id = (int) $a_mapping->getMapping("Services/MediaObjects", "mob_media_item", $a_rec["MiId"]); if (is_object($this->current_media_item) && $this->current_media_item->getId() == $med_id) { $med = $this->current_media_item; } else { $med = new ilMediaItem($med_id); } include_once "./Services/MediaObjects/classes/class.ilMapArea.php"; $map_area = new ilMapArea(); $map_area->setItemId($med_id); $map_area->setNr($a_rec["Nr"]); $map_area->setShape($a_rec["Shape"]); $map_area->setCoords($a_rec["Coords"]); $map_area->setLinkType($a_rec["LinkType"]); $map_area->setTitle($a_rec["Title"]); $map_area->setHref($a_rec["Href"]); $map_area->setTarget($a_rec["Target"]); $map_area->setType($a_rec["Type"]); $map_area->setTargetFrame($a_rec["TargetFrame"]); $map_area->setHighlightMode($a_rec["HighlightMode"]); $map_area->setHighlightClass($a_rec["HighlightClass"]); $map_area->create(); break; } }