public function load(ObjectManager $manager) { // TODO: Implement load() method. $category = new Category(); $category->setName('Default'); $manager->persist($category); foreach (range(1, 100) as $i) { $post = new Post(); $post->setTitle($this->getPostTitle()); $post->setSlug($this->container->get('slugger')->slugify($post->getTitle())); $post->setImage('post.jpeg'); $post->setContent($this->getPostContent()); $post->setAuthor('gunyem'); $post->setCreated(new \DateTime('now - ' . $i . 'days')); $post->setUpdated(new \DateTime('now - ' . $i . 'days')); $post->setCategory($category); foreach (range(1, 10) as $j) { $comment = new Comment(); $comment->setPost($post); $comment->setContent($this->getPostTitle()); $comment->setAuthor('gunyem'); $comment->setCreated(new \DateTime('now + ' . ($i + $j) . 'seconds')); $manager->persist($comment); $post->createComment($comment); } $manager->persist($post); } $manager->flush(); }
private function loadPosts(ObjectManager $manager) { foreach (range(1, 30) as $i) { $post = new Post(); $post->setTitle('Sed ut perspiciatis unde'); $post->setAlias('Sed ut perspiciatis unde'); $post->setIntrotext('Sed ut perspicantium, tocto beatae vitae dicta sunt explicabo. '); $post->setSlug($this->container->get('slugger')->slugify($post->getTitle())); $post->setBody('Sed ut is iste uasi architecto beatae vitae dicta sunt explicabo. '); $post->setAuthorEmail('*****@*****.**'); $post->setPublishedAt(new \DateTime('now - ' . $i . 'days')); $post->setState(1); $post->setImages('test.jpg'); foreach (range(1, 5) as $j) { $comment = new Comment(); $comment->setAuthorEmail('*****@*****.**'); $comment->setPublishedAt(new \DateTime('now + ' . ($i + $j) . 'seconds')); $comment->setContent('Sed ut perspiciatis undedasdadasd'); $comment->setPost($post); $manager->persist($comment); $post->addComment($comment); } $manager->persist($post); } $manager->flush(); }
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(); }
private function loadPosts(ObjectManager $manager) { $category = new Category(); $category->setName('Improvements'); foreach (range(1, 5) as $i) { $post = new Post(); $post->setTitle($this->getRandomPostTitle()); $post->setSummary($this->getRandomPostSummary()); $post->setSlug($this->container->get('slugger')->slugify($post->getTitle())); $post->setContent($this->getPostContent()); $post->setAuthorEmail('*****@*****.**'); $post->setPublishedAt(new \DateTime('now - ' . $i . 'days')); $post->setState($this->getRandomState()); $post->setCategory($category); foreach (range(1, 5) as $j) { $comment = new Comment(); $comment->setAuthorEmail('*****@*****.**'); $comment->setPublishedAt(new \DateTime('now + ' . ($i + $j) . 'seconds')); $comment->setContent($this->getRandomCommentContent()); $comment->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(); }
private function loadPosts(ObjectManager $manager) { foreach (range(1, 10) as $i) { $post = new Post(); $post->setTitle($this->getRandomPostTitle()); $post->setSummary($this->getRandomPostSummary()); $post->setSlug($this->container->get('slugger')->slugify($post->getTitle())); $post->setContent($this->getPostContent()); $post->setAuthorEmail('*****@*****.**'); $post->setPublishedAt(new \DateTime('now - ' . $i . 'days')); foreach (range(1, 5) as $j) { $comment = new Comment(); $comment->setAuthorEmail('*****@*****.**'); $comment->setPublishedAt(new \DateTime('now + ' . ($i + $j) . 'seconds')); $comment->setContent($this->getRandomCommentContent()); $comment->setPost($post); $manager->persist($comment); $post->addComment($comment); } $manager->persist($post); } $manager->flush(); }
public function publishOnPage(Post $post, $message = null) { $response = new FacebookPostAsPageResponse(); $accessToken = $this->getUserLongAccessToken(); if (!$post->getPublished()) { return $response->setException(new \Exception('flash_batch_facebook_post_not_published')); } if ($accessToken->tokenIsEmpty()) { return $response->setException(new \Exception('flash_batch_facebook_access_token_empty')); } $this->application->setDefaultAccessToken($accessToken->getAccessToken()); try { $getPageAccessToken = $this->application->sendRequest('GET', '/' . $this->pageId, array('fields' => 'access_token'))->getDecodedBody(); $params = array('message' => null !== $message ? $message : '', 'name' => $post->getTitle(), 'caption' => $post->getDescription(), 'link' => $this->router->generate('front_article_view', array('slug' => $post->getSlug()), true)); if (count($post->getImages()) > 0) { $hompage = $this->router->generate('homepage', array(), true); $imgWebPath = $this->assetsHelper->getUrl($post->getPreviewImage()->getWebPath()); $params['picture'] = $hompage . $imgWebPath; } $endPoint = null === $post->getFbId() ? $this->pageId . '/feed' : $post->getFbId(); $postAsPage = $this->application->post('/' . $endPoint, $params, $getPageAccessToken['access_token'])->getDecodedBody(); $response->setId(isset($postAsPage['id']) ? $postAsPage['id'] : $post->getFbId()); } catch (\Exception $e) { return $response->setException($e); } return $response; }
/** * {@inheritDoc} */ public function getTitle() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'getTitle', array()); return parent::getTitle(); }
/** * Slugify the post's title. * * @param Post $post */ private function setSlug(Post $post) { $title = $post->getTitle(); $slugify = $this->getConfigurationPool()->getContainer()->get('slugify'); $post->setSlug($slugify->slugify($title)); }