当前位置: 首页>>代码示例>>PHP>>正文


PHP tao_helpers_File类代码示例

本文整理汇总了PHP中tao_helpers_File的典型用法代码示例。如果您正苦于以下问题:PHP tao_helpers_File类的具体用法?PHP tao_helpers_File怎么用?PHP tao_helpers_File使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了tao_helpers_File类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: export

 /**
  * (non-PHPdoc)
  * @see tao_models_classes_export_ExportHandler::export()
  */
 public function export($formValues, $destination)
 {
     $file = null;
     if (isset($formValues['filename']) === true) {
         $instances = is_string($formValues['instances']) ? array($formValues['instances']) : $formValues['instances'];
         if (count($instances) > 0) {
             $fileName = $formValues['filename'] . '_' . time() . '.zip';
             $path = tao_helpers_File::concat(array($destination, $fileName));
             if (tao_helpers_File::securityCheck($path, true) === false) {
                 throw new common_Exception('Unauthorized file name for QTI Test ZIP archive.');
             }
             // Create a new ZIP archive to store data related to the QTI Test.
             $zip = new ZipArchive();
             if ($zip->open($path, ZipArchive::CREATE) !== true) {
                 throw new common_Exception("Unable to create ZIP archive for QTI Test at location '" . $path . "'.");
             }
             // Create an empty IMS Manifest as a basis.
             $manifest = taoQtiTest_helpers_Utils::emptyImsManifest();
             foreach ($instances as $instance) {
                 $testResource = new core_kernel_classes_Resource($instance);
                 $testExporter = new taoQtiTest_models_classes_export_QtiTestExporter($testResource, $zip, $manifest);
                 common_Logger::d('Export ' . $instance);
                 $testExporter->export();
             }
             $file = $path;
             $zip->close();
         } else {
             common_Logger::w("No instance in form to export");
         }
     } else {
         common_Logger::w("Missing filename for QTI Test export using Export Handler '" . __CLASS__ . "'.");
     }
     return $file;
 }
开发者ID:nagyist,项目名称:extension-tao-testqti,代码行数:38,代码来源:class.TestExport.php

示例2: import

 /**
  * Import file entry point by using $this->service
  * Check POST method & get valid uploaded file
  */
 public function import()
 {
     $fileUploadName = "qtiPackage";
     if ($this->getRequestMethod() != Request::HTTP_POST) {
         throw new \common_exception_NotImplemented('Only post method is accepted to import Qti package.');
     }
     if (tao_helpers_Http::hasUploadedFile($fileUploadName)) {
         $file = tao_helpers_Http::getUploadedFile($fileUploadName);
         $mimeType = tao_helpers_File::getMimeType($file['tmp_name']);
         if (!in_array($mimeType, self::$accepted_types)) {
             $this->returnFailure(new common_exception_BadRequest());
         } else {
             $report = $this->service->importQtiTest($file['tmp_name']);
             if ($report->getType() === common_report_Report::TYPE_SUCCESS) {
                 $data = array();
                 foreach ($report as $r) {
                     $values = $r->getData();
                     $testid = $values->rdfsResource->getUri();
                     foreach ($values->items as $item) {
                         $itemsid[] = $item->getUri();
                     }
                     $data[] = array('testId' => $testid, 'testItems' => $itemsid);
                 }
                 return $this->returnSuccess($data);
             } else {
                 return $this->returnFailure(new common_exception_InconsistentData($report->getMessage()));
             }
         }
     } else {
         return $this->returnFailure(new common_exception_BadRequest());
     }
 }
开发者ID:oat-sa,项目名称:extension-tao-testqti,代码行数:36,代码来源:class.RestQtiTests.php

示例3: outputFile

 public static function outputFile($relPath, $filename = null)
 {
     $fullpath = self::getExportPath() . DIRECTORY_SEPARATOR . $relPath;
     if (tao_helpers_File::securityCheck($fullpath, true) && file_exists($fullpath)) {
         Context::getInstance()->getResponse()->setContentHeader(tao_helpers_File::getMimeType($fullpath));
         $fileName = empty($filename) ? basename($fullpath) : $filename;
         header('Content-Disposition: attachment; fileName="' . $fileName . '"');
         header("Content-Length: " . filesize($fullpath));
         //Clean all levels of output buffering
         while (ob_get_level() > 0) {
             ob_end_clean();
         }
         flush();
         $fp = fopen($fullpath, "r");
         if ($fp !== false) {
             while (!feof($fp)) {
                 echo fread($fp, 65536);
                 flush();
             }
             fclose($fp);
             @unlink($fullpath);
         } else {
             common_Logger::e('Unable to open File to export' . $fullpath);
         }
     } else {
         common_Logger::e('Could not find File to export: ' . $fullpath);
     }
 }
开发者ID:nagyist,项目名称:tao-core,代码行数:28,代码来源:class.Export.php

示例4: import

 /**
  * (non-PHPdoc)
  * @see tao_models_classes_import_ImportHandler::import()
  */
 public function import($class, $form)
 {
     $fileInfo = $form->getValue('source');
     //import for CSV
     if (isset($fileInfo)) {
         set_time_limit(200);
         //the zip extraction is a long process that can exced the 30s timeout
         //get the services instances we will need
         $itemService = taoItems_models_classes_ItemsService::singleton();
         $uploadedFile = $fileInfo['uploaded_file'];
         $uploadedFileBaseName = basename($uploadedFile);
         // uploaded file name contains an extra prefix that we have to remove.
         $uploadedFileBaseName = preg_replace('/^([0-9a-z])+_/', '', $uploadedFileBaseName, 1);
         $uploadedFileBaseName = preg_replace('/.zip|.ZIP$/', '', $uploadedFileBaseName);
         $validate = count($form->getValue('disable_validation')) == 0 ? true : false;
         try {
             $report = taoDelivery_models_classes_import_Assembler::importDelivery($class, $uploadedFile);
         } catch (common_Exception $e) {
             $report = common_report_Report::createFailure(__('An error occured during the import'));
             if ($e instanceof common_exception_UserReadableException) {
                 $report->add($e);
             }
         }
         tao_helpers_File::remove($uploadedFile);
     } else {
         throw new common_exception_Error('No file provided as parameter \'source\' for OWI import');
     }
     return $report;
 }
开发者ID:swapnilaptara,项目名称:tao-aptara-assess,代码行数:33,代码来源:class.AssemblyImportHandler.php

示例5: generate

 /**
  * Generate a new Booklet from a specific test
  * in a specific class and return a report
  * 
  * @param core_kernel_classes_Resource $test
  * @param core_kernel_classes_Class $class
  * @return common_report_Report
  */
 public static function generate(core_kernel_classes_Resource $test, core_kernel_classes_Class $class)
 {
     $report = new common_report_Report(common_report_Report::TYPE_SUCCESS);
     $model = \taoTests_models_classes_TestsService::singleton()->getTestModel($test);
     if ($model->getUri() != INSTANCE_TEST_MODEL_QTI) {
         $report->setType(common_report_Report::TYPE_ERROR);
         $report->setMessage(__('%s is not a QTI test', $test->getLabel()));
         return $report;
     }
     // generate file content
     $tmpFolder = \tao_helpers_File::createTempDir();
     $tmpFile = $tmpFolder . 'test.txt';
     $content = '';
     foreach (self::getItems($test) as $item) {
         $content .= self::renderItem($item);
     }
     file_put_contents($tmpFile, $content);
     // generate tao instance
     $instance = BookletClassService::singleton()->createBookletInstance($class, __('%s Booklet', $test->getLabel()), $tmpFile);
     \tao_helpers_File::delTree($tmpFolder);
     // return report with instance
     $report->setMessage(__('%s created', $instance->getLabel()));
     $report->setData($instance);
     return $report;
 }
开发者ID:nagyist,项目名称:extension-tao-booklet,代码行数:33,代码来源:BookletRenderer.php

示例6: testDeepCloneTriplesFile

 public function testDeepCloneTriplesFile()
 {
     /** @var \core_kernel_versioning_Repository $repository */
     $repository = \tao_models_classes_FileSourceService::singleton()->addLocalSource("repository test", \tao_helpers_File::createTempDir());
     //see if clone item content works
     /** @var \core_kernel_versioning_File $file */
     $file = $repository->spawnFile(__DIR__ . '/sample/test.xml', "test", function ($originalName) {
         return md5($originalName);
     });
     //see if clone file works
     $rdfsTriple = new \core_kernel_classes_Triple();
     $rdfsTriple->predicate = "http://www.w3.org/1999/02/22-rdf-syntax-ns#value";
     $rdfsTriple->object = $file->getUri();
     $return = CloneHelper::deepCloneTriples(array($rdfsTriple));
     $this->assertCount(1, $return);
     $this->assertEquals($rdfsTriple->predicate, $return[0]->predicate);
     $this->assertNotEquals($rdfsTriple->object, $return[0]->object);
     $fileCopy = new \core_kernel_file_File($return[0]->object);
     $this->assertFileExists($fileCopy->getAbsolutePath());
     $this->assertEquals($file->getLabel(), $fileCopy->getLabel());
     $this->assertNotEquals($file->getAbsolutePath(), $fileCopy->getAbsolutePath());
     $file->delete(true);
     $fileCopy->delete(true);
     $repository->delete(true);
 }
开发者ID:kendaop,项目名称:extension-tao-revision,代码行数:25,代码来源:CloneHelperTest.php

示例7: retrieveFile

 /**
  * get the link and return the file that match it
  * @param string $link the link provided by storeFile
  * @return string $filename the file that match the link
  * @throws \common_exception_Error
  */
 public function retrieveFile($link)
 {
     if (!\tao_helpers_File::securityCheck($link)) {
         throw new \common_exception_Error('Unsecure file link found');
     }
     return $this->getBaseDir() . $link;
 }
开发者ID:oat-sa,项目名称:extension-tao-mediamanager,代码行数:13,代码来源:SimpleFileManagement.php

示例8: getRubrics

 /**
  * Gets the rubrics according to the current session state
  * The content is directly rendered into the page
  * @param RunnerServiceContext $context
  * @return mixed
  */
 public function getRubrics(RunnerServiceContext $context)
 {
     // TODO: make a better implementation for rubrics loading.
     /* @var AssessmentTestSession $session */
     $session = $context->getTestSession();
     $compilationDirs = $context->getCompilationDirectory();
     // -- variables used in the included rubric block templates.
     // base path (base URI to be used for resource inclusion).
     $basePathVarName = TAOQTITEST_BASE_PATH_NAME;
     ${$basePathVarName} = $compilationDirs['public']->getPublicAccessUrl();
     // state name (the variable to access to get the state of the assessmentTestSession).
     $stateName = TAOQTITEST_RENDERING_STATE_NAME;
     ${$stateName} = $session;
     // views name (the variable to be accessed for the visibility of rubric blocks).
     $viewsName = TAOQTITEST_VIEWS_NAME;
     ${$viewsName} = array(View::CANDIDATE);
     ob_start();
     foreach ($session->getRoute()->current()->getRubricBlockRefs() as $rubric) {
         $data = $compilationDirs['private']->read($rubric->getHref());
         $tmpFile = \tao_helpers_File::createTempDir() . basename($rubric->getHref());
         file_put_contents($tmpFile, $data);
         include $tmpFile;
         unlink($tmpFile);
     }
     $rubrics = ob_get_contents();
     ob_end_clean();
     return $rubrics;
 }
开发者ID:oat-sa,项目名称:extension-tao-testqti,代码行数:34,代码来源:QtiRunnerRubric.php

示例9: download

 /**
  * (non-PHPdoc)
  * @see \oat\tao\model\media\MediaBrowser::download()
  */
 public function download($link)
 {
     $url = str_replace('\\/', '/', $link);
     $fileName = \tao_helpers_File::createTempDir() . basename($link);
     common_Logger::d('Downloading ' . $url);
     helpers_TimeOutHelper::setTimeOutLimit(helpers_TimeOutHelper::NO_TIMEOUT);
     $fp = fopen($fileName, 'w+');
     $curlHandler = curl_init();
     curl_setopt($curlHandler, CURLOPT_URL, $url);
     curl_setopt($curlHandler, CURLOPT_FILE, $fp);
     curl_setopt($curlHandler, CURLOPT_TIMEOUT, 50);
     curl_setopt($curlHandler, CURLOPT_FOLLOWLOCATION, true);
     //if there is an http auth on the local domain, it's mandatory to auth with curl
     if (USE_HTTP_AUTH) {
         $addAuth = false;
         $domains = array('localhost', '127.0.0.1', ROOT_URL);
         foreach ($domains as $domain) {
             if (preg_match("/" . preg_quote($domain, '/') . "/", $url)) {
                 $addAuth = true;
             }
         }
         if ($addAuth) {
             curl_setopt($curlHandler, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
             curl_setopt($curlHandler, CURLOPT_USERPWD, USE_HTTP_USER . ":" . USE_HTTP_PASS);
         }
     }
     curl_exec($curlHandler);
     $httpCode = curl_getinfo($curlHandler, CURLINFO_HTTP_CODE);
     $success = $httpCode == 200;
     curl_close($curlHandler);
     fclose($fp);
     helpers_TimeOutHelper::reset();
     return $fileName;
 }
开发者ID:nagyist,项目名称:tao-core,代码行数:38,代码来源:HttpSource.php

示例10: import

 /**
  * (non-PHPdoc)
  * @see tao_models_classes_import_ImportHandler::import()
  */
 public function import($class, $form)
 {
     $fileInfo = $form->getValue('source');
     //import for CSV
     if (isset($fileInfo)) {
         \helpers_TimeOutHelper::setTimeOutLimit(\helpers_TimeOutHelper::MEDIUM);
         //get the services instances we will need
         $itemService = \taoItems_models_classes_ItemsService::singleton();
         $uploadedFile = $fileInfo['uploaded_file'];
         $uploadedFileBaseName = basename($uploadedFile);
         // uploaded file name contains an extra prefix that we have to remove.
         $uploadedFileBaseName = preg_replace('/^([0-9a-z])+_/', '', $uploadedFileBaseName, 1);
         $uploadedFileBaseName = preg_replace('/.zip|.ZIP$/', '', $uploadedFileBaseName);
         $validate = count($form->getValue('disable_validation')) == 0 ? true : false;
         try {
             $importer = new Assembler();
             $report = $importer->importDelivery($class, $uploadedFile);
         } catch (\common_Exception $e) {
             $report = common_report_Report::createFailure(__('An error occured during the import'));
             if ($e instanceof \common_exception_UserReadableException) {
                 $report->add($e);
             }
         }
         \tao_helpers_File::remove($uploadedFile);
         \helpers_TimeOutHelper::reset();
     } else {
         throw new \common_exception_Error('No file provided as parameter \'source\' for Delivery Assembly import');
     }
     return $report;
 }
开发者ID:oat-sa,项目名称:extension-tao-delivery-rdf,代码行数:34,代码来源:AssemblyImportHandler.php

示例11: getAsset

 public function getAsset()
 {
     $item = new \core_kernel_classes_Resource($this->getRequestParameter('id'));
     $assetPath = $this->getRequestParameter('asset');
     $mimeType = \tao_helpers_File::getMimeType($assetPath, true);
     header('Content-Type: ' . $mimeType);
     $loader = new Loader($item);
     $content = $loader->getAssetContent($assetPath);
     echo $content;
 }
开发者ID:oat-sa,项目名称:extension-tao-devtools,代码行数:10,代码来源:ItemTools.php

示例12: buildFile

 public static function buildFile(core_kernel_classes_Resource $test, $lang, $relPath, $filters = array())
 {
     $file = null;
     $baseDir = self::getBaseDir($test);
     $path = $baseDir . ltrim($relPath, '/');
     $mime = tao_helpers_File::getMimeType($path);
     if (count($filters) == 0 || in_array($mime, $filters)) {
         $file = array('name' => basename($path), 'mime' => $mime, 'size' => filesize($path), 'url' => _url('download', 'TestContent', 'taoQtiTest', array('uri' => $test->getUri(), 'lang' => $lang, 'path' => $relPath)));
     }
     return $file;
 }
开发者ID:nagyist,项目名称:extension-tao-testqti,代码行数:11,代码来源:class.ResourceManager.php

示例13: getFilePath

 /**
  * Get file path to save message
  * @param User $receiver
  * @param boolean $refresh whether the file path must be regenerated.
  */
 public function getFilePath(User $receiver)
 {
     $basePath = $this->getOption(self::CONFIG_FILEPATH);
     if (is_null($basePath) || !file_exists($basePath)) {
         throw new \common_exception_InconsistentData('Missing path ' . self::CONFIG_FILEPATH . ' for ' . __CLASS__);
     }
     $path = $basePath . \tao_helpers_File::getSafeFileName($receiver->getIdentifier()) . DIRECTORY_SEPARATOR;
     if (!file_exists($path)) {
         mkdir($path);
     }
     return $path . \tao_helpers_File::getSafeFileName('message.html', $path);
 }
开发者ID:nagyist,项目名称:tao-core,代码行数:17,代码来源:FileSink.php

示例14: send

 public function send(Message $message)
 {
     $receiver = $message->getTo();
     $path = $this->getOption(self::CONFIG_FILEPATH) . \tao_helpers_File::getSafeFileName($receiver->getIdentifier()) . DIRECTORY_SEPARATOR;
     if (!file_exists($path)) {
         mkdir($path);
     }
     $messageFile = $path . \tao_helpers_File::getSafeFileName('message.html', $path);
     \common_Logger::d($messageFile);
     $written = file_put_contents($messageFile, $message->getBody());
     return $written !== false;
 }
开发者ID:swapnilaptara,项目名称:tao-aptara-assess,代码行数:12,代码来源:FileSink.php

示例15: testStoreData

 public function testStoreData()
 {
     $store = new DataStorage($this->sentData);
     $this->sampleFilePath = \tao_helpers_File::createTempDir() . 'stored.csv';
     $ref = new \ReflectionProperty('oat\\taoClientDiagnostic\\model\\DataStorage', 'filePath');
     $ref->setAccessible(true);
     $ref->setValue($store, $this->sampleFilePath);
     $store->setIsCompatible(true)->storeData();
     $this->assertFileExists($this->sampleFilePath);
     $row = 0;
     if (($handle = fopen($this->sampleFilePath, "r")) !== FALSE) {
         while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {
             $num = count($data);
             $row++;
             $this->assertEquals(24, $num);
             if ($row === 2) {
                 $this->assertEquals($this->sentData['key'], $data[0]);
                 $this->assertEquals($this->sentData['login'], $data[1]);
                 $this->assertEquals($this->sentData['ip'], $data[2]);
                 $this->assertEquals($this->sentData['browser'], $data[3]);
                 $this->assertEquals($this->sentData['browserVersion'], $data[4]);
                 $this->assertEquals($this->sentData['os'], $data[5]);
                 $this->assertEquals($this->sentData['osVersion'], $data[6]);
                 $this->assertEquals(1, $data[23]);
             }
         }
         fclose($handle);
         $this->assertEquals(2, $row);
     }
     $store->setIsCompatible(false)->storeData();
     $row = 0;
     if (($handle = fopen($this->sampleFilePath, "r")) !== FALSE) {
         while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {
             $num = count($data);
             $row++;
             $this->assertEquals(24, $num);
             if ($row === 2) {
                 $this->assertEquals($this->sentData['key'], $data[0]);
                 $this->assertEquals($this->sentData['login'], $data[1]);
                 $this->assertEquals($this->sentData['ip'], $data[2]);
                 $this->assertEquals($this->sentData['browser'], $data[3]);
                 $this->assertEquals($this->sentData['browserVersion'], $data[4]);
                 $this->assertEquals($this->sentData['os'], $data[5]);
                 $this->assertEquals($this->sentData['osVersion'], $data[6]);
                 $this->assertEquals(0, $data[23]);
             }
         }
         fclose($handle);
         $this->assertEquals(2, $row);
     }
     return $store;
 }
开发者ID:nagyist,项目名称:extension-tao-clientdiag,代码行数:52,代码来源:DataStoringTest.php


注:本文中的tao_helpers_File类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。