Example #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = CategoryWords::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'category_id' => $this->category_id]);
     $query->andFilterWhere(['like', 'word', $this->word]);
     return $dataProvider;
 }
 /**
  * Finds the CategoryWords model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  *
  * @param integer $id
  *
  * @return CategoryWords the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = CategoryWords::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 protected function detectCategories($news_id, $pn_id)
 {
     $pn = PendingNews::findOne($pn_id);
     $content = mb_strtolower($pn->search_content, 'utf-8');
     if ($pn->additonal_data) {
         $data = json_decode($pn->additonal_data);
         if (isset($data->category_id)) {
             if (!($nhc = NewsHasCategory::findOne(['category_id' => $data->category_id, 'news_id' => $news_id]))) {
                 $nhc = new NewsHasCategory();
                 $nhc->news_id = $news_id;
                 $nhc->category_id = $data->category_id;
                 $nhc->save();
                 return true;
             }
         }
         if ($data->category) {
             $content = mb_strtolower($data->category, 'utf-8');
         }
     }
     $categoryWords = CategoryWords::find()->all();
     foreach ($categoryWords as $cw) {
         if (mb_strpos($content, mb_strtolower($cw->word, 'utf-8'), 0, 'utf-8') !== false) {
             if (!($nhc = NewsHasCategory::findOne(['category_id' => $cw->category_id, 'news_id' => $news_id]))) {
                 $nhc = new NewsHasCategory();
                 $nhc->news_id = $news_id;
                 $nhc->category_id = $cw->category_id;
                 $nhc->save();
             }
         }
     }
 }