Пример #1
0
 private function write($i_lft, $i_rgt, $i_id)
 {
     // fetch the source column
     $s_query = "SELECT * FROM `catalogs` WHERE `catalog_id`  = '" . $i_id . "'";
     if (!($i_result = mysql_query($s_query))) {
         echo "<pre>{$s_query}</pre>\n";
         throw new Exception(mysql_error());
     }
     $a_source = array();
     if (mysql_num_rows($i_result)) {
         $a_source = mysql_fetch_assoc($i_result);
     }
     // root node?  label it unless already labeled in source table
     if (1 == $i_lft && empty($a_source['name'])) {
         $a_source['name'] = 'ROOT';
         // return;
     }
     $catalog = Catalogs::findOne($i_id);
     if (is_null($catalog)) {
         // return;
         $catalog = new Catalogs();
         $catalog->detachBehaviors();
         $catalog->name = $a_source['name'];
         $catalog->lft = $i_lft;
         $catalog->rgt = $i_rgt;
         $catalog->save(false);
     } else {
         // каталог нашли, обновим индексы
         $catalog->detachBehaviors();
         $catalog->name = $a_source['name'];
         $catalog->lft = $i_lft;
         $catalog->rgt = $i_rgt;
         $catalog->save(false);
     }
 }
Пример #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  * @param Catalogs $catalog
  *
  * @return ActiveDataProvider
  */
 public function search($params, $catalog)
 {
     $viewList = CookieController::getViewList();
     $productsID = [];
     $productsID = array_merge($productsID, $catalog->getProducts()->select('product_id')->asArray()->all());
     foreach ($catalog->children()->all() as $child) {
         $productsID = array_merge($productsID, $child->getProducts()->select('product_id')->asArray()->all());
     }
     $query = Products::find()->where(['product_id' => $productsID]);
     $price_min = $query->min('price');
     $price_max = $query->max('price');
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => $viewList == 'panel' ? 6 : 5]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['like', 'name', $this->name]);
     // print_r($this->price_min);
     $query->andFilterWhere(['>=', 'price', $this->price_min]);
     $query->andFilterWhere(['<=', 'price', $this->price_max]);
     //print_r($params['ProductsCatalogSearch']);
     if ($params['ProductsCatalogSearch']['count'] == self::ALL) {
         // echo "всееее";
         // $query->andWhere('a > :a', ['a' => 'a'])
     } elseif ($params['ProductsCatalogSearch']['count'] == self::AVAILABLE) {
         // echo "в наличиbbи";
         $query->andWhere('count > 0');
     } elseif ($params['ProductsCatalogSearch']['count'] == self::NOT_AVAILABLE) {
         // echo "нетууу";
         $query->andWhere('count <= 0');
     }
     return ['dataProvider' => $dataProvider, 'price_min' => $price_min, 'price_max' => $price_max];
 }
Пример #3
0
 public static function SaveCatalog($catalogXML)
 {
     $catalog = Catalogs::findOne($catalogXML['id']);
     if (is_null($catalog)) {
         // создаем запись каталога
         $catalog = new Catalogs();
         $catalog->detachBehaviors();
         $catalog->catalog_id = $catalogXML['id'];
         $catalog->id_parent = $catalogXML['id_parent'];
         $catalog->name = $catalogXML['name'];
         $catalog->description = $catalogXML['description'];
         $catalog->level = $catalogXML['level'];
         // $catalog->root = $catalogXML['root'];
         $catalog->save(false);
     } else {
         // обновляем запись каталога
         $catalog->detachBehaviors();
         $catalog->catalog_id = $catalogXML['id'];
         $catalog->id_parent = $catalogXML['id_parent'];
         $catalog->name = $catalogXML['name'];
         $catalog->description = $catalogXML['description'];
         $catalog->level = $catalogXML['level'];
         // $catalog->root = $catalogXML['root'];
         $catalog->save(false);
     }
 }
Пример #4
0
 public function actionIndex()
 {
     $countOrders = Orders::find()->count();
     $countCatalogs = Catalogs::find()->where(['not', ['name' => 'ROOT']])->count();
     $countProducts = Products::find()->count();
     return $this->render('index', ['countOrders' => $countOrders, 'countCatalogs' => $countCatalogs, 'countProducts' => $countProducts]);
 }
Пример #5
0
 /**
  * Updates an existing CatalogsAdmin model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($catalog_id)
 {
     $model = $this->findModel($catalog_id);
     if ($model->load(Yii::$app->request->post())) {
         $id_parent = Yii::$app->request->post('CatalogsAdmin')['id_parent'];
         $parent = Catalogs::find()->where(['catalog_id' => $id_parent])->one();
         $model->prependTo($parent);
         if ($model->save()) {
             return $this->redirect(['view', 'catalog_id' => $model->catalog_id]);
         }
     } else {
         return $this->render('update', ['model' => $model]);
     }
 }
Пример #6
0
 public function actionView($catalog_id)
 {
     $model = Catalogs::findOne($catalog_id);
     if ($model === null) {
         throw new NotFoundHttpException();
     }
     $searchModel = new ProductsCatalogSearch();
     /** @var Catalogs $model */
     $arrayResult = $searchModel->search(Yii::$app->request->queryParams, $model);
     if ($arrayResult['dataProvider']->count > 0) {
         return $this->render('view', ['model' => $model, 'searchModel' => $searchModel, 'dataProvider' => $arrayResult['dataProvider'], 'price_min' => $arrayResult['price_min'], 'price_max' => $arrayResult['price_max']]);
     } else {
         return $this->render('emptyList', ['model' => $model, 'searchModel' => $searchModel, 'dataProvider' => $arrayResult['dataProvider'], 'price_min' => $arrayResult['price_min'], 'price_max' => $arrayResult['price_max']]);
     }
 }
Пример #7
0
    </div>


    <div class="box-body">
        <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'summary' => '', 'tableOptions' => ['class' => 'table table-bordered table-hover'], 'columns' => [['label' => 'Код', 'contentOptions' => ['style' => 'max-width: 30px;'], 'value' => function ($model) {
    return $model->catalog_id;
}], ['label' => '<i class="fa fa-picture-o"></i>', 'encodeLabel' => false, 'format' => 'raw', 'contentOptions' => ['style' => 'max-width: 30px;'], 'value' => function ($model) {
    if ($model->getBehavior('coverBehavior')->hasImage()) {
        //                                return Html::img($model->getBehavior('coverBehavior')->getUrl('original'),['class'=>'img-responsive','style'=>'max-width:50px;']);
        //                                $mainPhoto = $model->MainPhoto;
        return Html::a(Html::img($model->getBehavior('coverBehavior')->getUrl('original'), ['class' => 'img-responsive', 'style' => '']), ['products/view', 'catalog_id' => $model->catalog_id], ['style' => 'display:block;']);
    } else {
        return ' ';
    }
}], 'name', ['label' => 'Родитель', 'filter' => Html::activeDropDownList($searchModel, 'id_parent', ArrayHelper::map(Catalogs::find()->where(['not', ['catalog_id' => $model->catalog_id]])->andWhere(['not', ['name' => 'ROOT']])->all(), 'catalog_id', 'name'), ['class' => 'form-control', 'prompt' => '']), 'value' => function ($model) {
    $parent = $model->parents(1)->one();
    if ($parent->name == 'ROOT') {
        return '';
    } else {
        return $parent->name;
    }
}], ['class' => 'yii\\grid\\ActionColumn', 'urlCreator' => function ($action, $model, $key, $index) {
    return [$action, 'catalog_id' => $model->catalog_id];
}]]]);
?>

    </div>


</div>
Пример #8
0
 public function getCatalog()
 {
     return $this->hasOne(Catalogs::className(), ['catalog_id' => 'catalog_id']);
 }
Пример #9
0
            </ul>

            <div id="my-tab-content" class="tab-content">
                <div class="tab-pane active" id="decription" style="padding-top:15px;min-height:300px;">


                    <?php 
echo $form->field($model, 'popular', ['template' => "<div class='col-sm-offset-2 col-sm-10'>{input}</div>", 'inputOptions' => ['class' => 'form-control']])->checkbox();
?>

                    <?php 
echo $form->field($model, 'product_id', ['template' => "{label}\n<div class='col-sm-10'>{input}\n{hint}\n{error}</div>", 'labelOptions' => ['class' => 'control-label col-sm-2'], 'inputOptions' => ['class' => 'form-control', 'disabled' => true]])->textInput();
?>

                    <?
                    $catalogList = ArrayHelper::map(Catalogs::find()
                        ->where(['not',['name'=>'ROOT']])
                        ->all(), 'catalog_id', 'name');

                    echo $form->field(
                        $model, 'catalog_id',

                        [
                            'template'     => "{label}\n<div class='col-sm-10'>{input}\n{hint}\n{error}</div>",
                            'labelOptions' => [ 'class' => 'control-label col-sm-2' ],
                            'inputOptions' => [ 'class' => 'form-control' ],

                        ]
                    )->dropDownList($catalogList, [ 'prompt' => 'Выберите каталог ...' ]);
                    ?>
Пример #10
0
<?php

use yii\helpers\Html;
use common\models\catalogs\Catalogs;
use common\models\catalogs\CatalogsFtp;
?>

<?php 
$root = Catalogs::findOne(['name' => 'ROOT']);
$nodes = $root->children(1)->all();
?>



<div class="panel-basic panel-basic-primary">
        <div class="panel-basic-heading">
                  <h3 class="panel-basic-title">Каталог</h3>
        </div>
        <div class="panel-basic-body" style="padding:0px;">
                  
            <ul class="dropdown-menuu menu" role="menu" 
            style="display:block!important;border-radius: 0px;">
            
            <?php 
foreach ($nodes as $catalog) {
    ?>
            
            <li data-submenu-id="catalog_<?php 
    echo $catalog->catalog_id;
    ?>
">