public function load(ObjectManager $manager)
 {
     // create
     // a writer
     $writer = new Writer();
     $writer->setFullanme('Test Writer');
     $writer->setEmail("*****@*****.**");
     $writer->setPhone("00112233445566");
     $manager->persist($writer);
     self::$writers[] = $writer;
     // an article
     $article = new Article();
     $article->setTitle('This is a test title');
     $article->setLead('This is a test lead');
     $article->setContent('This is a test content');
     $article->setRate(1);
     $article->setWriter($writer);
     $manager->persist($article);
     self::$articles[] = $article;
     // a notifications
     $notify = new Notification();
     $notify->setNotify('This is a test notification');
     $notify->setArticles($article);
     $notify->setCreated(new \DateTime());
     $manager->persist($notify);
     self::$notifications[] = $notify;
     // an  another notifications
     $notify_2 = new Notification();
     $notify_2->setNotify('This is a test notification');
     $notify_2->setArticles($article);
     $notify_2->setCreated(new \DateTime("now"));
     self::$notifications[] = $notify_2;
     $manager->flush();
 }
Esempio n. 2
0
 public function ajoutAction(Request $request)
 {
     // Création de l'entité
     $article = new Article();
     $article->setDate(new \Datetime());
     $article->setTitle('Mettre le titre ici');
     $article->setAuthor('Qui êtes-vous ?');
     $article->setContent("Mettez ici la description de l'article.");
     // On peut ne pas définir ni la date ni la publication,
     // car ces attributs sont définis automatiquement dans le constructeur
     // On crée le formbuilder grace au service form factory
     $formBuilder = $this->get('form.factory')->createBuilder('form', $article);
     //On ajoute les champs de l'entité que l'on veut à notre formulaire
     $formBuilder->add('title', 'text')->add('content', 'textarea')->add('author', 'text')->add('published', 'checkbox')->add('save', 'submit');
     //A partir du formbuilder on génère le formulaire
     $form = $formBuilder->getForm();
     $form->HandleRequest($request);
     if ($form->isValid()) {
         //On l'enregistre en base de donnée
         $em = $this->getDoctrine()->getManager();
         $em->persist($article);
         $em->flush();
         $request->getSession()->getFlashBag()->add('notice', 'Article enregistré.');
         return $this->redirect($this->generateUrl('article_voir', array('id' => $article->getId())));
     }
     // Reste de la méthode qu'on avait déjà écrit
     //if ($request->isMethod('POST')) {
     //  $request->getSession()->getFlashBag()->ajout('article', 'Article bien enregistré.');
     // return $this->redirect($this->generateUrl('article_voir', array('id' => $article->getId())));}
     return $this->render('ArticleBundle:ArticleBlog:ajout.html.twig', array('form' => $form->createView()));
 }
Esempio n. 3
0
 public function addArticleAction(Request $request)
 {
     $form = $this->createFormBuilder()->add('title', 'text')->add('slug', 'hidden')->add('author', 'text')->add('tags', 'text')->add('content', 'ckeditor', array('input_sync' => true))->getForm();
     $form->handleRequest($request);
     if ($form->isValid()) {
         $data = $form->getData();
         $baseArticle = $this->getDoctrine()->getRepository('ArticleBundle:Article')->findBySlug($data['slug']);
         if ($baseArticle == FALSE) {
             $article = new Article();
             $article->setTitle($data['title']);
             $article->setSlug($data['slug']);
             $article->setAuthor($data['author']);
             $article->setTags($data['tags']);
             $article->setContent($data['content']);
             $em = $this->getDoctrine()->getManager();
             $em->persist($article);
             $em->flush();
             return $this->redirect('/' . $data['slug']);
         } else {
             $form->addError(new FormError("Tytuł ten występuje już w bazie wiedzy!"));
         }
     }
     return $this->render('ArticleBundle:Panel:form.html.twig', ['form' => $form->createView(), 'title' => 'Dodaj nowy artykuł']);
 }
Esempio n. 4
0
 /**
  * content test
  * @param $content
  * @param Article $article
  */
 protected function assertContent($content, Article $article)
 {
     $string = $article->getId() . '- ' . $article->getTitle() . ' - ' . $article->getRate();
     $this->assertRegexp("/{$string}/", $content);
 }