/** * 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; }