Exemple #1
0
 /**
  * Create a new file asset
  * 
  * @return object Asset
  * @access public
  * @since 1/26/07
  */
 function createFileAsset()
 {
     $contentAsset = $this->getContentAsset();
     $asset = MediaAsset::createForContentAsset($contentAsset);
     if (!($displayName = RequestContext::value('displayName'))) {
         $displayName = $_FILES['media_file']['name'];
     }
     if (!($description = RequestContext::value('description'))) {
         $description = '';
     }
     // Check the quota
     $slot = $this->getSlot();
     if ($this->getQuotaUsed() + $_FILES['media_file']['size'] > $slot->getMediaQuota()->value()) {
         throw new Exception("Cannot add File, {$displayName}, quota of " . $slot->getMediaQuota()->asString() . " exceeded.");
     }
     // Create the asset
     $asset->updateDisplayName($displayName);
     $asset->updateDescription($description);
     try {
         $this->addFileRecord($asset);
     } catch (Exception $e) {
         HarmoniErrorHandler::logException($e, 'Segue');
         $this->nonFatalError($e->getMessage(), get_class($e));
     }
     try {
         $this->addDublinCoreRecord($asset);
     } catch (Exception $e) {
         HarmoniErrorHandler::logException($e, 'Segue');
         $this->nonFatalError($e->getMessage(), get_class($e));
     }
     // Log the success or failure
     if (Services::serviceRunning("Logging")) {
         $loggingManager = Services::getService("Logging");
         $log = $loggingManager->getLogForWriting("Segue");
         $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("Media Library", "File uploaded with id '" . $asset->getId()->getIdString() . "' and filename '" . $_FILES['media_file']['name'] . "'");
         $item->addNodeId($asset->getId());
         $item->addNodeId($contentAsset->getId());
         $idManager = Services::getService("Id");
         $director = AssetSiteDirector::forAsset($contentAsset);
         $site = $director->getRootSiteComponent($contentAsset->getId()->getIdString());
         $item->addNodeId($idManager->getId($site->getId()));
         $log->appendLogWithTypes($item, $formatType, $priorityType);
     }
     return $asset;
 }
 /**
  * Add a Media File
  * 
  * @param Asset $contentAsset
  * @param object DOMElement $element
  * @return void
  * @access protected
  * @since 1/24/08
  */
 protected function addMedia(Asset $contentAsset, DOMElement $element)
 {
     $asset = MediaAsset::createForContentAsset($contentAsset);
     $element->setAttribute('new_id', $asset->getId()->getIdString());
     $asset->updateDisplayName($this->getStringValue($this->getSingleChild('displayName', $element)));
     $asset->updateDescription($this->getStringValue($this->getSingleChild('description', $element)));
     $fileElements = $this->xpath->query("./file", $element);
     foreach ($fileElements as $fileElement) {
         $this->addFileRecord($asset, $fileElement);
     }
     $dcElements = $this->xpath->query("./dublinCore", $element);
     foreach ($dcElements as $dcElement) {
         $this->addDublinCoreRecord($asset, $dcElement);
     }
     $this->setAssetAuthorship($asset, $element);
     $this->setAssetDates($asset, $element);
 }