Exemplo n.º 1
0
 /**
  * Уведомления при подписке на человека
  */
 public function actionSubscriptionUserNotifications()
 {
     $date_minus_six_hours = new \DateTime();
     $date_minus_six_hours = $date_minus_six_hours->modify('-2 hours');
     $email_queue = [];
     $wall_events = Wall::find()->where('created >= ' . $date_minus_six_hours->getTimestamp() . ' AND created <= ' . time())->all();
     foreach ($wall_events as $event) {
         if ($event->type == 2) {
             $event_data = json_decode($event->mem);
             $User = User::findOne(['id' => $event_data->to]);
             $Subscriber = User::find()->where(['id' => $event_data->from])->asArray()->one();
             if ($Subscriber) {
                 $email_queue[$User->email][$event_data->from] = ['subscriber' => User::find()->where(['id' => $event_data->from])->asArray()->one(), 'data' => $event->created, 'status' => $event_data->status];
             }
         }
     }
     foreach ($email_queue as $email => $recipient) {
         $subscribed = [];
         $unsubscribed = [];
         foreach ($recipient as $person) {
             if ($person['status']) {
                 $subscribed[] = $person;
             } else {
                 $unsubscribed[] = $person;
             }
         }
         $messages[] = \Yii::$app->mailer->compose('user-subscribe', ['subscribed' => $subscribed, 'unsubscribed' => $unsubscribed])->setFrom('*****@*****.**')->setTo($email)->setSubject('Для Вас есть новые уведомления на сайте http://findspree.ru');
     }
     if (isset($messages) && !empty($messages)) {
         \Yii::$app->mailer->sendMultiple($messages);
     }
 }
Exemplo n.º 2
0
 public function actionWall($id = null)
 {
     /**
      * @var $userView User
      */
     $userView = $id && \Yii::$app->user->identity != $id ? User::findOne($id) : \Yii::$app->user->identity;
     if (!$userView) {
         throw new NotFoundHttpException();
     }
     $collection = new ActiveDataProvider();
     $collection->pagination->pageSize = 12;
     $criteria = ['and', 'wall.id=wall_post.wall_id', ['=', 'target_type', WallPost::TARGET_TYPE_USER], ['=', 'target_id', $userView->id]];
     if (!$userView->isMy()) {
         $criteria[] = ['=', 'personal', 0];
     }
     $collection->query = Wall::find()->select('wall.*')->innerJoin(WallPost::tableName(), $criteria)->orderBy('wall.id DESC');
     return $this->renderCollection($collection);
 }