Controller/REST/ScheduledCampaignRESTController.php
public function postCampaignAction(Request $request)
    {
        $campaign = new Campaign();

        $campaignType = $this->get('campaignchain.core.form.type.campaign');
        $campaignType->setView('rest');
        $campaignType->setBundleName(ScheduledCampaignController::BUNDLE_NAME);
        $campaignType->setModuleIdentifier(ScheduledCampaignController::MODULE_IDENTIFIER);

        $form = $this->createForm($campaignType, $campaign);

        $form->handleRequest($request);

        if ($form->isValid()) {
            $em = $this->getDoctrine()->getManager();

            // Make sure that data stays intact by using transactions.
            try {
                $em->getConnection()->beginTransaction();

                $em->persist($campaign);

                // We need the campaign ID for storing the hooks. Hence we must flush here.
                $em->flush();

                /** @var HookService $hookService */
                $hookService = $this->get('campaignchain.core.hook');
                $hookService->processHooks(ScheduledCampaignController::BUNDLE_NAME, ScheduledCampaignController::MODULE_IDENTIFIER, $campaign, $form, true);
                $campaign = $hookService->getEntity();
                $em->flush();

                $em->getConnection()->commit();
            } catch (\Exception $e) {
                $em->getConnection()->rollback();

                return $this->errorResponse($e->getMessage());
            }

            return $this->response(['campaign' => ['id' => $campaign->getId()]]);
        }

        return $this->errorResponse($form);
    }
public function postCampaignAction(Request $request)
    {
        $campaign = new Campaign();

        $campaignType = $this->get('campaignchain.core.form.type.campaign');
        $campaignType->setView('rest');
        $campaignType->setBundleName(ScheduledCampaignController::BUNDLE_NAME);
        $campaignType->setModuleIdentifier(ScheduledCampaignController::MODULE_IDENTIFIER);

        $form = $this->createForm($campaignType, $campaign);

        $form->handleRequest($request);

        if ($form->isValid()) {
            $em = $this->getDoctrine()->getManager();

            // Make sure that data stays intact by using transactions.
            try {
                $em->getConnection()->beginTransaction();

                $em->persist($campaign);

                // We need the campaign ID for storing the hooks. Hence we must flush here.
                $em->flush();

                /** @var HookService $hookService */
                $hookService = $this->get('campaignchain.core.hook');
                $hookService->processHooks(ScheduledCampaignController::BUNDLE_NAME, ScheduledCampaignController::MODULE_IDENTIFIER, $campaign, $form, true);
                $campaign = $hookService->getEntity();
                $em->flush();

                $em->getConnection()->commit();
            } catch (\Exception $e) {
                $em->getConnection()->rollback();

                return $this->errorResponse($e->getMessage());
            }

            return $this->response(['campaign' => ['id' => $campaign->getId()]]);
        }

        return $this->errorResponse($form);
    }
public function postCampaignAction ( Request $ request ) { $ campaign = new Campaign ( ) ; $ campaignType = $ this -> get ( 'campaignchain.core.form.type.campaign' ) ; $ campaignType -> setView ( 'rest' ) ; $ campaignType -> setBundleName ( ScheduledCampaignController :: BUNDLE_NAME ) ; $ campaignType -> setModuleIdentifier ( ScheduledCampaignController :: MODULE_IDENTIFIER ) ; $ form = $ this -> createForm ( $ campaignType , $ campaign ) ; $ form -> handleRequest ( $ request ) ; if ( $ form -> isValid ( ) ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; // Make sure that data stays intact by using transactions. try { $ em -> getConnection ( ) -> beginTransaction ( ) ; $ em -> persist ( $ campaign ) ; // We need the campaign ID for storing the hooks. Hence we must flush here. $ em -> flush ( ) ; /** @var HookService $hookService */ $ hookService = $ this -> get ( 'campaignchain.core.hook' ) ; $ hookService -> processHooks ( ScheduledCampaignController :: BUNDLE_NAME , ScheduledCampaignController :: MODULE_IDENTIFIER , $ campaign , $ form , true ) ; $ campaign = $ hookService -> getEntity ( ) ; $ em -> flush ( ) ; $ em -> getConnection ( ) -> commit ( ) ; } catch ( \ Exception $ e ) { $ em -> getConnection ( ) -> rollback ( ) ; return $ this -> errorResponse ( $ e -> getMessage ( ) ) ; } return $ this -> response ( [ 'campaign' => [ 'id' => $ campaign -> getId ( ) ] ] ) ; } return $ this -> errorResponse ( $ form ) ; }
Create new Scheduled Campaign

Example Request
===============

POST /api/v1/p/campaignchain/campaign-scheduled/campaigns

Example Input
=============

{
"campaign": {
"name": "REST4 Campaign",
"timezone": "UTC",
"campaignchain_hook_campaignchain_duration": {
"startDate": "2016-05-05T12:00:00+0000",
"endDate": "2016-06-05T12:00:00+0000",
"timezone": "UTC"
}
}
}


Example Response
================

{
"campaign": {
"id": 5
}
}

@ApiDoc(section="Campaigns")

@param Request $request
@return \Symfony\Component\HttpFoundation\Response
Create new Scheduled Campaign