/** * @Route("/details/{id}", requirements={"id"="\d+"}, name="civix_front_petitions_details") * @Method({"GET"}) * @Template("CivixFrontBundle:Group:petitionDetails.html.twig") */ public function petitionDetailsAction(Petition $petition) { if ($petition->getGroup() !== $this->getUser()) { throw new AccessDeniedHttpException(); } $statistics = $this->get('civix_core.poll.micropetition_manager')->getStatisticByPetition($petition, array('#7ac768', '#ba3830')); return array('petition' => $petition, 'statistics' => $statistics); }
/** * @Route("/{id}/answers/") * @Method("GET") */ public function answersListAction(Petition $microPetition) { if ($microPetition->getGroup() !== $this->getUser()) { return $this->createJSONResponse('', 403); } $answers = $this->getDoctrine()->getRepository(Answer::class)->findByPetition($microPetition); return $this->createJSONResponse($this->jmsSerialization($answers, ['api-leader-answers'])); }
/** * @param Petition $petition * @param bool $saveTagsInEntity */ public function addForPetition(Petition $petition, $saveTagsInEntity = true) { $em = $this->getEntityManager(); $tags = HashTagParser::parseHashTags($petition->getPetitionBody()); foreach ($tags['parsed'] as $tag) { $entity = $this->findOneByName($tag); if (!$entity) { $entity = new HashTag($tag); $em->persist($entity); } $entity->addPetition($petition); $em->flush($entity); } if ($saveTagsInEntity) { $petition->setCachedHashTags($tags['original']); $em->flush($petition); } }
public function noticeMicropetitionCreated(Micropetition $micropetition) { $socialActivity = (new SocialActivity(SocialActivity::TYPE_GROUP_POST_CREATED, $micropetition->getUser(), $micropetition->getGroup()))->setTarget(['id' => $micropetition->getId(), 'title' => $micropetition->getTitle(), 'type' => $micropetition->getType(), 'body' => $micropetition->getPetitionBody()]); $this->em->persist($socialActivity); $this->em->flush($socialActivity); $this->pt->addToQueue('sendSocialActivity', [$socialActivity->getId()]); return $socialActivity; }
/** * @group petition */ public function testGetQuorumCount() { $petition = new Petition(); $group = new Group(); $petition->setGroup($group); $this->assertEquals(0, $petition->getQuorumCount()); /* 10 users in a group */ for ($i = 0; $i < 10; $i++) { $userGroup = new UserGroup(new User(), $group); $group->addUser($userGroup); } $this->assertEquals(1, $petition->getQuorumCount()); $group->setPetitionPercent(30); $this->assertEquals(3, $petition->getQuorumCount()); /* 112 users in a group (33 to quorum for 30%)*/ for ($i = 0; $i < 102; $i++) { $userGroup = new UserGroup(new User(), $group); $group->addUser($userGroup); } $this->assertGreaterThan(33, $petition->getQuorumCount()); }
/** * Check count answers from group of petition. If it greater than 10% group's followers * than need to publish to actitvity * * @param \Civix\CoreBundle\Entity\Micropetitions\Petition $petition * * @return boolean */ public function checkIfNeedPublish(UserPetition $petition) { if ($petition->getType() === $petition::TYPE_OPEN_LETTER) { return false; } $groupAnswers = $this->entityManager->getRepository('CivixCoreBundle:Micropetitions\\Answer')->getCountAnswerFromGroup($petition); return $groupAnswers >= $petition->getQuorumCount(); }
private function createActivityConditionsForMicroPetition(Activity $activity, MicroPetition $microPetition) { $this->createGroupActivityConditions($activity); if ($microPetition->getIsOutsidersSign() || $microPetition->getPublishStatus() === $microPetition::STATUS_USER) { $this->createUserActivityConditions($activity, $microPetition->getUser()); } }
public function getComments() { $this->__load(); return parent::getComments(); }