65 public function notifyUser($template_dir, $template, $subject, $tags)
68 $xoops = xoops::getInstance();
74 if (!is_object(
$user)) {
78 $method =
$user->getVar(
'notify_method');
80 $xoopsMailer =
$xoops->getMailer();
82 case NOTIFICATIONS_METHOD_PM:
83 $xoopsMailer->usePM();
86 foreach ($tags as $k => $v) {
87 $xoopsMailer->assign($k, $v);
90 case NOTIFICATIONS_METHOD_EMAIL:
91 $xoopsMailer->useMail();
92 foreach ($tags as $k => $v) {
93 $xoopsMailer->assign($k, preg_replace(
"/&/i",
'&', $v));
102 $xoopsMailer->setTemplateDir($template_dir);
103 $xoopsMailer->setTemplate($template);
104 $xoopsMailer->setToUsers(
$user);
108 $xoopsMailer->setSubject($subject);
109 $success = $xoopsMailer->send();
115 if ($this->
getVar(
'mode') == NOTIFICATIONS_MODE_SENDONCETHENDELETE) {
120 if ($this->
getVar(
'mode') == NOTIFICATIONS_MODE_SENDONCETHENWAIT) {
121 $this->
setVar(
'mode', NOTIFICATIONS_MODE_WAITFORLOGIN);
146 parent::__construct($db,
'notifications',
'NotificationsNotification',
'id',
'itemid');
159 $qb = $this->db2->createXoopsQueryBuilder()
161 ->from($this->table, null);
170 while ($myrow =
$result->fetch(\PDO::FETCH_ASSOC)) {
172 $notification->assignVars($myrow);
174 $ret[] = $notification;
176 $ret[$myrow[
'id']] = $notification;
178 unset($notification);
206 if (count($objects) == 1) {
271 $mode =
$user->getVar(
'notify_mode');
274 if (!is_array($events)) {
275 $events = array($events);
277 foreach ($events as $event) {
279 if ($notification->getVar(
'mode') != $mode) {
283 $notification = $this->
create();
285 $notification->setVar(
'category', $category);
286 $notification->setVar(
'itemid', $item_id);
287 $notification->setVar(
'uid',
$user_id);
288 $notification->setVar(
'event', $event);
289 $notification->setVar(
'mode', $mode);
290 $this->
insert($notification);
338 foreach ($results as
$result) {
339 $ret[] = $result->getVar(
'event');
395 $extra_tags = array(),
396 $user_list = array(),
400 if (!is_array($events)) {
401 $events = array($events);
403 foreach ($events as $event) {
425 $extra_tags = array(),
426 $user_list = array(),
430 $xoops = xoops::getInstance();
441 $mod_config =
$xoops->getHandlerConfig()->getConfigsByModule(
$module->getVar(
'mid'));
442 if (empty($mod_config[
'notifications_enabled'])) {
445 $category_info =
$helper->getCategory($category,
$module->getVar(
'dirname'));
446 $event_info =
$helper->getEvent($category, $event,
$module->getVar(
'dirname'));
448 $helper->generateConfig($category_info, $event_info,
'option_name'),
449 $mod_config[
'notification_events']
450 ) && empty($event_info[
'invisible'])) {
454 if (!isset($omit_user_id)) {
456 $omit_user_id =
$xoops->user->getVar(
'uid');
467 $mode_criteria->add(
new Criteria(
'mode', NOTIFICATIONS_MODE_SENDALWAYS),
'OR');
468 $mode_criteria->add(
new Criteria(
'mode', NOTIFICATIONS_MODE_SENDONCETHENDELETE),
'OR');
469 $mode_criteria->add(
new Criteria(
'mode', NOTIFICATIONS_MODE_SENDONCETHENWAIT),
'OR');
471 if (!empty($user_list)) {
473 foreach ($user_list as
$user) {
474 $user_criteria->add(
new Criteria(
'uid', intval($user)),
'OR');
479 if (empty($notifications)) {
483 $item_info =
$helper->getEvent($category, $item_id,
$module->getVar(
'dirname'));
486 $tags =
$helper->getTags($category, $item_id, $event,
$module->getVar(
'dirname'));
493 = !empty($category_info[
'item_name']) ? $category_info[
'title'] :
'['
495 $tags[
'X_MODULE'] =
$module->getVar(
'name');
497 $tags[
'X_NOTIFY_CATEGORY'] = $category;
498 $tags[
'X_NOTIFY_EVENT'] = $event;
500 $template_dir = $event_info[
'mail_template_dir'];
501 $template = $event_info[
'mail_template'] .
'.tpl';
502 $subject = $event_info[
'mail_subject'];
504 foreach ($notifications as $notification) {
506 if (empty($omit_user_id) || $notification->getVar(
'uid') != $omit_user_id) {
510 $tags[
'X_UNSUBSCRIBE_URL'] =
$helper->url(
'index.php');
511 $tags = array_merge($tags, $extra_tags);
512 $notification->notifyUser($template_dir, $template, $subject, $tags);
562 if (!is_array($events)) {
563 $events = array($events);
566 foreach ($events as $event) {
567 $event_criteria->add(
new Criteria(
'event', $event),
'OR');
623 foreach ($notifications as $n) {
625 $n->setVar(
'mode', NOTIFICATIONS_MODE_SENDONCETHENWAIT);
642 $notification->
setVar($field_name, $field_value);
643 return $this->
insert($notification);
isSubscribed($category, $item_id, $event, $module_id, $user_id)
const _MD_NOTIFICATIONS_ITEMURLNOTAVAILABLE
const _MD_NOTIFICATIONS_ITEMNAMENOTAVAILABLE
if($uname== ''||$pass== '') $member_handler
getCount(CriteriaElement $criteria=null)
__construct(Connection $db=null)
updateByField(NotificationsNotification $notification, $field_name, $field_value)
triggerEvent($category, $item_id, $event, $extra_tags=array(), $user_list=array(), $module_id=null, $omit_user_id=null)
insert(XoopsObject $object, $force=true)
const _MD_NOTIFICATIONS_ITEMTYPENOTAVAILABLE
subscribe($category, $item_id, $events, $mode=null, $module_id=null, $user_id=null)
getNotification($module_id, $category, $item_id, $event, $user_id)
notifyUser($template_dir, $template, $subject, $tags)
getObjectsArray(CriteriaElement $criteria=null, $id_as_key=false)
getVar($key, $format= 's')
unsubscribeByUser($user_id)
deleteAll(CriteriaElement $criteria, $force=true, $asObject=false)
triggerEvents($category, $item_id, $events, $extra_tags=array(), $user_list=array(), $module_id=null, $omit_user_id=null)
unsubscribeByModule($module_id)
setVar($key, $value, $not_gpc=false)
initVar($key, $data_type, $value=null, $required=false, $maxlength=null, $options= '')
unsubscribeByItem($module_id, $category, $item_id)
doLoginMaintenance($user_id)
getSubscribedEvents($category, $item_id, $module_id, $user_id)
unsubscribe($category, $item_id, $events, $module_id=null, $user_id=null)
getByItemId($module_id, $item_id, $order=null, $status=null)