getParent() 공개 메소드

Returns the parent task of this task, if one exists.
public getParent ( ) : mixed
리턴 mixed The parent task, null if none exists
예제 #1
0
파일: Nag.php 프로젝트: DSNS-LAB/Dmail
 /**
  * Sends email notifications that a task has been added, edited, or
  * deleted to users that want such notifications.
  *
  * @param string $action      The event action. One of "add", "edit", or
  *                            "delete".
  * @param Nag_Task $task      The changed task.
  * @param Nag_Task $old_task  The original task if $action is "edit".
  *
  * @throws Nag_Exception
  */
 public static function sendNotification($action, $task, $old_task = null)
 {
     if (!in_array($action, array('add', 'edit', 'delete'))) {
         throw new Nag_Exception('Unknown event action: ' . $action);
     }
     try {
         $share = $GLOBALS['nag_shares']->getShare($task->tasklist);
     } catch (Horde_Share_Exception $e) {
         Horde::log($e->getMessage(), 'ERR');
         throw new Nag_Exception($e);
     }
     $groups = $GLOBALS['injector']->getInstance('Horde_Group');
     $recipients = array();
     $identity = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create();
     $from = $identity->getDefaultFromAddress(true);
     $owner = $share->get('owner');
     if (strlen($owner)) {
         $recipients[$owner] = self::_notificationPref($owner, 'owner');
     }
     foreach ($share->listUsers(Horde_Perms::READ) as $user) {
         if (empty($recipients[$user])) {
             $recipients[$user] = self::_notificationPref($user, 'read', $task->tasklist);
         }
     }
     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', $task->tasklist);
             }
         }
     }
     $addresses = array();
     foreach ($recipients as $user => $vals) {
         if (!$vals) {
             continue;
         }
         $identity = $GLOBALS['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;
     }
     $mail = new Horde_Mime_Mail(array('User-Agent' => 'Nag ' . $GLOBALS['registry']->getVersion(), 'Precedence' => 'bulk', 'Auto-Submitted' => 'auto-generated', 'From' => $from));
     foreach ($addresses as $lang => $twentyFour) {
         $GLOBALS['registry']->setLanguageEnvironment($lang);
         $view_link = Horde::url('view.php', true)->add(array('tasklist' => $task->tasklist, 'task' => $task->id))->setRaw(true);
         switch ($action) {
             case 'add':
                 $subject = _("Task added:");
                 $notification_message = _("You requested to be notified when tasks are added to your task lists.") . "\n\n" . ($task->due ? _("The task \"%s\" has been added to task list \"%s\", with a due date of: %s.") : _("The task \"%s\" has been added to task list \"%s\".")) . "\n" . str_replace('%', '%%', $view_link);
                 break;
             case 'edit':
                 $subject = _("Task modified:");
                 $notification_message = _("You requested to be notified when tasks are edited on your task lists.") . "\n\n" . _("The task \"%s\" has been edited on task list \"%s\".") . "\n" . str_replace('%', '%%', $view_link) . "\n\n" . _("Changes made for this task:");
                 if ($old_task->name != $task->name) {
                     $notification_message .= "\n - " . sprintf(_("Changed name from \"%s\" to \"%s\""), $old_task->name, $task->name);
                 }
                 if ($old_task->tasklist != $task->tasklist) {
                     $old_share = $GLOBALS['nag_shares']->getShare($old_task->tasklist);
                     $notification_message .= "\n - " . sprintf(_("Changed task list from \"%s\" to \"%s\""), Nag::getLabel($old_share), Nag::getLabel($share));
                 }
                 if ($old_task->parent_id != $task->parent_id) {
                     $old_parent = $old_task->getParent();
                     try {
                         $parent = $task->getParent();
                         $notification_message .= "\n - " . sprintf(_("Changed parent task from \"%s\" to \"%s\""), $old_parent ? $old_parent->name : _("no parent"), $parent ? $parent->name : _("no parent"));
                     } catch (Nag_Exception $e) {
                     }
                 }
                 if ($old_task->assignee != $task->assignee) {
                     $identity = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create($old_task->assignee);
                     $old_name = $identity->getValue('fullname');
                     if (!strlen($old_name)) {
                         $old_name = $old_task->assignee;
                     }
                     $identity = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create($task->assignee);
                     $new_name = $identity->getValue('fullname');
                     if (!strlen($new_name)) {
                         $new_name = $new_task->assignee;
                     }
                     $notification_message .= "\n - " . sprintf(_("Changed assignee from \"%s\" to \"%s\""), $old_name, $new_name);
                 }
                 if ($old_task->private != $task->private) {
                     $notification_message .= "\n - " . ($task->private ? _("Turned privacy on") : _("Turned privacy off"));
                 }
                 if ($old_task->due != $task->due) {
                     $notification_message .= "\n - " . sprintf(_("Changed due date from %s to %s"), $old_task->due ? self::formatDate($old_task->due) : _("no due date"), $task->due ? self::formatDate($task->due) : _("no due date"));
                 }
                 if ($old_task->start != $task->start) {
                     $notification_message .= "\n - " . sprintf(_("Changed start date from %s to %s"), $old_task->start ? self::formatDate($old_task->start) : _("no start date"), $task->start ? self::formatDate($task->start) : _("no start date"));
                 }
                 if ($old_task->alarm != $task->alarm) {
                     $notification_message .= "\n - " . sprintf(_("Changed alarm from %s to %s"), self::formatAlarm($old_task->alarm), self::formatAlarm($task->alarm));
                 }
                 if ($old_task->priority != $task->priority) {
                     $notification_message .= "\n - " . sprintf(_("Changed priority from %s to %s"), $old_task->priority, $task->priority);
                 }
                 if ($old_task->estimate != $task->estimate) {
                     $notification_message .= "\n - " . sprintf(_("Changed estimate from %s to %s"), $old_task->estimate, $task->estimate);
                 }
                 if ($old_task->completed != $task->completed) {
                     $notification_message .= "\n - " . sprintf(_("Changed completion from %s to %s"), $old_task->completed ? _("completed") : _("not completed"), $task->completed ? _("completed") : _("not completed"));
                 }
                 if ($old_task->desc != $task->desc) {
                     $notification_message .= "\n - " . _("Changed description");
                 }
                 break;
             case 'delete':
                 $subject = _("Task deleted:");
                 $notification_message = _("You requested to be notified when tasks are deleted from your task lists.") . "\n\n" . _("The task \"%s\" has been deleted from task list \"%s\".");
                 break;
         }
         $mail->addHeader('Subject', $subject . ' ' . $task->name);
         foreach ($twentyFour as $tf => $dateFormat) {
             foreach ($dateFormat as $df => $df_recipients) {
                 $message = sprintf($notification_message, $task->name, Nag::getLabel($share), $task->due ? strftime($df, $task->due) . ' ' . date($tf ? 'H:i' : 'h:ia', $task->due) : '');
                 if (strlen(trim($task->desc))) {
                     $message .= "\n\n" . _("Task description:") . "\n\n" . $task->desc;
                 }
                 $mail->setBody($message);
                 $mail->clearRecipients();
                 $mail->addRecipients($df_recipients);
                 Horde::log(sprintf('Sending event notifications for %s to %s', $task->name, implode(', ', $df_recipients)), 'INFO');
                 $mail->send($GLOBALS['injector']->getInstance('Horde_Mail'));
             }
         }
     }
 }