/** * @Route("/topic/start", name="startTopic") */ public function newAction(Request $request) { $tags = $this->getDoctrine()->getRepository('AppBundle:Tag')->findAll(); dump($tags); $topic = new Topic(); $topic->setDate(new \DateTime('now')); $topic->setLastModified(new \DateTime('now')); $form = $this->createFormBuilder($topic)->add('headline', TextType::class)->add('description', TextareaType::class)->add('tags', EntityType::class, array('class' => 'AppBundle:Tag', 'choice_label' => 'title', 'choices' => $tags, "multiple" => true, 'choices_as_values' => true, 'expanded' => true))->add('save', SubmitType::class, array('label' => 'Start new Topic'))->getForm(); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { // ... perform some action, such as saving the task to the database dump($form); $securityContext = $this->container->get('security.authorization_checker'); $token = $this->get('security.token_storage')->getToken(); /* @var $user User */ $user = $token->getUser(); dump($user); $topic->setAuthor($user); $topic->addActiveUser($user); dump($topic); $em = $this->getDoctrine()->getManager(); $em->persist($topic); $em->flush(); return $this->redirect($this->generateUrl('watchTopic', array('id' => $topic->getId()))); } return $this->render('Topic/new.html.twig', array('form' => $form->createView())); }
public function save(Topic $entity) { $entity->setUpdated(date_create()); $entityManager = $this->getEntityManager(); $entityManager->persist($entity); $entityManager->flush(); return $entity; }
/** * @Given there are following topics: * * @param TableNode $tableNode */ public function thereAreFollowingTopics(TableNode $tableNode) { $em = $this->getEntityManager(); foreach ($tableNode->getHash() as $topicHash) { $topic = new Topic(); $topic->setName($topicHash['name']); $em->persist($topic); } $em->flush(); }
/** * Transforms a string to an ArrayCollection. * * @param string $value * * @return ArrayCollection */ public function reverseTransform($value) { $topics = new ArrayCollection(); if (null === $value) { return $topics; } $tokens = preg_split('/(\\s*,\\s*)+/', $value, -1, PREG_SPLIT_NO_EMPTY); foreach ($tokens as $token) { if (null === ($topic = $this->om->getRepository('AppBundle:Topic')->findOneByName($token))) { $topic = new Topic(); $topic->setName($token); $this->om->persist($topic); } $topics->add($topic); } $this->om->flush(); return $topics; }
public function load(ObjectManager $manager) { $u1 = new User(); $u1->setUsername('admin'); $u1->setGender(1); $u1->setEmail("*****@*****.**"); $u1->setCreationDate(new \DateTime('now')); $u1->setModificationDate(new \DateTime('now')); $t1 = new Topic(); $t1->setTitle('first topic'); $t1->setAnthorId(1); $t1->setAgree(1); $t1->setDisagree(0); $t1->setContent('long long long string'); $t1->setModificationDate(new \DateTime('now')); $t1->setCreationDate(new \DateTime('now')); $manager->persist($u1); $manager->persist($t1); $manager->flush(); }
private function route(Topic $topic) { return $this->get('router')->generate('api_1_get_topic', ['topic' => $topic->getId()]); }