public function testModel() { $myItem = new Item(); $myItem->setAttribute('title', 'My Coolest Item'); $myItem->getBody()->edit('sth'); $myInteraction = new ChoiceInteraction(); $myInteraction->getPrompt()->edit('Prompt you'); $myChoice1 = $myInteraction->createChoice(array('fixed' => true), 'This is correct'); $myChoice2 = $myInteraction->createChoice(array('fixed' => true), 'This is not correct'); $this->assertInstanceOf('\\oat\\taoQtiItem\\model\\qti\\choice\\SimpleChoice', $myChoice2); $this->assertEquals(count($myInteraction->getChoices()), 2); $myChoice1->setContent('answer #1'); $myChoice2->setContent('answer #2'); $myInteraction->removeChoice($myChoice1); $this->assertEquals(count($myInteraction->getChoices()), 1); $myItem->addInteraction($myInteraction, "Adding my interaction here {$myInteraction->getPlaceholder()}. And not there."); $this->assertNotNull($myInteraction->getRelatedItem()); $this->assertEquals($myInteraction->getRelatedItem()->getSerial(), $myItem->getSerial()); $myResponse = new ResponseDeclaration(); $myItem->addResponse($myResponse); $this->assertNotNull($myResponse->getRelatedItem()); $this->assertEquals($myResponse->getRelatedItem()->getSerial(), $myItem->getSerial()); $myItem->removeResponse($myResponse); $responses = $myItem->getResponses(); $this->assertTrue(empty($responses)); }
/** * Remove unused response declaration from the items and rp template misuse * * @param oat\taoQtiItem\modal\Item $item * @param string $itemFile * @return boolean */ protected function updateItem(\oat\taoQtiItem\model\qti\Item $item, $itemFile) { $changed = false; $responses = $item->getResponses(); $interactions = $item->getInteractions(); $usedResponses = []; foreach ($interactions as $interaction) { $usedResponses[] = $interaction->attr('responseIdentifier'); } foreach ($responses as $response) { $responseIdentifier = $response->attr('identifier'); if (!in_array($responseIdentifier, $usedResponses)) { $changed = true; $item->removeResponse($response); } } $xml = simplexml_load_file($itemFile); $rpTemplate = (string) $xml->responseProcessing['template']; //detect wrong usage for standard standard response declaration $rp = $item->getResponseProcessing(); if ($rp instanceof \oat\taoQtiItem\model\qti\response\TemplatesDriven && $rpTemplate) { if (count($interactions) > 1) { $changed = true; } else { $interaction = reset($interactions); if ($interaction && $interaction->attr('responseIdentifier') != 'RESPONSE') { $changed = true; } } } return $changed; }
/** * Update the item content by wrapping the modalfeedback body into a new wrapper * * @param oat\taoQtiItem\modal\Item $item * @param string $itemFile * @return boolean */ protected function updateItem(\oat\taoQtiItem\model\qti\Item $item, $itemFile) { $changed = false; $responses = $item->getResponses(); foreach ($responses as $response) { $responseIdentifier = $response->attr('identifier'); $rules = $response->getFeedbackRules(); foreach ($rules as $rule) { $modalFeedbacks = array(); if ($rule->getFeedbackThen()) { $modalFeedbacks[] = $rule->getFeedbackThen(); } if ($rule->getFeedbackElse()) { $modalFeedbacks[] = $rule->getFeedbackElse(); } foreach ($modalFeedbacks as $modalFeedback) { $feedbackXml = simplexml_load_string($modalFeedback->toQti()); if ($feedbackXml->div[0] && $feedbackXml->div[0]['class'] && preg_match('/^x-tao-wrapper/', $feedbackXml->div[0]['class'])) { //the item body has not already been wrapped by the new wrapper <div class="x-tao-wrapper w-tao-relatedOutcome-{{response.identifier}}"> continue; } $message = $modalFeedback->getBody()->getBody(); $modalFeedback->getBody()->edit('<div class="x-tao-wrapper x-tao-relatedOutcome-' . $responseIdentifier . '">' . $message . '</div>', true); $changed = true; } } } return $changed; }
protected function getResponse($identifier) { foreach ($this->item->getResponses() as $response) { if ($response->getIdentifier() == $identifier) { return $response; } } throw new ParsingException('cannot found the response with identifier ' . $identifier); }