/** * 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(); }
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'); ?>
/** * 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; }