Example #1
0
 public function getJson()
 {
     $returnValue = array('itemData' => null);
     $xml = file_get_contents('php://input');
     Authoring::validateQtiXml($xml);
     $qtiParser = new QtiParser($xml);
     $item = $qtiParser->load();
     if (!is_null($item)) {
         $returnValue['itemData'] = $item->toArray();
     } else {
         throw new common_Exception('invalid qti xml');
     }
     $this->returnJson($returnValue);
 }
 public function testFileParsingApipv1p0()
 {
     $files = glob($this->getSamplePath('/xml/apipv1p0/*.xml'));
     $dom = new \DOMDocument('1.0', 'UTF-8');
     foreach ($files as $file) {
         Authoring::validateQtiXml($file);
     }
 }
Example #3
0
 /**
  * @param $xml
  * @param core_kernel_classes_Resource $rdfItem
  * @return bool
  * @throws exception\QtiModelException
  */
 public function saveXmlItemToRdfItem($xml, core_kernel_classes_Resource $rdfItem)
 {
     $sanitized = Authoring::sanitizeQtiXml($xml);
     Authoring::validateQtiXml($sanitized);
     $qtiParser = new Parser($sanitized);
     $qtiItem = $qtiParser->load();
     return $this->saveDataItemToRdfItem($qtiItem, $rdfItem);
 }
 public function saveItem()
 {
     $returnValue = array('success' => false);
     if ($this->hasRequestParameter('uri')) {
         $uri = urldecode($this->getRequestParameter('uri'));
         $xml = file_get_contents('php://input');
         $rdfItem = new core_kernel_classes_Resource($uri);
         $itemService = taoItems_models_classes_ItemsService::singleton();
         //check if the item is QTI item
         if ($itemService->hasItemModel($rdfItem, array(ItemModel::MODEL_URI))) {
             try {
                 $sanitized = Authoring::sanitizeQtiXml($xml);
                 Authoring::validateQtiXml($sanitized);
                 //get the QTI xml
                 $returnValue['success'] = $itemService->setItemContent($rdfItem, $sanitized);
             } catch (QtiModelException $e) {
                 throw new \RuntimeException($e->getUserMessage(), 0, $e);
             }
         }
     }
     $this->returnJson($returnValue);
 }
 public function saveItem()
 {
     $returnValue = array('success' => false);
     if ($this->hasRequestParameter('uri')) {
         $uri = urldecode($this->getRequestParameter('uri'));
         $xml = file_get_contents('php://input');
         $rdfItem = new core_kernel_classes_Resource($uri);
         $itemService = taoItems_models_classes_ItemsService::singleton();
         //check if the item is QTI item
         if ($itemService->hasItemModel($rdfItem, array(ItemModel::MODEL_URI))) {
             $xml = Authoring::validateQtiXml($xml);
             //get the QTI xml
             $returnValue['success'] = $itemService->setItemContent($rdfItem, $xml);
             $returnValue['xml'] = $xml;
         }
     }
     $this->returnJson($returnValue);
 }