public function load(ObjectManager $manager) { $question = $this->getReference('question1'); $options = array(array('value' => 'option1'), array('value' => 'option2'), array('value' => 'option3')); foreach ($options as $data) { $option = new Option(); $option->setValue($data['value'])->setQuestion($question); $this->addReference('option-' . $data['value'], $option); $manager->persist($option); } $manager->flush(); }
public function load(ObjectManager $manager) { $petition = new GroupPetition(); $petition->setPetitionTitle('Petition title'); $petition->setPetitionBody('Petition body'); $petition->setUser($this->getReference('group-group1')); $petition->setPublishedAt(new \DateTime('now')); $option = new Option(); $option->setQuestion($petition)->setValue('sign'); $this->addReference('petition1', $petition); $this->addReference('petition-option1', $option); $manager->persist($option); $manager->persist($petition); $manager->flush(); }
public function load(ObjectManager $manager) { $questionData = array('question1', 'question2'); $options = array(array('value' => 'option1'), array('value' => 'option2')); foreach ($questionData as $key => $questionSubject) { $question = $this->getReference($questionSubject); foreach ($options as $optionKey => $data) { if ($key <= $optionKey) { $option = new Option(); $option->setValue($data['value'])->setQuestion($question); $this->addReference($questionSubject . '-option-' . $data['value'], $option); $manager->persist($option); } } } $manager->flush(); }
public function load(ObjectManager $manager) { $petition = $this->getReference('representativePetitionPublished1'); $user1 = $this->getReference('user-mobile1'); $signOption = new Option(); $signOption->setValue('sign'); $petition->addOption($signOption); $manager->persist($signOption); $answer = new Answer(); $answer->setQuestion($petition); $answer->setPrivacy(Answer::PRIVACY_PUBLIC); $answer->setUser($user1); $answer->setComment('Test comment'); $answer->setOption($signOption); $manager->persist($answer); $petition->addAnswer($answer); $manager->persist($petition); $manager->flush(); }
/** * @Given /^There are published questions$/ */ public function thereArePublishedQuestions(TableNode $table) { $em = $this->getEm(); $hash = $table->getHash(); foreach ($hash as $row) { $class = 'Civix\\CoreBundle\\Entity\\Poll\\Question\\' . $row['type']; /* @var $entity \Civix\CoreBundle\Entity\Poll\Question */ $entity = new $class(); $entity->setSubject($row['subject']); $entity->setPublishedAt(new \DateTime()); $expire = new \DateTime(); $expire->add(new \DateInterval('P1D')); $entity->setExpireAt($expire); $entity->setUser($em->getRepository('Civix\\CoreBundle\\Entity\\' . $row['owner'])->findOneByUsername($row['username'])); foreach (range(1, 2) as $value) { $option = new Option(); $option->setValue($value); $entity->addOption($option); } $em->persist($entity); $em->flush($entity); } }
/** * @Route("/new") * @Template("CivixFrontBundle:Petition:new.html.twig") */ public function newAction(Request $request) { $class = $this->getPetitionClass(); $petitionFormClass = $this->getPetitionFormClass(); $petition = new $class(); $form = $this->createForm(new $petitionFormClass($this->getUser()), new PetitionFormModel($petition)); if ('POST' === $request->getMethod()) { if ($form->submit($request)->isValid()) { $manager = $this->getDoctrine()->getManager(); $petition->setUser($this->getUser()); /* @var $educationalContext \Civix\FrontBundle\Form\Model\EducationalContext */ $educationalContext = $form->getData()->getEducationalContext(); $petition->clearEducationalContext(); foreach ($educationalContext->getItems() as $item) { if ($item->getImageFile()) { $this->get('vich_uploader.storage')->upload($item); } /** * @var $entity \Civix\CoreBundle\Entity\Poll\EducationalContext */ $entity = $item->createEntity(); if ($entity) { $entity->setQuestion($petition); $manager->persist($entity); } } $option = new Option(); $option->setQuestion($petition)->setValue('sign'); $manager->persist($option); $manager->persist($petition); $manager->flush(); $this->get('session')->getFlashBag()->add('notice', 'The petition has been successfully saved'); return $this->redirect($this->generateUrl("civix_front_{$this->getUser()->getType()}_petition_index")); } } return ['form' => $form->createView(), 'isShowGroupSection' => $this->isShowGroupSections($petition)]; }
/** * @Route("/publish/{id}/follow-up/{petition}", requirements={"id"="\d+"}) * @Template("CivixFrontBundle:PaymentRequest:follow-up-publish.html.twig") */ public function publishFollowUpAction(Request $request, $id, Petition $petition) { $paymentRequest = $this->getPaymentRequest($id); $package = $this->get('civix_core.subscription_manager')->getPackage($this->getUser()); if ($paymentRequest->getUser() !== $this->getUser() || $paymentRequest->getPublishedAt() || !$package->isTargetedPetitionFundraisingAvailable()) { throw new AccessDeniedHttpException(); } $users = $this->getDoctrine()->getRepository(Answer::class)->findSignedUsersByPetition($petition); $amount = $package->getTargetedPetitionFundraisingPrice() * count($users); $form = $this->createForm('form', null, ['label' => $amount / 100 . '$']); if ('POST' === $request->getMethod() && $form->submit($request)->isValid()) { if (intval($request->get('user_count')) !== count($users)) { $this->get('session')->getFlashBag()->add('notice', 'Users amount has changed. Please review.'); } else { try { $this->get('civix_core.stripe')->chargeUser($this->getUser(), $amount, 'PowerlinePay', 'Powerline Payment: Payment Request Publishing'); } catch (\Stripe\Error\Card $e) { $this->get('session')->getFlashBag()->add('error', $e->getJsonBody()['error']['message']); return $this->redirect($this->generateUrl("civix_front_{$this->getUser()->getType()}_paymentrequest_publishfollowup", ['id' => $id, 'petition' => $petition->getId()])); } $paymentRequest->setPublishedAt(new \DateTime()); $ignore = new Option(); $ignore->setPaymentAmount(0)->setValue('Ignore')->setQuestion($paymentRequest); $this->getDoctrine()->getManager()->persist($ignore); $this->getDoctrine()->getManager()->flush($paymentRequest); $this->getDoctrine()->getManager()->flush($ignore); $this->get('civix_core.activity_update')->publishPaymentRequestToActivity($paymentRequest, $users); if ($paymentRequest->getIsAllowOutsiders()) { /* @var User $user */ foreach ($users as $user) { if (!$user->getIsRegistrationComplete()) { $this->get('civix_core.email_sender')->sendPaymentRequest($paymentRequest, $user); } } } return $this->redirect($this->generateUrl("civix_front_{$this->getUser()->getType()}_paymentrequest_index")); } } return ['paymentRequest' => $paymentRequest, 'users' => $users, 'petition' => $petition, 'hasCard' => $this->get('civix_core.stripe')->hasCard($this->getUser()), 'form' => $form->createView()]; }
/** * Add options * * @param Option $options * * @return Question */ public function addOption(Option $options) { $options->setQuestion($this); $this->options[] = $options; return $this; }
public function getIsUserAmount() { $this->__load(); return parent::getIsUserAmount(); }
/** * Set option * * @param \Civix\CoreBundle\Entity\Poll\Option $option * @return Answer */ public function setOption(\Civix\CoreBundle\Entity\Poll\Option $option = null) { $this->option = $option; $this->optionId = $option->getId(); return $this; }