コード例 #1
3
 /**
  * Return a similar articles by category
  * @param Article $article
  * @return Article array
  */
 public function getSimilarArticlesByCategory(Article $article)
 {
     $category = $article->getCategory();
     $similarArticles = $this->articleRepository->findBy(array('category' => $category), array('date' => 'ASC'), 3);
     unset($similarArticles[array_search($article, $similarArticles)]);
     return $similarArticles;
 }
コード例 #2
0
ファイル: LoadArticleData.php プロジェクト: kusiu/Rest-API
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $article1 = new Article();
     $article1->setTitle('Article 1');
     $article1->setContent('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.');
     $answer1 = new Answer();
     $answer1->setContent('To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it?');
     $answer1->setArticle($article1);
     $answer2 = new Answer();
     $answer2->setContent('At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga.');
     $answer2->setArticle($article1);
     $rate1 = new Rate();
     $rate1->setValue(1);
     $rate1->setArticle($article1);
     $rate2 = new Rate();
     $rate2->setValue(5);
     $rate2->setArticle($article1);
     $article2 = new Article();
     $article2->setTitle('Article 2');
     $article2->setContent('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.');
     $manager->persist($article1);
     $manager->persist($answer1);
     $manager->persist($answer2);
     $manager->persist($rate1);
     $manager->persist($rate2);
     $manager->persist($article2);
     $manager->flush();
 }
コード例 #3
0
 private function canEdit(Article $article, User $user)
 {
     if ($user === $article->getUser()) {
         return true;
     }
     return false;
 }
コード例 #4
0
 /**
  * @param $id
  * @param $action
  * @param Request $request
  * @Route("/article/{action}/{id}", name="articleEdit",
  *     defaults={"id": 0},
  *     requirements={
  *      "action": "new|edit",
  *      "id": "\d+"
  *     })
  * @Method({"GET", "POST"})
  * @Template("AppBundle:admin/form:article.html.twig")
  *
  * @return Response
  */
 public function editArticleAction($id, $action, Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     if ($action == "edit") {
         $article = $em->getRepository('AppBundle:Article')->find($id);
         $title = 'Edit article id: ' . $id;
         $this->denyAccessUnlessGranted('edit', $article);
     } else {
         $article = new Article();
         $user = $this->get('security.token_storage')->getToken()->getUser();
         $article->setUser($user);
         $title = 'Create new article';
         $this->denyAccessUnlessGranted('create', $article);
     }
     $form = $this->createForm(ArticleType::class, $article, ['em' => $em, 'action' => $this->generateUrl('articleEdit', ['action' => $action, 'id' => $id]), 'method' => Request::METHOD_POST])->add('save', SubmitType::class, array('label' => 'Save'));
     if ($request->getMethod() == 'POST') {
         $form->handleRequest($request);
         if ($form->isValid()) {
             $em->persist($article);
             $em->flush();
             return $this->redirectToRoute('articlesAdmin');
         }
     }
     return ['title' => $title, 'form' => $form->createView()];
 }
コード例 #5
0
ファイル: ArticleAdmin.php プロジェクト: sghribi/garopi
 /**
  * @param Article $object
  */
 public function preUpdate($object)
 {
     /** @var ArticleMedia $media */
     foreach ($object->getMedias() as $media) {
         $media->setArticle($object);
     }
 }
コード例 #6
0
 /**
  * @covers AppBundle\Entity\Article::__construct
  * @covers AppBundle\Entity\Article::__toArray
  */
 public function test__construct()
 {
     $testData = ['title' => 'sample title', 'description' => 'sample description'];
     $article = new Article($testData['title'], $testData['description']);
     $articleArray = $article->__toArray();
     $this->assertEquals($testData['title'], $articleArray['title']);
     $this->assertEquals($testData['description'], $articleArray['description']);
 }
コード例 #7
0
 public function load(ObjectManager $manager)
 {
     $article = new Article();
     $article->setTitle('My first article');
     $article->setContent('This is my super article');
     $manager->persist($article);
     $manager->flush();
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $title = $input->getArgument('title');
     $content = $input->getArgument('content');
     $article = new Article();
     $article->setTitle($title)->setContent($content);
     $this->getContainer()->get('app.service.fluent_output_service')->save($article);
 }
コード例 #9
0
ファイル: ArticleManager.php プロジェクト: ShytN1k/blog
 public function createNewArticle(Article $article, Author $author)
 {
     $em = $this->doctrine->getManager();
     if ($author !== null) {
         $article->setAuthor($author);
     }
     $em->persist($article);
     $em->flush();
 }
コード例 #10
0
 private function canDelete(Article $article, User $user, $token)
 {
     if ($this->decisionManager->decide($token, array('ROLE_ADMIN'))) {
         return true;
     }
     if ($this->decisionManager->decide($token, array('ROLE_MODERATOR'))) {
         return $article->isAuthor($user);
     }
     return false;
 }
コード例 #11
0
ファイル: ArticleTest.php プロジェクト: jpass/articles_test
 public function testIfSluggableExtensionIsWorking()
 {
     $article = new Article();
     $article->setTitle('Article title');
     $article->setBody('Article body');
     $em = $this->container->get('doctrine')->getManager();
     $em->persist($article);
     $em->flush();
     $this->assertEquals('article-title', $article->getSlug());
 }
コード例 #12
0
ファイル: LoadData.php プロジェクト: pferre/playapi
 /**
  * Load data fixtures with the passed EntityManager
  *
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $faker = Factory::create();
     for ($i = 1; $i <= 10; $i++) {
         $article = new Article();
         $article->setTitle($faker->sentence());
         $article->setBody($faker->paragraph(2));
         $manager->persist($article);
         $manager->flush();
     }
 }
コード例 #13
0
ファイル: FileManager.php プロジェクト: KateSyrotchuk/blog
 public function fileManager(Article $article)
 {
     if ($article->getImage() !== null) {
         $file = $article->getImage();
         $fileName = md5(uniqid()) . '.' . $file->guessExtension();
         $brochuresDir = $this->rootDir . '/../web/images';
         $file->move($brochuresDir, $fileName);
         $article->setPathToImage("images/" . $fileName);
     }
     return $article;
 }
コード例 #14
0
ファイル: ArticleController.php プロジェクト: kusiu/Rest-API
 /**
  * Create an Article from the submitted data.
  *
  * @ApiDoc(
  *   resource = true,
  *   description = "Creates an article from the submitted data.",
  *   statusCodes = {
  *     200 = "Returned when successful",
  *     400 = "Returned when the form has errors"
  *   }
  * )
  *
  * @param ParamFetcher $paramFetcher Paramfetcher
  *
  * @RequestParam(name="title", nullable=false, strict=true, description="Title.")
  * @RequestParam(name="content", nullable=false, strict=true, description="Article Content.")
  *
  * @return View
  */
 public function postArticleAction(ParamFetcher $paramFetcher)
 {
     $em = $this->getDoctrine()->getManager();
     $article = new Article();
     $article->setTitle($paramFetcher->get('title'));
     $article->setContent($paramFetcher->get('content'));
     $em->persist($article);
     $em->flush();
     $view = View::create();
     $view->setData($article)->setStatusCode(200);
     return $view;
 }
コード例 #15
0
 /**
  * @Route("/")
  * @Method("POST")
  * @Template()
  */
 public function createAction()
 {
     $request = Request::createFromGlobals();
     $title = $request->request->get('article')['title'];
     $content = $request->request->get('article')['content'];
     $article = new Article();
     $article->setTitle($title);
     $article->setContent($content);
     $em = $this->getDoctrine()->getManager();
     $em->persist($article);
     $em->flush();
     return new Response('Created article id ' . $article->getId() . '<br />' . 'name is ' . $article->getTitle());
 }
コード例 #16
0
 /**
  * Creates a new article
  * @param  array  $params holds the parameters to be inserted (int author_id, text $article)
  * @return boolean
  */
 public function createArticle($params = array())
 {
     if (!is_array($params) || count($params) < 1) {
         return false;
     }
     $em = $this->getEntityManager();
     $article = new Article();
     $article->setArticleText($params['article']);
     $article->setAuthorId($params['author_id']);
     $article->setCreatedOn(new \DateTime());
     $em->persist($article);
     $em->flush();
     return true;
 }
コード例 #17
0
 /**
  * @Route("/article/new", name="article-create")
  */
 public function newAction(Request $request)
 {
     $articleRepository = $this->get('app.repository.articlerep');
     $article = new Article();
     $article->setTitle('Default article title');
     $builder = $articleRepository->createFormBuilder($article);
     $form = $builder->getForm();
     $form->handleRequest($request);
     if ($form->isValid()) {
         $article = $articleRepository->createArticle($form->getData());
         return $this->redirectToRoute('article-edit', array('id' => $article->getId()), 301);
     }
     return $this->render('AdminBundle:admin:article/edit.html.twig', array('form' => $form->createView(), 'article' => $article));
 }
コード例 #18
0
 /**
  * Creates a new Article entity.
  *
  * @Route("/", name="articles_create")
  * @Method("POST")
  * @Template("Article/new.html.twig")
  *
  * @param Request $request
  *
  * @return array|\Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function createAction(Request $request)
 {
     $article = new Article();
     $article->setUser($this->getUser());
     $form = $this->createCreateForm($article);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $em->persist($article);
         $em->flush();
         return $this->redirect($this->generateUrl('homepage'));
     }
     return ['article' => $article, 'new_form' => $form->createView()];
 }
コード例 #19
0
 /**
  *
  */
 public function putArticleAction(Article $article, Request $request)
 {
     // yes we replace totally the old article by a new one
     // except the id, because that's how PUT works
     // if you just want to "merge" you want to use PATCH, not PUT
     $id = $article->getId();
     $article = new Article();
     $article->setId($id);
     $errors = $this->treatAndValidateRequest($article, $request);
     if (count($errors) > 0) {
         return new View($errors, Response::HTTP_UNPROCESSABLE_ENTITY);
     }
     $this->persistAndFlush($article);
     return "";
 }
コード例 #20
0
 public function load(ObjectManager $manager)
 {
     $articleDev = new Article();
     $articleDev->setTitle("Title for demo Web Dev article");
     $articleDev->setSummary("This is a summary Dev");
     $articleDev->setContent("This is some dummy data for the web development article content.");
     $articleDev->setMainImage("http://i.imgur.com/oPcT6TC.jpg");
     $articleDev->setSlug("demo-article-dev");
     $articleDev->setCategory("development");
     $articleDev->setDatePosted(new \DateTime("2016-01-01 01:01:01"));
     $articleDev->setTitleColour("black-title");
     $manager->persist($articleDev);
     $articleManager = new Article();
     $articleManager->setTitle("Title for Project Management Web article");
     $articleManager->setSummary("This is a summary Management");
     $articleManager->setContent("This is some dummy data for the project management article content.");
     $articleManager->setMainImage("http://i.imgur.com/3O2kOG4.jpg");
     $articleManager->setSlug("demo-article-manager");
     $articleManager->setCategory("management");
     $articleManager->setDatePosted(new \DateTime("2016-02-02 02:02:02"));
     $articleManager->setTitleColour("white-title");
     $manager->persist($articleManager);
     $articleMarketing = new Article();
     $articleMarketing->setTitle("Title for demo Marketing article");
     $articleMarketing->setSummary("This is a summary Marketing");
     $articleMarketing->setContent('
                 <p>Never in all their history have men been able truly to conceive of the world as one: a single sphere, a globe, having the qualities of a globe, a round earth in which all the directions eventually meet, in which there is no center because every point, or none, is center — an equal earth which all men occupy as equals. The airman\'s earth, if free men make it, will be truly round: a globe in practice, not in theory.</p>
                 <p>Science cuts two ways, of course; its products can be used for both good and evil. But there\'s no turning back from science. The early warnings about technological dangers also come from science.</p>
                 <h2 class="section-heading">The Final Frontier</h2>
                 <p>Spaceflights cannot be stopped. This is not the work of any one man or even a group of men. It is a historical process which mankind is carrying out in accordance with the natural laws of human development.</p>
                 <a href="#">
                     <img class="img-responsive" src="http://blackrockdigital.github.io/startbootstrap-clean-blog/img/post-sample-image.jpg" alt="">
                 </a>
                 <span class="caption text-muted">To go places and do things that have never been done before – that’s what living is all about.</span>
                 <p>Space, the final frontier. These are the voyages of the Starship Enterprise. Its five-year mission: to explore strange new worlds, to seek out new life and new civilizations, to boldly go where no man has gone before.</p>
                 <p>As I stand out here in the wonders of the unknown at Hadley, I sort of realize there’s a fundamental truth to our nature, Man must explore, and this is exploration at its greatest.</p>
                 <p>Placeholder text by <a href="http://spaceipsum.com/">Space Ipsum</a>. Photographs by <a href="https://www.flickr.com/photos/nasacommons/">NASA on The Commons</a>.</p>
                 ');
     $articleMarketing->setMainImage("http://i.imgur.com/fOg16kD.jpg");
     $articleMarketing->setSlug("demo-article-marketing");
     $articleMarketing->setCategory("online-marketing");
     $articleMarketing->setDatePosted(new \DateTime("2016-03-03 03:03:03"));
     $articleMarketing->setTitleColour("black-title");
     $manager->persist($articleMarketing);
     $manager->flush();
 }
コード例 #21
0
 /**
  * @Security("has_role('ROLE_USER')")
  *
  * @Route("/create/article")
  */
 public function articleCreateAction(Request $request)
 {
     if (!$this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
         throw $this->createAccessDeniedException();
     }
     $user = $this->getUser();
     $article = new Article();
     $article->setAuthor($user);
     $form = $this->createForm(new ArticleType(), $article);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $entityManager = $this->getDoctrine()->getManager();
         $entityManager->persist($article);
         $entityManager->flush();
         return $this->redirectToRoute('categoriesList');
     }
     return $this->render('default/formArticle.html.twig', array('form' => $form->createView()));
 }
コード例 #22
0
 /**
  * @Route("/", name="homepage")
  */
 public function indexAction(Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $articles = $em->getRepository('AppBundle:Article')->findAll();
     $article = new Article();
     $user = new User();
     $authors = array();
     foreach ($articles as $article) {
         if ($article->getArticleOwner() == 0) {
             $authors[0] = "admin";
         } else {
             $user = $em->getRepository("AppBundle:User")->find($article->getArticleOwner());
             $authors[$user->getID()] = $user->getUsername();
         }
     }
     $form = $this->createFormBuilder()->add('commentContent', TextareaType::class)->getForm();
     return $this->render('default/index.html.twig', array('pageTitle' => 'Main Page', 'articles' => $articles, 'authors' => $authors, 'commentForm' => $form->createView()));
 }
コード例 #23
0
 public function submitAction(Request $request)
 {
     $article = new Article();
     $articleExtend = new ArticleExtend();
     $article->setArticleExtend($articleExtend);
     $form = $this->createForm(ArticleType::class, $article);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $article->setDate(new \DateTime());
         $articleExtend->setArticle($article);
         $em->persist($article);
         $em->persist($articleExtend);
         $em->flush();
         return $this->redirect($this->generateUrl('backoffice_article'));
     }
     return ['entity' => $article, 'form' => $form->createView()];
 }
コード例 #24
0
 /**
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     for ($i = 0; $i < 3; $i++) {
         $article = new Article();
         $article->setTitle('Article de test ' . $i);
         $article->setSlug($article->getTitle());
         $article->setContent($this->articleContent[$i]);
         $article->setExtract($this->articleExtract[$i]);
         $article->setCategory($this->getReference('category'));
         $article->setAuthor($this->getReference('user'));
         $article->setPictureName('default-image-' . $i . '.jpg');
         $manager->persist($article);
         // Reference added once
         if ($i == 0) {
             $this->addReference('article', $article);
         }
     }
     $manager->flush();
 }
コード例 #25
0
 /**
  * Perform a single access check operation on a given attribute, object and (optionally) user
  * It is safe to assume that $attribute and $object's class pass supportsAttribute/supportsClass
  * $user can be one of the following:
  *   a UserInterface object (fully authenticated user)
  *   a string               (anonymously authenticated user)
  *
  * @param string $attribute
  * @param Article $object
  * @param UserInterface|string $user
  *
  * @return bool
  */
 protected function isGranted($attribute, $object, $user = null)
 {
     switch ($attribute) {
         case 'UPLOAD_NEW_ARTICLE_REVIEW':
             // TODO: check deadtime
             if (Article::STATUS_ACCEPTED_SUGGESTIONS == $object->getStateEnd()) {
                 return true;
             }
             if (Article::STATUS_ACCEPTED_SUGGESTIONS == $object->getArticleReviews()->last()->getState()) {
                 return true;
             }
             break;
         case 'OWNER':
             if ($user instanceof UserInterface && $user->getUsername() === $object->getUser()->getUsername()) {
                 return true;
             }
             break;
     }
     return false;
 }
コード例 #26
0
 public function create(Request $request)
 {
     $fields = $this->getHydrationMap($request);
     $entity = new Article();
     if (!isset($fields['creation_date'])) {
         $entity->setCreationDate(new \DateTime());
     }
     //        $entity = $this->beforeHydration($entity, $fields);
     $entity = $this->hydrate($entity, $fields);
     if ($idArticleCategory = $request->request->get('id_article_category')) {
         $categoryEntity = $this->categoryRepository->find($idArticleCategory);
         $entity->setCategory($categoryEntity);
     }
     if ($idAuthor = $request->request->get('id_author')) {
         $userEntity = $this->userRepository->find($idAuthor);
         $entity->setAuthor($userEntity);
     }
     $this->entityRepository->save($entity);
     return $entity;
 }
コード例 #27
0
 /**
  * Perform a single access check operation on a given attribute, object and (optionally) user
  * It is safe to assume that $attribute and $object's class pass supportsAttribute/supportsClass
  * $user can be one of the following:
  *   a UserInterface object (fully authenticated user)
  *   a string               (anonymously authenticated user)
  *
  * @param string $attribute
  * @param Article $object
  * @param UserInterface|string $user
  *
  * @return bool
  */
 protected function isGranted($attribute, $object, $user = null)
 {
     if ($object->getStateEnd() != Article::STATUS_SENT) {
         return false;
     }
     /** @var Reviewer $reviewer */
     foreach ($object->getReviewers() as $reviewer) {
         if ($reviewer->getUser() == $user) {
             $reviews = $object->getArticleReviews()->last()->getReviewComments();
             /** @var ReviewComments $review */
             foreach ($reviews as $review) {
                 if ($review->getReviewer()->getUser() == $user) {
                     return false;
                 }
             }
             return true;
         }
     }
     return false;
 }
コード例 #28
0
ファイル: ArticleController.php プロジェクト: sghribi/garopi
 /**
  * @Route("/articles/{slug}")
  * @Template("AppBundle:Article:show.html.twig")
  * @ParamConverter("article", options={"mapping": {"slug": "slug"}, "entity_manager" = "default"})
  */
 public function showAction(Article $article, Request $request)
 {
     // @TODO: move this in service/event
     $em = $this->getDoctrine()->getManager();
     $em->persist(new Reading($this->getUser(), $article));
     $em->flush();
     // Comment to highlight
     $highlight = null;
     $comment = new Comment();
     $form = $this->createForm(new CommentType(), $comment);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $article->addComment($comment);
         $comment->setAuthor($this->getUser());
         $em->persist($comment);
         $em->flush();
         // Remove field after persist
         $form = $this->createForm(new CommentType(), new Comment());
         $highlight = $comment;
     }
     return array('article' => $article, 'form' => $form->createView(), 'highlight' => $highlight);
 }
コード例 #29
0
 /**
  * @Route("/importexcel", name="excel_import")
  */
 public function importExcelAction()
 {
     $filename = $this->get('kernel')->getRootDir() . '/../web/excel/test.xls';
     $lignes = $this->get('excel_service')->excel_to_array($filename);
     $em = $this->getDoctrine()->getManager();
     foreach ($lignes as $col) {
         $article = $em->getRepository('AppBundle:Article')->find($col['id']);
         if (!$article) {
             $article = new Article();
             $article->setTitle($col['title']);
             $article->setContent($col['content']);
             $article->setUrl($col['url']);
             $em->persist($article);
         } else {
             $article->setTitle($col['title']);
             $article->setContent($col['content']);
             $article->setUrl($col['url']);
         }
         $em->flush();
     }
     die;
 }
コード例 #30
0
 /**
  * @Route("/importcsv", name="csv_import")
  */
 public function importCSVAction()
 {
     $filename = $this->get('kernel')->getRootDir() . '/../web/csv/test.csv';
     $header = array('id', 'title', 'content', 'url');
     $lignes = $this->get('csv_service')->csv_to_array($filename, ',', $header);
     $em = $this->getDoctrine()->getManager();
     foreach ($lignes as $col) {
         $article = $em->getRepository('AppBundle:Article')->find($col['id']);
         if (!$article) {
             $article = new Article();
             $article->setTitle($col['title']);
             $article->setContent($col['content']);
             $article->setUrl($col['url']);
             $em->persist($article);
         } else {
             $article->setTitle($col['title']);
             $article->setContent($col['content']);
             $article->setUrl($col['url']);
         }
         $em->flush();
     }
     die;
 }