files = array(); $this->mainFile = ""; $this->version = 0; } /** * @ORM\PreRemove */ public function remove(){ $this->deleteFileInArray($this->files); } /** * delete all file from path in an array recursively * * @param $array */ protected function deleteFileInArray($array){ foreach($array as $file){ if(is_array($file)) $this->deleteFileInArray($file); else{ if(is_file((string)$file)){ @unlink($file); } else if(is_file($this->thumbContainer.(string)$file)) @unlink($this->thumbContainer.(string)$file); } } } /** * Get id * * @return int */ public function getId() { return $this->id; } /** * Set files * * @param array $files * * @return FilePreview */ public function setFiles(array $files) { $this->files = $files; return $this; } /** * @param $key * @param $arrayInner * @return $this */ public function addFile(int $key, $arrayInner){ if(!is_array($arrayInner)) return $this; $this->files[$key] = $arrayInner; return $this; } /** * @param $key * @param $name * @param $path * @return $this */ public function addInFile(int $key, $name, $path){ if(!isset($this->files[$key])) $this->files[$key] = array(); $this->files[$key][$name] = $path; return $this; } /** * @param $key * @return $this */ public function removeKeyFile(int $key){ if(isset($this->files[$key])) unset($this->files[$key]); return $this; } /** * @param $key * @param $name * @return $this */ public function removeInFile(int $key, $name){ if(isset($this->files[$key][$name])) unset($this->files[$key][$name]); return $this; } /** * @return bool|array */ public function getActualFileArray(){ if(isset($this->selected)) if(isset($this->files[(int)$this->selected])) return $this->files[(int)$this->selected]; return false; } /** * same as getActualFileArray but without filename in it * * @return array|bool */ public function getActualFileSecureArray(){ if(isset($this->selected)){ if(isset($this->files[(int)$this->selected])){ $cpy = array(); foreach ($this->files[(int)$this->selected] as $key=>$val){ $cpy[] = $key; } return $cpy; } } return false; } /** * @param $key * @return bool */ public function getKeyInActualFileArray($key){ if(isset($this->selected)){ if(isset($this->files[(int)$this->selected])){ if(isset($this->files[(int)$this->selected][$key])) return $this->files[(int)$this->selected][$key]; else { foreach($this->files[(int)$this->selected] as $val){ return $val; } } } } return false; } /** * @return int */ public function createNewKey(){ $this->files[] = array(); return (int)max(array_keys($this->files)); } /** * Get files * * @return array */ public function getFiles() { return $this->files; } /** * Set selected * * @param integer $selected * * @return FilePreview */ public function setSelected($selected) { $this->selected = $selected; return $this; } /** * Get selected * * @return int */ public function getSelected() { return $this->selected; } /** * @param string $mainFile * @return FilePreview */ public function setMainFile(string $mainFile): FilePreview { $this->mainFile = $mainFile; return $this; } /** * @return string */ public function getMainFile() { return $this->mainFile; } /** * @param string $mainMime * @return FilePreview */ public function setMainMime(string $mainMime): FilePreview { $this->mainMime = $mainMime; return $this; } /** * @return string */ public function getMainMime() { return $this->mainMime; } /** * @return string */ public function getThumbContainer(): string { return $this->thumbContainer; } /** * @param string $thumbContainer * @return $this */ public function setThumbContainer(string $thumbContainer) { $this->thumbContainer = $thumbContainer; return $this; } public function getVersion(): ?int { return $this->version; } public function setVersion(int $version): self { $this->version = $version; return $this; } }