<?php

if (!defined('BASEPATH')) {
    exit('No direct script access allowed');
}

/**
 * @author CIEXT skeleton
 */
class Newsletter_email_tmodel extends \Ciext\Model\AbstractTableModel
{

    protected $table = 'newsletter_email';
    protected $pkey = 'id_newsletter_email';

    public function __construct()
    {
        parent::__construct();

        // Send email to admin
        $this->attach($this->load->library('newsletter/events/new_user_subscribed_event'));
        // Copy to MailChimp
        $this->attach($this->load->library('newsletter/events/mailchimp_observer_event'));
    }

    public function is_email_exist($email = '')
    {
        $res = $this->db->select($this->pkey)
                        ->where('email', (string) $email)
                        ->get($this->table)->row_array();

        return !empty($res[$this->pkey]);
    }

}
