/** * Send scheduled group announcements * * @param object $job \Components\Cron\Models\Job * @return boolean */ public function sendGroupAnnouncements(\Components\Cron\Models\Job $job) { // Get all announcements that are not yet sent but want to be mailed $announcements = \Hubzero\Item\Announcement::all()->whereEquals('email', 1)->whereEquals('sent', 0)->whereEquals('state', 1)->whereEquals('scope', 'group')->rows(); include_once dirname(dirname(__DIR__)) . DS . 'groups' . DS . 'announcements' . DS . 'announcements.php'; // Loop through each announcement foreach ($announcements as $announcement) { // check to see if we can send if ($announcement->inPublishWindow()) { // get all group members $group = \Hubzero\User\Group::getInstance($announcement->get('scope_id')); if (plgGroupsAnnouncements::send($announcement, $group)) { // mark as sent $announcement->set('sent', 1); $announcement->save(); } } } return true; }
/** * Mark an entry as deleted * * @return mixed An html view on error, redirects on success */ private function _delete() { //verify were authorized if ($this->authorized != 'manager') { $this->setError(Lang::txt('PLG_GROUPS_ANNOUNCEMENTS_ONLY_MANAGERS_CAN_DELETE')); return $this->_list(); } // Incoming $id = Request::getInt('id', 0); $model = \Hubzero\Item\Announcement::oneOrFail($id); // Make sure we are the one who created it if ($model->get('created_by') != User::get('id') && $this->authorized != 'manager') { $this->setError(Lang::txt('PLG_GROUPS_ANNOUNCEMENTS_ONLY_MANAGER_CAN_DELETE', $model->creator()->get('name'))); return $this->_list(); } // Set to deleted state $model->set('state', \Hubzero\Item\Announcement::STATE_DELETED); // Attempt to delete announcement if (!$model->save()) { $this->setError(Lang::txt('PLG_GROUPS_ANNOUNCEMENTS_UNABLE_TO_DELETE')); return $this->_list(); } $url = 'index.php?option=' . $this->option . '&cn=' . $this->group->get('cn') . '&active=' . $this->_name; // Record the activity $recipients = array(['group', $this->group->get('gidNumber')]); foreach ($this->group->get('managers') as $recipient) { $recipients[] = ['user', $recipient]; } Event::trigger('system.logActivity', ['activity' => ['action' => 'deleted', 'scope' => 'announcement', 'scope_id' => $model->get('id'), 'description' => Lang::txt('PLG_GROUPS_ANNOUNCEMENTS_ACTIVITY_DELETED', '<a href="' . Route::url($url) . '">' . \Hubzero\Utility\String::truncate(strip_tags($model->get('content')), 70) . '</a>'), 'details' => array('url' => Route::url($url), 'id' => $this->group->get('gidNumber'), 'alias' => $this->group->get('cn'), 'title' => $this->group->get('description'))], 'recipients' => $recipients]); // Redirect to the main listing App::redirect(Route::url($url), Lang::txt('PLG_GROUPS_ANNOUNCEMENTS_SUCCESSFULLY_DELETED'), 'success'); }