/** * add the tag mapping in responseDeclaration. * * * @param \UJM\ExoBundle\Entity\Hole $hole */ private function mappingTag($hole) { $responseDeclaration = $this->responseDeclaration[$this->nbResponseDeclaration - 1]; $correctResponse = $this->correctResponse[$this->nbResponseDeclaration - 1]; $correctWordResponse = ''; $mapping = $this->document->createElement('mapping'); $mapping->setAttribute('defaultValue', '0'); foreach ($hole->getWordResponses() as $resp) { $i = 0; if ($correctWordResponse == '') { $correctWordResponse = $resp; } else { if ($correctWordResponse->getScore() < $resp->getScore()) { $correctWordResponse = $resp; } } $mapEntry = $this->document->createElement('mapEntry'); if (!$hole->getSelector()) { $mapEntry->setAttribute('mapKey', $resp->getResponse()); } else { $mapEntry->setAttribute('mapKey', 'choice_' . $resp->getId()); } $mapEntry->setAttribute('mappedValue', $resp->getScore()); $mapEntry->setAttribute('caseSensitive', $resp->getCaseSensitive()); $mapping->appendChild($mapEntry); if ($resp->getFeedback() != null && $resp->getFeedback() != '') { $feedbackInline = $this->document->CreateElement('feedbackInline'); $feedbackInline->setAttribute('outcomeIdentifier', 'FEEDBACK'); $feedbackInline->setAttribute('identifier', 'choice_' . $resp->getId()); $feedbackInline->setAttribute('showHide', 'show'); $this->getDomEl($feedbackInline, $resp->getFeedback()); $mapEntry->appendChild($feedbackInline); } ++$i; } $Tagvalue = $this->document->CreateElement('value'); if (!$hole->getSelector()) { $responsevalue = $this->document->CreateTextNode($correctWordResponse->getResponse()); } else { $responsevalue = $this->document->CreateTextNode('choice_' . $correctWordResponse->getId()); } $Tagvalue->appendChild($responsevalue); $correctResponse->appendChild($Tagvalue); $responseDeclaration->appendChild($correctResponse); $responseDeclaration->appendChild($mapping); }
/** * add the tag mapping in responseDeclaration * * @access private * * @param \UJM\ExoBundle\Entity\Hole $hole * */ private function mappingTag($hole) { $responseDeclaration = $this->responseDeclaration[$this->nbResponseDeclaration - 1]; $correctResponse = $this->correctResponse[$this->nbResponseDeclaration - 1]; $correctWordResponse = ''; $mapping = $this->document->createElement("mapping"); $mapping->setAttribute("defaultValue", "0"); foreach ($hole->getWordResponses() as $resp) { $i = 0; if ($correctWordResponse == '') { $correctWordResponse = $resp; } else { if ($correctWordResponse->getScore() < $resp->getScore()) { $correctWordResponse = $resp; } } $mapEntry = $this->document->createElement("mapEntry"); if (!$hole->getSelector()) { $mapEntry->setAttribute("mapKey", $resp->getResponse()); } else { $mapEntry->setAttribute("mapKey", 'choice_' . $resp->getId()); } $mapEntry->setAttribute("mappedValue", $resp->getScore()); $mapEntry->setAttribute("caseSensitive", $resp->getCaseSensitive()); $mapping->appendChild($mapEntry); $i++; } $Tagvalue = $this->document->CreateElement("value"); if (!$hole->getSelector()) { $responsevalue = $this->document->CreateTextNode($correctWordResponse->getResponse()); } else { $responsevalue = $this->document->CreateTextNode('choice_' . $correctWordResponse->getId()); } $Tagvalue->appendChild($responsevalue); $correctResponse->appendChild($Tagvalue); $responseDeclaration->appendChild($correctResponse); $responseDeclaration->appendChild($mapping); }
/** * {@inheritdoc} */ public function persistInteractionDetails(Question $question, \stdClass $importData) { $interaction = new InteractionHole(); for ($i = 0, $max = count($importData->holes); $i < $max; ++$i) { // temporary limitation if ($importData->holes[$i]->type !== 'text/html') { throw new \Exception("Import not implemented for MIME type {$importData->holes[$i]->type}"); } $hole = new Hole(); $hole->setOrdre($i); $hole->setInteractionHole($interaction); $interaction->addHole($hole); $this->om->persist($hole); } $interaction->setQuestion($question); $this->om->persist($interaction); }
/** * To delete keywords during the update of interactionHole * * @access private * * @param \UJM\ExoBundle\Entity\Hole $hole * @param Collection of \UJM\ExoBundle\Entity\Hole $originalHoles * */ private function delKeyWord($hole, $originalHoles) { $wordResponses = $hole->getWordResponses()->toArray(); foreach ($originalHoles as $holeOrig) { $originalWords = $holeOrig->getwordResponses()->getSnapshot(); if ($hole->getId() === $holeOrig->getId()) { foreach ($wordResponses as $word) { foreach ($originalWords as $key => $toDel) { if ($toDel->getId() === $word->getId()) { unset($originalWords[$key]); } } } // remove the relationship between the hole and the interactionhole foreach ($originalWords as $word) { // remove the wr from the wordResponse $hole->getWordResponses()->removeElement($word); // if you wanted to delete the Hole entirely, you can also do that $this->em->remove($word); } } } }
/** * Create wordResponse * * @access protected * * @param String $qtiId id of hole in the qti file * @param UJM\ExoBundle\Entity\Hole $hole * */ protected function createWordResponse($qtiId, $hole) { foreach ($this->assessmentItem->getElementsByTagName("responseDeclaration") as $rp) { if ($rp->getAttribute("identifier") == $qtiId) { $mapping = $rp->getElementsByTagName("mapping")->item(0); if ($hole->getSelector() === false) { $this->wordResponseForSimpleHole($mapping, $hole); } else { $ib = $this->assessmentItem->getElementsByTagName("itemBody")->item(0); if ($mapping != null) { $this->wordResponseForList($qtiId, $ib, $mapping, $hole); } } } } }
/** * Create hole * * @access protected * * @param Intger $size hole's size for the input * @param String $qtiId id of hole in the qti file * @param boolean $selector text or list * @param Integer $position position of hole in the text * */ protected function createHole($size, $qtiId, $selector, $position) { $hole = new Hole(); $hole->setSize($size); $hole->setSelector($selector); $hole->setPosition($position); $hole->setInteractionHole($this->interactionHole); $this->om->persist($hole); $this->createWordResponse($qtiId, $hole); }
public function addHole(\UJM\ExoBundle\Entity\Hole $hole) { $this->holes[] = $hole; $hole->setInteractionHole($this); }
/** * @param \UJM\ExoBundle\Entity\Hole $hole * @param string $response * * @return float */ private function getScoreHole($hole, $response) { $em = $this->doctrine->getManager(); $mark = 0; if ($hole->getSelector() == true) { $wr = $em->getRepository('UJMExoBundle:WordResponse')->find($response); $mark = $wr->getScore(); } else { foreach ($hole->getWordResponses() as $wr) { $mark += $this->getScoreWordResponse($wr, $response); } } return $mark; }
/** * Create wordResponse. * * * @param string $qtiId id of hole in the qti file * @param UJM\ExoBundle\Entity\Hole $hole */ protected function createWordResponse($qtiId, $hole) { foreach ($this->assessmentItem->getElementsByTagName('responseDeclaration') as $rp) { if ($rp->getAttribute('identifier') === (string) $qtiId) { $mapping = $rp->getElementsByTagName('mapping')->item(0); if ($hole->getSelector() === false) { $this->wordResponseForSimpleHole($mapping, $hole); } else { $ib = $this->assessmentItem->getElementsByTagName('itemBody')->item(0); $this->wordResponseForList($qtiId, $ib, $mapping, $hole); } } } }