File: D:/HostingSpaces/SBogers10/ridderstee.komma.pro/app/Komma/Contact/ContactController.php
<?php
/**
* Short description for the file.
*
* @author Komma <support@komma.pro>
* @copyright (c) 2012-2015, Komma Mediadesign
*/
namespace Komma\Contact;
use Ixudra\Curl\Facades\Curl;
use Komma\Blocks\BlockService;
use Komma\LanguageService;
use Komma\Mailers\MailService;
use Komma\Pages\PageService;
use Illuminate\Support\Facades\URL;
class ContactController extends \BaseController
{
protected $contactService;
protected $mailService;
protected $pageService;
protected $blockService;
public $languageService;
/**
* ContactController constructor.
* @param ContactService $contactService
* @param MailService $mailService
* @param PageService $pageService
*/
public function __construct(ContactService $contactService, BlockService $blockService, MailService $mailService, PageService $pageService)
{
parent::__construct();
$this->pageService = $pageService;
$this->mailService = $mailService;
$this->contactService = $contactService;
$this->blockService = $blockService;
}
/**
* This method returns the contact form view
*
* @param bool $sent
* @return mixed
*/
public function contactForm($send = false)
{
//get content of page by route because of the multiple news overviews all page links
$page = $this->pageService->getPageByCodeName('contact');
$page->send = $send;
// Get root parent and append code_name to page
// So we can find out to which branch/school the page belongs
if($page->getDepth() != 1)
{
$page->root = $this->pageService->getRootParent($page);
}
else
{
// The page itself is the root branch, so to prevent writing if/else statements append it as branch
$page->root = $page;
}
$links = $this->pageService->getAllRoutes();
//Return the view
return \View::make('layouts.pages.contact')
->with('page', $page)
->with('links', $links);
}
public function contactSuccess()
{
return $this->contactForm(true);
}
/**
* This method processes the contact form
*
* @return null
*/
public function contactFormProcess()
{
//Validate the input
$validation = $this->contactService->validateContactForm(\Input::all());
//If validation is not null and the request is via ajax, return the validation messages
if($validation !== null && \Request::ajax()) return $validation;
\Log::info($validation);
//If The validation is not null, redirect back to the form with the errors.
if($validation !== null) return \Redirect::back()->withErrors($validation)->withInput();
$this->mailService->saveMailToDatabase(\Input::all());
$this->mailService->sendContactForm(\Input::all());
// $this->mailService->sendClientMail(\Input::all());
//If the request ia via ajax, return the string true
//For the normal request show the contactForm page. with the send variable set to true
return \Redirect::to(route('contact.success'));
//return Redirect::back()->with('errors', $error);
}
/**
* This method processes the contact form
*
* @return null
*/
public function newsletterProcess()
{
// Birthday is hidden field and must be empty
if(\Input::get('birthday', '') != ''){
return \Redirect::back();
}
//Validate the input
$validation = $this->contactService->validateNewsletterForm(\Input::all());
//If validation is not null and the request is via ajax, return the validation messages
if($validation !== null && \Request::ajax()) return $validation;
\Log::info($validation);
//If The validation is not null, redirect back to the form with the errors.
if($validation !== null) return \Redirect::to(URL::previous() . "#brochure-row-anchor")->withErrors($validation)->withInput();
$this->mailService->saveMailToDatabase(\Input::all(), 'newsletter');
$this->mailService->sendNewsletterForm(\Input::all());
$this->mailService->sendClientMail(\Input::all());
//If the request ia via ajax, return the string true
//For the normal request show the contactForm page. with the send variable set to true
return \Redirect::to(route('newsletter.'. \App::getLocale() .'.success'));
}
public function newsletterSuccess()
{
//get content of page by route because of the multiple news overviews all page links
$page = $this->pageService->getPageByCodeName('contact');
$links = $this->pageService->getAllRoutes();
$page->code_name = 'thanksSubscribe';
//Return the view
return \View::make('layouts.pages.newsletter')
->with('page', $page)
->with('links', $links);
}
}