예제 #1
0
파일: Upload.php 프로젝트: Junyue/zidisha2
 public static function createFromFile(UploadedFile $file)
 {
     $upload = new Upload();
     $extension = $file->getClientOriginalExtension();
     $mimeType = $file->getMimeType();
     $fileType = in_array($extension, static::$image_types) ? 'image' : 'document';
     $upload->setExtension($extension);
     $upload->setType($fileType);
     $upload->setMimeType($mimeType);
     $upload->file = $file;
     return $upload;
 }
예제 #2
0
 public function updateLendingGroup(LendingGroup $group, $data, $image)
 {
     $leader = UserQuery::create()->findOneById($data['userId']);
     $group->setName($data['name'])->setAbout($data['about'])->setWebsite($data['website'] ? $data['website'] : null)->setLeader($leader->getLender());
     if ($image) {
         $user = $group->getCreator()->getUser();
         $upload = Upload::createFromFile($image);
         $upload->setUser($user);
         $group->setGroupProfilePicture($upload);
     }
     $group->save();
 }
예제 #3
0
 public function editComment($data, User $user, Comment $comment, $files = [])
 {
     $comment->setMessage($data['message']);
     $comment->save();
     if ($files) {
         foreach ($files as $file) {
             $upload = Upload::createFromFile($file);
             $upload->setUser($user);
             $comment->addUpload($upload);
         }
         $comment->save();
     }
 }
예제 #4
0
 public function editBorrower(Borrower $borrower, $data, $files = [])
 {
     $borrower->getUser()->setEmail($data['email']);
     $borrower->getProfile()->setAboutMe($data['aboutMe']);
     $borrower->getProfile()->setAboutBusiness($data['aboutBusiness']);
     if (!empty($data['password'])) {
         $borrower->getUser()->setPassword($data['password']);
     }
     if (\Input::hasFile('picture')) {
         $image = \Input::file('picture');
         $user = $borrower->getUser();
         if ($image) {
             $upload = Upload::createFromFile($image);
             $upload->setUser($user);
             $user->setProfilePicture($upload);
             //TODO: Test without user save
             $user->save();
         }
     }
     if ($files) {
         $user = $borrower->getUser();
         foreach ($files as $file) {
             $upload = Upload::createFromFile($file);
             $upload->setUser($user);
             $borrower->addUpload($upload);
         }
         $borrower->save();
     }
     $borrower->save();
 }