示例#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);
     }
 }
示例#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));
 }
示例#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;
 }
示例#4
0
 /**
  * Add a reminder linked to this model
  *
  * @param string $name The name of the reminder
  * @param int $time This needs to be an unixtimestamp
  * @param int $user_id The user where this reminder belongs to.
  * @param int $vtime The time that will be displayed in the reminder
  * @return \GO\Base\Model\Reminder
  */
 public function addReminder($name, $time, $user_id, $vtime = null)
 {
     $userModel = \GO\Base\Model\User::model()->findByPk($user_id, false, true);
     if (!empty($userModel) && !$userModel->no_reminders) {
         $reminder = \GO\Base\Model\Reminder::newInstance($name, $time, $this->className(), $this->pk, $vtime);
         $reminder->setForUser($user_id);
         return $reminder;
     } else {
         return false;
     }
 }
示例#5
0
文件: Event.php 项目: ajaboa/crmpuan
 public function countReminders()
 {
     $modelTypeModel = \GO\Base\Model\ModelType::model()->findSingleByAttribute('model_name', $this->className());
     $stmt = \GO\Base\Model\Reminder::model()->findByAttributes(array('model_id' => $this->id, 'model_type_id' => $modelTypeModel->id));
     return !empty($stmt) ? $stmt->rowCount() : 0;
 }
示例#6
0
 public static function initListeners()
 {
     \GO\Base\Model\User::model()->addListener('delete', "GO\\Calendar\\CalendarModule", "deleteUser");
     \GO\Base\Model\Reminder::model()->addListener('dismiss', "GO\\Calendar\\Model\\Event", "reminderDismissed");
 }