@@ -10,146 +10,146 @@ discard block |
||
| 10 | 10 | */ |
| 11 | 11 | class CartController extends Controller { |
| 12 | 12 | |
| 13 | - public function indexAction() { |
|
| 13 | + public function indexAction() { |
|
| 14 | 14 | $cart = ''; |
| 15 | 15 | $deliverys = \Ecommerce\Delivery::getList(['order' => ['weight', 'ASC']]); |
| 16 | 16 | $payTypes = \Ecommerce\PayType::getList(['order' => ['weight', 'ASC']]); |
| 17 | 17 | if (!empty($_SESSION['cart']['cart_id'])) { |
| 18 | - $cart = Ecommerce\Cart::get($_SESSION['cart']['cart_id']); |
|
| 19 | - if (!empty($_POST)) { |
|
| 18 | + $cart = Ecommerce\Cart::get($_SESSION['cart']['cart_id']); |
|
| 19 | + if (!empty($_POST)) { |
|
| 20 | 20 | $error = false; |
| 21 | 21 | if (!Users\User::$cur->id) { |
| 22 | - $user_id = $this->Users->registration($_POST, true); |
|
| 23 | - if (!$user_id) { |
|
| 22 | + $user_id = $this->Users->registration($_POST, true); |
|
| 23 | + if (!$user_id) { |
|
| 24 | 24 | $error = true; |
| 25 | - } else { |
|
| 25 | + } else { |
|
| 26 | 26 | $user = Users\User::get($user_id); |
| 27 | - } |
|
| 27 | + } |
|
| 28 | 28 | } else { |
| 29 | - $user = Users\User::$cur; |
|
| 29 | + $user = Users\User::$cur; |
|
| 30 | 30 | } |
| 31 | 31 | $ids = []; |
| 32 | 32 | if (!empty($_POST['cartItems'])) { |
| 33 | - foreach ($_POST['cartItems'] as $cartItemId => $cartItemCont) { |
|
| 33 | + foreach ($_POST['cartItems'] as $cartItemId => $cartItemCont) { |
|
| 34 | 34 | $cartItem = \Ecommerce\Cart\Item::get((int) $cartItemId); |
| 35 | 35 | if (!$cartItem) { |
| 36 | - continue; |
|
| 36 | + continue; |
|
| 37 | 37 | } |
| 38 | 38 | if ($cartItem->cart_id != $cart->id) { |
| 39 | - continue; |
|
| 39 | + continue; |
|
| 40 | 40 | } |
| 41 | 41 | $count = (float) $cartItemCont; |
| 42 | 42 | if ($count < 0.001) { |
| 43 | - $count = 1; |
|
| 43 | + $count = 1; |
|
| 44 | 44 | } |
| 45 | 45 | $cartItem->count = $count; |
| 46 | 46 | $cartItem->save(); |
| 47 | 47 | $ids[] = $cartItemId; |
| 48 | - } |
|
| 48 | + } |
|
| 49 | 49 | } |
| 50 | 50 | foreach ($cart->cartItems as $cartItem) { |
| 51 | - if (!in_array($cartItem->id, $ids)) { |
|
| 51 | + if (!in_array($cartItem->id, $ids)) { |
|
| 52 | 52 | $cartItem->delete(); |
| 53 | - } |
|
| 53 | + } |
|
| 54 | 54 | } |
| 55 | 55 | $cart = Ecommerce\Cart::get($cart->id); |
| 56 | 56 | if (!$cart->cartItems) { |
| 57 | - $error = true; |
|
| 58 | - //Tools::redirect('/ecommerce', 'Ваша корзина пуста'); |
|
| 57 | + $error = true; |
|
| 58 | + //Tools::redirect('/ecommerce', 'Ваша корзина пуста'); |
|
| 59 | 59 | } |
| 60 | 60 | if (empty($this->module->config['sell_over_warehouse'])) { |
| 61 | - foreach ($cart->cartItems as $cartitem) { |
|
| 61 | + foreach ($cart->cartItems as $cartitem) { |
|
| 62 | 62 | $warecount = $cartitem->price->offer->warehouseCount($cart->id); |
| 63 | 63 | if ($cartitem->count > $warecount) { |
| 64 | - $error = true; |
|
| 65 | - Msg::add('Вы заказали <b>' . $cartitem->item->name . '</b> больше чем есть на складе. на складе: <b>' . $warecount . '</b>', 'danger'); |
|
| 64 | + $error = true; |
|
| 65 | + Msg::add('Вы заказали <b>' . $cartitem->item->name . '</b> больше чем есть на складе. на складе: <b>' . $warecount . '</b>', 'danger'); |
|
| 66 | + } |
|
| 66 | 67 | } |
| 67 | - } |
|
| 68 | 68 | } |
| 69 | 69 | if ($deliverys && empty($deliverys[$_POST['delivery']])) { |
| 70 | - $error = 1; |
|
| 71 | - Msg::add('Выберите способ доставки', 'danger'); |
|
| 70 | + $error = 1; |
|
| 71 | + Msg::add('Выберите способ доставки', 'danger'); |
|
| 72 | 72 | } elseif ($deliverys && !empty($deliverys[$_POST['delivery']])) { |
| 73 | - $cart->delivery_id = $_POST['delivery']; |
|
| 74 | - foreach ($deliverys[$cart->delivery_id]->fields as $field) { |
|
| 73 | + $cart->delivery_id = $_POST['delivery']; |
|
| 74 | + foreach ($deliverys[$cart->delivery_id]->fields as $field) { |
|
| 75 | 75 | if (empty($_POST['deliveryFields'][$field->id]) && $field->required) { |
| 76 | - $error = 1; |
|
| 77 | - Msg::add('Вы не указали: ' . $field->name, 'danger'); |
|
| 76 | + $error = 1; |
|
| 77 | + Msg::add('Вы не указали: ' . $field->name, 'danger'); |
|
| 78 | + } |
|
| 78 | 79 | } |
| 79 | - } |
|
| 80 | 80 | } |
| 81 | 81 | if ($payTypes && (empty($_POST['payType']) || empty($payTypes[$_POST['payType']]))) { |
| 82 | - $error = 1; |
|
| 83 | - Msg::add('Выберите способ оплаты', 'danger'); |
|
| 82 | + $error = 1; |
|
| 83 | + Msg::add('Выберите способ оплаты', 'danger'); |
|
| 84 | 84 | } elseif ($payTypes && !empty($payTypes[$_POST['payType']])) { |
| 85 | - $payType = $payTypes[$_POST['payType']]; |
|
| 86 | - $cart->paytype_id = $payType->id; |
|
| 85 | + $payType = $payTypes[$_POST['payType']]; |
|
| 86 | + $cart->paytype_id = $payType->id; |
|
| 87 | 87 | } else { |
| 88 | - $payType = null; |
|
| 88 | + $payType = null; |
|
| 89 | 89 | } |
| 90 | 90 | foreach (\Ecommerce\UserAdds\Field::getList() as $field) { |
| 91 | - if (empty($_POST['userAdds']['fields'][$field->id]) && $field->required) { |
|
| 91 | + if (empty($_POST['userAdds']['fields'][$field->id]) && $field->required) { |
|
| 92 | 92 | $error = 1; |
| 93 | 93 | Msg::add('Вы не указали: ' . $field->name, 'danger'); |
| 94 | - } |
|
| 94 | + } |
|
| 95 | 95 | } |
| 96 | 96 | if (!empty($_POST['discounts']['card_item_id'])) { |
| 97 | - $userCard = \Ecommerce\Card\Item::get((int) $_POST['discounts']['card_item_id']); |
|
| 98 | - if (!$userCard) { |
|
| 97 | + $userCard = \Ecommerce\Card\Item::get((int) $_POST['discounts']['card_item_id']); |
|
| 98 | + if (!$userCard) { |
|
| 99 | 99 | $error = true; |
| 100 | 100 | Msg::add('Такой карты не существует', 'danger'); |
| 101 | - } elseif ($userCard->user_id != $user->id) { |
|
| 101 | + } elseif ($userCard->user_id != $user->id) { |
|
| 102 | 102 | $error = true; |
| 103 | 103 | Msg::add('Это не ваша карта', 'danger'); |
| 104 | - } else { |
|
| 104 | + } else { |
|
| 105 | 105 | $cart->card_item_id = $userCard->id; |
| 106 | - } |
|
| 106 | + } |
|
| 107 | 107 | } |
| 108 | 108 | $cart->save(); |
| 109 | 109 | if (!$error && !empty($_POST['action']) && $_POST['action'] = 'order') { |
| 110 | - $cart->user_id = $user->user_id; |
|
| 111 | - $this->module->parseFields($_POST['userAdds']['fields'], $cart); |
|
| 112 | - if ($payTypes && !empty($payTypes[$cart->paytype_id]) && !empty($_POST['deliveryFields'])) { |
|
| 110 | + $cart->user_id = $user->user_id; |
|
| 111 | + $this->module->parseFields($_POST['userAdds']['fields'], $cart); |
|
| 112 | + if ($payTypes && !empty($payTypes[$cart->paytype_id]) && !empty($_POST['deliveryFields'])) { |
|
| 113 | 113 | $this->module->parseDeliveryFields($_POST['deliveryFields'], $cart, $deliverys[$cart->delivery_id]->fields); |
| 114 | - } |
|
| 115 | - $cart->cart_status_id = 2; |
|
| 116 | - $cart->comment = !empty($_POST['comment']) ? htmlspecialchars($_POST['comment']) : ''; |
|
| 117 | - $cart->date_status = date('Y-m-d H:i:s'); |
|
| 118 | - $cart->complete_data = date('Y-m-d H:i:s'); |
|
| 119 | - $cart->warehouse_block = 1; |
|
| 120 | - $cart->save(); |
|
| 114 | + } |
|
| 115 | + $cart->cart_status_id = 2; |
|
| 116 | + $cart->comment = !empty($_POST['comment']) ? htmlspecialchars($_POST['comment']) : ''; |
|
| 117 | + $cart->date_status = date('Y-m-d H:i:s'); |
|
| 118 | + $cart->complete_data = date('Y-m-d H:i:s'); |
|
| 119 | + $cart->warehouse_block = 1; |
|
| 120 | + $cart->save(); |
|
| 121 | 121 | |
| 122 | - $cart = \Ecommerce\Cart::get($cart->id); |
|
| 123 | - foreach ($cart->cartItems as $cartItem) { |
|
| 122 | + $cart = \Ecommerce\Cart::get($cart->id); |
|
| 123 | + foreach ($cart->cartItems as $cartItem) { |
|
| 124 | 124 | $cartItem->discount = $cartItem->discount(); |
| 125 | 125 | $cartItem->final_price = $cartItem->price->price - $cartItem->discount; |
| 126 | 126 | $cartItem->save(); |
| 127 | - } |
|
| 128 | - $cart = \Ecommerce\Cart::get($cart->id); |
|
| 129 | - if (!empty(\App::$cur->ecommerce->config['notify_mail'])) { |
|
| 127 | + } |
|
| 128 | + $cart = \Ecommerce\Cart::get($cart->id); |
|
| 129 | + if (!empty(\App::$cur->ecommerce->config['notify_mail'])) { |
|
| 130 | 130 | $text = 'Перейдите в админ панель чтобы просмотреть новый заказ <a href = "http://' . idn_to_utf8(INJI_DOMAIN_NAME) . '/admin/ecommerce/Cart">Админ панель</a>'; |
| 131 | 131 | $title = 'Новый заказ в интернет магазине на сайте ' . idn_to_utf8(INJI_DOMAIN_NAME); |
| 132 | 132 | \Tools::sendMail('noreply@' . INJI_DOMAIN_NAME, \App::$cur->ecommerce->config['notify_mail'], $title, $text); |
| 133 | - } |
|
| 134 | - if ($this->notifications) { |
|
| 133 | + } |
|
| 134 | + if ($this->notifications) { |
|
| 135 | 135 | $notification = new Notifications\Notification(); |
| 136 | 136 | $notification->name = 'Новый заказ в интернет магазине на сайте ' . idn_to_utf8(INJI_DOMAIN_NAME); |
| 137 | 137 | $notification->text = 'Перейдите в админ панель чтобы просмотреть новый заказ'; |
| 138 | 138 | $notification->chanel_id = $this->notifications->getChanel('Ecommerce-orders')->id; |
| 139 | 139 | $notification->save(); |
| 140 | - } |
|
| 141 | - $handlers = $this->ecommerce->getSnippets('payTypeHandler'); |
|
| 142 | - $redirect = ['/ecommerce/cart/success']; |
|
| 143 | - if ($payType && !empty($handlers[$payType->handler]['handler'])) { |
|
| 140 | + } |
|
| 141 | + $handlers = $this->ecommerce->getSnippets('payTypeHandler'); |
|
| 142 | + $redirect = ['/ecommerce/cart/success']; |
|
| 143 | + if ($payType && !empty($handlers[$payType->handler]['handler'])) { |
|
| 144 | 144 | $newRedirect = $handlers[$payType->handler]['handler']($cart); |
| 145 | 145 | if (!empty($newRedirect)) { |
| 146 | - $redirect = $newRedirect; |
|
| 146 | + $redirect = $newRedirect; |
|
| 147 | + } |
|
| 147 | 148 | } |
| 148 | - } |
|
| 149 | - unset($_SESSION['cart']['cart_id']); |
|
| 150 | - call_user_func_array(['Tools', 'redirect'], $redirect); |
|
| 149 | + unset($_SESSION['cart']['cart_id']); |
|
| 150 | + call_user_func_array(['Tools', 'redirect'], $redirect); |
|
| 151 | + } |
|
| 151 | 152 | } |
| 152 | - } |
|
| 153 | 153 | } |
| 154 | 154 | $this->view->setTitle('Корзина'); |
| 155 | 155 | $bread = []; |
@@ -162,12 +162,12 @@ discard block |
||
| 162 | 162 | 'href' => '/ecommerce/cart' |
| 163 | 163 | ]; |
| 164 | 164 | $this->view->page(['data' => compact('cart', 'items', 'deliverys', 'payTypes', 'packItem', 'bread')]); |
| 165 | - } |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | - public function orderDetailAction($id = 0) { |
|
| 167 | + public function orderDetailAction($id = 0) { |
|
| 168 | 168 | $cart = Ecommerce\Cart::get((int) $id); |
| 169 | 169 | if ($cart->user_id != Users\User::$cur->id) { |
| 170 | - $this->url->redirect('/', 'Это не ваша корзина'); |
|
| 170 | + $this->url->redirect('/', 'Это не ваша корзина'); |
|
| 171 | 171 | } |
| 172 | 172 | $bread[] = [ |
| 173 | 173 | 'text' => 'Каталог', |
@@ -183,54 +183,54 @@ discard block |
||
| 183 | 183 | ]; |
| 184 | 184 | $this->view->setTitle('Заказ №' . $cart->id); |
| 185 | 185 | $this->view->page(['data' => compact('cart', 'bread')]); |
| 186 | - } |
|
| 186 | + } |
|
| 187 | 187 | |
| 188 | - public function continueAction($id = 0) { |
|
| 188 | + public function continueAction($id = 0) { |
|
| 189 | 189 | $cart = \Ecommerce\Cart::get((int) $id); |
| 190 | 190 | if ($cart->user_id != Users\User::$cur->id) { |
| 191 | - Tools::redirect('/', 'Это не ваша корзина'); |
|
| 191 | + Tools::redirect('/', 'Это не ваша корзина'); |
|
| 192 | 192 | } |
| 193 | 193 | if ($cart->cart_status_id > 1) { |
| 194 | - Tools::redirect('/', 'Корзина уже оформлена'); |
|
| 194 | + Tools::redirect('/', 'Корзина уже оформлена'); |
|
| 195 | 195 | } |
| 196 | 196 | $_SESSION['cart']['cart_id'] = $cart->id; |
| 197 | 197 | Tools::redirect('/ecommerce/cart'); |
| 198 | - } |
|
| 198 | + } |
|
| 199 | 199 | |
| 200 | - public function deleteAction($id = 0) { |
|
| 200 | + public function deleteAction($id = 0) { |
|
| 201 | 201 | $cart = \Ecommerce\Cart::get((int) $id); |
| 202 | 202 | if ($cart->user_id != Users\User::$cur->id) { |
| 203 | - Tools::redirect('/', 'Это не ваша корзина'); |
|
| 203 | + Tools::redirect('/', 'Это не ваша корзина'); |
|
| 204 | 204 | } |
| 205 | 205 | if ($cart->cart_status_id > 1) { |
| 206 | - Tools::redirect('/', 'Корзина уже оформлена'); |
|
| 206 | + Tools::redirect('/', 'Корзина уже оформлена'); |
|
| 207 | 207 | } |
| 208 | 208 | if (!empty($_SESSION['cart']['cart_id']) && $_SESSION['cart']['cart_id'] == $cart->id) { |
| 209 | - unset($_SESSION['cart']['cart_id']); |
|
| 209 | + unset($_SESSION['cart']['cart_id']); |
|
| 210 | 210 | } |
| 211 | 211 | $cart->delete(); |
| 212 | 212 | Tools::redirect('/users/cabinet/ecommerceOrdersHistory', 'Корзина была удалена', 'success'); |
| 213 | - } |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | - public function refillAction($id = 0) { |
|
| 215 | + public function refillAction($id = 0) { |
|
| 216 | 216 | $cart = \Ecommerce\Cart::get((int) $id); |
| 217 | 217 | if ($cart->user_id != Users\User::$cur->id) { |
| 218 | - Tools::redirect('/', 'Это не ваша корзина'); |
|
| 218 | + Tools::redirect('/', 'Это не ваша корзина'); |
|
| 219 | 219 | } |
| 220 | 220 | if (!empty($_SESSION['cart']['cart_id'])) { |
| 221 | - unset($_SESSION['cart']['cart_id']); |
|
| 221 | + unset($_SESSION['cart']['cart_id']); |
|
| 222 | 222 | } |
| 223 | 223 | $newCart = $this->ecommerce->getCurCart(); |
| 224 | 224 | foreach ($cart->cartItems as $cartitem) { |
| 225 | - $newCart->addItem($cartitem->item_offer_price_id, $cartitem->count); |
|
| 225 | + $newCart->addItem($cartitem->item_offer_price_id, $cartitem->count); |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | $newCart->save(); |
| 229 | 229 | |
| 230 | 230 | Tools::redirect('/ecommerce/cart/'); |
| 231 | - } |
|
| 231 | + } |
|
| 232 | 232 | |
| 233 | - public function successAction() { |
|
| 233 | + public function successAction() { |
|
| 234 | 234 | $bread = []; |
| 235 | 235 | $bread[] = [ |
| 236 | 236 | 'text' => 'Каталог', |
@@ -246,70 +246,70 @@ discard block |
||
| 246 | 246 | ]; |
| 247 | 247 | $this->view->setTitle('Заказ принят'); |
| 248 | 248 | $this->view->page(['data' => compact('bread')]); |
| 249 | - } |
|
| 249 | + } |
|
| 250 | 250 | |
| 251 | - public function addAction() { |
|
| 251 | + public function addAction() { |
|
| 252 | 252 | $result = new Server\Result(); |
| 253 | 253 | if (empty($_GET['itemOfferPriceId'])) { |
| 254 | - $result->success = false; |
|
| 255 | - $result->content = 'Произошла непредвиденная ошибка при добавлении товара'; |
|
| 256 | - $result->send(); |
|
| 254 | + $result->success = false; |
|
| 255 | + $result->content = 'Произошла непредвиденная ошибка при добавлении товара'; |
|
| 256 | + $result->send(); |
|
| 257 | 257 | } |
| 258 | 258 | $price = \Ecommerce\Item\Offer\Price::get((int) $_GET['itemOfferPriceId']); |
| 259 | 259 | if (!$price) { |
| 260 | - $result->success = false; |
|
| 261 | - $result->content = 'Такой цены не найдено'; |
|
| 262 | - $result->send(); |
|
| 260 | + $result->success = false; |
|
| 261 | + $result->content = 'Такой цены не найдено'; |
|
| 262 | + $result->send(); |
|
| 263 | 263 | } |
| 264 | 264 | $item = $price->offer->item; |
| 265 | 265 | |
| 266 | 266 | if (!$item) { |
| 267 | - $result->success = false; |
|
| 268 | - $result->content = 'Такого товара не существует'; |
|
| 269 | - $result->send(); |
|
| 267 | + $result->success = false; |
|
| 268 | + $result->content = 'Такого товара не существует'; |
|
| 269 | + $result->send(); |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | $item->sales ++; |
| 273 | 273 | $item->save(); |
| 274 | 274 | |
| 275 | 275 | if (empty($_GET['count'])) |
| 276 | - $count = 1; |
|
| 276 | + $count = 1; |
|
| 277 | 277 | else |
| 278 | - $count = (float) $_GET['count']; |
|
| 278 | + $count = (float) $_GET['count']; |
|
| 279 | 279 | |
| 280 | 280 | $cart = $this->ecommerce->getCurCart(); |
| 281 | 281 | $stages = Ecommerce\Cart\Stage::getList(); |
| 282 | 282 | if (empty($this->module->config['sell_over_warehouse']) && $price->offer->warehouseCount() < $count) { |
| 283 | - $result->success = false; |
|
| 284 | - $result->content = 'На складе недостаточно товара! Доступно: ' . $price->offer->warehouseCount(); |
|
| 285 | - $result->send(); |
|
| 283 | + $result->success = false; |
|
| 284 | + $result->content = 'На складе недостаточно товара! Доступно: ' . $price->offer->warehouseCount(); |
|
| 285 | + $result->send(); |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | $isset = false; |
| 289 | 289 | foreach ($cart->cartItems as $cartItem) { |
| 290 | - if ($cartItem->item_id == $item->id && $cartItem->item_offer_price_id == $price->id) { |
|
| 290 | + if ($cartItem->item_id == $item->id && $cartItem->item_offer_price_id == $price->id) { |
|
| 291 | 291 | $cartItem->count += $count; |
| 292 | 292 | $cartItem->save(); |
| 293 | 293 | $isset = true; |
| 294 | 294 | break; |
| 295 | - } |
|
| 295 | + } |
|
| 296 | 296 | } |
| 297 | 297 | if (!$isset) { |
| 298 | - $cart->addItem($price->id, $count); |
|
| 298 | + $cart->addItem($price->id, $count); |
|
| 299 | 299 | } |
| 300 | 300 | $cart->date_last_activ = date('Y-m-d H:i:s'); |
| 301 | 301 | $cart->calc(); |
| 302 | 302 | $result->successMsg = '<a href="/ecommerce/view/' . $item->id . '">' . $item->name() . ($price->offer->name() ? ' (' . $price->offer->name() . ')' : '') . '</a> добавлен <a href="/ecommerce/cart">в корзину покупок</a>!'; |
| 303 | 303 | $result->send(); |
| 304 | - } |
|
| 304 | + } |
|
| 305 | 305 | |
| 306 | - public function getcartAction() { |
|
| 306 | + public function getcartAction() { |
|
| 307 | 307 | $result = new Server\Result(); |
| 308 | 308 | ob_start(); |
| 309 | 309 | $this->view->widget('Ecommerce\cart'); |
| 310 | 310 | $result->content = ob_get_contents(); |
| 311 | 311 | ob_end_clean(); |
| 312 | 312 | $result->send(); |
| 313 | - } |
|
| 313 | + } |
|
| 314 | 314 | |
| 315 | 315 | } |
@@ -13,65 +13,65 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | class Delivery extends \Model { |
| 15 | 15 | |
| 16 | - public static $objectName = 'Доставка'; |
|
| 17 | - public static $cols = [ |
|
| 18 | - //Основные параметры |
|
| 19 | - 'name' => ['type' => 'text'], |
|
| 20 | - 'price' => ['type' => 'decimal'], |
|
| 21 | - 'currency_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'currency'], |
|
| 22 | - 'price_text' => ['type' => 'textarea'], |
|
| 23 | - 'max_cart_price' => ['type' => 'decimal'], |
|
| 24 | - 'icon_file_id' => ['type' => 'image'], |
|
| 25 | - 'info' => ['type' => 'html'], |
|
| 26 | - 'disabled' => ['type' => 'bool'], |
|
| 27 | - //Системные |
|
| 28 | - 'weight' => ['type' => 'number'], |
|
| 29 | - 'date_create' => ['type' => 'dateTime'], |
|
| 30 | - //Менеджеры |
|
| 31 | - 'field' => ['type' => 'dataManager', 'relation' => 'fields'], |
|
| 32 | - 'priceChanger' => ['type' => 'dataManager', 'relation' => 'prices'] |
|
| 33 | - ]; |
|
| 34 | - public static $labels = [ |
|
| 35 | - 'name' => 'Название', |
|
| 36 | - 'price' => 'Стоимость', |
|
| 37 | - 'price_text' => 'Текстовое описание стоимости (отображается вместо цены)', |
|
| 38 | - 'max_cart_price' => 'Басплатно при', |
|
| 39 | - 'icon_file_id' => 'Иконка', |
|
| 40 | - 'currency_id' => 'Валюта', |
|
| 41 | - 'info' => 'Дополнительная информация', |
|
| 42 | - 'priceChanger' => 'Градация стоимости', |
|
| 43 | - 'field' => 'Поля', |
|
| 44 | - 'disabled' => 'Отключено', |
|
| 45 | - ]; |
|
| 46 | - public static $dataManagers = [ |
|
| 47 | - 'manager' => [ |
|
| 48 | - 'name' => 'Варианты доставки', |
|
| 49 | - 'cols' => [ |
|
| 50 | - 'name', |
|
| 51 | - 'price', |
|
| 52 | - 'currency_id', |
|
| 53 | - 'max_cart_price', |
|
| 54 | - 'disabled', |
|
| 55 | - 'field', |
|
| 56 | - 'priceChanger', |
|
| 57 | - ], |
|
| 58 | - 'sortMode' => true |
|
| 59 | - ], |
|
| 60 | - ]; |
|
| 61 | - public static $forms = [ |
|
| 62 | - 'manager' => [ |
|
| 63 | - 'map' => [ |
|
| 64 | - ['name', 'disabled'], |
|
| 65 | - ['max_cart_price', 'icon_file_id'], |
|
| 66 | - ['price', 'currency_id'], |
|
| 67 | - ['price_text'], |
|
| 68 | - ['info'], |
|
| 69 | - ['priceChanger'], |
|
| 70 | - ['field'] |
|
| 71 | - ] |
|
| 72 | - ]]; |
|
| 16 | + public static $objectName = 'Доставка'; |
|
| 17 | + public static $cols = [ |
|
| 18 | + //Основные параметры |
|
| 19 | + 'name' => ['type' => 'text'], |
|
| 20 | + 'price' => ['type' => 'decimal'], |
|
| 21 | + 'currency_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'currency'], |
|
| 22 | + 'price_text' => ['type' => 'textarea'], |
|
| 23 | + 'max_cart_price' => ['type' => 'decimal'], |
|
| 24 | + 'icon_file_id' => ['type' => 'image'], |
|
| 25 | + 'info' => ['type' => 'html'], |
|
| 26 | + 'disabled' => ['type' => 'bool'], |
|
| 27 | + //Системные |
|
| 28 | + 'weight' => ['type' => 'number'], |
|
| 29 | + 'date_create' => ['type' => 'dateTime'], |
|
| 30 | + //Менеджеры |
|
| 31 | + 'field' => ['type' => 'dataManager', 'relation' => 'fields'], |
|
| 32 | + 'priceChanger' => ['type' => 'dataManager', 'relation' => 'prices'] |
|
| 33 | + ]; |
|
| 34 | + public static $labels = [ |
|
| 35 | + 'name' => 'Название', |
|
| 36 | + 'price' => 'Стоимость', |
|
| 37 | + 'price_text' => 'Текстовое описание стоимости (отображается вместо цены)', |
|
| 38 | + 'max_cart_price' => 'Басплатно при', |
|
| 39 | + 'icon_file_id' => 'Иконка', |
|
| 40 | + 'currency_id' => 'Валюта', |
|
| 41 | + 'info' => 'Дополнительная информация', |
|
| 42 | + 'priceChanger' => 'Градация стоимости', |
|
| 43 | + 'field' => 'Поля', |
|
| 44 | + 'disabled' => 'Отключено', |
|
| 45 | + ]; |
|
| 46 | + public static $dataManagers = [ |
|
| 47 | + 'manager' => [ |
|
| 48 | + 'name' => 'Варианты доставки', |
|
| 49 | + 'cols' => [ |
|
| 50 | + 'name', |
|
| 51 | + 'price', |
|
| 52 | + 'currency_id', |
|
| 53 | + 'max_cart_price', |
|
| 54 | + 'disabled', |
|
| 55 | + 'field', |
|
| 56 | + 'priceChanger', |
|
| 57 | + ], |
|
| 58 | + 'sortMode' => true |
|
| 59 | + ], |
|
| 60 | + ]; |
|
| 61 | + public static $forms = [ |
|
| 62 | + 'manager' => [ |
|
| 63 | + 'map' => [ |
|
| 64 | + ['name', 'disabled'], |
|
| 65 | + ['max_cart_price', 'icon_file_id'], |
|
| 66 | + ['price', 'currency_id'], |
|
| 67 | + ['price_text'], |
|
| 68 | + ['info'], |
|
| 69 | + ['priceChanger'], |
|
| 70 | + ['field'] |
|
| 71 | + ] |
|
| 72 | + ]]; |
|
| 73 | 73 | |
| 74 | - public static function relations() { |
|
| 74 | + public static function relations() { |
|
| 75 | 75 | return [ |
| 76 | 76 | 'icon' => [ |
| 77 | 77 | 'model' => 'Files\File', |
@@ -92,6 +92,6 @@ discard block |
||
| 92 | 92 | 'col' => 'delivery_id' |
| 93 | 93 | ] |
| 94 | 94 | ]; |
| 95 | - } |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | 97 | } |
@@ -10,38 +10,38 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | class DashboardController extends adminController { |
| 12 | 12 | |
| 13 | - public function indexAction() { |
|
| 13 | + public function indexAction() { |
|
| 14 | 14 | $sections = $this->module->getSnippets('adminDashboardWidget'); |
| 15 | 15 | $this->view->setTitle('Панель управления'); |
| 16 | 16 | $this->view->page(['data' => compact('sections')]); |
| 17 | - } |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | - public function siteConfigAction() { |
|
| 19 | + public function siteConfigAction() { |
|
| 20 | 20 | if (isset($_POST['site_name'])) { |
| 21 | - $config = \App::$primary->config; |
|
| 22 | - $config['site']['name'] = $_POST['site_name']; |
|
| 23 | - $config['site']['company_name'] = $_POST['company_name']; |
|
| 24 | - $config['site']['email'] = $_POST['site_email']; |
|
| 25 | - $config['site']['keywords'] = $_POST['site_keywords']; |
|
| 26 | - $config['site']['description'] = $_POST['site_description']; |
|
| 27 | - $config['site']['domain'] = $_POST['site_domain']; |
|
| 28 | - if (isset($_POST['metatags'])) { |
|
| 21 | + $config = \App::$primary->config; |
|
| 22 | + $config['site']['name'] = $_POST['site_name']; |
|
| 23 | + $config['site']['company_name'] = $_POST['company_name']; |
|
| 24 | + $config['site']['email'] = $_POST['site_email']; |
|
| 25 | + $config['site']['keywords'] = $_POST['site_keywords']; |
|
| 26 | + $config['site']['description'] = $_POST['site_description']; |
|
| 27 | + $config['site']['domain'] = $_POST['site_domain']; |
|
| 28 | + if (isset($_POST['metatags'])) { |
|
| 29 | 29 | $config['site']['metatags'] = $_POST['metatags']; |
| 30 | - } |
|
| 31 | - if (!empty($_FILES['site_logo']['tmp_name'])) { |
|
| 30 | + } |
|
| 31 | + if (!empty($_FILES['site_logo']['tmp_name'])) { |
|
| 32 | 32 | $fileId = $this->Files->upload($_FILES['site_logo'], array('file_code' => 'site_logo')); |
| 33 | 33 | $config['site']['site_logo'] = Files\File::get($fileId)->path; |
| 34 | - } |
|
| 35 | - Config::save('app', $config); |
|
| 36 | - Tools::redirect('/admin/dashboard/siteConfig', 'Изменения сохранены', 'success'); |
|
| 34 | + } |
|
| 35 | + Config::save('app', $config); |
|
| 36 | + Tools::redirect('/admin/dashboard/siteConfig', 'Изменения сохранены', 'success'); |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | $this->view->setTitle('Общие настройки сайта'); |
| 40 | 40 | $this->view->page(); |
| 41 | - } |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - public function phpInfoAction() { |
|
| 43 | + public function phpInfoAction() { |
|
| 44 | 44 | $this->view->page(); |
| 45 | - } |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | 47 | } |
@@ -13,75 +13,75 @@ |
||
| 13 | 13 | |
| 14 | 14 | class Options extends \Migrations\Parser { |
| 15 | 15 | |
| 16 | - static $options; |
|
| 16 | + static $options; |
|
| 17 | 17 | |
| 18 | - public function parse() { |
|
| 18 | + public function parse() { |
|
| 19 | 19 | if (!Options::$options) { |
| 20 | - Options::$options = \Ecommerce\Item\Option::getList(); |
|
| 20 | + Options::$options = \Ecommerce\Item\Option::getList(); |
|
| 21 | 21 | } |
| 22 | 22 | $options = []; |
| 23 | 23 | $modelName = 'Ecommerce\Item\Option'; |
| 24 | 24 | foreach ($this->data['ЗначенияСвойства'] as $opt) { |
| 25 | - $optionId = \App::$cur->migrations->ids['parseIds']['Ecommerce\Item\Option'][$opt['Ид']]->object_id; |
|
| 26 | - if ($optionId && !isset(Options::$options[$optionId])) { |
|
| 25 | + $optionId = \App::$cur->migrations->ids['parseIds']['Ecommerce\Item\Option'][$opt['Ид']]->object_id; |
|
| 26 | + if ($optionId && !isset(Options::$options[$optionId])) { |
|
| 27 | 27 | Options::$options = \Ecommerce\Item\Option::getList(); |
| 28 | - } |
|
| 29 | - if (isset(Options::$options[$optionId]) && Options::$options[$optionId]->type == 'select') { |
|
| 28 | + } |
|
| 29 | + if (isset(Options::$options[$optionId]) && Options::$options[$optionId]->type == 'select') { |
|
| 30 | 30 | if (empty($options[$optionId])) { |
| 31 | - $options[$optionId] = []; |
|
| 31 | + $options[$optionId] = []; |
|
| 32 | 32 | } else { |
| 33 | - if (!Options::$options[$optionId]->advance) { |
|
| 33 | + if (!Options::$options[$optionId]->advance) { |
|
| 34 | 34 | Options::$options[$optionId]->advance = ['multi' => true]; |
| 35 | 35 | Options::$options[$optionId]->save(); |
| 36 | - } |
|
| 36 | + } |
|
| 37 | 37 | } |
| 38 | 38 | if ($opt['Значение'] && isset(\App::$cur->migrations->ids['parseIds']['Ecommerce\Item\Option\Item'][$opt['Значение']])) { |
| 39 | - $options[$optionId][] = \App::$cur->migrations->ids['parseIds']['Ecommerce\Item\Option\Item'][$opt['Значение']]->object_id; |
|
| 39 | + $options[$optionId][] = \App::$cur->migrations->ids['parseIds']['Ecommerce\Item\Option\Item'][$opt['Значение']]->object_id; |
|
| 40 | 40 | } |
| 41 | - } else { |
|
| 41 | + } else { |
|
| 42 | 42 | $options[$optionId] = $opt['Значение']; |
| 43 | - } |
|
| 43 | + } |
|
| 44 | 44 | } |
| 45 | 45 | $itemParams = \Ecommerce\Item\Param::getList(['where' => ['item_id', $this->model->id]]); |
| 46 | 46 | foreach ($itemParams as $itemParam) { |
| 47 | - if ($itemParam->item_option_id && !isset(Options::$options[$itemParam->item_option_id])) { |
|
| 47 | + if ($itemParam->item_option_id && !isset(Options::$options[$itemParam->item_option_id])) { |
|
| 48 | 48 | Options::$options = \Ecommerce\Item\Option::getList(); |
| 49 | - } |
|
| 50 | - if (isset(Options::$options[$itemParam->item_option_id]) && Options::$options[$itemParam->item_option_id]->type == 'select') { |
|
| 49 | + } |
|
| 50 | + if (isset(Options::$options[$itemParam->item_option_id]) && Options::$options[$itemParam->item_option_id]->type == 'select') { |
|
| 51 | 51 | if (empty($options[$itemParam->item_option_id]) || !in_array($itemParam->value, $options[$itemParam->item_option_id])) { |
| 52 | - $itemParam->delete(); |
|
| 52 | + $itemParam->delete(); |
|
| 53 | 53 | } else { |
| 54 | - unset($options[$itemParam->item_option_id][array_search($itemParam->value, $options[$itemParam->item_option_id])]); |
|
| 54 | + unset($options[$itemParam->item_option_id][array_search($itemParam->value, $options[$itemParam->item_option_id])]); |
|
| 55 | 55 | } |
| 56 | - } else { |
|
| 56 | + } else { |
|
| 57 | 57 | if (empty($options[$itemParam->item_option_id])) { |
| 58 | - $itemParam->delete(); |
|
| 58 | + $itemParam->delete(); |
|
| 59 | 59 | } else { |
| 60 | - $itemParam->value = $options[$itemParam->item_option_id]; |
|
| 61 | - $itemParam->save(); |
|
| 62 | - unset($options[$itemParam->item_option_id]); |
|
| 60 | + $itemParam->value = $options[$itemParam->item_option_id]; |
|
| 61 | + $itemParam->save(); |
|
| 62 | + unset($options[$itemParam->item_option_id]); |
|
| 63 | + } |
|
| 63 | 64 | } |
| 64 | - } |
|
| 65 | 65 | } |
| 66 | 66 | foreach ($options as $optionId => $values) { |
| 67 | - if (is_array($values)) { |
|
| 67 | + if (is_array($values)) { |
|
| 68 | 68 | foreach ($values as $value) { |
| 69 | - $itemParam = new \Ecommerce\Item\Param([ |
|
| 70 | - 'item_option_id' => $optionId, |
|
| 71 | - 'item_id' => $this->model->id, |
|
| 72 | - 'value' => $value |
|
| 73 | - ]); |
|
| 74 | - $itemParam->save(); |
|
| 69 | + $itemParam = new \Ecommerce\Item\Param([ |
|
| 70 | + 'item_option_id' => $optionId, |
|
| 71 | + 'item_id' => $this->model->id, |
|
| 72 | + 'value' => $value |
|
| 73 | + ]); |
|
| 74 | + $itemParam->save(); |
|
| 75 | 75 | } |
| 76 | - } else { |
|
| 76 | + } else { |
|
| 77 | 77 | $itemParam = new \Ecommerce\Item\Param([ |
| 78 | 78 | 'item_option_id' => $optionId, |
| 79 | 79 | 'item_id' => $this->model->id, |
| 80 | 80 | 'value' => $values |
| 81 | 81 | ]); |
| 82 | 82 | $itemParam->save(); |
| 83 | - } |
|
| 83 | + } |
|
| 84 | + } |
|
| 84 | 85 | } |
| 85 | - } |
|
| 86 | 86 | |
| 87 | 87 | } |
@@ -12,10 +12,10 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | class Migrations extends \Module { |
| 14 | 14 | |
| 15 | - public $ids = []; |
|
| 16 | - public $migrationObjects = []; |
|
| 15 | + public $ids = []; |
|
| 16 | + public $migrationObjects = []; |
|
| 17 | 17 | |
| 18 | - public function startMigration($migrationId, $mapId, $filePath) { |
|
| 18 | + public function startMigration($migrationId, $mapId, $filePath) { |
|
| 19 | 19 | $log = new \Migrations\Log(); |
| 20 | 20 | $log->migration_id = $migrationId; |
| 21 | 21 | $log->migration_map_id = $mapId; |
@@ -24,11 +24,11 @@ discard block |
||
| 24 | 24 | |
| 25 | 25 | $reader = new Migrations\Reader\Xml(); |
| 26 | 26 | if (!$reader->loadData($filePath)) { |
| 27 | - $event = new Migrations\Log\Event(); |
|
| 28 | - $event->log_id = $log->id; |
|
| 29 | - $event->type = 'load_data_error'; |
|
| 30 | - $event->save(); |
|
| 31 | - return false; |
|
| 27 | + $event = new Migrations\Log\Event(); |
|
| 28 | + $event->log_id = $log->id; |
|
| 29 | + $event->type = 'load_data_error'; |
|
| 30 | + $event->save(); |
|
| 31 | + return false; |
|
| 32 | 32 | } |
| 33 | 33 | $walker = new \Migrations\Walker(); |
| 34 | 34 | $walker->migration = Migrations\Migration::get($migrationId); |
@@ -38,43 +38,43 @@ discard block |
||
| 38 | 38 | $walker->walk(); |
| 39 | 39 | $log->result = 'success'; |
| 40 | 40 | $log->save(); |
| 41 | - } |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - public function loadParseIds($type) { |
|
| 43 | + public function loadParseIds($type) { |
|
| 44 | 44 | $this->ids['parseIds'][$type] = \Migrations\Id::getList(['where' => ['type', $type], 'key' => 'parse_id']); |
| 45 | - } |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - public function loadObjectIds($type) { |
|
| 47 | + public function loadObjectIds($type) { |
|
| 48 | 48 | $this->ids['objectIds'][$type] = \Migrations\Id::getList(['where' => ['type', $type], 'key' => 'object_id']); |
| 49 | - } |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - public function findObject($parseId, $type) { |
|
| 51 | + public function findObject($parseId, $type) { |
|
| 52 | 52 | if (empty($this->ids['parseIds'][$type])) { |
| 53 | - $this->loadParseIds($type); |
|
| 54 | - ksort($this->ids['parseIds'][$type]); |
|
| 53 | + $this->loadParseIds($type); |
|
| 54 | + ksort($this->ids['parseIds'][$type]); |
|
| 55 | 55 | } |
| 56 | 56 | if (!empty($this->ids['parseIds'][$type][$parseId])) { |
| 57 | - return $this->ids['parseIds'][$type][$parseId]; |
|
| 57 | + return $this->ids['parseIds'][$type][$parseId]; |
|
| 58 | + } |
|
| 58 | 59 | } |
| 59 | - } |
|
| 60 | 60 | |
| 61 | - public function findParse($objectId, $type) { |
|
| 61 | + public function findParse($objectId, $type) { |
|
| 62 | 62 | if (empty($this->ids['objectIds'][$type])) { |
| 63 | - $this->loadObjectIds($type); |
|
| 64 | - ksort($this->ids['objectIds'][$type]); |
|
| 63 | + $this->loadObjectIds($type); |
|
| 64 | + ksort($this->ids['objectIds'][$type]); |
|
| 65 | 65 | } |
| 66 | 66 | if (!empty($this->ids['objectIds'][$type][$objectId])) { |
| 67 | - return $this->ids['objectIds'][$type][$objectId]; |
|
| 67 | + return $this->ids['objectIds'][$type][$objectId]; |
|
| 68 | + } |
|
| 68 | 69 | } |
| 69 | - } |
|
| 70 | 70 | |
| 71 | - public function getMigrationObject($objectId) { |
|
| 71 | + public function getMigrationObject($objectId) { |
|
| 72 | 72 | if (empty($this->migrationObjects)) { |
| 73 | - $this->migrationObjects = \Migrations\Migration\Object::getList(); |
|
| 73 | + $this->migrationObjects = \Migrations\Migration\Object::getList(); |
|
| 74 | 74 | } |
| 75 | 75 | if (!empty($this->migrationObjects[$objectId])) { |
| 76 | - return $this->migrationObjects[$objectId]; |
|
| 76 | + return $this->migrationObjects[$objectId]; |
|
| 77 | + } |
|
| 77 | 78 | } |
| 78 | - } |
|
| 79 | 79 | |
| 80 | 80 | } |
@@ -13,61 +13,61 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | class Walker { |
| 15 | 15 | |
| 16 | - public $migration = null; |
|
| 17 | - public $map = null; |
|
| 18 | - public $data = null; |
|
| 19 | - public $mapPath = null; |
|
| 20 | - public $mapPathParent = null; |
|
| 21 | - public $curPath = '/'; |
|
| 22 | - public $migtarionLog = null; |
|
| 16 | + public $migration = null; |
|
| 17 | + public $map = null; |
|
| 18 | + public $data = null; |
|
| 19 | + public $mapPath = null; |
|
| 20 | + public $mapPathParent = null; |
|
| 21 | + public $curPath = '/'; |
|
| 22 | + public $migtarionLog = null; |
|
| 23 | 23 | |
| 24 | - //walk map pathes on cur path |
|
| 25 | - public function walk() { |
|
| 24 | + //walk map pathes on cur path |
|
| 25 | + public function walk() { |
|
| 26 | 26 | $walked = []; |
| 27 | 27 | //walk know pathes |
| 28 | 28 | foreach ($this->map->paths(['where' => ['path', $this->curPath]]) as $path) { |
| 29 | - if (isset($this->data[$path->item])) { |
|
| 29 | + if (isset($this->data[$path->item])) { |
|
| 30 | 30 | if ($path->type == 'container') { //create walker for container |
| 31 | - $walker = new Walker(); |
|
| 32 | - $walker->migration = $this->migration; |
|
| 33 | - $walker->map = $this->map; |
|
| 34 | - $walker->data = &$this->data[$path->item]; |
|
| 35 | - $walker->curPath = $this->curPath . $path->item . '/'; |
|
| 36 | - $walker->mapPath = $path; |
|
| 37 | - $walker->mapPathParent = $this->mapPath; |
|
| 38 | - $walker->migtarionLog = $this->migtarionLog; |
|
| 39 | - $walker->walk(); |
|
| 31 | + $walker = new Walker(); |
|
| 32 | + $walker->migration = $this->migration; |
|
| 33 | + $walker->map = $this->map; |
|
| 34 | + $walker->data = &$this->data[$path->item]; |
|
| 35 | + $walker->curPath = $this->curPath . $path->item . '/'; |
|
| 36 | + $walker->mapPath = $path; |
|
| 37 | + $walker->mapPathParent = $this->mapPath; |
|
| 38 | + $walker->migtarionLog = $this->migtarionLog; |
|
| 39 | + $walker->walk(); |
|
| 40 | 40 | } elseif ($path->type == 'object') { //start parse path data |
| 41 | - $this->startObjectParse($path->object_id, $this->data[$path->item]); |
|
| 41 | + $this->startObjectParse($path->object_id, $this->data[$path->item]); |
|
| 42 | 42 | } |
| 43 | - } |
|
| 44 | - $walked[$path->item] = true; |
|
| 43 | + } |
|
| 44 | + $walked[$path->item] = true; |
|
| 45 | 45 | } |
| 46 | 46 | //check unparsed paths |
| 47 | 47 | foreach ($this->data as $key => &$data) { |
| 48 | - //skip parsed and attribtes |
|
| 49 | - if ($key == '@attributes' || !empty($walked[$key])) { |
|
| 48 | + //skip parsed and attribtes |
|
| 49 | + if ($key == '@attributes' || !empty($walked[$key])) { |
|
| 50 | 50 | continue; |
| 51 | - } |
|
| 52 | - //search object for parse |
|
| 53 | - $object = Migration\Object::get([ |
|
| 54 | - ['code', $key], |
|
| 55 | - ['migration_id', $this->migration->id] |
|
| 56 | - ]); |
|
| 57 | - if ($object) { //parse as object |
|
| 51 | + } |
|
| 52 | + //search object for parse |
|
| 53 | + $object = Migration\Object::get([ |
|
| 54 | + ['code', $key], |
|
| 55 | + ['migration_id', $this->migration->id] |
|
| 56 | + ]); |
|
| 57 | + if ($object) { //parse as object |
|
| 58 | 58 | $this->startObjectParse($object, $data); |
| 59 | - } else { //create new map path for configure unknown path |
|
| 59 | + } else { //create new map path for configure unknown path |
|
| 60 | 60 | $this->mapPath = new Migration\Map\Path(); |
| 61 | 61 | $this->mapPath->parent_id = $this->mapPathParent ? $this->mapPathParent->id : 0; |
| 62 | 62 | $this->mapPath->path = $this->curPath; |
| 63 | 63 | $this->mapPath->item = $key; |
| 64 | 64 | $this->mapPath->migration_map_id = $this->map->id; |
| 65 | 65 | $this->mapPath->save(); |
| 66 | - } |
|
| 66 | + } |
|
| 67 | + } |
|
| 67 | 68 | } |
| 68 | - } |
|
| 69 | 69 | |
| 70 | - private function startObjectParse($object_id, &$data) { |
|
| 70 | + private function startObjectParse($object_id, &$data) { |
|
| 71 | 71 | $objectParser = new Parser\Object(); |
| 72 | 72 | $objectParser->object = is_object($object_id) ? $object_id : \App::$cur->migrations->getMigrationObject($object_id); |
| 73 | 73 | $objectParser->data = $data; |
@@ -76,33 +76,33 @@ discard block |
||
| 76 | 76 | |
| 77 | 77 | if ($objectParser->object->clear && json_decode($objectParser->object->clear, true)) { |
| 78 | 78 | |
| 79 | - $where = json_decode($objectParser->object->clear, true); |
|
| 80 | - if (!$where) { |
|
| 79 | + $where = json_decode($objectParser->object->clear, true); |
|
| 80 | + if (!$where) { |
|
| 81 | 81 | $where = []; |
| 82 | - } else { |
|
| 82 | + } else { |
|
| 83 | 83 | $where = [[$where]]; |
| 84 | - } |
|
| 85 | - if ($ids) { |
|
| 84 | + } |
|
| 85 | + if ($ids) { |
|
| 86 | 86 | $where[] = ['id', implode(',', $ids), 'NOT IN']; |
| 87 | - } |
|
| 88 | - if (empty(\App::$cur->migrations->ids['objectIds'])) { |
|
| 87 | + } |
|
| 88 | + if (empty(\App::$cur->migrations->ids['objectIds'])) { |
|
| 89 | 89 | \App::$cur->migrations->loadObjectIds($objectParser->object->model); |
| 90 | - } |
|
| 91 | - if (!empty(\App::$cur->migrations->ids['objectIds'][$objectParser->object->model])) { |
|
| 90 | + } |
|
| 91 | + if (!empty(\App::$cur->migrations->ids['objectIds'][$objectParser->object->model])) { |
|
| 92 | 92 | $where[] = ['id', implode(',', array_keys(\App::$cur->migrations->ids['objectIds'][$objectParser->object->model])), 'IN']; |
| 93 | - } |
|
| 94 | - $modelName = $objectParser->object->model; |
|
| 95 | - $objects = $modelName::getList(['where' => $where]); |
|
| 96 | - foreach ($objects as $object) { |
|
| 93 | + } |
|
| 94 | + $modelName = $objectParser->object->model; |
|
| 95 | + $objects = $modelName::getList(['where' => $where]); |
|
| 96 | + foreach ($objects as $object) { |
|
| 97 | 97 | $objectId = \App::$cur->migrations->findParse($object->id, $objectParser->object->model); |
| 98 | 98 | if ($objectId) { |
| 99 | - $objectId->delete(); |
|
| 100 | - unset(\App::$cur->migrations->ids['objectIds'][$objectParser->object->model][$object->id]); |
|
| 101 | - unset(\App::$cur->migrations->ids['parseIds'][$objectParser->object->model][$objectId->parse_id]); |
|
| 99 | + $objectId->delete(); |
|
| 100 | + unset(\App::$cur->migrations->ids['objectIds'][$objectParser->object->model][$object->id]); |
|
| 101 | + unset(\App::$cur->migrations->ids['parseIds'][$objectParser->object->model][$objectId->parse_id]); |
|
| 102 | 102 | } |
| 103 | 103 | $object->delete(); |
| 104 | - } |
|
| 104 | + } |
|
| 105 | + } |
|
| 105 | 106 | } |
| 106 | - } |
|
| 107 | 107 | |
| 108 | 108 | } |
@@ -4,36 +4,36 @@ discard block |
||
| 4 | 4 | $optionsHtml = ''; |
| 5 | 5 | |
| 6 | 6 | foreach ($options['values'] as $key => $value) { |
| 7 | - $selected = ''; |
|
| 7 | + $selected = ''; |
|
| 8 | 8 | |
| 9 | - $primaryValue = isset($options['value']) ? $options['value'] : null; |
|
| 10 | - $primaryValue = is_array($primaryValue) && isset($primaryValue['primary']) ? $primaryValue['primary'] : $primaryValue; |
|
| 11 | - if (is_numeric($key) && !is_array($primaryValue) && $primaryValue !== '') { |
|
| 9 | + $primaryValue = isset($options['value']) ? $options['value'] : null; |
|
| 10 | + $primaryValue = is_array($primaryValue) && isset($primaryValue['primary']) ? $primaryValue['primary'] : $primaryValue; |
|
| 11 | + if (is_numeric($key) && !is_array($primaryValue) && $primaryValue !== '') { |
|
| 12 | 12 | $primaryValue = (int) $primaryValue; |
| 13 | - } |
|
| 14 | - if ( |
|
| 15 | - (!is_array($primaryValue) && ($key === $primaryValue || (isset($form->userDataTree[$name]) && $form->userDataTree[$name] === $key))) || |
|
| 13 | + } |
|
| 14 | + if ( |
|
| 15 | + (!is_array($primaryValue) && ($key === $primaryValue || (isset($form->userDataTree[$name]) && $form->userDataTree[$name] === $key))) || |
|
| 16 | 16 | (is_array($primaryValue) && (in_array($key, $primaryValue) || (isset($form->userDataTree[$name]) && in_array($key, $form->userDataTree[$name])))) |
| 17 | - ) { |
|
| 17 | + ) { |
|
| 18 | 18 | $selected = ' selected="selected"'; |
| 19 | - } |
|
| 20 | - if (is_array($value)) { |
|
| 19 | + } |
|
| 20 | + if (is_array($value)) { |
|
| 21 | 21 | $aditionalInputs[] = $value['input']; |
| 22 | 22 | if ($selected) { |
| 23 | - $showedInput = count($aditionalInputs) - 1; |
|
| 24 | - $aditionValue = !empty($options['aditionalValue']) ? $options['aditionalValue'] : ''; |
|
| 23 | + $showedInput = count($aditionalInputs) - 1; |
|
| 24 | + $aditionValue = !empty($options['aditionalValue']) ? $options['aditionalValue'] : ''; |
|
| 25 | 25 | } |
| 26 | 26 | $optionsHtml .= "<option data-aditionalInput='" . ( count($aditionalInputs) - 1) . "' value ='{$key}'{$selected}>{$value['text']}</option>"; |
| 27 | - } else { |
|
| 27 | + } else { |
|
| 28 | 28 | $optionsHtml .= "<option value ='{$key}'{$selected}>{$value}</option>"; |
| 29 | - } |
|
| 29 | + } |
|
| 30 | 30 | } |
| 31 | 31 | ?> |
| 32 | 32 | <?= empty($options['noContainer']) ? '<div class="form-group">' : ''; ?> |
| 33 | 33 | <?= $label !== false ? "<label>{$label}" : ''; ?> |
| 34 | 34 | <?php |
| 35 | 35 | if ($label !== false && !empty($options['createBtn'])) { |
| 36 | - echo ' (<a href="" onclick="' . $options['createBtn']['onclick'] . ';this.disabled=true;return false;">' . $options['createBtn']['text'] . '</a>)'; |
|
| 36 | + echo ' (<a href="" onclick="' . $options['createBtn']['onclick'] . ';this.disabled=true;return false;">' . $options['createBtn']['text'] . '</a>)'; |
|
| 37 | 37 | } |
| 38 | 38 | ?> |
| 39 | 39 | <?= $label !== false ? "</label>" : ''; ?> |
@@ -42,18 +42,18 @@ discard block |
||
| 42 | 42 | </select> |
| 43 | 43 | <?php |
| 44 | 44 | foreach ($aditionalInputs as $key => $input) { |
| 45 | - $input['options']['noContainer'] = true; |
|
| 45 | + $input['options']['noContainer'] = true; |
|
| 46 | 46 | |
| 47 | - if ($key !== $showedInput) { |
|
| 47 | + if ($key !== $showedInput) { |
|
| 48 | 48 | $input['options']['disabled'] = true; |
| 49 | 49 | $input['options']['class'] = !empty($input['options']['class']) ? $input['options']['class'] . ' hidden' : 'hidden'; |
| 50 | - } else { |
|
| 50 | + } else { |
|
| 51 | 51 | $input['options']['value'] = empty($input['options']['value']) ? $aditionValue : $input['options']['value']; |
| 52 | - } |
|
| 53 | - if ($input['type'] == 'select') { |
|
| 52 | + } |
|
| 53 | + if ($input['type'] == 'select') { |
|
| 54 | 54 | $input['options']['values'] = \Ui\ActiveForm::getOptionsList($input); |
| 55 | - } |
|
| 56 | - $form->input($input['type'], empty($input['name']) ? $name . '[aditional]' : $input['name'], false, $input['options']); |
|
| 55 | + } |
|
| 56 | + $form->input($input['type'], empty($input['name']) ? $name . '[aditional]' : $input['name'], false, $input['options']); |
|
| 57 | 57 | } |
| 58 | 58 | ?> |
| 59 | 59 | <?= empty($options['noContainer']) ? '</div>' : ''; ?> |
| 60 | 60 | \ No newline at end of file |
@@ -13,118 +13,118 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | class ActiveForm extends \Object { |
| 15 | 15 | |
| 16 | - public $model = null; |
|
| 17 | - public $modelName = ''; |
|
| 18 | - public $header = ""; |
|
| 19 | - public $action = ""; |
|
| 20 | - public $form = []; |
|
| 21 | - public $inputs = []; |
|
| 22 | - public $formName = 'noNameForm'; |
|
| 23 | - public $requestFormName = ''; |
|
| 24 | - public $requestFullFormName = ''; |
|
| 25 | - public $parent = null; |
|
| 16 | + public $model = null; |
|
| 17 | + public $modelName = ''; |
|
| 18 | + public $header = ""; |
|
| 19 | + public $action = ""; |
|
| 20 | + public $form = []; |
|
| 21 | + public $inputs = []; |
|
| 22 | + public $formName = 'noNameForm'; |
|
| 23 | + public $requestFormName = ''; |
|
| 24 | + public $requestFullFormName = ''; |
|
| 25 | + public $parent = null; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * |
|
| 29 | - * @param array|\Model $model |
|
| 30 | - * @param array|string $form |
|
| 31 | - */ |
|
| 32 | - public function __construct($model, $form = '') { |
|
| 27 | + /** |
|
| 28 | + * |
|
| 29 | + * @param array|\Model $model |
|
| 30 | + * @param array|string $form |
|
| 31 | + */ |
|
| 32 | + public function __construct($model, $form = '') { |
|
| 33 | 33 | if (is_array($model)) { |
| 34 | - $this->form = $model; |
|
| 35 | - if (is_string($form)) { |
|
| 34 | + $this->form = $model; |
|
| 35 | + if (is_string($form)) { |
|
| 36 | 36 | $this->formName = $form; |
| 37 | - } |
|
| 37 | + } |
|
| 38 | 38 | } else { |
| 39 | - $this->model = $model; |
|
| 40 | - $this->modelName = get_class($model); |
|
| 41 | - if (is_array($form)) { |
|
| 39 | + $this->model = $model; |
|
| 40 | + $this->modelName = get_class($model); |
|
| 41 | + if (is_array($form)) { |
|
| 42 | 42 | if (empty($form)) { |
| 43 | - throw new \Exception('empty form'); |
|
| 43 | + throw new \Exception('empty form'); |
|
| 44 | 44 | } |
| 45 | 45 | $this->form = $form; |
| 46 | - } else { |
|
| 46 | + } else { |
|
| 47 | 47 | $this->formName = $form; |
| 48 | 48 | $this->form = \App::$cur->ui->getModelForm($this->modelName, $form); |
| 49 | 49 | if (empty($this->form)) { |
| 50 | - throw new \Exception('empty form ' . $form); |
|
| 50 | + throw new \Exception('empty form ' . $form); |
|
| 51 | 51 | } |
| 52 | 52 | $this->inputs = $this->getInputs(); |
| 53 | - } |
|
| 53 | + } |
|
| 54 | 54 | } |
| 55 | 55 | $this->requestFormName = "ActiveForm_{$this->formName}"; |
| 56 | 56 | $modeName = $this->modelName; |
| 57 | 57 | |
| 58 | 58 | if (!empty($this->form['name'])) { |
| 59 | - $this->header = $this->form['name']; |
|
| 59 | + $this->header = $this->form['name']; |
|
| 60 | 60 | } elseif (!empty($modeName::$objectName)) { |
| 61 | - $this->header = $modeName::$objectName; |
|
| 61 | + $this->header = $modeName::$objectName; |
|
| 62 | 62 | } else { |
| 63 | - $this->header = $this->modelName; |
|
| 63 | + $this->header = $this->modelName; |
|
| 64 | + } |
|
| 64 | 65 | } |
| 65 | - } |
|
| 66 | 66 | |
| 67 | - public function getInputs() { |
|
| 67 | + public function getInputs() { |
|
| 68 | 68 | $inputs = !empty($this->form['inputs']) ? $this->form['inputs'] : []; |
| 69 | 69 | $modelName = $this->modelName; |
| 70 | 70 | foreach ($this->form['map'] as $row) { |
| 71 | - foreach ($row as $col) { |
|
| 71 | + foreach ($row as $col) { |
|
| 72 | 72 | if (!$col || !empty($inputs[$col])) { |
| 73 | - continue; |
|
| 73 | + continue; |
|
| 74 | 74 | } |
| 75 | 75 | if (strpos($col, 'form:') === 0) { |
| 76 | - $colPath = explode(':', $col); |
|
| 77 | - if ($this->model->{$colPath[1]}) { |
|
| 76 | + $colPath = explode(':', $col); |
|
| 77 | + if ($this->model->{$colPath[1]}) { |
|
| 78 | 78 | $inputs[$col] = new ActiveForm($this->model->{$colPath[1]}, $colPath[2]); |
| 79 | - } else { |
|
| 79 | + } else { |
|
| 80 | 80 | $relOptions = $modelName::getRelation($colPath[1]); |
| 81 | 81 | if (!isset($this->model->_params[$modelName::index()])) { |
| 82 | - $this->model->_params[$modelName::index()] = 0; |
|
| 82 | + $this->model->_params[$modelName::index()] = 0; |
|
| 83 | 83 | } |
| 84 | 84 | $relOptions['model']::fixPrefix($relOptions['col']); |
| 85 | 85 | $inputs[$col] = new ActiveForm(new $relOptions['model']([ $relOptions['col'] => &$this->model->_params[$modelName::index()]]), $colPath[2]); |
| 86 | - } |
|
| 87 | - $inputs[$col]->parent = $this; |
|
| 86 | + } |
|
| 87 | + $inputs[$col]->parent = $this; |
|
| 88 | 88 | } elseif (!empty($modelName::$cols[$col])) { |
| 89 | - $inputs[$col] = $modelName::$cols[$col]; |
|
| 89 | + $inputs[$col] = $modelName::$cols[$col]; |
|
| 90 | + } |
|
| 90 | 91 | } |
| 91 | - } |
|
| 92 | 92 | } |
| 93 | 93 | return $inputs; |
| 94 | - } |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - public function checkRequest($params = [], $ajax = false) { |
|
| 96 | + public function checkRequest($params = [], $ajax = false) { |
|
| 97 | 97 | if (!$this->checkAccess()) { |
| 98 | - $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->formName . '"'); |
|
| 99 | - return []; |
|
| 98 | + $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->formName . '"'); |
|
| 99 | + return []; |
|
| 100 | 100 | } |
| 101 | 101 | $successId = 0; |
| 102 | 102 | if (!empty($_POST[$this->requestFormName][$this->modelName])) { |
| 103 | - $request = $_POST[$this->requestFormName][$this->modelName]; |
|
| 104 | - if ($this->model) { |
|
| 103 | + $request = $_POST[$this->requestFormName][$this->modelName]; |
|
| 104 | + if ($this->model) { |
|
| 105 | 105 | if ($this->form['handler']) { |
| 106 | - $modelName = $this->model; |
|
| 107 | - $modelName::{$this->form['handler']}($request); |
|
| 108 | - $text = 'Новый элемент был успешно добавлен'; |
|
| 109 | - \Msg::add($text, 'success'); |
|
| 110 | - \Msg::show(); |
|
| 106 | + $modelName = $this->model; |
|
| 107 | + $modelName::{$this->form['handler']}($request); |
|
| 108 | + $text = 'Новый элемент был успешно добавлен'; |
|
| 109 | + \Msg::add($text, 'success'); |
|
| 110 | + \Msg::show(); |
|
| 111 | 111 | } else { |
| 112 | - $presets = !empty($this->form['preset']) ? $this->form['preset'] : []; |
|
| 113 | - if (!empty($this->form['userGroupPreset'][\Users\User::$cur->group_id])) { |
|
| 112 | + $presets = !empty($this->form['preset']) ? $this->form['preset'] : []; |
|
| 113 | + if (!empty($this->form['userGroupPreset'][\Users\User::$cur->group_id])) { |
|
| 114 | 114 | $presets = array_merge($presets, $this->form['userGroupPreset'][\Users\User::$cur->group_id]); |
| 115 | - } |
|
| 116 | - $afterSave = []; |
|
| 117 | - $error = false; |
|
| 118 | - foreach ($this->inputs as $col => $param) { |
|
| 115 | + } |
|
| 116 | + $afterSave = []; |
|
| 117 | + $error = false; |
|
| 118 | + foreach ($this->inputs as $col => $param) { |
|
| 119 | 119 | if (!empty($presets[$col])) { |
| 120 | - continue; |
|
| 120 | + continue; |
|
| 121 | 121 | } |
| 122 | 122 | if (is_object($param)) { |
| 123 | - $afterSave[] = $param; |
|
| 124 | - continue; |
|
| 123 | + $afterSave[] = $param; |
|
| 124 | + continue; |
|
| 125 | 125 | } |
| 126 | 126 | if (!empty($this->form['userGroupReadonly'][\Users\User::$cur->group_id]) && in_array($col, $this->form['userGroupReadonly'][\Users\User::$cur->group_id])) { |
| 127 | - continue; |
|
| 127 | + continue; |
|
| 128 | 128 | } |
| 129 | 129 | $inputClassName = '\Ui\ActiveForm\Input\\' . ucfirst($param['type']); |
| 130 | 130 | $input = new $inputClassName(); |
@@ -134,186 +134,186 @@ discard block |
||
| 134 | 134 | $input->colName = $col; |
| 135 | 135 | $input->colParams = $param; |
| 136 | 136 | try { |
| 137 | - $input->validate($request); |
|
| 138 | - $input->parseRequest($request); |
|
| 137 | + $input->validate($request); |
|
| 138 | + $input->parseRequest($request); |
|
| 139 | 139 | } catch (\Exception $exc) { |
| 140 | - \Msg::add($exc->getMessage(), 'danger'); |
|
| 141 | - $error = true; |
|
| 140 | + \Msg::add($exc->getMessage(), 'danger'); |
|
| 141 | + $error = true; |
|
| 142 | + } |
|
| 142 | 143 | } |
| 143 | - } |
|
| 144 | - if (!$error && empty($_GET['notSave'])) { |
|
| 144 | + if (!$error && empty($_GET['notSave'])) { |
|
| 145 | 145 | foreach ($presets as $col => $preset) { |
| 146 | - if (!empty($preset['value'])) { |
|
| 146 | + if (!empty($preset['value'])) { |
|
| 147 | 147 | $this->model->$col = $preset['value']; |
| 148 | - } elseif (!empty($preset['userCol'])) { |
|
| 148 | + } elseif (!empty($preset['userCol'])) { |
|
| 149 | 149 | if (strpos($preset['userCol'], ':')) { |
| 150 | - $rel = substr($preset['userCol'], 0, strpos($preset['userCol'], ':')); |
|
| 151 | - $param = substr($preset['userCol'], strpos($preset['userCol'], ':') + 1); |
|
| 152 | - $this->model->$col = \Users\User::$cur->$rel->$param; |
|
| 150 | + $rel = substr($preset['userCol'], 0, strpos($preset['userCol'], ':')); |
|
| 151 | + $param = substr($preset['userCol'], strpos($preset['userCol'], ':') + 1); |
|
| 152 | + $this->model->$col = \Users\User::$cur->$rel->$param; |
|
| 153 | 153 | } else { |
| 154 | - $this->model->$col = \Users\User::$cur->{$preset['userCol']}; |
|
| 154 | + $this->model->$col = \Users\User::$cur->{$preset['userCol']}; |
|
| 155 | + } |
|
| 155 | 156 | } |
| 156 | - } |
|
| 157 | 157 | } |
| 158 | 158 | if (!$this->parent) { |
| 159 | - if (!empty($this->form['successText'])) { |
|
| 159 | + if (!empty($this->form['successText'])) { |
|
| 160 | 160 | $text = $this->form['successText']; |
| 161 | - } else { |
|
| 161 | + } else { |
|
| 162 | 162 | $text = $this->model->pk() ? 'Изменения были успешно сохранены' : 'Новый элемент был успешно добавлен'; |
| 163 | - } |
|
| 164 | - \Msg::add($text, 'success'); |
|
| 163 | + } |
|
| 164 | + \Msg::add($text, 'success'); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | $this->model->save(!empty($params['dataManagerParams']) ? $params['dataManagerParams'] : []); |
| 168 | 168 | foreach ($afterSave as $form) { |
| 169 | - $form->checkRequest(); |
|
| 169 | + $form->checkRequest(); |
|
| 170 | 170 | } |
| 171 | 171 | if ($ajax) { |
| 172 | - \Msg::show(); |
|
| 172 | + \Msg::show(); |
|
| 173 | 173 | } elseif (!empty($_GET['redirectUrl'])) { |
| 174 | - \Tools::redirect($_GET['redirectUrl'] . (!empty($_GET['dataManagerHash']) ? '#' . $_GET['dataManagerHash'] : '')); |
|
| 174 | + \Tools::redirect($_GET['redirectUrl'] . (!empty($_GET['dataManagerHash']) ? '#' . $_GET['dataManagerHash'] : '')); |
|
| 175 | 175 | } |
| 176 | 176 | $successId = $this->model->pk(); |
| 177 | - } |
|
| 177 | + } |
|
| 178 | + } |
|
| 178 | 179 | } |
| 179 | - } |
|
| 180 | - if (!is_array($params) && is_callable($params)) { |
|
| 180 | + if (!is_array($params) && is_callable($params)) { |
|
| 181 | 181 | $params($request); |
| 182 | - } |
|
| 182 | + } |
|
| 183 | 183 | } |
| 184 | 184 | return $successId; |
| 185 | - } |
|
| 185 | + } |
|
| 186 | 186 | |
| 187 | - public function draw($params = [], $ajax = false) { |
|
| 187 | + public function draw($params = [], $ajax = false) { |
|
| 188 | 188 | if (!$this->checkAccess()) { |
| 189 | - $this->drawError('you not have access to "' . $this->modelName . '" form with name: "' . $this->formName . '"'); |
|
| 190 | - return []; |
|
| 189 | + $this->drawError('you not have access to "' . $this->modelName . '" form with name: "' . $this->formName . '"'); |
|
| 190 | + return []; |
|
| 191 | 191 | } |
| 192 | 192 | $form = new Form(!empty($this->form['formOptions']) ? $this->form['formOptions'] : []); |
| 193 | 193 | \App::$cur->view->widget('Ui\ActiveForm', ['form' => $form, 'activeForm' => $this, 'ajax' => $ajax, 'params' => $params]); |
| 194 | - } |
|
| 194 | + } |
|
| 195 | 195 | |
| 196 | - public function drawCol($colName, $options, $form, $params = []) { |
|
| 196 | + public function drawCol($colName, $options, $form, $params = []) { |
|
| 197 | 197 | if (is_object($options)) { |
| 198 | - $options->draw(); |
|
| 198 | + $options->draw(); |
|
| 199 | 199 | } else { |
| 200 | - $inputClassName = '\Ui\ActiveForm\Input\\' . ucfirst($options['type']); |
|
| 201 | - $input = new $inputClassName(); |
|
| 202 | - $input->form = $form; |
|
| 203 | - $input->activeForm = $this; |
|
| 204 | - $input->activeFormParams = $params; |
|
| 205 | - $input->modelName = $this->modelName; |
|
| 206 | - $input->colName = $colName; |
|
| 207 | - $input->colParams = $options; |
|
| 208 | - $input->options = !empty($options['options']) ? $options['options'] : []; |
|
| 209 | - $input->draw(); |
|
| 200 | + $inputClassName = '\Ui\ActiveForm\Input\\' . ucfirst($options['type']); |
|
| 201 | + $input = new $inputClassName(); |
|
| 202 | + $input->form = $form; |
|
| 203 | + $input->activeForm = $this; |
|
| 204 | + $input->activeFormParams = $params; |
|
| 205 | + $input->modelName = $this->modelName; |
|
| 206 | + $input->colName = $colName; |
|
| 207 | + $input->colParams = $options; |
|
| 208 | + $input->options = !empty($options['options']) ? $options['options'] : []; |
|
| 209 | + $input->draw(); |
|
| 210 | 210 | } |
| 211 | 211 | return true; |
| 212 | - } |
|
| 212 | + } |
|
| 213 | 213 | |
| 214 | - public static function getOptionsList($inputParams, $params = [], $modelName = '', $aditionalInputNamePrefix = 'aditional', $options = []) { |
|
| 214 | + public static function getOptionsList($inputParams, $params = [], $modelName = '', $aditionalInputNamePrefix = 'aditional', $options = []) { |
|
| 215 | 215 | $values = []; |
| 216 | 216 | switch ($inputParams['source']) { |
| 217 | - case 'model': |
|
| 217 | + case 'model': |
|
| 218 | 218 | $values = $inputParams['model']::getList(['forSelect' => true]); |
| 219 | 219 | break; |
| 220 | - case 'array': |
|
| 220 | + case 'array': |
|
| 221 | 221 | $values = $inputParams['sourceArray']; |
| 222 | 222 | break; |
| 223 | - case 'method': |
|
| 223 | + case 'method': |
|
| 224 | 224 | if (!empty($inputParams['params'])) { |
| 225 | - $values = call_user_func_array([\App::$cur->$inputParams['module'], $inputParams['method']], $inputParams['params']); |
|
| 225 | + $values = call_user_func_array([\App::$cur->$inputParams['module'], $inputParams['method']], $inputParams['params']); |
|
| 226 | 226 | } else { |
| 227 | - $values = \App::$cur->$inputParams['module']->$inputParams['method'](); |
|
| 227 | + $values = \App::$cur->$inputParams['module']->$inputParams['method'](); |
|
| 228 | 228 | } |
| 229 | 229 | break; |
| 230 | - case 'relation': |
|
| 230 | + case 'relation': |
|
| 231 | 231 | if (!$modelName) { |
| 232 | - return []; |
|
| 232 | + return []; |
|
| 233 | 233 | } |
| 234 | 234 | $relation = $modelName::getRelation($inputParams['relation']); |
| 235 | 235 | if (!empty($params['dataManagerParams']['appType'])) { |
| 236 | - $options['appType'] = $params['dataManagerParams']['appType']; |
|
| 236 | + $options['appType'] = $params['dataManagerParams']['appType']; |
|
| 237 | 237 | } |
| 238 | 238 | $items = []; |
| 239 | 239 | if (class_exists($relation['model'])) { |
| 240 | - $filters = $relation['model']::managerFilters(); |
|
| 241 | - if (!empty($filters['getRows']['where'])) { |
|
| 240 | + $filters = $relation['model']::managerFilters(); |
|
| 241 | + if (!empty($filters['getRows']['where'])) { |
|
| 242 | 242 | $options['where'][] = $filters['getRows']['where']; |
| 243 | - } |
|
| 244 | - if (!empty($relation['order'])) { |
|
| 243 | + } |
|
| 244 | + if (!empty($relation['order'])) { |
|
| 245 | 245 | $options['order'] = $relation['order']; |
| 246 | - } |
|
| 247 | - if (!empty($inputParams['itemName'])) { |
|
| 246 | + } |
|
| 247 | + if (!empty($inputParams['itemName'])) { |
|
| 248 | 248 | $options['itemName'] = $inputParams['itemName']; |
| 249 | - } |
|
| 250 | - $items = $relation['model']::getList($options); |
|
| 249 | + } |
|
| 250 | + $items = $relation['model']::getList($options); |
|
| 251 | 251 | } |
| 252 | 252 | if (!empty($params['noEmptyValue'])) { |
| 253 | - $values = []; |
|
| 253 | + $values = []; |
|
| 254 | 254 | } else { |
| 255 | - $values = [0 => 'Не задано']; |
|
| 255 | + $values = [0 => 'Не задано']; |
|
| 256 | 256 | } |
| 257 | 257 | foreach ($items as $key => $item) { |
| 258 | - if (!empty($inputParams['showCol'])) { |
|
| 258 | + if (!empty($inputParams['showCol'])) { |
|
| 259 | 259 | if (is_array($inputParams['showCol'])) { |
| 260 | - switch ($inputParams['showCol']['type']) { |
|
| 260 | + switch ($inputParams['showCol']['type']) { |
|
| 261 | 261 | case 'staticMethod': |
| 262 | 262 | $values[$key] = $inputParams['showCol']['class']::{$inputParams['showCol']['method']}($item); |
| 263 | - break; |
|
| 264 | - } |
|
| 263 | + break; |
|
| 264 | + } |
|
| 265 | 265 | } else { |
| 266 | - $values[$key] = $item->$inputParams['showCol']; |
|
| 266 | + $values[$key] = $item->$inputParams['showCol']; |
|
| 267 | 267 | } |
| 268 | - } else { |
|
| 268 | + } else { |
|
| 269 | 269 | $values[$key] = $item->name(); |
| 270 | - } |
|
| 270 | + } |
|
| 271 | 271 | } |
| 272 | 272 | break; |
| 273 | 273 | } |
| 274 | 274 | foreach ($values as $key => $value) { |
| 275 | - if (is_array($value) && !empty($value['input']) && empty($value['input']['noprefix'])) { |
|
| 275 | + if (is_array($value) && !empty($value['input']) && empty($value['input']['noprefix'])) { |
|
| 276 | 276 | $values[$key]['input']['name'] = $aditionalInputNamePrefix . "[{$value['input']['name']}]"; |
| 277 | - } |
|
| 277 | + } |
|
| 278 | 278 | } |
| 279 | 279 | return $values; |
| 280 | - } |
|
| 280 | + } |
|
| 281 | 281 | |
| 282 | - /** |
|
| 283 | - * Draw error message |
|
| 284 | - * |
|
| 285 | - * @param string $errorText |
|
| 286 | - */ |
|
| 287 | - public function drawError($errorText) { |
|
| 282 | + /** |
|
| 283 | + * Draw error message |
|
| 284 | + * |
|
| 285 | + * @param string $errorText |
|
| 286 | + */ |
|
| 287 | + public function drawError($errorText) { |
|
| 288 | 288 | echo $errorText; |
| 289 | - } |
|
| 289 | + } |
|
| 290 | 290 | |
| 291 | - /** |
|
| 292 | - * Check access cur user to form with name in param and $model |
|
| 293 | - * |
|
| 294 | - * @return boolean |
|
| 295 | - */ |
|
| 296 | - public function checkAccess() { |
|
| 291 | + /** |
|
| 292 | + * Check access cur user to form with name in param and $model |
|
| 293 | + * |
|
| 294 | + * @return boolean |
|
| 295 | + */ |
|
| 296 | + public function checkAccess() { |
|
| 297 | 297 | if (empty($this->form)) { |
| 298 | - $this->drawError('"' . $this->modelName . '" form with name: "' . $this->formName . '" not found'); |
|
| 299 | - return false; |
|
| 298 | + $this->drawError('"' . $this->modelName . '" form with name: "' . $this->formName . '" not found'); |
|
| 299 | + return false; |
|
| 300 | 300 | } |
| 301 | 301 | if (\App::$cur->Access && !\App::$cur->Access->checkAccess($this)) { |
| 302 | - return false; |
|
| 302 | + return false; |
|
| 303 | 303 | } |
| 304 | 304 | if (!empty($this->form['options']['access']['apps']) && !in_array(\App::$cur->name, $this->form['options']['access']['apps'])) { |
| 305 | - return false; |
|
| 305 | + return false; |
|
| 306 | 306 | } |
| 307 | 307 | if (!empty($this->form['options']['access']['groups']) && in_array(\Users\User::$cur->group_id, $this->form['options']['access']['groups'])) { |
| 308 | - return true; |
|
| 308 | + return true; |
|
| 309 | 309 | } |
| 310 | 310 | if ($this->model && !empty($this->form['options']['access']['self']) && \Users\User::$cur->id == $this->model->user_id) { |
| 311 | - return true; |
|
| 311 | + return true; |
|
| 312 | 312 | } |
| 313 | 313 | if ($this->formName == 'manager' && !\Users\User::$cur->isAdmin()) { |
| 314 | - return false; |
|
| 314 | + return false; |
|
| 315 | 315 | } |
| 316 | 316 | return true; |
| 317 | - } |
|
| 317 | + } |
|
| 318 | 318 | |
| 319 | 319 | } |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | class Select extends \Ui\ActiveForm\Input { |
| 15 | 15 | |
| 16 | - public function draw() { |
|
| 16 | + public function draw() { |
|
| 17 | 17 | $inputName = $this->colName(); |
| 18 | 18 | $inputLabel = $this->colLabel(); |
| 19 | 19 | $inputParams = $this->colParams; |
@@ -25,41 +25,41 @@ discard block |
||
| 25 | 25 | ]; |
| 26 | 26 | $modelName = ''; |
| 27 | 27 | switch ($inputParams['source']) { |
| 28 | - case 'model': |
|
| 28 | + case 'model': |
|
| 29 | 29 | $modelName = $inputParams['model']; |
| 30 | 30 | break; |
| 31 | - case 'relation': |
|
| 31 | + case 'relation': |
|
| 32 | 32 | if ($this->activeForm->modelName) { |
| 33 | - $itemModelName = $this->activeForm->modelName; |
|
| 34 | - $relation = $itemModelName::getRelation($inputParams['relation']); |
|
| 35 | - if ($relation['model'] && class_exists($relation['model'])) { |
|
| 33 | + $itemModelName = $this->activeForm->modelName; |
|
| 34 | + $relation = $itemModelName::getRelation($inputParams['relation']); |
|
| 35 | + if ($relation['model'] && class_exists($relation['model'])) { |
|
| 36 | 36 | $modelName = $relation['model']; |
| 37 | - } |
|
| 37 | + } |
|
| 38 | 38 | } |
| 39 | 39 | } |
| 40 | 40 | if (!empty($modelName)) { |
| 41 | - $inputOptions['createBtn'] = [ |
|
| 42 | - 'text' => 'Создать', |
|
| 43 | - 'onclick' => 'inji.Ui.forms.popUp(\'' . addslashes($modelName) . '\',{},function(elem){' |
|
| 44 | - . 'return function(data,modal){inji.Ui.forms.submitAjax($(elem).closest(\'form\')[0], {notSave: true});}}(this));return false;' |
|
| 45 | - ]; |
|
| 41 | + $inputOptions['createBtn'] = [ |
|
| 42 | + 'text' => 'Создать', |
|
| 43 | + 'onclick' => 'inji.Ui.forms.popUp(\'' . addslashes($modelName) . '\',{},function(elem){' |
|
| 44 | + . 'return function(data,modal){inji.Ui.forms.submitAjax($(elem).closest(\'form\')[0], {notSave: true});}}(this));return false;' |
|
| 45 | + ]; |
|
| 46 | 46 | } |
| 47 | 47 | if (!empty($inputOptions['values'][$this->activeForm->model->{$this->colName}]) && |
| 48 | 48 | is_array($inputOptions['values'][$this->activeForm->model->{$this->colName}]) && |
| 49 | 49 | !empty($inputOptions['values'][$this->activeForm->model->{$this->colName}]['input'])) { |
| 50 | - $aditionalCol = $inputOptions['values'][$this->activeForm->model->{$this->colName}]['input']['name']; |
|
| 51 | - $inputOptions['aditionalValue'] = $this->activeForm->model->$aditionalCol; |
|
| 50 | + $aditionalCol = $inputOptions['values'][$this->activeForm->model->{$this->colName}]['input']['name']; |
|
| 51 | + $inputOptions['aditionalValue'] = $this->activeForm->model->$aditionalCol; |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | $preset = $this->preset(); |
| 55 | 55 | |
| 56 | 56 | if ($preset !== null) { |
| 57 | - $inputOptions['disabled'] = true; |
|
| 58 | - $this->form->input('hidden', $inputName, '', $inputOptions); |
|
| 59 | - return true; |
|
| 57 | + $inputOptions['disabled'] = true; |
|
| 58 | + $this->form->input('hidden', $inputName, '', $inputOptions); |
|
| 59 | + return true; |
|
| 60 | 60 | } |
| 61 | 61 | $this->form->input('select', $inputName, $inputLabel, $inputOptions); |
| 62 | 62 | return true; |
| 63 | - } |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | 65 | } |