/** * Save our results. Tearing down and unsetting the Wizard is handled by * in {@link runWizard()} and does not need to be implemented here. * * @param string $cacheName * @return boolean TRUE if save was successful and tear-down/cleanup of the * Wizard should ensue. * @access public * @since 4/28/05 */ function saveWizard($cacheName) { $wizard = $this->getWizard($cacheName); // Make sure we have a valid Repository $authZ = Services::getService("AuthZ"); $idManager = Services::getService("Id"); $repositoryManager = Services::getService("Repository"); $repository = $repositoryManager->getRepository($idManager->getId("edu.middlebury.concerto.exhibition_repository")); $slideshowAsset = $repository->getAsset($idManager->getId(RequestContext::value('slideshow_id'))); $properties = $wizard->getAllValues(); $status = new StatusStars(_("Saving Slideshow")); $status->initializeStatistics(count($properties['slidestep']['slides']) + 2); // First, verify that we chose a parent that we can add children to. if ($authZ->isUserAuthorized($idManager->getId("edu.middlebury.authorization.modify"), $slideshowAsset->getId())) { $slideshowAssetId = $slideshowAsset->getId(); $this->_slideshowAssetId = $slideshowAssetId; // Update the Name and description if ($properties['namedescstep']['display_name']) { $slideshowAsset->updateDisplayName($properties['namedescstep']['display_name']); } if ($properties['namedescstep']['description']) { $slideshowAsset->updateDescription($properties['namedescstep']['description']); } // Update the effective/expiration dates // if ($properties['datestep']['effective_date']) // $slideshowAsset->updateEffectiveDate( // DateAndTime::fromString( // $properties['datestep']['effective_date'])); // if ($properties['datestep']['expiration_date']) // $slideshowAsset->updateExpirationDate( // DateAndTime::fromString( // $properties['datestep']['expiration_date'])); // --- Slides --- $slideAssetType = new HarmoniType("Asset Types", "edu.middlebury.concerto", "Slide", "Slides are components of Slide-Shows that contain captions and may reference media Assets."); $slideRecordStructId = $idManager->getId("Repository::edu.middlebury.concerto.exhibition_repository::edu.middlebury.concerto.slide_record_structure"); $targetIdPartStructId = $idManager->getId("Repository::edu.middlebury.concerto.exhibition_repository::edu.middlebury.concerto.slide_record_structure.edu.middlebury.concerto.slide_record_structure.target_id"); $textPositionPartStructId = $idManager->getId("Repository::edu.middlebury.concerto.exhibition_repository::edu.middlebury.concerto.slide_record_structure.edu.middlebury.concerto.slide_record_structure.text_position"); $displayMetadataPartStructId = $idManager->getId("Repository::edu.middlebury.concerto.exhibition_repository::edu.middlebury.concerto.slide_record_structure.edu.middlebury.concerto.slide_record_structure.display_metadata"); $setManager = Services::getService("Sets"); $pSlideOrder = $setManager->getPersistentSet($slideshowAssetId); $slideIterator = $slideshowAsset->getAssets(); // ---- Add/Update Slides in new order (hopefully) $existingSlides = array(); while ($slideIterator->hasNext()) { $currentSlide = $slideIterator->next(); $id = $currentSlide->getId(); $existingSlides[] = $id->getIdString(); } $pSlideOrder->removeAllItems(); $status->updateStatistics(); foreach ($properties['slidestep']['slides'] as $slideProperties) { // print get_class($slideProperties['slideId']).": ".$slideProperties['title']; if (!isset($slideProperties['slideId'])) { // ---- Clean the inputs ---- if (isset($slideProperties['title'])) { $title = $slideProperties['title']; } else { $title = ''; } if (isset($slideProperties['caption'])) { $caption = $slideProperties['caption']; } else { $caption = ''; } if (isset($slideProperties['text_position'])) { $textPosition = String::withValue($slideProperties['text_position']); } else { $textPosition = String::withValue(''); } if (isset($slideProperties['show_target_metadata'])) { $displayMetadata = Boolean::withValue($slideProperties['show_target_metadata']); } else { $displayMetadata = Boolean::false(); } if (isset($slideProperties['_assetId'])) { $targetId = String::withValue($slideProperties['_assetId']->getIdString()); } else { $targetId = String::withValue(''); } // ---- Create the asset ---- $slideAsset = $repository->createAsset($title, $caption, $slideAssetType); $slideAssetId = $slideAsset->getId(); $slideshowAsset->addAsset($slideAssetId); // Add it to the order field $pSlideOrder->addItem($slideAssetId); // ---- Set the additional info ---- $slideRecord = $slideAsset->createRecord($slideRecordStructId); $slideRecord->createPart($textPositionPartStructId, $textPosition); $slideRecord->createPart($displayMetadataPartStructId, $displayMetadata); $slideRecord->createPart($targetIdPartStructId, $targetId); } else { if (in_array($slideProperties['slideId']->getIdString(), $existingSlides)) { $slideAsset = $repository->getAsset($slideProperties['slideId']); $slideAsset->updateDisplayName($slideProperties['title']); $slideAsset->updateDescription($slideProperties['caption']); $textPositionIterator = $slideAsset->getPartsByPartStructure($textPositionPartStructId); if ($textPositionIterator->hasNext()) { $part = $textPositionIterator->next(); $part->updateValue(new String($slideProperties['text_position'])); } $showMetadataIterator = $slideAsset->getPartsByPartStructure($displayMetadataPartStructId); if ($showMetadataIterator->hasNext()) { $part = $showMetadataIterator->next(); $part->updateValue(new Boolean($slideProperties['show_target_metadata'])); } $pSlideOrder->addItem($slideProperties['slideId']); $records = $slideAsset->getRecordsByRecordStructure($slideRecordStructId); $slideRecord = $records->next(); } } $status->updateStatistics(); } // ==== Remove slide assets no longer in slideshow ---- foreach ($existingSlides as $older) { $old = $idManager->getId($older); if (!$pSlideOrder->isInSet($old)) { $slideshowAsset->removeAsset($old, false); $repository->deleteAsset($old); } } $status->updateStatistics(); // Log the success or failure if (Services::serviceRunning("Logging")) { $loggingManager = Services::getService("Logging"); $log = $loggingManager->getLogForWriting("Concerto"); $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("Modify Node", "Slideshow Modified"); $item->addNodeId($slideshowAssetId); $log->appendLogWithTypes($item, $formatType, $priorityType); } return TRUE; } else { return FALSE; } }
/** @test */ public function falseBoolean() { $this->assertFalse(Boolean::false()->evaluate()); }
/** * Save our results. Tearing down and unsetting the Wizard is handled by * in {@link runWizard()} and does not need to be implemented here. * * @param string $cacheName * @return boolean TRUE if save was successful and tear-down/cleanup of the * Wizard should ensue. * @access public * @since 4/28/05 */ function saveWizard($cacheName) { $wizard = $this->getWizard($cacheName); // Make sure we have a valid Repository $authZ = Services::getService("AuthZ"); $idManager = Services::getService("Id"); $repositoryManager = Services::getService("Repository"); $repository = $repositoryManager->getRepository($idManager->getId("edu.middlebury.concerto.exhibition_repository")); $exhibitionAsset = $repository->getAsset($idManager->getId(RequestContext::value('exhibition_id'))); $properties = $wizard->getAllValues(); $status = new StatusStars(_("Saving Slideshow")); $status->initializeStatistics(count($properties['slidestep']['slides']) + 2); // First, verify that we chose a parent that we can add children to. if ($authZ->isUserAuthorized($idManager->getId("edu.middlebury.authorization.add_children"), $exhibitionAsset->getId())) { $slideshowAssetType = new HarmoniType("Asset Types", "edu.middlebury.concerto", "Slideshow", "Slide-Shows are ordered collections of slides that contain captions and may reference media Assets."); $slideshowAsset = $repository->createAsset($properties['namedescstep']['display_name'], $properties['namedescstep']['description'], $slideshowAssetType); $slideshowAssetId = $slideshowAsset->getId(); $this->_slideshowAssetId = $slideshowAssetId; // Update the effective/expiration dates // if ($properties['datestep']['effective_date']) // $slideshowAsset->updateEffectiveDate( // DateAndTime::fromString($properties['datestep']['effective_date'])); // if ($properties['datestep']['expiration_date']) // $slideshowAsset->updateExpirationDate( // DateAndTime::fromString($properties['datestep']['expiration_date'])); $exhibitionAsset->addAsset($slideshowAssetId); // --- Slides --- $slideAssetType = new HarmoniType("Asset Types", "edu.middlebury.concerto", "Slide", "Slides are components of Slide-Shows that contain captions and may reference media Assets."); $slideRecordStructId = $idManager->getId("Repository::edu.middlebury.concerto.exhibition_repository::edu.middlebury.concerto.slide_record_structure"); $targetIdPartStructId = $idManager->getId("Repository::edu.middlebury.concerto.exhibition_repository::edu.middlebury.concerto.slide_record_structure.edu.middlebury.concerto.slide_record_structure.target_id"); $textPositionPartStructId = $idManager->getId("Repository::edu.middlebury.concerto.exhibition_repository::edu.middlebury.concerto.slide_record_structure.edu.middlebury.concerto.slide_record_structure.text_position"); $displayMetadataPartStructId = $idManager->getId("Repository::edu.middlebury.concerto.exhibition_repository::edu.middlebury.concerto.slide_record_structure.edu.middlebury.concerto.slide_record_structure.display_metadata"); $setManager = Services::getService("Sets"); $slideOrder = $setManager->getPersistentSet($slideshowAssetId); $status->updateStatistics(); foreach ($properties['slidestep']['slides'] as $slideProperties) { // ---- Clean the inputs ---- if (isset($slideProperties['title'])) { $title = $slideProperties['title']; } else { $title = ''; } if (isset($slideProperties['caption'])) { $caption = $slideProperties['caption']; } else { $caption = ''; } if (isset($slideProperties['text_position'])) { $textPosition = String::withValue($slideProperties['text_position']); } else { $textPosition = String::withValue(''); } if (isset($slideProperties['show_target_metadata'])) { $displayMetadata = Boolean::withValue($slideProperties['show_target_metadata']); } else { $displayMetadata = Boolean::false(); } if (isset($slideProperties['_assetId'])) { $targetId = String::withValue($slideProperties['_assetId']->getIdString()); } else { $targetId = String::withValue(''); } // ---- Create the asset ---- $slideAsset = $repository->createAsset($title, $caption, $slideAssetType); $slideAssetId = $slideAsset->getId(); $slideshowAsset->addAsset($slideAssetId); $slideOrder->addItem($slideAssetId); // ---- Set the additional info ---- $slideRecord = $slideAsset->createRecord($slideRecordStructId); $slideRecord->createPart($textPositionPartStructId, $textPosition); $slideRecord->createPart($displayMetadataPartStructId, $displayMetadata); $slideRecord->createPart($targetIdPartStructId, $targetId); $status->updateStatistics(); } // Log the success or failure if (Services::serviceRunning("Logging")) { $loggingManager = Services::getService("Logging"); $log = $loggingManager->getLogForWriting("Concerto"); $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", "Slideshow added"); $item->addNodeId($slideshowAssetId); $item->addNodeId($exhibitionAsset->getId()); $log->appendLogWithTypes($item, $formatType, $priorityType); } $status->updateStatistics(); return TRUE; } else { return FALSE; } }