Skip to content

Commit

Permalink
fix(campaigns): split campaigns settings and provide correct setting …
Browse files Browse the repository at this point in the history
…options list
  • Loading branch information
SonicGD committed Oct 20, 2021
1 parent eb52591 commit 2d04270
Show file tree
Hide file tree
Showing 11 changed files with 239 additions and 11 deletions.
20 changes: 16 additions & 4 deletions src/services/campaigns/CampaignsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
use directapi\services\campaigns\criterias\CampaignsSelectionCriteria;
use directapi\services\campaigns\enum\CampaignFieldEnum;
use directapi\services\campaigns\enum\CpmBannerCampaignFieldEnum;
use directapi\services\campaigns\enum\CpmCampaignSettingsEnum;
use directapi\services\campaigns\enum\DynamicCampaignFieldEnum;
use directapi\services\campaigns\enum\DynamicCampaignSettingsEnum;
use directapi\services\campaigns\enum\MobileAppCampaignFieldEnum;
use directapi\services\campaigns\enum\MobileAppCampaignSettingsEnum;
use directapi\services\campaigns\enum\SmartCampaignFieldEnum;
use directapi\services\campaigns\enum\SmartCampaignSettingsEnum;
use directapi\services\campaigns\enum\TextCampaignFieldEnum;
use directapi\services\campaigns\enum\TextCampaignSettingsEnum;
use directapi\services\campaigns\models\CampaignAddItem;
Expand Down Expand Up @@ -201,7 +205,7 @@ public function toUpdateEntities(array $entities): array
* @var CampaignUpdateItem[] $converted
*/
$converted = $this->convertClass($entities, CampaignUpdateItem::class);
foreach ($converted as &$campaign) {
foreach ($converted as $campaign) {
if ($campaign->TextCampaign && $campaign->TextCampaign->Settings) {
foreach ($campaign->TextCampaign->Settings as $i => $setting) {
if (TextCampaignSettingsEnum::isGetOnly($setting->Option)) {
Expand All @@ -212,28 +216,36 @@ public function toUpdateEntities(array $entities): array
}
if ($campaign->CpmBannerCampaign && $campaign->CpmBannerCampaign->Settings) {
foreach ($campaign->CpmBannerCampaign->Settings as $i => $setting) {
if (TextCampaignSettingsEnum::isGetOnly($setting->Option)) {
if (CpmCampaignSettingsEnum::isGetOnly($setting->Option)) {
unset($campaign->CpmBannerCampaign->Settings[$i]);
}
}
$campaign->CpmBannerCampaign->Settings = array_values($campaign->CpmBannerCampaign->Settings);
}
if ($campaign->DynamicTextCampaign && $campaign->DynamicTextCampaign->Settings) {
foreach ($campaign->DynamicTextCampaign->Settings as $i => $setting) {
if (TextCampaignSettingsEnum::isGetOnly($setting->Option)) {
if (DynamicCampaignSettingsEnum::isGetOnly($setting->Option)) {
unset($campaign->DynamicTextCampaign->Settings[$i]);
}
}
$campaign->DynamicTextCampaign->Settings = array_values($campaign->DynamicTextCampaign->Settings);
}
if ($campaign->SmartCampaign && $campaign->SmartCampaign->Settings) {
foreach ($campaign->SmartCampaign->Settings as $i => $setting) {
if (TextCampaignSettingsEnum::isGetOnly($setting->Option)) {
if (SmartCampaignSettingsEnum::isGetOnly($setting->Option)) {
unset($campaign->SmartCampaign->Settings[$i]);
}
}
$campaign->SmartCampaign->Settings = array_values($campaign->SmartCampaign->Settings);
}
if ($campaign->MobileAppCampaign && $campaign->MobileAppCampaign->Settings) {
foreach ($campaign->MobileAppCampaign->Settings as $i => $setting) {
if (MobileAppCampaignSettingsEnum::isGetOnly($setting->Option)) {
unset($campaign->MobileAppCampaign->Settings[$i]);
}
}
$campaign->MobileAppCampaign->Settings = array_values($campaign->MobileAppCampaign->Settings);
}
}
return $converted;
}
Expand Down
33 changes: 33 additions & 0 deletions src/services/campaigns/enum/CpmCampaignSettingsEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace directapi\services\campaigns\enum;

use directapi\components\Enum;

class CpmCampaignSettingsEnum extends Enum
{
public const ADD_METRICA_TAG = 'ADD_METRICA_TAG';
public const ADD_OPENSTAT_TAG = 'ADD_OPENSTAT_TAG';
public const ADD_TO_FAVORITES = 'ADD_TO_FAVORITES';
public const ENABLE_AREA_OF_INTEREST_TARGETING = 'ENABLE_AREA_OF_INTEREST_TARGETING';
public const ENABLE_SITE_MONITORING = 'ENABLE_SITE_MONITORING';
public const REQUIRE_SERVICING = 'REQUIRE_SERVICING';
public const SHARED_ACCOUNT_ENABLED = 'SHARED_ACCOUNT_ENABLED';
public const DAILY_BUDGET_ALLOWED = 'DAILY_BUDGET_ALLOWED';

/**
* @var array
*/
private static $getOnly = [
self::SHARED_ACCOUNT_ENABLED,
self::DAILY_BUDGET_ALLOWED,
];

public static function isGetOnly(CpmCampaignSettingsEnum $value): bool
{
if (in_array((string)$value, self::$getOnly, true)) {
return true;
}
return false;
}
}
37 changes: 37 additions & 0 deletions src/services/campaigns/enum/DynamicCampaignSettingsEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace directapi\services\campaigns\enum;

use directapi\components\Enum;

class DynamicCampaignSettingsEnum extends Enum
{
public const ADD_METRICA_TAG = 'ADD_METRICA_TAG';
public const ADD_OPENSTAT_TAG = 'ADD_OPENSTAT_TAG';
public const ADD_TO_FAVORITES = 'ADD_TO_FAVORITES';
public const ENABLE_AREA_OF_INTEREST_TARGETING = 'ENABLE_AREA_OF_INTEREST_TARGETING';
public const ENABLE_COMPANY_INFO = 'ENABLE_COMPANY_INFO';
public const ENABLE_EXTENDED_AD_TITLE = 'ENABLE_EXTENDED_AD_TITLE';
public const ENABLE_SITE_MONITORING = 'ENABLE_SITE_MONITORING';
public const REQUIRE_SERVICING = 'REQUIRE_SERVICING';
public const SHARED_ACCOUNT_ENABLED = 'SHARED_ACCOUNT_ENABLED';
public const DAILY_BUDGET_ALLOWED = 'DAILY_BUDGET_ALLOWED';
public const CAMPAIGN_EXACT_PHRASE_MATCHING_ENABLED = 'CAMPAIGN_EXACT_PHRASE_MATCHING_ENABLED';

/**
* @var array
*/
private static $getOnly = [
self::SHARED_ACCOUNT_ENABLED,
self::DAILY_BUDGET_ALLOWED,
self::CAMPAIGN_EXACT_PHRASE_MATCHING_ENABLED
];

public static function isGetOnly(DynamicCampaignSettingsEnum $value): bool
{
if (\in_array((string)$value, self::$getOnly, true)) {
return true;
}
return false;
}
}
24 changes: 23 additions & 1 deletion src/services/campaigns/enum/MobileAppCampaignSettingsEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,30 @@
class MobileAppCampaignSettingsEnum extends Enum
{
public const ADD_TO_FAVORITES = 'ADD_TO_FAVORITES';
public const ENABLE_BEHAVIORAL_TARGETING = 'ENABLE_BEHAVIORAL_TARGETING';
public const ENABLE_AUTOFOCUS = 'ENABLE_AUTOFOCUS';
public const REQUIRE_SERVICING = 'REQUIRE_SERVICING';
public const MAINTAIN_NETWORK_CPC = 'MAINTAIN_NETWORK_CPC';
public const ENABLE_AREA_OF_INTEREST_TARGETING = 'ENABLE_AREA_OF_INTEREST_TARGETING';
public const SHARED_ACCOUNT_ENABLED = 'SHARED_ACCOUNT_ENABLED';
public const DAILY_BUDGET_ALLOWED = 'DAILY_BUDGET_ALLOWED';
public const CAMPAIGN_EXACT_PHRASE_MATCHING_ENABLED = 'CAMPAIGN_EXACT_PHRASE_MATCHING_ENABLED';

/**
* @var array
*/
private static $getOnly = [
self::ENABLE_AUTOFOCUS,
self::MAINTAIN_NETWORK_CPC,
self::SHARED_ACCOUNT_ENABLED,
self::DAILY_BUDGET_ALLOWED,
self::CAMPAIGN_EXACT_PHRASE_MATCHING_ENABLED
];

public static function isGetOnly(MobileAppCampaignSettingsEnum $value): bool
{
if (\in_array((string)$value, self::$getOnly, true)) {
return true;
}
return false;
}
}
31 changes: 31 additions & 0 deletions src/services/campaigns/enum/SmartCampaignSettingsEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace directapi\services\campaigns\enum;

use directapi\components\Enum;

class SmartCampaignSettingsEnum extends Enum
{
public const ADD_TO_FAVORITES = 'ADD_TO_FAVORITES';
public const ENABLE_AREA_OF_INTEREST_TARGETING = 'ENABLE_AREA_OF_INTEREST_TARGETING';
public const REQUIRE_SERVICING = 'REQUIRE_SERVICING';
public const SHARED_ACCOUNT_ENABLED = 'SHARED_ACCOUNT_ENABLED';
public const DAILY_BUDGET_ALLOWED = 'DAILY_BUDGET_ALLOWED';

/**
* @var array
*/
private static $getOnly = [
self::SHARED_ACCOUNT_ENABLED,
self::DAILY_BUDGET_ALLOWED,
self::ENABLE_AREA_OF_INTEREST_TARGETING,
];

public static function isGetOnly(SmartCampaignSettingsEnum $value): bool
{
if (in_array((string)$value, self::$getOnly, true)) {
return true;
}
return false;
}
}
4 changes: 2 additions & 2 deletions src/services/campaigns/models/CpmBannerCampaignItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class CpmBannerCampaignItem extends Model
public $BiddingStrategy;

/**
* @var TextCampaignSetting[]
* @var CpmCampaignSetting[]
* @Assert\Valid()
* @DirectApiAssert\ArrayOf(type="directapi\services\campaigns\models\TextCampaignSetting")
* @DirectApiAssert\ArrayOf(type="directapi\services\campaigns\models\CpmCampaignSetting")
*/
public $Settings;

Expand Down
31 changes: 31 additions & 0 deletions src/services/campaigns/models/CpmCampaignSetting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace directapi\services\campaigns\models;

use directapi\common\enum\YesNoEnum;
use directapi\components\constraints as DirectApiAssert;
use directapi\services\campaigns\enum\CpmCampaignSettingsEnum;
use Symfony\Component\Validator\Constraints as Assert;

class CpmCampaignSetting
{
/**
* @var \directapi\services\campaigns\enum\CpmCampaignSettingsEnum
* @Assert\NotBlank()
* @DirectApiAssert\IsEnum(type="directapi\services\campaigns\enum\CpmCampaignSettingsEnum")
*/
public $Option;

/**
* @var \directapi\common\enum\YesNoEnum
* @Assert\NotBlank()
* @DirectApiAssert\IsEnum(type="directapi\common\enum\YesNoEnum")
*/
public $Value;

public function __construct(?CpmCampaignSettingsEnum $option = null, ?YesNoEnum $value = null)
{
$this->Option = $option;
$this->Value = $value;
}
}
31 changes: 31 additions & 0 deletions src/services/campaigns/models/DynamicCampaignSetting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace directapi\services\campaigns\models;

use directapi\common\enum\YesNoEnum;
use directapi\components\constraints as DirectApiAssert;
use directapi\services\campaigns\enum\DynamicCampaignSettingsEnum;
use Symfony\Component\Validator\Constraints as Assert;

class DynamicCampaignSetting
{
/**
* @var \directapi\services\campaigns\enum\DynamicCampaignSettingsEnum
* @Assert\NotBlank()
* @DirectApiAssert\IsEnum(type="directapi\services\campaigns\enum\DynamicCampaignSettingsEnum")
*/
public $Option;

/**
* @var \directapi\common\enum\YesNoEnum
* @Assert\NotBlank()
* @DirectApiAssert\IsEnum(type="directapi\common\enum\YesNoEnum")
*/
public $Value;

public function __construct(?DynamicCampaignSettingsEnum $option = null, ?YesNoEnum $value = null)
{
$this->Option = $option;
$this->Value = $value;
}
}
4 changes: 2 additions & 2 deletions src/services/campaigns/models/DynamicTextCampaignItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class DynamicTextCampaignItem extends Model
public $BiddingStrategy;

/**
* @var TextCampaignSetting[]
* @var DynamicCampaignSetting[]
* @Assert\Valid()
* @DirectApiAssert\ArrayOf(type="directapi\services\campaigns\models\TextCampaignSetting")
* @DirectApiAssert\ArrayOf(type="directapi\services\campaigns\models\DynamicCampaignSetting")
*/
public $Settings;

Expand Down
4 changes: 2 additions & 2 deletions src/services/campaigns/models/SmartCampaignItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ class SmartCampaignItem extends Model
public $BiddingStrategy;

/**
* @var TextCampaignSetting[]
* @var SmartCampaignSetting[]
* @Assert\Valid()
* @DirectApiAssert\ArrayOf(type="directapi\services\campaigns\models\TextCampaignSetting")
* @DirectApiAssert\ArrayOf(type="directapi\services\campaigns\models\SmartCampaignSetting")
*/
public $Settings;

Expand Down
31 changes: 31 additions & 0 deletions src/services/campaigns/models/SmartCampaignSetting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace directapi\services\campaigns\models;

use directapi\common\enum\YesNoEnum;
use directapi\components\constraints as DirectApiAssert;
use directapi\services\campaigns\enum\SmartCampaignSettingsEnum;
use Symfony\Component\Validator\Constraints as Assert;

class SmartCampaignSetting
{
/**
* @var \directapi\services\campaigns\enum\SmartCampaignSettingsEnum
* @Assert\NotBlank()
* @DirectApiAssert\IsEnum(type="directapi\services\campaigns\enum\SmartCampaignSettingsEnum")
*/
public $Option;

/**
* @var \directapi\common\enum\YesNoEnum
* @Assert\NotBlank()
* @DirectApiAssert\IsEnum(type="directapi\common\enum\YesNoEnum")
*/
public $Value;

public function __construct(?SmartCampaignSettingsEnum $option = null, ?YesNoEnum $value = null)
{
$this->Option = $option;
$this->Value = $value;
}
}

0 comments on commit 2d04270

Please sign in to comment.