From 58c1276bd58497d0a1ff7990d95bbd4b1c753bb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Stan=C4=9Bk?= Date: Wed, 3 Jan 2018 18:59:00 +0100 Subject: [PATCH] oprava chyb modelu --- app/model/ACL/Permission.php | 2 +- app/model/ACL/Resource.php | 8 ---- app/model/ACL/Role.php | 14 +++--- app/model/CMS/Content/CapacitiesContent.php | 2 +- app/model/CMS/Content/Content.php | 2 +- app/model/CMS/Document/Document.php | 4 +- app/model/CMS/Faq.php | 2 +- app/model/CMS/Page.php | 6 +-- app/model/Mailing/Mail.php | 8 +++- app/model/Mailing/Template.php | 8 ---- app/model/Program/Block.php | 14 ++---- app/model/Program/Category.php | 12 +---- app/model/Program/Program.php | 11 ++--- app/model/Program/Room.php | 8 ---- .../Settings/CustomInput/CustomInput.php | 8 ---- app/model/Structure/Subevent.php | 12 +---- app/model/User/Application/Application.php | 2 +- .../CustomInputValue/CustomInputValue.php | 4 +- app/model/User/User.php | 44 ++++--------------- app/services/ApplicationService.php | 19 -------- 20 files changed, 46 insertions(+), 144 deletions(-) diff --git a/app/model/ACL/Permission.php b/app/model/ACL/Permission.php index 7afbbfae9..044777085 100644 --- a/app/model/ACL/Permission.php +++ b/app/model/ACL/Permission.php @@ -85,7 +85,7 @@ class Permission /** * Prostředek oprávnění. - * @ORM\ManyToOne(targetEntity="\App\Model\ACL\Resource", inversedBy="permissions", cascade={"persist"}) + * @ORM\ManyToOne(targetEntity="\App\Model\ACL\Resource", inversedBy="permissions") * @var Resource */ protected $resource; diff --git a/app/model/ACL/Resource.php b/app/model/ACL/Resource.php index a5cee4063..8d7b5af16 100644 --- a/app/model/ACL/Resource.php +++ b/app/model/ACL/Resource.php @@ -121,12 +121,4 @@ public function getPermissions() { return $this->permissions; } - - /** - * @param Collection $permissions - */ - public function setPermissions($permissions) - { - $this->permissions = $permissions; - } } diff --git a/app/model/ACL/Role.php b/app/model/ACL/Role.php index 6fe1ff034..b73d82a9a 100644 --- a/app/model/ACL/Role.php +++ b/app/model/ACL/Role.php @@ -102,7 +102,7 @@ class Role /** * Oprávnění role. - * @ORM\ManyToMany(targetEntity="Permission", inversedBy="roles", cascade={"persist"}) + * @ORM\ManyToMany(targetEntity="Permission", inversedBy="roles") * @var Collection */ protected $permissions; @@ -197,7 +197,7 @@ class Role /** * Role vyžadované touto rolí. - * @ORM\ManyToMany(targetEntity="Role", inversedBy="requiredByRole", cascade={"persist"}) + * @ORM\ManyToMany(targetEntity="Role", inversedBy="requiredByRole") * @ORM\JoinTable(name="role_role_required", * joinColumns={@ORM\JoinColumn(name="role_id", referencedColumnName="id")}, * inverseJoinColumns={@ORM\JoinColumn(name="required_role_id", referencedColumnName="id")} @@ -299,7 +299,9 @@ public function getPermissions(): Collection */ public function setPermissions(Collection $permissions): void { - $this->permissions = $permissions; + $this->permissions->clear(); + foreach ($permissions as $permission) + $this->permissions->add($permission); } public function addPermission(Permission $permission): void @@ -318,7 +320,7 @@ public function getPages(): Collection /** * @param Collection $pages */ - public function setPages(Collection $pages): void + public function setPages(Collection $pages): void //TODO kontrola { foreach ($this->getPages() as $page) { if (!$pages->contains($page)) @@ -518,7 +520,7 @@ public function getIncompatibleRoles(): Collection /** * @param Collection $incompatibleRoles */ - public function setIncompatibleRoles(Collection $incompatibleRoles): void + public function setIncompatibleRoles(Collection $incompatibleRoles): void //TODO kontrola { foreach ($this->getIncompatibleRoles() as $role) { if (!$incompatibleRoles->contains($role)) @@ -601,7 +603,7 @@ public function getRequiredRoles(): Collection /** * @param Collection $requiredRoles */ - public function setRequiredRoles(Collection $requiredRoles): void + public function setRequiredRoles(Collection $requiredRoles): void //TODO kontrola { $this->requiredRoles = $requiredRoles; } diff --git a/app/model/CMS/Content/CapacitiesContent.php b/app/model/CMS/Content/CapacitiesContent.php index 24960081d..5371b2dc1 100644 --- a/app/model/CMS/Content/CapacitiesContent.php +++ b/app/model/CMS/Content/CapacitiesContent.php @@ -63,7 +63,7 @@ public function getRoles() /** * @param Collection $roles */ - public function setRoles($roles) + public function setRoles($roles) //TODO kontrola { $this->roles = $roles; } diff --git a/app/model/CMS/Content/Content.php b/app/model/CMS/Content/Content.php index 42f37b117..6776fcc94 100644 --- a/app/model/CMS/Content/Content.php +++ b/app/model/CMS/Content/Content.php @@ -156,7 +156,7 @@ abstract class Content implements IContent /** * Stránka, na které je obsah umístěn. - * @ORM\ManyToOne(targetEntity="\App\Model\CMS\Page", inversedBy="contents", cascade={"persist"}) + * @ORM\ManyToOne(targetEntity="\App\Model\CMS\Page", inversedBy="contents") * @var Page */ protected $page; diff --git a/app/model/CMS/Document/Document.php b/app/model/CMS/Document/Document.php index 132314293..f187a65fd 100644 --- a/app/model/CMS/Document/Document.php +++ b/app/model/CMS/Document/Document.php @@ -27,7 +27,7 @@ class Document /** * Tagy dokumentu. - * @ORM\ManyToMany(targetEntity="Tag", inversedBy="documents", cascade={"persist"}) + * @ORM\ManyToMany(targetEntity="Tag", inversedBy="documents") * @var Collection */ protected $tags; @@ -88,7 +88,7 @@ public function getTags() /** * @param Collection $tags */ - public function setTags($tags) + public function setTags($tags) //TODO kontrola { $this->tags = $tags; } diff --git a/app/model/CMS/Faq.php b/app/model/CMS/Faq.php index b0ca3e578..c154fbcd9 100644 --- a/app/model/CMS/Faq.php +++ b/app/model/CMS/Faq.php @@ -28,7 +28,7 @@ class Faq /** * Autor otázky. - * @ORM\ManyToOne(targetEntity="\App\Model\User\User", cascade={"persist"}) + * @ORM\ManyToOne(targetEntity="\App\Model\User\User") * @var User */ protected $author; diff --git a/app/model/CMS/Page.php b/app/model/CMS/Page.php index 032ff85d1..744e6383d 100644 --- a/app/model/CMS/Page.php +++ b/app/model/CMS/Page.php @@ -54,7 +54,7 @@ class Page /** * Role, které mají na stránku přístup. - * @ORM\ManyToMany(targetEntity="\App\Model\ACL\Role", inversedBy="pages", cascade={"persist"}) + * @ORM\ManyToMany(targetEntity="\App\Model\ACL\Role", inversedBy="pages") * @var Collection */ protected $roles; @@ -164,7 +164,7 @@ public function getRoles() /** * @param Collection $roles */ - public function setRoles($roles) + public function setRoles($roles) //TODO kontrola { $this->roles = $roles; } @@ -213,7 +213,7 @@ public function hasContents($area) /** * @param $content */ - public function addContent($content) + public function addContent($content) //TODO kontrola { $criteria = Criteria::create() ->where(Criteria::expr()->eq('area', $content->getArea())); diff --git a/app/model/Mailing/Mail.php b/app/model/Mailing/Mail.php index a7d0e2d43..6b6a5c75f 100644 --- a/app/model/Mailing/Mail.php +++ b/app/model/Mailing/Mail.php @@ -92,7 +92,9 @@ public function getRecipientRoles() */ public function setRecipientRoles($recipientRoles) { - $this->recipientRoles = $recipientRoles; + $this->recipientRoles->clear(); + foreach ($recipientRoles as $recipientRole) + $this->recipientRoles->add($recipientRole); } /** @@ -121,7 +123,9 @@ public function getRecipientUsers() */ public function setRecipientUsers($recipientUsers) { - $this->recipientUsers = $recipientUsers; + $this->recipientUsers->clear(); + foreach ($recipientUsers as $recipientUser) + $this->recipientUsers->add($recipientUser); } /** diff --git a/app/model/Mailing/Template.php b/app/model/Mailing/Template.php index 252a2d7c6..e2e606f13 100644 --- a/app/model/Mailing/Template.php +++ b/app/model/Mailing/Template.php @@ -220,14 +220,6 @@ public function getVariables() return $this->variables; } - /** - * @param Collection $variables - */ - public function setVariables($variables) - { - $this->variables = $variables; - } - /** * @return bool */ diff --git a/app/model/Program/Block.php b/app/model/Program/Block.php index ac59a986a..adcd654fe 100644 --- a/app/model/Program/Block.php +++ b/app/model/Program/Block.php @@ -39,21 +39,21 @@ class Block /** * Lektor. - * @ORM\ManyToOne(targetEntity="\App\Model\User\User", inversedBy="lecturersBlocks", cascade={"persist"}) + * @ORM\ManyToOne(targetEntity="\App\Model\User\User", inversedBy="lecturersBlocks") * @var User */ protected $lector; /** * Kategorie bloku. - * @ORM\ManyToOne(targetEntity="Category", inversedBy="blocks", cascade={"persist"}) + * @ORM\ManyToOne(targetEntity="Category", inversedBy="blocks") * @var Category */ protected $category; /** * Podakce bloku. - * @ORM\ManyToOne(targetEntity="\App\Model\Structure\Subevent", inversedBy="blocks", cascade={"persist"}) + * @ORM\ManyToOne(targetEntity="\App\Model\Structure\Subevent", inversedBy="blocks") * @var Subevent */ protected $subevent; @@ -141,14 +141,6 @@ public function getPrograms() return $this->programs; } - /** - * @param Collection $programs - */ - public function setPrograms($programs) - { - $this->programs = $programs; - } - /** * Vrací seznam účastníků bloku. * @return Collection diff --git a/app/model/Program/Category.php b/app/model/Program/Category.php index 863c6da71..b74531866 100644 --- a/app/model/Program/Category.php +++ b/app/model/Program/Category.php @@ -29,7 +29,7 @@ class Category /** * Role, které si mohou přihlašovat programy z kategorie. - * @ORM\ManyToMany(targetEntity="\App\Model\ACL\Role", inversedBy="registerableCategories", cascade={"persist"}) + * @ORM\ManyToMany(targetEntity="\App\Model\ACL\Role", inversedBy="registerableCategories") * @var Collection */ protected $registerableRoles; @@ -87,7 +87,7 @@ public function getRegisterableRoles() /** * @param Collection $registerableRoles */ - public function setRegisterableRoles($registerableRoles) + public function setRegisterableRoles($registerableRoles) //TODO kontrola { $this->registerableRoles = $registerableRoles; } @@ -108,12 +108,4 @@ public function getBlocks() { return $this->blocks; } - - /** - * @param Collection $blocks - */ - public function setBlocks($blocks) - { - $this->blocks = $blocks; - } } diff --git a/app/model/Program/Program.php b/app/model/Program/Program.php index 1b81a10db..d68ab1c59 100644 --- a/app/model/Program/Program.php +++ b/app/model/Program/Program.php @@ -23,7 +23,7 @@ class Program /** * Programový blok. - * @ORM\ManyToOne(targetEntity="Block", inversedBy="programs", cascade={"persist"}) + * @ORM\ManyToOne(targetEntity="Block", inversedBy="programs") * @var Block */ protected $block; @@ -37,7 +37,7 @@ class Program /** * Místnost. - * @ORM\ManyToOne(targetEntity="Room", inversedBy="programs", cascade={"persist"}) + * @ORM\ManyToOne(targetEntity="Room", inversedBy="programs") * @var Room */ protected $room; @@ -96,9 +96,8 @@ public function getAttendees() public function setAttendees(Collection $attendees) { $this->removeAllAttendees(); - foreach ($attendees as $attendee) { + foreach ($attendees as $attendee) $this->addAttendee($attendee); - } } /** @@ -106,10 +105,8 @@ public function setAttendees(Collection $attendees) */ public function addAttendee(User $user) { - if (!$this->attendees->contains($user)) { - $this->attendees->add($user); + if (!$this->attendees->contains($user)) $user->addProgram($this); - } } /** diff --git a/app/model/Program/Room.php b/app/model/Program/Room.php index 47d54d519..29260caed 100644 --- a/app/model/Program/Room.php +++ b/app/model/Program/Room.php @@ -97,12 +97,4 @@ public function getPrograms() { return $this->programs; } - - /** - * @param mixed $programs - */ - public function setPrograms($programs) - { - $this->programs = $programs; - } } diff --git a/app/model/Settings/CustomInput/CustomInput.php b/app/model/Settings/CustomInput/CustomInput.php index 4d1fad264..a22b404dc 100644 --- a/app/model/Settings/CustomInput/CustomInput.php +++ b/app/model/Settings/CustomInput/CustomInput.php @@ -167,12 +167,4 @@ public function getCustomInputValues() { return $this->customInputValues; } - - /** - * @param Collection $customInputValues - */ - public function setCustomInputValues($customInputValues) - { - $this->customInputValues = $customInputValues; - } } diff --git a/app/model/Structure/Subevent.php b/app/model/Structure/Subevent.php index 28faa223d..2ef46c5b8 100644 --- a/app/model/Structure/Subevent.php +++ b/app/model/Structure/Subevent.php @@ -85,7 +85,7 @@ class Subevent /** * Podakce vyžadované touto podakcí. - * @ORM\ManyToMany(targetEntity="Subevent", inversedBy="requiredBySubevent", cascade={"persist"}) + * @ORM\ManyToMany(targetEntity="Subevent", inversedBy="requiredBySubevent") * @ORM\JoinTable(name="subevent_subevent_required", * joinColumns={@ORM\JoinColumn(name="subevent_id", referencedColumnName="id")}, * inverseJoinColumns={@ORM\JoinColumn(name="required_subevent_id", referencedColumnName="id")} @@ -155,14 +155,6 @@ public function getBlocks() : Collection return $this->blocks; } - /** - * @param Collection $blocks - */ - public function setBlocks(Collection $blocks) : void - { - $this->blocks = $blocks; - } - /** * @return int */ @@ -298,7 +290,7 @@ public function getRequiredSubevents() : Collection /** * @param $requiredSubevents */ - public function setRequiredSubevents(Collection $requiredSubevents) : void + public function setRequiredSubevents(Collection $requiredSubevents) : void //TODO kontrola { $this->requiredSubevents = $requiredSubevents; } diff --git a/app/model/User/Application/Application.php b/app/model/User/Application/Application.php index 240c7e052..4f266aa79 100644 --- a/app/model/User/Application/Application.php +++ b/app/model/User/Application/Application.php @@ -59,7 +59,7 @@ abstract class Application /** * Role. - * @ORM\ManyToMany(targetEntity="\App\Model\ACL\Role") + * @ORM\ManyToMany(targetEntity="\App\Model\ACL\Role", cascade={"persist"}) * @var Collection */ protected $roles; diff --git a/app/model/User/CustomInputValue/CustomInputValue.php b/app/model/User/CustomInputValue/CustomInputValue.php index 359c376ed..8851db3d6 100644 --- a/app/model/User/CustomInputValue/CustomInputValue.php +++ b/app/model/User/CustomInputValue/CustomInputValue.php @@ -29,14 +29,14 @@ abstract class CustomInputValue /** * Vlastní pole přihlášky. - * @ORM\ManyToOne(targetEntity="\App\Model\Settings\CustomInput\CustomInput", inversedBy="customInputValues", cascade={"persist"}) + * @ORM\ManyToOne(targetEntity="\App\Model\Settings\CustomInput\CustomInput", inversedBy="customInputValues") * @var CustomInput */ protected $input; /** * Uživatel. - * @ORM\ManyToOne(targetEntity="\App\Model\User\User", inversedBy="customInputValues", cascade={"persist"}) + * @ORM\ManyToOne(targetEntity="\App\Model\User\User", inversedBy="customInputValues") * @var User */ protected $user; diff --git a/app/model/User/User.php b/app/model/User/User.php index 8c3d270c5..505bb0abb 100644 --- a/app/model/User/User.php +++ b/app/model/User/User.php @@ -58,14 +58,14 @@ class User /** * Role. - * @ORM\ManyToMany(targetEntity="\App\Model\ACL\Role", inversedBy="users", cascade={"persist"}) + * @ORM\ManyToMany(targetEntity="\App\Model\ACL\Role", inversedBy="users") * @var Collection */ protected $roles; /** * Přihlášené programy. - * @ORM\ManyToMany(targetEntity="\App\Model\Program\Program", inversedBy="attendees", cascade={"persist"}) + * @ORM\ManyToMany(targetEntity="\App\Model\Program\Program", inversedBy="attendees") * @ORM\OrderBy({"start" = "ASC"}) * @var Collection */ @@ -359,9 +359,11 @@ public function getRoles() /** * @param Collection $roles */ - public function setRoles($roles) + public function setRoles(Collection $roles) { - $this->roles = $roles; + $this->roles->clear(); + foreach ($roles as $role) + $this->roles->add($role); } /** @@ -456,12 +458,6 @@ public function getApplications() return $this->applications; } - public function addApplication($application) - { - if (!$this->applications->contains($application)) - $this->applications->add($application); - } - /** * Vrátí platné přihlášky. * @return Collection|Application[] @@ -578,14 +574,6 @@ public function getWaitingForPaymentSubeventsApplications(): Collection }); } - /** - * @param Collection $applications - */ - public function setApplications($applications) - { - $this->applications = $applications; - } - /** * @return Collection */ @@ -599,7 +587,9 @@ public function getPrograms() */ public function setPrograms($programs) { - $this->programs = $programs; + $this->programs->clear(); + foreach ($programs as $program) + $this->programs->add($program); } /** @@ -610,14 +600,6 @@ public function getLecturersBlocks() return $this->lecturersBlocks; } - /** - * @param Collection $lecturersBlocks - */ - public function setLecturersBlocks($lecturersBlocks) - { - $this->lecturersBlocks = $lecturersBlocks; - } - /** * @param Program $program */ @@ -1119,14 +1101,6 @@ public function getCustomInputValues() return $this->customInputValues; } - /** - * @param Collection $customInputValues - */ - public function setCustomInputValues($customInputValues) - { - $this->customInputValues = $customInputValues; - } - /** * @param CustomInput $customInput * @return mixed diff --git a/app/services/ApplicationService.php b/app/services/ApplicationService.php index c83cbe623..7bdf7399f 100644 --- a/app/services/ApplicationService.php +++ b/app/services/ApplicationService.php @@ -208,8 +208,6 @@ public function updateRoles(User $user, Collection $roles, ?User $createdBy, boo $application->setValidTo(new \DateTime()); $this->applicationRepository->save($application); - - $user->addApplication($newApplication); } else { $fee = $this->countSubeventsFee($roles, $application->getSubevents()); @@ -223,8 +221,6 @@ public function updateRoles(User $user, Collection $roles, ?User $createdBy, boo $application->setValidTo(new \DateTime()); $this->applicationRepository->save($application); - - $user->addApplication($newApplication); } } } @@ -334,9 +330,6 @@ public function updateSubeventsApplication(SubeventsApplication $application, Co $application->setValidTo(new \DateTime()); $this->applicationRepository->save($application); - $user->addApplication($newApplication); - $this->userRepository->save($user); - $this->programService->updateUserPrograms($user); }); @@ -365,9 +358,6 @@ public function cancelSubeventsApplication(SubeventsApplication $application, st $application->setValidTo(new \DateTime()); $this->applicationRepository->save($application); - $user->addApplication($newApplication); - $this->userRepository->save($user); - $this->programService->updateUserPrograms($user); }); @@ -432,9 +422,6 @@ public function updatePayment(Application $application, string $variableSymbol, $application->setValidTo(new \DateTime()); $this->applicationRepository->save($application); - $user->addApplication($newApplication); - $this->userRepository->save($user); - $this->programService->updateUserPrograms($user); }); @@ -480,9 +467,6 @@ private function createRolesApplication(User $user, Collection $roles, User $cre $application->setApplicationId($application->getId()); $this->applicationRepository->save($application); - $user->addApplication($application); - $this->userRepository->save($user); - return $application; } @@ -511,9 +495,6 @@ private function createSubeventsApplication(User $user, Collection $subevents, $application->setApplicationId($application->getId()); $this->applicationRepository->save($application); - $user->addApplication($application); - $this->userRepository->save($user); - return $application; }