tweaked for fullcalendar.


@param Request $request
@param string  $class

@return JsonResponse
775959
public function listAction(Request $request, $class)
    {
        $query = $request->query->all();
        $hiddenFilters = isset($query['hiddenFilters']) ? $query['hiddenFilters'] : [];
        $query['hiddenFilters'] = array_merge($hiddenFilters, $this->getDefaultHiddenFilters());

        //get start & end date and add them to the hidden filters list
        $query['hiddenFilters']['createdAfter'] = $query['start'];

        //we want to be able to fetch events that start a months before and ends a month after
        $date = new \DateTime($query['end']);
        $interval = new \DateInterval('P2M');
        $date->add($interval);
        $end = $date->format('Y-m-d');

        $query['hiddenFilters']['endBefore'] = $end;

        $data = $this->finder->search(
            $class,
            $query,
            $this->options['list']
        );

        return new JsonResponse($data['data']);
    }
201575
private function handleJson($data, $class)
    {
        $data   = json_decode($data);
        $output = $this->fromStdObject($data, $class);

        return $output;
    }
734296
public function changeAction(Request $request)
    {
        $regionManager = $this->get('compo_region.manager.region');

        $currentRegion = $request->request->get('current_region', $regionManager->getCurrentRegion());

        $regionManager->setCurrentRegion($currentRegion);

        return new JsonResponse($currentRegion);
    }
728866
public function postAction($type, Request $request)
    {
        $classname = AbstractClassContent::getClassnameByContentType($type);
        $content = new $classname();
        $this->granted('CREATE', $content);

        $this->getEntityManager()->persist($content);
        $content->setDraft($this->getClassContentManager()->getDraft($content, true));

        $this->getEntityManager()->flush();

        $data = $request->request->all();
        if (0 < count($data)) {
            $data = array_merge($data, [
                'type' => $type,
                'uid'  => $content->getUid(),
            ]);

            $this->updateClassContent($type, $data['uid'], $data);
            $this->getEntityManager()->flush();
        }

        return $this->createJsonResponse(null, 201, [
            'BB-RESOURCE-UID' => $content->getUid(),
            'Location'        => $this->getApplication()->getRouting()->getUrlByRouteName(
                'bb.rest.classcontent.get',
                [
                    'version' => $request->attributes->get('version'),
                    'type'    => $type,
                    'uid'     => $content->getUid(),
                ],
                '',
                false
            ),
        ]);
    }
663933
public function copyBulkAction(Request $request, $class)
    {
        //add params for the copy here
        $isModel = 1 === (int) $request->query->get('model') || 'true' === $request->query->get('model') ? true : false;

        $serializer = $this->serializer;
        $copies = [];

        foreach ($this->decodeIdsString($request, $class) as $workspace) {
            $new = new Workspace();
            $new->setCode($workspace->getCode().uniqid());
            $copies[] = $this->workspaceManager->copy($workspace, $new, $isModel);
        }

        return new JsonResponse(array_map(function ($copy) use ($serializer) {
            return $serializer->serialize($copy, $this->options['get']);
        }, $copies), 200);
    }
729920
public function getResponseObject(string $class, string $json)
    {
        $object = $this->deserialize($class, $json);
        $this->assertValid($object, ValidationException::RESPONSE);

        return $object;
    }
1357854
public function show(Request $request, $key)
    {
        $model = $this->findFirstByKey($key);

        if (!$model) {
            return $this->validNotFoundJsonResponse();
        }

        return response()->json($model, 200, [], JSON_PRETTY_PRINT);
    }
874128
protected function doRequest(Request $request)
    {

        $this->client->send($request, $response = new Response());

        return $response;
    }
1313525
public function removeGroupsAction($id, $class, Request $request)
    {
        $object = $this->find($class, $id);
        $groups = $this->decodeIdsString($request, 'Claroline\CoreBundle\Entity\Group');
        $this->crud->patch($object, 'group', Crud::COLLECTION_REMOVE, $groups);

        return new JsonResponse($this->serializer->serialize($object));
    }
1152072
public function createAction(Request $request, $class)
    {
        $data = $this->decodeRequest($request);

        //THIS IS FOR WORKSPACE IMPORT FROM ARCHIVE. IT'S CURRENTLY NOT TESTED (AND THEREFORE BROKEN)
        if (isset($data['archive'])) {
            $workspace = $this->importer->create($data, new Workspace());
            $this->toolManager->addMissingWorkspaceTools($workspace);

            return new JsonResponse(
                $this->serializer->serialize($workspace, $this->options['get']),
                201
            );
        }

        /** @var Workspace $workspace */
        $workspace = $this->crud->create(
            $class,
            $data,
            [Options::LIGHT_COPY]
        );

        if (is_array($workspace)) {
            return new JsonResponse($workspace, 400);
        }

        $model = $workspace->getWorkspaceModel();
        $logFile = $this->getLogFile($workspace);
        $logger = new JsonLogger($logFile);
        $this->workspaceManager->setLogger($logger);
        $workspace = $this->workspaceManager->copy($model, $workspace, false);
        $logger->end();

        return new JsonResponse(
            $this->serializer->serialize($workspace, $this->options['get']),
            201
        );
    }
681083
public function usersAction(Request $request)
    {
        $query = $request->get('query');
        $limit = $request->get('limit', 20);
        $offset = $request->get('start', 0);

        $userProvider = $this->get('phlexible_access_control.user_security_provider');

        $data = $userProvider->getAll($query, $limit, $offset);

        return new JsonResponse($data);
    }
907356
public function requestAction(Request $request)
    {
        $widget = $request->isXmlHttpRequest();

        $form = $this->getPasswordResetTokenFormFactory()->createRequestForm()->handleRequest($request);

        if (!$form->isSubmitted()) {
            return new Response($this->getPasswordResetTokenFormRenderer()->renderRequestForm($widget, $form));
        }

        $successMessage = 'password_reset_token.action.request.success';

        $passwordResetToken = $this->getPasswordResetTokenFormHandler()->handleRequestForm($form, !$widget, $successMessage);

        if (empty($passwordResetToken)) {
            $html = $this->getPasswordResetTokenFormRenderer()->renderRequestForm($widget, $form);

            return $widget
                ? new AjaxResponse($html, false, FlashNotifierInterface::MESSAGE_FORM_ERROR)
                : new Response($html);
        }
        if ($widget) {
            $webmailLink   = null;
            $webmailLinker = $this->getWebmailLinker();

            if (!empty($webmailLinker)) {
                $webmailLink = $webmailLinker->getProviderByEmailAddress($passwordResetToken->getUser()->getEmail());
            }

            return new AjaxResponse(
                $this->renderView('DarvinUserBundle:PasswordResetToken/widget/request:submitted.html.twig', [
                    'password_reset_token' => $passwordResetToken,
                    'webmail_link'         => $webmailLink,
                ]),
                true,
                $successMessage
            );
        }

        return $this->redirectToRoute('darvin_user_security_login');
    }
1261279
public function listUsersAction($id, $class, Request $request)
    {
        return new JsonResponse(
            $this->finder->search('Claroline\CoreBundle\Entity\User', array_merge(
                $request->query->all(),
                ['hiddenFilters' => [$this->getName() => [$id]]]
            ))
        );
    }
1095575
public function indexAction(Request $request)
    {

        // For Mailchimp ping GET
        if ($request->isMethod('GET')) {
            return new JsonResponse([
                'success' => true,
                'ping' => 'pong',
            ]);
        }

        // Handle POST request of Mailchimp
        $type = $request->request->get('type');
        $data = $request->request->get('data');
        /* Response example:
            data[merges][FNAME]: Tztz
            data[merges][EMAIL]: tztz@gmail.com
            data[email_type]: html
            data[reason]: manual
            data[email]: tztz@gmail.com
            data[id]: 5c1b5a7c1e
            data[merges][LNAME]: TZST
            data[list_id]: ba039c6198
            data[web_id]: 3375995
        */
        $hooksecret = $request->query->get('hooksecret');

        if (empty($type) || empty($data) || empty($hooksecret) || !array_key_exists('list_id', $data)) {
            throw new AccessDeniedHttpException('incorrect data format!');
        }

        $listId = $data['list_id'];

        $listProviderKey = $this->getParameter('welp_mailchimp.list_provider');
        try {
            $listProvider = $this->get($listProviderKey); 
        } catch (ServiceNotFoundException $e) {
            throw new \InvalidArgumentException(sprintf('List Provider "%s" should be defined as a service.', $listProviderKey), $e->getCode(), $e);
        }

        if (!$listProvider instanceof ListProviderInterface) {
            throw new \InvalidArgumentException(sprintf('List Provider "%s" should implement Welp\MailchimpBundle\Provider\ListProviderInterface.', $listProviderKey));
        }

        $list = $listProvider->getList($listId);

        // Check the webhook_secret
        $authorized = false;
        if($list != null && $list->getWebhookSecret() == $hooksecret) {
            $authorized = true;                           
        }

        if (!$authorized) {
            throw new AccessDeniedHttpException('Webhook secret mismatch!');
        }

        // Trigger the right event
        switch ($type) {
            case 'subscribe':
                $dispatcher = $this->get('event_dispatcher');
                $dispatcher->dispatch(WebhookEvent::EVENT_SUBSCRIBE, new WebhookEvent($data));
                break;
            case 'unsubscribe':
                $dispatcher = $this->get('event_dispatcher');
                $dispatcher->dispatch(WebhookEvent::EVENT_UNSUBSCRIBE, new WebhookEvent($data));
                break;
            case 'profile':
                $dispatcher = $this->get('event_dispatcher');
                $dispatcher->dispatch(WebhookEvent::EVENT_PROFILE, new WebhookEvent($data));
                break;
            case 'cleaned':
                $dispatcher = $this->get('event_dispatcher');
                $dispatcher->dispatch(WebhookEvent::EVENT_CLEANED, new WebhookEvent($data));
                break;
            case 'upemail':
                $dispatcher = $this->get('event_dispatcher');
                $dispatcher->dispatch(WebhookEvent::EVENT_UPEMAIL, new WebhookEvent($data));
                break;
            case 'campaign':
                $dispatcher = $this->get('event_dispatcher');
                $dispatcher->dispatch(WebhookEvent::EVENT_CAMPAIGN, new WebhookEvent($data));
                break;
            default:
                throw new AccessDeniedHttpException('type mismatch!');
                break;
        }

        return new JsonResponse([
            'type' => $type,
            'data' => $data,
        ]);
    }
807117
public function make($class)
    {
        $action = $this->container->make($class);
        $action->setEvents($this->container->make('events'));

        return $action;
    }
157286
public function api(Request $request)
	{
		$reflectClassRequest = new \ReflectionClass($request);
		$className           = $reflectClassRequest->getShortName();
		$className           = str_replace('Request', 'Api', $className);
		$namespace           = str_replace('\Request', '\Api\\', $reflectClassRequest->getNamespaceName());
		/** @var UrlAnnotation $urlAnnotation */
		$urlAnnotation = Reader::read($request);
		$data          = $this->fetchData($request, $reflectClassRequest, $urlAnnotation);

		$reflectClassName = new \ReflectionClass($namespace . $className);
		$instance         = $reflectClassName->newInstanceArgs([$request, $data, $urlAnnotation]);
		return call_user_func([$instance, 'execute']);
	}
939922
public function indexAction(Request $request)
    {
        $dispatcher = $this->get('event_dispatcher');
        $event = new ResponseEvent($request);
        $dispatcher->dispatch(OpiferMediaEvents::MEDIA_CONTROLLER_INDEX, $event);

        if (null !== $event->getResponse()) {
            return $event->getResponse();
        }

        $media = $this->get('opifer.media.media_manager')->getPaginatedByRequest($request);

        $items = $this->get('jms_serializer')->serialize(iterator_to_array($media->getCurrentPageResults()), 'json', SerializationContext::create()->setGroups(['Default', 'list']));

        return new JsonResponse([
            'results' => json_decode($items, true),
            'total_results' => $media->getNbResults(),
            'results_per_page' => $media->getMaxPerPage(),
        ]);
    }