private function getRelatedEntrySortValue($profile, $relatedEntryId)
 {
     $relatedEntrydistribution = new EntryDistribution();
     $relatedEntrydistribution->setEntryId($relatedEntryId);
     $relatedEntrydistribution->setPartnerId($profile->getPartnerId());
     $relatedEntrydistribution->setDistributionProfileId($profile->getId());
     return $profile->getFieldValue($relatedEntrydistribution, UverseClickToOrderDistributionField::SORT_ITEMS_BY_FIELD);
 }
 /**
  * @param entry $entry
  * @param DistributionProfile $distributionProfile
  * @return EntryDistribution
  */
 public static function createEntryDistribution(entry $entry, DistributionProfile $distributionProfile)
 {
     $entryDistribution = new EntryDistribution();
     $entryDistribution->setEntryId($entry->getId());
     $entryDistribution->setPartnerId($entry->getPartnerId());
     $entryDistribution->setDistributionProfileId($distributionProfile->getId());
     $entryDistribution->setStatus(EntryDistributionStatus::PENDING);
     self::assignFlavorAssets($entryDistribution, $entry, $distributionProfile);
     self::assignThumbAssets($entryDistribution, $entry, $distributionProfile);
     self::assignAssets($entryDistribution, $entry, $distributionProfile);
     $entryDistribution->save();
     // need to save before checking validations
     $validationErrors = $distributionProfile->validateForSubmission($entryDistribution, DistributionAction::SUBMIT);
     $entryDistribution->setValidationErrorsArray($validationErrors);
     return $entryDistribution;
 }
 /**
  * @param entry $entry
  * @param DistributionProfile $distributionProfile
  * @return EntryDistribution or null if failed to create.
  */
 public static function createEntryDistribution(entry $entry, DistributionProfile $distributionProfile)
 {
     $illegalEntryDistributionStatus = array(EntryDistributionStatus::SUBMITTING, EntryDistributionStatus::UPDATING, EntryDistributionStatus::DELETING, EntryDistributionStatus::IMPORT_SUBMITTING, EntryDistributionStatus::IMPORT_UPDATING);
     $entryDistribution = EntryDistributionPeer::retrieveByEntryAndProfileId($entry->getId(), $distributionProfile->getId());
     if (!$entryDistribution || $entryDistribution->getStatus() == EntryDistributionStatus::DELETED) {
         $entryDistribution = new EntryDistribution();
     } else {
         if (in_array($entryDistribution->getStatus(), $illegalEntryDistributionStatus)) {
             KalturaLog::err("Entry distribution already exist. entry [" . $entry->getId() . "] distribution profile [" . $distributionProfile->getId() . "] status [" . $entryDistribution->getStatus() . "]");
             return null;
         }
     }
     $entryDistribution->setEntryId($entry->getId());
     $entryDistribution->setPartnerId($entry->getPartnerId());
     $entryDistribution->setDistributionProfileId($distributionProfile->getId());
     $entryDistribution->setStatus(EntryDistributionStatus::PENDING);
     self::assignFlavorAssets($entryDistribution, $entry, $distributionProfile);
     self::assignThumbAssets($entryDistribution, $entry, $distributionProfile);
     self::assignAssets($entryDistribution, $entry, $distributionProfile);
     $entryDistribution->save();
     // need to save before checking validations
     $validationErrors = $distributionProfile->validateForSubmission($entryDistribution, DistributionAction::SUBMIT);
     $entryDistribution->setValidationErrorsArray($validationErrors);
     return $entryDistribution;
 }