EventOnlineSubscribe.php 1.13 KB
<?php

namespace MyMailer;

class EventOnlineSubscribe extends EventOnline{

    public $is_new = false;
    public $customer;

    /**
     * @param $post array()
     */
    public function subscribeNewCustomer($post){
        $user['email']       = $post['email'];
        $user['name']        = isset($post['name']) ? $post['name']:'';
        $user['project_id']  = $post['project_id'];

        $customers_model = new \customersEmailList;

        if(!$this->checkCustomer($customers_model, $post)){
            $customers_model->save($user);
            $this->addLettersList($post['project_id'],$customers_model->id);
            return $customers_model;
        }


    }

    public function checkCustomer($customers_model, $post){

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

        if($this->customer instanceof \customersEmailList){
            return true;
        } else {
            return false;
        }
    }

    public function addLatterListToNewCustomer($post,$customer){
        if($this->is_new){
            $this->addLettersList($post['project_id'],$this->customer->id);
        }
    }
}