* @author Jérôme Bogaerts, * @package taoItems */ abstract class taoItems_models_classes_ItemCompiler extends tao_models_classes_Compiler { /** * Get the languages in use for the item content. * * @return array An array of language tags (string). */ protected function getContentUsedLanguages() { return $this->getResource()->getUsedLanguages(new core_kernel_classes_Property(taoItems_models_classes_ItemsService::PROPERTY_ITEM_CONTENT)); } /** * deploys the item into the given absolute directory * * @param core_kernel_classes_Resource $item * @param string $languageCode * @param string $compiledDirectory * @return common_report_Report */ protected function deployItem(core_kernel_classes_Resource $item, $languageCode, $compiledDirectory) { $itemService = taoItems_models_classes_ItemsService::singleton(); // copy local files $sourceDir = $itemService->getItemDirectory($item, $languageCode); $success = taoItems_helpers_Deployment::copyResources($sourceDir->getPrefix(), $compiledDirectory, ['index.html']); if (!$success) { return $this->fail(__('Unable to copy resources for language %s', $languageCode)); } // render item $xhtml = $itemService->render($item, $languageCode); // retrieve external resources $subReport = taoItems_helpers_Deployment::retrieveExternalResources($xhtml, $compiledDirectory); if ($subReport->getType() == common_report_Report::TYPE_SUCCESS) { $xhtml = $subReport->getData(); // write index.html file_put_contents($compiledDirectory . 'index.html', $xhtml); return new common_report_Report( common_report_Report::TYPE_SUCCESS, __('Published "%1$s" in language "%2$s"', $item->getLabel(), $languageCode) ); } else { return $subReport; } } /** * Create the item's ServiceCall. * * @param core_kernel_classes_Resource $item * @param tao_models_classes_service_StorageDirectory $destinationDirectory * @return tao_models_classes_service_ServiceCall */ protected function createService(core_kernel_classes_Resource $item, tao_models_classes_service_StorageDirectory $destinationDirectory) { $service = new tao_models_classes_service_ServiceCall(new core_kernel_classes_Resource(taoItems_models_classes_ItemsService::INSTANCE_SERVICE_ITEM_RUNNER)); $service->addInParameter(new tao_models_classes_service_ConstantParameter( new core_kernel_classes_Resource(taoItems_models_classes_ItemsService::INSTANCE_FORMAL_PARAM_ITEM_PATH), $destinationDirectory->getId() )); $service->addInParameter(new tao_models_classes_service_ConstantParameter( new core_kernel_classes_Resource(taoItems_models_classes_ItemsService::INSTANCE_FORMAL_PARAM_ITEM_URI), $item )); return $service; } protected function getSubCompilerClass(core_kernel_classes_Resource $resource) { throw new common_Exception('Items cannot include other resources'); } }