Whups::sendReminders PHP Method

sendReminders() public static method

Sends reminders, one email per user.
public static sendReminders ( Horde_Variables $vars )
$vars Horde_Variables The selection criteria: - 'id' (integer) for individual tickets - 'queue' (integer) for tickets of a queue. - 'category' (array) for ticket categories, defaults to unresolved tickets. - 'unassigned' (boolean) for unassigned tickets.
    public static function sendReminders($vars)
    {
        global $whups_driver;
        if ($vars->get('id')) {
            $info = array('id' => $vars->get('id'));
        } elseif ($vars->get('queue')) {
            $info['queue'] = $vars->get('queue');
            if ($vars->get('category')) {
                $info['category'] = $vars->get('category');
            } else {
                // Make sure that resolved tickets aren't returned.
                $info['category'] = array('unconfirmed', 'new', 'assigned');
            }
        } else {
            throw new Whups_Exception(_("You must select at least one queue to send reminders for."));
        }
        $tickets = $whups_driver->getTicketsByProperties($info);
        self::sortTickets($tickets);
        if (!count($tickets)) {
            throw new Whups_Exception(_("No tickets matched your search criteria."));
        }
        $unassigned = $vars->get('unassigned');
        $remind = array();
        foreach ($tickets as $info) {
            $info['link'] = self::urlFor('ticket', $info['id'], true, -1);
            $owners = $whups_driver->getOwners($info['id']);
            if (!empty($owners)) {
                foreach (reset($owners) as $owner) {
                    $remind[$owner][] = $info;
                }
            } elseif (!empty($unassigned)) {
                $remind['**' . $unassigned][] = $info;
            }
        }
        /* Build message template. */
        $view = new Horde_View(array('templatePath' => WHUPS_BASE . '/config'));
        $view->date = strftime($GLOBALS['prefs']->getValue('date_format'));
        /* Get queue specific notification message text, if available. */
        $message_file = WHUPS_BASE . '/config/reminder_email.plain';
        if (file_exists($message_file . '.local.php')) {
            $message_file .= '.local.php';
        } else {
            $message_file .= '.php';
        }
        $message_file = basename($message_file);
        foreach ($remind as $user => $utickets) {
            if (empty($user) || !count($utickets)) {
                continue;
            }
            $view->tickets = $utickets;
            $subject = _("Reminder: Your open tickets");
            $whups_driver->mail(array('recipients' => array($user => 'owner'), 'subject' => $subject, 'view' => $view, 'template' => $message_file, 'from' => $user));
        }
    }

Usage Example

Exemplo n.º 1
0
 public function run()
 {
     $this->_runtime = time();
     // See if we need to include the reminders config file.
     if (filemtime(WHUPS_BASE . '/config/reminders.php') > $this->_filestamp) {
         $this->_filestamp = $this->_runtime;
         $this->_reminders = Horde::loadConfiguration('reminders.php', 'reminders', 'whups');
     }
     foreach ($this->_reminders as $reminder) {
         $ds = new Horde_Scheduler_Cron_Date($reminder['frequency']);
         if ($ds->scheduledAt($this->_runtime)) {
             if (!empty($reminder['server_name'])) {
                 $GLOBALS['conf']['server']['name'] = $reminder['server_name'];
             }
             $vars = new Horde_Variables($reminder);
             Whups::sendReminders($vars);
         }
     }
 }
All Usage Examples Of Whups::sendReminders