コード例 #1
0
 public function getVariableFile($variableUri)
 {
     //distinguish QTI file from other "file" base type
     $baseType = $this->getVariableBaseType($variableUri);
     // https://bugs.php.net/bug.php?id=52623 ;
     // if the constant for max buffering, mysqlnd or similar driver
     // is being used without need to adapt buffer size as it is atutomatically adapted for all the data.
     if (core_kernel_classes_DbWrapper::singleton()->getPlatForm()->getName() == 'mysql') {
         if (defined("PDO::MYSQL_ATTR_MAX_BUFFER_SIZE")) {
             $maxBuffer = is_int(ini_get('upload_max_filesize')) ? ini_get('upload_max_filesize') * 1.5 : 10485760;
             core_kernel_classes_DbWrapper::singleton()->getSchemaManager()->setAttribute(\PDO::MYSQL_ATTR_MAX_BUFFER_SIZE, $maxBuffer);
         }
     }
     switch ($baseType) {
         case "file":
             $value = $this->getVariableCandidateResponse($variableUri);
             common_Logger::i(var_export(strlen($value), true));
             $decodedFile = Datatypes::decodeFile($value);
             common_Logger::i("FileName:");
             common_Logger::i(var_export($decodedFile["name"], true));
             common_Logger::i("Mime Type:");
             common_Logger::i(var_export($decodedFile["mime"], true));
             $file = array("data" => $decodedFile["data"], "mimetype" => "Content-type: " . $decodedFile["mime"], "filename" => $decodedFile["name"]);
             break;
         default:
             //legacy files
             $file = array("data" => $this->getVariableCandidateResponse($variableUri), "mimetype" => "Content-type: text/xml", "filename" => "trace.xml");
     }
     return $file;
 }
コード例 #2
0
 /**
  * Short description of method prepare
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param array resources results
  * @param array columns variables
  * @return mixed
  */
 public function prepare($resources, $columns)
 {
     $resultsService = ResultsService::singleton();
     /**
      * @var \taoDelivery_models_classes_execution_DeliveryExecution $result
      */
     foreach ($resources as $result) {
         $itemresults = $resultsService->getVariables($result, false);
         foreach ($itemresults as $itemResultUri => $vars) {
             // cache the item information pertaining to a given itemResult (stable over time)
             if (common_cache_FileCache::singleton()->has('itemResultItemCache' . $itemResultUri)) {
                 $itemUri = common_cache_FileCache::singleton()->get('itemResultItemCache' . $itemResultUri);
                 $object = new core_kernel_classes_Resource($itemUri);
             } else {
                 $object = $resultsService->getItemFromItemResult($itemResultUri);
                 if (is_null($object)) {
                     $object = $resultsService->getVariableFromTest($itemResultUri);
                 }
                 if (!is_null($object)) {
                     common_cache_FileCache::singleton()->put($object->getUri(), 'itemResultItemCache' . $itemResultUri);
                 }
             }
             if (get_class($object) == "core_kernel_classes_Resource") {
                 $contextIdentifier = (string) $object->getUri();
             } else {
                 if (!is_null($object)) {
                     $contextIdentifier = (string) $object->__toString();
                 }
             }
             foreach ($vars as $var) {
                 $var = $var[0];
                 // cache the variable data
                 /**
                  * @var \taoResultServer_models_classes_Variable $varData
                  */
                 $varData = $var->variable;
                 if (common_cache_FileCache::singleton()->has('variableDataCache' . $var->uri . '_' . $varData->getIdentifier())) {
                     $varData = common_cache_FileCache::singleton()->get('variableDataCache' . $var->uri . '_' . $varData->getIdentifier());
                 } else {
                     common_cache_FileCache::singleton()->put($varData, 'variableDataCache' . $var->uri . '_' . $varData->getIdentifier());
                 }
                 if ($varData->getBaseType() === 'file') {
                     $decodedFile = Datatypes::decodeFile($varData->getValue());
                     $varData->setValue($decodedFile['name']);
                 }
                 $variableIdentifier = (string) $varData->getIdentifier();
                 foreach ($columns as $column) {
                     if ($variableIdentifier == $column->getIdentifier() and $contextIdentifier == $column->getContextIdentifier()) {
                         $epoch = $varData->getEpoch();
                         $readableTime = "";
                         if ($epoch != "") {
                             $readableTime = "@" . tao_helpers_Date::displayeDate(tao_helpers_Date::getTimeStamp($epoch), tao_helpers_Date::FORMAT_VERBOSE);
                         }
                         $this->cache[get_class($varData)][$result][$column->getContextIdentifier() . $variableIdentifier][(string) $epoch] = array($varData->getValue(), $readableTime);
                     }
                 }
             }
         }
     }
 }
コード例 #3
0
 /**
  * Short description of method prepare
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  array resources  results
  * @param  array columns    variables
  * @return mixed
  */
 public function prepare($resources, $columns)
 {
     $resultsService = ResultsService::singleton();
     foreach ($resources as $result) {
         $itemresults = $resultsService->getVariables($result, false);
         $cellData = array();
         foreach ($itemresults as $itemResultUri => $vars) {
             //cache the item information pertaining to a given itemResult (stable over time)
             if (common_cache_FileCache::singleton()->has('itemResultItemCache' . tao_helpers_Uri::encode($itemResultUri))) {
                 $itemUri = common_cache_FileCache::singleton()->get('itemResultItemCache' . tao_helpers_Uri::encode($itemResultUri));
                 $object = new core_kernel_classes_Resource($itemUri);
             } else {
                 $object = $resultsService->getItemFromItemResult($itemResultUri);
                 if (is_null($object)) {
                     $object = $resultsService->getVariableFromTest($itemResultUri);
                 }
                 if (!is_null($object)) {
                     common_cache_FileCache::singleton()->put($object->getUri(), 'itemResultItemCache' . tao_helpers_Uri::encode($itemResultUri));
                 }
             }
             if (get_class($object) == "core_kernel_classes_Resource") {
                 $contextIdentifier = (string) $object->getUri();
             } else {
                 if (!is_null($object)) {
                     $contextIdentifier = (string) $object->__toString();
                 }
             }
             foreach ($vars as $var) {
                 $var = $var[0];
                 //cache the variable data
                 $varData = (array) $var->variable;
                 if (common_cache_FileCache::singleton()->has('variableDataCache' . $var->uri . '_' . $varData["identifier"])) {
                     $varData = common_cache_FileCache::singleton()->get('variableDataCache' . $var->uri . '_' . $varData["identifier"]);
                 } else {
                     $varData["class"] = $var->class;
                     common_cache_FileCache::singleton()->put($varData, 'variableDataCache' . $var->uri . '_' . $varData["identifier"]);
                 }
                 $type = $varData["class"];
                 if (isset($varData["value"])) {
                     if (is_array($varData["value"])) {
                         $varData["value"] = json_encode($varData["value"]);
                     }
                 } else {
                     $varData["value"] = $varData["candidateResponse"];
                 }
                 $varData["value"] = base64_decode($varData["value"]);
                 if ($varData["baseType"] === 'file') {
                     $decodedFile = Datatypes::decodeFile($varData['value']);
                     $varData['value'] = $decodedFile['name'];
                 }
                 $variableIdentifier = (string) $varData["identifier"];
                 foreach ($columns as $column) {
                     if ($variableIdentifier == $column->getIdentifier() and $contextIdentifier == $column->getContextIdentifier()) {
                         $value = (string) $varData["value"];
                         $epoch = $varData["epoch"];
                         $readableTime = "";
                         if ($epoch != "") {
                             $readableTime = "@" . tao_helpers_Date::displayeDate(tao_helpers_Date::getTimeStamp($epoch), tao_helpers_Date::FORMAT_VERBOSE);
                         }
                         $this->cache[$type][$result->getUri()][$column->getContextIdentifier() . $variableIdentifier][(string) $epoch] = array($value, $readableTime);
                     }
                 }
             }
         }
     }
 }