コード例 #1
0
ファイル: tasks.class.php プロジェクト: victorrod/web2project
 /**
  * Called by the Event Queue processor to process a reminder
  * on a task.
  * @access  public
  * @param   string  $notUsed    Module name (not used)
  * @param   string  $notUsed2   Type of event (not used)
  * @param   integer $id         ID of task being reminded
  * @param   integer $owner      Originator of event
  * @param   mixed   $notUsed    event-specific arguments.
  *
  * @return  mixed   true, dequeue event, false, event stays in queue.
  * -1, event is destroyed.
  */
 public function remind($notUsed = null, $notUsed2 = null, $id, $owner, $notUsed3 = null)
 {
     // At this stage we won't have an object yet
     if (!$this->load($id)) {
         return -1;
         // No point it trying again later.
     }
     $this->htmlDecode();
     // Only remind on working days.
     $today = new w2p_Utilities_Date();
     if (!$today->isWorkingDay()) {
         return true;
     }
     // Check if the task is completed
     if ($this->task_percent_complete == 100) {
         return -1;
     }
     $contacts = $this->assignees($this->task_id);
     $contact = new CContact();
     $owner = $contact->findContactByUserId($this->task_owner);
     $contacts[$owner->contact_id] = array('user_id' => $this->task_owner, 'contact_id' => $owner->contact_id, 'contact_name' => $owner->contact_display_name, 'contact_email' => $owner->contact_email);
     // build the subject line, based on how soon the
     // task will be overdue.
     $starts = new w2p_Utilities_Date($this->task_start_date);
     $expires = new w2p_Utilities_Date($this->task_end_date);
     $now = new w2p_Utilities_Date();
     $diff = $expires->dateDiff($now);
     $diff *= $expires->compare($expires, $now);
     $prefix = $this->_AppUI->_('Task Due', UI_OUTPUT_RAW);
     if ($diff == 0) {
         $msg = $this->_AppUI->_('TODAY', UI_OUTPUT_RAW);
     } elseif ($diff == 1) {
         $msg = $this->_AppUI->_('TOMORROW', UI_OUTPUT_RAW);
     } elseif ($diff < 0) {
         $msg = $this->_AppUI->_(array('OVERDUE', abs($diff), 'DAYS'));
         $prefix = $this->_AppUI->_('Task', UI_OUTPUT_RAW);
     } else {
         $msg = $this->_AppUI->_(array($diff, 'DAYS'));
     }
     $project = new CProject();
     $project->overrideDatabase($this->_query);
     $project_name = $project->load($this->task_project)->project_name;
     // Check to see that the project is both active and not a template
     if (!$project->project_active || $project->project_status == w2PgetConfig('template_projects_status_id', 0)) {
         return -1;
     }
     $subject = $prefix . ' ' . $msg . ' ' . $this->task_name . '::' . $project_name;
     $emailManager = new w2p_Output_EmailManager($this->_AppUI);
     $body = $emailManager->getTaskRemind($this, $msg, $project_name, $contacts);
     $mail = new w2p_Utilities_Mail();
     $mail->Subject($subject);
     foreach ($contacts as $contact) {
         $user_id = $contact['user_id'];
         $this->_AppUI->loadPrefs($user_id);
         $df = $this->_AppUI->getPref('SHDATEFORMAT');
         $tz = $this->_AppUI->getPref('TIMEZONE');
         $body = str_replace('START-TIME', $starts->convertTZ($tz)->format($df), $body);
         $body = str_replace('END-TIME', $expires->convertTZ($tz)->format($df), $body);
         $mail->Body($body, $this->_locale_char_set);
         $mail->To($contact['contact_email'], true);
         $mail->Send();
     }
     return true;
 }