/**
  * Создание подкатегории (forum_name)
  *
  * @param string $subcat_name
  * @return bool|Subcategory
  */
 private function importSubcategory($subcat_name)
 {
     $model = Subcategory::findOne(['forum_name' => $subcat_name]);
     if ($model === null) {
         $model = new Subcategory(['forum_name' => $subcat_name]);
     }
     if ($model->save()) {
         return $model;
     } else {
         VarDumper::dump($model->errors);
     }
     return false;
 }
 /**
  * Finds the Subcategory model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Subcategory the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Subcategory::findOne(['id' => $id])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * Возвращает массив с одной категорией, если передана подкатегория
  *
  * @param null|integer $id
  * @return array
  */
 public static function catForSubs($id = null)
 {
     $query = Categories::find();
     if ($id != null && ($subCat = Subcategory::findOne($id)) !== null) {
         /** @var TorrentSearch $category */
         $category = self::find()->where(['forum_name_id_attr' => $id])->one();
         $query->andWhere(['id' => $category->category_attr]);
     }
     return ArrayHelper::map($query->asArray()->all(), 'id', 'category_name');
 }
Beispiel #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();