private function exists($subject, $property, $object, $lg)
 {
     $subject = new core_kernel_classes_Resource($subject->getUri());
     $values = $subject->getPropertyValuesByLg($property, $lg);
     $found = false;
     foreach ($values as $value) {
         $raw = (string) ($value instanceof core_kernel_classes_Resource ? $value->getUri() : $value);
         if ($raw == $object) {
             $found = true;
             break;
         }
     }
     return $found;
 }
 /**
  * Short description of method getItemFolder
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  Resource item
  * @param  string lang
  * @return string
  */
 public function getItemFolder(core_kernel_classes_Resource $item, $lang = '')
 {
     $returnValue = (string) '';
     if ($lang === '') {
         $files = $item->getPropertyValues(new core_kernel_classes_Property(TAO_ITEM_CONTENT_PROPERTY));
     } else {
         $files = $item->getPropertyValuesByLg(new core_kernel_classes_Property(TAO_ITEM_CONTENT_PROPERTY), $lang)->toArray();
     }
     if (count($files) == 0) {
         // no content found assign default
         $returnValue = $this->getDefaultItemFolder($item, $lang);
     } else {
         if (count($files) > 1) {
             throw new common_Exception(__METHOD__ . ': Item ' . $item->getUri() . ' has multiple.');
         }
         $content = new core_kernel_file_File(current($files));
         $returnValue = dirname($content->getAbsolutePath()) . DIRECTORY_SEPARATOR;
     }
     return (string) $returnValue;
 }
Ejemplo n.º 3
0
 /**
  * get the properties of an instance for a specific language
  *
  * @access public
  * @author Jerome Bogaerts, <*****@*****.**>
  * @param  Resource instance
  * @param  string lang
  * @return array
  */
 public function getTranslatedProperties(core_kernel_classes_Resource $instance, $lang)
 {
     $returnValue = array();
     try {
         foreach ($instance->getTypes() as $clazz) {
             foreach ($clazz->getProperties(true) as $property) {
                 if ($property->isLgDependent() || $property->getUri() == RDFS_LABEL) {
                     $collection = $instance->getPropertyValuesByLg($property, $lang);
                     if ($collection->count() > 0) {
                         if ($collection->count() == 1) {
                             $returnValue[$property->getUri()] = (string) $collection->get(0);
                         } else {
                             $propData = array();
                             foreach ($collection->getIterator() as $collectionItem) {
                                 $propData[] = (string) $collectionItem;
                             }
                             $returnValue[$property->getUri()] = $propData;
                         }
                     }
                 }
             }
         }
     } catch (Exception $e) {
         print $e;
     }
     return (array) $returnValue;
 }
 /**
  * Returns the items flysystem directory
  *
  * @param core_kernel_classes_Resource $item
  * @param string $language
  * @return \oat\oatbox\filesystem\Directory
  * @throws Exception
  * @throws common_Exception
  * @throws core_kernel_persistence_Exception
  */
 public function getItemDirectory(core_kernel_classes_Resource $item, $language = '')
 {
     // Get file by language
     if ($language === '') {
         $files = $item->getPropertyValues($this->itemContentProperty);
     } else {
         $files = $item->getPropertyValuesByLg($this->itemContentProperty, $language)->toArray();
     }
     // If multiple files then throw exception
     if (count($files) > 1) {
         common_Logger::i(print_r($files, true));
         throw new common_Exception(__METHOD__ . ': Item ' . $item->getUri() . ' has multiple.');
     }
     // If there is one file then return directory
     if (count($files) == 1) {
         $file = reset($files);
         $file = is_object($file) && $file instanceof core_kernel_classes_Resource ? $file->getUri() : (string) $file;
         return $this->getFileReferenceSerializer()->unserializeDirectory($file);
     }
     // Otherwise there is no file, create one and return directory
     $model = $this->getItemModel($item);
     if (is_null($model)) {
         throw new common_Exception('Call to ' . __FUNCTION__ . ' for item without model');
     }
     // File does not exist, let's create it
     $actualLang = empty($language) ? $this->getSessionLg() : $language;
     $filePath = tao_helpers_Uri::getUniqueId($item->getUri()) . DIRECTORY_SEPARATOR . 'itemContent' . DIRECTORY_SEPARATOR . $actualLang;
     // Create item directory
     $itemDirectory = $this->getDefaultItemDirectory()->getDirectory($filePath);
     // Set uri file value as serial to item persistence
     $serial = $this->getFileReferenceSerializer()->serialize($itemDirectory);
     $item->setPropertyValueByLg($this->itemContentProperty, $serial, $actualLang);
     // Store file into persistence, purpose of serializer ?
     $dataFile = (string) $model->getOnePropertyValue($this->getProperty(TAO_ITEM_MODEL_DATAFILE_PROPERTY));
     $this->getFileReferenceSerializer()->serialize($itemDirectory->getFile($dataFile));
     return $itemDirectory;
 }