/**
  * Displays a single Product model.
  * @param string $alias
  * @return mixed
  */
 public function actionView($alias)
 {
     $model = $this->findModel($alias);
     $menu_items_product = Product::getItemsProductMenu($model->category_id);
     $menu_items_category = Category::getItemsCategoryMenu($model->category->parent_category_id, $model->category_id);
     return $this->render('view', ['model' => $model, 'menu_items_product' => $menu_items_product, 'menu_items_category' => $menu_items_category]);
 }
 /**
  * Finds the Category model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Category the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Category::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * Finds the Category model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Category the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($alias)
 {
     if (($model = Category::findOne(['alias' => $alias, 'active' => 1])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Esempio n. 4
0
 /**
  * Updates an existing SubCategory 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);
     $categoriesArray = ArrayHelper::map(Category::find()->all(), 'id', 'name');
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model, 'categoriesArray' => $categoriesArray]);
     }
 }
 /**
  * Updates an existing Product 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);
     $model->updated = Yii::$app->formatter->format($model->updated, 'date');
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $this->fileAttach($model);
         $model->updated = Yii::$app->formatter->format($model->updated, 'date');
         return $this->render('update', ['model' => $model, 'listCategory' => Category::getListCategory()]);
     } else {
         return $this->render('update', ['model' => $model, 'listCategory' => Category::getListCategory()]);
     }
 }
Esempio n. 6
0
 public function actionShowOrder($id = null)
 {
     $model = new Order();
     $model = $model::findOne(['id' => $id]);
     //var_dump($model->product_id);die();
     $products = Product::find()->asArray()->all();
     $listProducts = ArrayHelper::map($products, 'id', 'name');
     $categories = Category::find()->asArray()->all();
     $listCategories = ArrayHelper::map($categories, 'id', 'name');
     $subCategories = SubCategory::find()->asArray()->all();
     $listSubCategories = ArrayHelper::map($subCategories, 'id', 'name');
     return $this->render('showOrder', ['model' => $model, 'listProducts' => $listProducts, 'listCategories' => $listCategories, 'listSubCategories' => $listSubCategories]);
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Category::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', 'title', $this->title]);
     return $dataProvider;
 }
Esempio n. 8
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Category::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->joinWith('parent');
     $query->andFilterWhere(['category.id' => $this->id, 'category.parent_category_id' => $this->parent_category_id, 'category.created' => $this->created, 'category.updated' => $this->updated, 'category.active' => $this->active]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'keywords', $this->keywords])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'image', $this->image]);
     return $dataProvider;
 }
Esempio n. 9
0
 public function saveCategories()
 {
     foreach ($this->categories as $category) {
         //$this->categories mi vraca listu objekata
         $i = array_search($category->id, $this->category_ids);
         //trazi konkretan int u nizu intova
         if ($i !== false) {
             //vraca index gdje se nalazi ili ako ga nema false
             unset($this->category_ids[$i]);
             //brise na i-tom mjestu caketogri id
         }
     }
     foreach ($this->category_ids as $value) {
         //prolazim kroz listu zeljenih ideva
         $category = Category::findOne($value);
         //nadjem objekat iz tabele na mjestu value
         $this->link('categories', $category);
         //relacija i objekat
     }
 }
Esempio n. 10
0
use app\modules\admin\models\Category;
$this->title = 'Project';
$this->params['breadcrumbs'][] = $this->title;
/* @var $this yii\web\View */
/* @var $model app\modules\admin\models\Project */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="project-form">

    <?php 
$form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]);
?>
    
    <?php 
echo $form->field($model, 'category_id')->dropDownList([ArrayHelper::map(Category::find()->all(), 'category_id', 'name')]);
?>

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

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

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

    <?php 
Esempio n. 11
0
 /**
  * Updates an existing Product 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);
     $modelCategory = new Category();
     $categoriesArray = ArrayHelper::map(Category::find()->all(), 'id', 'name');
     $modelLinkProduct = LinkProduct::find()->where(['id_product' => $id])->orderBy('id_category')->all();
     $subCategoriesArray = SubCategory::find()->all();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         LinkProduct::deleteAll(['id_product' => $id]);
         foreach (Yii::$app->request->post()['category'] as $key => $id) {
             //var_dump($id.'---');
             if (Yii::$app->request->post()['subCategory' . $id]) {
                 foreach (Yii::$app->request->post()['subCategory' . $id] as $keySub => $idSub) {
                     //$linkProductArray = array($model->id,$id,$idSub);
                     $modelLinkProduct = new LinkProduct();
                     //var_dump($keySub.$idSub );echo "<br>";
                     $modelLinkProduct->id_product = $model->id;
                     $modelLinkProduct->id_category = $id;
                     $modelLinkProduct->id_sub_category = $idSub;
                     $modelLinkProduct->save();
                 }
             } else {
                 $modelLinkProduct = new LinkProduct();
                 //var_dump($keySub.$idSub );echo "<br>";
                 $modelLinkProduct->id_product = $model->id;
                 $modelLinkProduct->id_category = $id;
                 $modelLinkProduct->id_sub_category = 0;
                 $modelLinkProduct->save();
             }
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         $modelLinkProduct = LinkProduct::find()->where(['id_product' => $id])->orderBy('id_category')->all();
         //            var_dump(ArrayHelper::map($modelLinkProduct,'id','id_product'));die();
         return $this->render('update', ['model' => $model, 'categoriesArray' => $categoriesArray, 'subCategoriesArray' => $subCategoriesArray, 'modelLinkProductCategory' => ArrayHelper::map($modelLinkProduct, 'id', 'id_category'), 'modelLinkProductSubCategory' => ArrayHelper::map($modelLinkProduct, 'id', 'id_sub_category')]);
     }
 }
Esempio n. 12
0
/* @var $model app\modules\blog\models\Post */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="post-form">

    <?php 
$form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]);
?>
    
    <?php 
echo $form->field($model, 'title')->textInput(['maxlength' => true]);
?>

    <?php 
echo $form->field($model, 'category_id')->widget(Select2::className(), ['data' => ArrayHelper::map(Category::find()->getActive()->all(), 'id', 'title'), 'language' => 'en', 'options' => ['placeholder' => 'Select a category ...'], 'pluginOptions' => ['allowClear' => true]]);
?>
    <?php 
echo $form->field($model, 'description')->widget(CKEditor::className(), ['options' => ['row' => 6], 'preset' => 'basic']);
?>
    <?php 
echo $form->field($model, 'text')->widget(CKEditor::className(), ['options' => ['row' => 6], 'preset' => 'basic']);
?>
    <?php 
echo $form->field($model, 'img')->widget(FileInput::classname(), ['name' => 'img[]', 'options' => ['multiple' => true], 'pluginOptions' => ['initialPreview' => $model->img ? Html::img($model->img, ['class' => 'file-preview-image']) : '', 'overwriteInitial' => true]]);
?>
    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>
Esempio n. 13
0
 public function getCategories()
 {
     $category = Category::find()->all();
     return $category;
 }
Esempio n. 14
0
 /**
  * Displays a single Post model.
  * @param integer $id
  * @return mixed
  */
 public function actionView($id)
 {
     $modelCategory = Category::find()->getActive()->all();
     return $this->render('view', ['model' => $this->findModel($id), 'modelCategory' => $modelCategory]);
 }
Esempio n. 15
0
use yii\helpers\ArrayHelper;
use app\modules\admin\models\Category;
use mihaildev\ckeditor\CKEditor;
?>

<div class="items-form">
    <?php 
$form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]);
?>
    <?php 
echo $form->field($model, 'file')->fileInput();
?>
    <?php 
echo $form->field($model, 'title')->textInput(['maxlength' => 255]);
?>
    <?php 
echo $form->field($model, 'text')->widget(CKEditor::className(), ['editorOptions' => ['preset' => 'full', 'inline' => false]]);
?>
    <?php 
echo $form->field($model, 'category')->dropDownList(ArrayHelper::map(Category::find()->all(), 'title', 'title'), ['promt' => 'Выберите категорию']);
?>
    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? 'Создать' : 'Обновить', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>
    <?php 
ActiveForm::end();
?>
</div>
Esempio n. 16
0
    <?php 
$form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]);
?>

    <?php 
echo $form->field($model, 'name')->textInput(['maxlength' => true]);
?>
    <?php 
echo $form->field($model, 'alias')->textInput(['maxlength' => true]);
?>
    <?php 
echo $form->field($model, 'active')->checkbox(['id' => 'check']);
?>
    <?php 
echo $form->field($model, 'parent_category_id')->dropDownList(ArrayHelper::map(\app\modules\admin\models\Category::getListCategory($model->isNewRecord ? [] : 'id!=' . $model->id), 'id', 'name'), ['prompt' => 'Не выбрано']);
?>

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

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

    <?php 
echo $form->field($model, 'image')->fileInput();
?>
    <div class="form-group">
        <div class="col-md-offset-2 col-md-10">
Esempio n. 17
0
 public function getCategory()
 {
     return $this->hasOne(Category::className(), ['id' => 'category_id']);
 }
Esempio n. 18
0
    <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>

    <p>
        <?php 
echo Html::a('Создать категорию', ['create'], ['class' => 'btn btn-success']);
?>
    </p>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['attribute' => 'id', 'headerOptions' => ['class' => 'col-sm-1']], ['attribute' => 'name', 'format' => 'raw', 'value' => function ($category) {
    return Html::tag('a', $category->name, ['href' => Url::to(['update', 'id' => $category->id])]);
}], ['attribute' => 'parent_category_id', 'format' => 'raw', 'value' => function ($data) {
    if ($data->parent) {
        return Html::a($data->parent->name, Url::to(['admin/category/update', 'id' => $data->id]));
    }
}, 'filter' => Html::activeDropDownList($searchModel, 'parent_category_id', \yii\helpers\ArrayHelper::map(\app\modules\admin\models\Category::getListCategory(), 'id', 'name'), ['prompt' => 'Не выбрано'])], ['attribute' => 'active', 'format' => 'raw', 'value' => function ($category) {
    if ($category->active) {
        $mes = 'Да';
        $class = 'success';
    } else {
        $mes = 'Нет';
        $class = 'warning';
    }
    return Html::tag('span', $mes, ['class' => 'label label-' . $class]);
}, 'filter' => Html::activeDropDownList($searchModel, 'active', \app\modules\admin\models\Category::getYesNo(), ['prompt' => 'Не выбрано']), 'headerOptions' => ['class' => 'col-sm-1']], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{delete}', 'headerOptions' => ['class' => 'col-sm-1']]]]);
?>

</div>