Exemplo n.º 1
0
 public function executeIndex(HTTPRequest $request)
 {
     $this->run();
     if ($request->method() == 'POST') {
         $member = new Member(['username' => $request->postData('username'), 'password' => $request->postData('password')]);
     } else {
         $member = new Member();
     }
     $formBuilder = new AutorFormBuilder($member);
     $formBuilder->build($this->managers->getManagerOf('Member'));
     $form = $formBuilder->form();
     $formHandler = new FormHandler($form, $this->managers->getManagerOf('Member'), $request);
     $entier = (int) $this->managers->getManagerOf('Member')->getId($member->username());
     if ($formHandler->process()) {
         $this->app->user()->setMember(1);
         // on met 1 pour auteur, il faudrait le faire dynamiquement ? (récupérer $member->priority() ?
         $this->app->user()->setUsername($member->username());
         $this->app->user()->setId($entier);
         //récupérer l'id du member
         $this->app->user()->setFlash('Tu es connecté');
         $this->app->httpResponse()->redirect($this->app->router()->getBuiltRoute('News', 'index', []));
     }
     $this->page->addVar('title', 'Connexion');
     $this->page->addVar('Member', $member);
     $this->page->addVar('form', $form->createView());
 }
Exemplo n.º 2
0
 public function processForm(HTTPRequest $request)
 {
     if ($request->method() == "POST") {
         $member = new Member(['login' => $request->postData('login'), 'password' => $request->postData('password'), 'level' => $request->postData('level')]);
         if ($request->getExists('id')) {
             $member->setId($request->getData('id'));
         }
     } else {
         // L'identifiant de l'utilisateur est transmis si on veut le modifier
         if ($request->getExists('id')) {
             $member = $this->managers->getManagerOf('Member')->getUnique($request->getData('id'));
         } else {
             $member = new Member();
         }
     }
     $formBuilder = new AdminFormBuilder($member);
     $formBuilder->build();
     $form = $formBuilder->form();
     // On récupère le gestionnaire de formulaire (le paramètre de getManagerOf() est bien entendu à remplacer).
     $formHandler = new \OCFram\FormHandler($form, $this->managers->getManagerOf('Member'), $request);
     if ($formHandler->process()) {
         if ($member->id() == $this->app->user()->getAttribute('user')->id()) {
             $this->app->user()->setAttribute('user', $member);
         }
         // Ici ne résident plus que les opérations à effectuer une fois l'entité du formulaire enregistrée
         // (affichage d'un message informatif, redirection, etc.).
         $this->app->user()->setFlash($member->isNew() ? 'L \'utilisateur a bien été ajouté !' : 'L\'utiilsateur a bien été modifié !');
         $this->app->httpResponse()->redirect('/admin/members.html');
     }
     $this->page->addVar('form', $form->createView());
     $this->run();
 }
Exemplo n.º 3
0
 public 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->managers->getManagerOf('News')->getUnique($request->getData('id'));
         } else {
             $news = new News();
         }
     }
     $formBuilder = new NewsFormBuilder($news);
     $formBuilder->build();
     $form = $formBuilder->form();
     // On récupère le gestionnaire de formulaire (le paramètre de getManagerOf() est bien entendu à remplacer).
     $formHandler = new \OCFram\FormHandler($form, $this->managers->getManagerOf('News'), $request);
     if ($formHandler->process()) {
         // Ici ne résident plus que les opérations à effectuer une fois l'entité du formulaire enregistrée
         // (affichage d'un message informatif, redirection, etc.).
         $this->app->user()->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());
 }
Exemplo n.º 4
0
 public 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->managers->getManagerOf('News')->getUnique($request->getData('id'));
         } else {
             $news = new News();
         }
     }
     $formBuilder = new NewsFormBuilder($news);
     $formBuilder->build();
     $form = $formBuilder->form();
     $formHandler = new FormHandler($form, $this->managers->getManagerOf('News'), $request);
     if ($formHandler->process()) {
         $this->app->user()->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());
 }
Exemplo n.º 5
0
 public function executeInscription(HTTPRequest $Request)
 {
     $this->page->addVar('title', 'Inscription');
     $this->run();
     if ($Request->method() == 'POST') {
         $Member = new Member();
         $Member->setLogin($Request->postData('login'));
         $Member->setPassword($Request->postData('password'));
         $Member->setPassword_confirmation($Request->postData('password_confirmation'));
         $Member->setEmail($Request->postData('email'));
         $Member->setLevel(3);
     } else {
         $Member = new Member();
     }
     $FormBuilder = new MemberFormBuilder($Member, $this->managers->getManagerOf('Member'));
     $FormBuilder->build();
     $Form = $FormBuilder->form();
     // On récupère le gestionnaire de formulaire.
     $FormHandler = new \OCFram\FormHandler($Form, $this->managers->getManagerOf('Member'), $Request);
     if ($FormHandler->process()) {
         // Ici ne résident plus que les opérations à effectuer une fois l'entité du formulaire enregistrée
         // (affichage d'un message informatif, redirection, etc.).
         $this->app->user()->setFlash('Le membre a bien été ajouté, merci !');
         $this->app->user()->setAuthenticated(true);
         $this->app->user()->setAttribute('user', $Member);
         $this->app->httpResponse()->redirect('.');
     }
     $Router = new Router();
     $this->page->addVar('form', $Form->createView());
     $this->page->addVar('router', $Router);
 }
Exemplo n.º 6
0
 public function executeShow(HTTPRequest $request)
 {
     $news = $this->managers->getManagerOf('News')->getUnique($request->getData('id'));
     if (empty($news)) {
         $this->app->httpResponse()->redirect404();
         $this->run();
     }
     // Si le formulaire a été envoyé.
     if ($request->method() == 'POST') {
         $Comment = new Comment(['newsId' => $request->getData('news_id'), 'auteurId' => $this->app->user()->getAttribute('user')->id(), 'contenu' => $request->postData('contenu')]);
     } else {
         $Comment = new Comment();
     }
     $formBuilder = new CommentFormBuilder($Comment);
     $formBuilder->build();
     $form = $formBuilder->form();
     // On récupère le gestionnaire de formulaire (le paramètre de getManagerOf() est bien entendu à remplacer).
     $formHandler = new \OCFram\FormHandler($form, $this->managers->getManagerOf('Comments'), $request);
     if ($formHandler->process()) {
         // Ici ne résident plus que les opérations à effectuer une fois l'entité du formulaire enregistrée
         // (affichage d'un message informatif, redirection, etc.).
         $this->app->user()->setFlash('Le commentaire a bien été ajouté, merci !');
         $this->app->httpResponse()->redirect('../news-' . $request->getData('news_id') . '.html');
     }
     $Router = new Router();
     $form_action = $Router->getUrl('Backend', 'News', 'insertComment', array('news_id' => $request->getData('id')));
     $form_action_ajax_validation = $Router->getUrl('Backend', 'News', 'insertCommentUsingAjax', array('news_id' => $request->getData('id')));
     $jsFiles_a = array();
     $jsFiles_a[] = '<script type="text/javascript" src="/js/CommentInsertUsingAjax.js"></script>';
     $news_id = $request->getData('id');
     $this->run();
     $this->page->addVar('news_id', $news_id);
     $this->page->addVar('form_action', $form_action);
     $this->page->addVar('form_action_ajax_validation', $form_action_ajax_validation);
     $this->page->addVar('comment', $Comment);
     $this->page->addVar('form', $form->createView());
     $this->page->addVar('title', 'Ajout d\'un commentaire');
     $this->page->addVar('jsFiles_a', $jsFiles_a);
     $this->page->addVar('router', new Router());
     $this->page->addVar('title', $news->titre());
     $this->page->addVar('news', $news);
     $this->page->addVar('comments', $this->managers->getManagerOf('Comments')->getListOf($news->id()));
 }
Exemplo n.º 7
0
 public function executeInsertComment(HTTPRequest $request)
 {
     // Si le formulaire a été envoyé.
     if ($request->method() == 'POST') {
         $comment = new Comment(['news' => $request->getData('news'), 'auteur' => $request->postData('auteur'), 'contenu' => $request->postData('contenu')]);
     } else {
         $comment = new Comment();
     }
     $formBuilder = new CommentFormBuilder($comment);
     $formBuilder->build();
     $form = $formBuilder->form();
     $formHandler = new FormHandler($form, $this->managers->getManagerOf('Comments'), $request);
     if ($formHandler->process()) {
         $this->app->user()->setFlash('Le commentaire a bien été ajouté, merci !');
         $this->app->httpResponse()->redirect('news-' . $request->getData('news') . '.html');
     }
     $this->page->addVar('comment', $comment);
     $this->page->addVar('form', $form->createView());
     $this->page->addVar('title', 'Ajout d\'un commentaire');
 }
Exemplo n.º 8
0
 public function executeIndex(HTTPRequest $request)
 {
     $this->run();
     if ($request->method() == 'POST') {
         $member = new Member(['username' => $request->postData('username'), 'password' => $request->postData('password')]);
     } else {
         $member = new Member();
     }
     $formBuilder = new MemberFormBuilder($member);
     $formBuilder->build($this->managers->getManagerOf('Member'));
     $form = $formBuilder->form();
     $formHandler = new FormHandler($form, $this->managers->getManagerOf('Member'), $request);
     if ($formHandler->process()) {
         $this->app->user()->setAuthenticated(true);
         $this->app->httpResponse()->redirect($this->app->router()->getBuiltRoute('News', 'index', []));
     }
     $this->page->addVar('title', 'Connexion');
     $this->page->addVar('Member', $member);
     $this->page->addVar('form', $form->createView());
 }
 public function executeIndex(HTTPRequest $request)
 {
     if ($request->method() == 'POST') {
         $member = new Member(['pseudo' => $request->postData('pseudo'), 'password' => $request->postData('password'), 'email' => $request->postData('email'), 'philosophy' => $request->postData('philosophy'), 'type' => Member::TYPE_AUTHOR]);
     } else {
         $member = new Member();
     }
     $membersManager = $this->managers->getManagerOf('Members');
     $formBuilder = new MemberFormBuilder($member);
     $formBuilder->build($this->managers->getManagerOf('Members'));
     $form = $formBuilder->form();
     $formHandler = new FormHandler($form, $membersManager, $request);
     if ($formHandler->process()) {
         $this->app->user()->setFlash('Merci de votre inscription !');
         $this->app->httpResponse()->redirect('/');
     }
     $this->page->addVar('member', $member);
     $this->page->addVar('form', $form->createView());
     $this->page->addVar('title', 'Ajout d\'un membre');
 }
Exemplo n.º 10
0
 public function executeIndex(HTTPRequest $request)
 {
     $this->run();
     if ($request->method() == 'POST') {
         $member = new Member(['username' => $request->postData('username'), 'password' => $request->postData('password'), 'confirmation' => $request->postData('confirmation'), 'description' => $request->postData('description'), 'mail' => $request->postData('mail')]);
     } else {
         $member = new Member();
         // on garde cette entité member ?
     }
     $formBuilder = new RegisterFormBuilder($member);
     // même formbuilder ?
     $formBuilder->build($this->managers->getManagerOf('Member'));
     $form = $formBuilder->form();
     $formHandler = new FormHandler($form, $this->managers->getManagerOf('Member'), $request);
     if ($formHandler->process()) {
         $this->app->user()->setFlash('vous êtes bien inscrit');
         $this->app->httpResponse()->redirect('.');
     }
     $this->page->addVar('title', 'Inscription');
     $this->page->addVar('Member', $member);
     $this->page->addVar('form', $form->createView());
 }
Exemplo n.º 11
0
 public function executeIndex(HTTPRequest $request)
 {
     if ($request->method() == 'POST') {
         $member = new Member(['pseudo' => $request->postData('pseudo'), 'password' => $request->postData('password')]);
     } else {
         $member = new Member();
     }
     $formBuilder = new ConnexionFormBuilder($member);
     $formBuilder->build($this->managers->getManagerOf('Members'));
     $form = $formBuilder->form();
     $formHandler = new FormHandler($form, $this->managers->getManagerOf('Members'), $request);
     /**@var $memberManager MembersManager */
     $memberManager = $this->managers->getManagerOf('Members');
     if ($formHandler->verify()) {
         $this->app->user()->setFlash('Vous etes désormais connecté');
         $this->app->user()->setAuthenticated($memberManager->getUnique($memberManager->connect($request->postData('pseudo'), $request->postData('password'))));
         $this->app->httpResponse()->redirect('/');
     }
     $this->page->addVar('member', $member);
     $this->page->addVar('form', $form->createView());
     $this->page->addVar('title', 'Connexion');
 }
Exemplo n.º 12
0
 public function executeInsertComment(HTTPRequest $request)
 {
     // Si le formulaire a été envoyé.
     if ($request->method() == 'POST') {
         $comment = new Comment(['news' => $request->getData('news'), 'auteur' => $request->postData('auteur'), 'contenu' => $request->postData('contenu')]);
     } else {
         $comment = new Comment();
     }
     $formBuilder = new CommentFormBuilder($comment);
     $formBuilder->build();
     $form = $formBuilder->form();
     // On récupère le gestionnaire de formulaire (le paramètre de getManagerOf() est bien entendu à remplacer).
     $formHandler = new \OCFram\FormHandler($form, $this->managers->getManagerOf('Comments'), $request);
     if ($formHandler->process()) {
         // Ici ne résident plus que les opérations à effectuer une fois l'entité du formulaire enregistrée
         // (affichage d'un message informatif, redirection, etc.).
         $this->app->user()->setFlash('Le commentaire a bien été ajouté, merci !');
         $this->app->httpResponse()->redirect('news-' . $request->getData('news') . '.html');
     }
     $this->page->addVar('comment', $comment);
     $this->page->addVar('form', $form->createView());
     $this->page->addVar('title', 'Ajout d\'un commentaire');
 }
Exemplo n.º 13
0
 public function executeTestInsertComment(HTTPRequest $request)
 {
     if ($request->method() == 'POST') {
         $comment = new Comment(['news' => $request->getData('news'), 'auteur' => $request->postData('auteur'), 'email' => $request->postData('email'), 'contenu' => $request->postData('contenu')]);
     } else {
         $comment = new Comment();
     }
     if (!$this->managers->getManagerOf('News')->getUnique($request->getData('news'))) {
         if ($request->method() == 'POST') {
             $this->app()->user()->setFlash('La news a été supprimée pendant que vous la commentiez, désolé !');
         }
         $this->generateOtherPage('error', 'La news n°' . $request->getData('news') . ' n\'existe pas');
         return;
     }
     $formBuilder = new CommentFormBuilder($comment);
     $formBuilder->build($this->app()->user()->isAuthenticated(), $this->managers->getManagerOf('Members'), $this->app()->user()->isAuthenticated() ? $this->app()->user()->member()->id() : null);
     $form = $formBuilder->form();
     $formHandler = new FormHandler($form, $this->managers->getManagerOf('Comments'), $request);
     echo json_encode($formHandler->processJSON());
     exit;
 }
Exemplo n.º 14
0
 public function processForm(HTTPRequest $request)
 {
     $this->run();
     //manager news
     $managersNews = $this->managers->getManagerOf('News');
     // manager tag
     $managersTag = $this->managers->getManagerOf('Tag');
     if ($request->method() == 'POST') {
         // Éléménet News
         $news = new News(['auteur' => $this->app->user()->getAttribute('user'), 'titre' => $request->postData('titre'), 'contenu' => $request->postData('contenu')]);
         // Élément Tag
         if ($request->postData('name') != '') {
             $tag = new Tag(['name' => $request->postData('name')]);
             $table = NewsController::separateTag($tag->name());
             //vraiment ici ?
             //on sauvegarde tout les tags rentré si ils n'existes pas !
         } else {
             $tag = new Tag();
         }
         if ($request->getExists('id')) {
             $news->setId($request->getData('id'));
             $tag = new Tag();
         }
     } else {
         // L'identifiant de la news est transmis si on veut la modifier
         if ($request->getExists('id')) {
             $news = $managersNews->getUnique($request->getData('id'));
             $text = '';
             foreach ($managersTag->getUnique($request->getData('id')) as $value) {
                 $text = $text . ' ' . $value['NTC_name'];
             }
             $tag = new Tag(['name' => $text]);
             if ($news == null) {
                 $this->app->httpResponse()->redirect404();
             }
         } else {
             $news = new News();
             $tag = new Tag();
         }
     }
     //construction formulaire news
     $formBuilderNews = new NewsMemberFormBuilder($news);
     $formBuilderNews->build();
     $formNews = $formBuilderNews->form();
     $formHandlerNews = new FormHandler($formNews, $managersNews, $request);
     //Construction formulaire Tag
     $formBuilderTag = new TagFormBuilder($tag);
     // même formbuilder ?
     $formBuilderTag->build($managersTag);
     $formTag = $formBuilderTag->form();
     // manager tagd
     $managersTagd = $this->managers->getManagerOf('Tagd');
     if ($formHandlerNews->process()) {
         //Refaire proprement le handler pour les tags
         $this->app->user()->setFlash($news->isNew() ? 'La news a bien été ajoutée !' : 'La news a bien été modifiée !');
         // récupérer le dernier id de news
         if ($news->isNew()) {
             $news->setId($managersNews->getlastid());
         }
         //var_dump($news->id());
         NewsController::saveTag($table, $managersTag);
         foreach ($table as $key => $value) {
             $idtag = $managersTag->getId($value);
             $tagd = new Tagd();
             $tagd->setIdnew($news->id());
             $tagd->setIdtag($idtag);
             $managersTagd->add($tagd);
         }
         $this->app->httpResponse()->redirect($this->app->router()->getBuiltRoute('News', 'index', []));
     }
     $this->page->addVar('formNews', $formNews->createView());
     $this->page->addVar('formTag', $formTag->createView());
 }
Exemplo n.º 15
0
 public function executeUpdateCommentUsingAjax(HTTPRequest $Request)
 {
     $ManagerComment = $this->managers->getManagerof('Comments');
     $Comment = $ManagerComment->getUnique($Request->getData('comment_id'));
     $Membre = $this->app->user()->getAttribute('user');
     $this->page->setTemplate('jsonLayout.php');
     if (!$Comment) {
         $this->page->addVar('ajax', json_encode(array('success' => false, 'erreurs' => 'Le commentaire n\'existe pas !')));
         return;
     }
     if ($Comment->Membre()->id() != $Membre->id() && $Membre->level() != MemberManager::ADMINISTRATOR) {
         $this->page->addVar('ajax', json_encode(array('success' => false, 'erreurs' => 'Droits insuffisants')));
         return;
     }
     $CommentPosted = new Comment();
     $CommentPosted->setId($Request->getData('comment_id'));
     $CommentPosted->setAuteurId($this->app->user()->getAttribute('user')->id());
     $CommentPosted->setContenu($Request->postData('contenu'));
     $FormBuilder = new CommentFormBuilder($CommentPosted);
     $FormBuilder->build();
     $Form = $FormBuilder->form();
     // On récupère le gestionnaire de formulaire (le paramètre de getManagerOf() est bien entendu à remplacer).
     $FormHandler = new \OCFram\FormHandler($Form, $ManagerComment, $Request);
     if (!$FormHandler->process()) {
         $errors_a = [];
         foreach ($Form->fields() as $Field) {
             $Field->isValid();
             $errors_a[$Field->id()] = $Field->errorMessage();
         }
         $this->page->setTemplate('jsonLayout.php');
         $this->page->addVar('ajax', json_encode(array('success' => false, 'erreurs' => $errors_a)));
         return;
     }
     $CommentPosted = $ManagerComment->getUnique($CommentPosted->id());
     $this->page->addVar('ajax', json_encode(array('success' => true, 'comment' => $CommentPosted)));
 }
 /**
  * Méthode pour l'action updateComment
  * La méthode contrôle les valeurs du formulaire
  * et modifie le commentaire en DB si l'ensemble des données sont valides
  * L'utilisateur est redirigé vers la news qu'il lisait
  * Un champ caché doit être ajouté dans le formulaire
  * pour transmettre le paramètre identifiant de la news
  * 
  * @param HTTPRequest $request
  * @return void
  */
 public function executeUpdateComment(HTTPRequest $request)
 {
     $this->page->addVar('title', 'Modification d\'un commentaire');
     if ($request->method() == 'POST') {
         $comment = new Comment(['id' => $request->getData('id'), 'auteur' => $request->postData('auteur'), 'contenu' => $request->postData('contenu')]);
     } else {
         $comment = $this->managers->getManagerOf('Comments')->get($request->getData('id'));
     }
     $formBuilder = new CommentFormBuilder($comment);
     $formBuilder->build();
     $form = $formBuilder->form();
     $formHandler = new FormHandler($form, $this->managers->getManagerOf('Comments'), $request);
     if ($formHandler->process()) {
         $this->app->user()->setFlash('Le commentaire a bien été modifié');
         $this->app->httpResponse()->redirect('/admin/');
     }
     $this->page->addVar('form', $form->createView());
 }
Exemplo n.º 17
0
 public function processForm(HTTPRequest $request)
 {
     if (!$this->app()->user()->isAuthenticated()) {
         $this->app->user()->setFlash('Connectez vous ou inscrivez vous pour accéder à cette section');
         $this->app->httpResponse()->redirect('/');
     }
     if ($request->method() == 'POST') {
         $news = new News(['auteur' => $this->app()->user()->member()->id(), 'titre' => $request->postData('titre'), 'contenu' => $request->postData('contenu'), 'tags' => $request->postData('tags')]);
         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->managers->getManagerOf('News')->getUnique($request->getData('id'), true);
             if ($news == NULL) {
                 $this->app()->httpResponse()->redirect404();
             }
         } else {
             $news = new News();
         }
     }
     $formBuilder = new NewsFormBuilder($news);
     $formBuilder->build();
     $form = $formBuilder->form();
     $formHandler = new FormHandler($form, $this->managers->getManagerOf('News'), $request);
     if ($formHandler->process()) {
         $this->app->user()->setFlash($news->isNew() ? 'La news a bien été ajoutée !' : 'La news a bien été modifiée !');
         $this->app->httpResponse()->redirect('/');
     }
     $this->managers->getManagerOf('News')->saveTags($news);
     $this->page->addVar('form', $form->createView());
 }