public function actionIndex()
 {
     $dataProvider = new ActiveDataProvider(['query' => Notice::find()]);
     $noticeDataProviders = array();
     $category = ConfigParam::getConfig('category', 'title');
     foreach ($category as $key => $value) {
         $data = new ActiveDataProvider(['totalCount' => 10, 'pagination' => ['pageSize' => 10], 'query' => Notice::find()->where(['category' => $key])->orderBy('publishdate desc')]);
         $noticeDataProviders[$key] = ['title' => $value, 'dataProvider' => $data];
     }
     return $this->render('index', ['dataProvider' => $dataProvider, 'notice' => $noticeDataProviders]);
 }
Ejemplo n.º 2
0
 /**
  * 获取当前登陆的用户的通知总数
  * @return array|\yii\db\ActiveRecord[]
  */
 static function Count()
 {
     $NoticeCount = Notice::find()->where(['to_user_id' => Yii::$app->user->id, 'is_read' => 0])->count();
     $NoticeCount = empty($NoticeCount) ? null : $NoticeCount;
     return $NoticeCount;
 }
Ejemplo n.º 3
0
 public function actionNotice()
 {
     $this->title = '通知' . ' - ' . Yii::$app->name;
     $this->description = '';
     if (Yii::$app->user->isGuest) {
         return $this->redirect('/account/login?next=/account/notice');
     }
     Notice::updateAll(['is_read' => 1], 'is_read = 0 and to_user_id = ' . Yii::$app->user->id);
     $query = Notice::find()->where(['to_user_id' => Yii::$app->user->id]);
     $pagination = new Pagination(['defaultPageSize' => Yii::$app->params['pageSize'], 'totalCount' => $query->count()]);
     $model = $query->orderBy(['id' => SORT_DESC])->offset($pagination->offset)->limit($pagination->limit)->all();
     return $this->render('notice', ['model' => $model, 'pagination' => $pagination]);
 }
 public function actionList($category)
 {
     $dataProvider = new ActiveDataProvider(['query' => Notice::find()->where(['category' => $category])]);
     return $this->render('list', ['dataProvider' => $dataProvider]);
 }