protected function createFileList($entities, PropertyMapping $propertyMapping)
 {
     $array = array();
     foreach ($entities as $entity) {
         $array[] = array('uuid' => uniqid(), 'name' => $this->get('vichimagine.file')->fileName($entity, $propertyMapping->getMappingName()), 'thumbnailUrl' => $this->get('vichimagine.file')->asset($entity, $propertyMapping->getMappingName()));
     }
     return $array;
 }
Beispiel #2
0
 public function upload(UploadedFile $file, PropertyMapping $propertyMapping, $filter_name = NULL)
 {
     if ($filter_name === NULL) {
         $filter_name = $propertyMapping->getMappingName();
     }
     // vars
     $provider = $this->getProvider($propertyMapping);
     $filesystem = $provider->getFilesystem();
     $relative_dir = $provider->getRelativeDir();
     //$propertyMapping->getUriPrefix();
     $file_name = $file->getClientOriginalName();
     // if namer set
     $mapping_config = $this->vichGetMappingConfig($propertyMapping->getMappingName());
     if ($mapping_config) {
         $namer = $mapping_config['namer'];
         // illegal offset warning (backwards compatibility)
         if (is_array($namer) && isset($namer['service'])) {
             $namer = $namer['service'];
         }
         if ($this->getContainer()->has($namer)) {
             $namer = $this->getContainer()->get($namer);
             if (method_exists($namer, 'getRandomFileName')) {
                 $file_name = $namer->getRandomFileName($file_name, $propertyMapping);
             }
         }
     }
     // upload
     $uploaded = $filesystem->write($relative_dir . '/' . $file_name, file_get_contents($file->getPathname()));
     //$uploaded = $file->move($upload_dir, $file_name);
     if ($uploaded) {
         // apply filter
         return $this->doApplyFilter($file_name, $propertyMapping);
     }
     return false;
 }
Beispiel #3
0
 /**
  * {@inheritDoc}
  */
 public function injectFile($obj, PropertyMapping $mapping)
 {
     $path = $this->storage->resolvePath($obj, $mapping->getMappingName());
     if ($path !== null) {
         $mapping->setFile($obj, new File($path, false));
     }
 }