Ejemplo n.º 1
0
 public function executeInsert(HTTPRequest $request)
 {
     if ($request->method() == 'POST') {
         $categoriesManager = $this->getManagerOf($this->module(), 'Categories');
         $category = new Category();
         $category->setName($request->postData('name'));
         $category->setParentId($request->postData('parentId'));
         $categoriesManager->save($category);
         $this->app->httpResponse()->previous();
     }
 }
Ejemplo n.º 2
0
 public function executeProfil(HTTPRequest $request)
 {
     //get Users manager
     $manager = $this->getManagerOf($this->module(), 'Users');
     //If datas posts
     if ($request->method() == 'POST') {
         //get the user from data base
         $user = $manager->getUnique($this->app->session()->getAttribute('UserId'));
         //Gestion de l'image
         $maxsize = 1234567;
         $maxwidth = 123456;
         $maxheight = 123456;
         $imageHandler = new ImageHandler($_FILES['avatar'], $maxsize, $maxwidth, $maxheight);
         if ($imageHandler->saveTo(__DIR__ . '/../../../../Web/images/avatars/', $user->id())) {
             $user->setAvatar($imageHandler->newFileName());
         }
         //Gestion du reste du formulaire
         $user->setNickName($request->postData('nickname'));
         $user->setMail($request->postData('mail'));
         $user->setName($request->postData('name'));
         $user->setFirstName($request->postData('firstName'));
         $user->setAddress($request->postData('address'));
         $user->setPostCode($request->postData('postCode'));
         $user->setCity($request->postData('city'));
         $user->setCellPhone(preg_replace('[\\s|\\.|\\-]', '', $request->postData('cellPhone')));
         $user->setPhone(preg_replace('[\\s|\\.|\\-]', '', $request->postData('phone')));
         $user->setGender($request->postData('gender'));
         $manager->save($user);
         $this->app->session()->setFlash('Le profil à été mis à jour');
     }
     //Si le formulaire n'est pas envoyé
     //On récupère le membre
     $user = $manager->getUnique($this->app->session()->getAttribute('UserId'));
     //On configure la page
     $this->sendView('users:usersFront:profil', array('user' => $user));
 }
Ejemplo n.º 3
0
 protected function processForm(HTTPRequest $request)
 {
     if ($request->method() == 'POST') {
         $news = new News(['auteur' => $request->postData('auteur'), 'titre' => $request->postData('titre'), 'contenu' => $request->postData('contenu')]);
         if ($request->getExists('id')) {
             $news->setId($request->getData('id'));
         }
     } else {
         // L'identifiant de la news est transmis si on veut la modifier
         if ($request->getExists('id')) {
             $news = $this->getManagerOf($this->module(), 'News')->getUnique($request->getData('id'));
         } else {
             $news = new News();
         }
     }
     $formBuilder = new NewsFormBuilder($news);
     $formBuilder->build();
     $form = $formBuilder->form();
     $formHandler = new FormHandler($form, $this->getManagerOf($this->module(), 'News'), $request);
     if ($formHandler->process()) {
         $this->app->session()->setFlash($news->isNew() ? 'La news a bien été ajoutée !' : 'La news a bien été modifiée !');
         $this->app->httpResponse()->redirect('/admin/');
     }
     $this->page->addVar('form', $form->createView());
 }