예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function persistInteractionDetails(Question $question, \stdClass $importData)
 {
     // used by QuestionManager->importQuestion
     // this importQuestion method seems to be used only in test context...
     $interaction = new InteractionMatching();
     // handle proposals
     $persistedProposals = [];
     // do not add twice the same label!!
     // for each firstSet in data (= proposal)
     for ($i = 0, $max = count($importData->firstSet); $i < $max; ++$i) {
         // temporary limitation
         if ($importData->firstSet[$i]->type !== 'text/plain') {
             throw new \Exception("Import not implemented for MIME type {$importData->firstSet[$i]->type}");
         }
         // create a Proposal
         $proposal = new Proposal();
         $proposal->setValue($importData->firstSet[$i]->data);
         $proposal->setOrdre($i);
         $proposal->setInteractionMatching($interaction);
         $interaction->addProposal($proposal);
         $this->om->persist($proposal);
         array_push($persistedProposals, $proposal);
     }
     for ($j = 0, $max = count($importData->secondSet); $j < $max; ++$j) {
         if ($importData->secondSet[$j]->type !== 'text/plain') {
             throw new \Exception("Import not implemented for MIME type {$importData->secondSet[$j]->type}");
         }
         // create interraction label in any case
         $label = new Label();
         $label->setValue($importData->secondSet[$j]->data);
         $label->setOrdre($j);
         // check if current label is in the solution
         foreach ($importData->solutions as $solution) {
             // label is in solution get score from solution
             if ($solution->secondId === $importData->secondSet[$j]->id) {
                 $label->setScoreRightResponse($solution->score);
                 // here we should add proposal to label $proposal->addAssociatedLabel($label);
                 // but how to retrieve the correct proposal (no flush = no id) ??
                 // find this solution a bit overkill
                 // @TODO find a better way to do that!!!!
                 for ($k = 0, $max = count($importData->firstSet); $k < $max; ++$k) {
                     if ($solution->firstId === $importData->firstSet[$k]->id) {
                         $value = $importData->firstSet[$k]->data;
                         for ($l = 0, $max = count($persistedProposals); $l < $max; ++$l) {
                             // find proposal by label... Unicity is not ensured!!!!
                             if ($persistedProposals[$l]->getValue() === $value) {
                                 $persistedProposals[$l]->addAssociatedLabel($label);
                                 $this->om->persist($persistedProposals[$l]);
                                 break;
                             }
                         }
                     }
                 }
             }
             // get feedback from solution
             if (isset($solution->feedback)) {
                 $label->setFeedback($solution->feedback);
             }
         }
         $label->setInteractionMatching($interaction);
         $interaction->addLabel($label);
         $this->om->persist($label);
     }
     $subTypeCode = $importData->toBind ? 1 : 2;
     $subType = $this->om->getRepository('UJMExoBundle:TypeMatching')->findOneByCode($subTypeCode);
     $interaction->setTypeMatching($subType);
     $interaction->setShuffle($importData->random);
     $interaction->setQuestion($question);
     $this->om->persist($interaction);
 }
예제 #2
0
 public function matchProposal($text, Label $label = null)
 {
     $proposal = new Proposal();
     $proposal->setValue($text);
     if ($label !== null) {
         $proposal->addAssociatedLabel($label);
     }
     $this->om->persist($proposal);
     return $proposal;
 }
예제 #3
0
 /**
  * Add proposal
  *
  */
 public function addProposal(\UJM\ExoBundle\Entity\Proposal $proposal)
 {
     $this->proposals[] = $proposal;
     $proposal->setInteractionMatching($this);
 }
예제 #4
0
 /**
  * Create Proposals in BDD.
  */
 protected function createProposals()
 {
     $ordre = 0;
     $ib = $this->assessmentItem->getElementsByTagName('itemBody')->item(0);
     $mi = $ib->getElementsByTagName('matchInteraction')->item(0);
     $sms = $mi->getElementsByTagName('simpleMatchSet')->item(0);
     $labels = $this->associatedLabels;
     $allRelations = $this->relations();
     // foreach proposal into the export file
     foreach ($sms->getElementsByTagName('simpleAssociableChoice') as $simpleProposal) {
         $proposal = new Proposal();
         $proposal->setValue($this->value($simpleProposal));
         $proposal->setOrdre($ordre);
         if ($simpleProposal->hasAttribute('fixed') && $simpleProposal->getAttribute('fixed') == 'true') {
             $proposal->setPositionForce(true);
         } else {
             $proposal->setPositionForce(false);
         }
         $identifiant = $simpleProposal->getAttribute('identifier');
         $proposal->setInteractionMatching($this->interactionMatching);
         $this->om->persist($proposal);
         $rightLabel = 0;
         //compare all relations to the proposal selected
         foreach ($allRelations as $relation) {
             if (stripos($relation, $identifiant) !== false) {
                 $rightLabel = $relation;
                 $rightLabel = str_replace($identifiant, '', $rightLabel);
                 $rightLabel = str_replace(' ', '', $rightLabel);
             }
         }
         // foreach label of the export file, compare to the right relation
         foreach ($labels as $key => $label) {
             if ($key == $rightLabel) {
                 $proposal->addAssociatedLabel($label);
                 $proposal->setInteractionMatching($this->interactionMatching);
                 $this->om->persist($proposal);
             }
         }
         ++$ordre;
     }
     $this->om->flush();
 }