Esempio n. 1
0
 public function load(ObjectManager $manager)
 {
     $comment1 = new Comment();
     $comment1->setTitle('Sample Comment 1');
     $comment1->setUsername('blogger1');
     $comment1->setComment('To make a long story short. You can\'t go wrong by choosing Symfony! And no one has ever been fired for using Symfony.');
     $comment1->setApproved(true);
     $comment1->setCreated(new \DateTime());
     $comment1->setCommentType('Blog');
     $comment1->setBlogPost($manager->merge($this->getReference('blog1')));
     $manager->persist($comment1);
     $comment2 = new Comment();
     $comment2->setTitle('Sample Comment 2');
     $comment2->setUsername('blogger2');
     $comment2->setComment('To make a long story short. You can\'t go wrong by choosing Symfony! And no one has ever been fired for using Symfony 2.');
     $comment2->setApproved(true);
     $comment2->setCreated(new \DateTime());
     $comment2->setCommentType('Blog');
     $comment2->setBlogPost($manager->merge($this->getReference('blog1')));
     $manager->persist($comment2);
     $comment3 = new Comment();
     $comment3->setTitle('Sample Comment 3');
     $comment3->setUsername('blogger3');
     $comment3->setComment('To make a long story short. You can\'t go wrong by choosing Symfony! And no one has ever been fired for using Symfony 3.');
     $comment3->setApproved(true);
     $comment3->setCreated(new \DateTime());
     $comment3->setCommentType('Blog');
     $comment3->setBlogPost($manager->merge($this->getReference('blog1')));
     $manager->persist($comment3);
     $manager->flush();
 }
Esempio n. 2
0
 protected function createComment($commentType, $associated_object, $associated_object_id)
 {
     // Create new comment object and associate with the desired object
     $comment = new Comment();
     if ($commentType == 'Blog') {
         $comment->setBlogPost($associated_object);
         $comment->setCommentType('Blog');
         $comment->setApproved(false);
     } else {
         throw $this->createNotFoundException('Commenting is not available.');
     }
     // get the request and check if it was ajax based
     $request = $this->getRequest();
     $ajaxForm = $request->get('isAjax');
     if (!isset($ajaxForm) || !$ajaxForm) {
         $ajaxForm = false;
     }
     // Bind the request to the comment form
     $form = $this->createForm(new CommentType(), $comment);
     $form->handleRequest($request);
     //Prepare the responce data
     $errorList = array();
     $successMsg = '';
     $formhasErrors = true;
     if ($form->isValid()) {
         // Persist (save) the form data to the database
         $em = $this->getDoctrine()->getManager();
         $em->persist($comment);
         $em->flush();
         // The responce for the user upon successful submission
         $successMsg = 'Thank you submitting your comment.';
         $formMessage = $successMsg;
         $formhasErrors = false;
     } else {
         // Validate the data and get errors
         $errorList = $this->getFormErrorMessages($form);
         $formMessage = 'There was an error submitting your comment. Please try again.';
     }
     // Return the responce to the user
     if ($ajaxForm) {
         $ajaxFormData = array('errors' => $errorList, 'formMessage' => $formMessage, 'hasErrors' => $formhasErrors);
         // Return the responce in json format
         $ajaxFormResponce = new Response(json_encode($ajaxFormData));
         $ajaxFormResponce->headers->set('Content-Type', 'application/json');
         return $ajaxFormResponce;
     } else {
         if ($commentType == 'Blog') {
             // Clear the form data object if it was submited successfully
             if (!$formhasErrors) {
                 $comment = new Comment();
             }
             // Retrieving the comments the view
             $postComments = $this->getBlogPostComments($associated_object_id);
             // get the blog post details (similar to the blog bundle)
             $settings = $this->get('bardiscms_settings.load_settings')->loadSettings();
             $page = $this->setBlogSettings($settings, $associated_object);
             // Return the responce as the blog post with form data
             return $this->render('BlogBundle:Default:page.html.twig', array('page' => $page, 'form' => $form->createView(), 'comments' => $postComments, 'comment' => $comment, 'ajaxform' => $ajaxForm, 'formMessage' => $formMessage));
         } else {
             throw $this->createNotFoundException('Commenting is not available.');
         }
     }
 }
Esempio n. 3
0
 protected function renderPage($page, $id, $publishStates, $extraParams, $currentpage, $totalpageitems, $linkUrlParams)
 {
     // Check if mobile content should be served
     $serveMobile = $this->get('bardiscms_mobile_detect.device_detection')->testMobile();
     $settings = $this->get('bardiscms_settings.load_settings')->loadSettings();
     if ($page->getPagetype() == 'blog_cat_page') {
         $tagIds = $this->getTagFilterIds($page->getTags()->toArray());
         $categoryIds = $this->getCategoryFilterIds($page->getCategories()->toArray());
         if (!empty($tagIds)) {
             $pageList = $this->getDoctrine()->getRepository('BlogBundle:Blog')->getTaggedCategoryItems($categoryIds, $id, $publishStates, $currentpage, $totalpageitems, $tagIds);
         } else {
             $pageList = $this->getDoctrine()->getRepository('BlogBundle:Blog')->getCategoryItems($categoryIds, $id, $publishStates, $currentpage, $totalpageitems);
         }
         $pages = $pageList['pages'];
         $totalPages = $pageList['totalPages'];
         $response = $this->render('BlogBundle:Default:page.html.twig', array('page' => $page, 'pages' => $pages, 'totalPages' => $totalPages, 'extraParams' => $extraParams, 'currentpage' => $currentpage, 'linkUrlParams' => $linkUrlParams, 'totalpageitems' => $totalpageitems, 'mobile' => $serveMobile));
     } else {
         if ($page->getPagetype() == 'blog_filtered_list') {
             $filterForm = $this->createForm('filterblogpostsform');
             $filterData = $this->getRequestedFilters($extraParams);
             $tagIds = $this->getTagFilterIds($filterData['tags']->toArray());
             $categoryIds = $this->getCategoryFilterIds($filterData['categories']->toArray());
             $filterForm->setData($filterData);
             if (!empty($categoryIds)) {
                 $pageList = $this->getDoctrine()->getRepository('BlogBundle:Blog')->getTaggedCategoryItems($categoryIds, $id, $publishStates, $currentpage, $totalpageitems, $tagIds);
             } else {
                 $pageList = $this->getDoctrine()->getRepository('BlogBundle:Blog')->getTaggedItems($tagIds, $id, $publishStates, $currentpage, $totalpageitems);
             }
             $pages = $pageList['pages'];
             $totalPages = $pageList['totalPages'];
             $response = $this->render('BlogBundle:Default:page.html.twig', array('page' => $page, 'pages' => $pages, 'totalPages' => $totalPages, 'extraParams' => $extraParams, 'currentpage' => $currentpage, 'linkUrlParams' => $linkUrlParams, 'totalpageitems' => $totalpageitems, 'filterForm' => $filterForm->createView(), 'mobile' => $serveMobile));
         } else {
             if ($page->getPagetype() == 'blog_home') {
                 $pageList = $this->getDoctrine()->getRepository('BlogBundle:Blog')->getAllItems($id, $publishStates, $currentpage, $totalpageitems);
                 $pages = $pageList['pages'];
                 $totalPages = $pageList['totalPages'];
                 $response = $this->render('BlogBundle:Default:page.html.twig', array('page' => $page, 'pages' => $pages, 'totalPages' => $totalPages, 'extraParams' => $extraParams, 'currentpage' => $currentpage, 'linkUrlParams' => $linkUrlParams, 'totalpageitems' => $totalpageitems, 'mobile' => $serveMobile));
             } else {
                 $commentsEnabled = true;
                 if ($commentsEnabled) {
                     // Retrieving the comments the views
                     $postComments = $this->getPostComments($id);
                     // Adding the form for new comment
                     $comment = new Comment();
                     $comment->setBlogPost($page);
                     $form = $this->createForm(new CommentType(), $comment);
                     $response = $this->render('BlogBundle:Default:page.html.twig', array('page' => $page, 'form' => $form->createView(), 'comments' => $postComments, 'mobile' => $serveMobile));
                 } else {
                     $response = $this->render('BlogBundle:Default:page.html.twig', array('page' => $page, 'mobile' => $serveMobile));
                 }
             }
         }
     }
     if ($this->container->getParameter('kernel.environment') == 'prod' && $settings->getActivateHttpCache()) {
         // set a custom Cache-Control directive
         $response->setPublic();
         $response->setLastModified($page->getDateLastModified());
         $response->setVary(array('Accept-Encoding', 'User-Agent'));
         $response->headers->addCacheControlDirective('must-revalidate', true);
         $response->setSharedMaxAge(3600);
     }
     return $response;
 }