Esempio n. 1
0
 /**
  * Notify subscribers of new activity
  *
  * @param   object  $publication  Publication model
  * @param   string  $activity
  * @return  void
  */
 public function onWatch($publication, $activity = 'newversion')
 {
     $this->publication = $publication;
     // Get subscribers
     $subscribers = \Hubzero\Item\Watch::all()->whereEquals('item_type', 'publication')->whereEquals('item_id', $publication->get('id'))->whereEquals('state', 1)->rows();
     // Determine message and url
     switch ($activity) {
         case 'newversion':
             $message = Lang::txt('PLG_PUBLICATIONS_WATCH_MESSAGE_NEWVERSION');
             $subject = Lang::txt('PLG_PUBLICATIONS_WATCH_PUBLICATIONS') . ': ' . Lang::txt('PLG_PUBLICATIONS_WATCH_SUBJECT_EMAIL');
             $url = Route::url($this->publication->link('version'));
             break;
     }
     // Do we have subscribers?
     if (!empty($message) && count($subscribers) > 0) {
         foreach ($subscribers as $subscriber) {
             // Check that user wants to receive update on specific activity
             // TBD
             // Send message
             if ($subscriber->email) {
                 $this->_sendEmail($subscriber, $message, $subject, $url);
             }
         }
     }
     return;
 }
Esempio n. 2
0
 /**
  * Notify subscribers of new activity
  *
  * @param   object   $project     Project model
  * @param   string   $area        Project area of activity
  * @param   array    $activities  Project activities (array of IDs)
  * @param   integer  $actor       Uid of team member posting the activity (to exclude from subscribers)
  * @return  array
  */
 public function onWatch($project, $area = '', $activities = array(), $actor = 0)
 {
     $this->project = $project;
     // Get subscribers
     $subscribers = \Hubzero\Item\Watch::all()->whereEquals('item_type', 'project')->whereEquals('item_id', $project->get('id'))->whereEquals('state', 1)->whereLike('params', '"' . $area . '":1')->whereLike('params', '"frequency":"immediate"')->rows();
     // Get full activity info from IDs
     if ($activities) {
         $activities = $project->table('Activity')->getActivities($project->get('id'), $filters = array('id' => $activities));
     }
     if (empty($activities)) {
         // Nothing to report
         return false;
     }
     $subject = Lang::txt('PLG_PROJECTS_WATCH_EMAIL_SUBJECT');
     // Do we have subscribers?
     if ($subscribers->count() > 0) {
         foreach ($subscribers as $subscriber) {
             if ($actor && $subscriber->created_by == $actor) {
                 // Skip
                 continue;
             }
             // Send message
             if ($subscriber->email) {
                 $this->_sendEmail($project, $subscriber, $activities, $subject);
             }
         }
     }
     return;
 }