コード例 #1
0
 private function hasSurveyRight(Survey $survey, $right)
 {
     $collection = new ResourceCollection([$survey->getResourceNode()]);
     return $this->authorization->isGranted($right, $collection);
 }
コード例 #2
0
 public function __construct(Survey $survey, User $user)
 {
     parent::__construct(self::ACTION, array(), $user, null, $survey->getResourceNode(), null, $survey->getResourceNode()->getWorkspace());
 }
コード例 #3
0
 /**
  * @DI\Observe("copy_claroline_survey")
  *
  * @param CopyResourceEvent $event
  */
 public function onCopy(CopyResourceEvent $event)
 {
     $survey = $event->getResource();
     $copy = new Survey();
     $copy->setPublished($survey->isPublished());
     $copy->setClosed($survey->isClosed());
     $copy->setHasPublicResult($survey->getHasPublicResult());
     $copy->setAllowAnswerEdition($survey->getAllowAnswerEdition());
     $copy->setStartDate($survey->getStartDate());
     $copy->setEndDate($survey->getEndDate());
     $this->om->persist($copy);
     $relations = $survey->getQuestionRelations();
     foreach ($relations as $relation) {
         $newRelation = new SurveyQuestionRelation();
         $newRelation->setSurvey($copy);
         $newRelation->setQuestion($relation->getQuestion());
         $newRelation->setQuestionOrder($relation->getQuestionOrder());
         $this->om->persist($newRelation);
     }
     $event->setCopy($copy);
     $event->stopPropagation();
 }
コード例 #4
0
 /**
  * @DI\Observe("copy_claroline_survey")
  *
  * @param CopyResourceEvent $event
  */
 public function onCopy(CopyResourceEvent $event)
 {
     $workspace = $event->getParent()->getWorkspace();
     $survey = $event->getResource();
     $copy = new Survey();
     $copy->setPublished($survey->isPublished());
     $copy->setClosed($survey->isClosed());
     $copy->setHasPublicResult($survey->getHasPublicResult());
     $copy->setAllowAnswerEdition($survey->getAllowAnswerEdition());
     $copy->setStartDate($survey->getStartDate());
     $copy->setEndDate($survey->getEndDate());
     $this->om->persist($copy);
     $relations = $survey->getQuestionRelations();
     foreach ($relations as $relation) {
         $question = $relation->getQuestion();
         $type = $question->getType();
         $copyQuestion = new Question();
         $copyQuestion->setTitle($question->getTitle());
         $copyQuestion->setQuestion($question->getQuestion());
         $copyQuestion->setWorkspace($workspace);
         $copyQuestion->setType($type);
         $copyQuestion->setCommentAllowed($question->isCommentAllowed());
         $copyQuestion->setCommentLabel($question->getCommentLabel());
         $this->om->persist($copyQuestion);
         switch ($type) {
             case 'multiple_choice_single':
             case 'multiple_choice_multiple':
                 $multiChoiceQuestion = $this->surveyManager->getMultipleChoiceQuestionByQuestion($question);
                 $choices = $multiChoiceQuestion->getChoices();
                 $copyMultiQuestion = new MultipleChoiceQuestion();
                 $copyMultiQuestion->setHorizontal($multiChoiceQuestion->getHorizontal());
                 $copyMultiQuestion->setQuestion($copyQuestion);
                 foreach ($choices as $choice) {
                     $copyChoice = new Choice();
                     $copyChoice->setContent($choice->getContent());
                     $copyChoice->setOther($choice->isOther());
                     $copyChoice->setChoiceQuestion($copyMultiQuestion);
                     $this->om->persist($copyChoice);
                 }
                 $this->om->persist($copyMultiQuestion);
                 break;
             case 'open-ended':
             default:
                 break;
         }
         $copyRelation = new SurveyQuestionRelation();
         $copyRelation->setSurvey($copy);
         $copyRelation->setQuestion($copyQuestion);
         $copyRelation->setQuestionOrder($relation->getQuestionOrder());
         $this->om->persist($copyRelation);
     }
     $event->setCopy($copy);
     $event->stopPropagation();
 }
コード例 #5
0
 public function updateSurveyStatus(Survey $survey)
 {
     $startDate = $survey->getStartDate();
     $endDate = $survey->getEndDate();
     $flush = false;
     if (!is_null($startDate) || !is_null($endDate)) {
         $now = new \DateTime();
         if (!is_null($startDate) && !is_null($endDate) && $now > $startDate && $now < $endDate && ($survey->isClosed() || !$survey->isPublished())) {
             $survey->setPublished(true);
             $survey->setClosed(false);
             $this->om->persist($survey);
             $flush = true;
         } else {
             if (!$survey->isPublished() && !$survey->isClosed() && !is_null($startDate) && $now > $startDate) {
                 $survey->setPublished(true);
                 $this->om->persist($survey);
                 $flush = true;
             }
             if (!$survey->isClosed() && !is_null($endDate) && $now > $endDate) {
                 $survey->setClosed(true);
                 $this->om->persist($survey);
                 $flush = true;
             }
         }
         if ($flush) {
             $this->om->flush();
         }
     }
 }