public function testIsFile() { $clazz = new core_kernel_classes_Class(CLASS_GENERIS_FILE); $instance = $clazz->createInstance('toto.txt', 'toto'); $fileNameProp = new core_kernel_classes_Property(PROPERTY_FILE_FILENAME); $instance->setPropertyValue($fileNameProp, 'file://toto.txt'); $this->assertTrue(core_kernel_file_File::isFile($instance)); $this->assertFalse(core_kernel_file_File::isFile($clazz)); $instance->delete(); }
public function getPropertyFileInfo() { $data = array('name' => __('(empty)')); if ($this->hasRequestParameter('uri') && $this->hasRequestParameter('propertyUri')) { $uri = tao_helpers_Uri::decode($this->getRequestParameter('uri')); $propertyUri = tao_helpers_Uri::decode($this->getRequestParameter('propertyUri')); $instance = new core_kernel_classes_Resource($uri); $file = $instance->getOnePropertyValue(new core_kernel_classes_Property($propertyUri)); if (!is_null($file) && $file instanceof core_kernel_classes_Resource && core_kernel_file_File::isFile($file)) { $data = $this->getFileInfo($file->getUri()); } } echo json_encode($data); }
/** * Short description of method setItemContent * * @access public * @author Joel Bout, <*****@*****.**> * @param Resource item * @param string content * @param string lang * @param string commitMessage * @return boolean */ public function setItemContent(core_kernel_classes_Resource $item, $content, $lang = '', $commitMessage = '') { $returnValue = (bool) false; if (is_null($item) && !$this->isItemModelDefined($item)) { throw new common_exception_Error('No item or itemmodel in ' . __FUNCTION__); } $lang = empty($lang) ? $lang = $this->getSessionLg() : $lang; $itemModel = $item->getUniquePropertyValue($this->itemModelProperty); $dataFile = (string) $itemModel->getOnePropertyValue(new core_kernel_classes_Property(TAO_ITEM_MODEL_DATAFILE_PROPERTY)); if ($this->hasItemContent($item, $lang)) { $itemContents = $item->getPropertyValuesByLg($this->itemContentProperty, $lang); $itemContent = $itemContents->get(0); if (!core_kernel_file_File::isFile($itemContent)) { throw new common_Exception('Item ' . $item->getUri() . ' has none file itemContent'); } $file = new core_kernel_versioning_File($itemContent); $returnValue = $file->setContent($content); } else { $repository = $this->getDefaultFileSource(); $file = $repository->createFile($dataFile, tao_helpers_Uri::getUniqueId($item->getUri()) . DIRECTORY_SEPARATOR . 'itemContent' . DIRECTORY_SEPARATOR . $lang); $item->setPropertyValueByLg($this->itemContentProperty, $file->getUri(), $lang); $file->setContent($content); $returnValue = $file->add(true, true); } if ($commitMessage != 'HOLD_COMMIT') { //hack to control commit or not $returnValue = $file->commit($commitMessage); } return (bool) $returnValue; }