Beispiel #1
0
 /**
  * Build the XML content for this action
  * 
  * @return void
  * @access protected
  * @since 1/14/09
  */
 protected function buildXml()
 {
     $upload = RequestContext::value('media_file');
     if ($upload['error']) {
         throw new OperationFailedException("Upload Error: " . $upload['error']);
     }
     if (!$upload['size']) {
         $postMax = ByteSize::fromString(ini_get('post_max_size'));
         $uploadMax = ByteSize::fromString(ini_get('upload_max_filesize'));
         $memoryLimit = ByteSize::fromString(ini_get('memory_limit'));
         $min = $postMax;
         if ($min->isGreaterThan($uploadMax)) {
             $min = $uploadMax;
         }
         if ($min->isGreaterThan($memoryLimit)) {
             $min = $memoryLimit;
         }
         throw new OperationFailedException("No file uploaded or file too big. Max: " . $min->asString());
     }
     $file = $this->addVideo(RequestContext::value('directory'), base64_encode(file_get_contents($upload['tmp_name'])), $upload['name'], $upload['type'], $upload['size']);
     print "\n<file ";
     print "name=\"" . $file['name'] . "\" ";
     print "httpUrl=\"" . $file['httpurl'] . "\" ";
     print "rtmpUrl=\"" . $file['rtmpurl'] . "\" ";
     print "mimeType=\"" . $file['mimetype'] . "\" ";
     print "size=\"" . $file['size'] . "\" ";
     print "date=\"" . $file['date'] . "\" ";
     if (isset($file['creator'])) {
         print "creator=\"" . $file['creator'] . "\" ";
     } else {
         print "creator=\"\" ";
     }
     if (isset($file['fullframeurl'])) {
         print "fullframeUrl=\"" . $file['fullframeurl'] . "\" ";
     } else {
         print "fullframeUrl=\"\" ";
     }
     if (isset($file['thumburl'])) {
         print "thumbUrl=\"" . $file['thumburl'] . "\" ";
     } else {
         print "thumbUrl=\"\" ";
     }
     if (isset($file['splashurl'])) {
         print "splashUrl=\"" . $file['splashurl'] . "\" ";
     } else {
         print "splashUrl=\"\" ";
     }
     print ">";
     print "\n\t<embedCode><![CDATA[";
     print $file['embedcode'];
     print "]]></embedCode>";
     print "</file>";
 }
 /**
  * Update the value for this Part.
  * 
  * @param object mixed $value (original type: java.io.Serializable)
  * 
  * @throws object RepositoryException An exception with one of
  *		   the following messages defined in
  *		   org.osid.repository.RepositoryException may be thrown: {@link
  *		   org.osid.repository.RepositoryException#OPERATION_FAILED
  *		   OPERATION_FAILED}, {@link
  *		   org.osid.repository.RepositoryException#PERMISSION_DENIED
  *		   PERMISSION_DENIED}, {@link
  *		   org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  *		   CONFIGURATION_ERROR}, {@link
  *		   org.osid.repository.RepositoryException#UNIMPLEMENTED
  *		   UNIMPLEMENTED}, {@link
  *		   org.osid.repository.RepositoryException#NULL_ARGUMENT
  *		   NULL_ARGUMENT}
  * 
  * @access public
  */
 function updateValue($value)
 {
     ArgumentValidator::validate($value, StringValidatorRule::getRule());
     // Store the size in the object in case its asked for again.
     try {
         $size = ByteSize::fromString($value);
     } catch (InvalidArgumentException $e) {
         $size = ByteSize::withValue(0);
     }
     $this->_size = $size->value();
     // then write it to the database.
     $dbHandler = Services::getService("DatabaseManager");
     // Check to see if the name is in the database
     $query = new SelectQuery();
     $query->addTable("dr_file");
     $query->addColumn("COUNT(*) as count");
     $query->addWhere("id = '" . $this->_recordId->getIdString() . "'");
     $result = $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
     // If it already exists, use an update query.
     if ($result->field("count") > 0) {
         $query = new UpdateQuery();
         $query->setTable("dr_file");
         $query->setColumns(array("size"));
         $query->setValues(array("'" . addslashes($this->_size) . "'"));
         $query->addWhere("id = '" . $this->_recordId->getIdString() . "'");
     } else {
         $query = new InsertQuery();
         $query->setTable("dr_file");
         $query->setColumns(array("id", "size"));
         $query->setValues(array("'" . $this->_recordId->getIdString() . "'", "'" . addslashes($this->_size) . "'"));
     }
     $result->free();
     // run the query
     $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
     $this->_asset->updateModificationDate();
 }
 function test_fromString()
 {
     $num = ByteSize::fromString('280 B');
     $this->assertEqual($num->printableString(), '280 B');
     $this->assertEqual(round($num->multipleOfPowerOf2(0), 2), 280);
     $num = ByteSize::fromString('2800 B');
     $this->assertEqual($num->printableString(), '2.73 kB');
     $this->assertEqual(round($num->multipleOfPowerOf2(0), 2), 2800);
     $num = ByteSize::fromString('2.73 kB');
     $this->assertEqual($num->printableString(), '2.73 kB');
     $this->assertEqual(round($num->multipleOfPowerOf2(0), 2), 2796);
     $num = ByteSize::fromString('2.73kB');
     $this->assertEqual($num->printableString(), '2.73 kB');
     $this->assertEqual(round($num->multipleOfPowerOf2(0), 2), 2796);
     $num = ByteSize::fromString('2.73kb');
     $this->assertEqual($num->printableString(), '2.73 kB');
     $this->assertEqual(round($num->multipleOfPowerOf2(0), 2), 2796);
     $num = ByteSize::fromString('2.73 KB');
     $this->assertEqual($num->printableString(), '2.73 kB');
     $this->assertEqual(round($num->multipleOfPowerOf2(0), 2), 2796);
     $num = ByteSize::fromString('2.73KB');
     $this->assertEqual($num->printableString(), '2.73 kB');
     $this->assertEqual(round($num->multipleOfPowerOf2(0), 2), 2796);
     $num = ByteSize::fromString('2.73		kB');
     $this->assertEqual($num->printableString(), '2.73 kB');
     $this->assertEqual(round($num->multipleOfPowerOf2(0), 2), 2796);
     $num = ByteSize::fromString('2.68 MB');
     $this->assertEqual($num->printableString(), '2.68 MB');
     $num = ByteSize::fromString('8.20 GB');
     $this->assertEqual($num->printableString(), '8.20 GB');
     $num = ByteSize::fromString('66.17 YB');
     $this->assertEqual($num->printableString(), '66.17 YB');
     $this->assertEqual(round($this->reallyBigNum->multipleOfPowerOf2(0), 2), 8.000000000000001E+25);
     $num = ByteSize::fromString('80000000000000000000000000 B');
     $this->assertEqual($num->printableString(), '66.17 YB');
     $this->assertEqual(round($this->reallyBigNum->multipleOfPowerOf2(0), 2), 8.000000000000001E+25);
 }
Beispiel #4
0
 /**
  * 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 12/7/07
  */
 function saveWizard($cacheName)
 {
     $wizard = $this->getWizard($cacheName);
     $slot = $wizard->slot;
     $values = $wizard->getAllValues();
     $changes = array();
     try {
         if ($slot->getType() != $values['slot']['type']) {
             $changes[] = "Type changed from " . $slot->getType() . " to " . $values['slot']['type'];
             $slotMgr = SlotManager::instance();
             $slot = $slotMgr->convertSlotToType($slot, $values['slot']['type']);
         }
         if ($slot->getLocationCategory() != $values['slot']['category']) {
             $changes[] = "Location Category changed from " . $slot->getLocationCategory() . " to " . $values['slot']['category'];
             $slot->setLocationCategory($values['slot']['category']);
         }
         if (strlen($values['slot']['quota'])) {
             $quota = ByteSize::fromString($values['slot']['quota']);
             if (!$quota->isEqual($slot->getMediaQuota())) {
                 $slot->setMediaQuota($quota);
             }
         } else {
             $slot->useDefaultMediaQuota();
         }
         $idMgr = Services::getService("Id");
         $oldOwners = array();
         foreach ($slot->getOwners() as $ownerId) {
             $oldOwners[] = $ownerId->getIdString();
         }
         $newOwners = $values['slot']['owners'];
         $agentMgr = Services::getService("Agent");
         // Remove any needed existing owners
         foreach ($oldOwners as $idString) {
             if (!in_array($idString, $newOwners)) {
                 $slot->removeOwner($idMgr->getId($idString));
                 try {
                     $agent = $agentMgr->getAgent($idMgr->getId($idString));
                     $agentName = $agent->getDisplayName();
                 } catch (Exception $e) {
                     $agentName = 'Unknown';
                 }
                 $changes[] = "Owner {$agentName} ({$idString}) removed";
             }
         }
         // Add an needed new owners
         foreach ($newOwners as $idString) {
             if (!in_array($idString, $oldOwners)) {
                 $slot->addOwner($idMgr->getId($idString));
                 try {
                     $agent = $agentMgr->getAgent($idMgr->getId($idString));
                     $agentName = $agent->getDisplayName();
                 } catch (Exception $e) {
                     $agentName = 'Unknown';
                 }
                 $changes[] = "Owner {$agentName} ({$idString}) added";
             }
         }
     } catch (Exception $e) {
         print $e->getMessage();
         return false;
     }
     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("Modify Placeholder", "Placeholder changed:  '" . $slot->getShortname() . "'. <br/><br/>Changes: <br/> " . implode(",<br/> ", $changes));
         $log->appendLogWithTypes($item, $formatType, $priorityType);
     }
     return true;
 }