- Basic HTML templates

- Created entities & new migration
- Added packages symfony/stimulus-bundle & symfony/webpack-encore-bundle
This commit is contained in:
2023-10-14 02:11:28 -06:00
parent e8df5bf019
commit 3ed53ac05e
33 changed files with 9009 additions and 42 deletions
+117
View File
@@ -3,22 +3,44 @@
namespace App\Entity;
use App\Repository\UserRepository;
use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation\Timestampable;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[ORM\Table(name: '`user`')]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
const ROLE_USER = 'ROLE_USER';
const ROLE_OWNER = 'ROLE_OWNER';
const ROLE_ADMIN = 'ROLE_ADMIN';
const ROLE_SUPER_ADMIN = 'ROLE_SUPER_ADMIN';
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 180, unique: true)]
#[Assert\NotBlank]
#[Assert\Email(mode: Assert\Email::VALIDATION_MODE_HTML5)]
#[Assert\Length(max: 180)]
#[Assert\NoSuspiciousCharacters()]
private ?string $email = null;
#[ORM\Column(length: 64)]
#[Assert\NotBlank]
#[Assert\Length(max: 64)]
#[Assert\NoSuspiciousCharacters()]
#[Assert\Regex(pattern: "/^[a-zA-Z0-9 _\-]+$/", message: "Display name can only contain characters [a-zA-Z0-9 _-]")]
private ?string $displayName = null;
#[ORM\Column]
private array $roles = [];
@@ -28,6 +50,22 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
#[ORM\Column]
private ?string $password = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
#[Timestampable(on: "create")]
private ?DateTimeInterface $createdAt = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
#[Timestampable(on: "update")]
private ?DateTimeInterface $updatedAt = null;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Comment::class)]
private Collection $comments;
public function __construct()
{
$this->comments = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
@@ -45,6 +83,18 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
return $this;
}
public function getDisplayName(): ?string
{
return $this->displayName;
}
public function setDisplayName(string $displayName): static
{
$this->displayName = $displayName;
return $this;
}
/**
* A visual identifier that represents this user.
*
@@ -74,6 +124,19 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
return $this;
}
public function addRole(string $role): static
{
if(!$this->roles) {
$this->roles = [];
}
if(!in_array($role, $this->roles)) {
$this->roles[] = $role;
}
return $this;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
@@ -97,4 +160,58 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function getCreatedAt(): ?DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(DateTimeInterface $createdAt): static
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(?DateTimeInterface $updatedAt): static
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* @return Collection<int, Comment>
*/
public function getComments(): Collection
{
return $this->comments;
}
public function addComment(Comment $comment): static
{
if (!$this->comments->contains($comment)) {
$this->comments->add($comment);
$comment->setUser($this);
}
return $this;
}
public function removeComment(Comment $comment): static
{
if ($this->comments->removeElement($comment)) {
// set the owning side to null (unless already changed)
if ($comment->getUser() === $this) {
$comment->setUser(null);
}
}
return $this;
}
}