예제 #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $user = Yii::$app->getModule("user")->model("User");
     $query = Album::find();
     $postTable = Album::tableName();
     // set up query with relation to `user.username`
     $userTable = $user::tableName();
     $query->joinWith(['user' => function ($query) use($userTable) {
         $query->from(['user' => $userTable]);
     }]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10], 'sort' => ['defaultOrder' => ['created_at' => SORT_DESC]]]);
     // enable sorting for the related columns
     $addSortAttributes = ["user.username"];
     foreach ($addSortAttributes as $addSortAttribute) {
         $dataProvider->sort->attributes[$addSortAttribute] = ['asc' => [$addSortAttribute => SORT_ASC], 'desc' => [$addSortAttribute => SORT_DESC]];
     }
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(["{$postTable}.id" => $this->id, 'user_id' => $this->user_id, 'is_public' => $this->is_public]);
     if ($this->created_at) {
         $createdTime = strtotime($this->created_at);
         $startDay = date("Y-m-d 00:00:00", $createdTime);
         $endDay = date("Y-m-d 00:00:00", $createdTime + 60 * 60 * 24);
         $query->andFilterWhere(['between', 'created_at', $startDay, $endDay]);
     }
     if ($this->updated_at) {
         $updatedTime = strtotime($this->updated_at);
         $startDay = date("Y-m-d 00:00:00", $updatedTime);
         $endDay = date("Y-m-d 00:00:00", $updatedTime + 60 * 60 * 24);
         $query->andFilterWhere(['between', 'updated_at', $startDay, $endDay]);
     }
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'cached_tag_list', $this->cached_tag_list])->andFilterWhere(['like', 'user.username', $this->getAttribute('user.username')]);
     return $dataProvider;
 }
예제 #2
0
 protected function findModel($id)
 {
     if (($model = Album::find()->where(['and', 'id=' . $id])->One()) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
예제 #3
0
 public function actionIndex()
 {
     //页面左侧分类
     $bigCate = Category::find()->where(['is_nav' => \common\models\YesNo::YES])->orderBy(['sort_order' => SORT_ASC])->all();
     //首页轮播图
     $slider = Slider::find()->where(['place' => 0])->orderBy(['ord' => SORT_ASC])->all();
     //师生风采
     $teachers = \common\models\Album::find()->orderBy(['id' => SORT_DESC])->limit(5)->all();
     //友情链接
     $friendLink = \common\models\Friendlink::find()->where(['isshow' => \common\models\YesNo::YES])->orderBy(['ord' => SORT_ASC])->all();
     return $this->render('index', ['bigCate' => $bigCate, 'slider' => $slider, 'teachers' => $teachers, 'friendlink' => $friendLink]);
 }
예제 #4
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Album::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'views' => $this->views, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'intro', $this->intro])->andFilterWhere(['like', 'author', $this->author]);
     return $dataProvider;
 }
예제 #5
0
 /**
  * Get block with photo reviews
  * @return array Data
  */
 public static function getPhotoNews()
 {
     // Photo review
     $photoReviewNews = Album::find()->where(['is_public' => 1])->orderBy(['created_at' => SORT_DESC])->limit(3)->all();
     if (count($photoReviewNews) == 0) {
         return false;
     }
     $block = ['view' => '@frontend/views/blocks/review_news_block', 'data' => compact('photoReviewNews')];
     return $block;
 }
예제 #6
0
 /**
  * Url: /album/{$album_id}-{$slug}/{$photo_id}
  * @param int $album_id Album id
  * @param string $slug Album slug
  * @param $photo_id
  * @return mixed Content
  * @throws NotFoundHttpException
  */
 public function actionPhoto($album_id, $slug, $photo_id)
 {
     $album = Album::find()->where(['id' => $album_id, 'is_public' => 1])->one();
     if (!isset($album)) {
         throw new NotFoundHttpException('Страница не найдена.');
     }
     $photo = Asset::find()->where(['id' => $photo_id, 'thumbnail' => Asset::THUMBNAIL_CONTENT])->one();
     if (!isset($photo)) {
         $photo = Asset::find()->where(['id' => $photo_id])->one();
     }
     if (!isset($photo)) {
         throw new NotFoundHttpException('Страница не найдена.');
     }
     return $this->render('@frontend/views/site/index', ['templateType' => 'col2', 'title' => 'Dynamomania.com | Фотоальбом: ' . $album->title, 'columnFirst' => ['content' => ['view' => '@frontend/views/site/photo_single', 'data' => compact('album', 'photo')], 'comments' => Comment::getCommentsBlock($photo->id, Comment::COMMENTABLE_PHOTO)], 'columnSecond' => ['short_news' => SiteBlock::getshortNews(50)]]);
 }