Example #1
0
 /**
  * The code that needs to be called when the cron is running
  * 
  * If $this->enableUserAndGroupSupport() returns TRUE then the run function 
  * will be called for each $user. (The $user parameter will be given)
  * 
  * If $this->enableUserAndGroupSupport() returns FALSE then the 
  * $user parameter is null and the run function will be called only once.
  * 
  * @param CronJob $cronJob
  * @param \GO\Base\Model\User $user [OPTIONAL]
  */
 public function run(CronJob $cronJob, \GO\Base\Model\User $user = null)
 {
     \GO::session()->runAsRoot();
     $usersStmt = \GO\Base\Model\User::model()->findByAttribute('mail_reminders', 1);
     while ($userModel = $usersStmt->fetch()) {
         \GO::debug("Sending mail reminders to " . $userModel->username);
         $remindersStmt = \GO\Base\Model\Reminder::model()->find(\GO\Base\Db\FindParams::newInstance()->joinModel(array('model' => 'GO\\Base\\Model\\ReminderUser', 'localTableAlias' => 't', 'localField' => 'id', 'foreignField' => 'reminder_id', 'tableAlias' => 'ru'))->criteria(\GO\Base\Db\FindCriteria::newInstance()->addCondition('user_id', $userModel->id, '=', 'ru')->addCondition('time', time(), '<', 'ru')->addCondition('mail_sent', '0', '=', 'ru')));
         while ($reminderModel = $remindersStmt->fetch()) {
             //					$relatedModel = $reminderModel->getRelatedModel();
             //					var_dump($relatedModel->name);
             //					$modelName = $relatedModel ? $relatedModel->localizedName : \GO::t('unknown');
             $subject = \GO::t('reminder') . ': ' . $reminderModel->name;
             $time = !empty($reminderModel->vtime) ? $reminderModel->vtime : $reminderModel->time;
             date_default_timezone_set($userModel->timezone);
             $body = \GO::t('time') . ': ' . date($userModel->completeDateFormat . ' ' . $userModel->time_format, $time) . "\n";
             $body .= \GO::t('name') . ': ' . str_replace('<br />', ',', $reminderModel->name) . "\n";
             //					date_default_timezone_set(\GO::user()->timezone);
             $message = \GO\Base\Mail\Message::newInstance($subject, $body);
             $message->addFrom(\GO::config()->noreply_email, \GO::config()->title);
             $message->addTo($userModel->email, $userModel->name);
             \GO\Base\Mail\Mailer::newGoInstance()->send($message, $failedRecipients);
             if (!empty($failedRecipients)) {
                 trigger_error("Reminder mail failed for recipient: " . implode(',', $failedRecipients), E_USER_NOTICE);
             }
             $reminderUserModelSend = \GO\Base\Model\ReminderUser::model()->findSingleByAttributes(array('user_id' => $userModel->id, 'reminder_id' => $reminderModel->id));
             $reminderUserModelSend->mail_sent = 1;
             $reminderUserModelSend->save();
         }
         date_default_timezone_set(\GO::user()->timezone);
     }
 }
Example #2
0
 protected function actionDisplay($params)
 {
     $findParams = \GO\Base\Db\FindParams::newInstance()->select('count(*) AS count')->join(\GO\Base\Model\ReminderUser::model()->tableName(), \GO\Base\Db\FindCriteria::newInstance()->addModel(\GO\Base\Model\Reminder::model())->addCondition('id', 'ru.reminder_id', '=', 't', true, true), 'ru')->criteria(\GO\Base\Db\FindCriteria::newInstance()->addModel(\GO\Base\Model\ReminderUser::model(), 'ru')->addCondition('user_id', \GO::user()->id, '=', 'ru')->addCondition('time', time(), '<', 'ru'));
     $model = \GO\Base\Model\Reminder::model()->findSingle($findParams);
     $html = "";
     $this->fireEvent('reminderdisplay', array($this, &$html, $params));
     $this->render("Reminder", array('count' => intval($model->count), 'html' => $html));
 }
Example #3
0
 protected function actionReminderUsers($params)
 {
     \GO::setIgnoreAclPermissions();
     $reminderModel = \GO\Base\Model\Reminder::model()->findByPk($params['reminder_id']);
     $response['success'] = true;
     $response['total'] = 0;
     $response['results'] = array();
     $addUserIds = isset($params['add_users']) ? json_decode($params['add_users']) : array();
     $delUserIds = isset($params['delete_keys']) ? json_decode($params['delete_keys']) : array();
     $addGroupIds = isset($params['add_groups']) ? json_decode($params['add_groups']) : array();
     try {
         $response['deleteSuccess'] = true;
         foreach ($delUserIds as $delUserId) {
             $reminderModel->removeManyMany('users', $delUserId);
         }
     } catch (\Exception $e) {
         $response['deleteSuccess'] = false;
         $response['deleteFeedback'] = $e->getMessage();
     }
     foreach ($addGroupIds as $addGroupId) {
         $groupModel = \GO\Base\Model\Group::model()->findByPk($addGroupId);
         $stmt = $groupModel->users;
         while ($userModel = $stmt->fetch()) {
             if (!in_array($userModel->id, $addUserIds)) {
                 $addUserIds[] = $userModel->id;
             }
         }
     }
     foreach ($addUserIds as $addUserId) {
         $remUserModel = \GO\Base\Model\ReminderUser::model()->findSingleByAttributes(array('user_id' => $addUserId, 'reminder_id' => $reminderModel->id));
         if (empty($remUserModel)) {
             $remUserModel = new \GO\Base\Model\ReminderUser();
         }
         $remUserModel->setAttributes(array('reminder_id' => $reminderModel->id, 'user_id' => $addUserId, 'time' => $reminderModel->time));
         $remUserModel->save();
     }
     if (!empty($reminderModel->users)) {
         $stmt = $reminderModel->users;
         while ($remUserModel = $stmt->fetch()) {
             $response['results'][] = array('id' => $remUserModel->id, 'name' => $remUserModel->name);
             $response['total'] += 1;
         }
     }
     return $response;
 }