Kronolith::sendNotification PHP 메소드

sendNotification() 공개 정적인 메소드

Sends email notifications that a event has been added, edited, or deleted to users that want such notifications.
public static sendNotification ( Kronolith_Event $event, string $action )
$event Kronolith_Event An event.
$action string The event action. One of "add", "edit", or "delete".
    public static function sendNotification($event, $action)
    {
        global $injector, $prefs, $registry;
        if (!in_array($action, array('add', 'edit', 'delete'))) {
            throw new Kronolith_Exception('Unknown event action: ' . $action);
        }
        // @TODO: Send notifications to the email addresses stored in the
        // resource object?
        if ($event->calendarType == 'resource') {
            return;
        }
        $groups = $injector->getInstance('Horde_Group');
        $calendar = $event->calendar;
        $recipients = array();
        try {
            $share = $injector->getInstance('Kronolith_Shares')->getShare($calendar);
        } catch (Horde_Share_Exception $e) {
            throw new Kronolith_Exception($e);
        }
        $owner = $share->get('owner');
        if ($owner) {
            $recipients[$owner] = self::_notificationPref($owner, 'owner');
        }
        $senderIdentity = $injector->getInstance('Horde_Core_Factory_Identity')->create($registry->getAuth() ?: $event->creator ?: $owner);
        foreach ($share->listUsers(Horde_Perms::READ) as $user) {
            if (empty($recipients[$user])) {
                $recipients[$user] = self::_notificationPref($user, 'read', $calendar);
            }
        }
        foreach ($share->listGroups(Horde_Perms::READ) as $group) {
            try {
                $group_users = $groups->listUsers($group);
            } catch (Horde_Group_Exception $e) {
                Horde::log($e, 'ERR');
                continue;
            }
            foreach ($group_users as $user) {
                if (empty($recipients[$user])) {
                    $recipients[$user] = self::_notificationPref($user, 'read', $calendar);
                }
            }
        }
        $addresses = array();
        foreach ($recipients as $user => $vals) {
            if (!$vals) {
                continue;
            }
            $identity = $injector->getInstance('Horde_Core_Factory_Identity')->create($user);
            $email = $identity->getValue('from_addr');
            if (strpos($email, '@') === false) {
                continue;
            }
            if (!isset($addresses[$vals['lang']][$vals['tf']][$vals['df']])) {
                $addresses[$vals['lang']][$vals['tf']][$vals['df']] = array();
            }
            $tmp = new Horde_Mail_Rfc822_Address($email);
            $tmp->personal = $identity->getValue('fullname');
            $addresses[$vals['lang']][$vals['tf']][$vals['df']][] = strval($tmp);
        }
        if (!$addresses) {
            return;
        }
        $image = self::getImagePart('big_new.png');
        $view = new Horde_View(array('templatePath' => KRONOLITH_TEMPLATES . '/update'));
        $view->event = $event;
        $view->calendar = Kronolith::getLabel($share);
        $view->imageId = $image->getContentId();
        if (!$prefs->isLocked('event_notification')) {
            $view->prefsUrl = Horde::url($registry->getServiceLink('prefs', 'kronolith'), true)->remove(session_name());
        }
        new Horde_View_Helper_Text($view);
        foreach ($addresses as $lang => $twentyFour) {
            $registry->setLanguageEnvironment($lang);
            switch ($action) {
                case 'add':
                    $subject = _("Event added:");
                    break;
                case 'edit':
                    $subject = _("Event edited:");
                    break;
                case 'delete':
                    $subject = _("Event deleted:");
                    break;
            }
            foreach ($twentyFour as $tf => $dateFormat) {
                foreach ($dateFormat as $df => $df_recipients) {
                    $view->header = $subject . ' ' . $event->title;
                    $mail = new Horde_Mime_Mail(array('Subject' => $view->header, 'To' => implode(',', $df_recipients), 'From' => $senderIdentity->getDefaultFromAddress(true), 'User-Agent' => 'Kronolith ' . $registry->getVersion()));
                    $multipart = self::buildMimeMessage($view, 'notification', $image);
                    $mail->setBasePart($multipart);
                    Horde::log(sprintf('Sending event notifications for %s to %s', $event->title, implode(', ', $df_recipients)), 'DEBUG');
                    $mail->send($injector->getInstance('Horde_Mail'));
                }
            }
        }
    }

Usage Example

예제 #1
0
파일: Driver.php 프로젝트: jubinpatel/horde
 /**
  * Wrapper for sending notifications, so that we can overwrite this action
  * in Kronolith_Driver_Resource.
  *
  * @param Kronolith_Event $event
  * @param string $action
  */
 protected function _handleNotifications(Kronolith_Event $event, $action)
 {
     Kronolith::sendNotification($event, $action);
 }
All Usage Examples Of Kronolith::sendNotification