public function up() { $this->addColumn('news', 'unpublishDate', Schema::TYPE_DATETIME); $this->addColumn('news', 'checkedDate', Schema::TYPE_DATETIME); $this->addColumn('news', 'checked', Schema::TYPE_INTEGER . ' UNSIGNED NOT NULL DEFAULT 0'); $this->addColumn('news', 'creator', Schema::TYPE_INTEGER . ' UNSIGNED NOT NULL DEFAULT 0'); $this->addColumn('news', 'textPreview', $this->text()); $this->addColumn('news', 'publishTimestamp', $this->integer()->unsigned()->notNull()->defaultValue(0)); $this->createIndex('publishTimestamp', 'news', 'publishTimestamp'); $this->execute("UPDATE `news` SET `publishTimestamp` = UNIX_TIMESTAMP(STR_TO_DATE(`publishDate`, '%Y-%m-%d %H:%i:%s'))"); $this->alterColumn('news', 'author', Schema::TYPE_STRING); $newsList = new \yii\db\Query(); $newsList = $newsList->from(\Yii::$app->params['oldDb'] . '.joom_content'); $newsListCount = $newsList->count(); echo " > migrating news... Almost have {$newsListCount} news...\r\n"; echo " > prepare news...\r\n"; $i = 0; foreach ($newsList->each(25) as $news) { $i++; echo " > news {$i} from {$newsListCount}... \r\n"; $newNews = new News(['id' => $news['id']]); $newNews->creator = $news['created_by']; $newNews->author = $news['created_by_alias']; $newNews->title = $news['title']; $newNews->textPreview = $news['introtext']; $newNews->text = $news['fulltext']; $newNews->link = $news['alias']; $newNews->published = $news['access'] == '1' ? 1 : 0; $newNews->deleted = $news['state'] == '-2' ? 1 : 0; $newNews->publishDate = $news['publish_up']; $newNews->favorite = $news['featured']; $newNews->hits = $news['hits']; $newNews->meta_description = $news['metadesc']; $newNews->meta_keywords = $news['metakey']; $newNews->category = $news['catid']; $newNews->unpublishDate = $news['publish_down']; $newNews->checkedDate = $news['checked_out_time']; $newNews->checked = $news['checked_out']; $newNews->image = $newNews->getImagePreview(); $newNews->publishTimestamp = $news['publish_up'] ? strtotime($news['publish_up']) : 0; $newNews->publishTimestamp = $newNews->publishTimestamp < 0 ? 0 : $newNews->publishTimestamp; $prepared[] = $newNews->attributes; if (count($prepared) >= 50 || $newsListCount - $i == 0) { $this->batchInsert(News::tableName(), array_keys($prepared[0]), $prepared); $prepared = []; } } }
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"; } }
/** * 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 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]); }
/** * 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 actionSave() { if (User::isAdmin(Yii::$app->user->identity->username)) { $model = new News(); if (Yii::$app->request->isPost && $model->load(Yii::$app->request->post())) { if ($model->save()) { return $this->redirect('/news/view'); } else { throw new ForbiddenHttpException('Ошибка добавления новости!', 404); } } return $this->render('save', compact('model')); } else { throw new ForbiddenHttpException('У вас нет прав администратора!', 404); } }
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]); // } }
/** * Finds the News model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return News the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = News::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
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; }
/** * 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(); $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()->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()->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()->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(); $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()->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; }
/** * 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; }
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 beforeSave($insert) { if (empty($this->author)) { $this->author = \Yii::$app->user->identity->username; } if ($this->isNewRecord) { $this->creator = \Yii::$app->user->id; } if ($this->isAttributeChanged('published')) { if ($this->published == 1 && empty($this->publishDate)) { $this->publishDate = time(); } else { $this->unpublishDate = time(); } } $this->updated = time(); $this->updateIndexes(); return parent::beforeSave($insert); // TODO: Change the autogenerated stub }
public static function processMessage($msg) { $params = json_decode($msg->body); print_r($params); try { $news = News::findOne($params->news_id); $text = mb_substr($news->title, 0, 140 - strlen(Yii::$app->params['domainName'] . $news->getLink()), 'utf-8'); $text .= " " . Yii::$app->params['domainName'] . $news->getLink(); Codebird::setConsumerKey(Yii::$app->params['twitter']['consumer_key'], Yii::$app->params['twitter']['consumer_secret']); $cb = Codebird::getInstance(); $cb->setToken(Yii::$app->params['twitter']['access_token'], Yii::$app->params['twitter']['access_token_secret']); $params = array('status' => $text, 'media[]' => $params->src); $reply = $cb->statuses_updateWithMedia($params); } catch (Exception $e) { echo $e->getMessage(); } $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']); }