Пример #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Sources::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if ($this->load($params) && !$this->validate()) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'active' => $this->active, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'label', $this->label])->andFilterWhere(['like', 'url', $this->url])->andFilterWhere(['like', 'category_pattern', $this->category_pattern])->andFilterWhere(['like', 'news_pattern', $this->news_pattern])->andFilterWhere(['like', 'thumb_pattern', $this->thumb_pattern]);
     return $dataProvider;
 }
Пример #2
0
 public function actionTest()
 {
     $data = [];
     if (Yii::$app->request->post()) {
         $data = Yii::$app->request->post();
         if (isset($data['url'])) {
             $parser = new NewsParserComponent(ParserQueue::findOne(1));
             $data['parserResult'] = $parser->parse(PageLoaderComponent::load($data['url']), $data['url'], Sources::findOne($data['Source']));
         }
     }
     return $this->render('test', $data);
 }
Пример #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getSource()
 {
     return $this->hasOne(Sources::className(), ['id' => 'source_id']);
 }
Пример #4
0
 public function getSource()
 {
     return $this->hasOne(Sources::className(), ["id" => "source_id"]);
 }
Пример #5
0
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model common\models\RssSources */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="rss-sources-form">

    <?php 
$form = ActiveForm::begin();
?>

    <?php 
echo $form->field($model, 'source_id')->dropDownList(\yii\helpers\ArrayHelper::map(\common\models\Sources::find()->orderBy('label')->asArray()->all(), 'id', 'label'), ['value' => $model->source_id]);
?>

    <?php 
echo $form->field($model, 'url')->textInput(['maxlength' => 255]);
?>

    <?php 
echo $form->field($model, 'active')->checkbox();
?>

    <?php 
echo $form->field($model, 'is_full')->checkbox();
?>

    <?php 
Пример #6
0
<h1>Parser test</h1>

<?php 
echo \yii\helpers\Html::beginForm();
?>
<p>
    <?php 
echo \yii\helpers\Html::dropDownList("Source", null, \yii\helpers\ArrayHelper::map(\common\models\Sources::find()->asArray()->all(), 'id', 'label'));
?>
</p>
<p>
    <?php 
echo \yii\helpers\Html::input("text", "url", isset($url) ? $url : "");
?>
</p>
<p>
    <?php 
echo \yii\helpers\Html::button("Parse", ["type" => "submit"]);
?>
</p>
<?php 
echo \yii\helpers\Html::endForm();
?>

<?php 
if (isset($parserResult)) {
    ?>
    <h1>Title:</h1>
    <p><?php 
    echo isset($parserResult['title']) ? $parserResult['title'] : "";
    ?>
Пример #7
0
 /**
  * Finds the Sources model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  *
  * @param integer $id
  *
  * @return Sources the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Sources::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }