function add() { $this->checkToken(); if (isset($_POST['add'])) { if ($_POST['categoryName'] == null) { echo 'Enter name!'; die; } $category = new Category($_POST['categoryName']); CategoriesRepository::create()->add($category); $this->redirect('home', 'userHome'); } }
public function edit() { $this->checkToken(); if ($_SESSION['roleId'] < 2) { $this->redirect('users', 'usersHome'); } $_SESSION['categories'] = CategoriesRepository::create()->getAll(); $_SESSION['product'] = $this->productRepository->getProduct($this->parameters[0]); if ($_SESSION['userId'] != $_SESSION['product']['editorId']) { echo 'You are not the editor of the product!'; die; } if (isset($_POST['edit'])) { $name = $_POST['name']; $price = floatval($_POST['price']); $quantity = floatval($_POST['quantity']); $categoryId = intval($_POST['category']); $editorID = intval($_SESSION['userId']); $id = $_SESSION['product']['id']; $product = new Product($name, $categoryId, $price, $quantity, $editorID, $id); ProductRepository::create()->edit($product); $this->redirect('home', 'editorHome'); } }