public function find()
 {
     $find = new CategoryModel();
     $find->id = (int) Request::get('find_value');
     $result = $find->getAll();
     $this->set("categorys", $result);
     return View('category.index');
 }
 public function actionCreate()
 {
     $errors = [];
     $categories = CategoryModel::getAll(false, true);
     $product = new ProductModel();
     if (isset($_POST['submit'])) {
         $name = FL::clearStr($_POST['name']);
         $categoryId = FL::clearInt($_POST['category_id']);
         $code = FL::clearInt($_POST['code']);
         $price = FL::clearFloat($_POST['price']);
         $availability = FL::clearInt($_POST['availability']);
         $brand = FL::clearStr($_POST['brand']);
         $description = FL::clearStr($_POST['description']);
         $isNew = FL::clearInt($_POST['is_new']);
         $isRecommended = FL::clearInt($_POST['is_recommended']);
         $status = FL::clearInt($_POST['status']);
         if (!FL::isValue($name)) {
             $errors[] = 'Название не может быть пустым';
         }
         if (empty($errors)) {
             $product->name = $name;
             $product->categoryId = $categoryId;
             $product->code = $code;
             $product->price = $price;
             $product->availability = $availability;
             $product->brand = $brand;
             $product->description = $description;
             $product->isNew = $isNew;
             $product->isRecommended = $isRecommended;
             $product->status = $status;
             $id = $product->save();
             if (!$id) {
                 $errors[] = 'Произошла ошибка';
             } else {
                 FL::redirectTo('/admin/product');
             }
         }
     }
     $view = new View();
     $view->categories = $categories;
     $view->errors = $errors;
     $view->display('admin_product/create.php');
     return true;
 }
 public function edit($id)
 {
     $release = new ReleasesModel();
     $release->id = (int) $id;
     if (Request::check(['value', 'type', 'category_id', 'description'], "POST")) {
         $release = new ReleasesModel();
         $release->id = (int) $id;
         $release->update->type = Request::get('type');
         $release->update->category_id = Request::get('category_id');
         $release->update->description = Request::get('description');
         $release->update->value = Request::get('value');
         $release->update();
         $this->set("success", "Lançamento atualizado com sucesso!");
     }
     $result = $release->get();
     $category = new CategoryModel();
     $resultCategory = $category->getAll();
     $this->set("categorys", $resultCategory);
     $this->set($this->output, $result);
     $this->set("id", $id);
     return View("releases.edit");
 }
 public function actionCreate()
 {
     $errors = [];
     $name = '';
     $sortOrder = '';
     $status = '';
     $categories = CategoryModel::getAll(false, true);
     $totalCategories = CategoryModel::getTotal();
     $currentCategory = $totalCategories + 1;
     if (isset($_POST['submit'])) {
         $name = FL::clearStr($_POST['name']);
         $status = FL::clearInt($_POST['status']);
         $sortOrder = FL::clearInt($currentCategory);
         if (!FL::isValue($name)) {
             $errors[] = 'Название не может быть пустым';
         }
         if (empty($errors)) {
             $category = new CategoryModel();
             $category->name = $name;
             $category->sort_order = $sortOrder;
             $category->status = $status;
             $res = $category->save();
             if (!$res) {
                 $errors[] = 'Произошла ошибка при добавлении!';
             } else {
                 FL::redirectTo('/admin/category');
             }
         }
     }
     $view = new View();
     $view->categories = $categories;
     $view->currentCategory = $currentCategory;
     $view->errors = $errors;
     $view->display('admin_category/create.php');
     return true;
 }