Get the current Campaign Limits (for real-time updates).

@param Request $request

@return \Symfony\Component\HttpFoundation\Response

@throws \Exception
@throws \MauticPlugin\MauticContactSourceBundle\Exception\ContactSourceException
979774
public function getCampaignLimitsAction(Request $request)
    {
        $contactSourceId = $request->request->get('contactSourceId');

        /** @var \MauticPlugin\MauticContactSourceBundle\Model\ContactSourceModel $contactSourceModel */
        $contactSourceModel = $this->get('mautic.contactsource.model.contactsource');
        if (!$contactSourceId || !$contactSource = $contactSourceModel->getEntity($contactSourceId)) {
            throw new \InvalidArgumentException('Contact Source argument is Invalid.');
        }

        $limits = $contactSourceModel->evaluateAllCampaignLimits($contactSource);

        return $this->sendJsonResponse(
            [
                'array' => $limits,
            ]
        );
    }
898450
public function listPlatformRolesGrantableAction(Request $request)
    {
        return new JsonResponse(
            $this->finder->search('Claroline\CoreBundle\Entity\Role', array_merge(
                $request->query->all(),
                ['hiddenFilters' => ['type' => 1, 'grantable' => true]]
            ))
        );
    }
461132
public function fetchAction(Request $request)
    {
        $reference = strtoupper($request->query->get('reference', null));
        $remote = (bool)$request->query->get('remote', 1);

        if (0 < strlen($reference) && $remote) {
            $remoteEndPoints = $this->container->getParameter('ekyna_setting.helper_remotes');
            foreach ($remoteEndPoints as $remoteEndPoint) {
                // remote=0 prevent infinite loop/recursion
                $url = $remoteEndPoint . '?reference=' . $reference . '&remote=0';
                $headers = $request->headers->all();
                if (null !== $response = $this->getRemoteResponse($url, $headers)) {
                    return $response;
                }
            }
        }

        $ttl = 7 * 24 * 3600;
        $response = new Response();
        $response
            ->setPublic()
            ->headers->add(['Content-Type' => 'application/xml; charset=utf-8'])
        ;

        if (0 < strlen($reference)) {
            $repository = $this->getDoctrine()->getRepository('EkynaSettingBundle:Helper');
            if (null !== $helper = $repository->findOneBy(['reference' => $reference])) {
                $response->setLastModified($helper->getUpdatedAt());
                if ($response->isNotModified($request)) {
                    return $response;
                }
                $response->setContent($this->renderView('EkynaSettingBundle:Helper:show.xml.twig', [
                    'helper' => $helper,
                ]));
                return $this->configureSharedCache($response, [$helper->getEntityTag()], $ttl);
            }
        }

        $expires = new \DateTime();
        $expires->modify('+7 days');
        return $response
            ->setMaxAge($ttl)
            ->setExpires($expires)
            ->setContent($this->renderView('EkynaSettingBundle:Helper:show.xml.twig'))
        ;
    }
1015061
public function cgetAction(Request $request)
    {
        $view = null;
        if ('true' == $request->get('flat')) {
            /** @var RestHelperInterface $restHelper */
            $restHelper = $this->get('sulu_core.doctrine_rest_helper');

            /** @var DoctrineListBuilderFactory $factory */
            $factory = $this->get('sulu_core.doctrine_list_builder_factory');

            $listBuilder = $factory->create($this->container->getParameter('sulu.model.user.class'));

            $restHelper->initializeListBuilder($listBuilder, $this->getFieldDescriptors());

            $list = new ListRepresentation(
                $listBuilder->execute(),
                static::$entityKey,
                'get_users',
                $request->query->all(),
                $listBuilder->getCurrentPage(),
                $listBuilder->getLimit(),
                $listBuilder->count()
            );
        } else {
            $contactId = $request->get('contactId');

            if (null != $contactId) {
                $user = $this->getDoctrine()->getRepository(
                    $this->container->getParameter('sulu.model.user.class')
                )->findUserByContact($contactId);

                $view = $this->view($user ?? new \stdClass(), 200);
            } else {
                $entities = $this->getUserManager()->findAll();
                $list = new CollectionRepresentation($entities, static::$entityKey);
            }
        }

        if (!$view) {
            $view = $this->view($list, 200);
        }

        $this->addSerializationGroups($view);

        return $this->handleView($view);
    }
91422
public function multipledeleteinfoAction(Request $request)
    {
        $ids = $request->get('ids');

        $response = [];
        $numContacts = 0;
        $numChildren = 0;

        foreach ($ids as $id) {
            $account = $this->getRepository()->countDistinctAccountChildrenAndContacts($id);

            // Get number of subaccounts.
            $numChildren += $account['numChildren'];

            // FIXME: Distinct contacts: (currently the same contacts could be counted multiple times).
            // Get full number of contacts.
            $numContacts += $account['numContacts'];
        }

        $response['numContacts'] = $numContacts;
        $response['numChildren'] = $numChildren;

        $view = $this->view($response, 200);

        return $this->handleView($view);
    }
168218
public function limitControlAction(Request $request, $total = '')
    {
        /* @var $controls ListControls */
        $controls = $this->get('anime_db.item.list_controls');

        if (!is_numeric($total) || $total < 0) {
            /* @var $rep ItemRepository */
            $rep = $this->getDoctrine()->getRepository('AnimeDbCatalogBundle:Item');
            $total = $rep->count();
        }

        return $this->render('AnimeDbCatalogBundle:Item:list_controls/limit.html.twig', [
            'limits' => $controls->getLimits($request->query->all()),
            'total' => $total,
        ]);
    }
1230614
public function listAction(Request $request)
    {
        $limit = $request->get('limit', 25);
        $start = $request->get('start', 0);
        $sort = $request->get('sort', 'createdAt');
        $dir = $request->get('dir', 'DESC');
        $filter = $request->get('filter', null);

        if ($filter) {
            $filter = json_decode($filter, true);
        }

        if (!is_array($filter)) {
            $filter = [];
        }

        $messageManager = $this->get('phlexible_message.message_manager');

        $priorityList = $messageManager->getPriorityNames();
        $typeList = $messageManager->getTypeNames();

        $priorityFilter = [];
        $typeFilter = [];
        $channelFilter = [];
        $roleFilter = [];

        $criteria = new Criteria();
        foreach ($filter as $key => $value) {
            if ($key === 'subject' && !empty($value)) {
                $criteria->addRaw(Criteria::CRITERIUM_SUBJECT_LIKE, $value);
            } elseif ($key === 'text' && !empty($value)) {
                $criteria->addRaw(Criteria::CRITERIUM_BODY_LIKE, $value);
            } elseif (substr($key, 0, 9) === 'priority_') {
                $priorityFilter[] = substr($key, 9);
            } elseif (substr($key, 0, 5) === 'type_') {
                $typeFilter[] = substr($key, 5);
            } elseif (substr($key, 0, 8) === 'channel_') {
                $channelFilter[] = substr($key, 8);
            } elseif (substr($key, 0, 5) === 'role_') {
                $roleFilter[] = substr($key, 9);
            } elseif ($key === 'date_after' && !empty($value)) {
                $criteria->addRaw(Criteria::CRITERIUM_START_DATE, $value);
            } elseif ($key === 'date_before' && !empty($value)) {
                $criteria->addRaw(Criteria::CRITERIUM_END_DATE, $value);
            }
        }

        if (count($priorityFilter)) {
            $criteria->addRaw(
                Criteria::CRITERIUM_PRIORITY_IN,
                implode(',', $priorityFilter)
            );
        }

        if (count($typeFilter)) {
            $criteria->addRaw(
                Criteria::CRITERIUM_TYPE_IN,
                implode(',', $typeFilter)
            );
        }

        if (count($channelFilter)) {
            $criteria->addRaw(
                Criteria::CRITERIUM_CHANNEL_IN,
                implode(',', $channelFilter)
            );
        }

        if (count($roleFilter)) {
            $criteria->addRaw(
                Criteria::CRITERIUM_ROLE_IN,
                implode(',', $roleFilter)
            );
        }

        $count = $messageManager->countByCriteria($criteria);
        $messages = $messageManager->findByCriteria($criteria, [$sort => $dir], $limit, $start);

        $data = [];
        foreach ($messages as $message) {
            $data[] = [
                'subject' => $message->getSubject(),
                'body' => nl2br($message->getBody()),
                'priority' => $priorityList[$message->getPriority()],
                'type' => $typeList[$message->getType()],
                'channel' => $message->getChannel(),
                'role' => $message->getRole(),
                'user' => $message->getUser(),
                'createdAt' => $message->getCreatedAt()->format('Y-m-d H:i:s'),
            ];
        }

        return new JsonResponse([
            'totalCount' => $count,
            'messages' => $data,
            'facets' => $messageManager->getFacetsByCriteria($criteria),
        ]);
    }
1286040
protected function clientRevenueAction(Request $request)
    {
        $params    = $this->getDateParams();
        $cache_dir = $this->container->getParameter('kernel.cache_dir');

        // Get the API payload to test.
        //$params['limit'] = 1000; // just in case we want to set this, or use a config parameter
        $em      = $this->dispatcher->getContainer()->get('doctrine.orm.default_entity_manager');
        $repo    = $em->getRepository(\MauticPlugin\MauticContactLedgerBundle\Entity\CampaignClientStats::class);
        $groupBy = $request->request->get('groupby', 'Client Name');

        $data       = $repo->getDashboardClientWidgetData($params, $cache_dir, $groupBy);

        $headers    = [
            'mautic.contactledger.dashboard.client-revenue.header.active',
            'mautic.contactledger.dashboard.client-revenue.header.id',
            'mautic.contactledger.dashboard.client-revenue.header.name',
        ];
        if ('Client Category' == $groupBy) {
            $headers[] = 'mautic.contactledger.dashboard.client-revenue.header.category';
        } else { // groupBy = Source Name
            $headers[] = 'mautic.contactledger.dashboard.client-revenue.header.clientid';
            $headers[] = 'mautic.contactledger.dashboard.client-revenue.header.clientname';
            $headers[] = 'mautic.contactledger.dashboard.client-revenue.header.utmsource';
        }

        $headers = array_merge($headers, [
            'mautic.contactledger.dashboard.client-revenue.header.received',
            'mautic.contactledger.dashboard.client-revenue.header.declined',
            'mautic.contactledger.dashboard.client-revenue.header.converted',
            'mautic.contactledger.dashboard.client-revenue.header.revenue',
            // hide the nexxt 3 columns until cost is processed correctly
            // 'mautic.contactledger.dashboard.client-revenue.header.cost',
            // 'mautic.contactledger.dashboard.client-revenue.header.gm',
            // 'mautic.contactledger.dashboard.client-revenue.header.margin',
            'mautic.contactledger.dashboard.client-revenue.header.ecpm',
            'mautic.contactledger.dashboard.client-revenue.header.rpu',
        ]);
        foreach ($headers as $header) {
            $data['columns'][] = [
                'title' => $this->translator->trans($header),
            ];
        }
        $data = UTF8Helper::fixUTF8($data);

        return $this->sendJsonResponse($data);
    }
342103
public function indexAction(Request $request)
    {
        $manager = $this->get('compo_faq.manager.faq');

        $page = $request->get('page', 1);

        $pager = $manager->getPager([], $page);
        $totalPages = $pager->getPageCount();

        $seoPage = $this->get('sonata.seo.page');
        $seoPage->setContext('faq_list');
        $seoPage->addVar('page', $page);
        $seoPage->addVar('total_pages', $pager->getPageCount());

        if (1 !== $page) {
            $seoPage->setLinkCanonical($manager->getFaqIndexPermalink(['page' => $page], 0));
            $metas = $seoPage->getMetas();
            $metas['name']['robots'] = 'noindex, follow';
            $seoPage->setMetas($metas);
        } else {
            $seoPage->setLinkCanonical($manager->getFaqIndexPermalink([], 0));
        }

        if ($totalPages > 1 && $page < $totalPages) {
            $seoPage->setLinkNext($manager->getFaqIndexPermalink(['page' => $page + 1], 0));
        }

        if ($totalPages > 1 && $page > 1) {
            $seoPage->setLinkPrev($manager->getFaqIndexPermalink(['page' => $page - 1], 0));
        }

        $seoPage->build();

        return $this->render(
            'CompoFaqBundle:Faq:index.html.twig',
            [
                'pager' => $pager,
            ]
        );
    }
445335
public function cgetAction(Request $request)
    {
        $locale = $this->getProductLocaleManager()->retrieveLocale($this->getUser(), $request->get('locale'));
        $queryString = $request->get('query');

        if ($request->get('flat') == 'true') {
            $list = $this->getListRepresentation($request);
        } else {
            $list = new CollectionRepresentation(
                $this->getManager()->findAllByLocaleAndQueryString($locale, $queryString),
                self::$entityKey
            );
        }

        $view = $this->view($list, 200);

        return $this->handleView($view);
    }
1083706
public function confirmUtmSourceAction($request)
    {
        $utmSource          = $request->request->get('utmSource');
        $contactSourceModel = $this->get('mautic.contactsource.model.contactsource');
        $utmSourceExists    = $contactSourceModel->getRepository()->findBy(['utmSource' => $utmSource]);

        return $this->sendJsonResponse(!empty($utmSourceExists) ? true : false);
    }
603765
public function retrieveCurrent(Request $request)
    {
        if (ConfigQuery::isRewritingEnable()) {
            $view = $request->attributes->get('_view', null);

            $viewLocale = $this->getViewLocale($request);

            $viewId = $view === null ? null : $request->query->get($view . '_id', null);

            $allOtherParameters = $request->query->all();
            if ($view !== null) {
                unset($allOtherParameters['view']);
                if ($viewId !== null) {
                    unset($allOtherParameters[$view . '_id']);
                }
            }
            if ($viewLocale !== null) {
                unset($allOtherParameters['lang']);
                unset($allOtherParameters['locale']);
            }

            $this->retriever->loadSpecificUrl($view, $viewLocale, $viewId, $allOtherParameters);
        } else {
            $allParametersWithoutView = $request->query->all();
            $view = $request->attributes->get('_view');
            if (isset($allOtherParameters['view'])) {
                unset($allOtherParameters['view']);
            }
            $this->retriever->rewrittenUrl = null;
            $this->retriever->url = URL::getInstance()->viewUrl($view, $allParametersWithoutView);
        }

        return $this->retriever;
    }
1136992
private function getRequestedPage(Request $request)
    {
        $pageNumber = $request->query->getInt('page', 1);
        if (!$pageNumber || $pageNumber < 1) {
            $pageNumber = 1;
        }

        return $pageNumber;
    }
131294
public function searchAction(Request $request)
    {
        $searchAction = $this->container->get(SearchAction::class);

        return $searchAction($request);
    }
277125
public function limit($request) {
        $limit = (int)$request->getVar('limit');
        if($limit && is_int($limit) && $limit > 0) {
            return $limit;
        } else {
            return static::$default_limit;
        }
    }
249175
public function ajaxTimelineAction(Request $request)
    {
        $dataArray = [
            'html'    => '',
            'success' => 0,
        ];
        $filters   = [];
        /** @var \MauticPlugin\MauticContactSourceBundle\Model\ContactSourceModel $contactSourceModel */
        $contactSourceModel = $this->get('mautic.contactsource.model.contactsource');

        // filters means the transaction table had a column sort, filter submission or pagination, otherwise its a fresh page load
        if ($request->request->has('filters')) {
            foreach ($request->request->get('filters') as $filter) {
                if (in_array($filter['name'], ['dateTo', 'dateFrom']) && !empty($filter['value'])) {
                    $filter['value']        = new \DateTime($filter['value']);
                    list($hour, $min, $sec) = 'dateTo' == $filter['name'] ? [23, 59, 59] : [00, 00, 00];
                    $filter['value']->setTime($hour, $min, $sec);
                }
                if (!empty($filter['value'])) {
                    $filters[$filter['name']] = $filter['value'];
                }
            }
        }
        $page     = isset($filters['page']) && !empty($filters['page']) ? $filters['page'] : 1;
        $objectId = InputHelper::clean($request->request->get('objectId'));
        if (empty($objectId)) {
            return $this->sendJsonResponse($dataArray);
        }

        $contactSource = $contactSourceModel->getEntity($objectId);

        $order = [
            'date_added',
            'DESC',
        ];
        if (isset($filters['orderby']) && !empty($filters['orderby'])) {
            $order[0] = $filters['orderby'];
        }
        if (isset($filters['orderbydir']) && !empty($filters['orderbydir'])) {
            $order[1] = $filters['orderbydir'];
        }
        $transactions         = $contactSourceModel->getEngagements($contactSource, $filters, $order, $page);
        $dataArray['html']    = $this->renderView(
            'MauticContactSourceBundle:Timeline:list.html.php',
            [
                'page'                => $page,
                'contactSource'       => $contactSource,
                'transactions'        => $transactions,
                'order'               => $order,
            ]
        );
        $dataArray['success'] = 1;
        $dataArray['total']   = $transactions['total'];

        return $this->sendJsonResponse($dataArray);
    }
531066
public function evaluateAllCampaignLimits(ContactSource $contactSource)
    {
        $container = $this->dispatcher->getContainer();
        /** @var CampaignSettings $campaignSettingsModel */
        $campaignModel         = $container->get('mautic.campaign.model.campaign');
        $campaignSettingsModel = $container->get('mautic.contactsource.model.campaign_settings');
        $campaignSettingsModel->setContactSource($contactSource);
        $campaignSettingsAll = $campaignSettingsModel->getCampaignSettings();

        $campaignLimits = [];
        if (!empty($campaignSettingsAll->campaigns)) {
            /* @var \MauticPlugin\MauticContactSourceBundle\Model\Cache $cacheModel */
            $cacheModel = $container->get('mautic.contactsource.model.cache');
            $cacheModel->setContactSource($contactSource);

            foreach ($campaignSettingsAll->campaigns as $campaign) {
                // Establish parameters from campaign settings.
                if (!empty($campaign->limits) && isset($campaign->campaignId)) {
                    $id                = intval($campaign->campaignId);
                    $name              = $campaignModel->getEntity($id)->getName();
                    $limitRules        = new \stdClass();
                    $limitRules->rules = $campaign->limits;
                    $limits            = $cacheModel->evaluateLimits($limitRules, $id, false, true);
                    if ($limits) {
                        $campaignLimits[] = [
                            'campaignId' => $id,
                            'limits'     => $limits,
                            'name'       => $name,
                            'link'       => $this->buildUrl(
                                'mautic_campaign_action',
                                ['objectAction' => 'view', 'objectId' => $id]
                            ),
                        ];
                    }
                }
            }
        }

        return $campaignLimits;
    }