示例#1
0
 /**
  * Displays homepage.
  *
  * @param null $category
  * @param null $rubric
  * @param null $price_before
  * @param null $price_after
  * @return mixed
  */
 public function actionIndex($category = null, $rubric = null, $price_before = null, $price_after = null)
 {
     $categories = ArrayHelper::map(Categories::find()->all(), 'id', 'name');
     $rubrics = [];
     if ($category) {
         $rubrics = ArrayHelper::map(Rubrics::find()->where(['category_id' => $category])->all(), 'id', 'name');
         if ($rubric && !in_array($rubric, $rubrics)) {
             $rubric = null;
         }
     } else {
         $rubrics = ArrayHelper::map(Rubrics::find()->all(), 'id', 'name');
     }
     $query = Goods::find();
     if ($rubric) {
         $query->where(['rubric_id' => $rubric]);
     } else {
         if ($category) {
             $query->where(['rubric_id' => array_keys($rubrics)]);
         }
     }
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count()]);
     $pages->pageSize = 12;
     $models = $query->offset($pages->offset)->limit($pages->limit)->all();
     $session = Yii::$app->getSession();
     $cart = $session->has('cart') ? $session->get('cart') : [];
     return $this->render('index', ['goods' => $models, 'cart' => $cart, 'pages' => $pages, 'categories' => $categories, 'rubrics' => $rubrics, 'active_category' => $category, 'active_rubric' => $rubric, 'price_before' => $price_before, 'price_after' => $price_after]);
 }
示例#2
0
 public function actionIndex()
 {
     $params = yii::$app->getRequest()->getQueryParams();
     if (empty($params['parent_id'])) {
         $query = Categories::find()->where(["category_parent_id" => $params['parent_id']]);
     }
     return new yii\data\ActiveDataProvider(['query' => $query, 'pagination' => array('pageSize' => 50)]);
 }
示例#3
0
 /**
  * Updates an existing News model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $categ = Categories::find()->all();
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model, 'categ' => $categ]);
     }
 }
示例#4
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Categories::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, 'status' => $this->status, 'created_at' => $this->created_at, 'created_by' => $this->created_by, 'updated_at' => $this->updated_at, 'updated_by' => $this->updated_by]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Categories::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, 'parent_id' => $this->parent_id]);
     $query->andFilterWhere(['like', 'title', $this->title]);
     return $dataProvider;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Categories::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;
     }
     if (!$this->parent_id) {
         $this->parent_id = 0;
     }
     $query->andFilterWhere(['id' => $this->id, 'parent_id' => $this->parent_id, 'position' => $this->position, 'publish' => $this->publish, 'create_date' => $this->create_date, 'update_date' => $this->update_date]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'alias', $this->alias]);
     return $dataProvider;
 }
示例#7
0
 public static function getTreeSelect($parent_id, $level = 0)
 {
     $cat = Categories::find()->where(['parent_id' => $parent_id])->all();
     $arr[0] = 'Нет';
     foreach ($cat as $c) {
         $tire = '-';
         if ($level != 0) {
             for ($i = 1; $i <= $level; $i++) {
                 $tire .= "-";
             }
         }
         $arr[$c->id] = $tire . $c->name;
         $level++;
         $arr2 = self::getTreeSelect($c->id, $level);
         $arr = $arr + $arr2;
         $level--;
     }
     return $arr;
 }
示例#8
0
 /**
  * Updates an existing Category model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $parent = Categories::find()->all();
     $media = Media::find()->orderBy('id DESC')->all();
     $block = Block::find()->where(['type' => ''])->all();
     $arr = CategoryTree::getTreeSelect(0);
     $arr1[0] = 'Нет';
     foreach ($block as $v) {
         $arr1[$v->id] = $v->name;
     }
     /*$arr[0] = 'Нет';
       foreach($parent as $v){
           $arr[$v->id]=$v->name;
       }*/
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['update', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model, 'parent' => $arr, 'media' => $media, 'block' => $arr1]);
     }
 }
示例#9
0
文件: Category.php 项目: apuc/admin
 public static function getParentCategories($id)
 {
     $cat = Categories::find()->where(['parent_id' => $id])->all();
     $html = '';
     foreach ($cat as $c) {
         $html .= '<div class="product">
                 ' . Html::a($c->name, ['/category', 'c' => $c->id]) . '
                 <div class="info">
                     <span></span>
                     <div class="hint">
                        ' . $c->description . '
                     </div>
                 </div>
             </div>';
         //Debag::prn('123');
     }
     if (count($cat) > 4) {
         $html .= '</div><a href="#" class="showall">показать все</a>';
     } else {
         $html .= '</div><div class="empty"></div>';
     }
     return $html;
 }
示例#10
0
文件: PrintBlind.php 项目: apuc/admin
 public static function getCountItems($id, $num)
 {
     $cat = Categories::find()->where(['id' => $id])->one();
     $count = $cat->count_product;
     $blinds = BlindCatid::find()->where(['id_cat' => $id])->offset($num * $count)->orderBy('id_blind DESC')->all();
     //Debag::prn($count);
     //Debag::prn(count($blinds));
     if (count($blinds) <= $count) {
         return 1;
     } else {
         return 0;
     }
 }
 /**
  * Импорт категорий
  *
  * @param $path
  * @return array|\yii\db\ActiveRecord[]
  */
 private function importCategories($path)
 {
     $file = $path . DIRECTORY_SEPARATOR . 'category_info.csv';
     $row = 1;
     if (($handle = fopen($file, "r")) !== FALSE) {
         while (($data = fgetcsv($handle, 0, ";")) !== FALSE) {
             $row++;
             $this->stdout("Row " . $row . ":\n");
             $model = Categories::findOne($data[0]);
             if ($model === null) {
                 $model = new Categories(['id' => $data[0], 'category_name' => $data[1], 'file_name' => $data[2]]);
             }
             if ($model->save()) {
                 $this->stdout("Category {$model->id} with name '{$model->category_name}' imported\n");
             }
             $this->stdout("\n");
         }
     } else {
         return false;
     }
     return Categories::find()->all();
 }
示例#12
0
                    {
                        var js, fjs = d.getElementsByTagName( s )[0], p = /^http:/.test( d.location ) ? 'http' : 'https';
                        if (! d.getElementById( id )) {
                            js = d.createElement( s );
                            js.id = id;
                            js.src = p + "://platform.twitter.com/widgets.js";
                            fjs.parentNode.insertBefore( js, fjs );
                        }
                    }( document, "script", "twitter-wjs" );</script>
            </div>
        </div>
        <div class="column-one-fourth">
            <h5 class="line"><span>Навигация.</span></h5>
            <ul class="footnav">
                <?php 
if ($categories = \common\models\Categories::find()->where('parent_id IS NULL')->orderBy('order ASC')->all()) {
    ?>

                    <?php 
    foreach ($categories as $category) {
        ?>
                        <li>
                            <a href="<?php 
        echo $category->getLink();
        ?>
"><i
                                    class="icon-right-open"></i><?php 
        echo \yii\helpers\Html::encode($category->name);
        ?>
</a>
                        </li>
 /**
  * Group data for Html::activeDropDownList method
  * @return array
  */
 private function getItems()
 {
     return ['categories' => ArrayHelper::map(Categories::find()->all(), 'id', 'name'), 'article_status' => [10 => 'Опубліковано', 0 => 'Прихована стаття'], 'comments_status' => [10 => 'Дозволені', 0 => 'Заборонені']];
 }
示例#14
0
文件: _form.php 项目: saqbest/res.dev
/* @var $this yii\web\View */
/* @var $model common\models\Places */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="places-form">

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

    <?php 
echo $form->field($model, 'name')->textInput(['maxlength' => true]);
?>
    <?php 
echo $form->field($model, 'category_id')->widget(Select2::classname(), ['data' => \yii\helpers\ArrayHelper::map(\common\models\Categories::find()->all(), 'id', 'name'), 'options' => ['placeholder' => 'Select a state ...'], 'pluginOptions' => ['allowClear' => true]]);
?>

    <?php 
echo $form->field($model, 'kitchensIds')->widget(Select2::classname(), ['data' => $model->getdropKitchens(), 'options' => ['placeholder' => 'Select a Kitchens ...', 'multiple' => true], 'pluginOptions' => ['allowClear' => true]])->label('Kitchens');
?>
    <?php 
echo $form->field($model, 'servicesIds')->widget(Select2::classname(), ['data' => $model->getdropServices(), 'options' => ['placeholder' => 'Select a Services ...', 'multiple' => true], 'pluginOptions' => ['allowClear' => true]])->label('Services');
?>

    <?php 
echo $form->field($model, 'metrosIds')->widget(Select2::classname(), ['data' => $model->getdropMetros(), 'options' => ['placeholder' => 'Select a Metros ...', 'multiple' => true], 'pluginOptions' => ['allowClear' => true]])->label('Metros');
?>

    <?php 
echo $form->field($model, 'description')->widget(CKEditor::className(), ['editorOptions' => ['preset' => 'basic', 'inline' => false]]);
示例#15
0
 public function init()
 {
     parent::init();
     $this->categories = Categories::find()->all();
 }
示例#16
0
 /**
  * Возвращает массив с одной категорией, если передана подкатегория
  *
  * @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');
 }
示例#17
0
文件: _form.php 项目: iryska/nagginua
    ?>
]"
                       value="<?php 
    echo $pattern;
    ?>
" maxlength="255" placeholder="<?php 
    echo $placeholder;
    ?>
">
            </div>

        <?php 
}
?>

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

    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>

    <?php 
ActiveForm::end();
?>

</div>
示例#18
0
 /**
  * Get Breadcrumbs
  *
  * @param $id
  * @return array
  */
 private function _getBreadcrumbs($id)
 {
     $breadcrumbs = [];
     if ($id > 0) {
         $this->_categories = Categories::find()->indexBy('id')->asArray()->all();
         $catId = (int) $id;
         while (true) {
             if ($catId === 0) {
                 break;
             }
             array_unshift($breadcrumbs, ['label' => $this->_categories[$catId]['title'], 'url' => $this->_categories[$catId]['id']]);
             $catId = (int) $this->_categories[$catId]['parent_id'];
         }
     }
     return $breadcrumbs;
 }
示例#19
0
文件: News.php 项目: iryska/nagginua
 public function getCategoryList()
 {
     return Categories::find()->join('inner join', NewsHasCategory::tableName(), NewsHasCategory::tableName() . ".category_id = " . Categories::tableName() . ".id")->where([NewsHasCategory::tableName() . ".news_id" => $this->id])->all();
 }
示例#20
0
文件: _form.php 项目: iryska/nagginua
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\helpers\ArrayHelper;
/* @var $this yii\web\View */
/* @var $model common\models\CategoryWords */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="category-words-form">

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

    <?php 
echo $form->field($model, 'category_id')->dropDownList(ArrayHelper::map(\common\models\Categories::find()->asArray()->all(), 'id', 'name'), ['value' => $model->category_id]);
?>

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

    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>

    <?php 
ActiveForm::end();
?>