Пример #1
0
 public function run()
 {
     $this->hotAlbum = Album::find()->limit(4)->all();
     $this->hotDiary = Diary::find()->limit(10)->all();
     $this->hotSong = Song::find()->limit(5)->orderBy(['created_at' => SORT_DESC])->all();
     return $this->render('home-hot-content', array('hotAlbum' => $this->hotAlbum, 'hotDiary' => $this->hotDiary, 'hotSong' => $this->hotSong));
 }
Пример #2
0
 /**
  * 个人日记
  * @param $userId
  * @return array
  */
 public function personalDiaryByUserId($userId)
 {
     $query = Diary::find()->andWhere(['created_by' => $userId]);
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count()]);
     $pages->setPageSize(10);
     $models = $query->orderBy(['created_at' => SORT_DESC])->offset($pages->offset)->limit($pages->limit)->all();
     return ['models' => $models, 'pages' => $pages, 'userCreadedBy' => User::find()->andWhere(['id' => $userId])->asArray()->one(), 'userExtendCreadedBy' => UserExtend::find()->andWhere(['user_id' => $userId])->asArray()->one()];
 }
Пример #3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search1($params)
 {
     fb($params);
     $query = Diary::find()->select(Diary::tableName() . '.*')->addSelect('b.content as content');
     $query->leftJoin(['b' => DiaryContent::tableName()], 'b.diary_id = ' . Diary::tableName() . '.id', ['b.content' => 'content']);
     fb($query->createCommand()->sql);
     $defaultOrder = ['release_time' => SORT_DESC];
     if (!empty($params['orderField'])) {
         $defaultOrder = [$params['orderField'] => $params['orderDirection'] == 'asc' ? SORT_ASC : SORT_DESC];
     }
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 20], 'sort' => ['defaultOrder' => $defaultOrder]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'release_time' => $this->release_time, 'recommend' => $this->recommend, 'like' => $this->like, 'created_by' => $this->created_by, 'created_at' => $this->created_at, 'updated_by' => $this->updated_by, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'author', $this->author])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'label', $this->label])->andFilterWhere(['like', 'profile', $this->profile])->andFilterWhere(['like', 'source', $this->source])->andFilterWhere(['like', 'diary_type', $this->diary_type])->andFilterWhere(['like', 'privacy', $this->privacy])->andFilterWhere(['like', 'can_reply', $this->can_reply]);
     fb($dataProvider->getModels());
     return $dataProvider;
 }
Пример #4
0
 /**
  * Finds the Diary model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Diary the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Diary::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Пример #5
0
 public function getUserLable($userId)
 {
     // TODO: Implement getUserLable() method.
     $diaryLabel = Diary::find()->select('label')->andWhere(['created_by' => $userId])->all();
     return $diaryLabel;
 }
Пример #6
0
 public function getUserResponse($userId)
 {
     $Query = (new Query())->select('b.comment_content,b.created_at')->addSelect('c.username')->addSelect('c.realname')->addSelect('d.avatar')->from(Diary::tableName() . ' as a')->leftJoin(['b' => DiaryComment::tableName()], 'b.diary_id = a.id')->leftJoin(['c' => User::tableName()], 'b.user_id = c.id')->leftJoin(['d' => UserExtend::tableName()], 'd.user_id = c.id')->where('1=1')->andFilterWhere(['a.created_by' => $userId])->andFilterWhere(['b.comment_id' => 0])->andFilterWhere(['b.comment_type' => 0])->orderBy(['b.created_at' => SORT_DESC])->limit(10);
     $result = $Query->createCommand()->queryAll();
     return $result;
 }