/**
  * @Route("/create", name="create_objects")
  *
  * @Rest\View()
  *
  * @return Response
  */
 public function createAction()
 {
     // We need an entity manager here
     $em = $this->getDoctrine()->getManager();
     // First, we try to create a post
     $post = new Post();
     $post->setTitle('Hello World');
     $post->setContent('This is a hello world post');
     $post->setCreated(new \DateTime());
     $em->persist($post);
     // Create new post log object
     $postLog = new PostLog();
     $postLog->setMessage('A new post was created');
     $postLog->setCreated(new \DateTime());
     $postLog->setParent($post);
     $em->persist($postLog);
     // Try to create a category
     $category = new Category();
     $category->setTitle('A Category');
     $category->setDescription('A category to created');
     $em->persist($category);
     // Create new category log object
     $categoryLog = new CategoryLog();
     $categoryLog->setMessage('A new category was created');
     $categoryLog->setCreated(new \DateTime());
     $categoryLog->setParent($category);
     $em->persist($categoryLog);
     // Actually store all the entities to the database
     // to get id of the post and the category
     $em->flush();
     return ['Done'];
 }
Exemple #2
0
 /**
  * @Route("/post/add/{id}", name="addPost")
  */
 public function addAction($id, Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $topic = $em->getRepository('AppBundle:Topic')->find($id);
     if (!$topic) {
         throw $this->createNotFoundException('No Topic found for id ' . $id);
     }
     $post = new Post();
     $post->setDate(new \DateTime('now'));
     $loggedIn = false;
     $securityContext = $this->container->get('security.authorization_checker');
     if ($securityContext->isGranted('IS_AUTHENTICATED_FULLY')) {
         $token = $this->get('security.token_storage')->getToken();
         /* @var $user User */
         $user = $token->getUser();
         $post->setAuthor($user);
         $post->setTopic($topic);
         $loggedIn = true;
     }
     $form = $this->createFormBuilder($post)->add('content', TextareaType::class)->add('save', SubmitType::class, array('label' => 'Reply'))->getForm();
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         $em->persist($post);
         $em->flush();
         return $this->render('Topic/watch.html.twig', array('topic' => $topic, 'form' => $form->createView(), 'loggedIn' => $loggedIn));
     }
     return $this->render('Post/add.html.twig', array('topic' => $topic, 'form' => $form->createView(), 'loggedIn' => $loggedIn));
 }
 private function loadPosts(ObjectManager $manager)
 {
     $passwordEncoder = $this->container->get('security.password_encoder');
     $user = new User();
     $user->setUsername('vvasia');
     $user->setDisplayName('Vasia Vasin');
     $user->setEmail('*****@*****.**');
     $user->setUuid('uuid');
     $encodedPassword = $passwordEncoder->encodePassword($user, 'password');
     $user->setPassword($encodedPassword);
     $user->setRoles(['ROLE_USER']);
     $manager->persist($user);
     $manager->flush();
     /** @var User $author */
     $author = $manager->getRepository('AppBundle:User')->findOneBy(['email' => '*****@*****.**']);
     foreach (range(1, 10) as $i) {
         $post = new Post();
         $post->setTitle($this->getRandomPostTitle() . ' ' . uniqid())->setSummary($this->getRandomPostSummary())->setSlug($this->container->get('slugger')->slugify($post->getTitle()))->setContent($this->getPostContent())->setAuthor($author)->setPublishedAt(new \DateTime('now - ' . $i . 'days'))->setState($this->getRandomState())->setCategory($category);
         foreach (range(1, 5) as $j) {
             $comment = new Comment();
             $comment->setUser($user)->setPublishedAt(new \DateTime('now + ' . ($i + $j) . 'seconds'))->setContent($this->getRandomCommentContent())->setPost($post);
             $manager->persist($comment);
             $post->addComment($comment);
         }
         if (rand(0, 1)) {
             $vote = new Vote();
             $vote->setAuthorEmail(rand(0, 1) ? '*****@*****.**' : '*****@*****.**');
             $vote->setPost($post);
             $vote->setVote(rand(0, 1));
         }
         $manager->persist($post);
         $category->addPost($post);
     }
     $manager->flush();
 }
 /**
  * @Route("/create", name="create_post")
  */
 public function createAction(Request $request)
 {
     // just setup a fresh $post object (remove the dummy data)
     $post = new Post();
     $post->setAuthorEmail('*****@*****.**');
     $form = $this->createForm(new PostType(), $post);
     $finder = new Finder();
     $data = $finder->files()->in($_SERVER['DOCUMENT_ROOT'] . 'Benedictux/web/upload');
     //$data = $this->get('app.scanner')->scanDir($_SERVER['DOCUMENT_ROOT'].'Benedictux/web/uploads');
     //$data = $this->get('app.scanner')->scanDirectory($this->get('request')->getBasePath());
     //$scanned_directory = array_diff(scandir('./web'), array('..', '.'));
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $slug = $this->get('app.slugger')->slugify($post->getTitle());
         $post->setSlug($slug);
         if (get_magic_quotes_gpc()) {
             $content = stripslashes($post->getContent());
             $content = $this->get('app.parser')->parserTexarea($content);
             $post->setContent($content);
         } else {
             $content = $this->get('app.parser')->parserTexarea($post->getContent());
             $post->setContent($content);
         }
         $em->persist($post);
         $em->flush();
         return $this->redirectToRoute('accueil');
     }
     return $this->render('app/postCreate.html.twig', array('form' => $form->createView(), 'data' => $data));
 }
 /**
  * Displays a form to create a new Post entity.
  *
  * @Route("/new", name="admin_post_new")
  * @Method("GET")
  * @Template()
  */
 public function newAction()
 {
     $entity = new Post();
     $entity->setCreatedAt();
     $form = $this->createCreateForm($entity);
     return array('entity' => $entity, 'form' => $form->createView());
 }
 /**
  * @Route("{page}/temat/{temat}")
  */
 public function addPostAction(Request $request, $temat, $page)
 {
     if ($this->getUser() == true) {
         $task = new Post();
         $task->setAutor($this->getUser()->getUsername());
         $task->setIdTematu($temat);
         $task->setCzasAdd(new \DateTime("now"));
         $form = $this->createFormBuilder($task)->add('Tresc', TextareaType::class)->add('Zapisz', SubmitType::class, array('label' => 'Dodaj'))->getForm();
         $form->handleRequest($request);
         if ($form->isSubmitted() && $form->isValid()) {
             $this->savePost($task);
             $this->upgradePost($page);
         }
         $em = $this->getDoctrine()->getManager();
         $query = $em->createQuery("SELECT u FROM AppBundle:Post u WHERE u.idTematu = :id ");
         $query->setParameter('id', $temat);
         $tematy = $query->getResult();
         $size = sizeof($tematy);
         return $this->render('Posts/post_page.html.twig', array('form' => $form->createView(), 'size' => $size, 'tematy' => $tematy, "page" => $page));
     } else {
         $em = $this->getDoctrine()->getManager();
         $query = $em->createQuery("SELECT u FROM AppBundle:Post u WHERE u.idTematu = :id ");
         $query->setParameter('id', $temat);
         $tematy = $query->getResult();
         $size = sizeof($tematy);
         return $this->render('Posts/post_page.html.twig', array('size' => $size, 'tematy' => $tematy, "page" => $page));
     }
 }
Exemple #7
0
 /**
  * @Route("/channel/{uniqID}/blog", name="oktothek_series_blog_post")
  * @Method({"GET", "POST"})
  * @Template()
  */
 public function blogAction(Request $request, Series $series)
 {
     $this->denyAccessUnlessGranted('edit_channel', $series);
     $post = new Post();
     $post->setIsActive(true);
     $form = $this->createForm(PostType::class, $post, ['action' => $this->generateUrl('oktothek_series_blog_post', ['uniqID' => $series->getUniqID()])]);
     $form->add('submit', SubmitType::class, ['label' => 'oktothek.post_create_button', 'attr' => ['class' => 'btn btn-primary']]);
     if ($request->getMethod() == "POST") {
         //sends form
         $form->handleRequest($request);
         if ($form->isValid()) {
             $em = $this->getDoctrine()->getManager();
             $series->addPost($post);
             foreach ($post->getAssets() as $asset) {
                 $asset->setSeries($series);
                 $em->persist($asset);
             }
             $em->persist($post);
             $em->persist($series);
             $em->flush();
             $this->get('session')->getFlashBag()->add('success', 'oktothek.success_create_post');
             $this->get('oktothek_notification_service')->createNewPostNotifications($post);
             return $this->redirect($this->generateUrl('oktothek_channel_blogposts', ['uniqID' => $series->getUniqID()]));
         } else {
             $this->get('session')->getFlashBag()->add('error', 'oktothek.error_create_post');
         }
     }
     return ['form' => $form->createView(), 'series' => $series];
 }
 private function canEdit(Post $post, UserInterface $user, TokenInterface $token)
 {
     if ($this->decisionManager->decide($token, ['ROLE_MANAGER']) && $post->getOwner() == $user) {
         return true;
     }
     return false;
 }
Exemple #9
0
 public function addPost(Post $post, User $user)
 {
     $post->setAuthor($user);
     $this->em->persist($post);
     $user->setLastPost($post);
     $user->increasePostsCount();
     $this->em->flush();
 }
Exemple #10
0
 public function save(Post $entity)
 {
     $entity->setUpdated(date_create());
     $entityManager = $this->getEntityManager();
     $entityManager->persist($entity);
     $entityManager->flush();
     return $entity;
 }
 /**
  * @return int
  */
 public function delete(User $user, Post $post)
 {
     $conn = $this->_em->getConnection();
     $statement = $conn->prepare('DELETE FROM post_vote WHERE user_id = :user_id AND post_id = :post_id');
     $statement->bindValue('user_id', $user->getId());
     $statement->bindValue('post_id', $post->getId());
     return $statement->execute();
 }
 /**
  * @Route("/create-blog", name="create-blog")
  */
 public function createBlogAction(Request $request)
 {
     $post = new Post();
     $post->setDescription('Nuevo post');
     $em = $this->getDoctrine()->getManager();
     $em->persist($post);
     $em->flush();
     return new Response('Created post id ' . $post->getId());
 }
Exemple #13
0
 private function canEdit(Post $post, User $user)
 {
     // this assumes that the data object has a getOwner() method
     // to get the entity of the user who owns this data object
     //if ($post->getAuthor()->getIsAdmin() and !$user->getIsAdmin()) {
     //    return false;
     //}
     return $user === $post->getAuthor() or $user->getIsAdmin();
 }
 /**
  * Creates a new Post entity.
  *
  * @Route("/", name="post_create")
  * @Method("POST")
  */
 public function createAction(Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $post = new Post();
     $post->setContent($request->getContent());
     $em->persist($post);
     $em->flush();
     return new JsonResponse();
 }
 public function load(ObjectManager $manager)
 {
     $repo = new Post();
     $repo->setTitle('Post title 1');
     $manager->persist($repo);
     $repo = new Post();
     $repo->setTitle('Post title 2');
     $manager->persist($repo);
     $manager->flush();
 }
 /**
  * @param Post $post
  * @param User $user
  *
  * @return bool
  */
 private function isEditGranted(Post $post, User $user)
 {
     switch ($post->getState()) {
         case Post::STATUS_DRAFT:
             return $post->isAuthor($user);
         case Post::STATUS_REVIEW:
             return $user->isAdmin();
     }
     return false;
 }
 /**
  * @Route("/new")
  * @Method({"GET"})
  */
 public function newAction()
 {
     $post = new Post();
     $categories = $this->getDoctrine()->getRepository('AppBundle:Category')->findAll();
     foreach ($categories as $category) {
         $post->addCategory($category);
     }
     $form = $this->createForm(new PostType(), $post);
     return $this->render('Admin/new.html.twig', ['form' => $form->createView()]);
 }
 /**
  * @return array
  */
 public function generateNewPdf()
 {
     $pdfName = $this->generateUniquePdfName();
     $this->post->setPdfName($pdfName);
     $postSerialized = $this->serializer->serialize($this->post, 'json');
     $this->container->get('old_sound_rabbit_mq.generate_pdf_producer')->setContentType('application/json');
     $this->container->get('old_sound_rabbit_mq.generate_pdf_producer')->publish($postSerialized);
     $response = array('pdfName' => $pdfName);
     return $response;
 }
Exemple #19
0
 public function load(ObjectManager $manager)
 {
     foreach ($this->getData() as $payload) {
         $post = new Entity\Post();
         $post->setTitle($payload[0]);
         $post->setContent($payload[1]);
         $post->setCreated($payload[2]);
         $manager->persist($post);
     }
     $manager->flush();
 }
 public function testSetUser()
 {
     // new entity
     $post = new Post();
     // dummy entity
     $user = new User();
     $user->setFirstName("Ole");
     // Use the setUser method
     $post->setUser($user);
     // Assert the result
     $this->assertEquals($user, $post->getUser());
 }
 /**
  * Send email to author and all people from comments when vote is Approved or Rejected
  *
  * @param Post   $post
  * @param string $translation
  * @param string $template
  */
 private function sendPostVoteClosedEmail(Post $post, $translation, $template)
 {
     $recipients[] = $post->getAuthor()->getEmail();
     /** @var Comment $comment */
     $comments = $post->getComments();
     foreach ($comments as $comment) {
         $recipients[] = $comment->getUser()->getEmail();
     }
     $subject = $this->translator->trans($translation);
     $body = $this->renderView($template, array('post' => $post));
     $this->mailer->send($recipients, $subject, $body);
 }
 function load(ObjectManager $manager)
 {
     $i = 1;
     while ($i < +100) {
         $post = new Post();
         $post->setTitle('Titre du post n°' . $i);
         $post->setBody('Corps du post');
         $post->setIsPublished($i % 2);
         $manager->persist($post);
         $i++;
     }
     $manager->flush();
 }
 public function load(ObjectManager $manager)
 {
     $faker = new Faker\Generator();
     $faker->addProvider(new Faker\Provider\en_US\Text($faker));
     $faker->addProvider(new Faker\Provider\Lorem($faker));
     for ($i = 1; $i <= 100; $i++) {
         $post = new Post();
         $post->setTitle($faker->sentence(4));
         $post->setBody($faker->realText(500));
         $manager->persist($post);
     }
     $manager->flush();
 }
Exemple #24
0
 public function countCommentsWithRating(\Twig_Environment $twig, Post $post)
 {
     $comments = $post->getComments();
     $countCommentsWithRating = 0;
     if (count($comments) !== 0) {
         foreach ($comments as $comment) {
             if (0 !== $comment->getRating()) {
                 $countCommentsWithRating++;
             }
         }
     }
     return $countCommentsWithRating;
 }
Exemple #25
0
 /**
  * @Route("/create", name="post_create")
  */
 public function createAction(Request $request)
 {
     $post = new Post();
     $post->setAuthorId(1);
     $form = $this->createFormBuilder($post)->add('authorId', 'hidden')->add('content', 'text')->add('save', 'submit', array('label' => 'Create Post'))->getForm();
     $form->handleRequest($request);
     if ($form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $em->persist($post);
         $em->flush();
         return $this->redirectToRoute('post_id', ['id' => $post->getPostId()]);
     }
     return $this->render('post/create.html.twig', array('form' => $form->createView()));
 }
Exemple #26
0
 public function load(ObjectManager $manager)
 {
     $faker = Factory::create();
     for ($i = 0; $i < 50; $i++) {
         static $id = 1;
         $post = new Post();
         $post->setTitle($faker->sentence);
         $post->setAuthorEmail('*****@*****.**');
         $post->setImageName("images/post/foto{$id}.jpg");
         $post->setContent($faker->realText($maxNbChars = 5000, $indexSize = 2));
         $marks = array();
         for ($q = 0; $q < rand(1, 10); $q++) {
             $marks[] = rand(1, 5);
         }
         $post->setMarks($marks);
         $post->addMark(5);
         $manager->persist($post);
         $this->addReference("{$id}", $post);
         $id = $id + 1;
         $rand = rand(3, 7);
         for ($j = 0; $j < $rand; $j++) {
             $comment = new Comment();
             $comment->setAuthorEmail('*****@*****.**');
             $comment->setCreatedBy('user_user');
             $comment->setContent($faker->realText($maxNbChars = 500, $indexSize = 2));
             $comment->setPost($post);
             $post->getComments()->add($comment);
             $manager->persist($comment);
             $manager->flush();
         }
     }
     $manager->flush();
 }
Exemple #27
0
 /**
  * @dataProvider getValidTestData
  */
 public function testForm($data)
 {
     $type = new CreatePostType();
     $form = $this->factory->create($type);
     $object = new Post();
     $object->fromArray($data);
     // submit the data to the form directly
     $form->submit($data);
     $this->assertTrue($form->isSynchronized());
     $this->assertEquals($object, $form->getData());
     $view = $form->createView();
     $children = $view->children;
     foreach (array_keys($data) as $key) {
         $this->assertArrayHasKey($key, $children);
     }
 }
 public function load(ObjectManager $manager)
 {
     $array_palabras = array('Symfony', 'PHP', 'Famework', 'Desarrollo Agil', 'Aplicaciones');
     $array_autores = array('Ezequiel', 'Matias', 'Jorge', 'Juan');
     for ($i = 1; $i <= 100; $i++) {
         $post = new Post();
         $post->setTitulo($array_palabras[array_rand($array_palabras)] . ' ' . $array_palabras[array_rand($array_palabras)]);
         $post->setAutor($array_autores[array_rand($array_autores)]);
         $post->setImagen('symfony1.gif');
         $fecha = new \DateTime();
         $numeroDias = rand(1, 1000);
         $fecha->modify('-' . $numeroDias . ' day');
         $post->setFechaCreacion($fecha);
         $post->setCuerpo('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce vitae sapien eros. Nulla facilisi. Aliquam id sodales mauris. Fusce venenatis leo ut leo condimentum sollicitudin. Nam rhoncus turpis sit amet leo posuere, sed accumsan purus mattis. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Phasellus non hendrerit nulla. Nulla volutpat dignissim dui, sit amet posuere odio maximus in. Etiam ut leo commodo, laoreet lectus eu, ultrices diam. Vivamus id dictum leo. Praesent congue sem nec metus congue euismod. In rhoncus ex finibus iaculis consectetur. Interdum et malesuada fames ac ante ipsum primis in faucibus. Quisque eu nibh nec enim pretium pretium vitae nec ipsum. Vivamus mollis lacus ut neque ultrices, sed tincidunt nulla hendrerit.');
         $manager->persist($post);
         $this->addReference('post-' . $i, $post);
     }
     /*$post1 = new Post();
       $post1->setTitulo('Symfony es un framework PHP');
       $post1->setAutor('Ezequiel');
       $post1->setImagen('symfony1.gif');
       $post1->setFechaCreacion(new \DateTime());
       $post1->setCuerpo('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce vitae sapien eros. Nulla facilisi. Aliquam id sodales mauris. Fusce venenatis leo ut leo condimentum sollicitudin. Nam rhoncus turpis sit amet leo posuere, sed accumsan purus mattis. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Phasellus non hendrerit nulla. Nulla volutpat dignissim dui, sit amet posuere odio maximus in. Etiam ut leo commodo, laoreet lectus eu, ultrices diam. Vivamus id dictum leo. Praesent congue sem nec metus congue euismod. In rhoncus ex finibus iaculis consectetur. Interdum et malesuada fames ac ante ipsum primis in faucibus. Quisque eu nibh nec enim pretium pretium vitae nec ipsum. Vivamus mollis lacus ut neque ultrices, sed tincidunt nulla hendrerit.');
       $manager->persist($post1);
       */
     $manager->flush();
 }
 /**
  * {@inheritdoc}
  */
 public function share(Post $post)
 {
     if (!$post->getPublished()) {
         return null;
     }
     $contacts = $this->contactProvider->getContacts();
     $now = new \DateTime();
     $from = $this->from;
     $subject = $this->getSubject($now);
     foreach ($contacts as $contact) {
         if (!$contact instanceof ContactInterface) {
             throw new \InvalidArgumentException(sprintf("%s must implement %s.", get_class($contact), ContactInterface::class));
         }
         $template = $this->templating->render('@App/Admin/Post/newsletter.html.twig', array('post' => $post, 'contact' => $contact));
         $to = array($contact->getEmail());
         if ($this->emailSender->send($from, $to, $subject, $template)) {
             $post->setSharedNewsletter($now);
         }
     }
 }
 public function create(User $user, $title, $url, $tag)
 {
     if ($errors = $this->getErrors($title, $url, $tag)) {
         throw new ServiceException($errors);
     }
     $post = new Post();
     $post->setUser($user);
     $post->setTitle($title);
     $post->setUrl($url);
     $post->setTag($this->formatTag($tag));
     $post->setUpvoteTotal(0);
     $post->setCreatedAt(new \DateTime());
     return $this->repository->create($post);
 }