From: Raphaël Gertz Date: Thu, 31 Oct 2024 06:46:11 +0000 (+0100) Subject: Import entities X-Git-Tag: 0.0.5~4 X-Git-Url: https://git.rapsys.eu/treebundle/commitdiff_plain/bc23d7a89281c97e385b252c02de5f117f72b5a3?ds=sidebyside Import entities --- diff --git a/Entity/Civility.php b/Entity/Civility.php new file mode 100644 index 0000000..bbf8493 --- /dev/null +++ b/Entity/Civility.php @@ -0,0 +1,17 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Rapsys\TreeBundle\Entity; + +use Rapsys\UserBundle\Entity\Civility as BaseCivility; + +class Civility extends BaseCivility { +} diff --git a/Entity/Group.php b/Entity/Group.php new file mode 100644 index 0000000..3fffaf1 --- /dev/null +++ b/Entity/Group.php @@ -0,0 +1,17 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Rapsys\TreeBundle\Entity; + +use Rapsys\UserBundle\Entity\Group as BaseGroup; + +class Group extends BaseGroup { +} diff --git a/Entity/Resource.php b/Entity/Resource.php new file mode 100644 index 0000000..8c10d23 --- /dev/null +++ b/Entity/Resource.php @@ -0,0 +1,154 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Rapsys\TreeBundle\Entity; + +use Doctrine\Common\Collections\Collection; +use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\ORM\Event\PreUpdateEventArgs; + +/** + * Resource + */ +class Resource { + /** + * @var int + */ + private ?int $id; + + /** + * @var \DateTime + */ + private \DateTime $created; + + /** + * @var \DateTime + */ + private \DateTime $updated; + + /** + * Constructor + * + * @param string $path The resource path + */ + public function __construct(private User $user, private string $path) { + $this->created = new \DateTime('now'); + $this->updated = new \DateTime('now'); + } + + /** + * Get id + * + * @return ?int + */ + public function getId(): ?int { + return $this->id; + } + + /** + * Set user + * + * @param \Rapsys\BlogBundle\Entity\User $user + * + * @return Resource + */ + public function setUser(User $user): Resource { + $this->user = $user; + + return $this; + } + + /** + * Get user + * + * @return \Rapsys\BlogBundle\Entity\User + */ + public function getUser(): User { + return $this->user; + } + + /** + * Set path + * + * @param string $path + * + * @return Resource + */ + public function setPath(string $path): Resource { + $this->path = $path; + + return $this; + } + + /** + * Get path + * + * @return string + */ + public function getPath(): string { + return $this->path; + } + + /** + * Set created + * + * @param \DateTime $created + * + * @return Resource + */ + public function setCreated(\DateTime $created): Resource { + $this->created = $created; + + return $this; + } + + /** + * Get created + * + * @return \DateTime + */ + public function getCreated(): \DateTime { + return $this->created; + } + + /** + * Set updated + * + * @param \DateTime $updated + * + * @return Resource + */ + public function setUpdated(\DateTime $updated): Resource { + $this->updated = $updated; + + return $this; + } + + /** + * Get updated + * + * @return \DateTime + */ + public function getUpdated(): \DateTime { + return $this->updated; + } + + /** + * {@inheritdoc} + */ + public function preUpdate(PreUpdateEventArgs $eventArgs): ?Resource { + //Check that we have an snippet instance + if (($entity = $eventArgs->getEntity()) instanceof Resource) { + //Set updated value + return $entity->setUpdated(new \DateTime('now')); + } + } +} diff --git a/Entity/User.php b/Entity/User.php new file mode 100644 index 0000000..b0a143e --- /dev/null +++ b/Entity/User.php @@ -0,0 +1,83 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Rapsys\TreeBundle\Entity; + +use Doctrine\Common\Collections\Collection; +use Doctrine\Common\Collections\ArrayCollection; + +use Rapsys\UserBundle\Entity\User as BaseUser; + +/** + * {@inheritdoc} + */ +class User extends BaseUser { + /** + * @var \Doctrine\Common\Collections\Collection + */ + private Collection $resources; + + /** + * Constructor + * + * @param string $mail The user mail + * @param string $password The user password + * @param ?Civility $civility The user civility + * @param ?string $forename The user forename + * @param ?string $surname The user surname + * @param bool $active The user is active + * @param bool $enable The user is enable + * @param ?string $pseudonym The user pseudonym + * @param ?string $slug The user slug + */ + public function __construct(string $mail, string $password, ?Civility $civility = null, ?string $forename = null, ?string $surname = null, bool $active = false, bool $enable = true, ?string $pseudonym = null, ?string $slug = null) { + //Call parent constructor + parent::__construct($mail, $password, $civility, $forename, $surname, $active, $enable); + + //Set defaults + + //Set collections + $this->resources = new ArrayCollection(); + } + + /** + * Add resource + * + * @param Resource $resource + * + * @return User + */ + public function addResource(Resource $resource): User { + $this->resources[] = $resource; + + return $this; + } + + /** + * Remove resource + * + * @param Resource $resource + * + * @return \Doctrine\Common\Collections\Collection + */ + public function removeResource(Resource $resource): Collection { + return $this->resources->removeElement($resource); + } + + /** + * Get resources + * + * @return \Doctrine\Common\Collections\Collection + */ + public function getResources(): Collection { + return $this->resources; + } +} diff --git a/config/doctrine/Civility.orm.yml b/config/doctrine/Civility.orm.yml new file mode 100644 index 0000000..8c70fff --- /dev/null +++ b/config/doctrine/Civility.orm.yml @@ -0,0 +1,8 @@ +Rapsys\TreeBundle\Entity\Civility: + type: entity + #repositoryClass: Rapsys\TreeBundle\Repository\CivilityRepository + table: civilities + oneToMany: + users: + targetEntity: User + mappedBy: civility diff --git a/config/doctrine/Group.orm.yml b/config/doctrine/Group.orm.yml new file mode 100644 index 0000000..a2ca805 --- /dev/null +++ b/config/doctrine/Group.orm.yml @@ -0,0 +1,8 @@ +Rapsys\TreeBundle\Entity\Group: + type: entity + #repositoryClass: Rapsys\TreeBundle\Repository\GroupRepository + table: groups + manyToMany: + users: + targetEntity: Rapsys\TreeBundle\Entity\User + mappedBy: groups diff --git a/config/doctrine/Resource.orm.yml b/config/doctrine/Resource.orm.yml new file mode 100644 index 0000000..470a66d --- /dev/null +++ b/config/doctrine/Resource.orm.yml @@ -0,0 +1,26 @@ +Rapsys\TreeBundle\Entity\Resource: + type: entity + repositoryClass: Rapsys\TreeBundle\Repository\ResourceRepository + table: resources + id: + id: + type: integer + generator: + strategy: AUTO + options: + unsigned: true + fields: + path: + type: string + length: 4096 + nullable: true + created: + type: datetime + updated: + type: datetime + manyToOne: + user: + targetEntity: Rapsys\TreeBundle\Entity\User + inversedBy: resources + lifecycleCallbacks: + preUpdate: ['preUpdate'] diff --git a/config/doctrine/User.orm.yml b/config/doctrine/User.orm.yml new file mode 100644 index 0000000..3baa63b --- /dev/null +++ b/config/doctrine/User.orm.yml @@ -0,0 +1,34 @@ +Rapsys\TreeBundle\Entity\User: + type: entity + repositoryClass: Rapsys\TreeBundle\Repository\UserRepository + table: users +# fields: +# pseudonym: +# type: string +# length: 64 +# nullable: true +# slug: +# type: string +# length: 64 +# unique: true +# nullable: true + oneToMany: + resources: + targetEntity: Rapsys\TreeBundle\Entity\Resource + mappedBy: user +# manyToMany: +# groups: +# targetEntity: Group +# inversedBy: users +# joinTable: +# name: users_groups + associationOverride: + groups: + joinTable: + name: users_groups + joinColumns: + id: + name: user_id + inverseJoinColumns: + id: + name: group_id