/** * Updates an existing GoodsType model. * If update is successful, the browser will be redirected to the 'view' page. * @param string $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['index']); } else { $arObjParams = \app\models\GoodsParamsName::find()->where('goods_type_type=:goods_type_type', [':goods_type_type' => $id])->all(); return $this->render('update', ['arObjParams' => $arObjParams, 'model' => $model]); } }
public function actionGetAddFilerRows($goodsType) { $paramsName = \app\models\GoodsParamsName::find()->where('goods_type_type=:goods_type_type', [':goods_type_type' => $goodsType])->orderBy('sort')->all(); $arRes = \yii\helpers\ArrayHelper::toArray($paramsName, ['app\\models\\GoodsParamsName' => ['title' => 'name', 'name' => 'id', 'data' => function ($paramsName) { $data = \yii\helpers\ArrayHelper::map($paramsName->getGoodsParams()->all(), 'id', 'value'); return ['' => ' - Все - '] + $data; }, 'parent_param' => 'parent_param', 'ch' => function () { return ''; }]]); header('Content-Type: utf-8'); foreach ($arRes as $value) { print $this->renderPartial('_row_filter', $value); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = GoodsParamsName::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(['required' => $this->required, 'sort' => $this->sort]); $query->andFilterWhere(['like', 'id', $this->id])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'data_type', $this->data_type])->andFilterWhere(['like', 'parent_param', $this->parent_param])->andFilterWhere(['like', 'goods_type_type', $this->goods_type_type]); return $dataProvider; }
/** * Deletes an existing GoodsParams model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed */ public function actionTech() { exit; $GoodsParamsName = \app\models\GoodsParamsName::find()->all(); foreach ($GoodsParamsName as $gpn) { print '============================== <br>'; print $gpn->id . '<br>'; $oGP = \app\models\GoodsParams::find()->where('goods_params_name_id=:goods_params_name_id', [':goods_params_name_id' => $gpn->id])->all(); // print ('<pre>');print_r($oGP);print('</pre>'); $arGP = \yii\helpers\ArrayHelper::map($oGP, 'id', 'id'); print implode(',', $arGP) . '<br>'; if (count($arGP) == 0) { continue; } // $goods = \app\components\Goods::find($gpn->goods_type_type, $gpn->id . ' not in (:ids)', [':ids' => implode(',',$arGP)])->all(); $goods = \app\components\Goods::find($gpn->goods_type_type, $gpn->id . ' not in (' . implode(',', $arGP) . ')', [])->all(); foreach ($goods as $good) { $ar = \yii\helpers\ArrayHelper::toArray($good); print '<pre>'; print_r($ar); print '</pre>'; \app\models\Goods::deleteAll('id=:goods_id', [':goods_id' => $good->goods_id]); } } }
/** * Creates a new GoodsParamsName model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new GoodsParamsName(); $arPost = Yii::$app->request->post(); if (Yii::$app->request->getIsPost()) { $arPost['GoodsParamsName']['goods_type_type'] = $this->goodType; $arPost['GoodsParamsName']['id'] = str_replace($this->goodType . '_', '', $arPost['GoodsParamsName']['id']); $arPost['GoodsParamsName']['id'] = $this->goodType . '_' . $arPost['GoodsParamsName']['id']; } if (Yii::$app->request->getIsPost() && $model->load($arPost) && $model->save()) { $arPost['GoodsParamsName']['id'] = str_replace($this->goodType . '_', '', $arPost['GoodsParamsName']['id']); $arPost['GoodsParamsName']['id'] = $this->goodType . '_' . $arPost['GoodsParamsName']['id']; $table = 'goods_t_' . $this->goodType; $fild = $arPost['GoodsParamsName']['id']; $dataType = $arPost['GoodsParamsName']['data_type']; $required = $arPost['GoodsParamsName']['required'] ? ' NOT NULL' : ''; // $sql = "ALTER TABLE `$table` ADD `$fild` $dataType $required"; $sql = "ALTER TABLE `{$table}` ADD `{$fild}` int(7) {$required}"; \Yii::$app->db->createCommand($sql)->execute(); // ALTER TABLE `goods_t_tyre` ADD `with` INT NOT NULL return $this->redirect(['index']); } else { $listTypesParams = ['' => ' - - ', 'int' => 'Целое число', 'float' => 'Число с запятой', 'varchar' => 'Строка']; $parentParam = GoodsParamsName::find()->where('goods_type_type=:goods_type', [':goods_type' => $this->goodType])->all(); $arParams = ['' => ' - - ']; foreach ($parentParam as $value) { $arParams[$value->id] = $value->name; } return $this->render('create', ['listTypesParams' => $listTypesParams, 'model' => $model, 'arParams' => $arParams]); } }
public function actionGetTypeParams($type) { $params = \app\models\GoodsParamsName::find()->where('goods_type_type=:goods_type_type', [':goods_type_type' => $type])->orderBy('sort ASC')->all(); $arParams = ['' => ' - Добавить параметр - ']; $arLinks = []; foreach ($params as $param) { $arParams[$param->id] = $param->name; if ($param->parent_param) { $arLinks[$param->id] = $param->parent_param; } } print '<script>oLinks = ' . json_encode($arLinks) . '</script>'; print \yii\helpers\BaseHtml::dropDownList('listParams', '', $arParams); }