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;
 }
 public function answerToPetitition(UserPetition $userPetition, User $user, $optionId)
 {
     $this->errors = [];
     $currentDate = new \DateTime();
     if ($userPetition->getExpireAt() <= $currentDate) {
         $this->errors[] = 'You could not answer to expired micropetition';
         return false;
     }
     if ($userPetition->getUser() == $user) {
         $this->errors[] = 'You could not answer to your micropetition';
         return false;
     }
     if (array_search($optionId, $userPetition->getOptionsIds()) === false) {
         $this->errors[] = 'Incorrect answer\'s option';
         return false;
     }
     $answer = $this->entityManager->getRepository('CivixCoreBundle:Micropetitions\\Answer')->findOneBy(array('petition' => $userPetition, 'user' => $user));
     if ($answer && $answer->getOptionId() !== 3) {
         $this->errors[] = 'User is already answered this micropetition';
         return false;
     } else {
         if ($answer) {
             $this->entityManager->remove($answer);
         }
     }
     //add answers
     $answer = $this->entityManager->getRepository('CivixCoreBundle:Micropetitions\\Answer')->createAnswer($userPetition, $user, $optionId);
     $this->entityManager->persist($answer);
     $this->entityManager->flush();
     //update response count activity for this petition
     $this->activityUpdate->updateResponsesPetition($userPetition);
     //check if need to publish to activity
     if ($userPetition->getPublishStatus() == UserPetition::STATUS_USER) {
         if ($this->checkIfNeedPublish($userPetition)) {
             $this->activityUpdate->publishMicroPetitionToActivity($userPetition, true);
         }
     }
     return $answer;
 }
 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 getUser()
 {
     $this->__load();
     return parent::getUser();
 }