Пример #1
0
 public function test_toFromAssociativeArray_returnsCorrectly()
 {
     $mockAmount = 1;
     $mockAmountType = "dollars";
     $mockBudgetType = "daily";
     $mockArray = array(Budget::AMOUNT => $mockAmount, Budget::AMOUNT_TYPE => $mockAmountType, Budget::BUDGET_TYPE => $mockBudgetType);
     $budget = Budget::fromAssociativeArray($mockArray);
     $this->assertEquals($mockAmount, $budget->getAmount());
     $this->assertEquals($mockAmountType, $budget->getAmountType());
     $this->assertEquals($mockBudgetType, $budget->getBudgetType());
     $mockArray[Budget::VERSION] = Budget::CURR_VERSION;
     $this->assertEquals($mockArray, $budget->toAssociativeArray());
 }
Пример #2
0
 public static function fromAssociativeArray($firehoundBlobArray)
 {
     $name = isset($firehoundBlobArray[self::NAME]) ? $firehoundBlobArray[self::NAME] : null;
     $identifier = isset($firehoundBlobArray[self::IDENTIFIER]) ? $firehoundBlobArray[self::IDENTIFIER] : null;
     $startDate = isset($firehoundBlobArray[self::START_DATE]) ? $firehoundBlobArray[self::START_DATE] : null;
     $endDate = isset($firehoundBlobArray[self::END_DATE]) ? $firehoundBlobArray[self::END_DATE] : null;
     $budgets = null;
     if (isset($firehoundBlobArray[self::BUDGETS]) && is_array($firehoundBlobArray[self::BUDGETS])) {
         $budgets = array();
         foreach ($firehoundBlobArray[self::BUDGETS] as $key => $budgetArray) {
             $budgets[$key] = Budget::fromAssociativeArray($budgetArray);
         }
     }
     $budget = is_array($budgets) ? $budgets : null;
     $targeting = isset($firehoundBlobArray[self::TARGETING]) ? Targeting::fromAssociativeArray($firehoundBlobArray[self::TARGETING]) : null;
     $platformTargeting = isset($firehoundBlobArray[self::PLATFORM_TARGETING]) ? PlatformTargeting::fromAssociativeArray($firehoundBlobArray[self::PLATFORM_TARGETING]) : null;
     $exchangeTargeting = isset($firehoundBlobArray[self::EXCHANGE_TARGETING]) ? ExchangeTargeting::fromAssociativeArray($firehoundBlobArray[self::EXCHANGE_TARGETING]) : null;
     $creative = self::getCreativeFromBlobArray($firehoundBlobArray);
     $context = isset($firehoundBlobArray[self::CONTEXT]) ? Context::fromAssociativeArray($firehoundBlobArray[self::CONTEXT]) : null;
     $firehoundBlob = new FirehoundBlob($name, $identifier, $startDate, $endDate, $budget, $targeting, $platformTargeting, $exchangeTargeting, $creative, $context);
     return $firehoundBlob;
 }
 /**
  * @param $array array
  */
 public function fromArray($array)
 {
     $this->status = $this->safeGet($array, self::STATUS);
     $this->endDate = $this->safeGet($array, self::END_DATE);
     $this->startDate = $this->safeGet($array, self::START_DATE);
     $geographicTargeting = $this->safeGet($array, self::GEOGRAPHIC_TARGETING);
     if (!empty($geographicTargeting)) {
         $this->geographicTargeting = new FacebookGeographicTargeting($geographicTargeting);
     }
     $demographicTargeting = $this->safeGet($array, self::DEMOGRAPHIC_TARGETING);
     if (!empty($demographicTargeting)) {
         $this->demographicTargeting = new FacebookDemographicTargeting($demographicTargeting);
         // versioned
     }
     $audienceTargeting = $this->safeGet($array, self::AUDIENCE_TARGETING);
     if (!empty($audienceTargeting)) {
         $this->audienceTargeting = new FacebookAudienceTargeting($audienceTargeting);
         // versioned
     }
     $this->objectsToUpdate = $this->safeGet($array, self::OBJECTS_TO_UPDATE);
     $this->adAccountId = $this->safeGet($array, self::AD_ACCOUNT_ID);
     $this->pageId = $this->safeGet($array, self::PAGE_ID);
     $this->accessToken = $this->safeGet($array, self::ACCESS_TOKEN);
     $this->igActorId = $this->safeGet($array, self::IG_ACTOR_ID);
     $creatives = $this->safeGet($array, self::CREATIVES, []);
     $this->creatives = [];
     foreach ($creatives as $creative) {
         $fbCreative = new FacebookCreative();
         $fbCreative->fromArray($creative);
         $this->creatives[] = $fbCreative;
     }
     $adSetResults = [];
     $adSets = $this->safeGet($array, self::AD_SETS, []);
     foreach ($adSets as $adSetArray) {
         $adSet = new FacebookAdSet();
         $adSet->fromAssociativeArray($adSetArray);
         $adSetResults[] = $adSet;
     }
     $this->adSets = $adSetResults;
     // versioned, might need builder
     $budget = $this->safeGet($array, self::BUDGET);
     if (!empty($budget)) {
         $budget = new Budget(null);
         $budget->fromArray($this->safeGet($array, self::BUDGET));
         $this->budget = $budget;
     }
 }