/** * {@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); }
public function matchLabel($text, $score = 0) { $label = new Label(); $label->setFeedback('feedback...'); $label->setValue($text); $label->setScoreRightResponse($score); $this->om->persist($label); return $label; }
/** * Add label * */ public function addLabel(\UJM\ExoBundle\Entity\Label $label) { $this->labels[] = $label; //le label est bien lié à l'entité interactionmatching, mais dans l'entité label il faut //aussi lié l'interactionmatching double travail avec les relations bidirectionnelles avec //lesquelles il faut bien faire attention à garder les données cohérentes dans un autre //script il faudra exécuter $interactionmatching->addLabel() qui garde la cohérence entre les //deux entités, il ne faudra pas exécuter $label->setInteractionMatching(), car lui ne garde //pas la cohérence $label->setInteractionMatching($this); }
/** * Create Labels in BDD. */ protected function createLabels() { $ordre = 0; $ib = $this->assessmentItem->getElementsByTagName('itemBody')->item(0); $mi = $ib->getElementsByTagName('matchInteraction')->item(0); $sms = $mi->getElementsByTagName('simpleMatchSet')->item(1); foreach ($sms->getElementsByTagName('simpleAssociableChoice') as $simpleLabel) { //create a new Label and set attributes $label = new Label(); $feedback = $simpleLabel->getElementsByTagName('feedbackInline'); if ($feedback->item(0)) { $feedbackVal = $this->domElementToString($feedback->item(0)); $feedbackVal = html_entity_decode($feedbackVal); $label->setFeedback($feedbackVal); $simpleLabel->removeChild($feedback->item(0)); } $label->setValue($this->value($simpleLabel)); $identifiant = $simpleLabel->getAttribute('identifier'); $label->setScoreRightResponse($this->notation($identifiant)); $label->setInteractionMatching($this->interactionMatching); $label->setOrdre($ordre); if ($simpleLabel->hasAttribute('fixed') && $simpleLabel->getAttribute('fixed') == 'true') { $label->setPositionForce(true); } else { $label->setPositionForce(false); } //recording in the DBB $this->om->persist($label); $this->associatedLabels[$identifiant] = $label; ++$ordre; } $this->om->flush(); }