Ejemplo n.º 1
0
 /**
  * Displays homepage.
  *
  * @return mixed
  */
 public function actionIndex()
 {
     $query = News::find();
     $pagination = new Pagination(['defaultPageSize' => 4, 'totalCount' => $query->count()]);
     $news = $query->orderBy(['id' => SORT_DESC])->offset($pagination->offset)->limit($pagination->limit)->all();
     return $this->render('index', ['news' => $news, 'pagination' => $pagination]);
 }
Ejemplo n.º 2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params, $cat)
 {
     if (Yii::$app->user->isGuest) {
         $isAdmin = false;
     } else {
         if (Yii::$app->user->identity->role == 1) {
             $isAdmin = true;
         } else {
             $isAdmin = false;
         }
     }
     if ($isAdmin) {
         $query = News::find();
     } else {
         $query = News::find()->where(['cat' => $cat]);
     }
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $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(['news_id' => $this->news_id, 'create_time' => $this->create_time, 'update_time' => $this->update_time, 'cat' => $this->cat, 'clickcnt' => $this->clickcnt]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'content', $this->content]);
     return $dataProvider;
 }
Ejemplo n.º 3
0
 public function actionArticle()
 {
     $id = $_GET['id'];
     $article = News::find()->where(["id" => $id])->one();
     // echo $id;
     return $this->render('article', ['article' => $article]);
 }
Ejemplo n.º 4
0
 public function actionIndex()
 {
     //Записываем в переменную все новости из базы через модель
     $model = News::find()->all();
     //Передаем переменную представлению
     return $this->render('index', ['news' => $model]);
 }
Ejemplo n.º 5
0
 public function actionIndex()
 {
     $news = News::find()->orderBy('createTime desc')->limit(3)->all();
     //  var_dump($news);
     //echo $news[0]->title;
     return $this->render('index', ['news' => $news]);
 }
Ejemplo n.º 6
0
 public function run()
 {
     // query
     $news = News::find()->orderBy('date_news DESC')->limit(5)->all();
     // render view
     return $this->render('news', ['news' => $news]);
 }
Ejemplo n.º 7
0
 public function actionIndex($kinds = 'all')
 {
     $sort = new Sort(['attributes' => ['theme' => ['asc' => ['theme' => SORT_ASC], 'desc' => ['theme' => SORT_DESC], 'default' => SORT_ASC, 'label' => '主题'], 'author' => ['asc' => ['author' => SORT_ASC], 'desc' => ['author' => SORT_DESC], 'default' => SORT_DESC, 'label' => '作者'], 'reply' => ['asc' => ['reply' => SORT_ASC], 'desc' => ['reply' => SORT_DESC], 'default' => SORT_DESC, 'label' => '回复'], 'updated_at' => ['asc' => ['updated_at' => SORT_ASC], 'desc' => ['updated_at' => SORT_DESC], 'default' => SORT_DESC, 'label' => '最后更新'], 'plike' => ['asc' => ['plike' => SORT_ASC], 'desc' => ['plike' => SORT_DESC], 'default' => SORT_DESC, 'label' => '赞'], 'kinds' => ['asc' => ['kinds' => SORT_ASC], 'desc' => ['kinds' => SORT_DESC], 'default' => SORT_ASC, 'label' => '类别']], 'defaultOrder' => ['updated_at' => SORT_DESC]]);
     if ($kinds === 'all') {
         $query = Forum::find();
     } elseif ($kinds === 'tucao') {
         $query = Forum::find()->where(array('kinds' => 'tucao'));
     } elseif ($kinds === 'tactic') {
         $query = Forum::find()->where(array('kinds' => 'tactic'));
     } elseif ($kinds === 'rule') {
         $query = Forum::find()->where(array('kinds' => 'rule'));
     } elseif ($kinds === 'bug') {
         $query = Forum::find()->where(array('kinds' => 'bug'));
     } elseif ($kinds === 'team') {
         $query = Forum::find()->where(array('kinds' => 'team'));
     } elseif ($kinds === 'myposts') {
         //我发的帖子
         $query = Forum::find()->where(array('author' => Yii::$app->user->identity->username));
     } elseif ($kinds === 'myreplies') {
         //我回复的帖子
         $queryid = DetailForum::find()->select(['fatherindex'])->where(array('author' => Yii::$app->user->identity->username));
         $query = Forum::find()->where(array('id' => $queryid));
     } else {
         $query = Forum::find();
     }
     $pagination = new Pagination(['defaultPageSize' => 10, 'totalCount' => $query->count()]);
     $forums = $query->orderBy($sort->orders)->offset($pagination->offset)->limit($pagination->limit)->all();
     //用来置顶2个点赞量最高的
     $sort1 = new Sort(['attributes' => ['plike' => ['asc' => ['plike' => SORT_ASC], 'desc' => ['plike' => SORT_DESC], 'default' => SORT_DESC, 'label' => '赞']], 'defaultOrder' => ['plike' => SORT_DESC]]);
     $topquery = Forum::find()->orderBy($sort1->orders)->limit(2)->all();
     //用来置顶2个点赞量最高的
     $news = News::find()->orderBy('addedat')->all();
     return $this->render('index', ['new' => $news[0], 'forums' => $forums, 'pagination' => $pagination, 'sort' => $sort, 'topquery' => $topquery]);
 }
Ejemplo n.º 8
0
 public function actionGet_data()
 {
     //      var_dump($_POST);
     $count = News::find()->count();
     $connection = Yii::$app->db;
     $sql = "select * from news ";
     $condition = '';
     if ($_POST['searchPhrase'] != '') {
         $condition .= 'where title like ' . '"%' . $_POST['searchPhrase'] . '%" ';
     }
     if (isset($_POST['sort']['title'])) {
         $condition .= " order by title  {$_POST['sort']['title']} ";
     }
     $t = (intval($_POST['current']) - 1) * $_POST['rowCount'];
     $condition .= " limit {$t} , {$_POST["rowCount"]}";
     $sql .= $condition;
     # $criteria->limit = $_POST['rowCount'];
     # $criteria->offset= (intval($_POST['current']) -1)*$_POST['rowCount'];
     //  echo $sql;
     #$model = News::find()->all($criteria);
     //      var_dump($model);
     $model = $connection->createCommand($sql)->queryAll();
     $arr = array();
     foreach ($model as $o) {
         $json = array('id' => intval($o['id']), 'title' => $o['title']);
         array_push($arr, $json);
     }
     //var_dump( $arr);
     echo json_encode(array('rowCount' => $_POST['rowCount'], 'current' => $_POST['current'], 'rows' => $arr, 'total' => $count));
 }
Ejemplo n.º 9
0
 public function run()
 {
     $query = News::find()->orderBy(['created_at' => SORT_DESC]);
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count()]);
     $models = $query->offset($pages->offset)->limit($pages->limit)->all();
     return $this->render('news', ['models' => $models, 'pages' => $pages]);
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     $news = News::find($id);
     if ($news->status_id != 3) {
         return redirect('/');
     }
     return view('front.news.show', compact('news'));
 }
Ejemplo n.º 11
0
 public function actionIndex()
 {
     $season = Season::findBySql('SELECT * FROM season WHERE invisible = 0 AND (unit1 != "" OR unit2 != "" OR unit3 != "" OR unit4 != "")')->all();
     $news = News::find()->where(['type' => '1'])->orderBy('id DESC')->one();
     $event = News::find()->where(['type' => '2'])->orderBy('id DESC')->one();
     $msgs = Chatmain::find()->orderBy('id DESC')->limit(50)->all();
     return $this->render('index', ['season' => $season, 'news' => $news, 'event' => $event, 'msgs' => $msgs]);
 }
Ejemplo n.º 12
0
 public function actionNews($news_id)
 {
     $news = News::find()->where(['id' => $news_id, 'is_published' => 1])->asArray()->one();
     if ($news) {
         $news['categories'] = CategoryRelations::get_news_categories_names($news['id']);
         return $this->render('news', compact('news'));
     }
 }
Ejemplo n.º 13
0
 public function actionPage($view)
 {
     $page = Pages::findOne(['slug' => '/' . $view]);
     if ($page == null) {
         return $this->render('error');
     }
     $news = new ActiveDataProvider(['query' => News::find(), 'sort' => ['defaultOrder' => ['data_new' => SORT_DESC]], 'pagination' => ['pageSize' => 3, 'validatePage' => false]]);
     return $this->render('index', ['page' => $page, 'news' => $news]);
 }
Ejemplo n.º 14
0
 public static function getLatestNews()
 {
     $query = News::find()->orderBy('id desc');
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count()]);
     $pages->defaultPageSize = 12;
     $models = $query->offset($pages->offset)->limit($pages->limit)->all();
     return ['models' => $models, 'pages' => $pages];
 }
Ejemplo n.º 15
0
 public function actionAdmin($status = null)
 {
     $query = News::find()->orderBy('id DESC');
     if ($status !== null) {
         $query->andWhere(['status' => $status]);
     }
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]);
     return $this->render('admin', ['status' => $status, 'dataProvider' => $dataProvider]);
 }
Ejemplo n.º 16
0
 public function actionIndex()
 {
     $page = Pages::findOne(['slug' => Yii::$app->request->url]);
     $news = new ActiveDataProvider(['query' => News::find()]);
     if ($page == null) {
         return $this->render('error');
     }
     return $this->render('index', ['page' => $page, 'news' => $news]);
 }
Ejemplo n.º 17
0
 public function actionIndex()
 {
     $categories = Category::find()->where(['status' => News::STATUS_ACTIVE])->orderBy('caption')->all();
     $query = News::find()->joinWith('category')->where(['news.status' => News::STATUS_ACTIVE])->Andwhere(['category.status' => Category::STATUS_ACTIVE]);
     $count = $query->count();
     $pagination = new Pagination(['totalCount' => $count, 'defaultPageSize' => SiteController::DEFAULT_PAGE_SIZE]);
     $news = $query->offset($pagination->offset)->orderBy('date DESC')->limit($pagination->limit)->all();
     return $this->render('index', ['categories' => $categories, 'news' => $news, 'pagination' => $pagination]);
 }
Ejemplo n.º 18
0
 /**
  * Displays user profile
  * @param integer $id
  * @return mixed
  * @throws NotFoundHttpException
  */
 public function actionView($id)
 {
     $user = User::findOne($id);
     if (!$user) {
         throw new NotFoundHttpException("No such user.");
     }
     $dataProvider = new ActiveDataProvider(['query' => News::find()->where(['user_id' => $id])->orderBy('id DESC'), 'pagination' => ['pageSize' => 10]]);
     return $this->render('view', ['model' => $user, 'dataProvider' => $dataProvider]);
 }
Ejemplo n.º 19
0
 public function actionList()
 {
     $imgNews = News::getImgRecommendNewsByCategory(2, 5);
     $categoryId = Yii::$app->request->get('category_id');
     $query = News::find()->where(['category_id' => $categoryId]);
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count()]);
     $models = $query->offset($pages->offset)->limit($pages->limit)->all();
     $data = ['models' => $models, 'pages' => $pages, 'categoryId' => $categoryId, 'imgNews' => $imgNews];
     return $this->render('list', ['data' => $data]);
 }
Ejemplo n.º 20
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = News::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'image_id' => $this->image_id]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'text', $this->text])->andFilterWhere(['like', 'date', $this->date])->andFilterWhere(['like', 'lang', $this->lang]);
     return $dataProvider;
 }
Ejemplo n.º 21
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = News::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'published_at' => $this->published_at]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'image', $this->image])->andFilterWhere(['like', 'body', $this->body]);
     return $dataProvider;
 }
Ejemplo n.º 22
0
 /**
  * Search by request criteria.
  *
  * @param array|null Filter params.
  * @return ActiveDataProvider Data provider.
  */
 public function search($params)
 {
     $query = News::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['date_pub' => SORT_DESC]], 'pagination' => ['pageSize' => 50]]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['status' => $this->status, 'DATE(date_pub)' => $this->date_pub]);
     $query->andFilterWhere(['like', 'news.title', $this->title]);
     return $dataProvider;
 }
Ejemplo n.º 23
0
 public function getCount()
 {
     $query = News::find();
     if (Common::getRole() == User::MODER) {
         $query->where(['status' => News::MODER_NEWS, 'category_id' => $this->getCategoryId()]);
     } elseif (Common::getRole() == User::SMODER) {
         $query->where(['status' => News::SMODER_NEWS, 'category_id' => $this->getCategoryId()]);
     } elseif (Common::getRole() == User::ADMIN) {
         $query->where(['status' => News::ADMIN_NEWS]);
     }
     return count($query->all());
 }
Ejemplo n.º 24
0
 public function actionIndex()
 {
     $categoryModel = Category::find()->All();
     $projectModel = Project::find()->where(['show_in_index' => '1'])->limit(6)->all();
     $customerModel = Customer::find()->All();
     $applicationConfig = ApplicationConfig::find()->one();
     $newsModel = News::find()->where(['show_in_index' => '1'])->limit(2)->all();
     $galleryModel = Gallery::find()->orderBy(new Expression('rand()'))->limit(6)->all();
     $visitor = ApplicationConfig::findOne(1);
     $visitor->visitors_count = $visitor->visitors_count + 1;
     $visitor->save();
     return $this->render('index', ['categoryModel' => $categoryModel, 'projectModel' => $projectModel, 'customerModel' => $customerModel, 'applicationConfig' => $applicationConfig, 'newsModel' => $newsModel, 'galleryModel' => $galleryModel]);
 }
Ejemplo n.º 25
0
 public function actionIndex($id = 1, $ajax = false)
 {
     $comment = new Comments();
     $login = new login();
     $news = News::find()->where(['id_category' => $id])->orderBy(['id' => SORT_DESC]);
     $pagination = new Pagination(['defaultPageSize' => 10, 'totalCount' => $news->count()]);
     $news = $news->offset($pagination->offset)->limit($pagination->limit)->all();
     if ($ajax == true) {
         return $this->renderAjax('index', ['comment' => $comment, 'pagination' => $pagination, 'login' => $login, 'news' => $news]);
     } else {
         return $this->render('index', ['comment' => $comment, 'pagination' => $pagination, 'login' => $login, 'news' => $news]);
     }
 }
Ejemplo n.º 26
0
 public function actionShow()
 {
     if (isset($_GET['name'])) {
         $name = $_GET['name'];
         $lang = \Yii::$app->language;
         //echo $name . ' - ' .$lang;
         $model = News::find()->where(['name' => $name, 'lang' => $lang])->one();
         if ($model !== null) {
             //var_dump($model);
             return $this->render('show', ['model' => $model]);
         }
     }
     return $this->render('news_not_found');
 }
 public function actionIndex()
 {
     $query = News::find();
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => 4]);
     $models = $query->offset($pages->offset)->limit($pages->limit)->all();
     return $this->render('index', ['models' => $models, 'pages' => $pages]);
     /*$query = News::getAll();
             $pages = new Pagination(['totalCount' => count($query), 'pageSize' => 5,]);
     
     
             return $this->render('index', ['model' => $query,
                 'pages' => $pages,]);*/
 }
Ejemplo n.º 28
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = News::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $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, 'date' => $this->date, 'status' => $this->status, 'category_id' => $this->category_id]);
     $query->andFilterWhere(['like', 'headline', $this->headline])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'image', $this->image]);
     return $dataProvider;
 }
Ejemplo n.º 29
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = News::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $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, 'date' => $this->date]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'text', $this->text]);
     return $dataProvider;
 }
Ejemplo n.º 30
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = News::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $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(['news_id' => $this->news_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'excerpt', $this->excerpt])->andFilterWhere(['like', 'content', $this->content]);
     return $dataProvider;
 }