コード例 #1
0
ファイル: DatabaseTest.php プロジェクト: cobase/cobase
 /**
  * @test
  *
  * @group cur
  */
 public function assertSqliteDbIsUsed()
 {
     $post = new Post();
     $post->setContent('TestContent');
     $this->getEntityManager()->persist($post);
     $this->getEntityManager()->flush();
 }
コード例 #2
0
ファイル: LikeRepository.php プロジェクト: cobase/cobase
 /**
  * @param Post $post
  * @param User $user
  *
  * @return Like
  */
 public function getPostSpecificLikeByUser(Post $post, User $user)
 {
     $qb = $this->getEntityManager()->createQueryBuilder();
     $qb->select('l')->from('Cobase\\AppBundle\\Entity\\Like', 'l')->where('l.resourceId = :id')->setParameter('id', $post->getId())->andWhere('l.resourceType = :type')->setParameter('type', 'post')->andWhere('l.user = :user')->setParameter('user', $user);
     try {
         return $qb->getQuery()->getSingleResult();
     } catch (NoResultException $e) {
         return null;
     }
 }
コード例 #3
0
ファイル: PostFixtures.php プロジェクト: cobase/cobase
 public function load(\Doctrine\Common\Persistence\ObjectManager $manager)
 {
     $post1 = new Post();
     $post1->setUser($manager->merge($this->getReference('user-1')));
     $post1->setContent('NSA chief: We thwarted more than 50 terror attacks: http://rt.com/usa/attacks-50-nsa-alexander-891');
     $post1->setGroup($manager->merge($this->getReference('group-1')));
     $manager->persist($post1);
     $post2 = new Post();
     $post2->setUser($manager->merge($this->getReference('user-2')));
     $post2->setContent('Wimbledon 2013: The state of grassroots & elite tennis in Britain: http://www.bbc.co.uk/sport/0/tennis/22912754');
     $post2->setGroup($manager->merge($this->getReference('group-2')));
     $manager->persist($post2);
     $post3 = new Post();
     $post3->setUser($manager->merge($this->getReference('user-3')));
     $post3->setContent('Justin Rose: A wonderful golfer who tamed the Merion beast. Read about at http://www.bbc.co.uk/sport/0/golf/22941311');
     $post3->setGroup($manager->merge($this->getReference('group-2')));
     $manager->persist($post3);
     $manager->flush();
 }
コード例 #4
0
ファイル: PostController.php プロジェクト: cobase/cobase
 /**
  * To create a new post from the bookmarklet
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function newAction()
 {
     $postService = $this->getPostService();
     $post = new Post();
     /**
      * if there is an url variable in the request someone is using the bookmarklet
      */
     $request = $this->getRequest();
     if ($request->query->has('url')) {
         $url = $request->query->get('url');
         $content = false;
         if ($request->query->has('content')) {
             $content = $request->query->get('content');
         }
         $metadata = $postService->fetchMetadataFromUrl($url);
         $post->setBookmarkletContent($content, $metadata, $url);
     }
     $form = $this->createForm(new NewPostType(), $post);
     $postService = $this->getPostService();
     if ($request->getMethod() == 'POST') {
         if ($this->processForm($form)) {
             // Convert line breaks to BR tag
             $content = $post->getContent();
             $content = str_replace("\n", '<br/>', $content);
             $post->setContent($content);
             // Save the posti modifications
             $postService->savePost($post);
             $this->get('session')->getFlashBag()->add('post.message', 'Your post has been saved.');
             return $this->redirect($this->generateUrl('CobaseAppBundle_group_view', array('groupId' => $post->getGroup()->getShortUrl(), 'closeFancyBox' => true)));
         }
     }
     return $this->render('CobaseAppBundle:Post:new.html.twig', $this->mergeVariables(array('post' => $post, 'form' => $form->createView())));
 }
コード例 #5
0
ファイル: PostEvent.php プロジェクト: cobase/cobase
 /**
  * @return Group
  */
 public function getGroup()
 {
     return $this->post->getGroup();
 }
コード例 #6
0
ファイル: PostRepository.php プロジェクト: cobase/cobase
 /**
  * @param Post $post
  * @return array
  */
 public function getLikes(Post $post)
 {
     $qb = $this->getEntityManager()->createQueryBuilder();
     $qb->select('l')->from('Cobase\\AppBundle\\Entity\\Like', 'l')->leftJoin('l.user', 'u')->where('l.resourceId = :id')->setParameter('id', $post->getId())->andWhere('l.resourceType = :type')->setParameter('type', 'post')->orderBy('u.name');
     return $qb->getQuery()->getResult();
 }
コード例 #7
0
ファイル: PostService.php プロジェクト: cobase/cobase
 /**
  * Save a post
  *
  * @param  Post $post
  * @param  Group $group
  * @param  User  $user
  * @return Group
  */
 public function savePost(Post $post)
 {
     if (!$post->getUser()) {
         $post->setUser($this->security->getToken()->getUser());
     }
     $this->em->persist($post);
     $this->em->flush();
     return $post;
 }
コード例 #8
0
ファイル: PostTest.php プロジェクト: cobase/cobase
 /**
  * @test
  *
  * @group entity
  * @group post-entity
  */
 public function assertFeedTitleIsShortenedProperlyWhenLastCharIsSpace()
 {
     $user = new User();
     $user->setName("John");
     $post = new Post();
     $post->setUser($user);
     $post->setMaxFeedTitleLength(21);
     $post->setContent('The hyperactive horse walked into a saloon');
     $expectedTitle = 'The hyperactive horse... (John)';
     $this->assertEquals($expectedTitle, $post->getFeedItemTitle());
 }