Exemplo n.º 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]);
     $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]);
     $query->andFilterWhere(['like', 'domain', $this->domain])->andFilterWhere(['like', 'dir', $this->dir]);
     return $dataProvider;
 }
Exemplo n.º 2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Sources::find();
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $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;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id, 'active' => $this->active]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'ownerId', $this->ownerId])->andFilterWhere(['like', 'domain', $this->domain]);
     return $dataProvider;
 }
Exemplo n.º 3
0
 /**
  * @inheritdoc
  * @return Result parsing group.
  */
 public static function parseAllSources()
 {
     $query = Sources::find();
     $sources = $query->active()->all();
     $i = 0;
     foreach ($sources as $source) {
         if ($source->ownerId) {
             $param['ownerId'] = $source->ownerId;
         } else {
             $param['ownerId'] = NULL;
         }
         $results = Yii::$app->vkApi->createRequest()->setUrl('wall.get')->setData(['owner_id' => $param['ownerId'], 'domain' => $source->domain, 'offset' => $source->postOffset, 'count' => $source->postCount, 'filter' => 'owner'])->send();
         if ($results->isOk) {
             $responses = $results->data['response'];
             foreach ($responses as $response) {
                 if (is_array($response)) {
                     $post = new Posts();
                     $post->recordId = $response['id'];
                     $post->sources_id = $source->id;
                     $prepare_content = preg_replace("/([^&]#[a-zA-zа-яА-я0-9]*)/", "", stripcslashes($response['text']));
                     $prepare_content = preg_replace("/\\[(.+?)\\]/", "", $prepare_content);
                     $post->content = $prepare_content;
                     $title = mb_substr($post->content, 0, mb_stripos($post->content, "<br"));
                     if (!$title) {
                         $title = $post->content;
                     }
                     $post->title = $title ? $title : NULL;
                     $post->slug = Inflector::slug($post->title);
                     if ($response['post_type'] != 'post') {
                         break;
                     }
                     try {
                         if ($post->save()) {
                             foreach ($response['attachments'] as $attachment) {
                                 if ($attachment['type'] == 'photo') {
                                     $photo = new Photos();
                                     $photo->id_posts = $post->id;
                                     $photo->text = $attachment['photo']['text'];
                                     if (isset($attachment['photo']['src'])) {
                                         $photo->link = $attachment['photo']['src'];
                                     }
                                     if (isset($attachment['photo']['src_small'])) {
                                         $photo->link = $attachment['photo']['src_small'];
                                     }
                                     if (isset($attachment['photo']['src_big'])) {
                                         $photo->link = $attachment['photo']['src_big'];
                                     }
                                     if (isset($attachment['photo']['src_xbig'])) {
                                         $photo->link = $attachment['photo']['src_xbig'];
                                     }
                                     if (isset($attachment['photo']['src_xxbig'])) {
                                         $photo->link = $attachment['photo']['src_xxbig'];
                                     }
                                     if (isset($attachment['photo']['src_xxxbig'])) {
                                         $photo->link = $attachment['photo']['src_xxxbig'];
                                     }
                                     $photo->save();
                                 } else {
                                     $post->delete();
                                     $i--;
                                 }
                             }
                             $i++;
                         }
                         $post->slug = $post->id . "-" . $post->slug;
                         $post->save();
                     } catch (yii\db\IntegrityException $e) {
                         //nothing
                     }
                 }
             }
         }
         sleep(5);
     }
     if ($i < 0) {
         $i = 0;
     }
     return Yii::t("app", '{n, plural, =0{Not added new records} =1{# record added} few{# records added} other{# added records}}', ['n' => $i]);
 }
Exemplo n.º 4
0
 private function getDocDir()
 {
     return Sources::getCurrentSource();
 }
Exemplo n.º 5
0
?>
</h1>
    <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>

    <div class="alert alert-warning">
        Каталог с документацией берется в соответствии с доменом где открыт <?php 
echo Yii::$app->params['name'];
?>
.
        <br/>
        Если совпадение не найдено, берется
        <strong>
            <?php 
echo \app\models\Sources::getCurrentSource();
?>
        </strong>
        <br/>
        Пример домена: <strong>doc.example.com</strong>
    </div>

    <p>
        <?php 
echo Html::a('Create Sources', ['create'], ['class' => 'btn btn-success']);
?>
    </p>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => ['domain', 'dir:ntext', ['class' => 'yii\\grid\\ActionColumn']]]);
?>
Exemplo n.º 6
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getSources()
 {
     return $this->hasMany(Sources::className(), ['user_id' => 'id']);
 }
Exemplo n.º 7
0
 /**
  * Finds the Groups 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.');
     }
 }
Exemplo n.º 8
0
 /**
  * This command get content from active sources.
  *
  */
 public function actionParseAllSources()
 {
     echo Sources::parseAllSources();
 }
Exemplo n.º 9
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getSource()
 {
     return $this->hasOne(Sources::className(), ['id' => 'source_id']);
 }