private static function processPost($category) { $errors = array(); if (!empty($_POST)) { if (empty($_POST['name'][DEF_LANG])) { $errors['name'] = 'Название должно быть указано хотя бы на языке по умолчанию'; } else { $langs = App::getLangs(); foreach ($langs as $lang) { if (empty($_POST['name'][$lang->getId()])) { $_POST['name'][$lang->getId()] = $_POST['name'][DEF_LANG]; } } $category->name = $_POST['name']; } $category->active = isset($_POST['active']) ? 1 : 0; if (empty($errors)) { $category->save(); self::redirect(App::getLink('AdminCategories')); } } return $errors; }
private static function processPost($product) { $errors = array(); if (!empty($_POST)) { if (empty($_POST['name'][DEF_LANG])) { $errors['name'] = 'Укажите название на языке по умолчанию'; } else { $langs = App::getLangs(); foreach ($langs as $lang) { if (empty($_POST['name'][$lang->getId()])) { $_POST['name'][$lang->getId()] = $_POST['name'][DEF_LANG]; } } $product->name = $_POST['name']; } if (empty($_POST['id_brand'])) { $errors['id_brand'] = 'Не выбран производитель'; } else { $product->id_brand = $_POST['id_brand']; } if (empty($_POST['id_category'])) { $errors['id_category'] = 'Не выбрана категория'; } else { $product->id_category = $_POST['id_category']; } if (empty($_POST['articul'])) { $errors['articul'] = 'Введите артикул'; } else { $product->articul = $_POST['articul']; } if ($_POST['price'] < 0) { $errors['price'] = 'Цена некорректна'; } else { $product->price = $_POST['price']; } $product->active = isset($_POST['active']) ? 1 : 0; $langs = App::getLangs(); foreach ($langs as $lang) { if (empty($_POST['description'][$lang->getId()])) { $_POST['description'][$lang->getId()] = $_POST['description'][DEF_LANG]; } } $product->description = $_POST['description']; if (empty($errors)) { $is_new = $product->getId() ? false : true; $product->save(); if ($is_new) { $images = json_decode($_POST['image_post_params'], true); $images = !empty($images['images']) ? explode(',', $images['images']) : array(); foreach ($images as $index => $image) { rename(ROOT_DIR . '/assets/images/temp/' . $image . '.png', ROOT_DIR . '/assets/images/products/' . $image . '.png'); rename(ROOT_DIR . '/assets/images/temp/' . $image . '_85x84.png', ROOT_DIR . '/assets/images/products/' . $image . '_85x84.png'); rename(ROOT_DIR . '/assets/images/temp/' . $image . '_110x110.png', ROOT_DIR . '/assets/images/products/' . $image . '_110x110.png'); rename(ROOT_DIR . '/assets/images/temp/' . $image . '_184x162.png', ROOT_DIR . '/assets/images/products/' . $image . '_184x162.png'); rename(ROOT_DIR . '/assets/images/temp/' . $image . '_255x128.png', ROOT_DIR . '/assets/images/products/' . $image . '_255x128.png'); rename(ROOT_DIR . '/assets/images/temp/' . $image . '_255x237.png', ROOT_DIR . '/assets/images/products/' . $image . '_255x237.png'); rename(ROOT_DIR . '/assets/images/temp/' . $image . '_329x380.png', ROOT_DIR . '/assets/images/products/' . $image . '_329x380.png'); $productImage = new ProductImageModel(); $productImage->id_product = $product->getId(); $productImage->file = $image; $productImage->position = $index + 1; $productImage->save(); } } self::redirect(App::getLink('AdminProducts')); } } return $errors; }
?> [<?php echo $lang->getId(); ?> ]"><?php echo $field['value'][$lang->getId()]; ?> </textarea> </span> <?php } ?> <ul class="langs-list clear"> <?php foreach (App::getLangs() as $lang) { ?> <li><a class="<?php echo $lang->getId() == 1 ? 'active' : ''; ?> " data-lang="<?php echo $lang->code; ?> " href="" onclick="return false;"></a></li> <?php } ?> </ul> <?php } else { ?>
private function insert() { if (in_array('add', static::$fields)) { $this->values['add'] = date('Y-m-d H:i:s'); } $query = "INSERT INTO `" . static::TABLE . "`"; $query .= ' (`' . implode('`, `', static::$fields) . '`) '; $query .= "VALUES ('" . implode("', '", $this->values) . "')"; Database::query($query); $this->id = Database::getInsertId(); if (!empty(static::$fieldsLang) && is_numeric($this->id_lang)) { if ($this->id_lang) { $query = "INSERT INTO `" . static::TABLE . "_lang` (`id_object`, `id_lang`, `"; $query .= implode(`, `, static::$fieldsLang); $query .= "`) VALUES ({$this->id}, {$this->id_lang}, '"; $query .= implode("', '", $this->valuesLang); $query .= "')"; Database::query($query); } else { foreach (App::getLangs() as $lang) { $lang = $lang->getId(); $query = "INSERT INTO `" . static::TABLE . "_lang` (`id_object`, `id_lang`, `"; $query .= implode('`, `', static::$fieldsLang); $query .= "`) VALUES ({$this->id}, {$lang}, "; foreach (static::$fieldsLang as $field) { $query .= "'{$this->values_lang[$field][$lang]}', "; } $query = rtrim($query, ', '); $query .= ")"; Database::query($query); } } } }