Ejemplo n.º 1
0
 /**
  * @param entry $entry
  * @param SimpleXMLElement $mrss
  * @return SimpleXMLElement
  */
 public function contribute(entry $entry, SimpleXMLElement $mrss)
 {
     $metadatas = MetadataPeer::retrieveAllByObject(Metadata::TYPE_ENTRY, $entry->getId());
     foreach ($metadatas as $metadata) {
         $this->contributeMetadata($metadata, $mrss);
     }
 }
 public function contribute(BaseObject $object, SimpleXMLElement $mrss, kMrssParameters $mrssParams = null)
 {
     $objectType = kMetadataManager::getTypeNameFromObject($object);
     $metadatas = MetadataPeer::retrieveAllByObject($objectType, $object->getId());
     foreach ($metadatas as $metadata) {
         $this->contributeMetadata($metadata, $mrss, $mrssParams);
     }
 }
 public function __construct(KalturaDistributionJobData $distributionJobData = null)
 {
     parent::__construct($distributionJobData);
     if (!$distributionJobData || !$distributionJobData->distributionProfile instanceof KalturaTvinciDistributionProfile || !$distributionJobData->entryDistribution) {
         return;
     }
     $entry = null;
     if ($distributionJobData->entryDistribution->entryId) {
         $entry = entryPeer::retrieveByPK($distributionJobData->entryDistribution->entryId);
     }
     if (!$entry) {
         KalturaLog::err("Can't find entry with id: {$distributionJobData->entryDistribution->entryId}");
         return;
     }
     $feedHelper = new TvinciDistributionFeedHelper($distributionJobData->distributionProfile);
     $feedHelper->setEntryId($entry->getId());
     $feedHelper->setReferenceId($entry->getReferenceID());
     $feedHelper->setDescription($entry->getDescription());
     $feedHelper->setTitleName($entry->getName());
     $feedHelper->setSunrise($distributionJobData->entryDistribution->sunrise);
     $feedHelper->setSunset($distributionJobData->entryDistribution->sunset);
     $thumbAssets = assetPeer::retrieveByIds(explode(',', $distributionJobData->entryDistribution->thumbAssetIds));
     $picRatios = array();
     $defaultThumbUrl = null;
     foreach ($thumbAssets as $thumbAsset) {
         $thumbDownloadUrl = $this->getAssetDownloadUrl($thumbAsset);
         $ratio = KDLVideoAspectRatio::ConvertFrameSize($thumbAsset->getWidth(), $thumbAsset->getHeight());
         $picRatios[] = array('url' => $thumbDownloadUrl, 'ratio' => $ratio);
         if ($thumbAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB)) {
             $defaultThumbUrl = $thumbDownloadUrl;
         }
     }
     $feedHelper->setPicRatiosArray($picRatios);
     if (!$defaultThumbUrl && count($picRatios)) {
         // Choose the URL of the first resource in the array
         $defaultThumbUrl = $picRatios[0]['url'];
     }
     $feedHelper->setDefaultThumbnailUrl($defaultThumbUrl);
     $this->createPlayManifestURLs($distributionJobData->entryDistribution, $entry, $feedHelper);
     $metadatas = MetadataPeer::retrieveAllByObject(MetadataObjectType::ENTRY, $distributionJobData->entryDistribution->entryId);
     $fullMetadataXML = '';
     foreach ($metadatas as $metadataField) {
         $syncKey = $metadataField->getSyncKey(Metadata::FILE_SYNC_METADATA_DATA);
         $currMetaXML = kFileSyncUtils::file_get_contents($syncKey, true, false);
         $fullMetadataXML .= $currMetaXML;
     }
     $feedHelper->setMetasXML($fullMetadataXML);
     if ($distributionJobData instanceof KalturaDistributionSubmitJobData) {
         $this->xml = $feedHelper->buildSubmitFeed();
     } elseif ($distributionJobData instanceof KalturaDistributionUpdateJobData) {
         $this->xml = $feedHelper->buildUpdateFeed();
     } elseif ($distributionJobData instanceof KalturaDistributionDeleteJobData) {
         $this->xml = $feedHelper->buildDeleteFeed();
     }
     KalturaLog::debug("XML Constructed by the Tvinci feed helper :{$this->xml}");
 }
Ejemplo n.º 4
0
 public function validateForSubmission(EntryDistribution $entryDistribution, $action)
 {
     $missingDesc = false;
     $missingTags = false;
     $validationErrors = parent::validateForSubmission($entryDistribution, $action);
     $entry = entryPeer::retrieveByPK($entryDistribution->getEntryId());
     if (!$entry) {
         KalturaLog::err("Entry [" . $entryDistribution->getEntryId() . "] not found");
         $validationErrors[] = $this->createValidationError($action, DistributionErrorType::INVALID_DATA, 'entry', 'entry not found');
         return $validationErrors;
     }
     // validate entry name minumum length of 1 character
     if (strlen($entry->getName()) < self::ENTRY_NAME_MINIMUM_LENGTH) {
         $validationError = $this->createValidationError($action, DistributionErrorType::INVALID_DATA, entryPeer::NAME, '');
         $validationError->setValidationErrorType(DistributionValidationErrorType::STRING_TOO_SHORT);
         $validationError->setValidationErrorParam(self::ENTRY_NAME_MINIMUM_LENGTH);
         $validationErrors[] = $validationError;
     }
     if (strlen($entry->getName()) > self::ENTRY_NAME_MAXIMUM_LENGTH) {
         $description = 'entry name length must be between ' . self::ENTRY_NAME_MINIMUM_LENGTH . ' and ' . self::ENTRY_NAME_MAXIMUM_LENGTH;
         $validationError = $this->createValidationError($action, DistributionErrorType::INVALID_DATA, entryPeer::NAME, $description);
         $validationError->setValidationErrorType(DistributionValidationErrorType::STRING_TOO_LONG);
         $validationError->setValidationErrorParam(self::ENTRY_NAME_MAXIMUM_LENGTH);
         $validationErrors[] = $validationError;
     }
     if (strlen($entry->getDescription()) < self::ENTRY_DESC_MINIMUM_LENGTH) {
         $missingDesc = true;
     }
     if (strlen($entry->getTags()) < self::ENTRY_DESC_MINIMUM_LENGTH) {
         $missingTags = true;
     }
     if (!class_exists('MetadataProfile')) {
         return $validationErrors;
     }
     $metadataFields = array(self::METADATA_FIELD_KEYWORDS, self::METADATA_FIELD_DESCRIPTION);
     $metadataProfileId = $this->getMetadataProfileId();
     $metadatas = MetadataPeer::retrieveAllByObject(MetadataObjectType::ENTRY, $entryDistribution->getEntryId());
     foreach ($metadataFields as $index => $metadataField) {
         $values = $this->findMetadataValue($metadatas, $metadataField);
         if (!count($values)) {
             switch ($metadataField) {
                 case self::METADATA_FIELD_DESCRIPTION:
                     if ($missingDesc) {
                         $validationErrors[] = $this->createValidationError($action, DistributionErrorType::MISSING_METADATA, entryPeer::DESCRIPTION, "");
                     }
                     break;
                 case self::METADATA_FIELD_KEYWORDS:
                     if ($missingTags) {
                         $validationErrors[] = $this->createValidationError($action, DistributionErrorType::MISSING_METADATA, entryPeer::TAGS, "");
                     }
                     break;
                 default:
                     $validationErrors[] = $this->createValidationError($action, DistributionErrorType::MISSING_METADATA, $metadataField);
             }
         }
         foreach ($values as $value) {
             if (!strlen($value)) {
                 $validationError = $this->createValidationError($action, DistributionErrorType::INVALID_DATA, $metadataField, "");
                 $validationError->setValidationErrorType(DistributionValidationErrorType::STRING_EMPTY);
                 $validationError->setMetadataProfileId($metadataProfileId);
                 $validationErrors[] = $validationError;
                 break;
             }
         }
     }
     return $validationErrors;
 }
 public static function generateCuePointXml(SimpleXMLElement $scene, $objectType, $cuePointId)
 {
     $metadatas = MetadataPeer::retrieveAllByObject($objectType, $cuePointId);
     foreach ($metadatas as $metadata) {
         /* @var $metadata Metadata */
         $metadataElement = $scene->addChild('scene-customData');
         $metadataElement->addAttribute('metadataId', $metadata->getId());
         $metadataElement->addAttribute('metadataVersion', $metadata->getVersion());
         $metadataElement->addAttribute('metadataProfileId', $metadata->getMetadataProfileId());
         $metadataElement->addAttribute('metadataProfileVersion', $metadata->getMetadataProfileVersion());
         $key = $metadata->getSyncKey(Metadata::FILE_SYNC_METADATA_DATA);
         $xml = kFileSyncUtils::file_get_contents($key, true, false);
         if ($xml) {
             $xmlElement = new SimpleXMLElement($xml);
             self::appendXML($metadataElement, $xmlElement);
         }
         $metadataProfile = $metadata->getMetadataProfile();
         if (!$metadataProfile) {
             continue;
         }
         if ($metadataProfile->getSystemName()) {
             $metadataElement->addAttribute('metadataProfile', $metadataProfile->getSystemName());
         }
         if ($metadataProfile->getName()) {
             $metadataElement->addAttribute('metadataProfileName', $metadataProfile->getName());
         }
     }
     return $scene;
 }
Ejemplo n.º 6
0
 /**
  * Return search texts per object id
  *
  * @param int $objectType
  * @param string $objectId
  *
  * @return array
  */
 public static function getSearchValuesByObject($objectType, $objectId)
 {
     $metadatas = MetadataPeer::retrieveAllByObject($objectType, $objectId);
     KalturaLog::debug("Found " . count($metadatas) . " metadata object");
     return self::getMetadataValuesByMetadataObjects($metadatas);
 }
Ejemplo n.º 7
0
 public function validateForSubmission(EntryDistribution $entryDistribution, $action)
 {
     // get validation errors from parent class
     $validationErrors = parent::validateForSubmission($entryDistribution, $action);
     // get the entry object
     $entry = entryPeer::retrieveByPK($entryDistribution->getEntryId());
     if (!$entry) {
         KalturaLog::err("Entry [" . $entryDistribution->getEntryId() . "] not found");
         return $validationErrors;
     }
     // validate entry name length
     if (strlen($entry->getName()) < self::ENTRY_NAME_MINIMUM_LENGTH) {
         $description = 'entry name length must be between ' . self::ENTRY_NAME_MINIMUM_LENGTH . ' and ' . self::ENTRY_NAME_MAXIMUM_LENGTH;
         $validationError = $this->createValidationError($action, DistributionErrorType::INVALID_DATA, entryPeer::NAME, $description);
         $validationError->setValidationErrorType(DistributionValidationErrorType::STRING_TOO_SHORT);
         $validationError->setValidationErrorParam(self::ENTRY_NAME_MINIMUM_LENGTH);
         $validationErrors[] = $validationError;
     }
     if (strlen($entry->getName()) > self::ENTRY_NAME_MAXIMUM_LENGTH) {
         $description = 'entry name length must be between ' . self::ENTRY_NAME_MINIMUM_LENGTH . ' and ' . self::ENTRY_NAME_MAXIMUM_LENGTH;
         $validationError = $this->createValidationError($action, DistributionErrorType::INVALID_DATA, entryPeer::NAME, $description);
         $validationError->setValidationErrorType(DistributionValidationErrorType::STRING_TOO_LONG);
         $validationError->setValidationErrorParam(self::ENTRY_NAME_MAXIMUM_LENGTH);
         $validationErrors[] = $validationError;
     }
     // get all metadata objects that related to the entry
     $metadatas = MetadataPeer::retrieveAllByObject(MetadataObjectType::ENTRY, $entryDistribution->getEntryId());
     if (!count($metadatas)) {
         $description = 'field is missing because there is no metadata object defined';
         $validationErrors[] = $this->createValidationError($action, DistributionErrorType::MISSING_METADATA, self::METADATA_FIELD_TEST_DATA, $description);
     }
     // get all fields from all metadata profile for the testData key
     $metadataProfileFields = MetadataProfileFieldPeer::retrieveByPartnerAndKey($this->getPartnerId(), self::METADATA_FIELD_TEST_DATA);
     if (!count($metadataProfileFields)) {
         $description = 'field is not defined in any of the metadata profiles';
         $validationErrors[] = $this->createValidationError($action, DistributionErrorType::MISSING_METADATA, self::METADATA_FIELD_TEST_DATA, $description);
     } elseif (count($metadatas)) {
         // get the values for the testData key from all metadata objects
         $values = $this->findMetadataValue($metadatas, self::METADATA_FIELD_TEST_DATA);
         if (!count($values)) {
             $description = 'field is not defined in any of the metadata objects';
             $validationErrors[] = $this->createValidationError($action, DistributionErrorType::MISSING_METADATA, self::METADATA_FIELD_TEST_DATA, $description);
             continue;
         } else {
             foreach ($metadatas as $metadata) {
                 $values = $this->findMetadataValue(array($metadata), self::METADATA_FIELD_TEST_DATA);
                 foreach ($values as $value) {
                     // validate that the field is not empty
                     if (!strlen($value)) {
                         $description = 'field is empty';
                         $validationError = $this->createValidationError($action, DistributionErrorType::INVALID_DATA, self::METADATA_FIELD_TEST_DATA, $description);
                         $validationError->setValidationErrorType(DistributionValidationErrorType::STRING_EMPTY);
                         $validationError->setMetadataProfileId($metadata->getMetadataProfileId());
                         $validationErrors[] = $validationError;
                         continue;
                     }
                     // match the value to the required format
                     $matches = null;
                     $isMatched = preg_match('/' . self::METADATA_FIELD_TEST_DATA_FORMAT . '/', $value, $matches);
                     if (!$isMatched) {
                         $description = 'test data must match the required format';
                         $validationError = $this->createValidationError($action, DistributionErrorType::INVALID_DATA, self::METADATA_FIELD_TEST_DATA, $description);
                         $validationError->setValidationErrorType(DistributionValidationErrorType::INVALID_FORMAT);
                         $validationError->setValidationErrorParam(self::METADATA_FIELD_TEST_DATA_FORMAT);
                         $validationError->setMetadataProfileId($metadata->getMetadataProfileId());
                         $validationErrors[] = $validationError;
                     }
                     $formatNumber = (int) $matches[1];
                     if ($formatNumber < self::METADATA_FIELD_TEST_DATA_MINIMUM_FORMAT || $formatNumber > self::METADATA_FIELD_TEST_DATA_MAXIMUM_FORMAT) {
                         $description = 'format number must be between ' . self::METADATA_FIELD_TEST_DATA_MINIMUM_FORMAT . ' and ' . self::METADATA_FIELD_TEST_DATA_MAXIMUM_FORMAT;
                         $validationError = $this->createValidationError($action, DistributionErrorType::INVALID_DATA, self::METADATA_FIELD_TEST_DATA, $description);
                         $validationError->setValidationErrorType(DistributionValidationErrorType::CUSTOM_ERROR);
                         $validationError->setMetadataProfileId($metadata->getMetadataProfileId());
                         $validationErrors[] = $validationError;
                     }
                 }
             }
         }
     }
     return $validationErrors;
 }
Ejemplo n.º 8
0
 /**
  * Return search texts per object id
  * 
  * @param int $objectType
  * @param string $objectId
  * 
  * @return array
  */
 public static function getSearchValuesByObject($objectType, $objectId)
 {
     $metadatas = MetadataPeer::retrieveAllByObject($objectType, $objectId);
     KalturaLog::debug("Found " . count($metadatas) . " metadata object");
     $searchTexts = array();
     foreach ($metadatas as $metadata) {
         $searchTexts = self::getSearchValues($metadata, $searchTexts);
     }
     if (!count($searchTexts)) {
         return null;
     }
     return implode(',', $searchTexts);
 }
 /**
  * Return search texts per object id
  * 
  * @param int $objectType
  * @param string $objectId
  * 
  * @return array
  */
 public static function getSearchValuesByObject($objectType, $objectId)
 {
     $metadatas = MetadataPeer::retrieveAllByObject($objectType, $objectId);
     KalturaLog::debug("Found " . count($metadatas) . " metadata object");
     $dataFieldName = MetadataPlugin::getSphinxFieldName(MetadataPlugin::SPHINX_EXPANDER_FIELD_DATA);
     $searchValues = array();
     foreach ($metadatas as $metadata) {
         $searchValues = self::getDataSearchValues($metadata, $searchValues);
     }
     if (isset($searchValues[$dataFieldName])) {
         $searchValues[$dataFieldName] = implode(' ', $searchValues[$dataFieldName]);
     }
     return $searchValues;
 }