public function getImagesForProductAction() { header('Content-type: text/plain; charset=utf-8'); header('Cache-Control: no-store, no-cache'); header('Expires: ' . date('r')); if (filter_has_var(INPUT_GET, 'id')) { $id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT); } else { return FALSE; } $model = new ImageTableModel(); $model->setTable('image'); $model->setId($id); $model->readRecordsById(); echo json_encode($model->getRecordsById()); }
public function editProductAction() { $fc = FrontController::getInstance(); $model = new AdminModel('Редактирование товара'); $id = filter_var($fc->getParams()['product'], FILTER_SANITIZE_STRING); $productModel = new ProductTableModel(); $productModel->setId($id); $productModel->setTable('product'); $imageModel = new ImageTableModel(); $imageModel->setTable('image'); $imageModel->setId($id); if ($_SERVER['REQUEST_METHOD'] === 'POST') { $productModel->setData(); $productModel->updateProduct(); $imageModel = new ImageTableModel($productModel->getId()); $imageModel->setTable('image'); $imageModel->setId($productModel->getId()); $imageModel->setData(); $imageModel->addAllImages(); Session::setMsg('Товар успешно обновлен', 'success'); header('Location: /admin/view/product/' . $productModel->getId()); exit; } else { if (!$id) { header('Location: /admin/notFound'); exit; } $product = $productModel->getAllProducts('*', "WHERE product.id = {$id} GROUP BY product.id"); $imageModel->readRecordsById('product_id'); if (empty($product)) { header('Location: /admin/NotFound'); exit; } else { $model->setData(['products' => $productModel->getAllProducts('*', "WHERE product.id = {$id} GROUP BY product.id"), 'images' => $imageModel->getRecordsById()]); } $catsAndSub = IndexWidgets::getCatsAndSubCats(); $model->categoryList = $catsAndSub['cats']; //used magic __set $model->subCategoryList = $catsAndSub['subcats']; //used magic __set $output = $model->render('../views/admin/product/edit.php', 'admin'); $fc->setPage($output); } }