public static function fromDbArray($arr, KalturaDetachedResponseProfile $responseProfile = null)
 {
     $newArr = new KalturaFlavorAssetArray();
     if ($arr == null) {
         return $newArr;
     }
     foreach ($arr as $obj) {
         $nObj = KalturaFlavorAsset::getInstanceByType($obj->getType());
         $nObj->fromObject($obj, $responseProfile);
         $newArr[] = $nObj;
     }
     return $newArr;
 }
Exemple #2
0
 /**
  * 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)
     $c = new Criteria();
     $flavorTypes = assetParamsPeer::retrieveAllFlavorParamsTypes();
     $c->add(assetParamsPeer::TYPE, $flavorTypes, Criteria::IN);
     $partnerIds = array($dbEntry->getPartnerId(), PartnerPeer::GLOBAL_PARTNER);
     $c->add(assetParamsPeer::PARTNER_ID, array_map('strval', $partnerIds), Criteria::IN);
     $flavorParamsDb = assetParamsPeer::doSelect($c);
     // get the flavor assets for this entry
     $c = new Criteria();
     $flavorTypes = assetPeer::retrieveAllFlavorsTypes();
     $c->add(assetPeer::TYPE, $flavorTypes, Criteria::IN);
     $c->add(assetPeer::ENTRY_ID, $entryId);
     $c->add(assetPeer::STATUS, array(flavorAsset::FLAVOR_ASSET_STATUS_DELETED, flavorAsset::FLAVOR_ASSET_STATUS_TEMP), Criteria::NOT_IN);
     $flavorAssetsDb = assetPeer::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 = assetParamsPeer::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 = KalturaFlavorAsset::getInstanceByType($flavorAssetDb->getType());
         $flavorAsset->fromObject($flavorAssetDb, $this->getResponseProfile());
         $flavorAssetWithParams->flavorAsset = $flavorAsset;
         if (isset($flavorParamsArray[$flavorParamsId])) {
             $flavorParamsDb = $flavorParamsArray[$flavorParamsId];
             $flavorParams = KalturaFlavorParamsFactory::getFlavorParamsInstance($flavorParamsDb->getType());
             $flavorParams->fromObject($flavorParamsDb, $this->getResponseProfile());
             $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, $this->getResponseProfile());
         $flavorAssetWithParams = new KalturaFlavorAssetWithParams();
         $flavorAssetWithParams->entryId = $entryId;
         $flavorAssetWithParams->flavorParams = $flavorParams;
         $flavorAssetWithParamsArray[] = $flavorAssetWithParams;
     }
     return $flavorAssetWithParamsArray;
 }