<?php

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

/**
 * @author CIEXT skeleton
 */
class New_user_subscribed_event implements SplObserver
{

    #[\ReturnTypeWillChange]
    public function update(SplSubject $subject)
    {
        $event_name = $subject->get_event_name();
        $event_data = $subject->get_event_data();

        if ($event_name == 'add' && !empty($event_data['id'])) {
            $ci = & get_instance();
            $data = $ci->newsletter_email_tmodel->fetch($event_data['id']);

            if (!empty($data)) {
                $admin_email = $ci->load->library('ciext/configurator')->set_resource('system')->item('admin_email');
                $ci->load->library('emailmng/emailmng');
                $ci->emailmng->to($admin_email);
                $ci->emailmng->send_template('newsletter_new_user_subscribed', [], $data);
            }
        }
    }

}
