-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add image upload for training, trainer and place
- Loading branch information
1 parent
c1555b1
commit 97d6347
Showing
16 changed files
with
132 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 68 additions & 0 deletions
68
projects/open-training/src/Entity/UploadableImageTrait.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace OpenTraining\Entity; | ||
|
||
use DateTime; | ||
use Doctrine\ORM\Mapping as ORM; | ||
use Symfony\Component\HttpFoundation\File\File; | ||
|
||
trait UploadableImageTrait | ||
{ | ||
/** | ||
* @ORM\Column(type="string", length=255) | ||
* @var string | ||
*/ | ||
private $image; | ||
|
||
/** | ||
* @Vich\UploadableField(mapping="image_uploads", fileNameProperty="image") | ||
* @var File | ||
*/ | ||
private $imageFile; | ||
|
||
/** | ||
* This needs to be changed on file upload, so the image changes. | ||
* | ||
* @ORM\Column(type="datetime", nullable=true) | ||
* @var DateTime | ||
*/ | ||
private $imageUploadedAt; | ||
|
||
public function getImage(): ?string | ||
{ | ||
return $this->image; | ||
} | ||
|
||
public function setImage(?string $image): void | ||
{ | ||
$this->image = $image; | ||
} | ||
|
||
public function getImageFile(): ?File | ||
{ | ||
return $this->imageFile; | ||
} | ||
|
||
public function setImageFile(?File $file = null): void | ||
{ | ||
$this->imageFile = $file; | ||
|
||
// VERY IMPORTANT: | ||
// It is required that at least one field changes if you are using Doctrine, | ||
// otherwise the event listeners won't be called and the file is lost | ||
if ($file) { | ||
// if 'updatedAt' is not defined in your entity, use another property | ||
$this->imageUploadedAt = new DateTime('now'); | ||
} | ||
} | ||
|
||
public function getImageUploadedAt(): ?DateTime | ||
{ | ||
return $this->imageUploadedAt; | ||
} | ||
|
||
public function setImageUploadedAt(DateTime $imageUploadedAt): void | ||
{ | ||
$this->imageUploadedAt = $imageUploadedAt; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters