예제 #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = CategoryModel::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'parentId' => $this->parentId]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
예제 #2
0
 /**
  * @return array \app\models\CategoryModel
  */
 public static function getCategoriesByParentId($parentId)
 {
     $categories = \Yii::$app->cache->get('categories');
     if ($categories === false) {
         $categories = CategoryModel::find()->all();
         \Yii::$app->cache->add('categories', $categories);
     }
     $result_categories = array();
     foreach ($categories as $category) {
         if ($category->parentId == $parentId) {
             $result_categories[] = $category;
         }
     }
     return $result_categories;
 }
예제 #3
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     CategoryModel::find($id)->delete();
     return redirect()->route('admin.category.index')->with('success_msg', 'Succesfully deleted category');
 }
예제 #4
0
파일: _form.php 프로젝트: Sywooch/WebStore
/* @var $model app\models\CategoryModel */
/* @var $form yii\widgets\ActiveForm */
?>

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

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

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

    <?php 
$categories = ArrayHelper::map(CategoryModel::find()->all(), 'id', 'name');
$categories[] = '';
asort($categories);
?>

    <?php 
echo $form->field($model, 'parentId')->dropDownList($categories);
?>

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

    <?php 
예제 #5
0
파일: _form.php 프로젝트: Sywooch/WebStore
    <?php 
echo $form->field($model, 'idCategory')->dropDownList(ArrayHelper::map(CategoryModel::find()->all(), 'id', 'name'), ['readonly' => isset($model['idCategory'])]);
?>

    <?php 
if (isset($model['idCategory']) && isset($model['id'])) {
    if (isset($model->idCategory)) {
        $characteristics = CharacteristicModel::find()->where(['idCategory' => $model['idCategory']])->all();
        $category = CategoryModel::find()->where(['id' => $model['idCategory']])->one();
        while ($category['parentId'] != null) {
            $temp = CharacteristicModel::find()->where(['idCategory' => $category['parentId']])->all();
            foreach ($temp as $temp_char) {
                $characteristics[] = $temp_char;
            }
            $category = CategoryModel::find()->where(['id' => $category['parentId']])->one();
        }
    }
    $counter = 0;
    foreach ($characteristics as $characteristic) {
        $char_model = CharacteristicValueModel::find()->where(['idProduct' => $model['id'], 'idCharacteristic' => $characteristic->id])->one();
        if ($char_model == null) {
            $char_model = new CharacteristicValueModel();
            $char_model->idProduct = $model['id'];
            $char_model->idCharacteristic = $characteristic->id;
        }
        echo Html::activeHiddenInput($char_model, "[{$counter}]idProduct");
        echo Html::activeHiddenInput($char_model, "[{$counter}]idCharacteristic");
        echo $form->field($char_model, "[{$counter}]value", ['labelOptions' => ['label' => $characteristic->name . ' (' . $characteristic->value . ')']])->textInput();
        $counter++;
    }
예제 #6
0
파일: _form.php 프로젝트: Sywooch/WebStore
use yii\widgets\ActiveForm;
use app\models\CategoryModel;
use yii\helpers\ArrayHelper;
/* @var $this yii\web\View */
/* @var $model app\models\CharacteristicModel */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="characteristic-model-form">

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

    <?php 
echo $form->field($model, 'idCategory')->dropDownList(ArrayHelper::map(CategoryModel::find()->all(), 'id', 'name'));
?>

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

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

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