public function actionChange_sup() { if (isset($_GET['code_val'])) { $id = explode('_', $_GET['id']); $sup = Supplies::find()->where(['id' => $id[1]])->one(); $sup->code = $_GET['code_val']; $sup->save(); } if (isset($_GET['mat_val'])) { $id = explode('_', $_GET['id']); $sup = Supplies::find()->where(['id' => $id[1]])->one(); $sup->type_mat = $_GET['mat_val']; $sup->save(); } if (isset($_GET['blind_val'])) { $id = explode('_', $_GET['id']); $sup = Supplies::find()->where(['id' => $id[1]])->one(); $sup->type_blind = $_GET['blind_val']; $sup->save(); } if (isset($_GET['price_val'])) { $id = explode('_', $_GET['id']); $sup = Supplies::find()->where(['id' => $id[1]])->one(); $sup->price = $_GET['price_val']; $sup->save(); } if (isset($_GET['width_val'])) { $id = explode('_', $_GET['id']); $sup = Supplies::find()->where(['id' => $id[1]])->one(); $sup->type_width = $_GET['width_val']; $sup->save(); } if (isset($_GET['color_val'])) { $sup = Supplies::find()->where(['id' => $_GET['id']])->one(); $sup->color = $_GET['color_val']; $sup->save(); } if (isset($_GET['img_val'])) { $sup = Supplies::find()->where(['id' => $_GET['id']])->one(); $sup->images = $_GET['img_val']; $sup->save(); } if (isset($_GET['id_mat']) && $_GET['id_page']) { // $pageItem = PageItem::find()->where(['id_item'=>$_GET['id_mat'],'id_blind'=>$_GET['id_page']])->all(); $pageItem = PageItem::deleteAll(['id_item' => $_GET['id_mat'], 'id_blind' => $_GET['id_page']]); } }
$catObj = \backend\modules\category\models\Category::find()->where(['id' => $c->id_cat])->one(); $title .= "<li>" . $catObj->name . "</li>"; } $title .= "</ul>"; return $title; }], ['attribute' => 'status', 'format' => 'text', 'value' => function ($model) { if ($model->status == 1) { return 'Опубликовано'; } else { return 'Не опубликовано'; } }], ['class' => DataColumn::className(), 'header' => 'Цена', 'format' => 'html', 'value' => function ($model) { $page2BlindID = PageToBlind::find()->where(['id_blind' => $model->id])->all(); $supIds = []; foreach ($page2BlindID as $page) { $s = PageItem::find()->where(['id_page' => $page->id_pages, 'item_type' => 'materials'])->all(); $supIds = array_merge($supIds, $s); } foreach ($supIds as $s) { $sup = Supplies::find()->where(['id' => $s->id_item])->one(); $prices[] = $sup->price; } if (isset($prices) && !empty($prices)) { $pricesMin = min($prices); $pricesMax = max($prices); } return "<div style='width: 100px'>" . $pricesMin . " - " . $pricesMax . "</div>"; }], ['class' => DataColumn::className(), 'header' => 'Действия', 'format' => 'html', 'value' => function ($model) { /*$view = Html::a("<img src='".\yii\helpers\Url::base()."crud_img/view.png' width='20px' title='Просмотр'></a>", ['/blind/blind/view','id'=>$model->id]);*/ $view = Html::a("<img src='" . \yii\helpers\Url::base() . "crud_img/edit.png' width='20px' title='Редактировать'></a>", ['/blind/blind/update', 'id' => $model->id]); $view .= Html::a("<img src='" . \yii\helpers\Url::base() . "crud_img/del.png' width='20px' title='Удалить'></a>", ['/blind/blind/delete', 'id' => $model->id]);
/** * Updates an existing Blind model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $blind = Blind::find()->where(['id' => $id])->one(); $model = new BlindForm(); $model->name = $blind->name; $model->status = $blind->status; $model->description = $blind->description; $model->tab = $blind->tab; $cat = BlindCatid::find()->where(['id_blind' => $id])->all(); $blindMaterialHeader = BlindMaterials::find()->where(['id_blind' => $id])->all(); //Debag::prn($_POST); foreach ($cat as $c) { $arr_catid[$c->id_cat] = ['selected ' => 'selected']; } $media = Media::find()->orderBy('id DESC')->all(); $supples = BlindIdmaterials::find()->where(['id_blind' => $id])->all(); foreach ($supples as $supl) { $arr_supl[$supl->id_materials] = ['selected ' => 'selected']; } $materials = \backend\modules\supplies\models\Supplies::find()->all(); foreach ($materials as $v) { $arr_materials[$v->id] = $v->code; } $arr_cat = CategoryTree::getTreeSelect(0); unset($arr_cat[0]); $blImg = new BlindImg(); $imgages = $blImg->find()->where(['id_blind' => $id])->all(); $addMaterials = \common\classes\Supplies::getAddSupplies(); if ($model->load(Yii::$app->request->post()) && $model->validate()) { $blind->name = $model->name; $blind->status = $model->status; $blind->description = $model->description; $blind->tab = $model->tab; $blind->save(); $delBmt = new BlindMaterials(); $delBmt->deleteAll(['id_blind' => $blind->id]); if (isset($_POST['blindTitle'])) { foreach ($_POST['blindTitle'] as $bt) { $arrBt = explode('*', $bt); $bmt = new BlindMaterials(); $bmt->id_blind = $blind->id; $bmt->id_materials = $arrBt[0]; $bmt->title = $arrBt[1]; $bmt->save(); } } $cat = BlindCatid::deleteAll(['id_blind' => $blind->id]); foreach ($model->categories as $cat) { $blindCatId = new BlindCatid(); $blindCatId->id_blind = $blind->id; $blindCatId->id_cat = $cat; $blindCatId->save(); } $blindImg = new BlindImg(); $cat = $blindImg->deleteAll(['id_blind' => $blind->id]); if (!empty($_POST['blind_image'])) { foreach ($_POST['blind_image'] as $img) { $blindImg = new BlindImg(); $imgarr = explode('*', $img); $blindImg->id_blind = $blind->id; $blindImg->images = $imgarr[0]; $blindImg->main = $imgarr[1]; $blindImg->save(); } } $cat = BlindIdmaterials::deleteAll(['id_blind' => $blind->id]); if (!empty($model->materials)) { foreach ($model->materials as $mat) { $blindMat = new BlindIdmaterials(); $blindMat->id_blind = $blind->id; $blindMat->id_materials = $mat; $blindMat->save(); } } //Debag::prn($_POST['infoPage']); $zag = PageToBlind::find()->where(['id_blind' => $blind->id])->all(); foreach ($zag as $v) { PageBlinds::deleteAll(['id' => $v->id_pages]); } PageToBlind::deleteAll(['id_blind' => $blind->id]); if (isset($_POST['infoPage'])) { foreach ($_POST['infoPage'] as $v) { $input = explode('*', $v); $s = str_replace('_', ' ', $input[0]); $pb = PageBlinds::find()->where(['name' => $s])->one(); if (empty($pb->id)) { $pb = new PageBlinds(); $pb->name = $s; $pb->save(); } //$pb->name = $input[0]; //$pb->save(); unset($input[0]); $del = PageToBlind::deleteAll(['id_pages' => $pb->id]); $ptb = new PageToBlind(); $ptb->id_pages = $pb->id; $ptb->id_blind = $blind->id; $ptb->save(); $cat = PageItem::deleteAll(['id_page' => $pb->id]); foreach ($input as $in) { //Debag::prn($in); $pageItem = new PageItem(); $item = explode('_', $in); if ($item[1] == 'materials') { $pageItem->id_page = $pb->id; $pageItem->id_item = $item[0]; $pageItem->item_type = 'materials'; } else { $pageTitle = PageForTitle::find()->where(['title' => $item[0]])->one(); if (empty($pageTitle->id)) { $pageTitle = new PageForTitle(); $pageTitle->title = $item[0]; $pageTitle->save(); } /*$pageTitle = new PageForTitle(); $pageTitle->title = $item[0]; $pageTitle->save();*/ $pageItem->id_page = $pb->id; $pageItem->id_item = $pageTitle->id; $pageItem->item_type = 'zagolovok'; } $pageItem->id_blind = $blind->id; $pageItem->save(); } } } else { } return $this->redirect(['update', 'id' => $blind->id]); } else { return $this->render('update', ['model' => $model, 'categories' => $arr_cat, 'catselect' => $arr_catid, 'materials' => $arr_materials, 'materialselect' => $arr_supl, 'media' => $media, 'img' => $imgages, 'bmt' => $blindMaterialHeader, 'blind' => $blind, 'addMat' => $addMaterials]); } }
$zag = \common\models\PageForTitle::getName($pg->id_item); $html .= '<tr class="itemPage" page-id="' . $title . '" materials-id="' . $zag . '" item-type="zagolovok"><td colspan="7">' . $zag . '</td><td><a class="delSuplies" href="#">Удалить</a></td></tr>'; $inp .= '*' . $zag . '_zagolovok'; } } $html .= '</table> <a page-id="' . $title . '"data-toggle="modal" data-target="#myModal4" href="#" class="attachMaterialList">Прикрепить материалы списком</a> | <a page-id="' . $title . '"data-toggle="modal" data-target="#myModal3" href="#" class="attachMaterial">Прикрепить материал</a> | <a class="attachZag" data-toggle="modal" data-target="#myModal2" href = "#" page-id="' . $title . '">Добавить заголовок</a> <input id="input_' . $title . '" type="hidden" name="infoPage[]" value="' . $inp . '"> </div>'; } else { $title = \common\models\PageBlinds::getNameTitleAdmin($p->id_pages); $inp = $title; $title = str_replace(' ', '_', $title); $ul .= '<li><a href="#panel' . $title . '"><input id-page="' . $title . '" type="text" class="insetName" value="' . $inp . '"/></a><span page-id="' . $title . '" class="delPages">x</span></li>'; $page = \common\models\PageItem::find()->where(['id_page' => $p->id_pages])->all(); $html .= '<div id="panel' . $title . '" class="tabPanel"><h3>' . $inp . '</h3>'; $html .= '<table id="t_' . $title . '" class="table table-bordered">'; foreach ($page as $pg) { if ($pg->item_type == 'materials') { $html .= \common\classes\Supplies::getOneAddSupplies($pg->id_item, $title); $inp .= '*' . $pg->id_item . '_materials'; } else { $zag = \common\models\PageForTitle::getName($pg->id_item); $html .= '<tr class="itemPage" page-id="' . $title . '" materials-id="' . $zag . '" item-type="zagolovok"><td colspan="7">' . $zag . '</td><td><a class="delSuplies" href="#">Удалить</a></td></tr>'; $inp .= '*' . $zag . '_zagolovok'; } } $html .= '</table> <a page-id="' . $title . '"data-toggle="modal" data-target="#myModal4" href="#" class="attachMaterialList">Прикрепить материалы списком</a> | <a page-id="' . $title . '"data-toggle="modal" data-target="#myModal3" href="#" class="attachMaterial">Прикрепить материал</a> | <a class="attachZag" data-toggle="modal" data-target="#myModal2" href = "#" page-id="' . $title . '">Добавить заголовок</a> <input id="input_' . $title . '" type="hidden" name="infoPage[]" value="' . $inp . '">
public static function getSupplies($id, $idPage = 0) { if ($idPage == 0) { $page = PageToBlind::find()->where(['id_blind' => $id])->one(); $idPage = $page->id_pages; } $allPagess = PageToBlind::find()->where(['id_blind' => $id])->all(); /*Debag::prn($allPagess);*/ $i = 0; $count = count($allPagess); foreach ($allPagess as $ap) { if ($ap->id_pages == $idPage) { $next = $allPagess[$i + 1]->id_pages; if ($i == 0) { $end = end($allPagess); $end = $end->id_pages; } else { if ($i == $count - 1) { $next = $allPagess[0]->id_pages; } $end = $allPagess[$i - 1]->id_pages; } } $i++; } $html = ' <div class="title"> <b>Вызов</b> <span>замерщика с образцами</span> бесплатный<br> Бесплатное <span>3D моделирование жалюзей</span> <b>на ваших окнах</b> </div> <a href="#" class="close"></a> <a href="#" class="cause">Вызвать замерщика</a> <div class="popup_content"> <div class="prices">'; $html .= PageBlinds::getNameTitle($idPage); if ($count > 1) { $html .= '<a href="#" id-page="' . $end . '" id-blind="' . $id . '" class="left pageChange">' . PageBlinds::getNameTitle($end) . '</a> <a href="#" id-page="' . $next . '" id-blind="' . $id . '" class="right pageChange">' . PageBlinds::getNameTitle($next) . '</a>'; } $html .= '</div>'; //$supplies = BlindIdmaterials::find()->where(['id_blind'=>$id])->all(); $supplies = PageItem::find()->where(['id_page' => $idPage])->all(); /*$blm = BlindMaterials::find()->where(['id_blind'=>$id])->all(); foreach($blm as $b){ $arrBlmID[] = $b->id_materials; }*/ $k = 1; $j = 0; foreach ($supplies as $v) { //$supl = \backend\modules\supplies\models\Supplies::find()->where(['id'=>$v->id_materials])->one(); if ($v->item_type == 'zagolovok') { $zag = PageForTitle::getName($v->id_item); if ($j != 0) { $html .= "</div></div></div>"; } else { $j = 1; } $html .= '<div class="group"> <div class="title">' . $zag . '</div> <div class="group_items">'; $k = 1; continue; //echo self::getTitle($id,$v->id_materials).'<br>'; } $supl = \backend\modules\supplies\models\Supplies::find()->where(['id' => $v->id_item])->one(); if ($k == 1) { $html .= '<div class="line">'; } $html .= '<div class="item"> <a href="#"><img src="' . $supl->images . '" alt="" width="163px"/></a> <span>Код: ' . $supl->code . '</span> <a href="#" class="order" blind-id="' . $id . '" suuples-id="' . $v->id_item . '">Заказать</a> </div>'; if ($k == 5) { $html .= '</div>'; $k = 1; } if ($v->item_type == 'zagolovok') { $html .= ''; //echo self::getTitle($id,$v->id_materials).'<br>'; } $k++; } $html .= '</div></div></div></div>'; return $html; }
}], ['attribute' => 'color', 'format' => 'raw', 'value' => function ($model) { $allColor = \common\models\Color::find()->all(); $color = \common\models\Color::find()->where(['id' => $model->color])->one(); $html = Html::hiddenInput('color_' . $model->id, $model->color, ['id' => 'color_' . $model->id, 'class' => 'colorInput']); $html .= '<div class="selectColor" style = "width:100px;height:20px;background-color: ' . $color->value . '"></div>'; $html .= "<div class='allColor'>"; foreach ($allColor as $c) { $html .= "<div class='selectOnecolor' color='{$c->value}' data-sup-id='{$model->id}' data-id='{$c->id}' style='background-color:{$c->value};width: 100px;height: 20px;margin: 5px'></div>"; } $html .= "</div>"; return $html; }, 'filter' => "<input id='colorId' type='hidden' name='SuppliesSearch[color]' value='" . $_GET['SuppliesSearch']['color'] . "'>" . $color], ['attribute' => 'price', 'format' => 'raw', 'value' => function ($model) { return Html::textInput('price_' . $model->id, $model->price, ['id' => 'price_' . $model->id, 'class' => 'priceInput', 'style' => 'width:120px;']); //return "<input type='text' value='$model->code' name='code'>"; }], ['class' => DataColumn::className(), 'header' => 'Прикреплен', 'format' => 'raw', 'value' => function ($model) { $pageItem = \common\models\PageItem::find()->where(['id_item' => $model->id, 'item_type' => 'materials'])->all(); foreach ($pageItem as $p) { $arr[] = $p->id_blind; } if (!empty($arr)) { $arr = array_unique($arr); $html = ''; $html .= '<div class="blindToSupliesOne" style="width: 200px">'; $k = 0; foreach ($arr as $p) { if ($p) { $title = \backend\modules\blind\models\Blind::find()->where(['id' => $p])->one(); if ($k == 2) { $html .= '</div><div class="blindToSuplies">'; } $html .= '<li>' . $title->name . '<a href="#" class="undock" id-mat="' . $model->id . '" id-page="' . $p . '"> -</a></li>';
public static function getCount($id) { //Debag::prn($id); //$sup = Supplies::find()->where(['type_blind' => $id])->all(); $page2BlindID = PageToBlind::find()->where(['id_blind' => $id])->all(); $supIds = []; foreach ($page2BlindID as $page) { $s = PageItem::find()->where(['id_page' => $page->id_pages, 'item_type' => 'materials'])->all(); $supIds = array_merge($supIds, $s); } $colors = []; $materials = []; $count = []; $prices = []; foreach ($supIds as $s) { $sup = Supplies::find()->where(['id' => $s->id_item])->one(); //Debag::prn($sup); $colors[] = $sup->color; $materials[] = $sup->type_mat; $prices[] = $sup->price; } $colors = count(array_unique($colors)); $materials = count(array_unique($materials)); //Debag::prn($prices); if (isset($prices) && !empty($prices)) { $prices = min($prices); $count['min_price'] = $prices; } $count['colors'] = $colors; $count['materials'] = $materials; //$count['min_price']= $prices; // Debag::prn($colors); return $count; }