/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = News::find(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pagesize' => '10']]); $dataProvider->setSort(['attributes' => ['category_name' => ['asc' => ['category.name' => SORT_ASC], 'desc' => ['category.name' => SORT_DESC], 'label' => 'Category name']]]); $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; } //关联表的操作 if ($this->category_name) { $categoryArray = self::categoryIdToName(); $id = array_search($this->category_name, $categoryArray); if ($id) { $this->category_id = $id; } else { $this->category_id = false; } } if ($this->created_at) { $this->created_at = strtotime($this->created_at); } if ($this->updated_at) { $this->updated_at = strtotime($this->updated_at); } // grid filtering conditions $query->andFilterWhere(['id' => $this->id, 'category_id' => $this->category_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'content', $this->content]); return $dataProvider; }
public function up() { $videos = \common\models\News::find()->andWhere(['or', ['like', 'textPreview', '{youtube}'], ['like', 'text', '{youtube}']]); $videosCount = $videos->count(); echo " > total news with videos: {$videosCount}\r\n"; $i = 0; foreach ($videos->each() as $video) { $i++; echo " > news {$i} from {$videosCount}... "; $video->textPreview = preg_replace_callback('/{youtube}(.*){\\/youtube}/', function ($finded) { $match = preg_replace('/(\\s+|){(\\/|)youtube}(\\s+|)/', '', strip_tags($finded[0])); $parts = explode('|', $match); return \yii\helpers\Html::tag('iframe', '', ['style' => (array_key_exists(1, $parts) ? "width: {$parts['1']}px;" : '') . (array_key_exists(2, $parts) ? "height: {$parts['2']}px;" : ''), 'src' => "//www.youtube.com/embed/{$parts['0']}", 'frameborder' => 0, 'allowfullscreen' => true]); }, $video->textPreview); $video->text = preg_replace_callback('/{youtube}(.*){\\/youtube}/', function ($finded) { $match = preg_replace('/(\\s+|){(\\/|)youtube}(\\s+|)/', '', strip_tags($finded[0])); $parts = explode('|', $match); return \yii\helpers\Html::tag('iframe', '', ['style' => (array_key_exists(1, $parts) ? "width: {$parts['1']}px;" : '') . (array_key_exists(2, $parts) ? "height: {$parts['2']}px;" : ''), 'src' => "//www.youtube.com/embed/{$parts['0']}", 'frameborder' => 0, 'allowfullscreen' => true]); }, $video->text); if ($video->save(false)) { echo "saved!"; } echo "\r\n"; } }
public function actionIndex($slug) { $this->layout = 'category'; $query = News::find(); $category = Categories::findOne(['slug' => $slug]); if (!$category) { $this->redirect("/"); } if ('all' != $slug) { $catArr = []; $catArr[] = $category->id; if ($subcatList = $category->child) { foreach ($subcatList as $subcat) { $catArr[] = $subcat->id; } } $query->join('INNER JOIN', NewsHasCategory::tableName(), NewsHasCategory::tableName() . ".news_id = " . News::tableName() . ".id"); $query->where([NewsHasCategory::tableName() . '.category_id' => $catArr]); } $query->orderBy(['id' => SORT_DESC]); $provider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 26]]); $breadCrumbs = []; $breadCrumbs[] = ['label' => 'Главная', 'url' => '/']; $breadCrumbs[] = ['label' => 'Категории', 'url' => '/category/all']; $breadCrumbs[] = ['label' => isset($category) ? $category->name : "Все новости"]; Yii::$app->view->title = isset($category) ? $category->name : "Все новости"; Yii::$app->view->registerMetaTag(['name' => 'keywords', 'content' => (isset($category) ? $category->name : "Все новости") . ' новости, свежие новости, новости украины, новости сегодня, агрегатор новостей']); Yii::$app->view->registerMetaTag(['name' => 'description', 'content' => 'Свежие новости со всех Украинских сайтов в одном сайте. Агрегатор новостей'], 'description'); Yii::$app->view->registerMetaTag(['name' => 'og:title', 'content' => Yii::$app->view->title], 'og:title'); return $this->render('index', ['provider' => $provider, 'slug' => $slug, 'category' => isset($category) ? $category->name : "Все новости", 'breadcrumbs' => $breadCrumbs]); }
public function actionIndex() { $query = News::find()->where('approved != 0'); $pagination = new Pagination(['defaultPageSize' => 4, 'totalCount' => $query->count()]); $news = $query->orderBy('updated_at DESC')->offset($pagination->offset)->limit($pagination->limit)->all(); return $this->render('index', ['news' => $news, 'pagination' => $pagination]); }
/** * view detail of news * @param int $id */ public function actionView($id) { $model = News::find()->where(['id' => $id])->one(); $model->view_count = $model->view_count + 1; $model->save(); return $this->render('view', array('model' => $model)); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = News::find()->innerJoinWith('category'); // add conditions that should always apply here $dataProvider = new ActiveDataProvider(['query' => $query]); $dataProvider->setSort(['attributes' => ['id', 'title', 'description', 'content', 'created_at', 'updated_at', 'categoryName' => ['asc' => ['wy_category.name' => SORT_ASC], 'desc' => ['wy_category.name' => SORT_DESC]]]]); $this->load($params); //var_dump($this);die; 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; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id, 'category_id' => $this->category_id]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'wy_category.name', $this->categoryName]); //datePicker if ($this->updated_at != '') { $query->andFilterWhere(['between', 'updated_at', strtotime($this->updated_at), strtotime($this->updated_at) + 24 * 3600]); } if ($this->created_at != '') { $query->andFilterWhere(['between', 'created_at', strtotime($this->created_at), strtotime($this->created_at) + 24 * 3600]); } return $dataProvider; }
public function actionList($id) { $where = ['status' => 1, 'category_id' => $id]; $query = \common\models\News::find()->where($where); $dataProvider = new \yii\data\ActiveDataProvider(['query' => $query, 'pagination' => ['defaultPageSize' => 2], 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]); return $this->render('list', ['id' => $id, 'dataProvider' => $dataProvider]); }
/** * Displays a single News model. * @param integer $id * @return mixed */ public function actionView($slug) { // $model = $this->findModel($id); $model = News::find()->where(['alias' => $slug])->one(); $model->views = $model->views + 1; $model->save(); return $this->render('view', ['model' => $model]); }
public function actionIndex() { $dataProvider = []; $dataProvider['guest-book'] = new ActiveDataProvider(['query' => GuestBook::find()->where(['status' => 'on'])->orderBy('date DESC')->limit(10), 'pagination' => false]); $dataProvider['club-questions'] = new ActiveDataProvider(['query' => ClubQuestions::find()->where(['status' => 'on'])->orderBy('date DESC')->limit(10), 'pagination' => false]); $dataProvider['news'] = new ActiveDataProvider(['query' => News::find()->orderBy('date_create DESC, date DESC')->limit(5), 'pagination' => false]); return $this->render('index', ['dataProvider' => $dataProvider]); }
public function run() { // if(!empty($this->zone)) { $output = News::find()->all(); // $output = News::find()->where(['zone' => $this->zone, 'status' => 'on'])->orderBy('sort')->all(); return $this->render($this->template, ['news' => $output]); // } }
protected function findModel($id) { if (($model = News::find()->where(['and', 'id=' . $id, 'status>=' . Status::STATUS_ACTIVE])->One()) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionGetNews() { $news = \common\models\News::find()->all(); //echo "<pre>"; print_r($news); exit; header('Content-type: application/json'); echo \yii\helpers\Json::encode($news); exit; }
public static function getNews($cid, $num) { $allCategory = Category::find()->asArray()->all(); $arrayCategoryIdName = \yii\helpers\ArrayHelper::map($allCategory, 'id', 'name'); $arrSubCat = Category::getArraySubCatalogId($cid, $allCategory); $where = ['and', ['category_id' => $arrSubCat], 'status>=' . Status::STATUS_ACTIVE]; $news = News::find()->where($where)->limit($num)->all(); return $news; }
public function _getTopNews() { $news = News::find()->orderBy('created_date DESC')->limit(5)->all(); $html = ''; foreach ($news as $new) { $html .= '<li><i class="fa fa-edit"></i><a href="' . Yii::$app->params['site_url'] . 'news/' . urlencode($new->title) . '-' . $new->id . '">' . $new->title . '</a></li>'; } return $html; }
public function actionView() { if (User::isAdmin(Yii::$app->user->identity->username)) { $link = new ActiveDataProvider(['query' => News::find(), 'pagination' => ['pageSize' => 50]]); return $this->render('view', compact('link')); } else { throw new ForbiddenHttpException('У вас нет прав администратора!', 404); } }
/** * 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, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'cnt' => $this->cnt]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'thumb', $this->thumb])->andFilterWhere(['like', 'status', $this->status]); return $dataProvider; }
public function actionIndex($key = '') { if ($key == '') { header("Content-type:text/html;charset=utf-8"); echo "<script>alert('请输入关键词!');window.history.go(-1);</script>"; die; } $where = ['and', ['like', 'title', $key], 'status>=' . Status::STATUS_ACTIVE]; $query = News::find()->where($where); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['defaultPageSize' => Yii::$app->params['defaultPageSizeProduct']], 'sort' => ['defaultOrder' => ['created_at' => SORT_DESC]]]); return $this->render('index', ['models' => $dataProvider->getModels(), 'pagination' => $dataProvider->pagination]); }
/** * 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_time' => $this->date_time, 'publish_status' => $this->publish_status, 'author_id' => $this->author_id, 'like' => $this->like, 'visited' => $this->visited]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'content', $this->content]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = News::find()->orderBy('id DESC'); $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, 'category_id' => $this->category_id, 'views' => $this->views, 'comments' => $this->comments, 'date' => $this->date]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'alias', $this->alias])->andFilterWhere(['like', 'snippet', $this->snippet])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'status_id', $this->status_id]); return $dataProvider; }
/** * 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, 'pagination' => ['pageSize' => 10]]); $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, 'updated_at' => $this->updated_at, 'created_at' => $this->created_at, 'sec' => $this->sec]); $query->andFilterWhere(['like', 'sid', $this->sid])->andFilterWhere(['like', 'header', $this->header])->andFilterWhere(['like', 'text', $this->text]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = News::find()->orderBy(['be_top' => SORT_DESC, 'public_at' => SORT_DESC]); $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, 'be_top' => $this->be_top, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'public_at' => $this->public_at]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'content', $this->content])->orderBy(['be_top' => SORT_DESC, 'public_at' => SORT_DESC]); return $dataProvider; }
/** * 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 any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'category_id' => $this->category_id, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'thumb', $this->thumb])->andFilterWhere(['like', 'keyword', $this->keyword])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'intro', $this->intro])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'author', $this->author]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = News::find()->joinWith('user101', 'categ'); $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, 'type' => $this->type, 'approved' => $this->approved, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'author' => $this->author]); $query->andFilterWhere(['like', 'short_description', $this->short_description])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'slug', $this->slug]); return $dataProvider; }
/** * 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, 'datetime' => $this->datetime]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'text', $this->text]); return $dataProvider; }
/** * 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 any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'updated_date' => $this->updated_date, 'created_date' => $this->created_date, 'view_count' => $this->view_count, 'featured' => $this->featured]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'meta_keyword', $this->meta_keyword])->andFilterWhere(['like', 'meta_description', $this->meta_description])->andFilterWhere(['like', 'meta_title', $this->meta_title]); $query->orderBy('created_date DESC'); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = News::find()->orderBy('date DESC'); // add conditions that should always apply here $dataProvider = new ActiveDataProvider(['query' => $query]); $dataProvider->pagination->pageSize = 10; $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; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'date' => $this->date]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'text', $this->text]); return $dataProvider; }
/** * 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 any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'status' => $this->status]); $query->andFilterWhere(['like', 'title', $this->title]); $query->andFilterWhere(['like', 'intro', $this->intro]); $query->andFilterWhere(['like', 'body', $this->body]); $query->andFilterWhere(['like', 'author', $this->author]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = News::find()->with('category'); // add conditions that should always apply here $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); //var_dump($this);die; 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; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id, 'category_id' => $this->category_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'content', $this->content]); return $dataProvider; }
public function actionView($sid, $section) { $news = News::find()->select('*')->where(['sid' => $sid])->one(); $sectionM = SecNews::find()->select(['id', 'sid', 'header'])->where(['sid' => $section])->asArray()->one(); $page = Page::find()->where(['sid' => Yii::$app->controller->id])->select(['id', 'pid', 'sid', 'header'])->one(); $pages = Page::find()->select(['id', 'pid', 'sid', 'header'])->asArray()->indexBy('id')->all(); $mode = $pages[$page->id]; $branch[] = $mode; while (!is_null($mode['pid'])) { $mode = $pages[$mode['pid']]; $branch[] = $mode; } krsort($branch); $branch[] = $sectionM; $branch[] = ['header' => $news->header]; return $this->render('view', ['news' => $news, 'branch' => $branch]); }
public function actionIndex() { Yii::$app->view->title = 'Свежие новости'; Yii::$app->view->registerMetaTag(['name' => 'keywords', 'content' => 'новости, свежие новости, новости украины, новости сегодня, агрегатор новостей']); Yii::$app->view->registerMetaTag(['name' => 'description', 'content' => 'Свежие новости со всех Украинских сайтов в одном сайте. Агрегатор новостей'], 'description'); Yii::$app->view->registerMetaTag(['name' => 'og:title', 'content' => Yii::$app->view->title], 'og:title'); $this->layout = 'front'; $notInIds = []; $sliders = News::find()->where("created_at BETWEEN NOW() - INTERVAL '6 hour' AND NOW() AND thumb IS NOT NULL")->orderBy(["cnt" => SORT_DESC])->limit(8)->all(); foreach ($sliders as $item) { $notInIds[] = $item->id; } $topNews = News::find()->where("created_at BETWEEN NOW() - INTERVAL '6 hour' AND NOW() AND thumb IS NOT NULL AND id NOT IN(" . implode(",", $notInIds) . ")")->orderBy(["cnt" => SORT_DESC])->limit(4)->all(); foreach ($topNews as $item) { $notInIds[] = $item->id; } $hotNews = News::find()->where("thumb IS NOT NULL AND id NOT IN(" . implode(",", $notInIds) . ")")->orderBy(["id" => SORT_DESC])->limit(4)->all(); foreach ($hotNews as $item) { $notInIds[] = $item->id; } $category = Categories::findOne(['slug' => 'ato']); $atoNews = News::find()->joinWith(['newsHasCategories'])->where(NewsHasCategory::tableName() . ".category_id = {$category->id} AND " . News::tableName() . ".id NOT IN(" . implode(",", $notInIds) . ")")->orderBy(["id" => SORT_DESC])->limit(7)->all(); foreach ($atoNews as $item) { $notInIds[] = $item->id; } $category = Categories::findOne(['slug' => 'economic']); $ecoNews = News::find()->joinWith(['newsHasCategories'])->where(NewsHasCategory::tableName() . ".category_id = {$category->id} AND " . News::tableName() . ".id NOT IN(" . implode(",", $notInIds) . ")")->orderBy(["id" => SORT_DESC])->limit(7)->all(); foreach ($ecoNews as $item) { $notInIds[] = $item->id; } $category = Categories::findOne(['slug' => 'sport']); $sportNews = News::find()->joinWith(['newsHasCategories'])->where(NewsHasCategory::tableName() . ".category_id = {$category->id} AND " . News::tableName() . ".id NOT IN(" . implode(",", $notInIds) . ")")->orderBy(["id" => SORT_DESC])->limit(3)->all(); foreach ($sportNews as $item) { $notInIds[] = $item->id; } $category = Categories::findOne(['slug' => 'politics']); $politicsNews = News::find()->joinWith(['newsHasCategories'])->where(NewsHasCategory::tableName() . ".category_id = {$category->id} AND " . News::tableName() . ".id NOT IN(" . implode(",", $notInIds) . ")")->orderBy(["id" => SORT_DESC])->limit(3)->all(); return $this->render('index', ['topNews' => $topNews, 'hotNews' => $hotNews, 'atoNews' => $atoNews, 'ecoNews' => $ecoNews, 'sportNews' => $sportNews, 'politicsNews' => $politicsNews, 'sliders' => $sliders]); }