Beispiel #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Npn::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if ($this->load($params) && !$this->validate()) {
         return $dataProvider;
     }
     $query->andFilterWhere(['news_id' => $this->news_id, 'pending_news_id' => $this->pending_news_id]);
     return $dataProvider;
 }
Beispiel #2
0
 public function getNpn()
 {
     return $this->hasOne(Npn::className(), ['pending_news_id' => 'id']);
 }
Beispiel #3
0
 /**
  * Finds the Npn model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  *
  * @param integer $news_id
  * @param integer $pending_news_id
  *
  * @return Npn the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($news_id, $pending_news_id)
 {
     if (($model = Npn::findOne(['news_id' => $news_id, 'pending_news_id' => $pending_news_id])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 protected function linkNews($news_id, $pn_id)
 {
     try {
         $npn = new Npn();
         $npn->news_id = $news_id;
         $npn->pending_news_id = $pn_id;
         if ($npn->save()) {
             $news = News::findOne($news_id);
             $news->updateCounters(['cnt' => 1]);
             $this->detectCategories($news_id, $pn_id);
         }
     } catch (\Exception $e) {
         print_r($e->getMessage());
     }
 }
Beispiel #5
0
 public function getShort($length = 150)
 {
     $npn = Npn::find()->where(['news_id' => $this->id])->orderBy(['pending_news_id' => SORT_DESC])->limit(1)->one();
     if ($pn = PendingNews::findOne($npn->pending_news_id)) {
         return html_entity_decode(mb_substr($pn->search_content, 0, $length, 'utf-8'));
     }
 }