EventOnline.php 1.42 KB
<?php
namespace MyMailer;

class EventOnline extends Event{

    /**
     * @param $customers
     * @param $post
     * @param $data
     * @param $template
     * @throws \Exception
     */
    public function sendEventDelivery($post, $data, $template){
        if($post['email']){

            $customers_model = new \customersEmailList();

            $customers = $customers_model->findFirst("email = '{$post['email']}'");

            $event_info =  new \eventInfo();


            if(isset($post['event']) && !empty($post['event'])) {


                $event_info->event_id = $data->id;
                $event_info->customer_id = $customers->id;
                $event_info->project_id = $post['project_id'];

                if($data->unique) {
                    $unique = $event_info->findFirst("event_id = {$data->id} AND customer_id = {$customers->id} AND project_id = {$post['project_id']}");
                    if($unique) {
                        throw new \Exception();
                    }
                }


                $MyMailer = new EventMailer();

                $MyMailer->setFromName($post['project_name']);

                $MyMailer->SendDelivery($template->toArray(),$data->toArray(),array($customers->toArray()));

                $event_info->save();


            } else {
                throw new \Exception();
            }

        } else {
            throw new \Exception("email missing");
        }
    }


}