Retrieve a list of campaigns for use in drop-downs.

@return \Symfony\Component\HttpFoundation\JsonResponse

@throws \Exception
192964
protected function getCampaignListAction()
    {
        $output = [];
        /** @var CampaignRepository */
        $campaignRepository = $this->get('mautic.campaign.model.campaign')->getRepository();
        $campaigns          = $campaignRepository->getEntities();
        foreach ($campaigns as $campaign) {
            $id                                  = $campaign->getId();
            $published                           = $campaign->isPublished();
            $name                                = $campaign->getName();
            $category                            = $campaign->getCategory();
            $category                            = $category ? $category->getName() : '';
            $output[$name.'_'.$category.'_'.$id] = [
                'category'  => $category,
                'published' => $published,
                'name'      => $name,
                'title'     => htmlspecialchars_decode($name.($category ? '  ('.$category.')' : '').(!$published ? '  (unpublished)' : '')),
                'value'     => $id,
            ];
        }
        $output['   '] = [
            'value' => 0,
            'title' => count($output) ? '-- Select a Campaign --' : '-- Please create a Campaign --',
        ];
        // Sort by name and category if not already, then drop the keys.
        ksort($output);

        return $this->sendJsonResponse(
            [
                'array' => array_values($output),
            ]
        );
    }
433476
public function listForSelect()
    {
        $object = Country::orderBy('name', 'asc')
            ->get(['id', 'name']);

        return $this->response->collection($object, CountryForSelectResource::class);
    }
494557
public function getThemes()
    {
        $json = $this->container->json;

        if (null === $definition = $json->getJson(ROOT_DIR . 'structure/definitions/themes.json', 'themes')) {
            throw new Exception('PitonCMS: Get themes exception: ' . implode($json->getErrorMessages(), ','));
        }

        return array_column($definition->themes, 'name', 'value');
    }
1186867
public function listAction()
    {
        $metaSetManager = $this->get('phlexible_meta_set.meta_set_manager');
        $metaSet = $metaSetManager->findAll();

        $data = [];
        foreach ($metaSet as $set) {
            /* @var $set MetaSetInterface */

            $data[] = [
                'id' => $set->getId(),
                'name' => $set->getName(),
                'createdAt' => $set->getCreatedAt() ? $set->getCreatedAt()->format('Y-m-d H:i:s') : null,
                'createUser' => $set->getCreateUser(),
                'modifiedAt' => $set->getModifiedAt() ? $set->getModifiedAt()->format('Y-m-d H:i:s') : null,
                'modifyUser' => $set->getModifyUser(),
                'revision' => $set->getRevision(),
            ];
        }

        return new JsonResponse(['sets' => $data]);
    }
592161
public function filtervaluesAction()
    {
        $groupManager = $this->get('phlexible_user.group_manager');

        $allGroups = $groupManager->findAll();
        $everyoneGroupId = $groupManager->getEveryoneGroupId();

        $groups = [];
        foreach ($allGroups as $group) {
            if ($group->getId() === $everyoneGroupId) {
                continue;
            }

            $groups[] = [
                'id' => $group->getId(),
                'title' => $group->getName(),
            ];
        }

        $roles = [];
        foreach ($this->container->getParameter('security.role_hierarchy.roles') as $role => $subRoles) {
            if (!$this->isGranted($role)) {
                continue;
            }

            $roles[] = ['id' => $role, 'title' => ucfirst(str_replace('_', ' ', $role))];
        }

        $data = [
            'groups' => $groups,
            'roles' => $roles,
        ];

        return new JsonResponse($data);
    }
1113966
public function index()
    {
        // $options = $this->getParams('offset', 'limit', 'includes', 'order_by');

        $categories = Subbly::api('subbly.category')->all();

        return $this->jsonResponse(array(
            'categories' => $this->presenter->collection($categories),
        ));
        // return $this->jsonCollectionResponse(array(
        //     'categories' => $this->presenter->collection($categories)
        // ));
    }
1074952
public function getNewBundles()
    {
        $bundles = $this->bundleLocatorService->getAvailableBundles();
        $newBundles = [];

        foreach ($bundles as $bundle) {
            // Check whether this bundle has already been installed
            switch ($this->isRegisteredBundle($bundle)) {
                case Installer::STATUS_REGISTERED_NO:
                    $bundle->setStatus(Installer::STATUS_REGISTERED_NO);
                    $newBundles[] = $bundle;
                    break;

                case Installer::STATUS_REGISTERED_OLDER:
                    // Get the existing bundle.
                    /** @var Bundle $registeredBundle */
                    $registeredBundle = $this->em
                        ->getRepository('CampaignChainCoreBundle:Bundle')
                        ->findOneByName($bundle->getName());
                    // Update the existing bundle's data.
                    $registeredBundle->setType($bundle->getType());
                    $registeredBundle->setDescription($bundle->getDescription());
                    $registeredBundle->setLicense($bundle->getLicense());
                    $registeredBundle->setAuthors($bundle->getAuthors());
                    $registeredBundle->setHomepage($bundle->getHomepage());
                    $registeredBundle->setVersion($bundle->getVersion());
                    $registeredBundle->setExtra($bundle->getExtra());

                    $registeredBundle->setStatus(Installer::STATUS_REGISTERED_OLDER);
                    $newBundles[] = $registeredBundle;
                    break;

                case Installer::STATUS_REGISTERED_SAME:
                    $bundle->setStatus(Installer::STATUS_REGISTERED_SAME);
                    break;
            }
        }

        return $newBundles;
    }
329916
public function listAction()
    {
        /** @var FeatureTypeService $featureService */
        $featureService = $this->container->get("features");
        $featureTypes   = $featureService->getFeatureTypeDeclarations();

        return new JsonResponse(array(
            'list' => $featureTypes,
        ));
    }
168620
public function getRegion()
    {
        $resource = 'campaigns/' . $this->campaignId . '/region.json';

        $response = $this->sendRequest('GET', $this->getServiceUrl($resource));

        $decodedResponseBody = $this->getDecodedBody($response->getBody());
        $getRegionResponse = new Models\GetRegionResponse($decodedResponseBody);
        return $getRegionResponse->getRegion();
    }
1363926
public static function getDropDownList()
    {
        $categories = static::find()->select(['id', 'name'])->where(['parent' => null])->with('categories')->orderBy(['sort' => SORT_ASC])->asArray()->all();
        foreach ($categories as $id => $category) {
            if (!empty($category['categories'])) {
                $categories[$id]['id'] = $category['name'];
                $categories[$id]['name'] = ArrayHelper::map($category['categories'], 'id', 'name');
            }
        }
        return $categories;
    }
678488
public function getAdAccounts()
    {
        //Authentication
        $data = array(
            'username' => AD_BULK_IMPORT_USER,
            'password' => AD_BULK_IMPORT_PASSWORD
        );

        //Fetch index
        $index = $this->curl->request('POST', rtrim(AD_INTEGRATION_URL, "/") . '/user/index', $data, 'json',
            array('Content-Type: application/json'));

        //Validate json response
        if ($this->response::isJsonError($index) || !json_decode($index)) {
            return false;
        }

        //Check that no errors occured
        if (json_last_error() != JSON_ERROR_NONE) {
            error_log("Ad integration: Could not read index due to the fact that the response wasen't a valid json string.");
            exit;
        }

        //Return
        return array_map('strtolower', json_decode($index));
    }
545937
public function getSettings()
    {
        $resource = 'campaigns/' . $this->campaignId . '/settings.json';
       
        $response = $this->sendRequest('GET', $this->getServiceUrl($resource));

        $decodedResponseBody = $this->getDecodedBody($response->getBody());
       
        $getSettingsResponse = new Models\GetSettingsResponse($decodedResponseBody);
        return $getSettingsResponse->getSettings();
    }
1269889
public function getJsonItemSchemas()
	{
		$list = array();

		foreach( $this->_getControllers() as $name => $controller ) {
			$list[$name] = $controller->getItemSchema();
		}

		if( ( $json = json_encode( $list ) ) === null ) {
			throw new Exception( 'Unable to encode schemas to JSON' );
		}

		return $json;
	}
209764
public function getBalance()
    {
        $resource = 'campaigns/' . $this->campaignId . '/balance.json';

        $response = $this->sendRequest('GET', $this->getServiceUrl($resource));

        $decodedResponseBody = $this->getDecodedBody($response->getBody());

        $getBalanceResponse = new Models\GetBalanceResponse($decodedResponseBody);
        return $getBalanceResponse->getBalance();
    }
49523
public function indexAction()
    {
        $templates = $this->get('doctrine.orm.entity_manager')->getRepository('VictoireTemplateBundle:Template')->findByTemplate(null, ['position' => 'ASC']);

        return new JsonResponse(
            [
                'success' => true,
                'html'    => $this->container->get('templating')->render(
                    'VictoireTemplateBundle:Template:index.html.twig',
                    ['templates' => $templates]
                ),
            ]
        );
    }
652052
private function getCampaign()
    {
        if (!$this->campaign && $this->event) {
            // Sometimes we have a campaignId as an integer ID.
            if (!empty($this->event['campaignId']) && is_integer($this->event['campaignId'])) {
                /** @var CampaignModel $campaignModel */
                $campaignModel  = $this->getContainer()->get('mautic.campaign.model.campaign');
                $this->campaign = $campaignModel->getEntity($this->event['campaignId']);
            }
            // Sometimes we have a campaignId as a hash.
            if (!$this->campaign) {
                try {
                    $identityMap = $this->em->getUnitOfWork()->getIdentityMap();
                    if (isset($identityMap['Mautic\CampaignBundle\Entity\Campaign']) && !empty($identityMap['Mautic\CampaignBundle\Entity\Campaign'])) {
                        $this->campaign = end($identityMap['Mautic\CampaignBundle\Entity\Campaign']);
                    }
                } catch (\Exception $e) {
                }
            }
            if ($this->campaign) {
                $this->addTrace('campaign', $this->campaign->getName());
                $this->addTrace('campaignId', $this->campaign->getId());
            }
        }

        return $this->campaign;
    }
226483
public function selectAction()
    {
        $selectFieldProviders = $this->get('phlexible_elementtype.select_field_providers');

        $data = [];
        foreach ($selectFieldProviders->all() as $selectFieldProvider) {
            $data[] = [
                'name' => $selectFieldProvider->getName(),
                'title' => $selectFieldProvider->getTitle($this->getUser()->getInterfaceLanguage('en')),
            ];
        }

        return new JsonResponse(['functions' => $data]);
    }