示例#1
0
 public function __invoke(\Application\Entity\Person $person, \Admin\Service\FileService $fileService, $imgClass = 'img-circle img-thumbnail img-sm')
 {
     if ($person->getFile()) {
         if (!file_exists('public/' . $person->parseFilePath())) {
             $file = $person->getFile();
             $data = $file->getData();
             $fileService->resizeImage(stream_get_contents($data), 200, 200, 'public/' . $person->parseFilePath());
         }
         return "<img class='" . $imgClass . "' src='" . $person->parseFilePath() . "' />";
     } else {
         $gender = $person->getGender()->getName();
         return '<i class="fa fa-' . strtolower($gender) . ' fa-4x"></i>';
     }
 }
示例#2
0
 public function addFileToPerson(Person $person, $postFile = [])
 {
     $em = $this->getEntityManager();
     $parts = explode('/', $postFile['type']);
     $public = 'public/';
     $link = 'cache/' . $person->getPersonId() . '.' . end($parts);
     $path = $public . $link;
     $data = file_get_contents($postFile['tmp_name']);
     $resized = $this->resizeImage($data, 300, 300, $path);
     $file = $person->getFile() ?: new File();
     $file->setData($resized)->setMimetype($postFile['type']);
     $em->persist($file);
     $person->setFile($file);
     $em->persist($person);
     $em->flush();
 }