public function create() { if ($this->auth->guest()) { $this->app->flash("info", "You must be logged on to register a patent"); $this->app->redirect("/login"); } else { $request = $this->app->request; $title = $request->post('title'); $description = $request->post('description'); $company = $request->post('company'); $date = date("dmY"); $file = $this->startUpload(); $validation = new PatentValidation($title, $description); if ($validation->isGoodToGo()) { $patent = new Patent($company, $title, $description, $date, $file); $patent->setCompany($company); $patent->setTitle($title); $patent->setDescription($description); $patent->setDate($date); $patent->setFile($file); $savedPatent = $this->patentRepository->save($patent); $this->app->redirect('/patents/' . $savedPatent . '?msg="Patent succesfully registered'); } } $this->app->flashNow('error', join('<br>', $validation->getValidationErrors())); $this->app->render('patents/new.twig'); }
public function save(Patent $patent) { $title = $patent->getTitle(); $company = $patent->getCompany(); $description = $patent->getDescription(); $date = $patent->getDate(); $file = $patent->getFile(); if ($patent->getPatentId() === null) { $query = "INSERT INTO patent (company, date, title, description, file) " . "VALUES ('{$company}', '{$date}', '{$title}', '{$description}', '{$file}')"; } $this->pdo->exec($query); return $this->pdo->lastInsertId(); }