/**
  * Импорт торрентов
  *
  * @param \common\models\Categories $cat
  * @param                           $path
  */
 private function importTorrents(Categories $cat, $path)
 {
     $filePath = Yii::getAlias('@' . $path . DIRECTORY_SEPARATOR . $cat->file_name);
     $row = 0;
     if (($handle = fopen($filePath, "r")) !== FALSE) {
         while (($data = fgetcsv($handle, 0, ";")) !== FALSE) {
             $row++;
             $model = Torrents::findOne(['forum_id' => $data[0], 'topic_id' => $data[2]]);
             if ($model !== null) {
                 continue;
             }
             // Subcategory
             $subcat = $this->importSubcategory($data[1]);
             if (!$subcat instanceof Subcategory) {
                 $this->stderr("Error! Unable to import subcategory!");
                 $this->stdout("\n");
                 continue;
             }
             $this->stdout("Row {$row} of category \"{$cat->category_name}\" ");
             $this->stdout("and subcategory \"{$subcat->forum_name}\": ");
             if ($model === null) {
                 if (isset($data[4])) {
                     $data[4] = str_replace('\\', '/', $data[4]);
                 }
                 if (!isset($data[0]) || !isset($data[1]) || !isset($data[2]) || !isset($data[3]) || !isset($data[4]) || !isset($data[5]) || !isset($data[6])) {
                     $this->stderr("Error! Undefined Field!\n", Console::FG_RED);
                     \yii\helpers\VarDumper::dump($data);
                     $this->stdout("\n");
                     continue;
                 }
                 $model = new Torrents(['forum_id' => $data[0], 'forum_name' => $data[1], 'topic_id' => $data[2], 'hash' => $data[3], 'topic_name' => $data[4], 'size' => $data[5], 'datetime' => strtotime($data[6]), 'category_id' => $cat->id]);
             }
             $model->forum_name_id = $subcat->id;
             if ($model->save()) {
                 $this->stdout("Torrent \t");
                 $this->stdout($model->topic_name, Console::FG_YELLOW);
                 $this->stdout(" added\n");
             }
             $this->stdout("\n");
         }
     }
 }
Exemplo n.º 2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTorrents()
 {
     return $this->hasMany(Torrents::className(), ['category_id' => 'id']);
 }
Exemplo n.º 3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTorrents()
 {
     return $this->hasMany(Torrents::className(), ['forum_name_id' => 'id']);
 }
Exemplo n.º 4
0
 * User: andrew72ru
 * Date: 01.01.16
 * Time: 13:15
 * File: index.php
 *
 * @var \yii\web\View $this
 * @var TorrentSearch $searchModel
 * @var \yii\sphinx\ActiveDataProvider $dataProvider
 */
$this->title = Yii::t('app', 'Rutracker Torrents Search');
use common\models\Categories;
use common\models\Subcategory;
use common\models\Torrents;
use common\models\TorrentSearch;
use yii\grid\GridView;
use yii\helpers\Html;
use yii\widgets\Pjax;
?>

<?php 
Pjax::begin(['scrollTo' => 0]);
echo GridView::widget(['filterModel' => $searchModel, 'dataProvider' => $dataProvider, 'columns' => ['name_attr' => ['attribute' => 'name_attr', 'value' => function ($model) {
    return Html::a($model['name_attr'], 'http://rutracker.org/forum/viewtopic.php?t=' . $model['topic_id_attr'], ['target' => '_blank']);
}, 'format' => 'raw', 'contentOptions' => ['style' => ['white-space' => 'normal']]], ['attribute' => 'category_attr', 'value' => function ($model) {
    return Categories::findOne($model['category_attr'])->category_name;
}, 'filter' => TorrentSearch::catForSubs($searchModel->forum_name_id_attr)], ['attribute' => 'forum_name_id_attr', 'value' => function ($model) {
    return Subcategory::findOne($model['forum_name_id_attr'])->forum_name;
}, 'contentOptions' => ['style' => ['white-space' => 'normal']], 'filter' => TorrentSearch::subsForCat($searchModel->category_attr)], ['attribute' => 'size_attr', 'format' => 'shortSize', 'contentOptions' => ['class' => 'text-right'], 'filter' => false], ['attribute' => 'datetime_attr', 'format' => 'datetime', 'headerOptions' => ['class' => 'text-nowrap'], 'filter' => false], ['header' => null, 'value' => function ($model) {
    return Html::a(Html::tag('span', '', ['class' => 'glyphicon glyphicon-download-alt']), 'magnet:?xt=urn:btih:' . Torrents::findOne($model['id'])->hash . '&tr=http://bt.rutracker.cc/ann?magnet');
}, 'format' => 'raw']]]);
Pjax::end();