Example #1
0
 /**
  * {@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();
 }
 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();
 }
Example #3
0
 /**
  * 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;
 }
 /**
  * @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());
 }
Example #5
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();
 }
Example #6
0
 /**
  * @Route("/article/json/add", name="article-add-post")
  * @param Request $request
  * @return string|\Symfony\Component\HttpFoundation\Response
  * @Method("POST")
  */
 public function articleAddNewAction(Request $request)
 {
     //create new article
     $article = new Article();
     // get heading and content from $_POST
     $article->setHeading($request->request->get('heading'));
     $article->setContent($request->request->get('content'));
     $article->setTags($request->request->get('tags'));
     if ($request->request->get('privacy') == 'internal') {
         $article->setPrivate(true);
     } else {
         $article->setPrivate(false);
     }
     $article->setUserId($this->getUser());
     $categoryId = (int) $request->request->get('category');
     $this->get('article_manager')->save($article, $categoryId);
     return new Response('Created article ' . $article->getHeading());
 }
 /**
  * @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();
 }
 public function load(ObjectManager $manager)
 {
     for ($i = 0; $i < 40; $i++) {
         $article = new Article();
         $article->setTitle('News' . $i);
         $article->setContent('This is default content');
         $article->setDatetime(new \DateTime('- ' . rand(1, 4) . ' day'));
         $commentA = new Comment();
         $commentA->setAuthor('Author');
         $commentA->setContent('Comment .... default');
         $manager->persist($commentA);
         $article->addComment($commentA);
         $commentB = new Comment();
         $commentB->setAuthor('Author' . $i);
         $commentB->setContent('Comment .... default');
         $manager->persist($commentB);
         $article->addComment($commentB);
         $manager->persist($article);
     }
     $manager->flush();
 }
 /**
  * @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;
 }
 /**
  * @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;
 }
Example #11
0
 public function load(ObjectManager $manager)
 {
     $faker = Factory::create();
     for ($i = 1; $i <= 24; $i++) {
         $article = new Article();
         // $article->setSlug('article' . $i);
         $article->setSummary($faker->sentences(10, true));
         $article->setContent($faker->text(3000));
         $article->setTitle($faker->sentence());
         $slug = $this->container->get('app.slugger')->slugify($article->getTitle());
         $article->setSlug($slug);
         $article->setAuthorEmail('*****@*****.**');
         $article->setPathToImage('images/foto_' . $i . '.jpg');
         for ($j = 1; $j <= 5; $j++) {
             $comment = new Comment();
             $comment->setContent($faker->sentences(5, true));
             //$comment->setPublishedAt(new \DateTime('now'));
             $comment->setArticle($article);
             $comment->setAuthorEmail('*****@*****.**');
             $article->addComment($comment);
             $manager->persist($comment);
         }
         $manager->persist($article);
         $arrayId = array();
         $k = rand(1, 10);
         while (count($arrayId) < $k) {
             $id = rand(1, 50);
             if (array_search($id, $arrayId) === false) {
                 $arrayId[] = $id;
                 $tagFromBase = $this->getReference("tag {$id}");
                 $article->addTag($tagFromBase);
                 $tagFromBase->getArticles()->add($article);
             }
         }
     }
     $manager->flush();
 }
 /**
  * {@inheritDoc}
  */
 public function setContent($content)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setContent', array($content));
     return parent::setContent($content);
 }
Example #13
0
 public function load(ObjectManager $manager)
 {
     $article1 = new Article();
     $article1->setPublishedAt(\DateTime::createFromFormat('Y-m-d H:i:s', '2013-09-24 13:53:00'));
     $article1->setTitle('Export datas to a csv file with Symfony2');
     $article1->setCategory($this->getReference('category_3'));
     $article1->setContent('I recently had to export a huge set of data to a csv file. This is easy and fast to do if you don’t care about memory and User Experience. I wanted the memory consumption does not increase with the volume of data.
         I got inspiration from this post (in French) but, in spite of what is written in the post, some tests with the memory_get_usage function proved that the memory consumption increased quickly with the number of datas.
     ');
     $article1->setTags(array('CSV', 'Symfony2'));
     $manager->persist($article1);
     $article2 = new Article();
     $article2->setPublishedAt(\DateTime::createFromFormat('Y-m-d H:i:s', '2013-09-24 13:53:00'));
     $article2->setTitle('How to use WSSE in Android app');
     $article2->setCategory($this->getReference('category_1'));
     $article2->setContent('After publishing an article about WSSE configuration in Symfony2, we received a lot of questions about using WSSE in Android application. We hope this article will answer some of these questions!
         Note that we will only speak about WSSE and not about designing a rest client in Android application.
     ');
     $article2->setTags(array('WSSE', 'Android'));
     $manager->persist($article2);
     $article3 = new Article();
     $article3->setPublishedAt(\DateTime::createFromFormat('Y-m-d H:i:s', '2013-09-13 10:57:00'));
     $article3->setTitle('Create a custom form theme block with Twig');
     $article3->setCategory($this->getReference('category_3'));
     $article3->setContent('I wanted to use the following block. As you see, in addition to the specific p element, the div and their specific classes, the big difference with the native Twig form_row method is that the radio labels are not in a label tag (but there is a label tag for the parent form field).
     ');
     $article3->setTags(array('Twig', 'Symfony2'));
     $manager->persist($article3);
     $article4 = new Article();
     $article4->setPublishedAt(\DateTime::createFromFormat('Y-m-d H:i:s', '2013-10-17 11:34:00'));
     $article4->setTitle('Efficient Elasticsearch indexing configuration');
     $article4->setCategory($this->getReference('category_2'));
     $article4->setContent('This post is about elasticsearch which is a great search engine.
         The biggest difficulty we meet is that we do not know how to configure it to have relevant search results. Another difficulty is (sorry to say that), the documentation is not very well done. Ok, it’s my opinion and I can’t denied we found usefull information in it, but information are sometimes difficult to find.
     ');
     $article4->setTags(array('Elasticsearch'));
     $manager->persist($article4);
     $article5 = new Article();
     $article5->setPublishedAt(\DateTime::createFromFormat('Y-m-d H:i:s', '2013-09-24 13:53:00'));
     $article5->setTitle('Configure WSSE on Symfony2 with FOSRestBundle');
     $article5->setCategory($this->getReference('category_1'));
     $article5->setContent('The client–server communication is further constrained by no client context being stored on the server between requests. Each request from any client contains all of the information necessary to service the request, and any session state is held in the client.
     ');
     $article5->setTags(array('Symfony2', 'WSSE'));
     $manager->persist($article5);
     $article6 = new Article();
     $article6->setPublishedAt(\DateTime::createFromFormat('Y-m-d H:i:s', '2013-06-21 16:24:00'));
     $article6->setTitle('How to keep your translations well organized in Symfony2');
     $article6->setCategory($this->getReference('category_3'));
     $article6->setContent('We are working at the moment on a big internationalized project, and we have consequently many translations in our application. These translations are dispatched in many bundles (7 for now) and are used throughout the application. At the begining of the development, we hadn’t any specific organisation for the translations and we put the translation in a random bundle (the one on which we were working, most of the time).');
     $article6->setTags(array('Symfony2'));
     $manager->persist($article6);
     $article7 = new Article();
     $article7->setPublishedAt(\DateTime::createFromFormat('Y-m-d H:i:s', '2013-05-31 15:13:00'));
     $article7->setTitle('Install Rest in Symfony2 existing application');
     $article7->setCategory($this->getReference('category_1'));
     $article7->setContent('As we needed a connection between a Symfony2 web application and an Android application, we had to learn and understand how to make this in a simple and secured way, based on our existing entities.
         We chose WSSE for security access, FOSRestBundle for datas restitution and JMSSerializerBundle for serialization. 
     ');
     $article7->setTags(array('Symfony2', 'REST'));
     $manager->persist($article7);
     $article8 = new Article();
     $article8->setPublishedAt(\DateTime::createFromFormat('Y-m-d H:i:s', '2013-04-21 11:44:00'));
     $article8->setTitle('DateTimePicker field type with Symfony2 and jQuery');
     $article8->setCategory($this->getReference('category_3'));
     $article8->setContent('In this third post, we’ll explain how to create a great custom field type that uses jQuery DatePicker to handle date input, and then, how to extend it to create a datetime field type. And the best? The datepicker is localized according to the user’s locale.
     ');
     $article8->setTags(array('Symfony2', 'jQuery'));
     $manager->persist($article8);
     $article9 = new Article();
     $article9->setPublishedAt(\DateTime::createFromFormat('Y-m-d H:i:s', '2013-04-21 11:44:00'));
     $article9->setTitle('Currency Change rates update on Symfony2 using openexchangerates.org API');
     $article9->setCategory($this->getReference('category_3'));
     $article9->setContent('In this post, we’ll explain how to create and maintain a database with currencies and change rates.
         In order to update our changes rates, we will user openexchangerates.org solution. (Exists as free, premium and pro)
     ');
     $article9->setTags(array('Symfony2', 'Currency'));
     $manager->persist($article9);
     $article10 = new Article();
     $article10->setPublishedAt(\DateTime::createFromFormat('Y-m-d H:i:s', '2012-11-05 11:00:00'));
     $article10->setTitle('Create a breadcrumb menu with KnpMenuBundle');
     $article10->setCategory($this->getReference('category_3'));
     $article10->setContent('In this first post, I’ll explain how to make a breadcrumb menu with the great KnpMenuBundle. The documentation explains the basics and how to make a common menu, but a breadcrumb menu has a particular behaviour.
     ');
     $article10->setTags(array('Symfony2', 'KnpMenuBundle'));
     $manager->persist($article10);
     $article11 = new Article();
     $article11->setPublishedAt(\DateTime::createFromFormat('Y-m-d H:i:s', '2013-05-29 17:39:00'));
     $article11->setTitle('Create new log file/channel for a Symfony2 Service (With monolog)');
     $article11->setCategory($this->getReference('category_3'));
     $article11->setContent('In this article about WSSE and Rest, we describe how to create a new log file/channel with monolog in Symfony2
     ');
     $article11->setTags(array('WSSE', 'REST', 'Symfony2'));
     $manager->persist($article11);
     $article12 = new Article();
     $article12->setPublishedAt(\DateTime::createFromFormat('Y-m-d H:i:s', '2013-05-29 17:39:00'));
     $article12->setTitle('Java');
     $article12->setCategory($this->getReference('category_4'));
     $article12->setContent('What is Java ?');
     $article12->setTags(array('Java'));
     $manager->persist($article12);
     $manager->flush();
 }