/** * return the flavor params the best fits the fileFormat for a given partner_id * * @param int $partnerId * @param string $fileFormat * @return FlavorParams */ public static function getFlavorParamsFromFileFormat($partnerId, $fileFormat, $ignoreSourceTag = true) { $defaultCriteria = flavorParamsPeer::getCriteriaFilter()->getFilter(); $defaultCriteria->remove(flavorParamsPeer::PARTNER_ID); // flavorParamsPeer::allowAccessToPartner0AndPartnerX($partnerId); // the flavor params can be from partner 0 too $c = new Criteria(); $c->addAnd(flavorParamsPeer::PARTNER_ID, array($partnerId, 0), Criteria::IN); // $c->add ( flavorParamsPeer::FORMAT , $fileFormat ); $possible_flavor_params = flavorParamsPeer::doSelect($c); flavorParamsPeer::setDefaultCriteriaFilter(); $best_fp = null; foreach ($possible_flavor_params as $fp) { if ($fileFormat != $fp->getFormat()) { continue; } if ($ignoreSourceTag && $fp->hasTag(flavorParams::TAG_SOURCE)) { continue; } if (!$best_fp) { $best_fp = $fp; } if ($fp->getPartnerId() != $partnerId) { continue; } // same format for the partner $best_fp = $fp; break; } // if not fount any - choose the first flavor params from the list if (!$best_fp) { $best_fp = $possible_flavor_params[0]; } return $best_fp; }
/** * Get Flavor Asset with the relevant Flavor Params (Flavor Params can exist without Flavor Asset & vice versa) * * @action getFlavorAssetsWithParams * @param string $entryId * @return KalturaFlavorAssetWithParamsArray */ public function getFlavorAssetsWithParamsAction($entryId) { $dbEntry = entryPeer::retrieveByPK($entryId); if (!$dbEntry) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId); } // get all the flavor params of partner 0 and the current partner (note that partner 0 is defined as partner group in service.ct) $flavorParamsDb = flavorParamsPeer::doSelect(new Criteria()); // get the flavor assets for this entry $c = new Criteria(); $c->add(flavorAssetPeer::ENTRY_ID, $entryId); $c->add(flavorAssetPeer::STATUS, array(flavorAsset::FLAVOR_ASSET_STATUS_DELETED, flavorAsset::FLAVOR_ASSET_STATUS_TEMP), Criteria::NOT_IN); $flavorAssetsDb = flavorAssetPeer::doSelect($c); // find what flavot params are required $requiredFlavorParams = array(); foreach ($flavorAssetsDb as $item) { $requiredFlavorParams[$item->getFlavorParamsId()] = true; } // now merge the results, first organize the flavor params in an array with the id as the key $flavorParamsArray = array(); foreach ($flavorParamsDb as $item) { $flavorParams = $item->getId(); $flavorParamsArray[$flavorParams] = $item; if (isset($requiredFlavorParams[$flavorParams])) { unset($requiredFlavorParams[$flavorParams]); } } // adding missing required flavors params to the list if (count($requiredFlavorParams)) { $flavorParamsDb = flavorParamsPeer::retrieveByPKsNoFilter(array_keys($requiredFlavorParams)); foreach ($flavorParamsDb as $item) { $flavorParamsArray[$item->getId()] = $item; } } $usedFlavorParams = array(); // loop over the flavor assets and add them, if it has flavor params add them too $flavorAssetWithParamsArray = new KalturaFlavorAssetWithParamsArray(); foreach ($flavorAssetsDb as $flavorAssetDb) { $flavorParamsId = $flavorAssetDb->getFlavorParamsId(); $flavorAssetWithParams = new KalturaFlavorAssetWithParams(); $flavorAssetWithParams->entryId = $entryId; $flavorAsset = new KalturaFlavorAsset(); $flavorAsset->fromObject($flavorAssetDb); $flavorAssetWithParams->flavorAsset = $flavorAsset; if (isset($flavorParamsArray[$flavorParamsId])) { $flavorParamsDb = $flavorParamsArray[$flavorParamsId]; $flavorParams = KalturaFlavorParamsFactory::getFlavorParamsInstance($flavorParamsDb->getType()); $flavorParams->fromObject($flavorParamsDb); $flavorAssetWithParams->flavorParams = $flavorParams; // we want to log which flavor params are in use, there could be more // than one flavor asset using same params $usedFlavorParams[$flavorParamsId] = $flavorParamsId; } // else if ($flavorAssetDb->getIsOriginal()) // { // // create a dummy flavor params // $flavorParams = new KalturaFlavorParams(); // $flavorParams->name = "Original source"; // $flavorAssetWithParams->flavorParams = $flavorParams; // } $flavorAssetWithParamsArray[] = $flavorAssetWithParams; } // copy the remaining params foreach ($flavorParamsArray as $flavorParamsId => $flavorParamsDb) { if (isset($usedFlavorParams[$flavorParamsId])) { // flavor params already exists for a flavor asset, not need // to list it one more time continue; } $flavorParams = KalturaFlavorParamsFactory::getFlavorParamsInstance($flavorParamsDb->getType()); $flavorParams->fromObject($flavorParamsDb); $flavorAssetWithParams = new KalturaFlavorAssetWithParams(); $flavorAssetWithParams->entryId = $entryId; $flavorAssetWithParams->flavorParams = $flavorParams; $flavorAssetWithParamsArray[] = $flavorAssetWithParams; } return $flavorAssetWithParamsArray; }
/** * @param int $conversionProfileId * @param $con * @return array<flavorParamsOutput> */ public static function retrieveByProfile($conversionProfileId, $con = null) { $flavorIds = flavorParamsConversionProfilePeer::getFlavorIdsByProfileId($conversionProfileId); $criteria = new Criteria(); $criteria->add(flavorParamsPeer::ID, $flavorIds, Criteria::IN); return flavorParamsPeer::doSelect($criteria, $con); }
public function execute() { $this->forceSystemAuthentication(); $this->pid = $this->getRequestParameter("pid", 0); if (!is_null($this->getRequestParameter("advanced"))) { $this->getResponse()->setCookie('flavor-params-advanced', $this->getRequestParameter("advanced")); $this->advanced = (int) $this->getRequestParameter("advanced"); } else { $this->advanced = (int) $this->getRequest()->getCookie('flavor-params-advanced'); } myDbHelper::$use_alternative_con = null; $this->editFlavorParam = null; if ($this->getRequestParameter("id")) { $this->editFlavorParam = flavorParamsPeer::retrieveByPK($this->getRequestParameter("id")); if ($this->getRequestParameter("clone")) { $newFalvorParams = $this->editFlavorParam->copy(); $newFalvorParams->setIsDefault(false); $newFalvorParams->setPartnerId(-1); $newFalvorParams->save(); $this->redirect("system/flavorParams?pid=" . $this->pid . "&id=" . $newFalvorParams->getId()); } if ($this->getRequestParameter("delete")) { if ($this->advanced || $this->editFlavorParam->getPartnerId() != 0) { $this->editFlavorParam->setDeletedAt(time()); $this->editFlavorParam->save(); } $this->redirect("system/flavorParams?pid=" . $this->pid); } if ($this->getRequest()->getMethod() == sfRequest::POST) { if ($this->advanced || $this->editFlavorParam->getPartnerId() != 0) { $partnerId = $this->getRequestParameter("partner-id"); if ($this->advanced) { $this->editFlavorParam->setPartnerId($partnerId); } else { if ($partnerId != 0) { $this->editFlavorParam->setPartnerId($partnerId); } } if ($this->advanced >= 1) { $this->editFlavorParam->setName($this->getRequestParameter("name")); $this->editFlavorParam->setDescription($this->getRequestParameter("description")); $this->editFlavorParam->setIsDefault($this->getRequestParameter("is-default", false)); $this->editFlavorParam->setReadyBehavior($this->getRequestParameter("ready-behavior")); $this->editFlavorParam->setTags($this->getRequestParameter("tags")); $this->editFlavorParam->setFormat($this->getRequestParameter("format")); $this->editFlavorParam->setTwoPass($this->getRequestParameter("two-pass", false)); $this->editFlavorParam->setWidth($this->getRequestParameter("width")); $this->editFlavorParam->setHeight($this->getRequestParameter("height")); $this->editFlavorParam->setVideoCodec($this->getRequestParameter("video-codec")); $this->editFlavorParam->setVideoBitrate($this->getRequestParameter("video-bitrate")); $this->editFlavorParam->setFrameRate($this->getRequestParameter("frame-rate")); $this->editFlavorParam->setGopSize($this->getRequestParameter("gop-size")); $this->editFlavorParam->setAudioCodec($this->getRequestParameter("audio-codec")); $this->editFlavorParam->setAudioBitrate($this->getRequestParameter("audio-bitrate")); $this->editFlavorParam->setAudioChannels($this->getRequestParameter("audio-channels")); $this->editFlavorParam->setAudioSampleRate($this->getRequestParameter("audio-sample-rate")); $this->editFlavorParam->setAudioResolution($this->getRequestParameter("audio-resolution")); $this->editFlavorParam->setConversionEngines($this->getRequestParameter("conversion-engines")); $this->editFlavorParam->setConversionEnginesExtraParams($this->getRequestParameter("conversion-engines-extra-params")); $this->editFlavorParam->setOperators($this->getRequestParameter("operators")); $this->editFlavorParam->setEngineVersion($this->getRequestParameter("engine-version")); } $this->editFlavorParam->save(); } $this->redirect("system/flavorParams?pid=" . $this->editFlavorParam->getPartnerId()); } } $c = new Criteria(); $c->add(flavorParamsPeer::PARTNER_ID, array(0, $this->pid), Criteria::IN); $this->flavorParams = flavorParamsPeer::doSelect($c); $this->formats = self::getEnumValues("flavorParams", "CONTAINER_FORMAT"); $this->videoCodecs = self::getEnumValues("flavorParams", "VIDEO_CODEC"); $this->audioCodecs = self::getEnumValues("flavorParams", "AUDIO_CODEC"); $this->readyBehaviors = self::getEnumValues("flavorParamsConversionProfile", "READY_BEHAVIOR"); $this->creationModes = self::getEnumValues("flavorParams", "CREATION_MODE"); }
/** * List Flavor Params by filter with paging support (By default - all system default params will be listed too) * * @action list * @param KalturaFlavorParamsFilter $filter * @param KalturaFilterPager $pager * @return KalturaFlavorParamsListResponse */ public function listAction(KalturaFlavorParamsFilter $filter = null, KalturaFilterPager $pager = null) { if (!$filter) { $filter = new KalturaFlavorParamsFilter(); } if (!$pager) { $pager = new KalturaFilterPager(); } $flavorParamsFilter = new assetParamsFilter(); $filter->toObject($flavorParamsFilter); $c = new Criteria(); $flavorParamsFilter->attachToCriteria($c); $pager->attachToCriteria($c); $dbList = flavorParamsPeer::doSelect($c); $c->setLimit(null); $totalCount = flavorParamsPeer::doCount($c); $list = KalturaFlavorParamsArray::fromDbArray($dbList); $response = new KalturaFlavorParamsListResponse(); $response->objects = $list; $response->totalCount = $totalCount; return $response; }