/**
  * Show the form to edit an instance, show also a preview of the media
  */
 public function editInstance()
 {
     $clazz = $this->getCurrentClass();
     $instance = $this->getCurrentInstance();
     $myFormContainer = new editInstanceForm($clazz, $instance);
     $myForm = $myFormContainer->getForm();
     if ($myForm->isSubmited()) {
         if ($myForm->isValid()) {
             $values = $myForm->getValues();
             // save properties
             $binder = new \tao_models_classes_dataBinding_GenerisFormDataBinder($instance);
             $instance = $binder->bind($values);
             $message = __('Instance saved');
             $this->setData('message', $message);
             $this->setData('reload', true);
         }
     }
     $this->setData('formTitle', __('Edit Instance'));
     $this->setData('myForm', $myForm->render());
     $uri = $this->hasRequestParameter('id') ? $this->getRequestParameter('id') : $this->getRequestParameter('uri');
     try {
         $mediaSource = new MediaSource(array());
         $fileInfo = $mediaSource->getFileInfo($uri);
         $mimeType = $fileInfo['mime'];
         $xml = in_array($mimeType, array('application/xml', 'text/xml'));
         $url = \tao_helpers_Uri::url('getFile', 'MediaManager', 'taoMediaManager', array('uri' => $uri));
         $this->setData('xml', $xml);
         $this->setData('fileurl', $url);
         $this->setData('mimeType', $mimeType);
     } catch (\tao_models_classes_FileNotFoundException $e) {
         $this->setData('error', __('No file found for this media'));
     }
     $this->setView('form.tpl');
 }
 public function getFile()
 {
     if ($this->hasRequestParameter('uri')) {
         $uri = urldecode($this->getRequestParameter('uri'));
         $mediaSource = new MediaSource(array());
         $fileInfo = $mediaSource->getFileInfo($uri);
         $link = $fileInfo['link'];
         $fileManagement = $this->getServiceManager()->get(FileManagement::SERVICE_ID);
         if ($fileInfo['mime'] === 'application/qti+xml') {
             \tao_helpers_Http::returnStream($fileManagement->getFileStream($link));
             return;
         }
         if ($this->hasRequestParameter('xml')) {
             $this->returnJson(htmlentities((string) $fileManagement->getFileStream($link)));
         } else {
             \tao_helpers_Http::returnStream($fileManagement->getFileStream($link), $fileInfo['mime']);
         }
     } else {
         throw new \common_exception_Error('invalid media identifier');
     }
 }
 /**
  * @expectedException        \tao_models_classes_FileNotFoundException
  * @expectedExceptionMessage File A Fake link not found
  */
 public function testGetFileInfoFail()
 {
     $link = 'A Fake link';
     $this->mediaManagerManagement->getFileInfo($link);
 }