Example #1
0
 /**
  * Construct
  *
  * @param null $name
  * @param array $options
  */
 public function __construct($name = null, $options = array())
 {
     parent::__construct($name, $options);
     $this->addElements();
 }
Example #2
0
File: File.php Project: zfury/cmf
 /**
  * Writes file to a DB and moves it to an appropriate path
  *
  * @param FileUpload $form
  * @return FileEntity
  * @throws \Exception
  */
 public function writeFile(FileUpload $form)
 {
     $ext = $this->getExt($form->getData()[$form->getFileType()]['name']);
     $type = $form->getFileType();
     //Creating new image to get ID for building its path
     $file = new FileEntity();
     $file->setExtension($ext);
     $file->setType($type);
     $this->sm->get('doctrine.entitymanager.orm_default')->persist($file);
     $this->sm->get('doctrine.entitymanager.orm_default')->flush();
     //Building path and creating directory. Then - moving
     $destination = null;
     switch ($type) {
         case FileEntity::AUDIO_FILETYPE:
             $destination = Audio::audioPath($file->getId(), $ext);
             break;
         case FileEntity::VIDEO_FILETYPE:
             $destination = Video::videoPath($file->getId(), $ext);
             break;
         case FileEntity::IMAGE_FILETYPE:
             $destination = Image::imgPath(Image::ORIGINAL, $file->getId(), $ext);
             break;
         default:
     }
     $this->prepareDir($destination);
     $this->moveFile($destination, $form->getData()[$type]);
     return $file;
 }