HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers85/dale-int.com/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 Komma\Mailers\MailService;
use Komma\Pages\PageService;

class ContactController extends \BaseController
{

    protected $contactService;
    protected $mailService;
    protected $pageService;

    /**
     * ContactController constructor.
     * @param ContactService $contactService
     * @param MailService $mailService
     * @param PageService $pageService
     */
    public function __construct(ContactService $contactService, MailService $mailService, PageService $pageService)
    {
        parent::__construct();
        $this->pageService = $pageService;

        $this->data = (object)[];
        $this->mailService = $mailService;
        $this->contactService = $contactService;
    }


    /**
     * This method returns the contact form view
     *
     * @param bool $sent
     * @return mixed
     */
    public function contactForm()
    {
        //By default sent is false
        $sent = false;

        //If the request has a status and the status is success set sent to true
        if (\Request::has('status') && \Request::get('status') == 'success') $sent = true;

        //Load the info from the contact page
        $page = $this->pageService->getPageByCodeName('home');

        //Set the data
        $this->data->content = $page;
        $this->data->id = $page->id;
        $this->data->links = $this->pageService->getAllRoutes();
        $otherLanguages = $this->pageService->getOtherLanguageRoutes($this->data->id);


        //Return the view
        return \View::make('layouts.pages.home')
            ->with('data', $this->data)
            ->with('blocks', $page->blocks)
            ->with('sent', $sent)
            ->with('otherLanguages', $otherLanguages->allTranslations);

    }

    /**
     * This method processes the contact form
     *
     * @return null
     */
    public function contactFormProcess()
    {
        //Validate the input
        $input = \Input::all();
        $validation = $this->contactService->validateContactForm($input);

        //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);
        $this->mailService->sendContactForm($input);

        //If the request ia via ajax, return the string true
        if (\Request::ajax()) return 'true';

        //For the normal request show the contactForm page. with the send variable set to true
        $redirectRoute = $this->pageService->getPageByCodeName('contact')->translation->route->route;
        //For the normal request show the contactForm page. with the send variable set to true 
        return \Redirect::to($redirectRoute.'?status=success');
    }

}