1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
<?php
namespace hji\users\models;
use hji\common\utils\WPHelper;
use hji\ResponsiveIDX\controllers\Settings as rIDXSettings;
use hji\users\core\abstracts\Component;
use hji\users\Users;
class RegistrationNotificationViewModel extends Component
{
protected $user;
protected $leadsEmail;
function __construct($user)
{
$this->user = $user;
$this->leadsEmail = get_option(rIDXSettings::$general_settings_key);
}
function sendNotification()
{
$emailData = (array)$this->getEmailData();
extract($emailData);
if (!$email || !$subject || !$headers || !$body)
{
return;
}
wp_mail($email, $subject, $body, $headers);
}
protected function getEmailData()
{
$host = parse_url(get_site_url(), PHP_URL_HOST);
$subject = 'New User Registration at ' . $host;
$headers[] = 'From:' . $host . '<do-not-reply@' . $host .'>';
$headers[] = 'Content-type: text/html';
$vars['user'] = $this->user;
$vars['userActions'] = $this->userActivityViewData();
return apply_filters('hji_user_registration_notification_email', array(
'email' => $this->leadsEmail,
'subject' => $subject,
'headers' => $headers,
'body' => $this->getEmailBody($vars)
));
}
protected function getEmailBody($vars)
{
$view = $this->services()->getView(Users::$dir . '/classes/views');
return $view->render('registration-lead-notification',$vars);
}
protected function userActivityViewData()
{
$data = array();
$userActionLogger = $this->di()->get('hji\\membership\\models\\UserActionLogger');
if ($events = $userActionLogger->getLog())
{
foreach ($events as $event)
{
if (is_object($event))
{
$data[$event->name][] = $this->formatEvenValues($event);
}
}
}
return $data;
}
protected function formatEvenValues($event)
{
$result = array();
$list = (array)$event;
foreach ($list as $label => $value)
{
switch($label)
{
case 'name':
continue;
case 'attributes':
$result = array_merge($result, $this->arrayToList($list[$label]));
break;
case 'timestamp':
$result[$label] = WPHelper::toDateTime($value);
break;
}
}
return $result;
}
protected function arrayToList($array)
{
$list = array();
foreach ($array as $k => $v)
{
$list[$k] = (is_array($v)) ? implode(' - ', $v) : $v;
}
return $list;
}
}