Exemplo n.º 1
0
 /**
  * Display module contents
  *
  * @return  void
  */
 public function display()
 {
     // Get the module parameters
     $this->moduleclass = $this->params->get('moduleclass');
     $this->limit = intval($this->params->get('limit', 10));
     $this->limit = $this->limit ? $this->limit : 10;
     $this->rows = Recipient::all()->including(['log', function ($log) {
         $log->select('*');
     }])->whereEquals('scope', 'user')->whereEquals('scope_id', User::get('id'))->whereEquals('state', 1)->ordered()->limit($this->limit)->paginated();
     require $this->getLayoutPath();
 }
Exemplo n.º 2
0
 /**
  * Create an activity log entry.
  *
  * @param   mixed    $data
  * @param   array    $recipients
  * @return  boolean
  */
 public static function log($data = array(), $recipients = array())
 {
     if (is_object($data)) {
         $data = (array) $data;
     }
     if (is_string($data)) {
         $data = array('description' => $data);
         $data['action'] = 'create';
         if (substr(strtolower($data['description']), 0, 6) == 'update') {
             $data['action'] = 'update';
         }
         if (substr(strtolower($data['description']), 0, 6) == 'delete') {
             $data['action'] = 'delete';
         }
     }
     try {
         $activity = self::blank()->set($data);
         if (!$activity->save()) {
             return false;
         }
         // Get everyone subscribed
         $subscriptions = Subscription::all()->whereEquals('scope', $activity->get('scope'))->whereEquals('scope_id', $activity->get('scope_id'))->rows();
         foreach ($subscriptions as $subscription) {
             $recipients[] = array('scope' => 'user', 'scope_id' => $subscription->user_id);
         }
         $sent = array();
         // Do we have any recipients?
         foreach ($recipients as $receiver) {
             // Default to type 'user'
             if (!is_array($receiver)) {
                 $receiver = array('scope' => 'user', 'scope_id' => $receiver);
             }
             // Make sure we have expected data
             if (!isset($receiver['scope']) || !isset($receiver['scope_id'])) {
                 $receiver = array_values($receiver);
                 $receiver['scope'] = $receiver[0];
                 $receiver['scope_id'] = $receiver[1];
             }
             $key = $receiver['scope'] . '.' . $receiver['scope_id'];
             // No duplicate sendings
             if (in_array($key, $sent)) {
                 continue;
             }
             // Create a recipient object that ties a user to an activity
             $recipient = Recipient::blank()->set(['scope' => $receiver['scope'], 'scope_id' => $receiver['scope_id'], 'log_id' => $activity->get('id'), 'state' => 1]);
             $recipient->save();
             $sent[] = $key;
         }
     } catch (Exception $e) {
         return false;
     }
     return true;
 }
Exemplo n.º 3
0
                echo Route::url('index.php?option=' . $this->option . '&cn=' . $group->cn . '&task=accept');
                ?>
" title="<?php 
                echo Lang::txt('PLG_MEMBERS_GROUPS_ACTION_ACCEPT_TITLE');
                ?>
"><?php 
                echo Lang::txt('PLG_MEMBERS_GROUPS_ACTION_ACCEPT');
                ?>
</a>
								<?php 
            } else {
                ?>
									<div class="grid">
										<div class="col span6">
											<span><?php 
                $activity = \Hubzero\Activity\Recipient::all()->including('log')->whereEquals('scope', 'group')->whereEquals('scope_id', $group->gidNumber)->whereEquals('state', 1)->ordered()->row();
                $dt = Date::of($activity->get('created'));
                $ct = Date::of('now');
                $lapsed = $ct->toUnix() - $dt->toUnix();
                if ($lapsed < 30) {
                    echo Lang::txt('PLG_MEMBERS_GROUPS_ACTIVITY_JUST_NOW');
                } elseif ($lapsed > 30 && $lapsed < 60) {
                    echo Lang::txt('PLG_MEMBERS_GROUPS_ACTIVITY_A_MINUTE_AGO');
                } else {
                    echo $dt->relative('week');
                }
                ?>
</span>
											<?php 
                echo Lang::txt('PLG_MEMBERS_GROUPS_ACTIVITY_LAST');
                ?>
Exemplo n.º 4
0
 /**
  * Email member activity digest
  *
  * Current limitations include a lack of queuing/scheduling. This means that this cron job
  * should not be set to run more than once daily, otherwise it will continue to send out the
  * same digest to people over and over again.
  *
  * @param   object  $job  \Components\Cron\Models\Job
  * @return  bool
  */
 public function emailMemberDigest(\Components\Cron\Models\Job $job)
 {
     // Make sure digests are enabled?  The cron job being on may be evidence enough...
     if (!Plugin::params('members', 'activity')->get('email_digests', false)) {
         return true;
     }
     // Load language files
     Lang::load('plg_members_activity') || Lang::load('plg_members_activity', PATH_CORE . DS . 'plugins' . DS . 'members' . DS . 'activity');
     // Database connection
     $db = App::get('db');
     // 0 = no email
     // 1 = immediately
     // 2 = digest daily
     // 3 = digest weekly
     // 4 = digest monthly
     $intervals = array(0 => 'none', 1 => 'now', 2 => 'day', 3 => 'week', 4 => 'month');
     // Check frequency (this plugin should run early every morning)
     // If daily, run every day
     // If weekly, only run this one on mondays
     // If monthly, only run this on on the 1st of the month
     $isDay = true;
     $isWeek = Date::of('now')->toLocal('N') == 1 ? true : false;
     $isMonth = Date::of('now')->toLocal('j') == 1 ? true : false;
     foreach ($intervals as $val => $interval) {
         // Skip the first two options for now
         if ($val < 2) {
             continue;
         }
         if ($val == 3 && !$isWeek) {
             continue;
         }
         if ($val == 4 && !$isMonth) {
             continue;
         }
         // Find all users that want weekly digests and the last time the digest
         // was sent was NEVER or older than 1 month ago.
         $previous = Date::of('now')->subtract('1 ' . $interval)->toSql();
         // Set up the query
         $query = "SELECT DISTINCT(scope_id) FROM `#__activity_digests` WHERE `scope`=" . $db->quote('user') . " AND `frequency`=" . $db->quote($val) . " AND (`sent` = '0000-00-00 00:00:00' OR `sent` <= " . $db->quote($previous) . ")";
         $db->setQuery($query);
         $users = $db->loadColumn();
         // Loop through members and get their groups that have the digest set
         if ($users && count($users) > 0) {
             foreach ($users as $user) {
                 $posts = \Hubzero\Activity\Recipient::all()->including('log')->whereEquals('scope', 'user')->whereEquals('scope_id', $user)->whereEquals('state', 1)->where('created', '>', $previous)->ordered()->rows();
                 // Gather up applicable posts and queue up the emails
                 if (count($posts) > 0) {
                     if ($this->sendEmail($user, $posts, $interval)) {
                         // Update the last sent timestamp
                         $query = "UPDATE `#__activity_digests` SET `sent`=" . $db->quote(Date::toSql()) . " WHERE `scope`=" . $db->quote('user') . " AND `scope_id`=" . $db->quote($user);
                         $db->setQuery($query);
                         $db->query();
                     }
                 }
             }
         }
     }
     return true;
 }