/** * builds asset in repository from assetinfo and records from recordlist * * @param array assetInfo * @param array recordList * @return asset or false on fatal error * @access public * @since 7/18/05 * */ function buildAsset($info) { $assetInfo = $info['assetInfo']; $recordList = $info['recordList']; $childAssetList = $info['childAssetList']; $buildOrderedSet = $info['buildOrderedSet']; $idManager = Services::getService("Id"); $mime = Services::getService("MIME"); $FILE_ID = $idManager->getId("FILE"); $FILE_DATA_ID = $idManager->getId("FILE_DATA"); $FILE_NAME_ID = $idManager->getId("FILE_NAME"); $MIME_TYPE_ID = $idManager->getId("MIME_TYPE"); $THUMBNAIL_DATA_ID = $idManager->getId("THUMBNAIL_DATA"); $THUMBNAIL_MIME_TYPE_ID = $idManager->getId("THUMBNAIL_MIME_TYPE"); $asset = $this->_destinationRepository->createAsset($assetInfo['displayName'], $assetInfo['description'], $assetInfo['type']); $assetId = $asset->getId(); // log creation if (Services::serviceRunning("Logging")) { $loggingManager = Services::getService("Logging"); $log = $loggingManager->getLogForWriting("Harmoni"); $formatType = new Type("logging", "edu.middlebury", "AgentsAndNodes", "A format in which the acting Agent[s] and the target nodes affected are specified."); $priorityType = new Type("logging", "edu.middlebury", "Event_Notice", "Normal Events."); $item = new AgentNodeEntryItem("Create Node", "Asset: " . $assetId->getIdString() . " created."); $item->addNodeId($assetId); $item->addNodeId($this->_destinationRepository->getId()); $log->appendLogWithTypes($item, $formatType, $priorityType); } $this->addGoodAssetId($asset->getId()); RecordManager::setCacheMode(false); if (is_array($recordList)) { foreach ($recordList as $entry) { $assetRecord = $asset->createRecord($entry['structureId']); $j = 0; // printpre("creating record for: "); printpre($entry['structureId']); foreach ($entry['partStructureIds'] as $id) { if (!$entry['structureId']->isEqual($FILE_ID)) { if (isset($entry['parts'][$j])) { if (is_array($entry['parts'][$j])) { for ($k = 0; $k < count($entry['parts'][$j]); $k++) { $assetRecord->createPart($id, $entry['parts'][$j][$k]); } } else { $assetRecord->createPart($id, $entry['parts'][$j]); } } $j++; } else { if ($entry['structureId']->isEqual($FILE_ID)) { $filename = basename(trim($entry['parts'][0])); $mimetype = $mime->getMIMETypeForFileName($filename); $assetRecord->createPart($FILE_DATA_ID, file_get_contents($this->_srcDir . $filename)); $assetRecord->createPart($FILE_NAME_ID, basename($filename)); $assetRecord->createPart($MIME_TYPE_ID, $mimetype); $imageProcessor = Services::getService("ImageProcessor"); if (isset($entry['parts'][1]) && $entry['parts'][1] != "") { $assetRecord->createPart($THUMBNAIL_DATA_ID, file_get_contents($this->_srcDir . $entry['parts'][1])); } else { if ($imageProcessor->isFormatSupported($mimetype)) { try { $thumbData = $imageProcessor->generateThumbnailData($mimetype, file_get_contents($this->_srcDir . $filename)); } catch (ImageProcessingFailedException $e) { $thumbData = null; } if ($thumbData) { $assetRecord->createPart($THUMBNAIL_DATA_ID, $thumbData); $assetRecord->createPart($THUMBNAIL_MIME_TYPE_ID, $imageProcessor->getThumbnailFormat()); } } } break; } } } } } if (!is_null($childAssetList)) { $stop = $this->assetBuildingIteration(new HarmoniIterator($childAssetList), $asset, $buildOrderedSet); if (!$stop) { return $stop; } // false } return $asset; }