@param array $campaignParams

@return string if no name-value is defined in the $campaignParams, date("y-m-d") will be used
482319
protected function getCampaignName($campaignParams)
    {
        if (array_key_exists($this->tracking_params_campaign_name, $campaignParams)) {
            return $campaignParams[$this->tracking_params_campaign_name];
        }

        return date('y-m-d');
    }
305396
protected function prepareParams(array $params)
	{
		$prepared = [];
		
		foreach($params as $k => $v)
		{
			if(is_array($v))
			{
				foreach(array_values($v) as $i => $val)
				{
					$prepared[sprintf('%s%u', $k, $i)] = $val;
				}
			}
			else
			{
				$prepared[(string)$k] = $v;
			}
		}
		
		return $prepared;
	}
5551
private function decorateParamsForMethodCall(array $params) : string
    {
        $params_out = [];
        foreach($params as $param) {
            $params_out[] = $this->decorateValue($param);
        }
        return implode(',',$params_out);
    }
1359864
public function getSourcesByCampaign($campaignId)
    {
        // WHERE campaign_settings REGEXP '\"campaignId\":\s*\"' . campaing_id . '\",';
        //       $where = 'l.'.$field.' REGEXP  :value';

        $q = $this->_em->getConnection()->createQueryBuilder()
            ->select('cs.*')
            ->from(MAUTIC_TABLE_PREFIX.'contactsource', 'cs');

        $where = 'REPLACE(cs.campaign_settings, " ", "") REGEXP  :regex';
        $q->where(
                $q->expr()->eq('cs.is_published', true),
                $q->expr()->andX($where)
        );

        $q->setParameter('regex', '"campaignId\":"'.$campaignId.'"');

        $results = $q->execute()->fetchAll();

        return $results;
    }
1237513
private function cleanParams(array $params = [])
    {
        if (isset($params['project'])) {
            $apiProject = $this->client->project;
            $params['project_id'] = $apiProject->getIdByName($params['project']);
            unset($params['project']);
            if (isset($params['category'])) {
                $apiIssueCategory = $this->client->issue_category;
                $params['category_id'] = $apiIssueCategory->getIdByName($params['project_id'], $params['category']);
                unset($params['category']);
            }
        }
        if (isset($params['status'])) {
            $apiIssueStatus = $this->client->issue_status;
            $params['status_id'] = $apiIssueStatus->getIdByName($params['status']);
            unset($params['status']);
        }
        if (isset($params['tracker'])) {
            $apiTracker = $this->client->tracker;
            $params['tracker_id'] = $apiTracker->getIdByName($params['tracker']);
            unset($params['tracker']);
        }
        if (isset($params['assigned_to'])) {
            $apiUser = $this->client->user;
            $params['assigned_to_id'] = $apiUser->getIdByUsername($params['assigned_to']);
            unset($params['assigned_to']);
        }
        if (isset($params['author'])) {
            $apiUser = $this->client->user;
            $params['author_id'] = $apiUser->getIdByUsername($params['author']);
            unset($params['author']);
        }

        return $params;
    }
761517
protected function campaignBudgetsAction(Request $request)
    {
        // Get the API payload to test.
        $params['campaignId'] = $this->request->request->get('campaignId');
        $params['dateFrom']   = new \DateTime('now');
        $em                   = $this->container->get('doctrine.orm.entity_manager');
        $statRepo             = $em->getRepository(\MauticPlugin\MauticContactSourceBundle\Entity\Stat::class);
        $data                 = $statRepo->getCampaignBudgetsData($params);
        $headers              = [
            'mautic.contactsource.campaign.budgets.header.source',
            'mautic.contactsource.campaign.budgets.header.cap_name',
            'mautic.contactsource.campaign.budgets.header.today',
            'mautic.contactsource.campaign.budgets.header.daily_cap',
            'mautic.contactsource.campaign.budgets.header.daily_reached',
            'mautic.contactsource.campaign.budgets.header.mtd',
            'mautic.contactsource.campaign.budgets.header.monthly_cap',
            'mautic.contactsource.campaign.budgets.header.monthly_reached',
        ];
        foreach ($headers as $header) {
            $data['columns'][] = [
                'title' => $this->translator->trans($header),
            ];
        }
        $data = UTF8Helper::fixUTF8($data);

        return $this->sendJsonResponse($data);
    }
49268
public function getActiveCampaignPage($campaign) {
    // Check if Campaign is Paused.
    $isPaused = $campaign->get('field_pause_campaign')->value;
    $fieldPauseLandingPage = $campaign->get('field_pause_landing_page')->getValue();
    $landingPageIds = [];
    if ($isPaused && isset($fieldPauseLandingPage[0]['target_id'])) {
      $landingPageIds[] = $fieldPauseLandingPage[0]['target_id'];
    }
    else {
      $fieldCampaignPages = $campaign->get('field_campaign_pages')->getValue();
      foreach ($fieldCampaignPages as $field) {
        $landingPageIds[] = $field['target_id'];
      }
    }
    /** @var \Drupal\node\NodeStorage $nodeStorage */
    $nodeStorage = $this->entityTypeManager->getStorage('node');

    // Load Landing page and check if it's published.
    $landingPages = $nodeStorage->loadMultiple($landingPageIds);
    /** @var \Drupal\node\Entity\Node $node */
    foreach ($landingPages as $node) {
      if ($node->isPublished()) {
        $publishedPages[] = $node;
      }
    }

    // If all pages are disabled, show Pause page.
    if (empty($publishedPages) && isset($fieldPauseLandingPage[0]['target_id'])) {
      return $nodeStorage->load($fieldPauseLandingPage[0]['target_id']);
    }

    return reset($publishedPages);
  }
894901
private static function createCampaign(
        AdWordsServices $adWordsServices,
        AdWordsSession $session,
        Budget $budget
    ) {
        $campaignService = $adWordsServices->get($session, CampaignService::class);

        // Create campaign with some properties set.
        $campaign = new Campaign();
        $campaign->setName('Interplanetary Cruise #' . uniqid());
        $campaign->setAdvertisingChannelType(AdvertisingChannelType::SEARCH);

        // Recommendation: Set the campaign to PAUSED when creating it to prevent
        // the ads from immediately serving. Set to ENABLED once you've added
        // targeting and the ads are ready to serve.
        $campaign->setStatus(CampaignStatus::PAUSED);

        $biddingStrategyConfiguration = new BiddingStrategyConfiguration();
        $biddingStrategyConfiguration->setBiddingStrategyType(
            BiddingStrategyType::MANUAL_CPC
        );
        $campaign->setBiddingStrategyConfiguration($biddingStrategyConfiguration);

        // Only the budgetId should be sent, all other fields will be ignored by
        // CampaignService.
        $campaignBudget = new Budget();
        $campaignBudget->setBudgetId($budget->getBudgetId());
        $campaign->setBudget($campaignBudget);

        // Required: Set the campaign's Dynamic Search Ads settings.
        $dynamicSearchAdsSetting = new DynamicSearchAdsSetting();
        // Required: Set the domain name and language.
        $dynamicSearchAdsSetting->setDomainName('example.com');
        $dynamicSearchAdsSetting->setLanguageCode('en');

        // Set the campaign settings.
        $campaign->setSettings([$dynamicSearchAdsSetting]);

        // Optional: Set the start date.
        $campaign->setStartDate(date('Ymd', strtotime('+1 day')));
        // Optional: Set the end date.
        $campaign->setEndDate(date('Ymd', strtotime('+1 year')));

        // Create a campaign operation.
        $operation = new CampaignOperation();
        $operation->setOperand($campaign);
        $operation->setOperator(Operator::ADD);

        // Create the campaign on the server and print out some information.
        $result = $campaignService->mutate([$operation]);
        $campaign = $result->getValue()[0];
        printf(
            "Campaign with name '%s' and ID %d was added.\n",
            $campaign->getName(),
            $campaign->getId()
        );

        return $campaign;
    }
620197
public static function getCampaignParameters()
    {
        $return = array(
            Config::getInstance()->Tracker['campaign_var_name'],
            Config::getInstance()->Tracker['campaign_keyword_var_name'],
        );

        foreach ($return as &$list) {
            if (strpos($list, ',') !== false) {
                $list = explode(',', $list);
            } else {
                $list = array($list);
            }
            $list = array_map('trim', $list);
        }

        return $return;
    }
1189212
public function getSmsCampaignCost(array $params, array $additionalParams = null)
    {
        if (!isset($params['addressBookId']) && !isset($params['phones'])) {
            return $this->handleError('You mast pass phones list or addressbook ID');
        }

        if ($additionalParams) {
            $params = array_merge($params, $additionalParams);
        }

        $requestResult = $this->sendRequest('/sms/campaigns/cost', 'GET', $params);

        return $this->handleResult($requestResult);
    }
450611
private function decorateArrayValue(array $params) : string
    {
        $params_out = [];
        foreach($params as $key => $param) {
            if (is_string($key)){
                $params_out[] = "'$key' =>" . $this->decorateValue($param);
            }
            else{
                $params_out[] = $this->decorateValue($param);
            }
        }
        return '[' . implode(',',$params_out) . ']';
    }
1099282
protected function checkCampaignPeriod(Node $campaign) {
    /** @var \Drupal\node\Entity\Node $campaign Campaign node. */
    $campaignStartDate = new \DateTime($campaign->get('field_campaign_start_date')->getString());
    $campaignEndDate = new \DateTime($campaign->get('field_campaign_end_date')->getString());
    $currentDate = new \DateTime();

    return $currentDate >= $campaignStartDate && $currentDate <= $campaignEndDate;
  }
26906
public function updateCampaign($CampaignId, Campaign $campaign) {
        $response = $this->mailjet->put(Resources::$Campaign, ['id' => $CampaignId, 'body' => $campaign->format()]);
        if (!$response->success()) {
            $this->throwError("CampaignManager:updateCampaign() failed", $response);
        }

        return $response->getData();
    }
700126
protected function paramsToUrl($params) {
        if (!$params) return '';

        $urlp = array();
        foreach ($params as $p => $val) {
            array_push($urlp, urlencode($p) . '=' . urlencode($this->formatQueryParameterValue($val)));
        }
        $result = '?' . implode ('&' , $urlp);
        return $result;
    }
207664
public function parseParam(array $bindParams = []): string
    {
        $argPos = \strpos($this->path, '{');
        $optPos = \strpos($this->path, '[');

        return $this->quickParseParams($argPos, $optPos, $bindParams);
    }
1334952
public function reportCampaignList($start_date, $end_date, $show_hidden)
		{
			$form_data = array(
				'from_date' => $start_date,
				'to_date' => $end_date,
				'show_hidden' => $show_hidden
			);
			$xml = $this->call('rpt_campaign_list', $form_data);

			$campaigns = array();

			foreach ($xml->Data as $campaign_item) {
				$campaign = new Report();
				$campaign
					->setCampaignId((int)$campaign_item->campaign_id)
					->setListId((int)$campaign_item->list_id)
					->setListName((string)$campaign_item->list_name)
					->setSubject((string)$campaign_item->subject)
					->setDate(\DateTime::createFromFormat('Y/m/d H:i:s', $campaign_item->deploy_date)) //2016-02-01 11:16:33
					->setRecipients((int)$campaign_item->pieces_sent)
					->setTaskId((int)$campaign_item->task_id);

				$campaigns[] = $campaign;
			}
			return $campaigns;
		}
71883
protected function encodeQueryParams(array $params)
  {
    $encoded = [];
    foreach ($params as $key => $value)
    {
      if (is_array($value))                 $encoded[$key] = $this->encodeQueryParams($value);
      else if (is_bool($value))             $encoded[$key] = $value ? 'true' : 'false';
      else if ($value instanceof \DateTime) $encoded[$key] = $value->format(\DateTime::ISO8601);
      else                                  $encoded[$key] = $value;
    }

    return $encoded;
  }