Example #1
0
 public function actionRss()
 {
     Yii::$app->response->format = \yii\web\Response::FORMAT_RAW;
     $headers = Yii::$app->response->headers;
     $headers->add('Content-Type', 'text/xml');
     $models = Hashtag::find()->orderBy("id desc")->limit(1000)->all();
     return $this->renderPartial('rss', ['models' => $models]);
 }
Example #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Hashtag::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => new \yii\data\Sort(['attributes' => ['id' => 'id']])]);
     $query->orderBy("id desc");
     $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, 'active' => $this->active, 'created' => $this->created]);
     //        $query->andFilterWhere(['like', 'tag', $this->tag]);
     return $dataProvider;
 }
Example #3
0
 /**
  * @param Tweet $tweet
  * @param array $tweetHashtags
  *
  * @throws Exception
  */
 private function importHashtags(Tweet $tweet, array $tweetHashtags)
 {
     foreach ($tweetHashtags as $tweetHashtag) {
         $hashtagFromDb = Hashtag::findOne($tweetHashtag);
         if (empty($hashtagFromDb)) {
             $hashtag = Hashtag::createInstanceFromParam($tweetHashtag);
             if (!$hashtag->save()) {
                 throw new Exception('Ошибка записи в базу данных: Таблица hashtag');
             }
             $tweet->link('hashtagTexts', $hashtag);
         } else {
             /**
              * @var Hashtag $hashtagFromDb
              */
             $tweet->link('hashtagTexts', $hashtagFromDb);
         }
     }
 }
Example #4
0
 /**
  * Finds the Hashtag model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Hashtag the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Hashtag::find()->where("tag = :tag", [':tag' => $id])->one()) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException(Yii::t('app', 'The requested page does not exist.'));
     }
 }
 /**
  * @param $hashtagForSearch
  *
  * @return array
  */
 public function findTweetByHashtag($hashtagForSearch)
 {
     $hashtags = Hashtag::find()->byHashtag($hashtagForSearch)->tweetsViaJunctionTable()->all();
     return $this->composeTweets($hashtags);
 }
Example #6
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getHashtagTexts()
 {
     return $this->hasMany(Hashtag::className(), ['text' => 'hashtag_text'])->viaTable('tweet_hashtag', ['tweet_id' => 'id']);
 }