コード例 #1
0
ファイル: SiteController.php プロジェクト: comaw/hashtag
 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]);
 }
コード例 #2
0
ファイル: HashtagSearch.php プロジェクト: comaw/hashtag
 /**
  * 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;
 }
コード例 #3
0
ファイル: TweetImporter.php プロジェクト: dshashkov/YiiTask1
 /**
  * @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);
         }
     }
 }
コード例 #4
0
ファイル: HashtagController.php プロジェクト: comaw/hashtag
 /**
  * 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.'));
     }
 }
コード例 #5
0
 /**
  * @param $hashtagForSearch
  *
  * @return array
  */
 public function findTweetByHashtag($hashtagForSearch)
 {
     $hashtags = Hashtag::find()->byHashtag($hashtagForSearch)->tweetsViaJunctionTable()->all();
     return $this->composeTweets($hashtags);
 }
コード例 #6
0
ファイル: Tweet.php プロジェクト: dshashkov/YiiTask1
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getHashtagTexts()
 {
     return $this->hasMany(Hashtag::className(), ['text' => 'hashtag_text'])->viaTable('tweet_hashtag', ['tweet_id' => 'id']);
 }