From c43e7daefedea7873bea74bc84214e2e36c0c5ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 18 Mar 2016 10:28:26 +0100 Subject: [PATCH 01/73] initial commit --- ChillEventBundle.php | 9 +++ Controller/DefaultController.php | 13 +++++ DependencyInjection/ChillEventExtension.php | 45 +++++++++++++++ DependencyInjection/Configuration.php | 29 ++++++++++ Resources/config/routing.yml | 3 + Resources/config/services.yml | 4 ++ Resources/views/Default/index.html.twig | 1 + Tests/Controller/DefaultControllerTest.php | 17 ++++++ composer.json | 61 +++++++++++++++++++++ 9 files changed, 182 insertions(+) create mode 100644 ChillEventBundle.php create mode 100644 Controller/DefaultController.php create mode 100644 DependencyInjection/ChillEventExtension.php create mode 100644 DependencyInjection/Configuration.php create mode 100644 Resources/config/routing.yml create mode 100644 Resources/config/services.yml create mode 100644 Resources/views/Default/index.html.twig create mode 100644 Tests/Controller/DefaultControllerTest.php create mode 100644 composer.json diff --git a/ChillEventBundle.php b/ChillEventBundle.php new file mode 100644 index 000000000..dc040dac6 --- /dev/null +++ b/ChillEventBundle.php @@ -0,0 +1,9 @@ +render('ChillEventBundle:Default:index.html.twig', array('name' => $name)); + } +} diff --git a/DependencyInjection/ChillEventExtension.php b/DependencyInjection/ChillEventExtension.php new file mode 100644 index 000000000..89eb98c57 --- /dev/null +++ b/DependencyInjection/ChillEventExtension.php @@ -0,0 +1,45 @@ +processConfiguration($configuration, $configs); + + $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); + $loader->load('services.yml'); + } + + /* (non-PHPdoc) + * @see \Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface::prepend() + */ + public function prepend(ContainerBuilder $container) + { + + //add routes for custom bundle + $container->prependExtensionConfig('chill_main', array( + 'routing' => array( + 'resources' => array( + '@ChillEventBundle/Resources/config/routing.yml' + ) + ) + )); + } +} diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php new file mode 100644 index 000000000..26441ce71 --- /dev/null +++ b/DependencyInjection/Configuration.php @@ -0,0 +1,29 @@ +root('chill_event'); + + // Here you should define the parameters that are allowed to + // configure your bundle. See the documentation linked above for + // more information on that topic. + + return $treeBuilder; + } +} diff --git a/Resources/config/routing.yml b/Resources/config/routing.yml new file mode 100644 index 000000000..712a131e6 --- /dev/null +++ b/Resources/config/routing.yml @@ -0,0 +1,3 @@ +chill_event_homepage: + path: /hello/{name} + defaults: { _controller: ChillEventBundle:Default:index } diff --git a/Resources/config/services.yml b/Resources/config/services.yml new file mode 100644 index 000000000..d2cfb62f0 --- /dev/null +++ b/Resources/config/services.yml @@ -0,0 +1,4 @@ +services: +# chill_event.example: +# class: Chill\EventBundle\Example +# arguments: [@service_id, "plain_value", %parameter%] diff --git a/Resources/views/Default/index.html.twig b/Resources/views/Default/index.html.twig new file mode 100644 index 000000000..4ce626e9b --- /dev/null +++ b/Resources/views/Default/index.html.twig @@ -0,0 +1 @@ +Hello {{ name }}! diff --git a/Tests/Controller/DefaultControllerTest.php b/Tests/Controller/DefaultControllerTest.php new file mode 100644 index 000000000..5c2a813f4 --- /dev/null +++ b/Tests/Controller/DefaultControllerTest.php @@ -0,0 +1,17 @@ +request('GET', '/hello/Fabien'); + + $this->assertTrue($crawler->filter('html:contains("Hello Fabien")')->count() > 0); + } +} diff --git a/composer.json b/composer.json new file mode 100644 index 000000000..14fc5af95 --- /dev/null +++ b/composer.json @@ -0,0 +1,61 @@ +{ + "name": "chill-project/event", + "description": "This bundle extend chill software. This bundle allow to define event and participation to those events.", + "type": "symfony-bundle", + "license": "AGPL-3.0", + "keywords" : ["chill", "social work"], + "homepage" : "https://git.framasoft.org/Chill-project/Chill-Group", + "autoload": { + "psr-4": { "Chill\\EventBundle\\": "" } + }, + "support": { + "issues": "https://git.framasoft.org/Chill-project/Chill-Event/issues", + "source": "https://git.framasoft.org/Chill-project/Chill-Event", + "docs" : "http://docs.chill.social", + "email": "dev@listes.chill.social" + }, + "authors": [ + { + "name": "Champs-Libres", + "email": "info@champs-libres.coop" + } + ], + "require": { + "twig/extensions": "^1.2", + "symfony/assetic-bundle": "~2.3", + "symfony/framework-bundle": "~2.7", + "symfony/yaml": "~2.8", + "symfony/symfony": "~2.8", + "doctrine/dbal": "~2.5", + "doctrine/orm": "~2.4", + "doctrine/common": "~2.4", + "doctrine/doctrine-bundle": "~1.2", + "chill-project/main": "dev-master@dev", + "chill-project/person": "dev-master@dev", + "champs-libres/composer-bundle-migration": "~1.0", + "doctrine/doctrine-migrations-bundle": "~1.1", + "chill-project/custom-fields": "dev-master@dev", + "doctrine/migrations": "~1.0", + "monolog/monolog": "^1.14" + }, + "require-dev": { + "doctrine/doctrine-fixtures-bundle": "~2.2", + "fzaninotto/faker": "~1", + "symfony/monolog-bundle": "^2.7", + "sensio/generator-bundle": "^2.5" + }, + "suggest" : { + "chill-project/group": "dev-master@dev" + }, + "scripts": { + "post-install-cmd": [ + "ComposerBundleMigration\\Composer\\Migrations::synchronizeMigrations" + ], + "post-update-cmd": [ + "ComposerBundleMigration\\Composer\\Migrations::synchronizeMigrations" + ] + }, + "extra": { + "app-migrations-dir": "Resources/test/Fixtures/App/DoctrineMigrations" + } +} From f3b00ac69b2c0ac250ca0e608e0e23c4f10a6108 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 18 Mar 2016 10:31:17 +0100 Subject: [PATCH 02/73] add license and readme --- LICENSE.txt | 661 ++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 16 ++ 2 files changed, 677 insertions(+) create mode 100644 LICENSE.txt create mode 100644 README.md diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 000000000..dba13ed2d --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,661 @@ + GNU AFFERO GENERAL PUBLIC LICENSE + Version 3, 19 November 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU Affero General Public License is a free, copyleft license for +software and other kinds of works, specifically designed to ensure +cooperation with the community in the case of network server software. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +our General Public Licenses are intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + Developers that use our General Public Licenses protect your rights +with two steps: (1) assert copyright on the software, and (2) offer +you this License which gives you legal permission to copy, distribute +and/or modify the software. + + A secondary benefit of defending all users' freedom is that +improvements made in alternate versions of the program, if they +receive widespread use, become available for other developers to +incorporate. Many developers of free software are heartened and +encouraged by the resulting cooperation. However, in the case of +software used on network servers, this result may fail to come about. +The GNU General Public License permits making a modified version and +letting the public access it on a server without ever releasing its +source code to the public. + + The GNU Affero General Public License is designed specifically to +ensure that, in such cases, the modified source code becomes available +to the community. It requires the operator of a network server to +provide the source code of the modified version running there to the +users of that server. Therefore, public use of a modified version, on +a publicly accessible server, gives the public access to the source +code of the modified version. + + An older license, called the Affero General Public License and +published by Affero, was designed to accomplish similar goals. This is +a different license, not a version of the Affero GPL, but Affero has +released a new version of the Affero GPL which permits relicensing under +this license. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU Affero General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Remote Network Interaction; Use with the GNU General Public License. + + Notwithstanding any other provision of this License, if you modify the +Program, your modified version must prominently offer all users +interacting with it remotely through a computer network (if your version +supports such interaction) an opportunity to receive the Corresponding +Source of your version by providing access to the Corresponding Source +from a network server at no charge, through some standard or customary +means of facilitating copying of software. This Corresponding Source +shall include the Corresponding Source for any work covered by version 3 +of the GNU General Public License that is incorporated pursuant to the +following paragraph. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the work with which it is combined will remain governed by version +3 of the GNU General Public License. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU Affero General Public License from time to time. Such new versions +will be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU Affero General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU Affero General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU Affero General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If your software can interact with users remotely through a computer +network, you should also make sure that it provides a way for users to +get its source. For example, if your program is a web application, its +interface could display a "Source" link that leads users to an archive +of the code. There are many ways you could offer source, and different +solutions will be better for different programs; see section 13 for the +specific requirements. + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU AGPL, see +. diff --git a/README.md b/README.md new file mode 100644 index 000000000..2aad96db5 --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +Chill Event Bundle +==================== + +This bundle extend [chill software](https://www.chill.social). This bundle allow to define event and participation to those events. + +Documentation & installation +============================ + +This bundle can be installed with the Chill software. + +Read documentation here : http://chill.readthedocs.org + +Issues and bug tracking +======================= + +The issues tracker is here : https://git.framasoft.org/Chill-project/Chill-Event/issues From 11d58a457ae3affeecb57b010c503a2a0872d745 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 18 Mar 2016 11:22:09 +0100 Subject: [PATCH 03/73] initialize entities --- Entity/Event.php | 130 +++++++++++++ Entity/EventType.php | 169 +++++++++++++++++ Entity/Participation.php | 171 ++++++++++++++++++ Entity/Role.php | 113 ++++++++++++ Entity/Status.php | 114 ++++++++++++ Resources/config/doctrine/Event.orm.yml | 20 ++ Resources/config/doctrine/EventType.orm.yml | 22 +++ .../config/doctrine/Participation.orm.yml | 23 +++ Resources/config/doctrine/Role.orm.yml | 19 ++ Resources/config/doctrine/Status.orm.yml | 19 ++ 10 files changed, 800 insertions(+) create mode 100644 Entity/Event.php create mode 100644 Entity/EventType.php create mode 100644 Entity/Participation.php create mode 100644 Entity/Role.php create mode 100644 Entity/Status.php create mode 100644 Resources/config/doctrine/Event.orm.yml create mode 100644 Resources/config/doctrine/EventType.orm.yml create mode 100644 Resources/config/doctrine/Participation.orm.yml create mode 100644 Resources/config/doctrine/Role.orm.yml create mode 100644 Resources/config/doctrine/Status.orm.yml diff --git a/Entity/Event.php b/Entity/Event.php new file mode 100644 index 000000000..d3e6a8881 --- /dev/null +++ b/Entity/Event.php @@ -0,0 +1,130 @@ +participations = new \Doctrine\Common\Collections\ArrayCollection(); + } + + + /** + * Get id + * + * @return integer + */ + public function getId() + { + return $this->id; + } + + /** + * Set label + * + * @param string $label + * + * @return Event + */ + public function setLabel($label) + { + $this->label = $label; + + return $this; + } + + /** + * Get label + * + * @return string + */ + public function getLabel() + { + return $this->label; + } + + /** + * Set date + * + * @param \DateTime $date + * + * @return Event + */ + public function setDate($date) + { + $this->date = $date; + + return $this; + } + + /** + * Get date + * + * @return \DateTime + */ + public function getDate() + { + return $this->date; + } + + /** + * Add participation + * + * @param \Chill\EventBundle\Entity\Participation $participation + * + * @return Event + */ + public function addParticipation(\Chill\EventBundle\Entity\Participation $participation) + { + $this->participations[] = $participation; + + return $this; + } + + /** + * Remove participation + * + * @param \Chill\EventBundle\Entity\Participation $participation + */ + public function removeParticipation(\Chill\EventBundle\Entity\Participation $participation) + { + $this->participations->removeElement($participation); + } + + /** + * Get participations + * + * @return \Doctrine\Common\Collections\Collection + */ + public function getParticipations() + { + return $this->participations; + } +} diff --git a/Entity/EventType.php b/Entity/EventType.php new file mode 100644 index 000000000..64c240b53 --- /dev/null +++ b/Entity/EventType.php @@ -0,0 +1,169 @@ +id; + } + + /** + * Set label + * + * @param array $label + * + * @return EventType + */ + public function setLabel($label) + { + $this->label = $label; + + return $this; + } + + /** + * Get label + * + * @return array + */ + public function getLabel() + { + return $this->label; + } + + /** + * Set active + * + * @param boolean $active + * + * @return EventType + */ + public function setActive($active) + { + $this->active = $active; + + return $this; + } + + /** + * Get active + * + * @return boolean + */ + public function getActive() + { + return $this->active; + } + /** + * @var \Doctrine\Common\Collections\Collection + */ + private $roles; + + /** + * @var \Doctrine\Common\Collections\Collection + */ + private $statuses; + + /** + * Constructor + */ + public function __construct() + { + $this->roles = new \Doctrine\Common\Collections\ArrayCollection(); + $this->statuses = new \Doctrine\Common\Collections\ArrayCollection(); + } + + /** + * Add role + * + * @param \Chill\EventBundle\Entity\Role $role + * + * @return EventType + */ + public function addRole(\Chill\EventBundle\Entity\Role $role) + { + $this->roles[] = $role; + + return $this; + } + + /** + * Remove role + * + * @param \Chill\EventBundle\Entity\Role $role + */ + public function removeRole(\Chill\EventBundle\Entity\Role $role) + { + $this->roles->removeElement($role); + } + + /** + * Get roles + * + * @return \Doctrine\Common\Collections\Collection + */ + public function getRoles() + { + return $this->roles; + } + + /** + * Add status + * + * @param \Chill\EventBundle\Entity\Status $status + * + * @return EventType + */ + public function addStatus(\Chill\EventBundle\Entity\Status $status) + { + $this->statuses[] = $status; + + return $this; + } + + /** + * Remove status + * + * @param \Chill\EventBundle\Entity\Status $status + */ + public function removeStatus(\Chill\EventBundle\Entity\Status $status) + { + $this->statuses->removeElement($status); + } + + /** + * Get statuses + * + * @return \Doctrine\Common\Collections\Collection + */ + public function getStatuses() + { + return $this->statuses; + } +} diff --git a/Entity/Participation.php b/Entity/Participation.php new file mode 100644 index 000000000..2c6fdb2f5 --- /dev/null +++ b/Entity/Participation.php @@ -0,0 +1,171 @@ +id; + } + + /** + * Set lastUpdate + * + * @param \DateTime $lastUpdate + * + * @return Participation + */ + public function setLastUpdate($lastUpdate) + { + $this->lastUpdate = $lastUpdate; + + return $this; + } + + /** + * Get lastUpdate + * + * @return \DateTime + */ + public function getLastUpdate() + { + return $this->lastUpdate; + } + + + /** + * Set event + * + * @param \Chill\EventBundle\Entity\Event $event + * + * @return Participation + */ + public function setEvent(\Chill\EventBundle\Entity\Event $event = null) + { + $this->event = $event; + + return $this; + } + + /** + * Get event + * + * @return \Chill\EventBundle\Entity\Event + */ + public function getEvent() + { + return $this->event; + } + + /** + * Set person + * + * @param \Chill\PersonBundle\Entity\Person $person + * + * @return Participation + */ + public function setPerson(\Chill\PersonBundle\Entity\Person $person = null) + { + $this->person = $person; + + return $this; + } + + /** + * Get person + * + * @return \Chill\PersonBundle\Entity\Person + */ + public function getPerson() + { + return $this->person; + } + + /** + * Set role + * + * @param \Chill\EventBundle\Entity\Role $role + * + * @return Participation + */ + public function setRole(\Chill\EventBundle\Entity\Role $role = null) + { + $this->role = $role; + + return $this; + } + + /** + * Get role + * + * @return \Chill\EventBundle\Entity\Role + */ + public function getRole() + { + return $this->role; + } + + /** + * Set status + * + * @param \Chill\EventBundle\Entity\Status $status + * + * @return Participation + */ + public function setStatus(\Chill\EventBundle\Entity\Status $status = null) + { + $this->status = $status; + + return $this; + } + + /** + * Get status + * + * @return \Chill\EventBundle\Entity\Status + */ + public function getStatus() + { + return $this->status; + } +} diff --git a/Entity/Role.php b/Entity/Role.php new file mode 100644 index 000000000..fe98414ab --- /dev/null +++ b/Entity/Role.php @@ -0,0 +1,113 @@ +id; + } + + /** + * Set label + * + * @param array $label + * + * @return Role + */ + public function setLabel($label) + { + $this->label = $label; + + return $this; + } + + /** + * Get label + * + * @return array + */ + public function getLabel() + { + return $this->label; + } + + /** + * Set active + * + * @param boolean $active + * + * @return Role + */ + public function setActive($active) + { + $this->active = $active; + + return $this; + } + + /** + * Get active + * + * @return boolean + */ + public function getActive() + { + return $this->active; + } + + + /** + * Set type + * + * @param \Chill\EventBundle\Entity\EventType $type + * + * @return Role + */ + public function setType(\Chill\EventBundle\Entity\EventType $type = null) + { + $this->type = $type; + + return $this; + } + + /** + * Get type + * + * @return \Chill\EventBundle\Entity\EventType + */ + public function getType() + { + return $this->type; + } +} diff --git a/Entity/Status.php b/Entity/Status.php new file mode 100644 index 000000000..d39a325c3 --- /dev/null +++ b/Entity/Status.php @@ -0,0 +1,114 @@ +id; + } + + /** + * Set label + * + * @param array $label + * + * @return Status + */ + public function setLabel($label) + { + $this->label = $label; + + return $this; + } + + /** + * Get label + * + * @return array + */ + public function getLabel() + { + return $this->label; + } + + + /** + * Set active + * + * @param boolean $active + * + * @return Status + */ + public function setActive($active) + { + $this->active = $active; + + return $this; + } + + /** + * Get active + * + * @return boolean + */ + public function getActive() + { + return $this->active; + } + + + /** + * Set type + * + * @param \Chill\EventBundle\Entity\EventType $type + * + * @return Status + */ + public function setType(\Chill\EventBundle\Entity\EventType $type = null) + { + $this->type = $type; + + return $this; + } + + /** + * Get type + * + * @return \Chill\EventBundle\Entity\EventType + */ + public function getType() + { + return $this->type; + } +} diff --git a/Resources/config/doctrine/Event.orm.yml b/Resources/config/doctrine/Event.orm.yml new file mode 100644 index 000000000..3bc880597 --- /dev/null +++ b/Resources/config/doctrine/Event.orm.yml @@ -0,0 +1,20 @@ +Chill\EventBundle\Entity\Event: + type: entity + table: chill_event_event + id: + id: + type: integer + id: true + generator: + strategy: AUTO + fields: + label: + type: string + length: '150' + date: + type: date + oneToMany: + participations: + targetEntity: Chill\EventBundle\Entity\Participation + mappedBy: event + lifecycleCallbacks: { } diff --git a/Resources/config/doctrine/EventType.orm.yml b/Resources/config/doctrine/EventType.orm.yml new file mode 100644 index 000000000..17bc5cadb --- /dev/null +++ b/Resources/config/doctrine/EventType.orm.yml @@ -0,0 +1,22 @@ +Chill\EventBundle\Entity\EventType: + type: entity + table: chill_event_event_type + id: + id: + type: integer + id: true + generator: + strategy: AUTO + fields: + label: + type: json_array + active: + type: boolean + oneToMany: + roles: + targetEntity: Chill\EventBundle\Entity\Role + mappedBy: type + statuses: + targetEntity: Chill\EventBundle\Entity\Status + mappedBy: type + lifecycleCallbacks: { } diff --git a/Resources/config/doctrine/Participation.orm.yml b/Resources/config/doctrine/Participation.orm.yml new file mode 100644 index 000000000..24858afc4 --- /dev/null +++ b/Resources/config/doctrine/Participation.orm.yml @@ -0,0 +1,23 @@ +Chill\EventBundle\Entity\Participation: + type: entity + table: chill_event_participation + id: + id: + type: integer + id: true + generator: + strategy: AUTO + fields: + lastUpdate: + type: datetime + manyToOne: + event: + targetEntity: Chill\EventBundle\Entity\Event + inversedBy: participations + person: + targetEntity: Chill\PersonBundle\Entity\Person + role: + targetEntity: Chill\EventBundle\Entity\Role + status: + targetEntity: Chill\EventBundle\Entity\Status + lifecycleCallbacks: { } diff --git a/Resources/config/doctrine/Role.orm.yml b/Resources/config/doctrine/Role.orm.yml new file mode 100644 index 000000000..8d1723c37 --- /dev/null +++ b/Resources/config/doctrine/Role.orm.yml @@ -0,0 +1,19 @@ +Chill\EventBundle\Entity\Role: + type: entity + table: chill_event_role + id: + id: + type: integer + id: true + generator: + strategy: AUTO + fields: + label: + type: json_array + active: + type: boolean + manyToOne: + type: + targetEntity: Chill\EventBundle\Entity\EventType + inversedBy: roles + lifecycleCallbacks: { } diff --git a/Resources/config/doctrine/Status.orm.yml b/Resources/config/doctrine/Status.orm.yml new file mode 100644 index 000000000..2849b7522 --- /dev/null +++ b/Resources/config/doctrine/Status.orm.yml @@ -0,0 +1,19 @@ +Chill\EventBundle\Entity\Status: + type: entity + table: chill_event_status + id: + id: + type: integer + id: true + generator: + strategy: AUTO + fields: + label: + type: json_array + active: + type: boolean + manyToOne: + type: + targetEntity: Chill\EventBundle\Entity\EventType + inversedBy: statuses + lifecycleCallbacks: { } From cd7e9a9e2bcd7d280704fb01ef49257ca2e64d35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 18 Mar 2016 11:33:59 +0100 Subject: [PATCH 04/73] add migration file --- .../migrations/Version20160318111334.php | 116 ++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 Resources/migrations/Version20160318111334.php diff --git a/Resources/migrations/Version20160318111334.php b/Resources/migrations/Version20160318111334.php new file mode 100644 index 000000000..6ab4d5004 --- /dev/null +++ b/Resources/migrations/Version20160318111334.php @@ -0,0 +1,116 @@ +abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); + + $this->addSql('CREATE SEQUENCE chill_event_event_type_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE SEQUENCE chill_event_role_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE SEQUENCE chill_event_status_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE SEQUENCE chill_event_event_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE SEQUENCE chill_event_participation_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE TABLE chill_event_event_type (' + . 'id INT NOT NULL, label JSON NOT NULL, ' + . 'active BOOLEAN NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE TABLE chill_event_role (' + . 'id INT NOT NULL, ' + . 'type_id INT DEFAULT NULL, ' + . 'label JSON NOT NULL, ' + . 'active BOOLEAN NOT NULL, ' + . 'PRIMARY KEY(id))'); + $this->addSql('CREATE INDEX IDX_AA714E54C54C8C93 ON chill_event_role (type_id)'); + $this->addSql('CREATE TABLE chill_event_status (id INT NOT NULL, ' + . 'type_id INT DEFAULT NULL, ' + . 'label JSON NOT NULL, ' + . 'active BOOLEAN NOT NULL, ' + . 'PRIMARY KEY(id))'); + $this->addSql('CREATE INDEX IDX_A6CC85D0C54C8C93 ON chill_event_status (type_id)'); + $this->addSql('CREATE TABLE chill_event_event (' + . 'id INT NOT NULL, ' + . 'label VARCHAR(150) NOT NULL, ' + . 'date DATE NOT NULL, ' + . 'PRIMARY KEY(id))'); + $this->addSql('CREATE TABLE chill_event_participation (' + . 'id INT NOT NULL, ' + . 'event_id INT DEFAULT NULL, ' + . 'person_id INT DEFAULT NULL, ' + . 'role_id INT DEFAULT NULL, ' + . 'status_id INT DEFAULT NULL, ' + . 'lastUpdate TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, ' + . 'PRIMARY KEY(id))'); + $this->addSql('CREATE INDEX IDX_4E7768AC71F7E88B ON chill_event_participation (event_id)'); + $this->addSql('CREATE INDEX IDX_4E7768AC217BBB47 ON chill_event_participation (person_id)'); + $this->addSql('CREATE INDEX IDX_4E7768ACD60322AC ON chill_event_participation (role_id)'); + $this->addSql('CREATE INDEX IDX_4E7768AC6BF700BD ON chill_event_participation (status_id)'); + $this->addSql('ALTER TABLE chill_event_role ' + . 'ADD CONSTRAINT FK_AA714E54C54C8C93 FOREIGN KEY (type_id) ' + . 'REFERENCES chill_event_event_type (id) ' + . 'NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE chill_event_status ' + . 'ADD CONSTRAINT FK_A6CC85D0C54C8C93 ' + . 'FOREIGN KEY (type_id) ' + . 'REFERENCES chill_event_event_type (id) ' + . 'NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE chill_event_participation ' + . 'ADD CONSTRAINT FK_4E7768AC71F7E88B ' + . 'FOREIGN KEY (event_id) ' + . 'REFERENCES chill_event_event (id) ' + . 'NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE chill_event_participation ' + . 'ADD CONSTRAINT FK_4E7768AC217BBB47 ' + . 'FOREIGN KEY (person_id) ' + . 'REFERENCES Person (id) ' + . 'NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE chill_event_participation ' + . 'ADD CONSTRAINT FK_4E7768ACD60322AC ' + . 'FOREIGN KEY (role_id) ' + . 'REFERENCES chill_event_role (id) ' + . 'NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE chill_event_participation ' + . 'ADD CONSTRAINT FK_4E7768AC6BF700BD ' + . 'FOREIGN KEY (status_id) ' + . 'REFERENCES chill_event_status (id) ' + . 'NOT DEFERRABLE INITIALLY IMMEDIATE'); + + } + + /** + * @param Schema $schema + */ + public function down(Schema $schema) + { + // this down() migration is auto-generated, please modify it to your needs + $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); + + $this->addSql('ALTER TABLE chill_event_role DROP CONSTRAINT FK_AA714E54C54C8C93'); + $this->addSql('ALTER TABLE chill_event_status DROP CONSTRAINT FK_A6CC85D0C54C8C93'); + $this->addSql('ALTER TABLE chill_event_participation DROP CONSTRAINT FK_4E7768ACD60322AC'); + $this->addSql('ALTER TABLE chill_event_participation DROP CONSTRAINT FK_4E7768AC6BF700BD'); + $this->addSql('ALTER TABLE chill_event_participation DROP CONSTRAINT FK_4E7768AC71F7E88B'); + $this->addSql('DROP SEQUENCE chill_event_event_type_id_seq CASCADE'); + $this->addSql('DROP SEQUENCE chill_event_role_id_seq CASCADE'); + $this->addSql('DROP SEQUENCE chill_event_status_id_seq CASCADE'); + $this->addSql('DROP SEQUENCE chill_event_event_id_seq CASCADE'); + $this->addSql('DROP SEQUENCE chill_event_participation_id_seq CASCADE'); + $this->addSql('DROP TABLE chill_event_event_type'); + $this->addSql('DROP TABLE chill_event_role'); + $this->addSql('DROP TABLE chill_event_status'); + $this->addSql('DROP TABLE chill_event_event'); + $this->addSql('DROP TABLE chill_event_participation'); + + } +} From 9512528018a2e81859c4e7f2be965684fa9f78ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 18 Mar 2016 11:34:25 +0100 Subject: [PATCH 05/73] add basic crud for admin --- .gitignore | 21 ++ Controller/EventTypeController.php | 224 +++++++++++++++++++ Controller/RoleController.php | 224 +++++++++++++++++++ Controller/StatusController.php | 224 +++++++++++++++++++ DependencyInjection/ChillEventExtension.php | 2 +- Form/EventTypeType.php | 40 ++++ Form/RoleType.php | 41 ++++ Form/StatusType.php | 41 ++++ Resources/config/routing.yml | 15 +- Resources/config/routing/eventtype.yml | 30 +++ Resources/config/routing/role.yml | 30 +++ Resources/config/routing/status.yml | 30 +++ Resources/views/EventType/edit.html.twig | 16 ++ Resources/views/EventType/index.html.twig | 43 ++++ Resources/views/EventType/new.html.twig | 15 ++ Resources/views/EventType/show.html.twig | 36 +++ Resources/views/Role/edit.html.twig | 16 ++ Resources/views/Role/index.html.twig | 43 ++++ Resources/views/Role/new.html.twig | 15 ++ Resources/views/Role/show.html.twig | 36 +++ Resources/views/Status/edit.html.twig | 16 ++ Resources/views/Status/index.html.twig | 43 ++++ Resources/views/Status/new.html.twig | 15 ++ Resources/views/Status/show.html.twig | 36 +++ Tests/Controller/EventTypeControllerTest.php | 55 +++++ Tests/Controller/RoleControllerTest.php | 55 +++++ Tests/Controller/StatusControllerTest.php | 55 +++++ 27 files changed, 1413 insertions(+), 4 deletions(-) create mode 100644 .gitignore create mode 100644 Controller/EventTypeController.php create mode 100644 Controller/RoleController.php create mode 100644 Controller/StatusController.php create mode 100644 Form/EventTypeType.php create mode 100644 Form/RoleType.php create mode 100644 Form/StatusType.php create mode 100644 Resources/config/routing/eventtype.yml create mode 100644 Resources/config/routing/role.yml create mode 100644 Resources/config/routing/status.yml create mode 100644 Resources/views/EventType/edit.html.twig create mode 100644 Resources/views/EventType/index.html.twig create mode 100644 Resources/views/EventType/new.html.twig create mode 100644 Resources/views/EventType/show.html.twig create mode 100644 Resources/views/Role/edit.html.twig create mode 100644 Resources/views/Role/index.html.twig create mode 100644 Resources/views/Role/new.html.twig create mode 100644 Resources/views/Role/show.html.twig create mode 100644 Resources/views/Status/edit.html.twig create mode 100644 Resources/views/Status/index.html.twig create mode 100644 Resources/views/Status/new.html.twig create mode 100644 Resources/views/Status/show.html.twig create mode 100644 Tests/Controller/EventTypeControllerTest.php create mode 100644 Tests/Controller/RoleControllerTest.php create mode 100644 Tests/Controller/StatusControllerTest.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..9f103fd7c --- /dev/null +++ b/.gitignore @@ -0,0 +1,21 @@ +*~ +# MacOS +.DS_Store + +# Bootstrap +app/bootstrap* + +# Symfony directories +vendor/* +*/logs/* +*/cache/* +web/uploads/* +web/bundles/* + +# Configuration files +app/config/parameters.ini +app/config/parameters.yml +Tests/Fixtures/App/config/parameters.yml + +#composer +composer.lock diff --git a/Controller/EventTypeController.php b/Controller/EventTypeController.php new file mode 100644 index 000000000..cbe28999b --- /dev/null +++ b/Controller/EventTypeController.php @@ -0,0 +1,224 @@ +getDoctrine()->getManager(); + + $entities = $em->getRepository('ChillEventBundle:EventType')->findAll(); + + return $this->render('ChillEventBundle:EventType:index.html.twig', array( + 'entities' => $entities, + )); + } + /** + * Creates a new EventType entity. + * + */ + public function createAction(Request $request) + { + $entity = new EventType(); + $form = $this->createCreateForm($entity); + $form->handleRequest($request); + + if ($form->isValid()) { + $em = $this->getDoctrine()->getManager(); + $em->persist($entity); + $em->flush(); + + return $this->redirect($this->generateUrl('{_locale}_admin_show', array('id' => $entity->getId()))); + } + + return $this->render('ChillEventBundle:EventType:new.html.twig', array( + 'entity' => $entity, + 'form' => $form->createView(), + )); + } + + /** + * Creates a form to create a EventType entity. + * + * @param EventType $entity The entity + * + * @return \Symfony\Component\Form\Form The form + */ + private function createCreateForm(EventType $entity) + { + $form = $this->createForm(new EventTypeType(), $entity, array( + 'action' => $this->generateUrl('{_locale}_admin_create'), + 'method' => 'POST', + )); + + $form->add('submit', 'submit', array('label' => 'Create')); + + return $form; + } + + /** + * Displays a form to create a new EventType entity. + * + */ + public function newAction() + { + $entity = new EventType(); + $form = $this->createCreateForm($entity); + + return $this->render('ChillEventBundle:EventType:new.html.twig', array( + 'entity' => $entity, + 'form' => $form->createView(), + )); + } + + /** + * Finds and displays a EventType entity. + * + */ + public function showAction($id) + { + $em = $this->getDoctrine()->getManager(); + + $entity = $em->getRepository('ChillEventBundle:EventType')->find($id); + + if (!$entity) { + throw $this->createNotFoundException('Unable to find EventType entity.'); + } + + $deleteForm = $this->createDeleteForm($id); + + return $this->render('ChillEventBundle:EventType:show.html.twig', array( + 'entity' => $entity, + 'delete_form' => $deleteForm->createView(), + )); + } + + /** + * Displays a form to edit an existing EventType entity. + * + */ + public function editAction($id) + { + $em = $this->getDoctrine()->getManager(); + + $entity = $em->getRepository('ChillEventBundle:EventType')->find($id); + + if (!$entity) { + throw $this->createNotFoundException('Unable to find EventType entity.'); + } + + $editForm = $this->createEditForm($entity); + $deleteForm = $this->createDeleteForm($id); + + return $this->render('ChillEventBundle:EventType:edit.html.twig', array( + 'entity' => $entity, + 'edit_form' => $editForm->createView(), + 'delete_form' => $deleteForm->createView(), + )); + } + + /** + * Creates a form to edit a EventType entity. + * + * @param EventType $entity The entity + * + * @return \Symfony\Component\Form\Form The form + */ + private function createEditForm(EventType $entity) + { + $form = $this->createForm(new EventTypeType(), $entity, array( + 'action' => $this->generateUrl('{_locale}_admin_update', array('id' => $entity->getId())), + 'method' => 'PUT', + )); + + $form->add('submit', 'submit', array('label' => 'Update')); + + return $form; + } + /** + * Edits an existing EventType entity. + * + */ + public function updateAction(Request $request, $id) + { + $em = $this->getDoctrine()->getManager(); + + $entity = $em->getRepository('ChillEventBundle:EventType')->find($id); + + if (!$entity) { + throw $this->createNotFoundException('Unable to find EventType entity.'); + } + + $deleteForm = $this->createDeleteForm($id); + $editForm = $this->createEditForm($entity); + $editForm->handleRequest($request); + + if ($editForm->isValid()) { + $em->flush(); + + return $this->redirect($this->generateUrl('{_locale}_admin_edit', array('id' => $id))); + } + + return $this->render('ChillEventBundle:EventType:edit.html.twig', array( + 'entity' => $entity, + 'edit_form' => $editForm->createView(), + 'delete_form' => $deleteForm->createView(), + )); + } + /** + * Deletes a EventType entity. + * + */ + public function deleteAction(Request $request, $id) + { + $form = $this->createDeleteForm($id); + $form->handleRequest($request); + + if ($form->isValid()) { + $em = $this->getDoctrine()->getManager(); + $entity = $em->getRepository('ChillEventBundle:EventType')->find($id); + + if (!$entity) { + throw $this->createNotFoundException('Unable to find EventType entity.'); + } + + $em->remove($entity); + $em->flush(); + } + + return $this->redirect($this->generateUrl('{_locale}_admin')); + } + + /** + * Creates a form to delete a EventType entity by id. + * + * @param mixed $id The entity id + * + * @return \Symfony\Component\Form\Form The form + */ + private function createDeleteForm($id) + { + return $this->createFormBuilder() + ->setAction($this->generateUrl('{_locale}_admin_delete', array('id' => $id))) + ->setMethod('DELETE') + ->add('submit', 'submit', array('label' => 'Delete')) + ->getForm() + ; + } +} diff --git a/Controller/RoleController.php b/Controller/RoleController.php new file mode 100644 index 000000000..3834e89a9 --- /dev/null +++ b/Controller/RoleController.php @@ -0,0 +1,224 @@ +getDoctrine()->getManager(); + + $entities = $em->getRepository('ChillEventBundle:Role')->findAll(); + + return $this->render('ChillEventBundle:Role:index.html.twig', array( + 'entities' => $entities, + )); + } + /** + * Creates a new Role entity. + * + */ + public function createAction(Request $request) + { + $entity = new Role(); + $form = $this->createCreateForm($entity); + $form->handleRequest($request); + + if ($form->isValid()) { + $em = $this->getDoctrine()->getManager(); + $em->persist($entity); + $em->flush(); + + return $this->redirect($this->generateUrl('{_locale}_admin_role_show', array('id' => $entity->getId()))); + } + + return $this->render('ChillEventBundle:Role:new.html.twig', array( + 'entity' => $entity, + 'form' => $form->createView(), + )); + } + + /** + * Creates a form to create a Role entity. + * + * @param Role $entity The entity + * + * @return \Symfony\Component\Form\Form The form + */ + private function createCreateForm(Role $entity) + { + $form = $this->createForm(new RoleType(), $entity, array( + 'action' => $this->generateUrl('{_locale}_admin_role_create'), + 'method' => 'POST', + )); + + $form->add('submit', 'submit', array('label' => 'Create')); + + return $form; + } + + /** + * Displays a form to create a new Role entity. + * + */ + public function newAction() + { + $entity = new Role(); + $form = $this->createCreateForm($entity); + + return $this->render('ChillEventBundle:Role:new.html.twig', array( + 'entity' => $entity, + 'form' => $form->createView(), + )); + } + + /** + * Finds and displays a Role entity. + * + */ + public function showAction($id) + { + $em = $this->getDoctrine()->getManager(); + + $entity = $em->getRepository('ChillEventBundle:Role')->find($id); + + if (!$entity) { + throw $this->createNotFoundException('Unable to find Role entity.'); + } + + $deleteForm = $this->createDeleteForm($id); + + return $this->render('ChillEventBundle:Role:show.html.twig', array( + 'entity' => $entity, + 'delete_form' => $deleteForm->createView(), + )); + } + + /** + * Displays a form to edit an existing Role entity. + * + */ + public function editAction($id) + { + $em = $this->getDoctrine()->getManager(); + + $entity = $em->getRepository('ChillEventBundle:Role')->find($id); + + if (!$entity) { + throw $this->createNotFoundException('Unable to find Role entity.'); + } + + $editForm = $this->createEditForm($entity); + $deleteForm = $this->createDeleteForm($id); + + return $this->render('ChillEventBundle:Role:edit.html.twig', array( + 'entity' => $entity, + 'edit_form' => $editForm->createView(), + 'delete_form' => $deleteForm->createView(), + )); + } + + /** + * Creates a form to edit a Role entity. + * + * @param Role $entity The entity + * + * @return \Symfony\Component\Form\Form The form + */ + private function createEditForm(Role $entity) + { + $form = $this->createForm(new RoleType(), $entity, array( + 'action' => $this->generateUrl('{_locale}_admin_role_update', array('id' => $entity->getId())), + 'method' => 'PUT', + )); + + $form->add('submit', 'submit', array('label' => 'Update')); + + return $form; + } + /** + * Edits an existing Role entity. + * + */ + public function updateAction(Request $request, $id) + { + $em = $this->getDoctrine()->getManager(); + + $entity = $em->getRepository('ChillEventBundle:Role')->find($id); + + if (!$entity) { + throw $this->createNotFoundException('Unable to find Role entity.'); + } + + $deleteForm = $this->createDeleteForm($id); + $editForm = $this->createEditForm($entity); + $editForm->handleRequest($request); + + if ($editForm->isValid()) { + $em->flush(); + + return $this->redirect($this->generateUrl('{_locale}_admin_role_edit', array('id' => $id))); + } + + return $this->render('ChillEventBundle:Role:edit.html.twig', array( + 'entity' => $entity, + 'edit_form' => $editForm->createView(), + 'delete_form' => $deleteForm->createView(), + )); + } + /** + * Deletes a Role entity. + * + */ + public function deleteAction(Request $request, $id) + { + $form = $this->createDeleteForm($id); + $form->handleRequest($request); + + if ($form->isValid()) { + $em = $this->getDoctrine()->getManager(); + $entity = $em->getRepository('ChillEventBundle:Role')->find($id); + + if (!$entity) { + throw $this->createNotFoundException('Unable to find Role entity.'); + } + + $em->remove($entity); + $em->flush(); + } + + return $this->redirect($this->generateUrl('{_locale}_admin_role')); + } + + /** + * Creates a form to delete a Role entity by id. + * + * @param mixed $id The entity id + * + * @return \Symfony\Component\Form\Form The form + */ + private function createDeleteForm($id) + { + return $this->createFormBuilder() + ->setAction($this->generateUrl('{_locale}_admin_role_delete', array('id' => $id))) + ->setMethod('DELETE') + ->add('submit', 'submit', array('label' => 'Delete')) + ->getForm() + ; + } +} diff --git a/Controller/StatusController.php b/Controller/StatusController.php new file mode 100644 index 000000000..e0a57ba51 --- /dev/null +++ b/Controller/StatusController.php @@ -0,0 +1,224 @@ +getDoctrine()->getManager(); + + $entities = $em->getRepository('ChillEventBundle:Status')->findAll(); + + return $this->render('ChillEventBundle:Status:index.html.twig', array( + 'entities' => $entities, + )); + } + /** + * Creates a new Status entity. + * + */ + public function createAction(Request $request) + { + $entity = new Status(); + $form = $this->createCreateForm($entity); + $form->handleRequest($request); + + if ($form->isValid()) { + $em = $this->getDoctrine()->getManager(); + $em->persist($entity); + $em->flush(); + + return $this->redirect($this->generateUrl('fr_admin_event_status_show', array('id' => $entity->getId()))); + } + + return $this->render('ChillEventBundle:Status:new.html.twig', array( + 'entity' => $entity, + 'form' => $form->createView(), + )); + } + + /** + * Creates a form to create a Status entity. + * + * @param Status $entity The entity + * + * @return \Symfony\Component\Form\Form The form + */ + private function createCreateForm(Status $entity) + { + $form = $this->createForm(new StatusType(), $entity, array( + 'action' => $this->generateUrl('fr_admin_event_status_create'), + 'method' => 'POST', + )); + + $form->add('submit', 'submit', array('label' => 'Create')); + + return $form; + } + + /** + * Displays a form to create a new Status entity. + * + */ + public function newAction() + { + $entity = new Status(); + $form = $this->createCreateForm($entity); + + return $this->render('ChillEventBundle:Status:new.html.twig', array( + 'entity' => $entity, + 'form' => $form->createView(), + )); + } + + /** + * Finds and displays a Status entity. + * + */ + public function showAction($id) + { + $em = $this->getDoctrine()->getManager(); + + $entity = $em->getRepository('ChillEventBundle:Status')->find($id); + + if (!$entity) { + throw $this->createNotFoundException('Unable to find Status entity.'); + } + + $deleteForm = $this->createDeleteForm($id); + + return $this->render('ChillEventBundle:Status:show.html.twig', array( + 'entity' => $entity, + 'delete_form' => $deleteForm->createView(), + )); + } + + /** + * Displays a form to edit an existing Status entity. + * + */ + public function editAction($id) + { + $em = $this->getDoctrine()->getManager(); + + $entity = $em->getRepository('ChillEventBundle:Status')->find($id); + + if (!$entity) { + throw $this->createNotFoundException('Unable to find Status entity.'); + } + + $editForm = $this->createEditForm($entity); + $deleteForm = $this->createDeleteForm($id); + + return $this->render('ChillEventBundle:Status:edit.html.twig', array( + 'entity' => $entity, + 'edit_form' => $editForm->createView(), + 'delete_form' => $deleteForm->createView(), + )); + } + + /** + * Creates a form to edit a Status entity. + * + * @param Status $entity The entity + * + * @return \Symfony\Component\Form\Form The form + */ + private function createEditForm(Status $entity) + { + $form = $this->createForm(new StatusType(), $entity, array( + 'action' => $this->generateUrl('fr_admin_event_status_update', array('id' => $entity->getId())), + 'method' => 'PUT', + )); + + $form->add('submit', 'submit', array('label' => 'Update')); + + return $form; + } + /** + * Edits an existing Status entity. + * + */ + public function updateAction(Request $request, $id) + { + $em = $this->getDoctrine()->getManager(); + + $entity = $em->getRepository('ChillEventBundle:Status')->find($id); + + if (!$entity) { + throw $this->createNotFoundException('Unable to find Status entity.'); + } + + $deleteForm = $this->createDeleteForm($id); + $editForm = $this->createEditForm($entity); + $editForm->handleRequest($request); + + if ($editForm->isValid()) { + $em->flush(); + + return $this->redirect($this->generateUrl('fr_admin_event_status_edit', array('id' => $id))); + } + + return $this->render('ChillEventBundle:Status:edit.html.twig', array( + 'entity' => $entity, + 'edit_form' => $editForm->createView(), + 'delete_form' => $deleteForm->createView(), + )); + } + /** + * Deletes a Status entity. + * + */ + public function deleteAction(Request $request, $id) + { + $form = $this->createDeleteForm($id); + $form->handleRequest($request); + + if ($form->isValid()) { + $em = $this->getDoctrine()->getManager(); + $entity = $em->getRepository('ChillEventBundle:Status')->find($id); + + if (!$entity) { + throw $this->createNotFoundException('Unable to find Status entity.'); + } + + $em->remove($entity); + $em->flush(); + } + + return $this->redirect($this->generateUrl('fr_admin_event_status')); + } + + /** + * Creates a form to delete a Status entity by id. + * + * @param mixed $id The entity id + * + * @return \Symfony\Component\Form\Form The form + */ + private function createDeleteForm($id) + { + return $this->createFormBuilder() + ->setAction($this->generateUrl('fr_admin_event_status_delete', array('id' => $id))) + ->setMethod('DELETE') + ->add('submit', 'submit', array('label' => 'Delete')) + ->getForm() + ; + } +} diff --git a/DependencyInjection/ChillEventExtension.php b/DependencyInjection/ChillEventExtension.php index 89eb98c57..1035659fd 100644 --- a/DependencyInjection/ChillEventExtension.php +++ b/DependencyInjection/ChillEventExtension.php @@ -13,7 +13,7 @@ use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; * * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} */ -class ChillEventExtension extends Extension +class ChillEventExtension extends Extension implements PrependExtensionInterface { /** * {@inheritdoc} diff --git a/Form/EventTypeType.php b/Form/EventTypeType.php new file mode 100644 index 000000000..02ec828e8 --- /dev/null +++ b/Form/EventTypeType.php @@ -0,0 +1,40 @@ +add('label') + ->add('active') + ; + } + + /** + * @param OptionsResolverInterface $resolver + */ + public function setDefaultOptions(OptionsResolverInterface $resolver) + { + $resolver->setDefaults(array( + 'data_class' => 'Chill\EventBundle\Entity\EventType' + )); + } + + /** + * @return string + */ + public function getName() + { + return 'chill_eventbundle_eventtype'; + } +} diff --git a/Form/RoleType.php b/Form/RoleType.php new file mode 100644 index 000000000..293aec1d1 --- /dev/null +++ b/Form/RoleType.php @@ -0,0 +1,41 @@ +add('label') + ->add('active') + ->add('type') + ; + } + + /** + * @param OptionsResolverInterface $resolver + */ + public function setDefaultOptions(OptionsResolverInterface $resolver) + { + $resolver->setDefaults(array( + 'data_class' => 'Chill\EventBundle\Entity\Role' + )); + } + + /** + * @return string + */ + public function getName() + { + return 'chill_eventbundle_role'; + } +} diff --git a/Form/StatusType.php b/Form/StatusType.php new file mode 100644 index 000000000..24bdcd604 --- /dev/null +++ b/Form/StatusType.php @@ -0,0 +1,41 @@ +add('label') + ->add('active') + ->add('type') + ; + } + + /** + * @param OptionsResolverInterface $resolver + */ + public function setDefaultOptions(OptionsResolverInterface $resolver) + { + $resolver->setDefaults(array( + 'data_class' => 'Chill\EventBundle\Entity\Status' + )); + } + + /** + * @return string + */ + public function getName() + { + return 'chill_eventbundle_status'; + } +} diff --git a/Resources/config/routing.yml b/Resources/config/routing.yml index 712a131e6..f6262b049 100644 --- a/Resources/config/routing.yml +++ b/Resources/config/routing.yml @@ -1,3 +1,12 @@ -chill_event_homepage: - path: /hello/{name} - defaults: { _controller: ChillEventBundle:Default:index } +chill_event_fr_admin_event_status: + resource: "@ChillEventBundle/Resources/config/routing/status.yml" + prefix: /{_locale}/admin/event/status + +chill_event_admin_role: + resource: "@ChillEventBundle/Resources/config/routing/role.yml" + prefix: /{_locale}/admin/event/role + +chill_event_admin_event_type: + resource: "@ChillEventBundle/Resources/config/routing/eventtype.yml" + prefix: /{_locale}/admin/event/event_type + diff --git a/Resources/config/routing/eventtype.yml b/Resources/config/routing/eventtype.yml new file mode 100644 index 000000000..cdf54fe85 --- /dev/null +++ b/Resources/config/routing/eventtype.yml @@ -0,0 +1,30 @@ +chill_event_admin: + path: / + defaults: { _controller: "ChillEventBundle:EventType:index" } + +chill_event_admin_show: + path: /{id}/show + defaults: { _controller: "ChillEventBundle:EventType:show" } + +chill_event_admin_new: + path: /new + defaults: { _controller: "ChillEventBundle:EventType:new" } + +chill_event_admin_create: + path: /create + defaults: { _controller: "ChillEventBundle:EventType:create" } + methods: POST + +chill_event_admin_edit: + path: /{id}/edit + defaults: { _controller: "ChillEventBundle:EventType:edit" } + +chill_event_admin_update: + path: /{id}/update + defaults: { _controller: "ChillEventBundle:EventType:update" } + methods: [POST, PUT] + +chill_event_admin_delete: + path: /{id}/delete + defaults: { _controller: "ChillEventBundle:EventType:delete" } + methods: [POST, DELETE] diff --git a/Resources/config/routing/role.yml b/Resources/config/routing/role.yml new file mode 100644 index 000000000..bfc51216d --- /dev/null +++ b/Resources/config/routing/role.yml @@ -0,0 +1,30 @@ +chill_event_admin_role: + path: / + defaults: { _controller: "ChillEventBundle:Role:index" } + +chill_event_admin_role_show: + path: /{id}/show + defaults: { _controller: "ChillEventBundle:Role:show" } + +chill_event_admin_role_new: + path: /new + defaults: { _controller: "ChillEventBundle:Role:new" } + +chill_event_admin_role_create: + path: /create + defaults: { _controller: "ChillEventBundle:Role:create" } + methods: POST + +chill_event_admin_role_edit: + path: /{id}/edit + defaults: { _controller: "ChillEventBundle:Role:edit" } + +chill_event_admin_role_update: + path: /{id}/update + defaults: { _controller: "ChillEventBundle:Role:update" } + methods: [POST, PUT] + +chill_event_admin_role_delete: + path: /{id}/delete + defaults: { _controller: "ChillEventBundle:Role:delete" } + methods: [POST, DELETE] diff --git a/Resources/config/routing/status.yml b/Resources/config/routing/status.yml new file mode 100644 index 000000000..396f72c39 --- /dev/null +++ b/Resources/config/routing/status.yml @@ -0,0 +1,30 @@ +fr_admin_event_status: + path: / + defaults: { _controller: "ChillEventBundle:Status:index" } + +fr_admin_event_status_show: + path: /{id}/show + defaults: { _controller: "ChillEventBundle:Status:show" } + +fr_admin_event_status_new: + path: /new + defaults: { _controller: "ChillEventBundle:Status:new" } + +fr_admin_event_status_create: + path: /create + defaults: { _controller: "ChillEventBundle:Status:create" } + methods: POST + +fr_admin_event_status_edit: + path: /{id}/edit + defaults: { _controller: "ChillEventBundle:Status:edit" } + +fr_admin_event_status_update: + path: /{id}/update + defaults: { _controller: "ChillEventBundle:Status:update" } + methods: [POST, PUT] + +fr_admin_event_status_delete: + path: /{id}/delete + defaults: { _controller: "ChillEventBundle:Status:delete" } + methods: [POST, DELETE] diff --git a/Resources/views/EventType/edit.html.twig b/Resources/views/EventType/edit.html.twig new file mode 100644 index 000000000..5849fa686 --- /dev/null +++ b/Resources/views/EventType/edit.html.twig @@ -0,0 +1,16 @@ +{% extends '::base.html.twig' %} + +{% block body -%} +

EventType edit

+ + {{ form(edit_form) }} + + +{% endblock %} diff --git a/Resources/views/EventType/index.html.twig b/Resources/views/EventType/index.html.twig new file mode 100644 index 000000000..72c47e279 --- /dev/null +++ b/Resources/views/EventType/index.html.twig @@ -0,0 +1,43 @@ +{% extends '::base.html.twig' %} + +{% block body -%} +

EventType list

+ + + + + + + + + + + + {% for entity in entities %} + + + + + + + {% endfor %} + +
IdLabelActiveActions
{{ entity.id }}{{ entity.label }}{{ entity.active }} + +
+ + + {% endblock %} diff --git a/Resources/views/EventType/new.html.twig b/Resources/views/EventType/new.html.twig new file mode 100644 index 000000000..4e097dd92 --- /dev/null +++ b/Resources/views/EventType/new.html.twig @@ -0,0 +1,15 @@ +{% extends '::base.html.twig' %} + +{% block body -%} +

EventType creation

+ + {{ form(form) }} + + +{% endblock %} diff --git a/Resources/views/EventType/show.html.twig b/Resources/views/EventType/show.html.twig new file mode 100644 index 000000000..818e30fa9 --- /dev/null +++ b/Resources/views/EventType/show.html.twig @@ -0,0 +1,36 @@ +{% extends '::base.html.twig' %} + +{% block body -%} +

EventType

+ + + + + + + + + + + + + + + + +
Id{{ entity.id }}
Label{{ entity.label }}
Active{{ entity.active }}
+ + +{% endblock %} diff --git a/Resources/views/Role/edit.html.twig b/Resources/views/Role/edit.html.twig new file mode 100644 index 000000000..1bf9dc66d --- /dev/null +++ b/Resources/views/Role/edit.html.twig @@ -0,0 +1,16 @@ +{% extends '::base.html.twig' %} + +{% block body -%} +

Role edit

+ + {{ form(edit_form) }} + + +{% endblock %} diff --git a/Resources/views/Role/index.html.twig b/Resources/views/Role/index.html.twig new file mode 100644 index 000000000..dcfda2a25 --- /dev/null +++ b/Resources/views/Role/index.html.twig @@ -0,0 +1,43 @@ +{% extends '::base.html.twig' %} + +{% block body -%} +

Role list

+ + + + + + + + + + + + {% for entity in entities %} + + + + + + + {% endfor %} + +
IdLabelActiveActions
{{ entity.id }}{{ entity.label }}{{ entity.active }} + +
+ + + {% endblock %} diff --git a/Resources/views/Role/new.html.twig b/Resources/views/Role/new.html.twig new file mode 100644 index 000000000..a9ea41a1b --- /dev/null +++ b/Resources/views/Role/new.html.twig @@ -0,0 +1,15 @@ +{% extends '::base.html.twig' %} + +{% block body -%} +

Role creation

+ + {{ form(form) }} + + +{% endblock %} diff --git a/Resources/views/Role/show.html.twig b/Resources/views/Role/show.html.twig new file mode 100644 index 000000000..a212c2f6d --- /dev/null +++ b/Resources/views/Role/show.html.twig @@ -0,0 +1,36 @@ +{% extends '::base.html.twig' %} + +{% block body -%} +

Role

+ + + + + + + + + + + + + + + + +
Id{{ entity.id }}
Label{{ entity.label }}
Active{{ entity.active }}
+ + +{% endblock %} diff --git a/Resources/views/Status/edit.html.twig b/Resources/views/Status/edit.html.twig new file mode 100644 index 000000000..f9c2f7bda --- /dev/null +++ b/Resources/views/Status/edit.html.twig @@ -0,0 +1,16 @@ +{% extends '::base.html.twig' %} + +{% block body -%} +

Status edit

+ + {{ form(edit_form) }} + + +{% endblock %} diff --git a/Resources/views/Status/index.html.twig b/Resources/views/Status/index.html.twig new file mode 100644 index 000000000..e5ec9e480 --- /dev/null +++ b/Resources/views/Status/index.html.twig @@ -0,0 +1,43 @@ +{% extends '::base.html.twig' %} + +{% block body -%} +

Status list

+ + + + + + + + + + + + {% for entity in entities %} + + + + + + + {% endfor %} + +
IdLabelActiveActions
{{ entity.id }}{{ entity.label }}{{ entity.active }} + +
+ + + {% endblock %} diff --git a/Resources/views/Status/new.html.twig b/Resources/views/Status/new.html.twig new file mode 100644 index 000000000..7cd7093b1 --- /dev/null +++ b/Resources/views/Status/new.html.twig @@ -0,0 +1,15 @@ +{% extends '::base.html.twig' %} + +{% block body -%} +

Status creation

+ + {{ form(form) }} + + +{% endblock %} diff --git a/Resources/views/Status/show.html.twig b/Resources/views/Status/show.html.twig new file mode 100644 index 000000000..7b0dd4049 --- /dev/null +++ b/Resources/views/Status/show.html.twig @@ -0,0 +1,36 @@ +{% extends '::base.html.twig' %} + +{% block body -%} +

Status

+ + + + + + + + + + + + + + + + +
Id{{ entity.id }}
Label{{ entity.label }}
Active{{ entity.active }}
+ + +{% endblock %} diff --git a/Tests/Controller/EventTypeControllerTest.php b/Tests/Controller/EventTypeControllerTest.php new file mode 100644 index 000000000..2075dfdbe --- /dev/null +++ b/Tests/Controller/EventTypeControllerTest.php @@ -0,0 +1,55 @@ +request('GET', '/{_locale}/admin/'); + $this->assertEquals(200, $client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET /{_locale}/admin/"); + $crawler = $client->click($crawler->selectLink('Create a new entry')->link()); + + // Fill in the form and submit it + $form = $crawler->selectButton('Create')->form(array( + 'chill_eventbundle_eventtype[field_name]' => 'Test', + // ... other fields to fill + )); + + $client->submit($form); + $crawler = $client->followRedirect(); + + // Check data in the show view + $this->assertGreaterThan(0, $crawler->filter('td:contains("Test")')->count(), 'Missing element td:contains("Test")'); + + // Edit the entity + $crawler = $client->click($crawler->selectLink('Edit')->link()); + + $form = $crawler->selectButton('Update')->form(array( + 'chill_eventbundle_eventtype[field_name]' => 'Foo', + // ... other fields to fill + )); + + $client->submit($form); + $crawler = $client->followRedirect(); + + // Check the element contains an attribute with value equals "Foo" + $this->assertGreaterThan(0, $crawler->filter('[value="Foo"]')->count(), 'Missing element [value="Foo"]'); + + // Delete the entity + $client->submit($crawler->selectButton('Delete')->form()); + $crawler = $client->followRedirect(); + + // Check the entity has been delete on the list + $this->assertNotRegExp('/Foo/', $client->getResponse()->getContent()); + } + + */ +} diff --git a/Tests/Controller/RoleControllerTest.php b/Tests/Controller/RoleControllerTest.php new file mode 100644 index 000000000..39d21ff7b --- /dev/null +++ b/Tests/Controller/RoleControllerTest.php @@ -0,0 +1,55 @@ +request('GET', '/{_locale}/admin/role/'); + $this->assertEquals(200, $client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET /{_locale}/admin/role/"); + $crawler = $client->click($crawler->selectLink('Create a new entry')->link()); + + // Fill in the form and submit it + $form = $crawler->selectButton('Create')->form(array( + 'chill_eventbundle_role[field_name]' => 'Test', + // ... other fields to fill + )); + + $client->submit($form); + $crawler = $client->followRedirect(); + + // Check data in the show view + $this->assertGreaterThan(0, $crawler->filter('td:contains("Test")')->count(), 'Missing element td:contains("Test")'); + + // Edit the entity + $crawler = $client->click($crawler->selectLink('Edit')->link()); + + $form = $crawler->selectButton('Update')->form(array( + 'chill_eventbundle_role[field_name]' => 'Foo', + // ... other fields to fill + )); + + $client->submit($form); + $crawler = $client->followRedirect(); + + // Check the element contains an attribute with value equals "Foo" + $this->assertGreaterThan(0, $crawler->filter('[value="Foo"]')->count(), 'Missing element [value="Foo"]'); + + // Delete the entity + $client->submit($crawler->selectButton('Delete')->form()); + $crawler = $client->followRedirect(); + + // Check the entity has been delete on the list + $this->assertNotRegExp('/Foo/', $client->getResponse()->getContent()); + } + + */ +} diff --git a/Tests/Controller/StatusControllerTest.php b/Tests/Controller/StatusControllerTest.php new file mode 100644 index 000000000..fc2c94259 --- /dev/null +++ b/Tests/Controller/StatusControllerTest.php @@ -0,0 +1,55 @@ +request('GET', '/fr/admin/event/status/'); + $this->assertEquals(200, $client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET /fr/admin/event/status/"); + $crawler = $client->click($crawler->selectLink('Create a new entry')->link()); + + // Fill in the form and submit it + $form = $crawler->selectButton('Create')->form(array( + 'chill_eventbundle_status[field_name]' => 'Test', + // ... other fields to fill + )); + + $client->submit($form); + $crawler = $client->followRedirect(); + + // Check data in the show view + $this->assertGreaterThan(0, $crawler->filter('td:contains("Test")')->count(), 'Missing element td:contains("Test")'); + + // Edit the entity + $crawler = $client->click($crawler->selectLink('Edit')->link()); + + $form = $crawler->selectButton('Update')->form(array( + 'chill_eventbundle_status[field_name]' => 'Foo', + // ... other fields to fill + )); + + $client->submit($form); + $crawler = $client->followRedirect(); + + // Check the element contains an attribute with value equals "Foo" + $this->assertGreaterThan(0, $crawler->filter('[value="Foo"]')->count(), 'Missing element [value="Foo"]'); + + // Delete the entity + $client->submit($crawler->selectButton('Delete')->form()); + $crawler = $client->followRedirect(); + + // Check the entity has been delete on the list + $this->assertNotRegExp('/Foo/', $client->getResponse()->getContent()); + } + + */ +} From d7fc04cdaa478b48c41d072157ab38b202c167e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 22 Mar 2016 09:59:00 +0100 Subject: [PATCH 06/73] add fixtures for events fix #17 --- DataFixtures/ORM/LoadEventTypes.php | 97 +++++++++++++++++++++++++ DataFixtures/ORM/LoadParticipation.php | 92 +++++++++++++++++++++++ Entity/Event.php | 50 ++++++++++++- Entity/EventType.php | 36 ++++----- Entity/Participation.php | 19 ++++- Resources/config/doctrine/Event.orm.yml | 5 ++ 6 files changed, 278 insertions(+), 21 deletions(-) create mode 100644 DataFixtures/ORM/LoadEventTypes.php create mode 100644 DataFixtures/ORM/LoadParticipation.php diff --git a/DataFixtures/ORM/LoadEventTypes.php b/DataFixtures/ORM/LoadEventTypes.php new file mode 100644 index 000000000..38e171d97 --- /dev/null +++ b/DataFixtures/ORM/LoadEventTypes.php @@ -0,0 +1,97 @@ + + * @author Champs Libres + */ +class LoadEventTypes extends AbstractFixture implements OrderedFixtureInterface +{ + public static $refs = array(); + + public function getOrder() + { + return 30000; + } + + public function load(ObjectManager $manager) + { + $type = (new EventType()) + ->setActive(true) + ->setLabel(array('fr' => 'Échange de savoirs', 'en' => 'Exchange of knowledge')) + ; + $manager->persist($type); + $this->addReference('event_type_knowledge', $type); + self::$refs[] = 'event_type_knowledge'; + + $role = (new Role()) + ->setActive(true) + ->setLabel(array('fr' => 'Participant', 'nl' => 'Deelneemer', 'en' => 'Participant')) + ->setType($type) + ; + $manager->persist($role); + + $role = (new Role()) + ->setActive(true) + ->setLabel(array('fr' => 'Animateur')) + ->setType($type); + $manager->persist($role); + + $status = (new Status()) + ->setActive(true) + ->setLabel(array('fr' => 'Inscrit')) + ->setType($type); + $manager->persist($status); + + $status = (new Status()) + ->setActive(true) + ->setLabel(array('fr' => 'Présent')) + ->setType($type) + ; + $manager->persist($status); + + + $type = (new EventType()) + ->setActive(true) + ->setLabel(array('fr' => 'Formation', 'en' => 'Course', 'nl' => 'Opleiding')) + ; + $manager->persist($type); + $this->addReference('event_type_course', $type); + self::$refs[] = 'event_type_course'; + + $role = (new Role()) + ->setActive(true) + ->setLabel(array('fr' => 'Participant', 'nl' => 'Deelneemer', 'en' => 'Participant')) + ->setType($type) + ; + $manager->persist($role); + + $status = (new Status()) + ->setActive(true) + ->setLabel(array('fr' => 'Inscrit')) + ->setType($type) + ; + $manager->persist($status); + + $status = (new Status()) + ->setActive(true) + ->setLabel(array('fr' => 'En liste d\'attente')) + ->setType($type) + ; + $manager->persist($status); + + $manager->flush(); + } + +} diff --git a/DataFixtures/ORM/LoadParticipation.php b/DataFixtures/ORM/LoadParticipation.php new file mode 100644 index 000000000..618b44d7c --- /dev/null +++ b/DataFixtures/ORM/LoadParticipation.php @@ -0,0 +1,92 @@ + + * @author Champs Libres + */ +class LoadParticipation extends AbstractFixture implements OrderedFixtureInterface +{ + /** + * + * @var \Faker\Generator + */ + protected $faker; + + public function __construct() + { + $this->faker = \Faker\Factory::create('fr_FR'); + } + + public function getOrder() + { + return 30010; + } + + public function load(ObjectManager $manager) + { + $centers = $manager->getRepository('ChillMainBundle:Center') + ->findAll(); + + foreach($centers as $center) { + + $people = $manager->getRepository('ChillPersonBundle:Person') + ->findBy(array('center' => $center)); + $events = $this->createEvents($center, $manager); + + /* @var $person \Chill\PersonBundle\Entity\Person */ + foreach ($people as $person) { + $nb = rand(0,3); + + for ($i=0; $i<$nb; $i++) { + $event = $events[array_rand($events)]; + $role = $event->getType()->getRoles()->get( + array_rand($event->getType()->getRoles()->toArray())); + $status = $event->getType()->getStatuses()->get( + array_rand($event->getType()->getStatuses()->toArray())); + + $participation = (new Participation()) + ->setPerson($person) + ->setRole($role) + ->setStatus($status) + ->setEvent($event) + ; + $manager->persist($participation); + } + } + } + + $manager->flush(); + + + } + + public function createEvents(Center $center, ObjectManager $manager) + { + $expectedNumber = 20; + $events = array(); + + for($i=0; $i<$expectedNumber; $i++) { + $event = (new Event()) + ->setDate($this->faker->dateTimeBetween('-2 years', '+6 months')) + ->setLabel($this->faker->words(rand(2,4), true)) + ->setType($this->getReference(LoadEventTypes::$refs[array_rand(LoadEventTypes::$refs)])) + ->setCenter($center) + ; + $manager->persist($event); + $events[] = $event; + } + + return $events; + } +} diff --git a/Entity/Event.php b/Entity/Event.php index d3e6a8881..ec8c16f43 100644 --- a/Entity/Event.php +++ b/Entity/Event.php @@ -22,6 +22,18 @@ class Event */ private $date; + /** + * + * @var \Chill\MainBundle\Entity\Center + */ + private $center; + + /** + * + * @var EventType + */ + private $type; + /** * @var \Doctrine\Common\Collections\Collection */ @@ -77,7 +89,7 @@ class Event * * @return Event */ - public function setDate($date) + public function setDate(\DateTime $date) { $this->date = $date; @@ -93,6 +105,42 @@ class Event { return $this->date; } + + public function setCenter(\Chill\MainBundle\Entity\Center $center) + { + $this->center = $center; + + return $this; + } + + /** + * + * @return EventType + */ + public function getType() + { + return $this->type; + } + + /** + * + * @param \Chill\EventBundle\Entity\EventType $type + * @return \Chill\EventBundle\Entity\Event + */ + public function setType(EventType $type) + { + $this->type = $type; + return $this; + } + + /** + * + * @return \Chill\MainBundle\Entity\Center + */ + public function getCenter() + { + return $this->center; + } /** * Add participation diff --git a/Entity/EventType.php b/Entity/EventType.php index 64c240b53..e7646c03a 100644 --- a/Entity/EventType.php +++ b/Entity/EventType.php @@ -21,7 +21,25 @@ class EventType * @var boolean */ private $active; + + /** + * @var \Doctrine\Common\Collections\Collection + */ + private $roles; + /** + * @var \Doctrine\Common\Collections\Collection + */ + private $statuses; + + /** + * Constructor + */ + public function __construct() + { + $this->roles = new \Doctrine\Common\Collections\ArrayCollection(); + $this->statuses = new \Doctrine\Common\Collections\ArrayCollection(); + } /** * Get id @@ -80,24 +98,6 @@ class EventType { return $this->active; } - /** - * @var \Doctrine\Common\Collections\Collection - */ - private $roles; - - /** - * @var \Doctrine\Common\Collections\Collection - */ - private $statuses; - - /** - * Constructor - */ - public function __construct() - { - $this->roles = new \Doctrine\Common\Collections\ArrayCollection(); - $this->statuses = new \Doctrine\Common\Collections\ArrayCollection(); - } /** * Add role diff --git a/Entity/Participation.php b/Entity/Participation.php index 2c6fdb2f5..cc8b8544e 100644 --- a/Entity/Participation.php +++ b/Entity/Participation.php @@ -55,9 +55,9 @@ class Participation * * @return Participation */ - public function setLastUpdate($lastUpdate) + protected function update() { - $this->lastUpdate = $lastUpdate; + $this->lastUpdate = new \DateTime('now'); return $this; } @@ -82,6 +82,10 @@ class Participation */ public function setEvent(\Chill\EventBundle\Entity\Event $event = null) { + if ($this->event !== $event) { + $this->update(); + } + $this->event = $event; return $this; @@ -106,6 +110,10 @@ class Participation */ public function setPerson(\Chill\PersonBundle\Entity\Person $person = null) { + if ($person !== $this->person) { + $this->update(); + } + $this->person = $person; return $this; @@ -130,6 +138,9 @@ class Participation */ public function setRole(\Chill\EventBundle\Entity\Role $role = null) { + if ($role !== $this->role) { + $this->update(); + } $this->role = $role; return $this; @@ -154,6 +165,10 @@ class Participation */ public function setStatus(\Chill\EventBundle\Entity\Status $status = null) { + if ($this->status !== $status) { + $this->update(); + } + $this->status = $status; return $this; diff --git a/Resources/config/doctrine/Event.orm.yml b/Resources/config/doctrine/Event.orm.yml index 3bc880597..b4325981c 100644 --- a/Resources/config/doctrine/Event.orm.yml +++ b/Resources/config/doctrine/Event.orm.yml @@ -17,4 +17,9 @@ Chill\EventBundle\Entity\Event: participations: targetEntity: Chill\EventBundle\Entity\Participation mappedBy: event + manyToOne: + center: + targetEntity: Chill\MainBundle\Entity\Center + type: + targetEntity: Chill\EventBundle\Entity\EventType lifecycleCallbacks: { } From e66a855c0a4b37b0a789c97736ad0e7a7ed15684 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 22 Mar 2016 12:36:11 +0100 Subject: [PATCH 07/73] adding a scope/circle to events ref #1 --- DataFixtures/ORM/LoadParticipation.php | 6 ++++ Entity/Event.php | 37 +++++++++++++++++++++++++ Resources/config/doctrine/Event.orm.yml | 2 ++ 3 files changed, 45 insertions(+) diff --git a/DataFixtures/ORM/LoadParticipation.php b/DataFixtures/ORM/LoadParticipation.php index 618b44d7c..98f19a82e 100644 --- a/DataFixtures/ORM/LoadParticipation.php +++ b/DataFixtures/ORM/LoadParticipation.php @@ -8,6 +8,7 @@ use Doctrine\Common\DataFixtures\OrderedFixtureInterface; use Chill\EventBundle\Entity\Participation; use Chill\MainBundle\Entity\Center; use Chill\EventBundle\Entity\Event; +use Chill\MainBundle\DataFixtures\ORM\LoadScopes; /** * Load Events and Participation @@ -82,6 +83,11 @@ class LoadParticipation extends AbstractFixture implements OrderedFixtureInterfa ->setLabel($this->faker->words(rand(2,4), true)) ->setType($this->getReference(LoadEventTypes::$refs[array_rand(LoadEventTypes::$refs)])) ->setCenter($center) + ->setCircle( + $this->getReference( + LoadScopes::$references[array_rand(LoadScopes::$references)] + ) + ) ; $manager->persist($event); $events[] = $event; diff --git a/Entity/Event.php b/Entity/Event.php index ec8c16f43..763f27f56 100644 --- a/Entity/Event.php +++ b/Entity/Event.php @@ -34,6 +34,12 @@ class Event */ private $type; + /** + * + * @var \Chill\MainBundle\Entity\Scope + */ + private $circle; + /** * @var \Doctrine\Common\Collections\Collection */ @@ -141,7 +147,38 @@ class Event { return $this->center; } + + /** + * + * @return \Chill\MainBundle\Entity\Scope + */ + public function getCircle() + { + return $this->circle; + } + /** + * + * @param \Chill\MainBundle\Entity\Scope $circle + * @return \Chill\EventBundle\Entity\Event + */ + public function setCircle(\Chill\MainBundle\Entity\Scope $circle) + { + $this->circle = $circle; + return $this; + } + + /** + * + * @deprecated + * @return \Chill\MainBundle\Entity\Scope + */ + public function getScope() + { + return $this->getCircle(); + } + + /** * Add participation * diff --git a/Resources/config/doctrine/Event.orm.yml b/Resources/config/doctrine/Event.orm.yml index b4325981c..ae69e2f06 100644 --- a/Resources/config/doctrine/Event.orm.yml +++ b/Resources/config/doctrine/Event.orm.yml @@ -22,4 +22,6 @@ Chill\EventBundle\Entity\Event: targetEntity: Chill\MainBundle\Entity\Center type: targetEntity: Chill\EventBundle\Entity\EventType + circle: + targetEntity: Chill\MainBundle\Entity\Scope lifecycleCallbacks: { } From b89ed5d534593458389c1022095bceee04376641 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 22 Mar 2016 14:00:48 +0100 Subject: [PATCH 08/73] add link to scope, center, type on Event --- .../migrations/Version20160318111334.php | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Resources/migrations/Version20160318111334.php b/Resources/migrations/Version20160318111334.php index 6ab4d5004..fe23df743 100644 --- a/Resources/migrations/Version20160318111334.php +++ b/Resources/migrations/Version20160318111334.php @@ -43,6 +43,9 @@ class Version20160318111334 extends AbstractMigration . 'id INT NOT NULL, ' . 'label VARCHAR(150) NOT NULL, ' . 'date DATE NOT NULL, ' + . 'center_id INT DEFAULT NULL, ' + . 'type_id INT DEFAULT NULL, ' + . 'circle_id INT DEFAULT NULL, ' . 'PRIMARY KEY(id))'); $this->addSql('CREATE TABLE chill_event_participation (' . 'id INT NOT NULL, ' @@ -56,6 +59,21 @@ class Version20160318111334 extends AbstractMigration $this->addSql('CREATE INDEX IDX_4E7768AC217BBB47 ON chill_event_participation (person_id)'); $this->addSql('CREATE INDEX IDX_4E7768ACD60322AC ON chill_event_participation (role_id)'); $this->addSql('CREATE INDEX IDX_4E7768AC6BF700BD ON chill_event_participation (status_id)'); + $this->addSql('CREATE INDEX IDX_FA320FC85932F377 ON chill_event_event (center_id)'); + $this->addSql('CREATE INDEX IDX_FA320FC8C54C8C93 ON chill_event_event (type_id)'); + $this->addSql('CREATE INDEX IDX_FA320FC870EE2FF6 ON chill_event_event (circle_id)'); + + $this->addSql('ALTER TABLE chill_event_event ' + . 'ADD CONSTRAINT FK_FA320FC85932F377 FOREIGN KEY (center_id) ' + . 'REFERENCES centers (id) ' + . 'NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE chill_event_event ' + . 'ADD CONSTRAINT FK_FA320FC870EE2FF6 FOREIGN KEY (circle_id) ' + . 'REFERENCES scopes (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE chill_event_event ' + . 'ADD CONSTRAINT FK_FA320FC8C54C8C93 FOREIGN KEY (type_id) ' + . 'REFERENCES chill_event_event_type (id) ' + . 'NOT DEFERRABLE INITIALLY IMMEDIATE'); $this->addSql('ALTER TABLE chill_event_role ' . 'ADD CONSTRAINT FK_AA714E54C54C8C93 FOREIGN KEY (type_id) ' . 'REFERENCES chill_event_event_type (id) ' @@ -101,6 +119,13 @@ class Version20160318111334 extends AbstractMigration $this->addSql('ALTER TABLE chill_event_participation DROP CONSTRAINT FK_4E7768ACD60322AC'); $this->addSql('ALTER TABLE chill_event_participation DROP CONSTRAINT FK_4E7768AC6BF700BD'); $this->addSql('ALTER TABLE chill_event_participation DROP CONSTRAINT FK_4E7768AC71F7E88B'); + // drop center_id constraint + $this->addSql('ALTER TABLE chill_event_event DROP CONSTRAINT FK_FA320FC85932F377'); + // drop type_id constraint + $this->addSql('ALTER TABLE chill_event_event DROP CONSTRAINT FK_FA320FC8C54C8C93'); + // drop circle_id constraint + $this->addSql('ALTER TABLE chill_event_event DROP CONSTRAINT FK_FA320FC870EE2FF6'); + $this->addSql('DROP SEQUENCE chill_event_event_type_id_seq CASCADE'); $this->addSql('DROP SEQUENCE chill_event_role_id_seq CASCADE'); $this->addSql('DROP SEQUENCE chill_event_status_id_seq CASCADE'); From 1acf3a468565841c491058378e98dae1d547b228 Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Tue, 22 Mar 2016 14:49:19 +0100 Subject: [PATCH 09/73] Adding layout for event-vue --- Resources/views/layout.html.twig | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Resources/views/layout.html.twig diff --git a/Resources/views/layout.html.twig b/Resources/views/layout.html.twig new file mode 100644 index 000000000..cbe1b9b47 --- /dev/null +++ b/Resources/views/layout.html.twig @@ -0,0 +1,31 @@ +{# + * Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS, + / + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . +#} + +{% extends "ChillMainBundle::layoutWithVerticalMenu.html.twig" %} + +{% block vertical_menu_content %} + {{ chill_menu('event', { + 'layout': 'ChillMainBundle::Menu/verticalMenu.html.twig', + }) }} +{% endblock %} + +{% block layout_wvm_content %} + {% block event_content %} +

{{ 'Event Menu' |trans }}

+ {% endblock %} +{% endblock %} From 6d2bb8ca1dce3da11f2547cd5d224ad928f7d9e9 Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Tue, 22 Mar 2016 15:35:21 +0100 Subject: [PATCH 10/73] Correction of the comment & H1 title --- Resources/views/layout.html.twig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Resources/views/layout.html.twig b/Resources/views/layout.html.twig index cbe1b9b47..091092cf6 100644 --- a/Resources/views/layout.html.twig +++ b/Resources/views/layout.html.twig @@ -25,7 +25,7 @@ {% endblock %} {% block layout_wvm_content %} - {% block event_content %} -

{{ 'Event Menu' |trans }}

+ {% block event_content %}} +

{{ 'Event' |trans }}

{% endblock %} {% endblock %} From 55a2c667939ff51d88366eba81940bd97d4b6597 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 22 Mar 2016 17:01:25 +0100 Subject: [PATCH 11/73] adding a basic search page, which create event list ref #10 ref #18 --- DataFixtures/ORM/LoadRolesACL.php | 84 ++++++++++++ DependencyInjection/ChillEventExtension.php | 36 ++++- Resources/config/services.yml | 4 - Resources/config/services/authorization.yml | 8 ++ Resources/config/services/repositories.yml | 6 + Resources/config/services/search.yml | 11 ++ Resources/translations/messages.fr.yml | 11 ++ Resources/views/Event/list.html.twig | 43 ++++++ Search/EventSearch.php | 143 ++++++++++++++++++++ Security/Authorization/EventVoter.php | 63 +++++++++ 10 files changed, 402 insertions(+), 7 deletions(-) create mode 100644 DataFixtures/ORM/LoadRolesACL.php delete mode 100644 Resources/config/services.yml create mode 100644 Resources/config/services/authorization.yml create mode 100644 Resources/config/services/repositories.yml create mode 100644 Resources/config/services/search.yml create mode 100644 Resources/translations/messages.fr.yml create mode 100644 Resources/views/Event/list.html.twig create mode 100644 Search/EventSearch.php create mode 100644 Security/Authorization/EventVoter.php diff --git a/DataFixtures/ORM/LoadRolesACL.php b/DataFixtures/ORM/LoadRolesACL.php new file mode 100644 index 000000000..c0236d25c --- /dev/null +++ b/DataFixtures/ORM/LoadRolesACL.php @@ -0,0 +1,84 @@ + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + + +namespace Chill\EventBundle\DataFixtures\ORM; + +use Doctrine\Common\DataFixtures\AbstractFixture; +use Doctrine\Common\DataFixtures\OrderedFixtureInterface; +use Chill\MainBundle\DataFixtures\ORM\LoadPermissionsGroup; +use Chill\MainBundle\Entity\RoleScope; +use Chill\MainBundle\DataFixtures\ORM\LoadScopes; +use Doctrine\Common\Persistence\ObjectManager; + +/** + * Add roles to existing groups + * + * @author Julien Fastré + * @author Champs Libres + */ +class LoadRolesACL extends AbstractFixture implements OrderedFixtureInterface +{ + public function load(ObjectManager $manager) + { + foreach (LoadPermissionsGroup::$refs as $permissionsGroupRef) { + $permissionsGroup = $this->getReference($permissionsGroupRef); + foreach (LoadScopes::$references as $scopeRef){ + $scope = $this->getReference($scopeRef); + //create permission group + switch ($permissionsGroup->getName()) { + case 'social': + if ($scope->getName()['en'] === 'administrative') { + break 2; // we do not want any power on administrative + } + break; + case 'administrative': + case 'direction': + if (in_array($scope->getName()['en'], array('administrative', 'social'))) { + break 2; // we do not want any power on social or administrative + } + break; + } + + printf("Adding CHILL_EVENT_UPDATE & CHILL_EVENT_CREATE to %s " + . "permission group, scope '%s' \n", + $permissionsGroup->getName(), $scope->getName()['en']); + $roleScopeUpdate = (new RoleScope()) + ->setRole('CHILL_EVENT_UPDATE') + ->setScope($scope); + $permissionsGroup->addRoleScope($roleScopeUpdate); + $roleScopeCreate = (new RoleScope()) + ->setRole('CHILL_EVENT_CREATE') + ->setScope($scope); + $permissionsGroup->addRoleScope($roleScopeCreate); + $manager->persist($roleScopeUpdate); + $manager->persist($roleScopeCreate); + } + + } + + $manager->flush(); + } + + public function getOrder() + { + return 30011; + } + +} diff --git a/DependencyInjection/ChillEventExtension.php b/DependencyInjection/ChillEventExtension.php index 1035659fd..5933488f1 100644 --- a/DependencyInjection/ChillEventExtension.php +++ b/DependencyInjection/ChillEventExtension.php @@ -7,6 +7,7 @@ use Symfony\Component\Config\FileLocator; use Symfony\Component\HttpKernel\DependencyInjection\Extension; use Symfony\Component\DependencyInjection\Loader; use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; +use Chill\EventBundle\Security\Authorization\EventVoter; /** * This is the class that loads and manages your bundle configuration @@ -23,8 +24,11 @@ class ChillEventExtension extends Extension implements PrependExtensionInterface $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); - $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); - $loader->load('services.yml'); + $loader = new Loader\YamlFileLoader($container, + new FileLocator(__DIR__.'/../Resources/config/services')); + $loader->load('repositories.yml'); + $loader->load('search.yml'); + $loader->load('authorization.yml'); } /* (non-PHPdoc) @@ -32,7 +36,17 @@ class ChillEventExtension extends Extension implements PrependExtensionInterface */ public function prepend(ContainerBuilder $container) { - + $this->prependAuthorization($container); + $this->prependRoute($container); + } + + /** + * add route to route loader for chill + * + * @param ContainerBuilder $container + */ + protected function prependRoute(ContainerBuilder $container) + { //add routes for custom bundle $container->prependExtensionConfig('chill_main', array( 'routing' => array( @@ -42,4 +56,20 @@ class ChillEventExtension extends Extension implements PrependExtensionInterface ) )); } + + /** + * add authorization hierarchy + * + * @param ContainerBuilder $container + */ + protected function prependAuthorization(ContainerBuilder $container) + { + $container->prependExtensionConfig('security', array( + 'role_hierarchy' => array( + EventVoter::SEE_DETAILS => array(EventVoter::SEE), + EventVoter::UPDATE => array(EventVoter::SEE_DETAILS), + EventVoter::CREATE => array(EventVoter::SEE_DETAILS) + ) + )); + } } diff --git a/Resources/config/services.yml b/Resources/config/services.yml deleted file mode 100644 index d2cfb62f0..000000000 --- a/Resources/config/services.yml +++ /dev/null @@ -1,4 +0,0 @@ -services: -# chill_event.example: -# class: Chill\EventBundle\Example -# arguments: [@service_id, "plain_value", %parameter%] diff --git a/Resources/config/services/authorization.yml b/Resources/config/services/authorization.yml new file mode 100644 index 000000000..9adb5b087 --- /dev/null +++ b/Resources/config/services/authorization.yml @@ -0,0 +1,8 @@ +services: + chill_event.event_voter: + class: Chill\EventBundle\Security\Authorization\EventVoter + arguments: + - "@chill.main.security.authorization.helper" + tags: + - { name: chill.role } + - { name: security.voter } diff --git a/Resources/config/services/repositories.yml b/Resources/config/services/repositories.yml new file mode 100644 index 000000000..44e653cc0 --- /dev/null +++ b/Resources/config/services/repositories.yml @@ -0,0 +1,6 @@ +services: + chill_group.repository.event: + class: Doctrine\ORM\EntityRepository + factory: ['@doctrine.orm.entity_manager', getRepository] + arguments: + - 'Chill\EventBundle\Entity\Event' \ No newline at end of file diff --git a/Resources/config/services/search.yml b/Resources/config/services/search.yml new file mode 100644 index 000000000..99b455bae --- /dev/null +++ b/Resources/config/services/search.yml @@ -0,0 +1,11 @@ +services: + chill_event.search_events: + class: Chill\EventBundle\Search\EventSearch + arguments: + - "@security.token_storage" + - "@chill_group.repository.event" + - "@chill.main.security.authorization.helper" + - "@templating" + tags: + - { name: chill.search, alias: 'event_regular' } + diff --git a/Resources/translations/messages.fr.yml b/Resources/translations/messages.fr.yml new file mode 100644 index 000000000..d579fd3a2 --- /dev/null +++ b/Resources/translations/messages.fr.yml @@ -0,0 +1,11 @@ +#events +Name: Nom +Date: Date +Event type : Type d'événement +See: Voir + + + +#search +Event search: Recherche d'événements +'%total% events match the search %pattern%' : '{0} Aucun événement ne correspond aux termes de recherche "%pattern%" | {1} Un événement a été trouvé par la recherche "%pattern%" | ]1,Inf] %total% événements correspondent aux termes de recherche "%pattern%".' diff --git a/Resources/views/Event/list.html.twig b/Resources/views/Event/list.html.twig new file mode 100644 index 000000000..9e158b285 --- /dev/null +++ b/Resources/views/Event/list.html.twig @@ -0,0 +1,43 @@ +

{{ 'Event search'|trans }}

+ +

{% transchoice total with { '%pattern%' : pattern } %}%total% events match the search %pattern%{% endtranschoice %}

+ + +{% if events|length > 0 %} + + + + + + + + + + + {% for event in events %} + + + + + + + {% endfor %} + +
{{ 'Name'|trans }}{{ 'Date'|trans }}{{ 'Event type'|trans }} 
{{ event.label }}{{ event.date|localizeddate('long', 'none') }}{{ event.type.label|localize_translatable_string }} + +
+ +{% endif %} \ No newline at end of file diff --git a/Search/EventSearch.php b/Search/EventSearch.php new file mode 100644 index 000000000..c2b4e4e80 --- /dev/null +++ b/Search/EventSearch.php @@ -0,0 +1,143 @@ + + * @author Champs Libres + */ +class EventSearch extends AbstractSearch +{ + + /** + * + * @var EntityRepository + */ + private $er; + + /** + * + * @var \Chill\MainBundle\Entity\User + */ + private $user; + + /** + * + * @var AuthorizationHelper + */ + private $helper; + + /** + * + * @var TemplatingEngine + */ + private $templating; + + + public function __construct( + TokenStorageInterface $tokenStorage, + EntityRepository $eventRepository, + AuthorizationHelper $authorizationHelper, + TemplatingEngine $templating + ) + { + $this->user = $tokenStorage->getToken()->getUser(); + $this->er = $eventRepository; + $this->helper = $authorizationHelper; + $this->templating = $templating; + } + + public function supports($domain) + { + return 'event' === $domain or 'events' === $domain; + } + + public function isActiveByDefault() + { + return false; + } + + public function getOrder() + { + return 3000; + } + + public function renderResult(array $terms, $start = 0, $limit = 50, array $options = array()) + { + return $this->templating->render('ChillEventBundle:Event:list.html.twig', + array( + 'events' => $this->search($terms, $start, $limit, $options), + 'pattern' => $this->recomposePattern($terms, array(), $terms['_domain']), + 'total' => $this->count($terms) + )); + } + + protected function search(array $terms, $start, $limit, $options) + { + $qb = $this->er->createQueryBuilder('e'); + $qb->select('e'); + $this->composeQuery($qb, $terms) + ->setMaxResults($limit) + ->setFirstResult($start) + ->orderBy('e.date', 'DESC') + ; + + return $qb->getQuery()->getResult(); + } + + protected function count(array $terms) + { + $qb = $this->er->createQueryBuilder('e'); + $qb->select('COUNT(e)'); + $this->composeQuery($qb, $terms) + ; + + return $qb->getQuery()->getSingleScalarResult(); + } + + protected function composeQuery(QueryBuilder &$qb, $terms) + { + + // add security clauses + $reachableCenters = $this->helper + ->getReachableCenters($this->user, new Role('CHILL_EVENT_SEE')); + + if (count($reachableCenters) === 0) { + // add a clause to block all events + $where = $qb->expr()->isNull('e.center'); + $qb->andWhere($where); + } else { + + $n = 0; + $orWhere = $qb->expr()->orX(); + foreach ($reachableCenters as $center) { + $circles = $this->helper->getReachableScopes($this->user, + new Role('CHILL_EVENT_SEE'), $center); + $where = $qb->expr()->andX( + $qb->expr()->eq('e.center', ':center_'.$n), + $qb->expr()->in('e.circle', ':circle_'.$n) + ); + $qb->setParameter('center_'.$n, $center); + $qb->setParameter('circle_'.$n, $circles); + $orWhere->add($where); + } + + $qb->andWhere($orWhere); + } + + + + return $qb; + } +} diff --git a/Security/Authorization/EventVoter.php b/Security/Authorization/EventVoter.php new file mode 100644 index 000000000..23fcccf28 --- /dev/null +++ b/Security/Authorization/EventVoter.php @@ -0,0 +1,63 @@ + + * @author Champs Libres + */ +class EventVoter extends AbstractChillVoter implements ProvideRoleInterface +{ + + const SEE = 'CHILL_EVENT_SEE'; + const SEE_DETAILS = 'CHILL_EVENT_SEE_DETAILS'; + const CREATE = 'CHILL_EVENT_CREATE'; + const UPDATE = 'CHILL_EVENT_UPDATE'; + + protected $authorizationHelper; + + public function __construct(AuthorizationHelper $helper) + { + $this->authorizationHelper = $helper; + } + + protected function getSupportedAttributes() + { + return array(self::SEE, self::SEE_DETAILS, + self::CREATE, self::UPDATE); + } + + protected function getSupportedClasses() + { + return array(Event::class); + } + + protected function isGranted($attribute, $event, $user = null) + { + if (!$user instanceof User) { + return false; + } + + return $this->helper->userHasAccess($user, $event, $attribute); + } + + public function getRoles() + { + return $this->getSupportedAttributes(); + } + + public function getRolesWithoutScope() + { + return null; + } + +} From 4d02314770096ce492e23df83f1c4370275f69f1 Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Tue, 22 Mar 2016 17:16:19 +0100 Subject: [PATCH 12/73] Event CRUD generated --- Controller/EventController.php | 224 +++++++++++++++++++++++ Form/EventType.php | 43 +++++ Resources/config/routing.yml | 4 + Resources/config/routing/event.yml | 30 +++ Resources/views/Event/edit.html.twig | 16 ++ Resources/views/Event/index.html.twig | 43 +++++ Resources/views/Event/new.html.twig | 15 ++ Resources/views/Event/show.html.twig | 36 ++++ Tests/Controller/EventControllerTest.php | 55 ++++++ 9 files changed, 466 insertions(+) create mode 100644 Controller/EventController.php create mode 100644 Form/EventType.php create mode 100644 Resources/config/routing/event.yml create mode 100644 Resources/views/Event/edit.html.twig create mode 100644 Resources/views/Event/index.html.twig create mode 100644 Resources/views/Event/new.html.twig create mode 100644 Resources/views/Event/show.html.twig create mode 100644 Tests/Controller/EventControllerTest.php diff --git a/Controller/EventController.php b/Controller/EventController.php new file mode 100644 index 000000000..b084218df --- /dev/null +++ b/Controller/EventController.php @@ -0,0 +1,224 @@ +getDoctrine()->getManager(); + + $entities = $em->getRepository('ChillEventBundle:Event')->findAll(); + + return $this->render('ChillEventBundle:Event:index.html.twig', array( + 'entities' => $entities, + )); + } + /** + * Creates a new Event entity. + * + */ + public function createAction(Request $request) + { + $entity = new Event(); + $form = $this->createCreateForm($entity); + $form->handleRequest($request); + + if ($form->isValid()) { + $em = $this->getDoctrine()->getManager(); + $em->persist($entity); + $em->flush(); + + return $this->redirect($this->generateUrl('event_show', array('id' => $entity->getId()))); + } + + return $this->render('ChillEventBundle:Event:new.html.twig', array( + 'entity' => $entity, + 'form' => $form->createView(), + )); + } + + /** + * Creates a form to create a Event entity. + * + * @param Event $entity The entity + * + * @return \Symfony\Component\Form\Form The form + */ + private function createCreateForm(Event $entity) + { + $form = $this->createForm(new EventType(), $entity, array( + 'action' => $this->generateUrl('event_create'), + 'method' => 'POST', + )); + + $form->add('submit', 'submit', array('label' => 'Create')); + + return $form; + } + + /** + * Displays a form to create a new Event entity. + * + */ + public function newAction() + { + $entity = new Event(); + $form = $this->createCreateForm($entity); + + return $this->render('ChillEventBundle:Event:new.html.twig', array( + 'entity' => $entity, + 'form' => $form->createView(), + )); + } + + /** + * Finds and displays a Event entity. + * + */ + public function showAction($id) + { + $em = $this->getDoctrine()->getManager(); + + $entity = $em->getRepository('ChillEventBundle:Event')->find($id); + + if (!$entity) { + throw $this->createNotFoundException('Unable to find Event entity.'); + } + + $deleteForm = $this->createDeleteForm($id); + + return $this->render('ChillEventBundle:Event:show.html.twig', array( + 'entity' => $entity, + 'delete_form' => $deleteForm->createView(), + )); + } + + /** + * Displays a form to edit an existing Event entity. + * + */ + public function editAction($id) + { + $em = $this->getDoctrine()->getManager(); + + $entity = $em->getRepository('ChillEventBundle:Event')->find($id); + + if (!$entity) { + throw $this->createNotFoundException('Unable to find Event entity.'); + } + + $editForm = $this->createEditForm($entity); + $deleteForm = $this->createDeleteForm($id); + + return $this->render('ChillEventBundle:Event:edit.html.twig', array( + 'entity' => $entity, + 'edit_form' => $editForm->createView(), + 'delete_form' => $deleteForm->createView(), + )); + } + + /** + * Creates a form to edit a Event entity. + * + * @param Event $entity The entity + * + * @return \Symfony\Component\Form\Form The form + */ + private function createEditForm(Event $entity) + { + $form = $this->createForm(new EventType(), $entity, array( + 'action' => $this->generateUrl('event_update', array('id' => $entity->getId())), + 'method' => 'PUT', + )); + + $form->add('submit', 'submit', array('label' => 'Update')); + + return $form; + } + /** + * Edits an existing Event entity. + * + */ + public function updateAction(Request $request, $id) + { + $em = $this->getDoctrine()->getManager(); + + $entity = $em->getRepository('ChillEventBundle:Event')->find($id); + + if (!$entity) { + throw $this->createNotFoundException('Unable to find Event entity.'); + } + + $deleteForm = $this->createDeleteForm($id); + $editForm = $this->createEditForm($entity); + $editForm->handleRequest($request); + + if ($editForm->isValid()) { + $em->flush(); + + return $this->redirect($this->generateUrl('event_edit', array('id' => $id))); + } + + return $this->render('ChillEventBundle:Event:edit.html.twig', array( + 'entity' => $entity, + 'edit_form' => $editForm->createView(), + 'delete_form' => $deleteForm->createView(), + )); + } + /** + * Deletes a Event entity. + * + */ + public function deleteAction(Request $request, $id) + { + $form = $this->createDeleteForm($id); + $form->handleRequest($request); + + if ($form->isValid()) { + $em = $this->getDoctrine()->getManager(); + $entity = $em->getRepository('ChillEventBundle:Event')->find($id); + + if (!$entity) { + throw $this->createNotFoundException('Unable to find Event entity.'); + } + + $em->remove($entity); + $em->flush(); + } + + return $this->redirect($this->generateUrl('event')); + } + + /** + * Creates a form to delete a Event entity by id. + * + * @param mixed $id The entity id + * + * @return \Symfony\Component\Form\Form The form + */ + private function createDeleteForm($id) + { + return $this->createFormBuilder() + ->setAction($this->generateUrl('event_delete', array('id' => $id))) + ->setMethod('DELETE') + ->add('submit', 'submit', array('label' => 'Delete')) + ->getForm() + ; + } +} diff --git a/Form/EventType.php b/Form/EventType.php new file mode 100644 index 000000000..5434681a7 --- /dev/null +++ b/Form/EventType.php @@ -0,0 +1,43 @@ +add('label') + ->add('date') + ->add('center') + ->add('type') + ->add('circle') + ; + } + + /** + * @param OptionsResolverInterface $resolver + */ + public function setDefaultOptions(OptionsResolverInterface $resolver) + { + $resolver->setDefaults(array( + 'data_class' => 'Chill\EventBundle\Entity\Event' + )); + } + + /** + * @return string + */ + public function getName() + { + return 'chill_eventbundle_event'; + } +} diff --git a/Resources/config/routing.yml b/Resources/config/routing.yml index f6262b049..83a6a4093 100644 --- a/Resources/config/routing.yml +++ b/Resources/config/routing.yml @@ -1,3 +1,7 @@ +chill_event_event: + resource: "@ChillEventBundle/Resources/config/routing/event.yml" + prefix: /event + chill_event_fr_admin_event_status: resource: "@ChillEventBundle/Resources/config/routing/status.yml" prefix: /{_locale}/admin/event/status diff --git a/Resources/config/routing/event.yml b/Resources/config/routing/event.yml new file mode 100644 index 000000000..cd3573f4e --- /dev/null +++ b/Resources/config/routing/event.yml @@ -0,0 +1,30 @@ +event: + path: / + defaults: { _controller: "ChillEventBundle:Event:index" } + +event_show: + path: /{id}/show + defaults: { _controller: "ChillEventBundle:Event:show" } + +event_new: + path: /new + defaults: { _controller: "ChillEventBundle:Event:new" } + +event_create: + path: /create + defaults: { _controller: "ChillEventBundle:Event:create" } + methods: POST + +event_edit: + path: /{id}/edit + defaults: { _controller: "ChillEventBundle:Event:edit" } + +event_update: + path: /{id}/update + defaults: { _controller: "ChillEventBundle:Event:update" } + methods: [POST, PUT] + +event_delete: + path: /{id}/delete + defaults: { _controller: "ChillEventBundle:Event:delete" } + methods: [POST, DELETE] diff --git a/Resources/views/Event/edit.html.twig b/Resources/views/Event/edit.html.twig new file mode 100644 index 000000000..733f7332c --- /dev/null +++ b/Resources/views/Event/edit.html.twig @@ -0,0 +1,16 @@ +{% extends '::base.html.twig' %} + +{% block body -%} +

Event edit

+ + {{ form(edit_form) }} + + +{% endblock %} diff --git a/Resources/views/Event/index.html.twig b/Resources/views/Event/index.html.twig new file mode 100644 index 000000000..9ba265dda --- /dev/null +++ b/Resources/views/Event/index.html.twig @@ -0,0 +1,43 @@ +{% extends '::base.html.twig' %} + +{% block body -%} +

Event list

+ + + + + + + + + + + + {% for entity in entities %} + + + + + + + {% endfor %} + +
IdLabelDateActions
{{ entity.id }}{{ entity.label }}{% if entity.date %}{{ entity.date|date('Y-m-d H:i:s') }}{% endif %} + +
+ + + {% endblock %} diff --git a/Resources/views/Event/new.html.twig b/Resources/views/Event/new.html.twig new file mode 100644 index 000000000..25e6d2661 --- /dev/null +++ b/Resources/views/Event/new.html.twig @@ -0,0 +1,15 @@ +{% extends '::base.html.twig' %} + +{% block body -%} +

Event creation

+ + {{ form(form) }} + + +{% endblock %} diff --git a/Resources/views/Event/show.html.twig b/Resources/views/Event/show.html.twig new file mode 100644 index 000000000..a2e9f85cb --- /dev/null +++ b/Resources/views/Event/show.html.twig @@ -0,0 +1,36 @@ +{% extends '::base.html.twig' %} + +{% block body -%} +

Event

+ + + + + + + + + + + + + + + + +
Id{{ entity.id }}
Label{{ entity.label }}
Date{{ entity.date|date('Y-m-d H:i:s') }}
+ + +{% endblock %} diff --git a/Tests/Controller/EventControllerTest.php b/Tests/Controller/EventControllerTest.php new file mode 100644 index 000000000..6435a2712 --- /dev/null +++ b/Tests/Controller/EventControllerTest.php @@ -0,0 +1,55 @@ +request('GET', '/event/'); + $this->assertEquals(200, $client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET /event/"); + $crawler = $client->click($crawler->selectLink('Create a new entry')->link()); + + // Fill in the form and submit it + $form = $crawler->selectButton('Create')->form(array( + 'chill_eventbundle_event[field_name]' => 'Test', + // ... other fields to fill + )); + + $client->submit($form); + $crawler = $client->followRedirect(); + + // Check data in the show view + $this->assertGreaterThan(0, $crawler->filter('td:contains("Test")')->count(), 'Missing element td:contains("Test")'); + + // Edit the entity + $crawler = $client->click($crawler->selectLink('Edit')->link()); + + $form = $crawler->selectButton('Update')->form(array( + 'chill_eventbundle_event[field_name]' => 'Foo', + // ... other fields to fill + )); + + $client->submit($form); + $crawler = $client->followRedirect(); + + // Check the element contains an attribute with value equals "Foo" + $this->assertGreaterThan(0, $crawler->filter('[value="Foo"]')->count(), 'Missing element [value="Foo"]'); + + // Delete the entity + $client->submit($crawler->selectButton('Delete')->form()); + $crawler = $client->followRedirect(); + + // Check the entity has been delete on the list + $this->assertNotRegExp('/Foo/', $client->getResponse()->getContent()); + } + + */ +} From 26fa6a2c5634c037c8fb8752fcabf1ee1e14fe48 Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Tue, 22 Mar 2016 18:26:34 +0100 Subject: [PATCH 13/73] Route for event is now {locale}/event/event --- Resources/config/routing.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Resources/config/routing.yml b/Resources/config/routing.yml index 83a6a4093..0f58caa77 100644 --- a/Resources/config/routing.yml +++ b/Resources/config/routing.yml @@ -1,6 +1,6 @@ chill_event_event: resource: "@ChillEventBundle/Resources/config/routing/event.yml" - prefix: /event + prefix: /{_locale}/event/event chill_event_fr_admin_event_status: resource: "@ChillEventBundle/Resources/config/routing/status.yml" @@ -13,4 +13,3 @@ chill_event_admin_role: chill_event_admin_event_type: resource: "@ChillEventBundle/Resources/config/routing/eventtype.yml" prefix: /{_locale}/admin/event/event_type - From 041c43a93659b0fb0014d2acd682f585e89cbbc1 Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Tue, 22 Mar 2016 18:59:59 +0100 Subject: [PATCH 14/73] Basic form to create an Event --- Form/EventType.php | 14 +++++++++++--- Resources/views/Event/new.html.twig | 4 ++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Form/EventType.php b/Form/EventType.php index 5434681a7..bdfad1855 100644 --- a/Form/EventType.php +++ b/Form/EventType.php @@ -16,10 +16,18 @@ class EventType extends AbstractType { $builder ->add('label') - ->add('date') + ->add( + 'date', + 'date', + array( + 'required' => true, + 'widget' => 'single_text', + 'format' => 'dd-MM-yyyy' + ) + ) ->add('center') - ->add('type') - ->add('circle') + //->add('type') + //->add('circle') ; } diff --git a/Resources/views/Event/new.html.twig b/Resources/views/Event/new.html.twig index 25e6d2661..46b00a2b2 100644 --- a/Resources/views/Event/new.html.twig +++ b/Resources/views/Event/new.html.twig @@ -1,6 +1,6 @@ -{% extends '::base.html.twig' %} +{% extends 'ChillEventBundle::layout.html.twig' %} -{% block body -%} +{% block event_content -%}

Event creation

{{ form(form) }} From 888bcad81a794b4d459e5b865f9efbbd7bc35dcd Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Tue, 22 Mar 2016 20:34:34 +0100 Subject: [PATCH 15/73] Adding type to the creation event form --- DependencyInjection/ChillEventExtension.php | 1 + Form/EventType.php | 3 +- Form/Type/TranslatableEventType.php | 70 +++++++++++++++++++++ Resources/config/services/forms.yml | 7 +++ 4 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 Form/Type/TranslatableEventType.php create mode 100644 Resources/config/services/forms.yml diff --git a/DependencyInjection/ChillEventExtension.php b/DependencyInjection/ChillEventExtension.php index 5933488f1..29e273178 100644 --- a/DependencyInjection/ChillEventExtension.php +++ b/DependencyInjection/ChillEventExtension.php @@ -29,6 +29,7 @@ class ChillEventExtension extends Extension implements PrependExtensionInterface $loader->load('repositories.yml'); $loader->load('search.yml'); $loader->load('authorization.yml'); + $loader->load('forms.yml'); } /* (non-PHPdoc) diff --git a/Form/EventType.php b/Form/EventType.php index bdfad1855..053c02007 100644 --- a/Form/EventType.php +++ b/Form/EventType.php @@ -5,6 +5,7 @@ namespace Chill\EventBundle\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Chill\EventBundle\Form\Type\TranslatableEventType; class EventType extends AbstractType { @@ -26,7 +27,7 @@ class EventType extends AbstractType ) ) ->add('center') - //->add('type') + ->add('type', TranslatableEventType::class) //->add('circle') ; } diff --git a/Form/Type/TranslatableEventType.php b/Form/Type/TranslatableEventType.php new file mode 100644 index 000000000..cf2abc14a --- /dev/null +++ b/Form/Type/TranslatableEventType.php @@ -0,0 +1,70 @@ +, + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace Chill\EventBundle\Form\Type; + +use Symfony\Component\Form\AbstractType; +use Symfony\Component\OptionsResolver\OptionsResolver; +use Chill\MainBundle\Templating\TranslatableStringHelper; +use Symfony\Bridge\Doctrine\Form\Type\EntityType; +use Doctrine\ORM\EntityRepository; +use Chill\EventBundle\Entity\EventType; + +/** + * Description of TranslatableEventType + * + * @author Champs-Libres Coop + */ +class TranslatableEventType extends AbstractType +{ + /** + * @var TranslatableStringHelper + */ + protected $translatableStringHelper; + + public function __construct(TranslatableStringHelper $helper) + { + $this->translatableStringHelper = $helper; + } + + public function getParent() + { + return EntityType::class; + } + + public function configureOptions(OptionsResolver $resolver) + { + $helper = $this->translatableStringHelper; + $resolver->setDefaults( + array( + 'class' => EventType::class, + 'query_builder' => function (EntityRepository $er) { + return $er->createQueryBuilder('et') + ->where('et.active = true'); + }, + 'choice_label' => function (EventType $t) use ($helper) { + return $helper->localize($t->getLabel()); + }, + ) + ); + } +} diff --git a/Resources/config/services/forms.yml b/Resources/config/services/forms.yml new file mode 100644 index 000000000..1dc75d5e4 --- /dev/null +++ b/Resources/config/services/forms.yml @@ -0,0 +1,7 @@ +services: + chill_event.form.event_type_type: + class: Chill\EventBundle\Form\Type\TranslatableEventType + arguments: + - "@chill.main.helper.translatable_string" + tags: + - { name: form.type } From 90cbb78621ba7d221738c7ad21dd1c1d61ba2ceb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 22 Mar 2016 21:18:32 +0100 Subject: [PATCH 16/73] add a "view page" for event ref #3 --- Controller/EventController.php | 10 +-- Entity/Event.php | 5 +- Resources/config/routing/event.yml | 2 +- Resources/translations/messages.fr.yml | 9 +++ Resources/views/Event/list.html.twig | 6 +- Resources/views/Event/show.html.twig | 89 +++++++++++++++++++------- Resources/views/layout.html.twig | 2 +- Security/Authorization/EventVoter.php | 7 +- 8 files changed, 94 insertions(+), 36 deletions(-) diff --git a/Controller/EventController.php b/Controller/EventController.php index b084218df..0cccb2f83 100644 --- a/Controller/EventController.php +++ b/Controller/EventController.php @@ -91,21 +91,21 @@ class EventController extends Controller * Finds and displays a Event entity. * */ - public function showAction($id) + public function showAction($event_id) { $em = $this->getDoctrine()->getManager(); - $entity = $em->getRepository('ChillEventBundle:Event')->find($id); + $entity = $em->getRepository('ChillEventBundle:Event')->find($event_id); if (!$entity) { throw $this->createNotFoundException('Unable to find Event entity.'); } - $deleteForm = $this->createDeleteForm($id); + $this->denyAccessUnlessGranted('CHILL_EVENT_SEE_DETAILS', $entity, + "You are not allowed to see details on this event"); return $this->render('ChillEventBundle:Event:show.html.twig', array( - 'entity' => $entity, - 'delete_form' => $deleteForm->createView(), + 'event' => $entity )); } diff --git a/Entity/Event.php b/Entity/Event.php index 763f27f56..ac10db4cb 100644 --- a/Entity/Event.php +++ b/Entity/Event.php @@ -2,10 +2,13 @@ namespace Chill\EventBundle\Entity; +use Chill\MainBundle\Entity\HasScopeInterface; +use Chill\MainBundle\Entity\HasCenterInterface; + /** * Event */ -class Event +class Event implements HasScopeInterface, HasCenterInterface { /** * @var integer diff --git a/Resources/config/routing/event.yml b/Resources/config/routing/event.yml index cd3573f4e..84d775aab 100644 --- a/Resources/config/routing/event.yml +++ b/Resources/config/routing/event.yml @@ -3,7 +3,7 @@ event: defaults: { _controller: "ChillEventBundle:Event:index" } event_show: - path: /{id}/show + path: /{event_id}/show defaults: { _controller: "ChillEventBundle:Event:show" } event_new: diff --git a/Resources/translations/messages.fr.yml b/Resources/translations/messages.fr.yml index d579fd3a2..90a759f7c 100644 --- a/Resources/translations/messages.fr.yml +++ b/Resources/translations/messages.fr.yml @@ -3,8 +3,17 @@ Name: Nom Date: Date Event type : Type d'événement See: Voir +Event: Événement +'Event : %label%': Événement "%label%" +Participation: Participation +Status: Statut +Last update: Dernière mise à jour +'%count% participations to this event': '{0} Aucun participant à l''événement | {1} Un participant à l''événement | ]1,Inf] %count% participants à l''événement' +#CRUD +Details of an event: Détails d'un événement +Edit all the participations: Modifier toutes les participations #search Event search: Recherche d'événements diff --git a/Resources/views/Event/list.html.twig b/Resources/views/Event/list.html.twig index 9e158b285..f7338fd98 100644 --- a/Resources/views/Event/list.html.twig +++ b/Resources/views/Event/list.html.twig @@ -22,11 +22,11 @@
  • - {% if is_granted('CHILL_EVENT_SEE_DETAILS', event) %} - + {# {% if is_granted('CHILL_EVENT_SEE_DETAILS', event) %} #} + {{ 'See'|trans }} - {% endif %} + {# {% endif %} #} {% if is_granted('CHILL_EVENT_UPDATE', event) %} {{ 'Edit'|trans }} diff --git a/Resources/views/Event/show.html.twig b/Resources/views/Event/show.html.twig index a2e9f85cb..1a500381a 100644 --- a/Resources/views/Event/show.html.twig +++ b/Resources/views/Event/show.html.twig @@ -1,36 +1,81 @@ -{% extends '::base.html.twig' %} +{% extends 'ChillEventBundle::layout.html.twig' %} -{% block body -%} -

    Event

    +{% block title 'Event : %label%'|trans({ '%label%' : event.label } ) %} + +{% import 'ChillPersonBundle:Person:macro.html.twig' as person_macro %} + +{% block event_content -%} +

    {{ 'Details of an event'|trans }}

    - - + + - - + + - - + + + + + +
    Id{{ entity.id }}{{ 'Name'|trans }}{{ event.label }}
    Label{{ entity.label }}{{ 'Date'|trans }}{{ event.date|localizeddate('long', 'none') }}
    Date{{ entity.date|date('Y-m-d H:i:s') }}{{ 'Event type'|trans }}{{ event.type.label|localize_translatable_string }}
    {{ 'Circle'|trans }}{{ event.circle.name|localize_translatable_string }}
    + +
    + +

    {{ 'Participation'|trans }}

    + {% set count = event.participations|length %} +

    {% transchoice count %}%count% participations to this event{% endtranschoice %}

    + + {% if count > 0 %} + + + + + + + + + + + + {% for participation in event.participations %} + + + + + + + + {% endfor %} + +
    {{ 'Person'|trans }}{{ 'Role'|trans }}{{ 'Status'|trans }}{{ 'Last update'|trans }} 
    {{ person_macro.render(participation.person) }}{{ participation.role.label|localize_translatable_string }}{{ participation.status.label|localize_translatable_string }}{{ participation.lastUpdate|localizeddate("long", "none") }} + +
    + + + {% endif %} - + {% endblock %} diff --git a/Resources/views/layout.html.twig b/Resources/views/layout.html.twig index 091092cf6..a788962e3 100644 --- a/Resources/views/layout.html.twig +++ b/Resources/views/layout.html.twig @@ -25,7 +25,7 @@ {% endblock %} {% block layout_wvm_content %} - {% block event_content %}} + {% block event_content %}

    {{ 'Event' |trans }}

    {% endblock %} {% endblock %} diff --git a/Security/Authorization/EventVoter.php b/Security/Authorization/EventVoter.php index 23fcccf28..dc7a63971 100644 --- a/Security/Authorization/EventVoter.php +++ b/Security/Authorization/EventVoter.php @@ -8,6 +8,7 @@ use Chill\MainBundle\Security\Authorization\AbstractChillVoter; use Chill\MainBundle\Security\ProvideRoleInterface; use Chill\EventBundle\Entity\Event; use Chill\MainBundle\Security\Authorization\AuthorizationHelper; +use Chill\MainBundle\Entity\User; /** * Description of EventVoter @@ -42,12 +43,12 @@ class EventVoter extends AbstractChillVoter implements ProvideRoleInterface } protected function isGranted($attribute, $event, $user = null) - { + { if (!$user instanceof User) { return false; - } + } - return $this->helper->userHasAccess($user, $event, $attribute); + return $this->authorizationHelper->userHasAccess($user, $event, $attribute); } public function getRoles() From 4fe31185df451304a1e52df50e52f1786eacab01 Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Wed, 23 Mar 2016 18:19:48 +0100 Subject: [PATCH 17/73] Good Center - Circle suggested --- Controller/EventController.php | 6 +-- Entity/Event.php | 17 +++--- Form/EventType.php | 82 ++++++++++++++++++++++++++++- Resources/config/services/forms.yml | 11 +++- 4 files changed, 103 insertions(+), 13 deletions(-) diff --git a/Controller/EventController.php b/Controller/EventController.php index b084218df..8d08f281f 100644 --- a/Controller/EventController.php +++ b/Controller/EventController.php @@ -4,10 +4,10 @@ namespace Chill\EventBundle\Controller; use Symfony\Component\HttpFoundation\Request; use Symfony\Bundle\FrameworkBundle\Controller\Controller; - use Chill\EventBundle\Entity\Event; use Chill\EventBundle\Form\EventType; + /** * Event controller. * @@ -62,9 +62,9 @@ class EventController extends Controller */ private function createCreateForm(Event $entity) { - $form = $this->createForm(new EventType(), $entity, array( + $form = $this->createForm(EventType::class, $entity, array( 'action' => $this->generateUrl('event_create'), - 'method' => 'POST', + 'method' => 'POST' )); $form->add('submit', 'submit', array('label' => 'Create')); diff --git a/Entity/Event.php b/Entity/Event.php index 763f27f56..d9512fda0 100644 --- a/Entity/Event.php +++ b/Entity/Event.php @@ -2,10 +2,13 @@ namespace Chill\EventBundle\Entity; +use Chill\MainBundle\Entity\HasCenterInterface; +use Chill\MainBundle\Entity\HasScopeInterface; + /** * Event */ -class Event +class Event implements HasCenterInterface, HasScopeInterface { /** * @var integer @@ -120,7 +123,7 @@ class Event } /** - * + * * @return EventType */ public function getType() @@ -129,7 +132,7 @@ class Event } /** - * + * * @param \Chill\EventBundle\Entity\EventType $type * @return \Chill\EventBundle\Entity\Event */ @@ -140,7 +143,7 @@ class Event } /** - * + * * @return \Chill\MainBundle\Entity\Center */ public function getCenter() @@ -149,7 +152,7 @@ class Event } /** - * + * * @return \Chill\MainBundle\Entity\Scope */ public function getCircle() @@ -158,7 +161,7 @@ class Event } /** - * + * * @param \Chill\MainBundle\Entity\Scope $circle * @return \Chill\EventBundle\Entity\Event */ @@ -169,7 +172,7 @@ class Event } /** - * + * * @deprecated * @return \Chill\MainBundle\Entity\Scope */ diff --git a/Form/EventType.php b/Form/EventType.php index 053c02007..5ad2f6414 100644 --- a/Form/EventType.php +++ b/Form/EventType.php @@ -6,15 +6,66 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolverInterface; use Chill\EventBundle\Form\Type\TranslatableEventType; +use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; +use Chill\MainBundle\Security\Authorization\AuthorizationHelper; +use Doctrine\Common\Persistence\ObjectManager; +use Chill\MainBundle\Templating\TranslatableStringHelper; +use Chill\MainBundle\Entity\User; +use Symfony\Bridge\Doctrine\Form\Type\EntityType; +use Chill\MainBundle\Entity\Center; +use Chill\MainBundle\Entity\Scope; + +use Symfony\Component\Security\Core\Role\Role; class EventType extends AbstractType { + + /** @var the user running this form */ + protected $user; + + /** @var AuthorizationHelper */ + protected $authorizationHelper; + + /** @var TranslatableStringHelper */ + protected $translatableStringHelper; + + public function __construct( + TokenStorageInterface $tokenStorage, + AuthorizationHelper $authorizationHelper, + TranslatableStringHelper $translatableStringHelper + ) { + if (!$tokenStorage->getToken()->getUser() instanceof User) { + throw new \RuntimeException("you should have a valid user"); + } + $this->user = $tokenStorage->getToken()->getUser(); + $this->authorizationHelper = $authorizationHelper; + $this->translatableStringHelper = $translatableStringHelper; + } + /** * @param FormBuilderInterface $builder * @param array $options */ public function buildForm(FormBuilderInterface $builder, array $options) { + $userReachableCenters = $this->authorizationHelper + ->getReachableCenters($this->user, new Role('CHILL_EVENT_CREATE')); + + $userReachableCirclesByCircleId = array(); + $userReachableCentersByCircleId = array(); + + foreach ($userReachableCenters as $center) { + foreach ($this->authorizationHelper + ->getReachableCircles($this->user, new Role('CHILL_EVENT_CREATE'), $center) as $circle) { + if (array_key_exists($circle->getId(), $userReachableCirclesByCircleId)) { + array_push($userReachableCentersByCircleId[$circle->getId()], $center); + } else { + $userReachableCirclesByCircleId[$circle->getId()] = $circle; + $userReachableCentersByCircleId[$circle->getId()] = array($center); + } + } + } + $builder ->add('label') ->add( @@ -26,9 +77,36 @@ class EventType extends AbstractType 'format' => 'dd-MM-yyyy' ) ) - ->add('center') + ->add('center', EntityType::class, array( + 'class' => Center::class, + 'choices' => $userReachableCenters, + 'choice_attr' => function (Center $center) { + return array( + 'data-link-category' => $center->getId() + ); + }, + )) + ->add('circle', EntityType::class, array( + 'class' => Scope::class, + 'choices' => array_values($userReachableCirclesByCircleId), + 'choice_label' => function ($circle) { + $helper = $this->translatableStringHelper; + return $helper->localize($circle->getName()); + }, + 'choice_attr' => function ($circle) use ($userReachableCentersByCircleId) { + $centersId = ""; + foreach ($userReachableCentersByCircleId[$circle->getId()] as $center) { + print $center; + $centersId = $centersId.($center->getId()).','; + } + $centersId = trim($centersId, ','); + return array( + 'data-link-categories' => $centersId, + + ); + }, + )) ->add('type', TranslatableEventType::class) - //->add('circle') ; } diff --git a/Resources/config/services/forms.yml b/Resources/config/services/forms.yml index 1dc75d5e4..2f1cb1d00 100644 --- a/Resources/config/services/forms.yml +++ b/Resources/config/services/forms.yml @@ -1,7 +1,16 @@ services: - chill_event.form.event_type_type: + chill.event.form.type.translatable_event_type: class: Chill\EventBundle\Form\Type\TranslatableEventType arguments: - "@chill.main.helper.translatable_string" tags: - { name: form.type } + + chill.event.form.event_type_test: + class: Chill\EventBundle\Form\EventType + arguments: + - "@security.token_storage" + - "@chill.main.security.authorization.helper" + - "@chill.main.helper.translatable_string" + tags: + - { name: form.type } From 5c29e85e4e66fd415bc1dc28cb457f180d88f414 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 23 Mar 2016 21:57:25 +0100 Subject: [PATCH 18/73] prevent test/fixtures to be registered --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 9f103fd7c..a06b406d1 100644 --- a/.gitignore +++ b/.gitignore @@ -17,5 +17,8 @@ app/config/parameters.ini app/config/parameters.yml Tests/Fixtures/App/config/parameters.yml +# fixtures +Resources/test/* + #composer composer.lock From e2decee8cb48a4980d1613cd7f80cc06b7b6fb5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 23 Mar 2016 21:57:42 +0100 Subject: [PATCH 19/73] add a form to make a ling with 'add a participant' page --- Controller/EventController.php | 49 +++++++++++++++++++++- Resources/config/routing.yml | 4 ++ Resources/config/routing/participation.yml | 3 ++ Resources/translations/messages.fr.yml | 1 + Resources/views/Event/show.html.twig | 8 +++- 5 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 Resources/config/routing/participation.yml diff --git a/Controller/EventController.php b/Controller/EventController.php index 0cccb2f83..6fd94d173 100644 --- a/Controller/EventController.php +++ b/Controller/EventController.php @@ -4,9 +4,13 @@ namespace Chill\EventBundle\Controller; use Symfony\Component\HttpFoundation\Request; use Symfony\Bundle\FrameworkBundle\Controller\Controller; - +use Chill\PersonBundle\Form\Type\PickPersonType; use Chill\EventBundle\Entity\Event; use Chill\EventBundle\Form\EventType; +use Symfony\Component\Security\Core\Role\Role; +use Symfony\Component\Form\Extension\Core\Type\FormType; +use Symfony\Component\Form\Extension\Core\Type\SubmitType; +use Symfony\Component\Form\Extension\Core\Type\HiddenType; /** * Event controller. @@ -103,11 +107,52 @@ class EventController extends Controller $this->denyAccessUnlessGranted('CHILL_EVENT_SEE_DETAILS', $entity, "You are not allowed to see details on this event"); + + $addParticipationByPersonForm = $this->createAddParticipationByPersonForm($entity); return $this->render('ChillEventBundle:Event:show.html.twig', array( - 'event' => $entity + 'event' => $entity, + 'form_add_participation_by_person' => $addParticipationByPersonForm->createView() )); } + + /** + * create a form to add a participation with a person + * + * @return \Symfony\Component\Form\FormInterface + */ + protected function createAddParticipationByPersonForm(Event $event) + { + /* @var $builder \Symfony\Component\Form\FormBuilderInterface */ + $builder = $this + ->get('form.factory') + ->createNamedBuilder( + null, + FormType::class, + null, + array( + 'method' => 'GET', + 'action' => $this->generateUrl('chill_event_participation_new'), + 'csrf_protection' => false + )) + ; + + $builder->add('person_id', PickPersonType::class, array( + 'role' => new Role('CHILL_EVENT_CREATE'), + 'centers' => $event->getCenter() + )); + + $builder->add('center_id', HiddenType::class, array( + 'data' => $event->getCenter()->getId() + )); + + $builder->add('submit', SubmitType::class, + array( + 'label' => 'Add a participation' + )); + + return $builder->getForm(); + } /** * Displays a form to edit an existing Event entity. diff --git a/Resources/config/routing.yml b/Resources/config/routing.yml index 0f58caa77..c8be2882e 100644 --- a/Resources/config/routing.yml +++ b/Resources/config/routing.yml @@ -13,3 +13,7 @@ chill_event_admin_role: chill_event_admin_event_type: resource: "@ChillEventBundle/Resources/config/routing/eventtype.yml" prefix: /{_locale}/admin/event/event_type + +chill_event_participation: + resource: "@ChillEventBundle/Resources/config/routing/participation.yml" + prefix: /{_locale}/event/participation diff --git a/Resources/config/routing/participation.yml b/Resources/config/routing/participation.yml new file mode 100644 index 000000000..d89dd3b9c --- /dev/null +++ b/Resources/config/routing/participation.yml @@ -0,0 +1,3 @@ +chill_event_participation_new: + path: /new + defaults: { _controller: ChillEventBundle:Participation:new } diff --git a/Resources/translations/messages.fr.yml b/Resources/translations/messages.fr.yml index 90a759f7c..7c558341a 100644 --- a/Resources/translations/messages.fr.yml +++ b/Resources/translations/messages.fr.yml @@ -14,6 +14,7 @@ Last update: Dernière mise à jour Details of an event: Détails d'un événement Edit all the participations: Modifier toutes les participations +Add a participation: Ajouter un participant #search Event search: Recherche d'événements diff --git a/Resources/views/Event/show.html.twig b/Resources/views/Event/show.html.twig index 1a500381a..d5e02aa96 100644 --- a/Resources/views/Event/show.html.twig +++ b/Resources/views/Event/show.html.twig @@ -36,7 +36,7 @@
-

{{ 'Participation'|trans }}

+

{{ 'Participations'|trans }}

{% set count = event.participations|length %}

{% transchoice count %}%count% participations to this event{% endtranschoice %}

@@ -74,6 +74,12 @@
  • {{ 'Edit all the participations'|trans }}
  • +
  • + {{ form_widget(form_add_participation_by_person.person_id, { 'attr' : { 'style' : 'width: 20em; display:inline-block; ' } } ) }} + {{ form_widget(form_add_participation_by_person.submit, { 'attr' : { 'class' : 'sc-button btn-create' } } ) }} + {{ form_rest(form_add_participation_by_person) }} +
    +
{% endif %} From 627b9fb08f99e80a6240220d299ed3ba881e1791 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 24 Mar 2016 01:44:32 +0100 Subject: [PATCH 20/73] add the possibility to add a participation of a person to an event ref #5 --- Controller/EventController.php | 4 +- Controller/ParticipationController.php | 151 ++++++++++++++++++ DataFixtures/ORM/LoadRolesACL.php | 14 +- Entity/Participation.php | 52 +++++- Form/ParticipationType.php | 117 ++++++++++++++ Resources/config/routing/participation.yml | 4 + Resources/config/services/authorization.yml | 8 + Resources/config/services/forms.yml | 7 + Resources/config/validation.yml | 10 ++ Resources/translations/messages.fr.yml | 6 +- Resources/views/Event/show.html.twig | 2 + Resources/views/Participation/new.html.twig | 37 +++++ Security/Authorization/ParticipationVoter.php | 82 ++++++++++ 13 files changed, 489 insertions(+), 5 deletions(-) create mode 100644 Controller/ParticipationController.php create mode 100644 Form/ParticipationType.php create mode 100644 Resources/config/validation.yml create mode 100644 Resources/views/Participation/new.html.twig create mode 100644 Security/Authorization/ParticipationVoter.php diff --git a/Controller/EventController.php b/Controller/EventController.php index b77517160..ddc6e4ebc 100644 --- a/Controller/EventController.php +++ b/Controller/EventController.php @@ -143,8 +143,8 @@ class EventController extends Controller 'centers' => $event->getCenter() )); - $builder->add('center_id', HiddenType::class, array( - 'data' => $event->getCenter()->getId() + $builder->add('event_id', HiddenType::class, array( + 'data' => $event->getId() )); $builder->add('submit', SubmitType::class, diff --git a/Controller/ParticipationController.php b/Controller/ParticipationController.php new file mode 100644 index 000000000..8b9685462 --- /dev/null +++ b/Controller/ParticipationController.php @@ -0,0 +1,151 @@ + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace Chill\EventBundle\Controller; + +use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use Symfony\Component\HttpFoundation\Request; +use Chill\EventBundle\Entity\Participation; +use Chill\EventBundle\Form\ParticipationType; +use Symfony\Component\Form\Extension\Core\Type\SubmitType; +use Chill\EventBundle\Security\Authorization\ParticipationVoter; + +/** + * + * + * @author Julien Fastré + */ +class ParticipationController extends Controller +{ + public function newAction(Request $request) + { + $participation = $this->handleRequest($request, new Participation()); + + $this->denyAccessUnlessGranted(ParticipationVoter::CREATE, + $participation, 'The user is not allowed to create this participation'); + + $form = $this->createCreateForm($participation); + + return $this->render('ChillEventBundle:Participation:new.html.twig', array( + 'form' => $form->createView(), + 'participation' => $participation + )); + } + + public function createAction(Request $request) + { + $participation = $this->handleRequest($request, new Participation()); + + $this->denyAccessUnlessGranted(ParticipationVoter::CREATE, + $participation, 'The user is not allowed to create this participation'); + + $form = $this->createCreateForm($participation); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $em = $this->getDoctrine()->getManager(); + + $em->persist($participation); + $em->flush(); + + $this->addFlash('success', $this->get('translator')->trans( + 'The participation was created' + )); + + return $this->redirectToRoute('event_show', array( + 'event_id' => $participation->getEvent()->getId() + )); + } + + return $this->render('ChillEventBundle:Participation:new.html.twig', array( + 'form' => $form->createView(), + 'participation' => $participation + )); + } + + /** + * + * @param Request $request + * @param Participation $participation + * @return Participation + * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException if the event/person is not found + * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException if the user does not have access to event/person + */ + protected function handleRequest(Request $request, Participation $participation) + { + $em = $this->getDoctrine()->getManager(); + + $event_id = $request->query->getInt('event_id', null); + + if ($event_id !== NULL) { + $event = $em->getRepository('ChillEventBundle:Event') + ->find($event_id); + + if ($event === NULL) { + throw $this->createNotFoundException('The event with id '.$event_id.' is not found'); + } + + $this->denyAccessUnlessGranted('CHILL_EVENT_SEE', $event, + 'The user is not allowed to see the event'); + + $participation->setEvent($event); + } + + $person_id = $request->query->getInt('person_id', null); + + if ($person_id !== NULL) { + $person = $em->getRepository('ChillPersonBundle:Person') + ->find($person_id); + + if ($person === NULL) { + throw $this->createNotFoundException('The person with id '.$person_id.' is not found'); + } + + $this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person, + 'The user is not allowed to see the person'); + + $participation->setPerson($person); + } + + return $participation; + } + + /** + * + * @param Participation $participation + * @return \Symfony\Component\Form\FormInterface + */ + public function createCreateForm(Participation $participation) + { + $form = $this->createForm(ParticipationType::class, $participation, array( + 'event_type' => $participation->getEvent()->getType(), + 'action' => $this->generateUrl('chill_event_participation_create', array( + 'event_id' => $participation->getEvent()->getId(), + 'person_id' => $participation->getPerson()->getId() + )) + )); + + $form->add('submit', SubmitType::class, array( + 'label' => 'Create' + )); + + return $form; + } + +} diff --git a/DataFixtures/ORM/LoadRolesACL.php b/DataFixtures/ORM/LoadRolesACL.php index c0236d25c..08c0a8feb 100644 --- a/DataFixtures/ORM/LoadRolesACL.php +++ b/DataFixtures/ORM/LoadRolesACL.php @@ -56,19 +56,31 @@ class LoadRolesACL extends AbstractFixture implements OrderedFixtureInterface break; } - printf("Adding CHILL_EVENT_UPDATE & CHILL_EVENT_CREATE to %s " + printf("Adding CHILL_EVENT_UPDATE & CHILL_EVENT_CREATE " + . "CHILL_EVENT_PARTICIPATION_UPDATE & CHILL_EVENT_PARTICIPATION_CREATE " + . "to %s " . "permission group, scope '%s' \n", $permissionsGroup->getName(), $scope->getName()['en']); $roleScopeUpdate = (new RoleScope()) ->setRole('CHILL_EVENT_UPDATE') ->setScope($scope); + $roleScopeUpdate2 = (new RoleScope()) + ->setRole('CHILL_EVENT_PARTICIPATION_UPDATE') + ->setScope($scope); $permissionsGroup->addRoleScope($roleScopeUpdate); + $permissionsGroup->addRoleScope($roleScopeUpdate2); $roleScopeCreate = (new RoleScope()) ->setRole('CHILL_EVENT_CREATE') ->setScope($scope); + $roleScopeCreate2 = (new RoleScope()) + ->setRole('CHILL_EVENT_PARTICIPATION_CREATE') + ->setScope($scope); $permissionsGroup->addRoleScope($roleScopeCreate); + $permissionsGroup->addRoleScope($roleScopeCreate2); $manager->persist($roleScopeUpdate); + $manager->persist($roleScopeUpdate2); $manager->persist($roleScopeCreate); + $manager->persist($roleScopeCreate2); } } diff --git a/Entity/Participation.php b/Entity/Participation.php index cc8b8544e..ef33c6b99 100644 --- a/Entity/Participation.php +++ b/Entity/Participation.php @@ -2,10 +2,14 @@ namespace Chill\EventBundle\Entity; +use Chill\MainBundle\Entity\HasScopeInterface; +use Chill\MainBundle\Entity\HasCenterInterface; +use Symfony\Component\Validator\Context\ExecutionContextInterface; + /** * Participation */ -class Participation +class Participation implements HasCenterInterface, HasScopeInterface { /** * @var integer @@ -183,4 +187,50 @@ class Participation { return $this->status; } + + public function getCenter() + { + if ($this->getEvent() === NULL) { + throw new \RuntimeException('The event is not linked with this instance. ' + . 'You should initialize the event with a valid center before.'); + } + + return $this->getEvent()->getCenter(); + } + + public function getScope() + { + if ($this->getEvent() === NULL) { + throw new \RuntimeException('The event is not linked with this instance. ' + . 'You should initialize the event with a valid center before.'); + } + + return $this->getEvent()->getCircle(); + } + + /** + * Check that : + * + * - the role can be associated with this event type + * - the status can be associated with this event type + * + * @param ExecutionContextInterface $context + */ + public function isConsistent(ExecutionContextInterface $context) + { + if ($this->getRole()->getType()->getId() !== + $this->getEvent()->getType()->getId()) { + $context->buildViolation('The role is not allowed with this event type') + ->atPath('role') + ->addViolation(); + } + + if ($this->getStatus()->getType()->getId() !== + $this->getEvent()->getType()->getId()) { + $context->buildViolation('The status is not allowed with this event type') + ->atPath('status') + ->addViolation(); + } + } + } diff --git a/Form/ParticipationType.php b/Form/ParticipationType.php new file mode 100644 index 000000000..4891a4811 --- /dev/null +++ b/Form/ParticipationType.php @@ -0,0 +1,117 @@ + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace Chill\EventBundle\Form; + +use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; +use Chill\EventBundle\Entity\EventType; +use Chill\EventBundle\Entity\Status; +use Symfony\Bridge\Doctrine\Form\Type\EntityType; +use Doctrine\ORM\EntityRepository; +use Chill\EventBundle\Entity\Role; +use Chill\MainBundle\Templating\TranslatableStringHelper; + +/** + * A type to create a participation + * + * If the `event` option is defined, the role will be restricted + * + * @author Julien Fastré + */ +class ParticipationType extends AbstractType +{ + /** + * + * @var TranslatableStringHelper + */ + protected $translatableStringHelper; + + public function __construct(TranslatableStringHelper $translatableStringHelper) + { + $this->translatableStringHelper = $translatableStringHelper; + } + + public function buildForm(FormBuilderInterface $builder, array $options) + { + // local copy of variable for Closure + $translatableStringHelper = $this->translatableStringHelper; + + // add role + $builder->add('role', EntityType::class, array( + 'class' => Role::class, + 'query_builder' => function (EntityRepository $er) use ($options) { + $qb = $er->createQueryBuilder('r'); + + if ($options['event_type'] instanceof EventType) { + $qb->where($qb->expr()->eq('r.type', ':event_type')) + ->setParameter('event_type', $options['event_type']); + } + + $qb->andWhere($qb->expr()->eq('r.active', ':active')) + ->setParameter('active', true); + + return $qb; + }, + 'choice_attr' => function(Role $r) { + return array( + 'data-event-type' => $r->getType()->getId() + ); + }, + 'choice_label' => function(Role $r) use ($translatableStringHelper) { + return $translatableStringHelper->localize($r->getLabel()); + } + )); + + // add a status + $builder->add('status', EntityType::class, array( + 'class' => Status::class, + 'choice_attr' => function(Status $s) { + return array( + 'data-event-type' => $s->getType()->getId() + ); + }, + 'query_builder' => function (EntityRepository $er) use ($options) { + $qb = $er->createQueryBuilder('s'); + + if ($options['event_type'] instanceof EventType) { + $qb->where($qb->expr()->eq('s.type', ':event_type')) + ->setParameter('event_type', $options['event_type']); + } + + $qb->andWhere($qb->expr()->eq('s.active', ':active')) + ->setParameter('active', true); + + return $qb; + }, + 'choice_label' => function(Status $s) use ($translatableStringHelper) { + return $translatableStringHelper->localize($s->getLabel()); + } + )); + + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefined('event_type') + ->setAllowedTypes('event_type', array('null', EventType::class)) + ->setDefault('event_type', 'null'); + } +} diff --git a/Resources/config/routing/participation.yml b/Resources/config/routing/participation.yml index d89dd3b9c..f79e584a6 100644 --- a/Resources/config/routing/participation.yml +++ b/Resources/config/routing/participation.yml @@ -1,3 +1,7 @@ chill_event_participation_new: path: /new defaults: { _controller: ChillEventBundle:Participation:new } + +chill_event_participation_create: + path: /create + defaults: { _controller: ChillEventBundle:Participation:create } diff --git a/Resources/config/services/authorization.yml b/Resources/config/services/authorization.yml index 9adb5b087..d44f1e9d9 100644 --- a/Resources/config/services/authorization.yml +++ b/Resources/config/services/authorization.yml @@ -6,3 +6,11 @@ services: tags: - { name: chill.role } - { name: security.voter } + + chill_event.event_participation: + class: Chill\EventBundle\Security\Authorization\ParticipationVoter + arguments: + - "@chill.main.security.authorization.helper" + tags: + - { name: chill.role } + - { name: security.voter } diff --git a/Resources/config/services/forms.yml b/Resources/config/services/forms.yml index 2f1cb1d00..2f622a326 100644 --- a/Resources/config/services/forms.yml +++ b/Resources/config/services/forms.yml @@ -14,3 +14,10 @@ services: - "@chill.main.helper.translatable_string" tags: - { name: form.type } + + chill.event.form.participation_type: + class: Chill\EventBundle\Form\ParticipationType + arguments: + - "@chill.main.helper.translatable_string" + tags: + - { name: form.type } diff --git a/Resources/config/validation.yml b/Resources/config/validation.yml new file mode 100644 index 000000000..90ebf28e0 --- /dev/null +++ b/Resources/config/validation.yml @@ -0,0 +1,10 @@ +Chill\EventBundle\Event\Participation: + properties: + event: + - NotNull: ~ + status: + - NotNull: ~ + person: + - NotNull: ~ + constraints: + - Callback: [isConsistent] diff --git a/Resources/translations/messages.fr.yml b/Resources/translations/messages.fr.yml index 7c558341a..e5d2a5e98 100644 --- a/Resources/translations/messages.fr.yml +++ b/Resources/translations/messages.fr.yml @@ -12,9 +12,13 @@ Last update: Dernière mise à jour #CRUD Details of an event: Détails d'un événement - Edit all the participations: Modifier toutes les participations Add a participation: Ajouter un participant +Participation creation: Ajouter une participation +Associated person: Personne associée +Associated event: Événement associé +Back to the event: Retour à l'événement +The participation was created: La participation a été créée #search Event search: Recherche d'événements diff --git a/Resources/views/Event/show.html.twig b/Resources/views/Event/show.html.twig index d5e02aa96..720075281 100644 --- a/Resources/views/Event/show.html.twig +++ b/Resources/views/Event/show.html.twig @@ -75,9 +75,11 @@
  • {{ 'Edit all the participations'|trans }}
  • + {{ form_start(form_add_participation_by_person) }} {{ form_widget(form_add_participation_by_person.person_id, { 'attr' : { 'style' : 'width: 20em; display:inline-block; ' } } ) }} {{ form_widget(form_add_participation_by_person.submit, { 'attr' : { 'class' : 'sc-button btn-create' } } ) }} {{ form_rest(form_add_participation_by_person) }} + {{ form_end(form_add_participation_by_person) }}
diff --git a/Resources/views/Participation/new.html.twig b/Resources/views/Participation/new.html.twig new file mode 100644 index 000000000..bd99347fe --- /dev/null +++ b/Resources/views/Participation/new.html.twig @@ -0,0 +1,37 @@ +{% extends 'ChillEventBundle::layout.html.twig' %} + +{% import 'ChillPersonBundle:Person:macro.html.twig' as person_macro %} + +{% block event_content -%} +

{{ 'Participation creation'|trans }}

+ + + + + + + + + + + + +
{{ 'Associated person'|trans }}{{ person_macro.render(participation.person) }}
{{ 'Associated event'|trans }} {{ participation.event.label }}
+ + {{ form_start(form) }} + {{ form_row(form.role) }} + {{ form_row(form.status) }} + + + + {{ form_end(form) }} +{% endblock %} diff --git a/Security/Authorization/ParticipationVoter.php b/Security/Authorization/ParticipationVoter.php new file mode 100644 index 000000000..e8ba27548 --- /dev/null +++ b/Security/Authorization/ParticipationVoter.php @@ -0,0 +1,82 @@ + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace Chill\EventBundle\Security\Authorization; + +use Chill\MainBundle\Security\ProvideRoleInterface; +use Chill\MainBundle\Security\Authorization\AbstractChillVoter; +use Chill\MainBundle\Security\Authorization\AuthorizationHelper; +use Chill\EventBundle\Entity\Participation; +use Chill\MainBundle\Entity\User; + +/** + * + * + * @author Julien Fastré + */ +class ParticipationVoter extends AbstractChillVoter implements ProvideRoleInterface +{ + /** + * + * @var AuthorizationHelper + */ + protected $authorizationHelper; + + const CREATE = 'CHILL_EVENT_PARTICIPATION_CREATE'; + const UPDATE = 'CHILL_EVENT_PARTICIPATION_UPDATE'; + + public function __construct(AuthorizationHelper $helper) + { + $this->authorizationHelper = $helper; + } + + protected function getSupportedAttributes() + { + return array( + self::CREATE, self::UPDATE + ); + } + + protected function getSupportedClasses() + { + return array( + Participation::class + ); + } + + protected function isGranted($attribute, $participation, $user = null) + { + if (!$user instanceof User) { + return false; + } + + return $this->authorizationHelper->userHasAccess($user, $participation, $attribute); + } + + public function getRoles() + { + return $this->getSupportedAttributes(); + } + + public function getRolesWithoutScope() + { + return null; + } + +} From 9eed387285431446a902475978bf7b0d24a43c67 Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Thu, 24 Mar 2016 10:45:03 +0100 Subject: [PATCH 21/73] Adding the js function categoryLinkParentChildSelect for center and scope --- Form/EventType.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Form/EventType.php b/Form/EventType.php index 5ad2f6414..623004306 100644 --- a/Form/EventType.php +++ b/Form/EventType.php @@ -80,8 +80,10 @@ class EventType extends AbstractType ->add('center', EntityType::class, array( 'class' => Center::class, 'choices' => $userReachableCenters, + 'attr' => array('class' => 'select2 chill-category-link-parent'), 'choice_attr' => function (Center $center) { return array( + 'class' => ' chill-category-link-parent', 'data-link-category' => $center->getId() ); }, From b1b258d76b0bb95c340abe4d4576cbed50d0b43a Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Thu, 24 Mar 2016 10:52:21 +0100 Subject: [PATCH 22/73] Removing print --- Form/EventType.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Form/EventType.php b/Form/EventType.php index 623004306..29b32a086 100644 --- a/Form/EventType.php +++ b/Form/EventType.php @@ -98,7 +98,6 @@ class EventType extends AbstractType 'choice_attr' => function ($circle) use ($userReachableCentersByCircleId) { $centersId = ""; foreach ($userReachableCentersByCircleId[$circle->getId()] as $center) { - print $center; $centersId = $centersId.($center->getId()).','; } $centersId = trim($centersId, ','); From ccb4d6cfb54d778078ca04d88cbacb11e7adaa3e Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Thu, 24 Mar 2016 11:29:17 +0100 Subject: [PATCH 23/73] Correction of routing : id -> event_id --- Controller/EventController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Controller/EventController.php b/Controller/EventController.php index ddc6e4ebc..bb73708a2 100644 --- a/Controller/EventController.php +++ b/Controller/EventController.php @@ -49,7 +49,7 @@ class EventController extends Controller $em->persist($entity); $em->flush(); - return $this->redirect($this->generateUrl('event_show', array('id' => $entity->getId()))); + return $this->redirect($this->generateUrl('event_show', array('event_id' => $entity->getId()))); } return $this->render('ChillEventBundle:Event:new.html.twig', array( From 993882e92504b09e7caf2cad2e1e5e56c3588366 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 24 Mar 2016 14:18:03 +0100 Subject: [PATCH 24/73] feature: update an existing participation The update allow to modify the status and role of a participation. ref #8 --- Controller/ParticipationController.php | 90 ++++++++++++++++++++ Resources/config/routing/participation.yml | 9 ++ Resources/translations/messages.fr.yml | 1 + Resources/views/Event/show.html.twig | 7 +- Resources/views/Participation/edit.html.twig | 41 +++++++++ Resources/views/Participation/new.html.twig | 2 + 6 files changed, 148 insertions(+), 2 deletions(-) create mode 100644 Resources/views/Participation/edit.html.twig diff --git a/Controller/ParticipationController.php b/Controller/ParticipationController.php index 8b9685462..8cf065706 100644 --- a/Controller/ParticipationController.php +++ b/Controller/ParticipationController.php @@ -148,4 +148,94 @@ class ParticipationController extends Controller return $form; } + /** + * show an edit form for the participation with the given id. + * + * @param int $participation_id + * @return \Symfony\Component\HttpFoundation\Response + * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException if the participation is not found + * @throws \Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException if the user is not allowed to edit the participation + */ + public function editAction($participation_id) + { + /* @var $participation Participation */ + $participation = $this->getDoctrine()->getManager() + ->getRepository('ChillEventBundle:Participation') + ->find($participation_id); + + if ($participation === NULL) { + throw $this->createNotFoundException('The participation is not found'); + } + + $this->denyAccessUnlessGranted(ParticipationVoter::UPDATE, $participation, + 'You are not allowed to edit this participation'); + + $form = $this->createEditForm($participation); + + return $this->render('ChillEventBundle:Participation:edit.html.twig', array( + 'form' => $form->createView(), + 'participation' => $participation + )); + } + + public function updateAction($participation_id, Request $request) + { + /* @var $participation Participation */ + $participation = $this->getDoctrine()->getManager() + ->getRepository('ChillEventBundle:Participation') + ->find($participation_id); + + if ($participation === NULL) { + throw $this->createNotFoundException('The participation is not found'); + } + + $this->denyAccessUnlessGranted(ParticipationVoter::UPDATE, $participation, + 'You are not allowed to edit this participation'); + + $form = $this->createEditForm($participation); + + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $em = $this->getDoctrine()->getManager(); + + $em->flush(); + + $this->addFlash('success', $this->get('translator')->trans( + 'The participation was updated' + )); + + return $this->redirectToRoute('event_show', array( + 'event_id' => $participation->getEvent()->getId() + )); + + } + + return $this->render('ChillEventBundle:Participation:edit.html.twig', array( + 'form' => $form->createView(), + 'participation' => $participation + )); + } + + /** + * + * @param Participation $participation + * @return \Symfony\Component\Form\FormInterface + */ + public function createEditForm(Participation $participation) + { + $form = $this->createForm(ParticipationType::class, $participation, array( + 'event_type' => $participation->getEvent()->getType(), + 'action' => $this->generateUrl('chill_event_participation_update', array( + 'participation_id' => $participation->getId() + )) + )); + + $form->add('submit', SubmitType::class, array( + 'label' => 'Edit' + )); + + return $form; + } + } diff --git a/Resources/config/routing/participation.yml b/Resources/config/routing/participation.yml index f79e584a6..54d18fb71 100644 --- a/Resources/config/routing/participation.yml +++ b/Resources/config/routing/participation.yml @@ -5,3 +5,12 @@ chill_event_participation_new: chill_event_participation_create: path: /create defaults: { _controller: ChillEventBundle:Participation:create } + +chill_event_participation_edit: + path: /{participation_id}/edit + defaults: { _controller: ChillEventBundle:Participation:edit } + +chill_event_participation_update: + path: /{participation_id}/update + defaults: { _controller: ChillEventBundle:Participation:update } + methods: [POST] diff --git a/Resources/translations/messages.fr.yml b/Resources/translations/messages.fr.yml index e5d2a5e98..91e7e1ea8 100644 --- a/Resources/translations/messages.fr.yml +++ b/Resources/translations/messages.fr.yml @@ -19,6 +19,7 @@ Associated person: Personne associée Associated event: Événement associé Back to the event: Retour à l'événement The participation was created: La participation a été créée +The participation was updated: La participation a été mise à jour #search Event search: Recherche d'événements diff --git a/Resources/views/Event/show.html.twig b/Resources/views/Event/show.html.twig index 720075281..e28fec753 100644 --- a/Resources/views/Event/show.html.twig +++ b/Resources/views/Event/show.html.twig @@ -57,14 +57,17 @@ {{ person_macro.render(participation.person) }} {{ participation.role.label|localize_translatable_string }} {{ participation.status.label|localize_translatable_string }} - {{ participation.lastUpdate|localizeddate("long", "none") }} + {{ participation.lastUpdate|time_diff }} diff --git a/Resources/views/Participation/edit.html.twig b/Resources/views/Participation/edit.html.twig new file mode 100644 index 000000000..438fba6b3 --- /dev/null +++ b/Resources/views/Participation/edit.html.twig @@ -0,0 +1,41 @@ +{% extends 'ChillEventBundle::layout.html.twig' %} + +{% import 'ChillPersonBundle:Person:macro.html.twig' as person_macro %} + +{% block event_content -%} +

{{ 'Participation Edit'|trans }}

+ + + + + + + + + + + + + + + + +
{{ 'Associated person'|trans }}{{ person_macro.render(participation.person) }}
{{ 'Associated event'|trans }} {{ participation.event.label }}
{{ 'Date'|trans }} {{ participation.event.date|localizeddate('long', 'none') }}
+ + {{ form_start(form) }} + {{ form_row(form.role) }} + {{ form_row(form.status) }} + + + + {{ form_end(form) }} +{% endblock %} diff --git a/Resources/views/Participation/new.html.twig b/Resources/views/Participation/new.html.twig index bd99347fe..cbf6c72bd 100644 --- a/Resources/views/Participation/new.html.twig +++ b/Resources/views/Participation/new.html.twig @@ -2,6 +2,8 @@ {% import 'ChillPersonBundle:Person:macro.html.twig' as person_macro %} +{% block title 'Participation creation'|trans %} + {% block event_content -%}

{{ 'Participation creation'|trans }}

From 3ac192d34cde31672eb6d89fbebc3913e50ba4ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 24 Mar 2016 14:30:08 +0100 Subject: [PATCH 25/73] remove empty default controller --- Controller/DefaultController.php | 13 ------------- Resources/views/Default/index.html.twig | 1 - Tests/Controller/DefaultControllerTest.php | 17 ----------------- 3 files changed, 31 deletions(-) delete mode 100644 Controller/DefaultController.php delete mode 100644 Resources/views/Default/index.html.twig delete mode 100644 Tests/Controller/DefaultControllerTest.php diff --git a/Controller/DefaultController.php b/Controller/DefaultController.php deleted file mode 100644 index 6d455c21a..000000000 --- a/Controller/DefaultController.php +++ /dev/null @@ -1,13 +0,0 @@ -render('ChillEventBundle:Default:index.html.twig', array('name' => $name)); - } -} diff --git a/Resources/views/Default/index.html.twig b/Resources/views/Default/index.html.twig deleted file mode 100644 index 4ce626e9b..000000000 --- a/Resources/views/Default/index.html.twig +++ /dev/null @@ -1 +0,0 @@ -Hello {{ name }}! diff --git a/Tests/Controller/DefaultControllerTest.php b/Tests/Controller/DefaultControllerTest.php deleted file mode 100644 index 5c2a813f4..000000000 --- a/Tests/Controller/DefaultControllerTest.php +++ /dev/null @@ -1,17 +0,0 @@ -request('GET', '/hello/Fabien'); - - $this->assertTrue($crawler->filter('html:contains("Hello Fabien")')->count() > 0); - } -} From 69465c387d5d37365d2f93d8fc68cd724c10ab02 Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Thu, 24 Mar 2016 14:33:18 +0100 Subject: [PATCH 26/73] Adding validation for the event --- Resources/config/validation.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Resources/config/validation.yml b/Resources/config/validation.yml index 90ebf28e0..4163cd0bf 100644 --- a/Resources/config/validation.yml +++ b/Resources/config/validation.yml @@ -1,3 +1,17 @@ +Chill\EventBundle\Entity\Event: + properties: + label: + - Length: + min: 3 + max: 75 + minMessage: The event name must have at least {{ limit }} characters. + maxMessage: The event name must have maximum {{ limit }} characters. + type: + - NotNull: ~ + circle: + - NotNull: ~ + center: + - NotNull: ~ Chill\EventBundle\Event\Participation: properties: event: From a91ce5fe4f7f7a0e11d13ea80a90f457f437c548 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 24 Mar 2016 15:02:08 +0100 Subject: [PATCH 27/73] fix bug in validation close #21 --- Resources/config/validation.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Resources/config/validation.yml b/Resources/config/validation.yml index 90ebf28e0..e214de89a 100644 --- a/Resources/config/validation.yml +++ b/Resources/config/validation.yml @@ -1,4 +1,4 @@ -Chill\EventBundle\Event\Participation: +Chill\EventBundle\Entity\Participation: properties: event: - NotNull: ~ From 372cae7008428561b94c1bc7ef99d99944fd1ee9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 24 Mar 2016 15:18:50 +0100 Subject: [PATCH 28/73] show always the form "add a participant" even if no participation yet --- Resources/views/Event/show.html.twig | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/Resources/views/Event/show.html.twig b/Resources/views/Event/show.html.twig index e28fec753..8c47ab42c 100644 --- a/Resources/views/Event/show.html.twig +++ b/Resources/views/Event/show.html.twig @@ -75,18 +75,22 @@ -
    -
  • {{ 'Edit all the participations'|trans }}
  • -
  • - {{ form_start(form_add_participation_by_person) }} - {{ form_widget(form_add_participation_by_person.person_id, { 'attr' : { 'style' : 'width: 20em; display:inline-block; ' } } ) }} - {{ form_widget(form_add_participation_by_person.submit, { 'attr' : { 'class' : 'sc-button btn-create' } } ) }} - {{ form_rest(form_add_participation_by_person) }} - {{ form_end(form_add_participation_by_person) }} -
    -
  • -
+ {% endif %} + +
    + {% if count > 0 %} +
  • {{ 'Edit all the participations'|trans }}
  • + {% endif %} +
  • + {{ form_start(form_add_participation_by_person) }} + {{ form_widget(form_add_participation_by_person.person_id, { 'attr' : { 'style' : 'width: 20em; display:inline-block; ' } } ) }} + {{ form_widget(form_add_participation_by_person.submit, { 'attr' : { 'class' : 'sc-button btn-create' } } ) }} + {{ form_rest(form_add_participation_by_person) }} + {{ form_end(form_add_participation_by_person) }} +
    +
  • +
{% endblock %} From cd13140e6c372aa387fbc99b7b54a15215c48d2e Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Thu, 24 Mar 2016 15:18:59 +0100 Subject: [PATCH 29/73] Adding add an event into the section menu --- Resources/config/routing/event.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Resources/config/routing/event.yml b/Resources/config/routing/event.yml index 84d775aab..c6e7ebe79 100644 --- a/Resources/config/routing/event.yml +++ b/Resources/config/routing/event.yml @@ -9,6 +9,13 @@ event_show: event_new: path: /new defaults: { _controller: "ChillEventBundle:Event:new" } + options: + menus: + section: + order: 11 + label: Add an event + icons: [plus, calendar-o] + event_create: path: /create From 8db8c8925cc10e27e76f0399d844494c9ebd27d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 24 Mar 2016 15:19:23 +0100 Subject: [PATCH 30/73] add a link into section menu Currently, the main link in section menu redirect to a search which display the last events ref #10 --- Controller/EventController.php | 8 ++++++++ Entity/Participation.php | 1 + Resources/config/routing/event.yml | 10 ++++++++++ Resources/translations/messages.fr.yml | 7 ++++++- Resources/views/Event/list.html.twig | 10 +++++++++- 5 files changed, 34 insertions(+), 2 deletions(-) diff --git a/Controller/EventController.php b/Controller/EventController.php index bb73708a2..ec3f5a3d5 100644 --- a/Controller/EventController.php +++ b/Controller/EventController.php @@ -34,6 +34,14 @@ class EventController extends Controller 'entities' => $entities, )); } + + public function mostRecentIndexAction() + { + return $this->redirectToRoute('chill_main_search', array( + 'q' => '@event' + )); + } + /** * Creates a new Event entity. * diff --git a/Entity/Participation.php b/Entity/Participation.php index ef33c6b99..3aa52313c 100644 --- a/Entity/Participation.php +++ b/Entity/Participation.php @@ -231,6 +231,7 @@ class Participation implements HasCenterInterface, HasScopeInterface ->atPath('status') ->addViolation(); } + var_dump('ok'); } } diff --git a/Resources/config/routing/event.yml b/Resources/config/routing/event.yml index 84d775aab..87781f06f 100644 --- a/Resources/config/routing/event.yml +++ b/Resources/config/routing/event.yml @@ -1,6 +1,16 @@ event: path: / defaults: { _controller: "ChillEventBundle:Event:index" } + +chill_event_list_most_recent: + path: most_recent + defaults: { _controller: "ChillEventBundle:Event:mostRecentIndex" } + options: + menus: + section: + order: 90 + label: Events + icons: [calendar] event_show: path: /{event_id}/show diff --git a/Resources/translations/messages.fr.yml b/Resources/translations/messages.fr.yml index 91e7e1ea8..a456de1ee 100644 --- a/Resources/translations/messages.fr.yml +++ b/Resources/translations/messages.fr.yml @@ -4,14 +4,18 @@ Date: Date Event type : Type d'événement See: Voir Event: Événement +Events: Événements 'Event : %label%': Événement "%label%" Participation: Participation Status: Statut Last update: Dernière mise à jour '%count% participations to this event': '{0} Aucun participant à l''événement | {1} Un participant à l''événement | ]1,Inf] %count% participants à l''événement' -#CRUD +#CRUD event Details of an event: Détails d'un événement +New event: Nouvel événement + +#crud participation Edit all the participations: Modifier toutes les participations Add a participation: Ajouter un participant Participation creation: Ajouter une participation @@ -20,6 +24,7 @@ Associated event: Événement associé Back to the event: Retour à l'événement The participation was created: La participation a été créée The participation was updated: La participation a été mise à jour +Participation Edit: Modifier une participation #search Event search: Recherche d'événements diff --git a/Resources/views/Event/list.html.twig b/Resources/views/Event/list.html.twig index f7338fd98..38196122a 100644 --- a/Resources/views/Event/list.html.twig +++ b/Resources/views/Event/list.html.twig @@ -40,4 +40,12 @@ -{% endif %} \ No newline at end of file +{% endif %} + + \ No newline at end of file From fdb2c094a65275a7a46ea9bdd0278b90cf6d33ea Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Thu, 24 Mar 2016 17:39:01 +0100 Subject: [PATCH 31/73] Removing IndexAction from Event controller --- Controller/EventController.php | 15 --------------- Resources/config/routing/event.yml | 4 ---- 2 files changed, 19 deletions(-) diff --git a/Controller/EventController.php b/Controller/EventController.php index ec3f5a3d5..126a6b86a 100644 --- a/Controller/EventController.php +++ b/Controller/EventController.php @@ -19,21 +19,6 @@ use Symfony\Component\Form\Extension\Core\Type\HiddenType; */ class EventController extends Controller { - - /** - * Lists all Event entities. - * - */ - public function indexAction() - { - $em = $this->getDoctrine()->getManager(); - - $entities = $em->getRepository('ChillEventBundle:Event')->findAll(); - - return $this->render('ChillEventBundle:Event:index.html.twig', array( - 'entities' => $entities, - )); - } public function mostRecentIndexAction() { diff --git a/Resources/config/routing/event.yml b/Resources/config/routing/event.yml index c868cd9b7..ecbcf144f 100644 --- a/Resources/config/routing/event.yml +++ b/Resources/config/routing/event.yml @@ -1,7 +1,3 @@ -event: - path: / - defaults: { _controller: "ChillEventBundle:Event:index" } - chill_event_list_most_recent: path: most_recent defaults: { _controller: "ChillEventBundle:Event:mostRecentIndex" } From cf7f8a929b01cf2f14bc485e2a3904d7b9c30f94 Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Thu, 24 Mar 2016 18:03:45 +0100 Subject: [PATCH 32/73] Allow the modification of event + adding the prefix chill_even to all the route --- Controller/EventController.php | 35 ++++++++++---------- Controller/ParticipationController.php | 4 +-- Resources/config/routing/event.yml | 19 +++++------ Resources/views/Event/edit.html.twig | 6 ++-- Resources/views/Event/index.html.twig | 8 ++--- Resources/views/Event/list.html.twig | 8 ++--- Resources/views/Event/new.html.twig | 2 +- Resources/views/Event/show.html.twig | 2 +- Resources/views/Participation/edit.html.twig | 2 +- Resources/views/Participation/new.html.twig | 2 +- 10 files changed, 44 insertions(+), 44 deletions(-) diff --git a/Controller/EventController.php b/Controller/EventController.php index 126a6b86a..56c2b2d7f 100644 --- a/Controller/EventController.php +++ b/Controller/EventController.php @@ -42,7 +42,7 @@ class EventController extends Controller $em->persist($entity); $em->flush(); - return $this->redirect($this->generateUrl('event_show', array('event_id' => $entity->getId()))); + return $this->redirect($this->generateUrl('chill_event__event_show', array('event_id' => $entity->getId()))); } return $this->render('ChillEventBundle:Event:new.html.twig', array( @@ -61,7 +61,7 @@ class EventController extends Controller private function createCreateForm(Event $entity) { $form = $this->createForm(EventType::class, $entity, array( - 'action' => $this->generateUrl('event_create'), + 'action' => $this->generateUrl('chill_event__event_create'), 'method' => 'POST' )); @@ -152,18 +152,18 @@ class EventController extends Controller * Displays a form to edit an existing Event entity. * */ - public function editAction($id) + public function editAction($event_id) { $em = $this->getDoctrine()->getManager(); - $entity = $em->getRepository('ChillEventBundle:Event')->find($id); + $entity = $em->getRepository('ChillEventBundle:Event')->find($event_id); if (!$entity) { throw $this->createNotFoundException('Unable to find Event entity.'); } $editForm = $this->createEditForm($entity); - $deleteForm = $this->createDeleteForm($id); + $deleteForm = $this->createDeleteForm($event_id); return $this->render('ChillEventBundle:Event:edit.html.twig', array( 'entity' => $entity, @@ -181,11 +181,12 @@ class EventController extends Controller */ private function createEditForm(Event $entity) { - $form = $this->createForm(new EventType(), $entity, array( - 'action' => $this->generateUrl('event_update', array('id' => $entity->getId())), + $form = $this->createForm(EventType::class, $entity, array( + 'action' => $this->generateUrl('chill_event__event_update', array('event_id' => $entity->getId())), 'method' => 'PUT', )); + $form->add('submit', 'submit', array('label' => 'Update')); return $form; @@ -194,24 +195,24 @@ class EventController extends Controller * Edits an existing Event entity. * */ - public function updateAction(Request $request, $id) + public function updateAction(Request $request, $event_id) { $em = $this->getDoctrine()->getManager(); - $entity = $em->getRepository('ChillEventBundle:Event')->find($id); + $entity = $em->getRepository('ChillEventBundle:Event')->find($event_id); if (!$entity) { throw $this->createNotFoundException('Unable to find Event entity.'); } - $deleteForm = $this->createDeleteForm($id); + $deleteForm = $this->createDeleteForm($event_id); $editForm = $this->createEditForm($entity); $editForm->handleRequest($request); if ($editForm->isValid()) { $em->flush(); - return $this->redirect($this->generateUrl('event_edit', array('id' => $id))); + return $this->redirect($this->generateUrl('chill_event__event_edit', array('event_id' => $event_id))); } return $this->render('ChillEventBundle:Event:edit.html.twig', array( @@ -224,14 +225,14 @@ class EventController extends Controller * Deletes a Event entity. * */ - public function deleteAction(Request $request, $id) + public function deleteAction(Request $request, $event_id) { - $form = $this->createDeleteForm($id); + $form = $this->createDeleteForm($event_id); $form->handleRequest($request); if ($form->isValid()) { $em = $this->getDoctrine()->getManager(); - $entity = $em->getRepository('ChillEventBundle:Event')->find($id); + $entity = $em->getRepository('ChillEventBundle:Event')->find($event_id); if (!$entity) { throw $this->createNotFoundException('Unable to find Event entity.'); @@ -247,14 +248,14 @@ class EventController extends Controller /** * Creates a form to delete a Event entity by id. * - * @param mixed $id The entity id + * @param mixed $event_id The event id * * @return \Symfony\Component\Form\Form The form */ - private function createDeleteForm($id) + private function createDeleteForm($event_id) { return $this->createFormBuilder() - ->setAction($this->generateUrl('event_delete', array('id' => $id))) + ->setAction($this->generateUrl('chill_event__event_delete', array('event_id' => $event_id))) ->setMethod('DELETE') ->add('submit', 'submit', array('label' => 'Delete')) ->getForm() diff --git a/Controller/ParticipationController.php b/Controller/ParticipationController.php index 8cf065706..9024ea253 100644 --- a/Controller/ParticipationController.php +++ b/Controller/ParticipationController.php @@ -68,7 +68,7 @@ class ParticipationController extends Controller 'The participation was created' )); - return $this->redirectToRoute('event_show', array( + return $this->redirectToRoute('chill_event__event_show', array( 'event_id' => $participation->getEvent()->getId() )); } @@ -205,7 +205,7 @@ class ParticipationController extends Controller 'The participation was updated' )); - return $this->redirectToRoute('event_show', array( + return $this->redirectToRoute('chill_event__event_show', array( 'event_id' => $participation->getEvent()->getId() )); diff --git a/Resources/config/routing/event.yml b/Resources/config/routing/event.yml index ecbcf144f..25b39a5c6 100644 --- a/Resources/config/routing/event.yml +++ b/Resources/config/routing/event.yml @@ -8,11 +8,11 @@ chill_event_list_most_recent: label: Events icons: [calendar] -event_show: +chill_event__event_show: path: /{event_id}/show defaults: { _controller: "ChillEventBundle:Event:show" } -event_new: +chill_event__event_new: path: /new defaults: { _controller: "ChillEventBundle:Event:new" } options: @@ -22,22 +22,21 @@ event_new: label: Add an event icons: [plus, calendar-o] - -event_create: +chill_event__event_create: path: /create defaults: { _controller: "ChillEventBundle:Event:create" } methods: POST -event_edit: - path: /{id}/edit +chill_event__event_edit: + path: /{event_id}/edit defaults: { _controller: "ChillEventBundle:Event:edit" } -event_update: - path: /{id}/update +chill_event__event_update: + path: /{event_id}/update defaults: { _controller: "ChillEventBundle:Event:update" } methods: [POST, PUT] -event_delete: - path: /{id}/delete +chill_event__event_delete: + path: /{event_id}/delete defaults: { _controller: "ChillEventBundle:Event:delete" } methods: [POST, DELETE] diff --git a/Resources/views/Event/edit.html.twig b/Resources/views/Event/edit.html.twig index 733f7332c..1d365f28a 100644 --- a/Resources/views/Event/edit.html.twig +++ b/Resources/views/Event/edit.html.twig @@ -1,13 +1,13 @@ -{% extends '::base.html.twig' %} +{% extends 'ChillEventBundle::layout.html.twig' %} -{% block body -%} +{% block event_content -%}

Event edit

{{ form(edit_form) }}
  • - + Back to the list
  • diff --git a/Resources/views/Event/index.html.twig b/Resources/views/Event/index.html.twig index 9ba265dda..b5ac1e62a 100644 --- a/Resources/views/Event/index.html.twig +++ b/Resources/views/Event/index.html.twig @@ -15,16 +15,16 @@ {% for entity in entities %} - {{ entity.id }} + {{ entity.id }} {{ entity.label }} {% if entity.date %}{{ entity.date|date('Y-m-d H:i:s') }}{% endif %} @@ -35,7 +35,7 @@
    • - + Create a new entry
    • diff --git a/Resources/views/Event/list.html.twig b/Resources/views/Event/list.html.twig index 38196122a..c8e8ecbdd 100644 --- a/Resources/views/Event/list.html.twig +++ b/Resources/views/Event/list.html.twig @@ -23,12 +23,12 @@ diff --git a/Resources/views/Event/new.html.twig b/Resources/views/Event/new.html.twig index 46b00a2b2..fcd90a28b 100644 --- a/Resources/views/Event/new.html.twig +++ b/Resources/views/Event/new.html.twig @@ -7,7 +7,7 @@
      • - + Back to the list
      • diff --git a/Resources/views/Event/show.html.twig b/Resources/views/Event/show.html.twig index 8c47ab42c..12cf2672d 100644 --- a/Resources/views/Event/show.html.twig +++ b/Resources/views/Event/show.html.twig @@ -30,7 +30,7 @@
        • - + {{ 'Edit'|trans }}
        • diff --git a/Resources/views/Participation/edit.html.twig b/Resources/views/Participation/edit.html.twig index 438fba6b3..67f37802a 100644 --- a/Resources/views/Participation/edit.html.twig +++ b/Resources/views/Participation/edit.html.twig @@ -28,7 +28,7 @@
          • - + {{ 'Back to the event'|trans }}
          • diff --git a/Resources/views/Participation/new.html.twig b/Resources/views/Participation/new.html.twig index cbf6c72bd..36b77a8b6 100644 --- a/Resources/views/Participation/new.html.twig +++ b/Resources/views/Participation/new.html.twig @@ -26,7 +26,7 @@
            • - + {{ 'Back to the event'|trans }}
            • From c9ce3aca96e1246219510584ec25971e5c54eccc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 24 Mar 2016 23:00:45 +0100 Subject: [PATCH 33/73] some improvement to the Update / create event pages - i18n of all the form - add a title to each page - chill layout of each page - add flash message on successfully creation and update action For the update page, (see #23), the user is not allowed to update the center close #23 close #2 --- Controller/EventController.php | 7 ++++++ Resources/translations/messages.fr.yml | 7 ++++++ Resources/views/Event/edit.html.twig | 34 ++++++++++++++++++-------- Resources/views/Event/new.html.twig | 31 ++++++++++++++++------- Resources/views/Event/show.html.twig | 2 +- 5 files changed, 61 insertions(+), 20 deletions(-) diff --git a/Controller/EventController.php b/Controller/EventController.php index 56c2b2d7f..702433e08 100644 --- a/Controller/EventController.php +++ b/Controller/EventController.php @@ -41,6 +41,9 @@ class EventController extends Controller $em = $this->getDoctrine()->getManager(); $em->persist($entity); $em->flush(); + + $this->addFlash('success', $this->get('translator') + ->trans('The event was created')); return $this->redirect($this->generateUrl('chill_event__event_show', array('event_id' => $entity->getId()))); } @@ -186,6 +189,7 @@ class EventController extends Controller 'method' => 'PUT', )); + $form->remove('center'); $form->add('submit', 'submit', array('label' => 'Update')); @@ -211,6 +215,9 @@ class EventController extends Controller if ($editForm->isValid()) { $em->flush(); + + $this->addFlash('success', $this->get('translator') + ->trans('The event was updated')); return $this->redirect($this->generateUrl('chill_event__event_edit', array('event_id' => $event_id))); } diff --git a/Resources/translations/messages.fr.yml b/Resources/translations/messages.fr.yml index a456de1ee..67e992d7e 100644 --- a/Resources/translations/messages.fr.yml +++ b/Resources/translations/messages.fr.yml @@ -1,5 +1,6 @@ #events Name: Nom +Label: Nom Date: Date Event type : Type d'événement See: Voir @@ -14,6 +15,12 @@ Last update: Dernière mise à jour #CRUD event Details of an event: Détails d'un événement New event: Nouvel événement +Back to the most recent events: Retour aux derniers événements +Event creation: Création d'un événement +Add an event: Ajouter un événement +Event edit: Modifier un événement +The event was updated: L'événement a été modifié +The event was created: L'événement a été créé #crud participation Edit all the participations: Modifier toutes les participations diff --git a/Resources/views/Event/edit.html.twig b/Resources/views/Event/edit.html.twig index 1d365f28a..ca326aa80 100644 --- a/Resources/views/Event/edit.html.twig +++ b/Resources/views/Event/edit.html.twig @@ -1,16 +1,30 @@ {% extends 'ChillEventBundle::layout.html.twig' %} +{% block title 'Event edit'|trans %} + {% block event_content -%} -

              Event edit

              +

              {{ 'Event edit'|trans }}

              - {{ form(edit_form) }} + {{ form_start(edit_form) }} + {{ form_errors(edit_form) }} + {{ form_row(edit_form.circle) }} + {% if edit_form.center is defined %} + {{ form_row(edit_form.center) }} + {% endif %} + {{ form_row(edit_form.label) }} + {{ form_row(edit_form.date) }} + {{ form_row(edit_form.type, { 'label': 'Event type' }) }} - + + + {{ form_end(edit_form) }} {% endblock %} diff --git a/Resources/views/Event/new.html.twig b/Resources/views/Event/new.html.twig index fcd90a28b..2986a83ac 100644 --- a/Resources/views/Event/new.html.twig +++ b/Resources/views/Event/new.html.twig @@ -1,15 +1,28 @@ {% extends 'ChillEventBundle::layout.html.twig' %} +{% block title 'Event creation'|trans %} + {% block event_content -%} -

              Event creation

              +

              {{ 'Event creation'|trans }}

              - {{ form(form) }} + {{ form_start(form) }} + {{ form_errors(form) }} + {{ form_row(form.circle) }} + {{ form_row(form.center) }} + {{ form_row(form.label) }} + {{ form_row(form.date) }} + {{ form_row(form.type, { 'label': 'Event type' }) }} - + + + {{ form_end(form) }} {% endblock %} diff --git a/Resources/views/Event/show.html.twig b/Resources/views/Event/show.html.twig index 12cf2672d..541e08ea1 100644 --- a/Resources/views/Event/show.html.twig +++ b/Resources/views/Event/show.html.twig @@ -30,7 +30,7 @@
              • - + {{ 'Edit'|trans }}
              • From 20c49d5bd06d3b24b99c0972f9d8e4c35c1a2075 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 24 Mar 2016 23:06:35 +0100 Subject: [PATCH 34/73] remove event menu ref #24 --- Resources/views/layout.html.twig | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Resources/views/layout.html.twig b/Resources/views/layout.html.twig index a788962e3..3b1a4d092 100644 --- a/Resources/views/layout.html.twig +++ b/Resources/views/layout.html.twig @@ -18,12 +18,6 @@ {% extends "ChillMainBundle::layoutWithVerticalMenu.html.twig" %} -{% block vertical_menu_content %} - {{ chill_menu('event', { - 'layout': 'ChillMainBundle::Menu/verticalMenu.html.twig', - }) }} -{% endblock %} - {% block layout_wvm_content %} {% block event_content %}

                {{ 'Event' |trans }}

                From d8de53ca3c700fd70eb50002a3dd666204d74d9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 24 Mar 2016 23:27:39 +0100 Subject: [PATCH 35/73] rename 'label' to 'name'. Warning : this commit require to rename some table column, but the original Version file has been update. If you do not care to loose your date, you may run : ``` php app/console doctrine:migrations:execute --down 20160318111334 php app/console doctrine:migrations:execute --up 20160318111334 php app/console doctrine:cache:metadata #(if you have a cache for doctrine meta date) ``` close #20 --- DataFixtures/ORM/LoadEventTypes.php | 18 +++++++++--------- DataFixtures/ORM/LoadParticipation.php | 2 +- Entity/Event.php | 10 +++++----- Entity/EventType.php | 10 +++++----- Entity/Role.php | 10 +++++----- Entity/Status.php | 12 ++++++------ Form/EventType.php | 2 +- Form/EventTypeType.php | 2 +- Form/ParticipationType.php | 4 ++-- Form/RoleType.php | 2 +- Form/StatusType.php | 2 +- Form/Type/TranslatableEventType.php | 2 +- Resources/config/doctrine/Event.orm.yml | 2 +- Resources/config/doctrine/EventType.orm.yml | 2 +- Resources/config/doctrine/Role.orm.yml | 2 +- Resources/config/doctrine/Status.orm.yml | 2 +- Resources/migrations/Version20160318111334.php | 8 ++++---- Resources/views/Event/edit.html.twig | 2 +- Resources/views/Event/index.html.twig | 4 ++-- Resources/views/Event/list.html.twig | 4 ++-- Resources/views/Event/new.html.twig | 2 +- Resources/views/Event/show.html.twig | 12 ++++++------ Resources/views/EventType/index.html.twig | 2 +- Resources/views/EventType/show.html.twig | 4 ++-- Resources/views/Participation/edit.html.twig | 2 +- Resources/views/Participation/new.html.twig | 2 +- Resources/views/Role/index.html.twig | 4 ++-- Resources/views/Role/show.html.twig | 4 ++-- Resources/views/Status/index.html.twig | 4 ++-- Resources/views/Status/show.html.twig | 4 ++-- 30 files changed, 71 insertions(+), 71 deletions(-) diff --git a/DataFixtures/ORM/LoadEventTypes.php b/DataFixtures/ORM/LoadEventTypes.php index 38e171d97..40e9b76b0 100644 --- a/DataFixtures/ORM/LoadEventTypes.php +++ b/DataFixtures/ORM/LoadEventTypes.php @@ -29,7 +29,7 @@ class LoadEventTypes extends AbstractFixture implements OrderedFixtureInterface { $type = (new EventType()) ->setActive(true) - ->setLabel(array('fr' => 'Échange de savoirs', 'en' => 'Exchange of knowledge')) + ->setName(array('fr' => 'Échange de savoirs', 'en' => 'Exchange of knowledge')) ; $manager->persist($type); $this->addReference('event_type_knowledge', $type); @@ -37,26 +37,26 @@ class LoadEventTypes extends AbstractFixture implements OrderedFixtureInterface $role = (new Role()) ->setActive(true) - ->setLabel(array('fr' => 'Participant', 'nl' => 'Deelneemer', 'en' => 'Participant')) + ->setName(array('fr' => 'Participant', 'nl' => 'Deelneemer', 'en' => 'Participant')) ->setType($type) ; $manager->persist($role); $role = (new Role()) ->setActive(true) - ->setLabel(array('fr' => 'Animateur')) + ->setName(array('fr' => 'Animateur')) ->setType($type); $manager->persist($role); $status = (new Status()) ->setActive(true) - ->setLabel(array('fr' => 'Inscrit')) + ->setName(array('fr' => 'Inscrit')) ->setType($type); $manager->persist($status); $status = (new Status()) ->setActive(true) - ->setLabel(array('fr' => 'Présent')) + ->setName(array('fr' => 'Présent')) ->setType($type) ; $manager->persist($status); @@ -64,7 +64,7 @@ class LoadEventTypes extends AbstractFixture implements OrderedFixtureInterface $type = (new EventType()) ->setActive(true) - ->setLabel(array('fr' => 'Formation', 'en' => 'Course', 'nl' => 'Opleiding')) + ->setName(array('fr' => 'Formation', 'en' => 'Course', 'nl' => 'Opleiding')) ; $manager->persist($type); $this->addReference('event_type_course', $type); @@ -72,21 +72,21 @@ class LoadEventTypes extends AbstractFixture implements OrderedFixtureInterface $role = (new Role()) ->setActive(true) - ->setLabel(array('fr' => 'Participant', 'nl' => 'Deelneemer', 'en' => 'Participant')) + ->setName(array('fr' => 'Participant', 'nl' => 'Deelneemer', 'en' => 'Participant')) ->setType($type) ; $manager->persist($role); $status = (new Status()) ->setActive(true) - ->setLabel(array('fr' => 'Inscrit')) + ->setName(array('fr' => 'Inscrit')) ->setType($type) ; $manager->persist($status); $status = (new Status()) ->setActive(true) - ->setLabel(array('fr' => 'En liste d\'attente')) + ->setName(array('fr' => 'En liste d\'attente')) ->setType($type) ; $manager->persist($status); diff --git a/DataFixtures/ORM/LoadParticipation.php b/DataFixtures/ORM/LoadParticipation.php index 98f19a82e..5f18d06b2 100644 --- a/DataFixtures/ORM/LoadParticipation.php +++ b/DataFixtures/ORM/LoadParticipation.php @@ -80,7 +80,7 @@ class LoadParticipation extends AbstractFixture implements OrderedFixtureInterfa for($i=0; $i<$expectedNumber; $i++) { $event = (new Event()) ->setDate($this->faker->dateTimeBetween('-2 years', '+6 months')) - ->setLabel($this->faker->words(rand(2,4), true)) + ->setName($this->faker->words(rand(2,4), true)) ->setType($this->getReference(LoadEventTypes::$refs[array_rand(LoadEventTypes::$refs)])) ->setCenter($center) ->setCircle( diff --git a/Entity/Event.php b/Entity/Event.php index d9512fda0..0246be6fd 100644 --- a/Entity/Event.php +++ b/Entity/Event.php @@ -18,7 +18,7 @@ class Event implements HasCenterInterface, HasScopeInterface /** * @var string */ - private $label; + private $name; /** * @var \DateTime @@ -74,9 +74,9 @@ class Event implements HasCenterInterface, HasScopeInterface * * @return Event */ - public function setLabel($label) + public function setName($label) { - $this->label = $label; + $this->name = $label; return $this; } @@ -86,9 +86,9 @@ class Event implements HasCenterInterface, HasScopeInterface * * @return string */ - public function getLabel() + public function getName() { - return $this->label; + return $this->name; } /** diff --git a/Entity/EventType.php b/Entity/EventType.php index e7646c03a..8f0d2bba4 100644 --- a/Entity/EventType.php +++ b/Entity/EventType.php @@ -15,7 +15,7 @@ class EventType /** * @var array */ - private $label; + private $name; /** * @var boolean @@ -58,9 +58,9 @@ class EventType * * @return EventType */ - public function setLabel($label) + public function setName($label) { - $this->label = $label; + $this->name = $label; return $this; } @@ -70,9 +70,9 @@ class EventType * * @return array */ - public function getLabel() + public function getName() { - return $this->label; + return $this->name; } /** diff --git a/Entity/Role.php b/Entity/Role.php index fe98414ab..c50665b11 100644 --- a/Entity/Role.php +++ b/Entity/Role.php @@ -15,7 +15,7 @@ class Role /** * @var array */ - private $label; + private $name; /** * @var boolean @@ -45,9 +45,9 @@ class Role * * @return Role */ - public function setLabel($label) + public function setName($label) { - $this->label = $label; + $this->name = $label; return $this; } @@ -57,9 +57,9 @@ class Role * * @return array */ - public function getLabel() + public function getName() { - return $this->label; + return $this->name; } /** diff --git a/Entity/Status.php b/Entity/Status.php index d39a325c3..6a4ee29ad 100644 --- a/Entity/Status.php +++ b/Entity/Status.php @@ -15,7 +15,7 @@ class Status /** * @var array */ - private $label; + private $name; /** * @var boolean @@ -41,13 +41,13 @@ class Status /** * Set label * - * @param array $label + * @param array $name * * @return Status */ - public function setLabel($label) + public function setName($name) { - $this->label = $label; + $this->name = $name; return $this; } @@ -57,9 +57,9 @@ class Status * * @return array */ - public function getLabel() + public function getName() { - return $this->label; + return $this->name; } diff --git a/Form/EventType.php b/Form/EventType.php index 29b32a086..a3417a81e 100644 --- a/Form/EventType.php +++ b/Form/EventType.php @@ -67,7 +67,7 @@ class EventType extends AbstractType } $builder - ->add('label') + ->add('name') ->add( 'date', 'date', diff --git a/Form/EventTypeType.php b/Form/EventTypeType.php index 02ec828e8..9616f9f59 100644 --- a/Form/EventTypeType.php +++ b/Form/EventTypeType.php @@ -15,7 +15,7 @@ class EventTypeType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options) { $builder - ->add('label') + ->add('name') ->add('active') ; } diff --git a/Form/ParticipationType.php b/Form/ParticipationType.php index 4891a4811..5b754dcf9 100644 --- a/Form/ParticipationType.php +++ b/Form/ParticipationType.php @@ -76,7 +76,7 @@ class ParticipationType extends AbstractType ); }, 'choice_label' => function(Role $r) use ($translatableStringHelper) { - return $translatableStringHelper->localize($r->getLabel()); + return $translatableStringHelper->localize($r->getName()); } )); @@ -102,7 +102,7 @@ class ParticipationType extends AbstractType return $qb; }, 'choice_label' => function(Status $s) use ($translatableStringHelper) { - return $translatableStringHelper->localize($s->getLabel()); + return $translatableStringHelper->localize($s->getName()); } )); diff --git a/Form/RoleType.php b/Form/RoleType.php index 293aec1d1..4f8fb3c53 100644 --- a/Form/RoleType.php +++ b/Form/RoleType.php @@ -15,7 +15,7 @@ class RoleType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options) { $builder - ->add('label') + ->add('name') ->add('active') ->add('type') ; diff --git a/Form/StatusType.php b/Form/StatusType.php index 24bdcd604..1bef97168 100644 --- a/Form/StatusType.php +++ b/Form/StatusType.php @@ -15,7 +15,7 @@ class StatusType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options) { $builder - ->add('label') + ->add('name') ->add('active') ->add('type') ; diff --git a/Form/Type/TranslatableEventType.php b/Form/Type/TranslatableEventType.php index cf2abc14a..6b7a80d03 100644 --- a/Form/Type/TranslatableEventType.php +++ b/Form/Type/TranslatableEventType.php @@ -62,7 +62,7 @@ class TranslatableEventType extends AbstractType ->where('et.active = true'); }, 'choice_label' => function (EventType $t) use ($helper) { - return $helper->localize($t->getLabel()); + return $helper->localize($t->getName()); }, ) ); diff --git a/Resources/config/doctrine/Event.orm.yml b/Resources/config/doctrine/Event.orm.yml index ae69e2f06..eb02041e4 100644 --- a/Resources/config/doctrine/Event.orm.yml +++ b/Resources/config/doctrine/Event.orm.yml @@ -8,7 +8,7 @@ Chill\EventBundle\Entity\Event: generator: strategy: AUTO fields: - label: + name: type: string length: '150' date: diff --git a/Resources/config/doctrine/EventType.orm.yml b/Resources/config/doctrine/EventType.orm.yml index 17bc5cadb..dcfab3ba6 100644 --- a/Resources/config/doctrine/EventType.orm.yml +++ b/Resources/config/doctrine/EventType.orm.yml @@ -8,7 +8,7 @@ Chill\EventBundle\Entity\EventType: generator: strategy: AUTO fields: - label: + name: type: json_array active: type: boolean diff --git a/Resources/config/doctrine/Role.orm.yml b/Resources/config/doctrine/Role.orm.yml index 8d1723c37..b6a1ae677 100644 --- a/Resources/config/doctrine/Role.orm.yml +++ b/Resources/config/doctrine/Role.orm.yml @@ -8,7 +8,7 @@ Chill\EventBundle\Entity\Role: generator: strategy: AUTO fields: - label: + name: type: json_array active: type: boolean diff --git a/Resources/config/doctrine/Status.orm.yml b/Resources/config/doctrine/Status.orm.yml index 2849b7522..f1567f8f0 100644 --- a/Resources/config/doctrine/Status.orm.yml +++ b/Resources/config/doctrine/Status.orm.yml @@ -8,7 +8,7 @@ Chill\EventBundle\Entity\Status: generator: strategy: AUTO fields: - label: + name: type: json_array active: type: boolean diff --git a/Resources/migrations/Version20160318111334.php b/Resources/migrations/Version20160318111334.php index fe23df743..df23eaab1 100644 --- a/Resources/migrations/Version20160318111334.php +++ b/Resources/migrations/Version20160318111334.php @@ -24,24 +24,24 @@ class Version20160318111334 extends AbstractMigration $this->addSql('CREATE SEQUENCE chill_event_event_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); $this->addSql('CREATE SEQUENCE chill_event_participation_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); $this->addSql('CREATE TABLE chill_event_event_type (' - . 'id INT NOT NULL, label JSON NOT NULL, ' + . 'id INT NOT NULL, name JSON NOT NULL, ' . 'active BOOLEAN NOT NULL, PRIMARY KEY(id))'); $this->addSql('CREATE TABLE chill_event_role (' . 'id INT NOT NULL, ' . 'type_id INT DEFAULT NULL, ' - . 'label JSON NOT NULL, ' + . 'name JSON NOT NULL, ' . 'active BOOLEAN NOT NULL, ' . 'PRIMARY KEY(id))'); $this->addSql('CREATE INDEX IDX_AA714E54C54C8C93 ON chill_event_role (type_id)'); $this->addSql('CREATE TABLE chill_event_status (id INT NOT NULL, ' . 'type_id INT DEFAULT NULL, ' - . 'label JSON NOT NULL, ' + . 'name JSON NOT NULL, ' . 'active BOOLEAN NOT NULL, ' . 'PRIMARY KEY(id))'); $this->addSql('CREATE INDEX IDX_A6CC85D0C54C8C93 ON chill_event_status (type_id)'); $this->addSql('CREATE TABLE chill_event_event (' . 'id INT NOT NULL, ' - . 'label VARCHAR(150) NOT NULL, ' + . 'name VARCHAR(150) NOT NULL, ' . 'date DATE NOT NULL, ' . 'center_id INT DEFAULT NULL, ' . 'type_id INT DEFAULT NULL, ' diff --git a/Resources/views/Event/edit.html.twig b/Resources/views/Event/edit.html.twig index ca326aa80..03519eff9 100644 --- a/Resources/views/Event/edit.html.twig +++ b/Resources/views/Event/edit.html.twig @@ -11,7 +11,7 @@ {% if edit_form.center is defined %} {{ form_row(edit_form.center) }} {% endif %} - {{ form_row(edit_form.label) }} + {{ form_row(edit_form.name) }} {{ form_row(edit_form.date) }} {{ form_row(edit_form.type, { 'label': 'Event type' }) }} diff --git a/Resources/views/Event/index.html.twig b/Resources/views/Event/index.html.twig index b5ac1e62a..442d5ca67 100644 --- a/Resources/views/Event/index.html.twig +++ b/Resources/views/Event/index.html.twig @@ -7,7 +7,7 @@ Id - Label + Name Date Actions @@ -16,7 +16,7 @@ {% for entity in entities %} {{ entity.id }} - {{ entity.label }} + {{ entity.name }} {% if entity.date %}{{ entity.date|date('Y-m-d H:i:s') }}{% endif %}
                  diff --git a/Resources/views/Event/list.html.twig b/Resources/views/Event/list.html.twig index c8e8ecbdd..4f3687049 100644 --- a/Resources/views/Event/list.html.twig +++ b/Resources/views/Event/list.html.twig @@ -16,9 +16,9 @@ {% for event in events %} - {{ event.label }} + {{ event.name }} {{ event.date|localizeddate('long', 'none') }} - {{ event.type.label|localize_translatable_string }} + {{ event.type.name|localize_translatable_string }}
                  • diff --git a/Resources/views/Event/new.html.twig b/Resources/views/Event/new.html.twig index 2986a83ac..17c8de06b 100644 --- a/Resources/views/Event/new.html.twig +++ b/Resources/views/Event/new.html.twig @@ -9,7 +9,7 @@ {{ form_errors(form) }} {{ form_row(form.circle) }} {{ form_row(form.center) }} - {{ form_row(form.label) }} + {{ form_row(form.name) }} {{ form_row(form.date) }} {{ form_row(form.type, { 'label': 'Event type' }) }} diff --git a/Resources/views/Event/show.html.twig b/Resources/views/Event/show.html.twig index 541e08ea1..19393459e 100644 --- a/Resources/views/Event/show.html.twig +++ b/Resources/views/Event/show.html.twig @@ -1,6 +1,6 @@ {% extends 'ChillEventBundle::layout.html.twig' %} -{% block title 'Event : %label%'|trans({ '%label%' : event.label } ) %} +{% block title 'Event : %label%'|trans({ '%label%' : event.name } ) %} {% import 'ChillPersonBundle:Person:macro.html.twig' as person_macro %} @@ -11,7 +11,7 @@ {{ 'Name'|trans }} - {{ event.label }} + {{ event.name }} {{ 'Date'|trans }} @@ -19,7 +19,7 @@ {{ 'Event type'|trans }} - {{ event.type.label|localize_translatable_string }} + {{ event.type.name|localize_translatable_string }} {{ 'Circle'|trans }} @@ -55,9 +55,9 @@ {% for participation in event.participations %} {{ person_macro.render(participation.person) }} - {{ participation.role.label|localize_translatable_string }} - {{ participation.status.label|localize_translatable_string }} - {{ participation.lastUpdate|time_diff }} + {{ participation.role.name|localize_translatable_string }} + {{ participation.status.name|localize_translatable_string }} + {{ participation.lastUpdate|time_diff }}
                      {% if is_granted('CHILL_EVENT_PARTICIPATION_UPDATE', participation) %} diff --git a/Resources/views/EventType/index.html.twig b/Resources/views/EventType/index.html.twig index 72c47e279..b40ce7b0f 100644 --- a/Resources/views/EventType/index.html.twig +++ b/Resources/views/EventType/index.html.twig @@ -16,7 +16,7 @@ {% for entity in entities %} {{ entity.id }} - {{ entity.label }} + {{ entity.name }} {{ entity.active }}
                        diff --git a/Resources/views/EventType/show.html.twig b/Resources/views/EventType/show.html.twig index 818e30fa9..3e748ca85 100644 --- a/Resources/views/EventType/show.html.twig +++ b/Resources/views/EventType/show.html.twig @@ -10,8 +10,8 @@ {{ entity.id }} - Label - {{ entity.label }} + Name + {{ entity.name }} Active diff --git a/Resources/views/Participation/edit.html.twig b/Resources/views/Participation/edit.html.twig index 67f37802a..7ad24aed1 100644 --- a/Resources/views/Participation/edit.html.twig +++ b/Resources/views/Participation/edit.html.twig @@ -13,7 +13,7 @@ {{ 'Associated event'|trans }} - {{ participation.event.label }} + {{ participation.event.name }} {{ 'Date'|trans }} diff --git a/Resources/views/Participation/new.html.twig b/Resources/views/Participation/new.html.twig index 36b77a8b6..9544d62a7 100644 --- a/Resources/views/Participation/new.html.twig +++ b/Resources/views/Participation/new.html.twig @@ -15,7 +15,7 @@ {{ 'Associated event'|trans }} - {{ participation.event.label }} + {{ participation.event.name }} diff --git a/Resources/views/Role/index.html.twig b/Resources/views/Role/index.html.twig index dcfda2a25..b6dd692bc 100644 --- a/Resources/views/Role/index.html.twig +++ b/Resources/views/Role/index.html.twig @@ -7,7 +7,7 @@ Id - Label + Name Active Actions @@ -16,7 +16,7 @@ {% for entity in entities %} {{ entity.id }} - {{ entity.label }} + {{ entity.name }} {{ entity.active }}
                          diff --git a/Resources/views/Role/show.html.twig b/Resources/views/Role/show.html.twig index a212c2f6d..99207becc 100644 --- a/Resources/views/Role/show.html.twig +++ b/Resources/views/Role/show.html.twig @@ -10,8 +10,8 @@ {{ entity.id }} - Label - {{ entity.label }} + Name + {{ entity.name }} Active diff --git a/Resources/views/Status/index.html.twig b/Resources/views/Status/index.html.twig index e5ec9e480..67d138ce9 100644 --- a/Resources/views/Status/index.html.twig +++ b/Resources/views/Status/index.html.twig @@ -7,7 +7,7 @@ Id - Label + Name Active Actions @@ -16,7 +16,7 @@ {% for entity in entities %} {{ entity.id }} - {{ entity.label }} + {{ entity.name }} {{ entity.active }}
                            diff --git a/Resources/views/Status/show.html.twig b/Resources/views/Status/show.html.twig index 7b0dd4049..2b56d32eb 100644 --- a/Resources/views/Status/show.html.twig +++ b/Resources/views/Status/show.html.twig @@ -10,8 +10,8 @@ {{ entity.id }} - Label - {{ entity.label }} + Name + {{ entity.name }} Active From 90edc185314a2b5771e4737991280d112e06318a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 24 Mar 2016 23:59:24 +0100 Subject: [PATCH 36/73] fix missing label=> name in validation ref #20 --- Resources/config/validation.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Resources/config/validation.yml b/Resources/config/validation.yml index b8b62d678..d6a12b418 100644 --- a/Resources/config/validation.yml +++ b/Resources/config/validation.yml @@ -12,7 +12,7 @@ Chill\EventBundle\Entity\Participation: Chill\EventBundle\Entity\Event: properties: - label: + name: - Length: min: 3 max: 75 From a6d4cb5f5e85430c327c3358170b6a9988cbcafd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 25 Mar 2016 00:07:34 +0100 Subject: [PATCH 37/73] remove var_dump --- Entity/Participation.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Entity/Participation.php b/Entity/Participation.php index 3aa52313c..ef33c6b99 100644 --- a/Entity/Participation.php +++ b/Entity/Participation.php @@ -231,7 +231,6 @@ class Participation implements HasCenterInterface, HasScopeInterface ->atPath('status') ->addViolation(); } - var_dump('ok'); } } From 5949fd8cfb09166d8cec504e6796217b56c6ea33 Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Fri, 25 Mar 2016 08:53:29 +0100 Subject: [PATCH 38/73] adding css class for buttons --- Resources/views/Event/list.html.twig | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Resources/views/Event/list.html.twig b/Resources/views/Event/list.html.twig index 4f3687049..0c98cb027 100644 --- a/Resources/views/Event/list.html.twig +++ b/Resources/views/Event/list.html.twig @@ -23,12 +23,12 @@
                            • {# {% if is_granted('CHILL_EVENT_SEE_DETAILS', event) %} #} - + {{ 'See'|trans }} {# {% endif %} #} {% if is_granted('CHILL_EVENT_UPDATE', event) %} - + {{ 'Edit'|trans }} {% endif %} @@ -44,7 +44,8 @@
                              • - + + {{ 'New event'|trans }}
                              • From 827d1d3f2c35c45610b12a952712ecb9ff9f45e1 Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Fri, 25 Mar 2016 08:57:41 +0100 Subject: [PATCH 39/73] adding css class for buttons - page event edit --- Resources/views/Event/edit.html.twig | 1 + 1 file changed, 1 insertion(+) diff --git a/Resources/views/Event/edit.html.twig b/Resources/views/Event/edit.html.twig index 03519eff9..a5752fb73 100644 --- a/Resources/views/Event/edit.html.twig +++ b/Resources/views/Event/edit.html.twig @@ -18,6 +18,7 @@
                                • + {{ 'Back to the most recent events'|trans }}
                                • From 4aa6c4b53f15480e7b4a1db6174d4f89f8a9b2dc Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Fri, 25 Mar 2016 09:02:48 +0100 Subject: [PATCH 40/73] adding css class for buttons - page event new & show --- Resources/views/Event/new.html.twig | 1 + Resources/views/Event/show.html.twig | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Resources/views/Event/new.html.twig b/Resources/views/Event/new.html.twig index 17c8de06b..1c29a495d 100644 --- a/Resources/views/Event/new.html.twig +++ b/Resources/views/Event/new.html.twig @@ -16,6 +16,7 @@
                                  • + {{ 'Back to the most recent events'|trans }}
                                  • diff --git a/Resources/views/Event/show.html.twig b/Resources/views/Event/show.html.twig index 19393459e..74fa07559 100644 --- a/Resources/views/Event/show.html.twig +++ b/Resources/views/Event/show.html.twig @@ -30,7 +30,7 @@
                                    • - + {{ 'Edit'|trans }}
                                    • @@ -63,7 +63,7 @@ {% if is_granted('CHILL_EVENT_PARTICIPATION_UPDATE', participation) %}
                                    • + class="sc-button bt-edit"> {{ 'Edit'|trans }}
                                    • @@ -80,12 +80,12 @@
                                        {% if count > 0 %} -
                                      • {{ 'Edit all the participations'|trans }}
                                      • +
                                      • {{ 'Edit all the participations'|trans }}
                                      • {% endif %}
                                      • {{ form_start(form_add_participation_by_person) }} {{ form_widget(form_add_participation_by_person.person_id, { 'attr' : { 'style' : 'width: 20em; display:inline-block; ' } } ) }} - {{ form_widget(form_add_participation_by_person.submit, { 'attr' : { 'class' : 'sc-button btn-create' } } ) }} + {{ form_widget(form_add_participation_by_person.submit, { 'attr' : { 'class' : 'sc-button bt-create' } } ) }} {{ form_rest(form_add_participation_by_person) }} {{ form_end(form_add_participation_by_person) }}
                                        From 005fd222905b11fcd76ca9a1a285daad692eb18c Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Fri, 25 Mar 2016 09:07:32 +0100 Subject: [PATCH 41/73] adding css class for buttons - page participation new & edit --- Resources/views/Participation/edit.html.twig | 5 +++-- Resources/views/Participation/new.html.twig | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Resources/views/Participation/edit.html.twig b/Resources/views/Participation/edit.html.twig index 7ad24aed1..a778eeef7 100644 --- a/Resources/views/Participation/edit.html.twig +++ b/Resources/views/Participation/edit.html.twig @@ -28,12 +28,13 @@
                                        • - + + {{ 'Back to the event'|trans }}
                                        • - {{ form_widget(form.submit, { 'attr' : { 'class' : 'sc-button btn-create' } } ) }} + {{ form_widget(form.submit, { 'attr' : { 'class' : 'sc-button bt-edit' } } ) }}
                                        diff --git a/Resources/views/Participation/new.html.twig b/Resources/views/Participation/new.html.twig index 9544d62a7..9b7a55a7f 100644 --- a/Resources/views/Participation/new.html.twig +++ b/Resources/views/Participation/new.html.twig @@ -27,11 +27,12 @@
                                        • + {{ 'Back to the event'|trans }}
                                        • - {{ form_widget(form.submit, { 'attr' : { 'class' : 'sc-button btn-create' } } ) }} + {{ form_widget(form.submit, { 'attr' : { 'class' : 'sc-button bt-create' } } ) }}
                                        From 9cdbd8303a9f4fc42d13a421fac109f18a45043d Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Fri, 25 Mar 2016 10:10:15 +0100 Subject: [PATCH 42/73] Removing code for Deleting an event --- Controller/EventController.php | 44 ------------------------------ Resources/config/routing/event.yml | 5 ---- 2 files changed, 49 deletions(-) diff --git a/Controller/EventController.php b/Controller/EventController.php index 702433e08..cb2301e6d 100644 --- a/Controller/EventController.php +++ b/Controller/EventController.php @@ -166,12 +166,10 @@ class EventController extends Controller } $editForm = $this->createEditForm($entity); - $deleteForm = $this->createDeleteForm($event_id); return $this->render('ChillEventBundle:Event:edit.html.twig', array( 'entity' => $entity, 'edit_form' => $editForm->createView(), - 'delete_form' => $deleteForm->createView(), )); } @@ -209,7 +207,6 @@ class EventController extends Controller throw $this->createNotFoundException('Unable to find Event entity.'); } - $deleteForm = $this->createDeleteForm($event_id); $editForm = $this->createEditForm($entity); $editForm->handleRequest($request); @@ -225,47 +222,6 @@ class EventController extends Controller return $this->render('ChillEventBundle:Event:edit.html.twig', array( 'entity' => $entity, 'edit_form' => $editForm->createView(), - 'delete_form' => $deleteForm->createView(), )); } - /** - * Deletes a Event entity. - * - */ - public function deleteAction(Request $request, $event_id) - { - $form = $this->createDeleteForm($event_id); - $form->handleRequest($request); - - if ($form->isValid()) { - $em = $this->getDoctrine()->getManager(); - $entity = $em->getRepository('ChillEventBundle:Event')->find($event_id); - - if (!$entity) { - throw $this->createNotFoundException('Unable to find Event entity.'); - } - - $em->remove($entity); - $em->flush(); - } - - return $this->redirect($this->generateUrl('event')); - } - - /** - * Creates a form to delete a Event entity by id. - * - * @param mixed $event_id The event id - * - * @return \Symfony\Component\Form\Form The form - */ - private function createDeleteForm($event_id) - { - return $this->createFormBuilder() - ->setAction($this->generateUrl('chill_event__event_delete', array('event_id' => $event_id))) - ->setMethod('DELETE') - ->add('submit', 'submit', array('label' => 'Delete')) - ->getForm() - ; - } } diff --git a/Resources/config/routing/event.yml b/Resources/config/routing/event.yml index 25b39a5c6..256850e5c 100644 --- a/Resources/config/routing/event.yml +++ b/Resources/config/routing/event.yml @@ -35,8 +35,3 @@ chill_event__event_update: path: /{event_id}/update defaults: { _controller: "ChillEventBundle:Event:update" } methods: [POST, PUT] - -chill_event__event_delete: - path: /{event_id}/delete - defaults: { _controller: "ChillEventBundle:Event:delete" } - methods: [POST, DELETE] From 93a5568aeec0263c8c1ff027f42a683726740296 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 7 Apr 2016 23:29:22 +0200 Subject: [PATCH 43/73] splitting function in order to prepare single/multiple adding association ref #6 --- Controller/ParticipationController.php | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Controller/ParticipationController.php b/Controller/ParticipationController.php index 9024ea253..a04f05ed0 100644 --- a/Controller/ParticipationController.php +++ b/Controller/ParticipationController.php @@ -21,6 +21,7 @@ namespace Chill\EventBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Chill\EventBundle\Entity\Participation; use Chill\EventBundle\Form\ParticipationType; use Symfony\Component\Form\Extension\Core\Type\SubmitType; @@ -33,7 +34,33 @@ use Chill\EventBundle\Security\Authorization\ParticipationVoter; */ class ParticipationController extends Controller { + /** + * Show a form to add a participation + * + * This function parse the person_id / persons_ids query argument + * and decide if it should process a single or multiple participation + * + * @param Request $request + */ public function newAction(Request $request) + { + $single = $request->query->getInt('person_id', null); + $multiple = $request->query->get('persons_ids', null); + + if ($single !== NULL AND $multiple !== NULL) { + // we are not allowed to have both person_id and persons_ids + return (new Response()) + ->setStatusCode(Response::HTTP_BAD_REQUEST) + ->setContent("You are not allow to provide both 'person_id' and " + . "'persons_ids' simulaneously"); + } + + if ($single !== NULL) { + return $this->newSingleAction($request); + } + } + + protected function newSingleAction(Request $request) { $participation = $this->handleRequest($request, new Participation()); From bcfa2c2131d210deb14420954e1f3f0512f595bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Sat, 9 Apr 2016 23:44:40 +0200 Subject: [PATCH 44/73] bootstrapping tests --- .gitignore | 2 +- Resources/test/Fixtures/App/AppKernel.php | 46 ++++++++++++++++ Resources/test/Fixtures/App/config/config.yml | 43 +++++++++++++++ .../test/Fixtures/App/config/config_test.yml | 52 +++++++++++++++++++ .../App/config/parameters.gitlab-ci.yml | 11 ++++ .../test/Fixtures/App/config/parameters.yml | 11 ++++ .../Fixtures/App/config/parameters.yml.dist | 11 ++++ .../test/Fixtures/App/config/routing.yml | 4 ++ Resources/test/Fixtures/App/console | 27 ++++++++++ Resources/test/bootstrap.php | 8 +++ .../Participation/new-multiple.html.twig | 40 ++++++++++++++ phpunit.xml.dist | 23 ++++++++ 12 files changed, 277 insertions(+), 1 deletion(-) create mode 100644 Resources/test/Fixtures/App/AppKernel.php create mode 100644 Resources/test/Fixtures/App/config/config.yml create mode 100644 Resources/test/Fixtures/App/config/config_test.yml create mode 100644 Resources/test/Fixtures/App/config/parameters.gitlab-ci.yml create mode 100644 Resources/test/Fixtures/App/config/parameters.yml create mode 100644 Resources/test/Fixtures/App/config/parameters.yml.dist create mode 100644 Resources/test/Fixtures/App/config/routing.yml create mode 100644 Resources/test/Fixtures/App/console create mode 100644 Resources/test/bootstrap.php create mode 100644 Resources/views/Participation/new-multiple.html.twig create mode 100644 phpunit.xml.dist diff --git a/.gitignore b/.gitignore index a06b406d1..093d23fa5 100644 --- a/.gitignore +++ b/.gitignore @@ -18,7 +18,7 @@ app/config/parameters.yml Tests/Fixtures/App/config/parameters.yml # fixtures -Resources/test/* +Resources/test/Fixtures/App/DoctrineMigrations/ #composer composer.lock diff --git a/Resources/test/Fixtures/App/AppKernel.php b/Resources/test/Fixtures/App/AppKernel.php new file mode 100644 index 000000000..366c1e6a0 --- /dev/null +++ b/Resources/test/Fixtures/App/AppKernel.php @@ -0,0 +1,46 @@ +load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml'); + } + + /** + * @return string + */ + public function getCacheDir() + { + return sys_get_temp_dir().'/ChillEventBundle/cache'; + } + + /** + * @return string + */ + public function getLogDir() + { + return sys_get_temp_dir().'/ChillEventBundle/logs'; + } +} diff --git a/Resources/test/Fixtures/App/config/config.yml b/Resources/test/Fixtures/App/config/config.yml new file mode 100644 index 000000000..cf6bb3108 --- /dev/null +++ b/Resources/test/Fixtures/App/config/config.yml @@ -0,0 +1,43 @@ +imports: + - { resource: parameters.yml } + +framework: + secret: Not very secret + router: { resource: "%kernel.root_dir%/config/routing.yml" } + form: true + csrf_protection: true + session: ~ + default_locale: fr + translator: { fallback: fr } + profiler: { only_exceptions: false } + templating: + engines: ['twig'] + +# Doctrine Configuration +doctrine: + dbal: + driver: pdo_pgsql + host: "%database_host%" + port: "%database_port%" + dbname: "%database_name%" + user: "%database_user%" + password: "%database_password%" + charset: UTF8 + mapping_types: + jsonb: json_array + + orm: + auto_generate_proxy_classes: "%kernel.debug%" + auto_mapping: true + +# Assetic Configuration +assetic: + debug: "%kernel.debug%" + use_controller: false + bundles: [ ] + #java: /usr/bin/java + filters: + cssrewrite: ~ + +chill_main: + available_languages: [fr, en] diff --git a/Resources/test/Fixtures/App/config/config_test.yml b/Resources/test/Fixtures/App/config/config_test.yml new file mode 100644 index 000000000..b4f6d786a --- /dev/null +++ b/Resources/test/Fixtures/App/config/config_test.yml @@ -0,0 +1,52 @@ +imports: + - { resource: config.yml } + +framework: + test: ~ + session: + storage_id: session.storage.filesystem + +security: + role_hierarchy: + CHILL_MASTER_ROLE: [CHILL_INHERITED_ROLE_1] + providers: + chain_provider: + chain : + providers: [in_memory, users] + in_memory: + memory: + users: + admin: { password: "password", roles: 'ROLE_ADMIN' } + users: + entity: + class: Chill\MainBundle\Entity\User + property: username + + encoders: + Chill\MainBundle\Entity\User: + algorithm: bcrypt + Symfony\Component\Security\Core\User\User: + algorithm: plaintext + + firewalls: + dev: + pattern: ^/(_(profiler|wdt)|css|images|js)/ + security: false + + + + default: + anonymous: ~ + http_basic: ~ + form_login: + csrf_parameter: _csrf_token + csrf_token_id: authenticate + csrf_provider: form.csrf_provider + + logout: ~ + + + access_control: + - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY } + - { path: ^/[a-z]*/admin, roles: ROLE_ADMIN } + - { path: ^/, roles: ROLE_USER } \ No newline at end of file diff --git a/Resources/test/Fixtures/App/config/parameters.gitlab-ci.yml b/Resources/test/Fixtures/App/config/parameters.gitlab-ci.yml new file mode 100644 index 000000000..c4e63ef76 --- /dev/null +++ b/Resources/test/Fixtures/App/config/parameters.gitlab-ci.yml @@ -0,0 +1,11 @@ +parameters: + database_host: chill__database + database_port: 5432 + database_name: postgres + database_user: postgres + database_password: postgres + locale: fr + secret: ThisTokenIsNotSoSecretChangeIt + debug_toolbar: true + debug_redirects: false + use_assetic_controller: true \ No newline at end of file diff --git a/Resources/test/Fixtures/App/config/parameters.yml b/Resources/test/Fixtures/App/config/parameters.yml new file mode 100644 index 000000000..d92cc2318 --- /dev/null +++ b/Resources/test/Fixtures/App/config/parameters.yml @@ -0,0 +1,11 @@ +parameters: + database_host: 127.0.0.1 + database_port: 5435 + database_name: postgres + database_user: postgres + database_password: postgres + locale: fr + secret: ThisTokenIsNotSoSecretChangeIt + debug_toolbar: true + debug_redirects: false + use_assetic_controller: true \ No newline at end of file diff --git a/Resources/test/Fixtures/App/config/parameters.yml.dist b/Resources/test/Fixtures/App/config/parameters.yml.dist new file mode 100644 index 000000000..38fab7fd2 --- /dev/null +++ b/Resources/test/Fixtures/App/config/parameters.yml.dist @@ -0,0 +1,11 @@ +parameters: + database_host: 127.0.0.1 + database_port: 5435 + database_name: chill + database_user: chill + database_password: chill + locale: fr + secret: ThisTokenIsNotSoSecretChangeIt + debug_toolbar: true + debug_redirects: false + use_assetic_controller: true \ No newline at end of file diff --git a/Resources/test/Fixtures/App/config/routing.yml b/Resources/test/Fixtures/App/config/routing.yml new file mode 100644 index 000000000..802d3a1c8 --- /dev/null +++ b/Resources/test/Fixtures/App/config/routing.yml @@ -0,0 +1,4 @@ +#load routes for chil bundles +chill_routes: + resource: . + type: chill_routes \ No newline at end of file diff --git a/Resources/test/Fixtures/App/console b/Resources/test/Fixtures/App/console new file mode 100644 index 000000000..4ee9cfb33 --- /dev/null +++ b/Resources/test/Fixtures/App/console @@ -0,0 +1,27 @@ +#!/usr/bin/env php +getParameterOption(array('--env', '-e'), getenv('SYMFONY_ENV') ?: 'test'); +$debug = getenv('SYMFONY_DEBUG') !== '0' && !$input->hasParameterOption(array('--no-debug', '')) && $env !== 'prod'; + +if ($debug) { + Debug::enable(); +} + +$kernel = new AppKernel($env, $debug); +$application = new Application($kernel); +$application->run($input); diff --git a/Resources/test/bootstrap.php b/Resources/test/bootstrap.php new file mode 100644 index 000000000..0279b4ee6 --- /dev/null +++ b/Resources/test/bootstrap.php @@ -0,0 +1,8 @@ +{{ 'Participation creation'|trans }} + + + + + + + + + + + + +
                                        {{ 'Associated person'|trans }}{{ person_macro.render(participation.person) }}
                                        {{ 'Associated event'|trans }} {{ participation.event.name }}
                                        + + {{ form_start(form) }} + {{ form_row(form.role) }} + {{ form_row(form.status) }} + + + + {{ form_end(form) }} +{% endblock %} diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 000000000..cb1f867cf --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,23 @@ + + + + + + ./Tests + + + + + ./ + + ./Resources + ./Tests + ./vendor + + + + + + + + From 9459d7a287e961d47159f5e17cfcb4b09b8e2400 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Sat, 9 Apr 2016 23:45:07 +0200 Subject: [PATCH 45/73] Allow to add multiple participation The participationController accept a new parameter : `persons_ids`, which must receive a comma-separated list of person ids. A participation will be create for all those peoples. The `new` and `create` actions does not allow to receive both `person_id` and `persons_ids`. Tests are added. ref #6 --- Controller/ParticipationController.php | 224 +++++++++++-- Entity/Participation.php | 55 +++- .../Participation/new-multiple.html.twig | 47 ++- Resources/views/Participation/new.html.twig | 3 + Tests/Controller/EventControllerTest.php | 5 + Tests/Controller/EventTypeControllerTest.php | 4 + .../ParticipationControllerTest.php | 311 ++++++++++++++++++ Tests/Controller/RoleControllerTest.php | 4 + Tests/Controller/StatusControllerTest.php | 4 + 9 files changed, 626 insertions(+), 31 deletions(-) create mode 100644 Tests/Controller/ParticipationControllerTest.php diff --git a/Controller/ParticipationController.php b/Controller/ParticipationController.php index a04f05ed0..007a7825d 100644 --- a/Controller/ParticipationController.php +++ b/Controller/ParticipationController.php @@ -26,6 +26,7 @@ use Chill\EventBundle\Entity\Participation; use Chill\EventBundle\Form\ParticipationType; use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Chill\EventBundle\Security\Authorization\ParticipationVoter; +use Symfony\Component\Form\Extension\Core\Type\CollectionType; /** * @@ -44,23 +45,65 @@ class ParticipationController extends Controller */ public function newAction(Request $request) { - $single = $request->query->getInt('person_id', null); - $multiple = $request->query->get('persons_ids', null); - - if ($single !== NULL AND $multiple !== NULL) { - // we are not allowed to have both person_id and persons_ids + // test the request is correct + try { + $this->testRequest($request); + } catch (\RuntimeException $ex) { + $this->get('logger')->warning($ex->getMessage()); + return (new Response()) ->setStatusCode(Response::HTTP_BAD_REQUEST) - ->setContent("You are not allow to provide both 'person_id' and " + ->setContent($ex->getMessage()); + } + + // forward to other action + $single = $request->query->has('person_id'); + $multiple = $request->query->has('persons_ids'); + + if ($single === true) { + return $this->newSingle($request); + } + + if ($multiple === true) { + + return $this->newMultiple($request); + } + + // at this point, we miss the required fields. Throw an error + return (new Response()) + ->setStatusCode(Response::HTTP_BAD_REQUEST) + ->setContent("You must provide either 'person_id' or " + . "'persons_ids' argument in query"); + } + + protected function testRequest($request) + { + $single = $request->query->has('person_id'); + $multiple = $request->query->has('persons_ids'); + + if ($single === true AND $multiple === true) { + // we are not allowed to have both person_id and persons_ids + throw new \RuntimeException("You are not allow to provide both 'person_id' and " . "'persons_ids' simulaneously"); } - if ($single !== NULL) { - return $this->newSingleAction($request); + if ($multiple === true) { + $persons_ids = $request->query->get('persons_ids'); + + if (!preg_match('/^([0-9]{1,},){1,}[0-9]{1,}$/', $persons_ids)) { + throw new \RuntimeException("The persons_ids value should " + . "contains int separated by ','"); + } } + + // check for event_id - this could be removed later + if ($request->query->has('event_id') === FALSE) { + throw new \RuntimeException("You must provide an event_id"); + } + } - protected function newSingleAction(Request $request) + protected function newSingle(Request $request) { $participation = $this->handleRequest($request, new Participation()); @@ -75,7 +118,57 @@ class ParticipationController extends Controller )); } + protected function newMultiple(Request $request) + { + $participations = $this->handleRequest($request, new Participation()); + + foreach ($participations as $participation) { + $this->denyAccessUnlessGranted(ParticipationVoter::CREATE, + $participation, 'The user is not allowed to create this participation'); + } + + $form = $this->createCreateFormMultiple($participations); + + return $this->render('ChillEventBundle:Participation:new-multiple.html.twig', array( + 'form' => $form->createView(), + 'participations' => $participations + )); + } + public function createAction(Request $request) + { + // test the request is correct + try { + $this->testRequest($request); + } catch (\RuntimeException $ex) { + $this->get('logger')->warning($ex->getMessage()); + + return (new Response()) + ->setStatusCode(Response::HTTP_BAD_REQUEST) + ->setContent($ex->getMessage()); + } + + // forward to other action + $single = $request->query->has('person_id'); + $multiple = $request->query->has('persons_ids'); + + if ($single === true) { + return $this->createSingle($request); + } + + if ($multiple === true) { + + return $this->createMultiple($request); + } + + // at this point, we miss the required fields. Throw an error + return (new Response()) + ->setStatusCode(Response::HTTP_BAD_REQUEST) + ->setContent("You must provide either 'person_id' or " + . "'persons_ids' argument in query"); + } + + public function createSingle(Request $request) { $participation = $this->handleRequest($request, new Participation()); @@ -106,7 +199,49 @@ class ParticipationController extends Controller )); } + public function createMultiple(Request $request) + { + $participations = $this->handleRequest($request, new Participation()); + + foreach($participations as $participation) { + $this->denyAccessUnlessGranted(ParticipationVoter::CREATE, + $participation, 'The user is not allowed to create this participation'); + } + + $form = $this->createCreateFormMultiple($participations); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $em = $this->getDoctrine()->getManager(); + $data = $form->getData(); + + foreach($data['participations'] as $participation) { + $em->persist($participation); + } + + $em->flush(); + + $this->addFlash('success', $this->get('translator')->trans( + 'The participations were created' + )); + + return $this->redirectToRoute('chill_event__event_show', array( + 'event_id' => $participations[0]->getEvent()->getId() + )); + } + + return $this->render('ChillEventBundle:Participation:new.html.twig', array( + 'form' => $form->createView(), + 'participation' => $participation + )); + } + /** + * + * Handle the request to adapt $participation. + * + * If the request is multiple, the $participation object is cloned. + * Limitations: the $participation should not be persisted. * * @param Request $request * @param Participation $participation @@ -117,6 +252,10 @@ class ParticipationController extends Controller protected function handleRequest(Request $request, Participation $participation) { $em = $this->getDoctrine()->getManager(); + if ($em->contains($participation)) { + throw new \LogicException("The participation object should not be managed by " + . "the object manager using the method ".__METHOD__); + } $event_id = $request->query->getInt('event_id', null); @@ -134,23 +273,37 @@ class ParticipationController extends Controller $participation->setEvent($event); } - $person_id = $request->query->getInt('person_id', null); + // this script should be able to handle multiple, so we translate + // single person_id in an array + $persons_ids = $request->query->has('person_id') ? + array($request->query->getInt('person_id', null)): + explode(',', $request->query->get('persons_ids')) + ; + $participations = array(); - if ($person_id !== NULL) { - $person = $em->getRepository('ChillPersonBundle:Person') - ->find($person_id); + foreach($persons_ids as $person_id) { - if ($person === NULL) { - throw $this->createNotFoundException('The person with id '.$person_id.' is not found'); + // clone if we have to reuse the $participation + $participation = count($persons_ids) > 1 ? clone $participation : $participation; + + if ($person_id !== NULL) { + $person = $em->getRepository('ChillPersonBundle:Person') + ->find($person_id); + + if ($person === NULL) { + throw $this->createNotFoundException('The person with id '.$person_id.' is not found'); + } + + $this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person, + 'The user is not allowed to see the person'); + + $participation->setPerson($person); } - $this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person, - 'The user is not allowed to see the person'); - - $participation->setPerson($person); + $participations[] = $participation; } - return $participation; + return count($participations) > 1 ? $participations : $participations[0]; } /** @@ -175,6 +328,37 @@ class ParticipationController extends Controller return $form; } + /** + * + * @param array $participations + * @return type + */ + public function createCreateFormMultiple(array $participations) + { + $form = $this->createForm(\Symfony\Component\Form\Extension\Core\Type\FormType::class, + array('participations' => $participations), array( + 'action' => $this->generateUrl('chill_event_participation_create', array( + 'event_id' => $participations[0]->getEvent()->getId(), + 'persons_ids' => implode(',', array_map( + function(Participation $p) { return $p->getPerson()->getId(); }, + $participations)) + ) + ))); + $form->add('participations', CollectionType::class, array( + 'entry_type' => ParticipationType::class, + 'entry_options' => array( + 'event_type' => $participations[0]->getEvent()->getType() + ), + ) + ); + + $form->add('submit', SubmitType::class, array( + 'label' => 'Create' + )); + + return $form; + } + /** * show an edit form for the participation with the given id. * diff --git a/Entity/Participation.php b/Entity/Participation.php index ef33c6b99..07967edca 100644 --- a/Entity/Participation.php +++ b/Entity/Participation.php @@ -9,7 +9,7 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface; /** * Participation */ -class Participation implements HasCenterInterface, HasScopeInterface +class Participation implements HasCenterInterface, HasScopeInterface, \ArrayAccess { /** * @var integer @@ -218,6 +218,11 @@ class Participation implements HasCenterInterface, HasScopeInterface */ public function isConsistent(ExecutionContextInterface $context) { + + if ($this->getEvent() === NULL || $this->getRole() === NULL || $this->getStatus() === NULL) { + return; + } + if ($this->getRole()->getType()->getId() !== $this->getEvent()->getType()->getId()) { $context->buildViolation('The role is not allowed with this event type') @@ -233,4 +238,52 @@ class Participation implements HasCenterInterface, HasScopeInterface } } + public function offsetExists($offset) + { + return in_array($offset, array( + 'person', 'role', 'status', 'event' + )); + } + + public function offsetGet($offset) + { + switch ($offset) { + case 'person': + return $this->getPerson(); + break; + case 'role': + return $this->getRole(); + break; + case 'status': + return $this->getStatus(); + break; + case 'event': + return $this->getEvent(); + break; + } + } + + public function offsetSet($offset, $value) + { + switch($offset) { + case 'person': + return $this->setPerson($value); + break; + case 'role': + return $this->setRole($value); + break; + case 'status': + return $this->setStatus($value); + break; + case 'event': + return $this->setEvent($value); + break; + } + } + + public function offsetUnset($offset) + { + $this->offsetSet($offset, null); + } + } diff --git a/Resources/views/Participation/new-multiple.html.twig b/Resources/views/Participation/new-multiple.html.twig index 9b7a55a7f..634ffa78f 100644 --- a/Resources/views/Participation/new-multiple.html.twig +++ b/Resources/views/Participation/new-multiple.html.twig @@ -3,30 +3,57 @@ {% import 'ChillPersonBundle:Person:macro.html.twig' as person_macro %} {% block title 'Participation creation'|trans %} + + {% form_theme form _self %} + + {% block _collection_row %} + + + {{ form_widget(form) }} + + + {# {{ form_row(participationField.status) }} #} + + + {% endblock %} {% block event_content -%}

                                        {{ 'Participation creation'|trans }}

                                        - - - - - +
                                        {{ 'Associated person'|trans }}{{ person_macro.render(participation.person) }}
                                        {{ 'Associated event'|trans }} {{ participation.event.name }}{{ participations[0].event.name }}
                                        - - {{ form_start(form) }} - {{ form_row(form.role) }} - {{ form_row(form.status) }} + + + {{ form_start(form) }} + + + + + + + + + + {% for participationField in form.participations %} + + + + + + {% endfor %} + +
                                        {{ 'Person'|trans }}{{ 'Role'|trans }}{{ 'Status'|trans }}
                                        {{ person_macro.render(participationField.vars.value.person) }}{{ form_widget(participationField.role) }}{{ form_widget(participationField.status) }}
                                        +
                                        • - + {{ 'Back to the event'|trans }} diff --git a/Resources/views/Participation/new.html.twig b/Resources/views/Participation/new.html.twig index 9b7a55a7f..f74aef392 100644 --- a/Resources/views/Participation/new.html.twig +++ b/Resources/views/Participation/new.html.twig @@ -21,6 +21,9 @@ {{ form_start(form) }} + + {{ form_errors(form) }} + {{ form_row(form.role) }} {{ form_row(form.status) }} diff --git a/Tests/Controller/EventControllerTest.php b/Tests/Controller/EventControllerTest.php index 6435a2712..d955d4a56 100644 --- a/Tests/Controller/EventControllerTest.php +++ b/Tests/Controller/EventControllerTest.php @@ -6,6 +6,11 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; class EventControllerTest extends WebTestCase { + + public function testSkipped() + { + $this->markTestSkipped(); + } /* public function testCompleteScenario() { diff --git a/Tests/Controller/EventTypeControllerTest.php b/Tests/Controller/EventTypeControllerTest.php index 2075dfdbe..57af95de5 100644 --- a/Tests/Controller/EventTypeControllerTest.php +++ b/Tests/Controller/EventTypeControllerTest.php @@ -6,6 +6,10 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; class EventTypeControllerTest extends WebTestCase { + public function testSkipped() + { + $this->markTestSkipped(); + } /* public function testCompleteScenario() { diff --git a/Tests/Controller/ParticipationControllerTest.php b/Tests/Controller/ParticipationControllerTest.php new file mode 100644 index 000000000..b9a6d8dde --- /dev/null +++ b/Tests/Controller/ParticipationControllerTest.php @@ -0,0 +1,311 @@ + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace Chill\EventBundle\Tests\Controller; + +use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; + +/** + * Test the creation of participation controller + * + * + * @author Julien Fastré + */ +class ParticipationControllerTest extends WebTestCase +{ + /** + * + * @var \Symfony\Component\BrowserKit\Client + */ + protected $client; + + /** + * + * @var \Doctrine\ORM\EntityManagerInterface + */ + protected $em; + + /** + * Keep a cache for each person id given by the function getRandomPerson. + * + * This is reset by setUp() + * + * @var int[] + */ + private $personsIdsCache = array(); + + public function setUp() + { + self::bootKernel(); + + $this->client = static::createClient(array(), array( + 'PHP_AUTH_USER' => 'center a_social', + 'PHP_AUTH_PW' => 'password', + 'HTTP_ACCEPT_LANGUAGE' => 'fr_FR' + )); + + $container = self::$kernel->getContainer(); + + $this->em = $container->get('doctrine.orm.entity_manager') + ; + + $this->personsIdsCache = array(); + } + + /** + * + * + * @return \Chill\EventBundle\Entity\Event + */ + protected function getRandomEvent($centerName = 'Center A', $circleName = 'social') + { + $center = $this->em->getRepository('ChillMainBundle:Center') + ->findByName($centerName); + + $circles = $this->em->getRepository('ChillMainBundle:Scope') + ->findAll(); + array_filter($circles, function($circle) use ($circleName) { + return in_array($circleName, $circle->getName()); + }); + $circle = $circles[0]; + + $events = $this->em->getRepository('ChillEventBundle:Event') + ->findBy(array('center' => $center, 'circle' => $circle)); + + return $events[array_rand($events)]; + } + + /** + * This function does not give the same person twice + * for each test + * + * @param string $centerName + * @return \Chill\PersonBundle\Entity\Person + */ + protected function getRandomPerson($centerName = 'Center A') + { + $center = $this->em->getRepository('ChillMainBundle:Center') + ->findByName($centerName); + + $persons = $this->em->getRepository('ChillPersonBundle:Person') + ->findBy(array('center' => $center)); + + $person = $persons[array_rand($persons)]; + + if (in_array($person->getId(), $this->personsIdsCache)) { + return $this->getRandomPerson($centerName); // we try another time + } else { + $this->personsIdsCache[] = $person->getId(); + return $person; + } + + } + + public function testNewActionWrongParameters() + { + $event = $this->getRandomEvent(); + $person = $this->getRandomPerson(); + + // missing person_id or persons_ids + $this->client->request('GET', '/fr/event/participation/new', + array( + 'event_id' => $event->getId() + )); + $this->assertEquals(400, $this->client->getResponse()->getStatusCode(), + "Test that /fr/event/participation/new fail if " + . "both person_id and persons_ids are missing"); + + // having both person_id and persons_ids + $this->client->request('GET', '/fr/event/participation/new', + array( + 'event_id' => $event->getId(), + 'persons_ids' => implode(',', array( + $this->getRandomPerson()->getId(), + $this->getRandomPerson()->getId() + )), + 'person_id' => $person->getId() + )); + $this->assertEquals(400, $this->client->getResponse()->getStatusCode(), + "test that /fr/event/participation/new fail if both person_id and " + . "persons_ids are set"); + + // missing event_id + $this->client->request('GET', '/fr/event/participation/new', + array( + 'person_id' => $person->getId() + )); + $this->assertEquals(400, $this->client->getResponse()->getStatusCode(), + "Test that /fr/event/participation/new fails if event_id is missing"); + + // persons_ids with wrong content + $this->client->request('GET', '/fr/event/participation/new', + array( + 'persons_ids' => 'a,b,531', + 'event_id' => $event->getId() + )); + $this->assertEquals(400, $this->client->getResponse()->getStatusCode(), + "Test that /fr/event/participation/new fails if persons_ids has wrong content"); + } + + /** + * This method test participation creation with wrong parameters. + * + * Those request should fail before any processing. + */ + public function testCreateActionWrongParameters() + { + $event = $this->getRandomEvent(); + $person = $this->getRandomPerson(); + + // missing person_id or persons_ids + $this->client->request('GET', '/fr/event/participation/create', + array( + 'event_id' => $event->getId() + )); + $this->assertEquals(400, $this->client->getResponse()->getStatusCode(), + "Test that /fr/event/participation/create fail if " + . "both person_id and persons_ids are missing"); + + // having both person_id and persons_ids + $this->client->request('GET', '/fr/event/participation/create', + array( + 'event_id' => $event->getId(), + 'persons_ids' => implode(',', array( + $this->getRandomPerson()->getId(), + $this->getRandomPerson()->getId() + )), + 'person_id' => $person->getId() + )); + $this->assertEquals(400, $this->client->getResponse()->getStatusCode(), + "test that /fr/event/participation/create fail if both person_id and " + . "persons_ids are set"); + + // missing event_id + $this->client->request('GET', '/fr/event/participation/create', + array( + 'person_id' => $person->getId() + )); + $this->assertEquals(400, $this->client->getResponse()->getStatusCode(), + "Test that /fr/event/participation/create fails if event_id is missing"); + + // persons_ids with wrong content + $this->client->request('GET', '/fr/event/participation/create', + array( + 'persons_ids' => 'a,b,531', + 'event_id' => $event->getId() + )); + $this->assertEquals(400, $this->client->getResponse()->getStatusCode(), + "Test that /fr/event/participation/create fails if persons_ids has wrong content"); + } + + public function testNewSingleAction() + { + $event = $this->getRandomEvent(); + // record the number of participation for the event + $nbParticipations = $event->getParticipations()->count(); + $person = $this->getRandomPerson(); + + $crawler = $this->client->request('GET', '/fr/event/participation/new', + array( + 'person_id' => $person->getId(), + 'event_id' => $event->getId() + )); + + $this->assertEquals(200, $this->client->getResponse()->getStatusCode(), + "test that /fr/event/participation/new is successful"); + + $button = $crawler->selectButton('Créer'); + + $this->assertNotNull($button, "test the form with button 'Créer' exists"); + + $this->client->submit($button->form(), array( + 'participation[role]' => $event->getType()->getRoles()->first()->getId(), + 'participation[status]' => $event->getType()->getStatuses()->first()->getId() + )); + + $this->assertTrue($this->client->getResponse()->isRedirect()); + $crawler = $this->client->followRedirect(); + + $span = $crawler->filter('table td span.entity-person a:contains("' + .$person->getFirstName().'"):contains("'.$person->getLastname().'")'); + + $this->assertGreaterThan(0, count($span)); + + // as the container has reloaded, reload the event + $event = $this->em->getRepository('ChillEventBundle:Event')->find($event->getId()); + $this->em->refresh($event); + + $this->assertEquals($nbParticipations + 1, $event->getParticipations()->count()); + } + + public function testNewMultipleAction() + { + $event = $this->getRandomEvent(); + // record the number of participation for the event + $nbParticipations = $event->getParticipations()->count(); + $person1 = $this->getRandomPerson(); + $person2 = $this->getRandomPerson(); + + $crawler = $this->client->request('GET', '/fr/event/participation/new', + array( + 'persons_ids' => implode(',', array($person1->getId(), $person2->getId())), + 'event_id' => $event->getId() + )); + + $this->assertEquals(200, $this->client->getResponse()->getStatusCode(), + "test that /fr/event/participation/new is successful"); + + $button = $crawler->selectButton('Créer'); + + $this->assertNotNull($button, "test the form with button 'Créer' exists"); + + $this->client->submit($button->form(), array( + 'form' => array( + 'participations' => array( + 0 => array( + 'role' => $event->getType()->getRoles()->first()->getId(), + 'status' => $event->getType()->getStatuses()->first()->getId() + ), + 1 => array( + 'role' => $event->getType()->getRoles()->first()->getId(), + 'status' => $event->getType()->getStatuses()->first()->getId() + ), + ) + ) + )); + + $this->assertTrue($this->client->getResponse()->isRedirect()); + $crawler = $this->client->followRedirect(); + + $span1 = $crawler->filter('table td span.entity-person a:contains("' + .$person1->getFirstName().'"):contains("'.$person1->getLastname().'")'); + $this->assertGreaterThan(0, count($span1)); + $span2 = $crawler->filter('table td span.entity-person a:contains("' + .$person2->getFirstName().'"):contains("'.$person2->getLastname().'")'); + $this->assertGreaterThan(0, count($span2)); + + // as the container has reloaded, reload the event + $event = $this->em->getRepository('ChillEventBundle:Event')->find($event->getId()); + $this->em->refresh($event); + + $this->assertEquals($nbParticipations + 2, $event->getParticipations()->count()); + } + + +} diff --git a/Tests/Controller/RoleControllerTest.php b/Tests/Controller/RoleControllerTest.php index 39d21ff7b..f2286f208 100644 --- a/Tests/Controller/RoleControllerTest.php +++ b/Tests/Controller/RoleControllerTest.php @@ -6,6 +6,10 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; class RoleControllerTest extends WebTestCase { + public function testSkipped() + { + $this->markTestSkipped(); + } /* public function testCompleteScenario() { diff --git a/Tests/Controller/StatusControllerTest.php b/Tests/Controller/StatusControllerTest.php index fc2c94259..99e297575 100644 --- a/Tests/Controller/StatusControllerTest.php +++ b/Tests/Controller/StatusControllerTest.php @@ -6,6 +6,10 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; class StatusControllerTest extends WebTestCase { + public function testSkipped() + { + $this->markTestSkipped(); + } /* public function testCompleteScenario() { From fe8994d775943e8a97f8a6ff416da92dd55e1b42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Sun, 10 Apr 2016 01:38:42 +0200 Subject: [PATCH 46/73] Add event on page footer --- Resources/views/Event/show.html.twig | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Resources/views/Event/show.html.twig b/Resources/views/Event/show.html.twig index 74fa07559..a94d7e1ba 100644 --- a/Resources/views/Event/show.html.twig +++ b/Resources/views/Event/show.html.twig @@ -82,15 +82,18 @@ {% if count > 0 %}
                                        • {{ 'Edit all the participations'|trans }}
                                        • {% endif %} -
                                        • - {{ form_start(form_add_participation_by_person) }} - {{ form_widget(form_add_participation_by_person.person_id, { 'attr' : { 'style' : 'width: 20em; display:inline-block; ' } } ) }} - {{ form_widget(form_add_participation_by_person.submit, { 'attr' : { 'class' : 'sc-button bt-create' } } ) }} - {{ form_rest(form_add_participation_by_person) }} - {{ form_end(form_add_participation_by_person) }} -
                                          -
                                        + +
                                        + {{ form_start(form_add_participation_by_person) }} + {{ form_widget(form_add_participation_by_person.person_id, { 'attr' : { 'style' : 'width: 25em; display:inline-block; ' } } ) }} + {{ form_widget(form_add_participation_by_person.submit, { 'attr' : { 'class' : 'sc-button bt-create' } } ) }} + {{ form_rest(form_add_participation_by_person) }} + {{ form_end(form_add_participation_by_person) }} +
                                        +
                                        + {{ chill_delegated_block('block_footer_show', { 'event': event }) }} +
                                        {% endblock %} From c1b9069138a53a7cb0949cb6c00b0178bb7b85ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 11 Apr 2016 23:59:14 +0200 Subject: [PATCH 47/73] fix the possibility to add multiple participation ref #6 --- Controller/ParticipationController.php | 99 ++++++++++++-- Resources/translations/messages.fr.yml | 2 + .../_ignored_participations.html.twig | 10 ++ .../Participation/new-multiple.html.twig | 5 +- Resources/views/Participation/new.html.twig | 5 + .../ParticipationControllerTest.php | 122 +++++++++++++++++- 6 files changed, 225 insertions(+), 18 deletions(-) create mode 100644 Resources/views/Participation/_ignored_participations.html.twig diff --git a/Controller/ParticipationController.php b/Controller/ParticipationController.php index 007a7825d..e2eaa3fa2 100644 --- a/Controller/ParticipationController.php +++ b/Controller/ParticipationController.php @@ -39,7 +39,8 @@ class ParticipationController extends Controller * Show a form to add a participation * * This function parse the person_id / persons_ids query argument - * and decide if it should process a single or multiple participation + * and decide if it should process a single or multiple participation. Depending + * on this, the appropriate layout and form. * * @param Request $request */ @@ -76,7 +77,18 @@ class ParticipationController extends Controller . "'persons_ids' argument in query"); } - protected function testRequest($request) + /** + * + * Test that the query parameters are valid : + * + * - an `event_id` is existing ; + * - `person_id` and `persons_ids` are **not** both present ; + * - `persons_id` is correct (contains only numbers and a ','. + * + * @param Request $request + * @throws \RuntimeException if an error is detected + */ + protected function testRequest(Request $request) { $single = $request->query->has('person_id'); $multiple = $request->query->has('persons_ids'); @@ -103,6 +115,12 @@ class ParticipationController extends Controller } + /** + * Show a form with single participation. + * + * @param Request $request + * @return Response + */ protected function newSingle(Request $request) { $participation = $this->handleRequest($request, new Participation()); @@ -114,25 +132,84 @@ class ParticipationController extends Controller return $this->render('ChillEventBundle:Participation:new.html.twig', array( 'form' => $form->createView(), - 'participation' => $participation + 'participation' => $participation, + 'ignored_participations' => array() // this is required, see self::newMultiple )); } + /** + * Show a form with multiple participation. + * + * If a person is already participating on the event (if a participation with + * the same person is associated with the event), the participation is ignored. + * + * If all but one participation is ignored, the page show the same response + * than the newSingle function. + * + * If all participations must be ignored, an error is shown and the method redirects + * to the event 'show' view with an appropriate flash message. + * + * @param Request $request + * @return Response + */ protected function newMultiple(Request $request) { $participations = $this->handleRequest($request, new Participation()); - foreach ($participations as $participation) { + foreach ($participations as $i => $participation) { + // check for authorization $this->denyAccessUnlessGranted(ParticipationVoter::CREATE, $participation, 'The user is not allowed to create this participation'); + + // check that the user is not already in the event (computing only once) + /* @var $peopleParticipating \Doctrine\Common\Collections\ArrayCollection */ + $peopleParticipating = isset($peopleParticipating) ? $peopleParticipating : + $participation->getEvent()->getParticipations()->map( + function(Participation $p) { return $p->getPerson()->getId(); } + ); + + if ($peopleParticipating->contains($participation->getPerson()->getId())) { + $ignoredParticipations[] = $participation + ->getEvent()->getParticipations()->filter( + function (Participation $p) use ($participation) { + return $p->getPerson()->getId() === $participation->getPerson()->getId(); + } + )->first(); + } else { + $newParticipations[] = $participation; + } } - $form = $this->createCreateFormMultiple($participations); + // this is where the function redirect depending on valid participation - return $this->render('ChillEventBundle:Participation:new-multiple.html.twig', array( - 'form' => $form->createView(), - 'participations' => $participations - )); + if (!isset($newParticipations)) { + // if we do not have nay participants, redirect to event view + $this->addFlash('error', 'Any of the requested people may be added ' + . 'on the event: they are maybe already participating.'); + + return $this->redirectToRoute('chill_event_participation_new', array( + 'event_id' => $request->query->getInt('event_id', 0) + )); + } elseif (count($newParticipations) > 1) { + // if we have multiple participations, show a form with multiple participations + $form = $this->createCreateFormMultiple($newParticipations); + + return $this->render('ChillEventBundle:Participation:new-multiple.html.twig', array( + 'form' => $form->createView(), + 'participations' => $newParticipations, + 'ignored_participations' => isset($ignoredParticipations) ? $ignoredParticipations : array() + )); + } else { + // if we have only one participation, show the same form than for single participation + $form = $this->createCreateForm($participation); + + return $this->render('ChillEventBundle:Participation:new.html.twig', array( + 'form' => $form->createView(), + 'participation' => $participation, + 'ignored_participations' => isset($ignoredParticipations) ? $ignoredParticipations : array() + )); + + } } public function createAction(Request $request) @@ -338,7 +415,7 @@ class ParticipationController extends Controller $form = $this->createForm(\Symfony\Component\Form\Extension\Core\Type\FormType::class, array('participations' => $participations), array( 'action' => $this->generateUrl('chill_event_participation_create', array( - 'event_id' => $participations[0]->getEvent()->getId(), + 'event_id' => current($participations)->getEvent()->getId(), 'persons_ids' => implode(',', array_map( function(Participation $p) { return $p->getPerson()->getId(); }, $participations)) @@ -347,7 +424,7 @@ class ParticipationController extends Controller $form->add('participations', CollectionType::class, array( 'entry_type' => ParticipationType::class, 'entry_options' => array( - 'event_type' => $participations[0]->getEvent()->getType() + 'event_type' => current($participations)->getEvent()->getType() ), ) ); diff --git a/Resources/translations/messages.fr.yml b/Resources/translations/messages.fr.yml index 67e992d7e..3d1d9c4ca 100644 --- a/Resources/translations/messages.fr.yml +++ b/Resources/translations/messages.fr.yml @@ -32,6 +32,8 @@ Back to the event: Retour à l'événement The participation was created: La participation a été créée The participation was updated: La participation a été mise à jour Participation Edit: Modifier une participation +'Any of the requested people may be added on the event: they are maybe already participating.': 'Aucune des personnes suggérées ne peut être ajoutée à l''événement: elles sont peut-être déjà inscrites comme participantes.' +'The following people have been ignored because they are already participating on the event': '{1} La personne suivante a été ignorée parce qu''elle participe déjà à l''événement | ]1,Inf] Les personnes suivantes ont été ignorées parce qu''elles participent déjà à l''événement' #search Event search: Recherche d'événements diff --git a/Resources/views/Participation/_ignored_participations.html.twig b/Resources/views/Participation/_ignored_participations.html.twig new file mode 100644 index 000000000..0d54dd624 --- /dev/null +++ b/Resources/views/Participation/_ignored_participations.html.twig @@ -0,0 +1,10 @@ +{% import 'ChillPersonBundle:Person:macro.html.twig' as person_macro %} + +{% if ignored_participations|length > 0 %} +

                                        {% transchoice ignored_participations|length %}The following people have been ignored because they are already participating on the event{% endtranschoice %} :

                                        +
                                          + {% for p in ignored_participations %} +
                                        • {{ person_macro.render(p.person) }}
                                        • + {% endfor %} +
                                        +{% endif %} \ No newline at end of file diff --git a/Resources/views/Participation/new-multiple.html.twig b/Resources/views/Participation/new-multiple.html.twig index 634ffa78f..8cdfed800 100644 --- a/Resources/views/Participation/new-multiple.html.twig +++ b/Resources/views/Participation/new-multiple.html.twig @@ -28,8 +28,8 @@ - - + + {% include 'ChillEventBundle:Participation:_ignored_participations.html.twig' with ignored_participations %} {{ form_start(form) }} @@ -64,4 +64,5 @@ {{ form_end(form) }} + {% endblock %} diff --git a/Resources/views/Participation/new.html.twig b/Resources/views/Participation/new.html.twig index f74aef392..7ec10fa5f 100644 --- a/Resources/views/Participation/new.html.twig +++ b/Resources/views/Participation/new.html.twig @@ -19,6 +19,8 @@
                                        + + {% include 'ChillEventBundle:Participation:_ignored_participations.html.twig' with ignored_participations %} {{ form_start(form) }} @@ -26,6 +28,8 @@ {{ form_row(form.role) }} {{ form_row(form.status) }} + +
                                        • @@ -40,4 +44,5 @@
                                        {{ form_end(form) }} + {% endblock %} diff --git a/Tests/Controller/ParticipationControllerTest.php b/Tests/Controller/ParticipationControllerTest.php index b9a6d8dde..d912b206f 100644 --- a/Tests/Controller/ParticipationControllerTest.php +++ b/Tests/Controller/ParticipationControllerTest.php @@ -44,7 +44,9 @@ class ParticipationControllerTest extends WebTestCase /** * Keep a cache for each person id given by the function getRandomPerson. * - * This is reset by setUp() + * You may ask to ignore some people by adding their id to the array. + * + * This is reset by setUp(). * * @var int[] */ @@ -92,8 +94,31 @@ class ParticipationControllerTest extends WebTestCase } /** + * Return a random event only if he has more than one participation. + * + * @param string $centerName + * @param type $circleName + * @return \Chill\EventBundle\Entity\Event + */ + protected function getRandomEventWithMultipleParticipations( + $centerName = 'Center A', + $circleName = 'social') + { + $event = $this->getRandomEvent($centerName, $circleName); + + return $event->getParticipations()->count() > 1 ? + $event : + $this->getRandomEventWithMultipleParticipations($centerName, $circleName); + } + + /** + * Returns a person randomly. + * * This function does not give the same person twice - * for each test + * for each test. + * + * You may ask to ignore some people by adding their id to the property + * `$this->personsIdsCache` * * @param string $centerName * @return \Chill\PersonBundle\Entity\Person @@ -226,7 +251,7 @@ class ParticipationControllerTest extends WebTestCase 'person_id' => $person->getId(), 'event_id' => $event->getId() )); - + $this->assertEquals(200, $this->client->getResponse()->getStatusCode(), "test that /fr/event/participation/new is successful"); @@ -257,8 +282,17 @@ class ParticipationControllerTest extends WebTestCase public function testNewMultipleAction() { $event = $this->getRandomEvent(); - // record the number of participation for the event + // record the number of participation for the event (used later in this test) $nbParticipations = $event->getParticipations()->count(); + // make ignore the people already in the event from the function getRandomPerson + $this->personsIdsCache = array_merge( + $this->personsIdsCache, + $event->getParticipations()->map( + function($p) { return $p->getPerson()->getId(); } + ) + ->toArray() + ); + // get some random people $person1 = $this->getRandomPerson(); $person2 = $this->getRandomPerson(); @@ -267,7 +301,7 @@ class ParticipationControllerTest extends WebTestCase 'persons_ids' => implode(',', array($person1->getId(), $person2->getId())), 'event_id' => $event->getId() )); - + $this->assertEquals(200, $this->client->getResponse()->getStatusCode(), "test that /fr/event/participation/new is successful"); @@ -307,5 +341,83 @@ class ParticipationControllerTest extends WebTestCase $this->assertEquals($nbParticipations + 2, $event->getParticipations()->count()); } + public function testMultipleWithAllPeopleParticipating() + { + $event = $this->getRandomEventWithMultipleParticipations(); + + $persons_id = implode(',', $event->getParticipations()->map( + function($p) { return $p->getPerson()->getId(); } + )->toArray()); + + $crawler = $this->client->request('GET', '/fr/event/participation/new', + array( + 'persons_ids' => $persons_id, + 'event_id' => $event->getId() + )); + + $this->assertEquals(302, $this->client->getResponse()->getStatusCode(), + "test that /fr/event/participation/new is redirecting"); + } + + public function testMultipleWithSomePeopleParticipating() + { + $event = $this->getRandomEventWithMultipleParticipations(); + // record the number of participation for the event (used later in this test) + $nbParticipations = $event->getParticipations()->count(); + // get the persons_id participating on this event + $persons_id = $event->getParticipations()->map( + function($p) { return $p->getPerson()->getId(); } + )->toArray(); + // exclude the existing persons_ids from the new person + $this->personsIdsCache = array_merge($this->personsIdsCache, $persons_id); + + // get a random person + $newPerson = $this->getRandomPerson(); + + // build the `persons_ids` parameter + $persons_ids_string = implode(',', array_merge($persons_id, + array($newPerson->getId()))); + + $crawler = $this->client->request('GET', '/fr/event/participation/new', + array( + 'persons_ids' => $persons_ids_string, + 'event_id' => $event->getId() + )); + + $this->assertEquals(200, $this->client->getResponse()->getStatusCode(), + "test that /fr/event/participation/new is successful"); + + // count that the one UL contains the new person string + $firstPerson = $event->getParticipations()->first()->getPerson(); + $ul = $crawler->filter('ul:contains("'.$firstPerson->getLastName().'")' + . ':contains("'.$firstPerson->getFirstName().'")'); + + $this->assertEquals(1, $ul->count(), + "assert an ul containing the name of ignored people is present"); + $this->assertEquals($event->getParticipations()->count(), $ul->children()->count(), + "assert the li listing ignored people has the correct number"); + + // test a form is present on the page + $button = $crawler->selectButton('Créer'); + + $this->assertNotNull($button, "test the form with button 'Créer' exists"); + + // submit the form + $this->client->submit($button->form(), array( + 'participation[role]' => $event->getType()->getRoles()->first()->getId(), + 'participation[status]' => $event->getType()->getStatuses()->first()->getId() + )); + + $this->assertTrue($this->client->getResponse()->isRedirect()); + + // reload the event and test there is a new participation + $event = $this->em->getRepository('ChillEventBundle:Event') + ->find($event->getId()); + $this->em->refresh($event); + + $this->assertEquals($nbParticipations + 1, $event->getParticipations()->count(), + "Test we have persisted a new participation associated to the test"); + } + } From 78c53fe7b0f6e43edc4df1ef105d7980159ce9b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 12 Apr 2016 22:40:11 +0200 Subject: [PATCH 48/73] [feature] allow to edit multiple participations at once ref #7 --- Controller/ParticipationController.php | 120 ++++++++++++++++++ Resources/config/routing/participation.yml | 9 ++ Resources/translations/messages.fr.yml | 3 + Resources/views/Event/show.html.twig | 2 +- .../Participation/edit-multiple.html.twig | 60 +++++++++ .../ParticipationControllerTest.php | 29 ++++- 6 files changed, 220 insertions(+), 3 deletions(-) create mode 100644 Resources/views/Participation/edit-multiple.html.twig diff --git a/Controller/ParticipationController.php b/Controller/ParticipationController.php index e2eaa3fa2..ca2a5f953 100644 --- a/Controller/ParticipationController.php +++ b/Controller/ParticipationController.php @@ -526,4 +526,124 @@ class ParticipationController extends Controller return $form; } + /** + * show a form to edit multiple participation for the same event. + * + * @param int $event_id + */ + public function editMultipleAction($event_id) + { + $event = $this->getDoctrine()->getRepository('ChillEventBundle:Event') + ->find($event_id); + + if ($event === null) { + throw $this->createNotFoundException("The event with id $event_id is not found"); + } + + // check for ACL, on Event level and on Participation Level + $this->denyAccessUnlessGranted('CHILL_EVENT_SEE', $event, "You are not allowed " + . "to see this event"); + foreach ($event->getParticipations() as $participation) { + $this->denyAccessUnlessGranted(ParticipationVoter::UPDATE, $participation, + "You are not allowed to update participation with id ".$participation->getId()); + } + + + switch ($event->getParticipations()->count()) { + + case 0: + // if there aren't any participation, redirect to the 'show' view with an add flash + $this->addFlash('warning', $this->get('translator') + ->trans( "There are no participation to edit for this event")); + + return $this->redirectToRoute('chill_event__event_show', + array('event_id' => $event->getId())); + + case 1: + // redirect to the form for a single participation + return $this->redirectToRoute('chill_event_participation_edit', array( + 'participation_id' => $event->getParticipations()->first()->getId() + )); + } + + $form = $this->createEditFormMultiple($event->getParticipations(), $event); + + return $this->render('ChillEventBundle:Participation:edit-multiple.html.twig', array( + 'event' => $event, + 'participations' => $event->getParticipations(), + 'form' => $form->createView() + )); + } + + public function updateMultipleAction($event_id, Request $request) + { + /* @var $event \Chill\EventBundle\Entity\Event */ + $event = $this->getDoctrine()->getRepository('ChillEventBundle:Event') + ->find($event_id); + + if ($event === null) { + throw $this->createNotFoundException("The event with id $event_id is not found"); + } + + $this->denyAccessUnlessGranted('CHILL_EVENT_SEE', $event, "You are not allowed " + . "to see this event"); + foreach ($event->getParticipations() as $participation) { + $this->denyAccessUnlessGranted(ParticipationVoter::UPDATE, $participation, + "You are not allowed to update participation with id ".$participation->getId()); + } + + $form = $this->createEditFormMultiple($event->getParticipations(), $event); + + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $this->getDoctrine()->getManager()->flush(); + + $this->addFlash('success', $this->get('translator')->trans("The participations " + . "have been successfully updated.")); + + return $this->redirectToRoute('chill_event__event_show', + array('event_id' => $event->getId())); + } + + return $this->render('ChillEventBundle:Participation:edit-multiple.html.twig', array( + 'event' => $event, + 'participations' => $event->getParticipations(), + 'form' => $form->createView() + )); + } + + /** + * + * @param \Doctrine\Common\Collections\Collectionn $participations contains object of Participation type + * @param \Chill\EventBundle\Entity\Event $event + * @return \Symfony\Component\Form\FormInterface + */ + protected function createEditFormMultiple( + \Doctrine\Common\Collections\Collection $participations, + \Chill\EventBundle\Entity\Event $event + ) { + $form = $this->createForm(\Symfony\Component\Form\Extension\Core\Type\FormType::class, + array('participations' => $participations), array( + 'method' => 'POST', + 'action' => $this->generateUrl('chill_event_participation_update_multiple', array( + 'event_id' => $event->getId() + )) + )); + + $form->add('participations', CollectionType::class, array( + 'entry_type' => ParticipationType::class, + 'entry_options' => array( + 'event_type' => $event->getType() + ), + ) + ); + + $form->add('submit', SubmitType::class, array( + 'label' => 'Update' + )); + + return $form; + } + } diff --git a/Resources/config/routing/participation.yml b/Resources/config/routing/participation.yml index 54d18fb71..bbb727382 100644 --- a/Resources/config/routing/participation.yml +++ b/Resources/config/routing/participation.yml @@ -14,3 +14,12 @@ chill_event_participation_update: path: /{participation_id}/update defaults: { _controller: ChillEventBundle:Participation:update } methods: [POST] + +chill_event_participation_edit_multiple: + path: /{event_id}/edit_multiple + defaults: { _controller: ChillEventBundle:Participation:editMultiple } + +chill_event_participation_update_multiple: + path: /{event_id}/update_multiple + defaults: { _controller: ChillEventBundle:Participation:updateMultiple } + methods: [POST] diff --git a/Resources/translations/messages.fr.yml b/Resources/translations/messages.fr.yml index 3d1d9c4ca..4af7a2b83 100644 --- a/Resources/translations/messages.fr.yml +++ b/Resources/translations/messages.fr.yml @@ -8,6 +8,7 @@ Event: Événement Events: Événements 'Event : %label%': Événement "%label%" Participation: Participation +Participations: Participations Status: Statut Last update: Dernière mise à jour '%count% participations to this event': '{0} Aucun participant à l''événement | {1} Un participant à l''événement | ]1,Inf] %count% participants à l''événement' @@ -34,6 +35,8 @@ The participation was updated: La participation a été mise à jour Participation Edit: Modifier une participation 'Any of the requested people may be added on the event: they are maybe already participating.': 'Aucune des personnes suggérées ne peut être ajoutée à l''événement: elles sont peut-être déjà inscrites comme participantes.' 'The following people have been ignored because they are already participating on the event': '{1} La personne suivante a été ignorée parce qu''elle participe déjà à l''événement | ]1,Inf] Les personnes suivantes ont été ignorées parce qu''elles participent déjà à l''événement' +There are no participation to edit for this event: Il n'y a pas de participation pour cet événement +The participations have been successfully updated.: Les participations ont été mises à jour. #search Event search: Recherche d'événements diff --git a/Resources/views/Event/show.html.twig b/Resources/views/Event/show.html.twig index a94d7e1ba..e2aa9caf3 100644 --- a/Resources/views/Event/show.html.twig +++ b/Resources/views/Event/show.html.twig @@ -80,7 +80,7 @@ diff --git a/Resources/views/Participation/edit-multiple.html.twig b/Resources/views/Participation/edit-multiple.html.twig new file mode 100644 index 000000000..747b53260 --- /dev/null +++ b/Resources/views/Participation/edit-multiple.html.twig @@ -0,0 +1,60 @@ +{% extends 'ChillEventBundle::layout.html.twig' %} + +{% import 'ChillPersonBundle:Person:macro.html.twig' as person_macro %} + +{% block event_content -%} +

                                        {{ 'Participation Edit'|trans }}

                                        + + + + + + + + + + + + +
                                        {{ 'Associated event'|trans }} {{ event.name }}
                                        {{ 'Date'|trans }} {{ event.date|localizeddate('long', 'none') }}
                                        + +

                                        {{ 'Participations'|trans }}

                                        + + {{ form_start(form) }} + + + + + + + + + + + + + {% for participation in form.participations %} + + + + + + + {% endfor %} + +
                                        {{ 'Person'|trans }}{{ 'Role'|trans }}{{ 'Status'|trans }}{{ 'Last update'|trans }} 
                                        {{ person_macro.render(participation.vars.value.person) }}{{ form_widget(participation.role) }}{{ form_widget(participation.status) }}{{ participation.vars.value.lastUpdate|time_diff }}
                                        + + + + {{ form_end(form) }} +{% endblock %} diff --git a/Tests/Controller/ParticipationControllerTest.php b/Tests/Controller/ParticipationControllerTest.php index d912b206f..a51fae197 100644 --- a/Tests/Controller/ParticipationControllerTest.php +++ b/Tests/Controller/ParticipationControllerTest.php @@ -341,7 +341,7 @@ class ParticipationControllerTest extends WebTestCase $this->assertEquals($nbParticipations + 2, $event->getParticipations()->count()); } - public function testMultipleWithAllPeopleParticipating() + public function testNewMultipleWithAllPeopleParticipating() { $event = $this->getRandomEventWithMultipleParticipations(); @@ -359,7 +359,7 @@ class ParticipationControllerTest extends WebTestCase "test that /fr/event/participation/new is redirecting"); } - public function testMultipleWithSomePeopleParticipating() + public function testNewMultipleWithSomePeopleParticipating() { $event = $this->getRandomEventWithMultipleParticipations(); // record the number of participation for the event (used later in this test) @@ -419,5 +419,30 @@ class ParticipationControllerTest extends WebTestCase "Test we have persisted a new participation associated to the test"); } + public function testEditMultipleAction() + { + /* @var $event \Chill\EventBundle\Entity\Event */ + $event = $this->getRandomEventWithMultipleParticipations(); + + $crawler = $this->client->request('GET', '/fr/event/participation/'.$event->getId(). + '/edit_multiple'); + + $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + + $button = $crawler->selectButton('Mettre à jour'); + $this->assertEquals(1, $button->count(), "test the form with button 'mettre à jour' exists "); + + + $this->client->submit($button->form(), array( + 'form[participations][0][role]' => $event->getType()->getRoles()->first()->getId(), + 'form[participations][0][status]' => $event->getType()->getStatuses()->first()->getId(), + 'form[participations][1][role]' => $event->getType()->getRoles()->last()->getId(), + 'form[participations][1][status]' => $event->getType()->getStatuses()->last()->getId(), + )); + + $this->assertTrue($this->client->getResponse() + ->isRedirect('/fr/event/event/'.$event->getId().'/show')); + } + } From cf4a0d9e75542f122d26453198a489a473c7d2dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 19 Apr 2016 15:30:44 +0200 Subject: [PATCH 49/73] factorize PickRoleType, PickStatusType and rename TranslatableEventType --- Form/EventType.php | 4 +- Form/ParticipationType.php | 55 +------ ...latableEventType.php => PickEventType.php} | 5 +- Form/Type/PickRoleType.php | 144 ++++++++++++++++++ Form/Type/PickStatusType.php | 134 ++++++++++++++++ Resources/config/services/forms.yml | 22 ++- Resources/config/services/repositories.yml | 16 +- Resources/config/services/search.yml | 2 +- 8 files changed, 326 insertions(+), 56 deletions(-) rename Form/Type/{TranslatableEventType.php => PickEventType.php} (91%) create mode 100644 Form/Type/PickRoleType.php create mode 100644 Form/Type/PickStatusType.php diff --git a/Form/EventType.php b/Form/EventType.php index a3417a81e..2d4895efa 100644 --- a/Form/EventType.php +++ b/Form/EventType.php @@ -5,7 +5,7 @@ namespace Chill\EventBundle\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolverInterface; -use Chill\EventBundle\Form\Type\TranslatableEventType; +use Chill\EventBundle\Form\Type\PickEventType; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Chill\MainBundle\Security\Authorization\AuthorizationHelper; use Doctrine\Common\Persistence\ObjectManager; @@ -107,7 +107,7 @@ class EventType extends AbstractType ); }, )) - ->add('type', TranslatableEventType::class) + ->add('type', PickEventType::class) ; } diff --git a/Form/ParticipationType.php b/Form/ParticipationType.php index 5b754dcf9..d7186ac91 100644 --- a/Form/ParticipationType.php +++ b/Form/ParticipationType.php @@ -26,8 +26,9 @@ use Chill\EventBundle\Entity\EventType; use Chill\EventBundle\Entity\Status; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Doctrine\ORM\EntityRepository; -use Chill\EventBundle\Entity\Role; use Chill\MainBundle\Templating\TranslatableStringHelper; +use Chill\EventBundle\Form\Type\PickRoleType; +use Chill\EventBundle\Form\Type\PickStatusType; /** * A type to create a participation @@ -55,55 +56,13 @@ class ParticipationType extends AbstractType $translatableStringHelper = $this->translatableStringHelper; // add role - $builder->add('role', EntityType::class, array( - 'class' => Role::class, - 'query_builder' => function (EntityRepository $er) use ($options) { - $qb = $er->createQueryBuilder('r'); - - if ($options['event_type'] instanceof EventType) { - $qb->where($qb->expr()->eq('r.type', ':event_type')) - ->setParameter('event_type', $options['event_type']); - } - - $qb->andWhere($qb->expr()->eq('r.active', ':active')) - ->setParameter('active', true); - - return $qb; - }, - 'choice_attr' => function(Role $r) { - return array( - 'data-event-type' => $r->getType()->getId() - ); - }, - 'choice_label' => function(Role $r) use ($translatableStringHelper) { - return $translatableStringHelper->localize($r->getName()); - } - )); + $builder->add('role', PickRoleType::class, array( + 'event_type' => $options['event_type'] + )); // add a status - $builder->add('status', EntityType::class, array( - 'class' => Status::class, - 'choice_attr' => function(Status $s) { - return array( - 'data-event-type' => $s->getType()->getId() - ); - }, - 'query_builder' => function (EntityRepository $er) use ($options) { - $qb = $er->createQueryBuilder('s'); - - if ($options['event_type'] instanceof EventType) { - $qb->where($qb->expr()->eq('s.type', ':event_type')) - ->setParameter('event_type', $options['event_type']); - } - - $qb->andWhere($qb->expr()->eq('s.active', ':active')) - ->setParameter('active', true); - - return $qb; - }, - 'choice_label' => function(Status $s) use ($translatableStringHelper) { - return $translatableStringHelper->localize($s->getName()); - } + $builder->add('status', PickStatusType::class, array( + 'event_type' => $options['event_type'] )); } diff --git a/Form/Type/TranslatableEventType.php b/Form/Type/PickEventType.php similarity index 91% rename from Form/Type/TranslatableEventType.php rename to Form/Type/PickEventType.php index 6b7a80d03..0d41fb2e3 100644 --- a/Form/Type/TranslatableEventType.php +++ b/Form/Type/PickEventType.php @@ -34,7 +34,7 @@ use Chill\EventBundle\Entity\EventType; * * @author Champs-Libres Coop */ -class TranslatableEventType extends AbstractType +class PickEventType extends AbstractType { /** * @var TranslatableStringHelper @@ -64,6 +64,9 @@ class TranslatableEventType extends AbstractType 'choice_label' => function (EventType $t) use ($helper) { return $helper->localize($t->getName()); }, + 'choice_attrs' => function (EventType $t) { + return array('data-link-category' => $t->getId()); + } ) ); } diff --git a/Form/Type/PickRoleType.php b/Form/Type/PickRoleType.php new file mode 100644 index 000000000..4ea4b46a2 --- /dev/null +++ b/Form/Type/PickRoleType.php @@ -0,0 +1,144 @@ +, + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace Chill\EventBundle\Form\Type; + +use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; +use Chill\EventBundle\Entity\Role; +use Chill\EventBundle\Entity\EventType; +use Chill\MainBundle\Templating\TranslatableStringHelper; +use Symfony\Component\Translation\TranslatorInterface; +use Symfony\Bridge\Doctrine\Form\Type\EntityType; +use Doctrine\ORM\EntityRepository; + +/** + * Allow to pick a choice amongst different choices + * + * @author Julien Fastré + * @author Champs Libres + */ +class PickRoleType extends AbstractType +{ + + /** + * + * @var TranslatableStringHelper + */ + protected $translatableStringHelper; + + /** + * + * @var TranslatorInterface + */ + protected $translator; + + /** + * + * @var EntityRepository + */ + protected $roleRepository; + + public function __construct( + TranslatableStringHelper $translatableStringHelper, + TranslatorInterface $translator, + EntityRepository $roleRepository + ) { + $this->translatableStringHelper = $translatableStringHelper; + $this->translator = $translator; + $this->roleRepository = $roleRepository; + } + + public function buildForm(FormBuilderInterface $builder, array $options) + { + // create copy for use in Closure + $translatableStringHelper = $this->translatableStringHelper; + // create copy for easier management + $qb = $options['query_builder']; + + if ($options['event_type'] instanceof EventType) { + $options['query_builder']->where($qb->expr()->eq('r.type', ':event_type')) + ->setParameter('event_type', $options['event_type']); + } + + if ($options['active_only'] === true) { + $options['query_builder']->andWhere($qb->expr()->eq('r.active', ':active')) + ->setParameter('active', true); + } + +// if ($options['show_group_type'] === true) { +// $closure = $options['choice_label']; +// $options['choice_label'] = function(Role $r) +// use ($translatableStringHelper, $closure) { +// return $translatableStringHelper->localize($r->get) +// +// } +// } + + + } + + public function configureOptions(OptionsResolver $resolver) + { + // create copy for use in Closure + $translatableStringHelper = $this->translatableStringHelper; + $translator = $this->translator; + + $resolver + // add option "event_type" + ->setDefined('event_type') + ->setAllowedTypes('event_type', array('null', EventType::class)) + ->setDefault('event_type', null) + // add option allow unactive + ->setDefault('active_only', true) + ->setAllowedTypes('active_only', array('boolean')) + // add possibility to prepend by group_type + ->setDefault('show_group_type', false) + ->setAllowedTypes('show_group_type', array('boolean')) + ; + + $qb = $this->roleRepository->createQueryBuilder('r'); + + $resolver->setDefaults(array( + 'class' => Role::class, + 'query_builder' => $qb, + 'choice_attr' => function(Role $r) { + return array( + 'data-event-type' => $r->getType()->getId(), + 'data-link-category' => $r->getType()->getId() + ); + }, + 'choice_label' => function(Role $r) + use ($translatableStringHelper, $translator) { + return $translatableStringHelper->localize($r->getName()). + ($r->getActive() === true ? '' : + ' ('.$translator->trans('unactive').')'); + } + )); + } + + public function getParent() + { + return EntityType::class; + } +} diff --git a/Form/Type/PickStatusType.php b/Form/Type/PickStatusType.php new file mode 100644 index 000000000..c4bde94e2 --- /dev/null +++ b/Form/Type/PickStatusType.php @@ -0,0 +1,134 @@ +, + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace Chill\EventBundle\Form\Type; + +use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; +use Chill\EventBundle\Entity\Status; +use Chill\EventBundle\Entity\EventType; +use Chill\MainBundle\Templating\TranslatableStringHelper; +use Symfony\Component\Translation\TranslatorInterface; +use Symfony\Bridge\Doctrine\Form\Type\EntityType; +use Doctrine\ORM\EntityRepository; + +/** + * Allow to pick amongst type + * + * parameters : + * + * - event_type : restricts to a certain event type. Default null (= all event types) + * - active_only: restricts to active type only. Default true + * + * @author Julien Fastré + * @author Champs Libres + */ +class PickStatusType extends AbstractType +{ + + /** + * + * @var TranslatableStringHelper + */ + protected $translatableStringHelper; + + /** + * + * @var TranslatorInterface + */ + protected $translator; + + /** + * + * @var EntityRepository + */ + protected $statusRepository; + + public function __construct( + TranslatableStringHelper $translatableStringHelper, + TranslatorInterface $translator, + EntityRepository $statusRepository + ) { + $this->translatableStringHelper = $translatableStringHelper; + $this->translator = $translator; + $this->statusRepository = $statusRepository; + } + + public function buildForm(FormBuilderInterface $builder, array $options) + { + $qb = $options['query_builder']; + + if ($options['event_type'] instanceof EventType) { + $options['query_builder']->where($qb->expr()->eq('r.type', ':event_type')) + ->setParameter('event_type', $options['event_type']); + + } + + if ($options['active_only'] === true) { + $options['query_builder']->andWhere($qb->expr()->eq('r.active', ':active')) + ->setParameter('active', true); + } + + + } + + public function configureOptions(OptionsResolver $resolver) + { + // create copy for use in Closure + $translatableStringHelper = $this->translatableStringHelper; + $translator = $this->translator; + + $resolver + // add option "event_type" + ->setDefined('event_type') + ->setAllowedTypes('event_type', array('null', EventType::class)) + ->setDefault('event_type', null) + // add option allow unactive + ->setDefault('active_only', true) + ->setAllowedTypes('active_only', array('boolean')) + ; + + $qb = $this->statusRepository->createQueryBuilder('r'); + + $resolver->setDefaults(array( + 'class' => Status::class, + 'query_builder' => $qb, + 'choice_attr' => function(Status $s) { + return array( + 'data-event-type' => $s->getType()->getId() + ); + }, + 'choice_label' => function(Status $s) + use ($translatableStringHelper, $translator) { + return $translatableStringHelper->localize($s->getName()). + ($s->getActive() === true ? '' : + ' ('.$translator->trans('unactive').')'); + } + )); + } + + public function getParent() + { + return EntityType::class; + } +} diff --git a/Resources/config/services/forms.yml b/Resources/config/services/forms.yml index 2f622a326..b587bac49 100644 --- a/Resources/config/services/forms.yml +++ b/Resources/config/services/forms.yml @@ -1,6 +1,6 @@ services: - chill.event.form.type.translatable_event_type: - class: Chill\EventBundle\Form\Type\TranslatableEventType + chill.event.form.type.pick_event_type: + class: Chill\EventBundle\Form\Type\PickEventType arguments: - "@chill.main.helper.translatable_string" tags: @@ -21,3 +21,21 @@ services: - "@chill.main.helper.translatable_string" tags: - { name: form.type } + + chill.event.form.pick_role_type: + class: Chill\EventBundle\Form\Type\PickRoleType + arguments: + - "@chill.main.helper.translatable_string" + - "@translator" + - "@chill_event.repository.role" + tags: + - { name: form.type } + + chill.event.form.pick_status_type: + class: Chill\EventBundle\Form\Type\PickStatusType + arguments: + - "@chill.main.helper.translatable_string" + - "@translator" + - "@chill_event.repository.status" + tags: + - { name: form.type } diff --git a/Resources/config/services/repositories.yml b/Resources/config/services/repositories.yml index 44e653cc0..d27130bcd 100644 --- a/Resources/config/services/repositories.yml +++ b/Resources/config/services/repositories.yml @@ -1,6 +1,18 @@ services: - chill_group.repository.event: + chill_event.repository.event: class: Doctrine\ORM\EntityRepository factory: ['@doctrine.orm.entity_manager', getRepository] arguments: - - 'Chill\EventBundle\Entity\Event' \ No newline at end of file + - 'Chill\EventBundle\Entity\Event' + + chill_event.repository.role: + class: Doctrine\ORM\EntityRepository + factory: ['@doctrine.orm.entity_manager', getRepository] + arguments: + - 'Chill\EventBundle\Entity\Role' + + chill_event.repository.status: + class: Doctrine\ORM\EntityRepository + factory: ['@doctrine.orm.entity_manager', getRepository] + arguments: + - 'Chill\EventBundle\Entity\Status' \ No newline at end of file diff --git a/Resources/config/services/search.yml b/Resources/config/services/search.yml index 99b455bae..a1e0b2f17 100644 --- a/Resources/config/services/search.yml +++ b/Resources/config/services/search.yml @@ -3,7 +3,7 @@ services: class: Chill\EventBundle\Search\EventSearch arguments: - "@security.token_storage" - - "@chill_group.repository.event" + - "@chill_event.repository.event" - "@chill.main.security.authorization.helper" - "@templating" tags: From e77409095914c2449831fdb49dfaccefd9833f57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 19 Apr 2016 18:36:29 +0200 Subject: [PATCH 50/73] allow group_by in PickRoleType and PickStatusType --- Form/Type/PickRoleType.php | 39 +++++++++++++++++++++--------------- Form/Type/PickStatusType.php | 21 ++++++++++++++++++- 2 files changed, 43 insertions(+), 17 deletions(-) diff --git a/Form/Type/PickRoleType.php b/Form/Type/PickRoleType.php index 4ea4b46a2..545892b98 100644 --- a/Form/Type/PickRoleType.php +++ b/Form/Type/PickRoleType.php @@ -31,6 +31,8 @@ use Chill\MainBundle\Templating\TranslatableStringHelper; use Symfony\Component\Translation\TranslatorInterface; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Doctrine\ORM\EntityRepository; +use Symfony\Component\Form\FormEvent; +use Symfony\Component\Form\FormEvents; /** * Allow to pick a choice amongst different choices @@ -71,31 +73,38 @@ class PickRoleType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options) { - // create copy for use in Closure - $translatableStringHelper = $this->translatableStringHelper; // create copy for easier management $qb = $options['query_builder']; if ($options['event_type'] instanceof EventType) { $options['query_builder']->where($qb->expr()->eq('r.type', ':event_type')) ->setParameter('event_type', $options['event_type']); - } + } if ($options['active_only'] === true) { $options['query_builder']->andWhere($qb->expr()->eq('r.active', ':active')) ->setParameter('active', true); } -// if ($options['show_group_type'] === true) { -// $closure = $options['choice_label']; -// $options['choice_label'] = function(Role $r) -// use ($translatableStringHelper, $closure) { -// return $translatableStringHelper->localize($r->get) -// -// } -// } - - + if ($options['group_by'] === null) { + $builder->addEventListener( + FormEvents::PRE_SET_DATA, + function(FormEvent $event) use ($options) { + if ($options['event_type'] === null) { + $form = $event->getForm(); + $name = $form->getName(); + $config = $form->getConfig(); + $type = $config->getType()->getName(); + $options = $config->getOptions(); + + $form->getParent()->add($name, $type, array_replace($options, array( + 'group_by' => function(Role $r) + { return $this->translatableStringHelper->localize($r->getType()->getName()); } + ))); + } + } + ); + } } public function configureOptions(OptionsResolver $resolver) @@ -112,9 +121,6 @@ class PickRoleType extends AbstractType // add option allow unactive ->setDefault('active_only', true) ->setAllowedTypes('active_only', array('boolean')) - // add possibility to prepend by group_type - ->setDefault('show_group_type', false) - ->setAllowedTypes('show_group_type', array('boolean')) ; $qb = $this->roleRepository->createQueryBuilder('r'); @@ -122,6 +128,7 @@ class PickRoleType extends AbstractType $resolver->setDefaults(array( 'class' => Role::class, 'query_builder' => $qb, + 'group_by' => null, 'choice_attr' => function(Role $r) { return array( 'data-event-type' => $r->getType()->getId(), diff --git a/Form/Type/PickStatusType.php b/Form/Type/PickStatusType.php index c4bde94e2..0557a0648 100644 --- a/Form/Type/PickStatusType.php +++ b/Form/Type/PickStatusType.php @@ -31,6 +31,8 @@ use Chill\MainBundle\Templating\TranslatableStringHelper; use Symfony\Component\Translation\TranslatorInterface; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Doctrine\ORM\EntityRepository; +use Symfony\Component\Form\FormEvent; +use Symfony\Component\Form\FormEvents; /** * Allow to pick amongst type @@ -88,7 +90,23 @@ class PickStatusType extends AbstractType $options['query_builder']->andWhere($qb->expr()->eq('r.active', ':active')) ->setParameter('active', true); } - + + if ($options['group_by'] === null && $options['event_type'] === null) { + $builder->addEventListener( + FormEvents::PRE_SET_DATA, + function(FormEvent $event) { + $form = $event->getForm(); + $name = $form->getName(); + $config = $form->getConfig(); + $type = $config->getType()->getName(); + $options = $config->getOptions(); + $form->getParent()->add($name, $type, array_replace($options, array( + 'group_by' => function(Status $s) + { return $this->translatableStringHelper->localize($s->getType()->getName()); } + ))); + } + ); + } } @@ -113,6 +131,7 @@ class PickStatusType extends AbstractType $resolver->setDefaults(array( 'class' => Status::class, 'query_builder' => $qb, + 'group_by' => null, 'choice_attr' => function(Status $s) { return array( 'data-event-type' => $s->getType()->getId() From e723aeeeb4787f77a93b6df670fd890e15fc194f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 17 May 2016 09:20:27 +0200 Subject: [PATCH 51/73] [minor] add translation --- Resources/translations/messages.fr.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/Resources/translations/messages.fr.yml b/Resources/translations/messages.fr.yml index 4af7a2b83..07f5ec9ce 100644 --- a/Resources/translations/messages.fr.yml +++ b/Resources/translations/messages.fr.yml @@ -37,6 +37,7 @@ Participation Edit: Modifier une participation 'The following people have been ignored because they are already participating on the event': '{1} La personne suivante a été ignorée parce qu''elle participe déjà à l''événement | ]1,Inf] Les personnes suivantes ont été ignorées parce qu''elles participent déjà à l''événement' There are no participation to edit for this event: Il n'y a pas de participation pour cet événement The participations have been successfully updated.: Les participations ont été mises à jour. +The participations were created: Les participations ont été créées #search Event search: Recherche d'événements From 54ac8d052f3ca82280e0d699ef412bff295d3d61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 17 May 2016 20:41:03 +0200 Subject: [PATCH 52/73] fix bug on redirection when all required participation already exists When we request multiple participations on an event, and all people already participate on the event, the controller redirected to a route which provoked a bad request error. Now, we redirect to the view route. --- Controller/ParticipationController.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Controller/ParticipationController.php b/Controller/ParticipationController.php index ca2a5f953..1b23db177 100644 --- a/Controller/ParticipationController.php +++ b/Controller/ParticipationController.php @@ -156,18 +156,19 @@ class ParticipationController extends Controller { $participations = $this->handleRequest($request, new Participation()); + foreach ($participations as $i => $participation) { // check for authorization $this->denyAccessUnlessGranted(ParticipationVoter::CREATE, $participation, 'The user is not allowed to create this participation'); - // check that the user is not already in the event (computing only once) + // create a collection of person's id participating to the event /* @var $peopleParticipating \Doctrine\Common\Collections\ArrayCollection */ $peopleParticipating = isset($peopleParticipating) ? $peopleParticipating : $participation->getEvent()->getParticipations()->map( function(Participation $p) { return $p->getPerson()->getId(); } ); - + // check that the user is not already in the event if ($peopleParticipating->contains($participation->getPerson()->getId())) { $ignoredParticipations[] = $participation ->getEvent()->getParticipations()->filter( @@ -184,10 +185,11 @@ class ParticipationController extends Controller if (!isset($newParticipations)) { // if we do not have nay participants, redirect to event view - $this->addFlash('error', 'Any of the requested people may be added ' - . 'on the event: they are maybe already participating.'); + $this->addFlash('error', $this->get('translator')->trans( + 'None of the requested people may participate ' + . 'the event: they are maybe already participating.')); - return $this->redirectToRoute('chill_event_participation_new', array( + return $this->redirectToRoute('chill_event__event_show', array( 'event_id' => $request->query->getInt('event_id', 0) )); } elseif (count($newParticipations) > 1) { From 5bcff0cba4c529150cb0f9c03dbbc9bbea34bc86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 17 May 2016 21:04:14 +0200 Subject: [PATCH 53/73] allow to add single participation with persons_ids --- Controller/ParticipationController.php | 20 ++++++++++++-------- Resources/translations/messages.fr.yml | 2 +- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Controller/ParticipationController.php b/Controller/ParticipationController.php index 1b23db177..4c597a818 100644 --- a/Controller/ParticipationController.php +++ b/Controller/ParticipationController.php @@ -102,7 +102,7 @@ class ParticipationController extends Controller if ($multiple === true) { $persons_ids = $request->query->get('persons_ids'); - if (!preg_match('/^([0-9]{1,},){1,}[0-9]{1,}$/', $persons_ids)) { + if (!preg_match('/^([0-9]{1,},{0,1}){1,}[0-9]{0,}$/', $persons_ids)) { throw new \RuntimeException("The persons_ids value should " . "contains int separated by ','"); } @@ -123,7 +123,7 @@ class ParticipationController extends Controller */ protected function newSingle(Request $request) { - $participation = $this->handleRequest($request, new Participation()); + $participation = $this->handleRequest($request, new Participation(), false); $this->denyAccessUnlessGranted(ParticipationVoter::CREATE, $participation, 'The user is not allowed to create this participation'); @@ -154,7 +154,7 @@ class ParticipationController extends Controller */ protected function newMultiple(Request $request) { - $participations = $this->handleRequest($request, new Participation()); + $participations = $this->handleRequest($request, new Participation(), true); foreach ($participations as $i => $participation) { @@ -249,7 +249,7 @@ class ParticipationController extends Controller public function createSingle(Request $request) { - $participation = $this->handleRequest($request, new Participation()); + $participation = $this->handleRequest($request, new Participation(), false); $this->denyAccessUnlessGranted(ParticipationVoter::CREATE, $participation, 'The user is not allowed to create this participation'); @@ -280,7 +280,7 @@ class ParticipationController extends Controller public function createMultiple(Request $request) { - $participations = $this->handleRequest($request, new Participation()); + $participations = $this->handleRequest($request, new Participation(), true); foreach($participations as $participation) { $this->denyAccessUnlessGranted(ParticipationVoter::CREATE, @@ -324,11 +324,15 @@ class ParticipationController extends Controller * * @param Request $request * @param Participation $participation - * @return Participation + * @param boolean $multiple (default false) + * @return Participation|Participations[] return one single participation if $multiple == false * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException if the event/person is not found * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException if the user does not have access to event/person */ - protected function handleRequest(Request $request, Participation $participation) + protected function handleRequest( + Request $request, + Participation $participation, + $multiple = false) { $em = $this->getDoctrine()->getManager(); if ($em->contains($participation)) { @@ -382,7 +386,7 @@ class ParticipationController extends Controller $participations[] = $participation; } - return count($participations) > 1 ? $participations : $participations[0]; + return $multiple ? $participations : $participations[0]; } /** diff --git a/Resources/translations/messages.fr.yml b/Resources/translations/messages.fr.yml index 07f5ec9ce..0a38cf10b 100644 --- a/Resources/translations/messages.fr.yml +++ b/Resources/translations/messages.fr.yml @@ -33,7 +33,7 @@ Back to the event: Retour à l'événement The participation was created: La participation a été créée The participation was updated: La participation a été mise à jour Participation Edit: Modifier une participation -'Any of the requested people may be added on the event: they are maybe already participating.': 'Aucune des personnes suggérées ne peut être ajoutée à l''événement: elles sont peut-être déjà inscrites comme participantes.' +'None of the requested people may participate the event: they are maybe already participating.': 'Aucune des personnes indiquées ne peut être ajoutée à l''événement: elles sont peut-être déjà inscrites comme participantes.' 'The following people have been ignored because they are already participating on the event': '{1} La personne suivante a été ignorée parce qu''elle participe déjà à l''événement | ]1,Inf] Les personnes suivantes ont été ignorées parce qu''elles participent déjà à l''événement' There are no participation to edit for this event: Il n'y a pas de participation pour cet événement The participations have been successfully updated.: Les participations ont été mises à jour. From ca2d4db6f93ea2af30e87e5480ac57a4b50ee78e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 17 May 2016 21:33:10 +0200 Subject: [PATCH 54/73] add search within event name, date, date-from, date-to ref #10 --- Search/EventSearch.php | 46 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/Search/EventSearch.php b/Search/EventSearch.php index c2b4e4e80..882dd2a77 100644 --- a/Search/EventSearch.php +++ b/Search/EventSearch.php @@ -13,6 +13,17 @@ use Symfony\Component\Security\Core\Role\Role; /** * Search within Events. + * + * available terms : + * - name: to search within the name + * - date: search the event at a the given date + * - date-from: search the event after the given date + * - date-to : search the event before the given date + * + * Default terms search within the name, but the term "name" has precedence. This + * means that if the search string is `@event xyz name:"abc"`, the searched + * string will be "abc" and not xyz + * * * @author Julien Fastré * @author Champs Libres @@ -65,7 +76,7 @@ class EventSearch extends AbstractSearch public function isActiveByDefault() { - return false; + return true; } public function getOrder() @@ -136,6 +147,39 @@ class EventSearch extends AbstractSearch $qb->andWhere($orWhere); } + if (isset($terms['name']) OR isset($terms['_default'])) { + // the form with name:"xyz" has precedence + $name = isset($terms['name']) ? $terms['name'] : $terms['_default']; + + $where = $qb->expr()->like('UNACCENT(LOWER(e.name))', ':name'); + $qb->setParameter('name', '%'.$name.'%'); + $qb->andWhere($where); + } + + if (isset($terms['date'])) { + $date = $this->parseDate($terms['date']); + + $where = $qb->expr()->eq('e.date', ':date'); + $qb->setParameter('date', $date); + $qb->andWhere($where); + } + + if (isset($terms['date-from'])) { + $date = $this->parseDate($terms['date-from']); + + $where = $qb->expr()->gte('e.date', ':datefrom'); + $qb->setParameter('datefrom', $date); + $qb->andWhere($where); + } + + if (isset($terms['date-to'])) { + $date = $this->parseDate($terms['date-to']); + + $where = $qb->expr()->lte('e.date', ':dateto'); + $qb->setParameter('dateto', $date); + $qb->andWhere($where); + } + return $qb; From 329d688b5a2e043c0abf1cfd4d79c40bb711396c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 27 May 2016 15:44:28 +0200 Subject: [PATCH 55/73] adding a link to event types for link parent/categories --- Form/Type/PickStatusType.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Form/Type/PickStatusType.php b/Form/Type/PickStatusType.php index 0557a0648..b4f40b7be 100644 --- a/Form/Type/PickStatusType.php +++ b/Form/Type/PickStatusType.php @@ -134,7 +134,8 @@ class PickStatusType extends AbstractType 'group_by' => null, 'choice_attr' => function(Status $s) { return array( - 'data-event-type' => $s->getType()->getId() + 'data-event-type' => $s->getType()->getId(), + 'data-link-category' => $s->getType()->getId() ); }, 'choice_label' => function(Status $s) From 9be006a9466b8cfe7e112ac78d01afdcaa8ffe28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 27 May 2016 17:15:54 +0200 Subject: [PATCH 56/73] fix error in recompose pattern --- Search/EventSearch.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Search/EventSearch.php b/Search/EventSearch.php index 882dd2a77..62f4e1604 100644 --- a/Search/EventSearch.php +++ b/Search/EventSearch.php @@ -89,11 +89,16 @@ class EventSearch extends AbstractSearch return $this->templating->render('ChillEventBundle:Event:list.html.twig', array( 'events' => $this->search($terms, $start, $limit, $options), - 'pattern' => $this->recomposePattern($terms, array(), $terms['_domain']), + 'pattern' => $this->recomposePattern($terms, $this->getAvailableTerms(), $terms['_domain']), 'total' => $this->count($terms) )); } + protected function getAvailableTerms() + { + return array('date-from', 'date-to', 'name', 'date'); + } + protected function search(array $terms, $start, $limit, $options) { $qb = $this->er->createQueryBuilder('e'); From 69af3e8d43a53422b311984c1994bbbb19a2432e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 31 May 2016 17:30:35 +0200 Subject: [PATCH 57/73] add test to eventSearch ref #10 --- Resources/views/Event/list.html.twig | 2 +- Search/EventSearch.php | 5 +- Tests/Search/EventSearchTest.php | 276 +++++++++++++++++++++++++++ 3 files changed, 281 insertions(+), 2 deletions(-) create mode 100644 Tests/Search/EventSearchTest.php diff --git a/Resources/views/Event/list.html.twig b/Resources/views/Event/list.html.twig index 0c98cb027..10d274e2d 100644 --- a/Resources/views/Event/list.html.twig +++ b/Resources/views/Event/list.html.twig @@ -4,7 +4,7 @@ {% if events|length > 0 %} - +
                                        diff --git a/Search/EventSearch.php b/Search/EventSearch.php index 62f4e1604..d04d0e3eb 100644 --- a/Search/EventSearch.php +++ b/Search/EventSearch.php @@ -152,7 +152,10 @@ class EventSearch extends AbstractSearch $qb->andWhere($orWhere); } - if (isset($terms['name']) OR isset($terms['_default'])) { + if ( + (isset($terms['name']) OR isset($terms['_default'])) + AND + (!empty($terms['name']) OR !empty($terms['_default']))) { // the form with name:"xyz" has precedence $name = isset($terms['name']) ? $terms['name'] : $terms['_default']; diff --git a/Tests/Search/EventSearchTest.php b/Tests/Search/EventSearchTest.php new file mode 100644 index 000000000..ab5e732c9 --- /dev/null +++ b/Tests/Search/EventSearchTest.php @@ -0,0 +1,276 @@ + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace Chill\EventBundle\Tests\Search; + +use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; +use Chill\EventBundle\Entity\Event; +use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; +use Chill\EventBundle\Search\EventSearch; + + +/** + * Test the EventSearch class + * + * @author Julien Fastré + */ +class EventSearchTest extends WebTestCase +{ + /** + * The eventSearch service, which is used to search events + * + * @var \Chill\EventBundle\Search\EventSearch + */ + protected $eventSearch; + + /** + * + * @var \Doctrine\ORM\EntityManagerInterface + */ + protected $entityManager; + + /** + * The center A + * + * @var \Chill\MainBundle\Entity\Center + */ + protected $centerA; + + /** + * a random event type + * + * @var \Chill\EventBundle\Entity\EventType + */ + protected $eventType; + + /** + * Events created during this test + * + * @var Event[] + */ + protected $events = array(); + + /** + * + * @var \Prophecy\Prophet + */ + protected $prophet; + + /** + * + * @var \Symfony\Component\BrowserKit\Client + */ + protected $client; + + public function setUp() + { + self::bootKernel(); + /* @var $kernel \Symfony\Component\HttpKernel\KernelInterface */ + $kernel = self::$kernel; + + $this->client = static::createClient(array(), array( + 'PHP_AUTH_USER' => 'center a_social', + 'PHP_AUTH_PW' => 'password', + 'HTTP_ACCEPT_LANGUAGE' => 'fr_FR' + )); + + $this->prophet = new \Prophecy\Prophet; + + $this->entityManager = self::$kernel->getContainer() + ->get('doctrine.orm.entity_manager') + ; + + $this->centerA = $this->entityManager + ->getRepository('ChillMainBundle:Center') + ->findOneBy(array('name' => 'Center A')); + + $this->eventType = $this->entityManager + ->getRepository('ChillEventBundle:EventType') + ->findAll()[0]; + + $this->createEvents(); + } + + public function tearDown() + { + foreach ($this->events as $event) { + $this->entityManager->createQuery('DELETE FROM ChillEventBundle:Event e WHERE e.id = :event_id') + ->setParameter('event_id', $event->getId()) + ->execute(); + } + + $this->events = array(); + } + + protected function createEvents() + { + $event1 = (new Event()) + ->setCenter($this->centerA) + ->setDate(new \DateTime('2016-05-30')) + ->setName('Printemps européen') + ->setType($this->eventType) + ->setCircle($this->getCircle()) + ; + $this->entityManager->persist($event1); + $this->events[] = $event1; + + $event2 = (new Event()) + ->setCenter($this->centerA) + ->setDate(new \DateTime('2016-06-24')) + ->setName('Hiver de la droite') + ->setType($this->eventType) + ->setCircle($this->getCircle()) + ; + $this->entityManager->persist($event2); + $this->events[] = $event2; + + $this->entityManager->flush(); + } + + /** + * + * @param string $name the name of the circle + * @return \Chill\MainBundle\Entity\Scope + */ + protected function getCircle($name = 'social') + { + $circles = $this->entityManager->getRepository('ChillMainBundle:Scope') + ->findAll(); + + /* @var $circle \Chill\MainBundle\Entity\Scope */ + foreach($circles as $circle) { + if (in_array($name, $circle->getName())) { + return $circle; + } + } + } + + public function testDisplayAll() + { + $crawler = $this->client->request('GET', '/fr/search', array( + 'q' => '@events' + )); + + $this->assertGreaterThan(2, $crawler->filter('table.events tr')->count(), + 'assert than more than 2 tr are present'); + } + + public function testSearchByDefault() + { + $crawler = $this->client->request('GET', '/fr/search', array( + 'q' => '@events printemps' + )); + + $this->assertEquals( + 1, + $crawler->filter('table.events tr')->count() - 1 /* as the header is a th */, + 'assert than more than 2 tr are present'); + + $this->assertEquals( + 1, + $crawler->filter('tr:contains("Printemps")')->count(), + 'assert that the word "printemps" is present'); + } + + public function testSearchByName() + { + $crawler = $this->client->request('GET', '/fr/search', array( + 'q' => '@events name:printemps' + )); + + $this->assertEquals( + 1, + $crawler->filter('table.events tr')->count() - 1 /* as the header is a th */, + 'assert than more than 2 tr are present'); + + $this->assertEquals( + 1, + $crawler->filter('tr:contains("Printemps")')->count(), + 'assert that the word "printemps" is present'); + } + + public function testSearchByDate() + { + // search with date from + $crawler = $this->client->request('GET', '/fr/search', array( + 'q' => '@events date-from:2016-05-30' + )); + + $this->assertEquals( + 1, + $crawler->filter('tr:contains("Printemps")')->count(), + 'assert that the word "printemps" is present'); + $this->assertEquals( + 1, + $crawler->filter('tr:contains("Hiver")')->count(), + 'assert that the word "Hiver" is present'); + + // serach with date from **and** date-to + $crawler = $this->client->request('GET', '/fr/search', array( + 'q' => '@events date-from:2016-05-30 date-to:2016-06-20' + )); + + $this->assertEquals( + 1, + $crawler->filter('tr:contains("Printemps")')->count(), + 'assert that the word "printemps" is present'); + $this->assertEquals( + 0, + $crawler->filter('tr:contains("Hiver")')->count(), + 'assert that the word "Hiver" is not present'); + + // serach with date from **and** date-to + $crawler = $this->client->request('GET', '/fr/search', array( + 'q' => '@events date:2016-05-30' + )); + + $this->assertEquals( + 1, + $crawler->filter('tr:contains("Printemps")')->count(), + 'assert that the word "printemps" is present'); + $this->assertEquals( + 0, + $crawler->filter('tr:contains("Hiver")')->count(), + 'assert that the word "Hiver" is not present'); + } + + /** + * Test that a user connected with an user with the wrong center does not + * see the events + */ + public function testDisplayAllWrongUser() + { + $client = static::createClient(array(), array( + 'PHP_AUTH_USER' => 'center b_social', + 'PHP_AUTH_PW' => 'password', + 'HTTP_ACCEPT_LANGUAGE' => 'fr_FR' + )); + + $crawler = $client->request('GET', '/fr/search', array( + 'q' => '@events printemps' + )); + + $this->assertEquals(0, $crawler->filter('tr:contains("Printemps")')->count(), + 'assert that the word "printemps" is present'); + + } + + + +} From c8fcab4d1d8ba909391967f84229c8bfcfb854cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 10 Jun 2016 17:07:34 +0200 Subject: [PATCH 58/73] fix routes and translatable string in admin prototype ref #12 ref #13 ref #14 ref #15 --- Controller/EventTypeController.php | 16 ++++++++++------ Controller/RoleController.php | 19 +++++++++++-------- Controller/StatusController.php | 12 ++++++------ Form/EventTypeType.php | 3 ++- Form/RoleType.php | 23 +++++++++++++++++++++-- Form/StatusType.php | 6 ++++-- Resources/config/routing/eventtype.yml | 14 +++++++------- Resources/config/routing/status.yml | 14 +++++++------- Resources/config/services/forms.yml | 7 +++++++ Resources/views/EventType/edit.html.twig | 2 +- Resources/views/EventType/index.html.twig | 10 +++++----- Resources/views/EventType/new.html.twig | 2 +- Resources/views/EventType/show.html.twig | 6 +++--- Resources/views/Role/edit.html.twig | 2 +- Resources/views/Role/index.html.twig | 10 +++++----- Resources/views/Role/new.html.twig | 2 +- Resources/views/Role/show.html.twig | 6 +++--- Resources/views/Status/edit.html.twig | 2 +- Resources/views/Status/index.html.twig | 10 +++++----- Resources/views/Status/new.html.twig | 2 +- Resources/views/Status/show.html.twig | 6 +++--- 21 files changed, 105 insertions(+), 69 deletions(-) diff --git a/Controller/EventTypeController.php b/Controller/EventTypeController.php index cbe28999b..760594600 100644 --- a/Controller/EventTypeController.php +++ b/Controller/EventTypeController.php @@ -44,7 +44,8 @@ class EventTypeController extends Controller $em->persist($entity); $em->flush(); - return $this->redirect($this->generateUrl('{_locale}_admin_show', array('id' => $entity->getId()))); + return $this->redirect($this->generateUrl('chill_eventtype_admin_show', + array('id' => $entity->getId()))); } return $this->render('ChillEventBundle:EventType:new.html.twig', array( @@ -63,7 +64,7 @@ class EventTypeController extends Controller private function createCreateForm(EventType $entity) { $form = $this->createForm(new EventTypeType(), $entity, array( - 'action' => $this->generateUrl('{_locale}_admin_create'), + 'action' => $this->generateUrl('chill_eventtype_admin_create'), 'method' => 'POST', )); @@ -143,7 +144,8 @@ class EventTypeController extends Controller private function createEditForm(EventType $entity) { $form = $this->createForm(new EventTypeType(), $entity, array( - 'action' => $this->generateUrl('{_locale}_admin_update', array('id' => $entity->getId())), + 'action' => $this->generateUrl('chill_eventtype_admin_update', + array('id' => $entity->getId())), 'method' => 'PUT', )); @@ -172,7 +174,8 @@ class EventTypeController extends Controller if ($editForm->isValid()) { $em->flush(); - return $this->redirect($this->generateUrl('{_locale}_admin_edit', array('id' => $id))); + return $this->redirect($this->generateUrl('chill_eventtype_admin_edit', + array('id' => $id))); } return $this->render('ChillEventBundle:EventType:edit.html.twig', array( @@ -202,7 +205,7 @@ class EventTypeController extends Controller $em->flush(); } - return $this->redirect($this->generateUrl('{_locale}_admin')); + return $this->redirect($this->generateUrl('chill_eventtype_admin')); } /** @@ -215,7 +218,8 @@ class EventTypeController extends Controller private function createDeleteForm($id) { return $this->createFormBuilder() - ->setAction($this->generateUrl('{_locale}_admin_delete', array('id' => $id))) + ->setAction($this->generateUrl('chill_eventtype_admin_delete', + array('id' => $id))) ->setMethod('DELETE') ->add('submit', 'submit', array('label' => 'Delete')) ->getForm() diff --git a/Controller/RoleController.php b/Controller/RoleController.php index 3834e89a9..b1c560292 100644 --- a/Controller/RoleController.php +++ b/Controller/RoleController.php @@ -44,7 +44,8 @@ class RoleController extends Controller $em->persist($entity); $em->flush(); - return $this->redirect($this->generateUrl('{_locale}_admin_role_show', array('id' => $entity->getId()))); + return $this->redirect($this->generateUrl('chill_event_admin_role_show', + array('id' => $entity->getId()))); } return $this->render('ChillEventBundle:Role:new.html.twig', array( @@ -62,8 +63,8 @@ class RoleController extends Controller */ private function createCreateForm(Role $entity) { - $form = $this->createForm(new RoleType(), $entity, array( - 'action' => $this->generateUrl('{_locale}_admin_role_create'), + $form = $this->createForm($this->get('chill.event.form.role_type'), $entity, array( + 'action' => $this->generateUrl('chill_event_admin_role_create'), 'method' => 'POST', )); @@ -142,8 +143,9 @@ class RoleController extends Controller */ private function createEditForm(Role $entity) { - $form = $this->createForm(new RoleType(), $entity, array( - 'action' => $this->generateUrl('{_locale}_admin_role_update', array('id' => $entity->getId())), + $form = $this->createForm($this->get('chill.event.form.role_type'), $entity, array( + 'action' => $this->generateUrl('chill_event_admin_role_update', + array('id' => $entity->getId())), 'method' => 'PUT', )); @@ -172,7 +174,8 @@ class RoleController extends Controller if ($editForm->isValid()) { $em->flush(); - return $this->redirect($this->generateUrl('{_locale}_admin_role_edit', array('id' => $id))); + return $this->redirect($this->generateUrl('chill_event_admin_role_edit', + array('id' => $id))); } return $this->render('ChillEventBundle:Role:edit.html.twig', array( @@ -202,7 +205,7 @@ class RoleController extends Controller $em->flush(); } - return $this->redirect($this->generateUrl('{_locale}_admin_role')); + return $this->redirect($this->generateUrl('chill_event_admin_role')); } /** @@ -215,7 +218,7 @@ class RoleController extends Controller private function createDeleteForm($id) { return $this->createFormBuilder() - ->setAction($this->generateUrl('{_locale}_admin_role_delete', array('id' => $id))) + ->setAction($this->generateUrl('chill_event_admin_role_delete', array('id' => $id))) ->setMethod('DELETE') ->add('submit', 'submit', array('label' => 'Delete')) ->getForm() diff --git a/Controller/StatusController.php b/Controller/StatusController.php index e0a57ba51..211153b94 100644 --- a/Controller/StatusController.php +++ b/Controller/StatusController.php @@ -44,7 +44,7 @@ class StatusController extends Controller $em->persist($entity); $em->flush(); - return $this->redirect($this->generateUrl('fr_admin_event_status_show', array('id' => $entity->getId()))); + return $this->redirect($this->generateUrl('chill_event_admin_status_show', array('id' => $entity->getId()))); } return $this->render('ChillEventBundle:Status:new.html.twig', array( @@ -63,7 +63,7 @@ class StatusController extends Controller private function createCreateForm(Status $entity) { $form = $this->createForm(new StatusType(), $entity, array( - 'action' => $this->generateUrl('fr_admin_event_status_create'), + 'action' => $this->generateUrl('chill_event_admin_status_create'), 'method' => 'POST', )); @@ -143,7 +143,7 @@ class StatusController extends Controller private function createEditForm(Status $entity) { $form = $this->createForm(new StatusType(), $entity, array( - 'action' => $this->generateUrl('fr_admin_event_status_update', array('id' => $entity->getId())), + 'action' => $this->generateUrl('chill_event_admin_status_update', array('id' => $entity->getId())), 'method' => 'PUT', )); @@ -172,7 +172,7 @@ class StatusController extends Controller if ($editForm->isValid()) { $em->flush(); - return $this->redirect($this->generateUrl('fr_admin_event_status_edit', array('id' => $id))); + return $this->redirect($this->generateUrl('chill_event_admin_status_edit', array('id' => $id))); } return $this->render('ChillEventBundle:Status:edit.html.twig', array( @@ -202,7 +202,7 @@ class StatusController extends Controller $em->flush(); } - return $this->redirect($this->generateUrl('fr_admin_event_status')); + return $this->redirect($this->generateUrl('chill_event_admin_status')); } /** @@ -215,7 +215,7 @@ class StatusController extends Controller private function createDeleteForm($id) { return $this->createFormBuilder() - ->setAction($this->generateUrl('fr_admin_event_status_delete', array('id' => $id))) + ->setAction($this->generateUrl('chill_event_admin_status_delete', array('id' => $id))) ->setMethod('DELETE') ->add('submit', 'submit', array('label' => 'Delete')) ->getForm() diff --git a/Form/EventTypeType.php b/Form/EventTypeType.php index 9616f9f59..b72a9f186 100644 --- a/Form/EventTypeType.php +++ b/Form/EventTypeType.php @@ -5,6 +5,7 @@ namespace Chill\EventBundle\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Chill\MainBundle\Form\Type\TranslatableStringFormType; class EventTypeType extends AbstractType { @@ -15,7 +16,7 @@ class EventTypeType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options) { $builder - ->add('name') + ->add('name', TranslatableStringFormType::class) ->add('active') ; } diff --git a/Form/RoleType.php b/Form/RoleType.php index 4f8fb3c53..d3483e917 100644 --- a/Form/RoleType.php +++ b/Form/RoleType.php @@ -5,9 +5,23 @@ namespace Chill\EventBundle\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Chill\MainBundle\Form\Type\TranslatableStringFormType; +use Chill\MainBundle\Templating\TranslatableStringHelper; +use Symfony\Bridge\Doctrine\Form\Type\EntityType; +use Chill\EventBundle\Entity\EventType; class RoleType extends AbstractType { + /** + * + * @var TranslatableStringHelper + */ + protected $translatableStringHelper; + + public function __construct(TranslatableStringHelper $translatableStringHelper) { + $this->translatableStringHelper = $translatableStringHelper; + } + /** * @param FormBuilderInterface $builder * @param array $options @@ -15,9 +29,14 @@ class RoleType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options) { $builder - ->add('name') + ->add('name', TranslatableStringFormType::class) ->add('active') - ->add('type') + ->add('type', EntityType::class, array( + 'class' => EventType::class, + 'choice_label' => function (EventType $e) { + return $this->translatableStringHelper->localize($e->getName()); + } + )) ; } diff --git a/Form/StatusType.php b/Form/StatusType.php index 1bef97168..d02b21781 100644 --- a/Form/StatusType.php +++ b/Form/StatusType.php @@ -5,6 +5,8 @@ namespace Chill\EventBundle\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Chill\MainBundle\Form\Type\TranslatableStringFormType; +use Chill\EventBundle\Form\Type\PickEventType; class StatusType extends AbstractType { @@ -15,9 +17,9 @@ class StatusType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options) { $builder - ->add('name') + ->add('name', TranslatableStringFormType::class) ->add('active') - ->add('type') + ->add('type', PickEventType::class) ; } diff --git a/Resources/config/routing/eventtype.yml b/Resources/config/routing/eventtype.yml index cdf54fe85..305c27af8 100644 --- a/Resources/config/routing/eventtype.yml +++ b/Resources/config/routing/eventtype.yml @@ -1,30 +1,30 @@ -chill_event_admin: +chill_eventtype_admin: path: / defaults: { _controller: "ChillEventBundle:EventType:index" } -chill_event_admin_show: +chill_eventtype_admin_show: path: /{id}/show defaults: { _controller: "ChillEventBundle:EventType:show" } -chill_event_admin_new: +chill_eventtype_admin_new: path: /new defaults: { _controller: "ChillEventBundle:EventType:new" } -chill_event_admin_create: +chill_eventtype_admin_create: path: /create defaults: { _controller: "ChillEventBundle:EventType:create" } methods: POST -chill_event_admin_edit: +chill_eventtype_admin_edit: path: /{id}/edit defaults: { _controller: "ChillEventBundle:EventType:edit" } -chill_event_admin_update: +chill_eventtype_admin_update: path: /{id}/update defaults: { _controller: "ChillEventBundle:EventType:update" } methods: [POST, PUT] -chill_event_admin_delete: +chill_eventtype_admin_delete: path: /{id}/delete defaults: { _controller: "ChillEventBundle:EventType:delete" } methods: [POST, DELETE] diff --git a/Resources/config/routing/status.yml b/Resources/config/routing/status.yml index 396f72c39..383a704ff 100644 --- a/Resources/config/routing/status.yml +++ b/Resources/config/routing/status.yml @@ -1,30 +1,30 @@ -fr_admin_event_status: +chill_event_admin_status: path: / defaults: { _controller: "ChillEventBundle:Status:index" } -fr_admin_event_status_show: +chill_event_admin_status_show: path: /{id}/show defaults: { _controller: "ChillEventBundle:Status:show" } -fr_admin_event_status_new: +chill_event_admin_status_new: path: /new defaults: { _controller: "ChillEventBundle:Status:new" } -fr_admin_event_status_create: +chill_event_admin_status_create: path: /create defaults: { _controller: "ChillEventBundle:Status:create" } methods: POST -fr_admin_event_status_edit: +chill_event_admin_status_edit: path: /{id}/edit defaults: { _controller: "ChillEventBundle:Status:edit" } -fr_admin_event_status_update: +chill_event_admin_status_update: path: /{id}/update defaults: { _controller: "ChillEventBundle:Status:update" } methods: [POST, PUT] -fr_admin_event_status_delete: +chill_event_admin_status_delete: path: /{id}/delete defaults: { _controller: "ChillEventBundle:Status:delete" } methods: [POST, DELETE] diff --git a/Resources/config/services/forms.yml b/Resources/config/services/forms.yml index b587bac49..90981d31b 100644 --- a/Resources/config/services/forms.yml +++ b/Resources/config/services/forms.yml @@ -39,3 +39,10 @@ services: - "@chill_event.repository.status" tags: - { name: form.type } + + chill.event.form.role_type: + class: Chill\EventBundle\Form\RoleType + arguments: + - "@chill.main.helper.translatable_string" + tags: + - { name: form.type } diff --git a/Resources/views/EventType/edit.html.twig b/Resources/views/EventType/edit.html.twig index 5849fa686..92bf5a236 100644 --- a/Resources/views/EventType/edit.html.twig +++ b/Resources/views/EventType/edit.html.twig @@ -7,7 +7,7 @@
                                        • - + Back to the list
                                        • diff --git a/Resources/views/EventType/index.html.twig b/Resources/views/EventType/index.html.twig index b40ce7b0f..669384172 100644 --- a/Resources/views/EventType/index.html.twig +++ b/Resources/views/EventType/index.html.twig @@ -15,16 +15,16 @@
                                        {% for entity in entities %} - - + + @@ -35,7 +35,7 @@
                                        • - + Create a new entry
                                        • diff --git a/Resources/views/EventType/new.html.twig b/Resources/views/EventType/new.html.twig index 4e097dd92..69a8f2638 100644 --- a/Resources/views/EventType/new.html.twig +++ b/Resources/views/EventType/new.html.twig @@ -7,7 +7,7 @@
                                          • - + Back to the list
                                          • diff --git a/Resources/views/EventType/show.html.twig b/Resources/views/EventType/show.html.twig index 3e748ca85..df2712898 100644 --- a/Resources/views/EventType/show.html.twig +++ b/Resources/views/EventType/show.html.twig @@ -11,7 +11,7 @@
                                        - + @@ -22,12 +22,12 @@
                                        • - + Back to the list
                                        • - + Edit
                                        • diff --git a/Resources/views/Role/edit.html.twig b/Resources/views/Role/edit.html.twig index 1bf9dc66d..021c810d6 100644 --- a/Resources/views/Role/edit.html.twig +++ b/Resources/views/Role/edit.html.twig @@ -7,7 +7,7 @@
                                          • - + Back to the list
                                          • diff --git a/Resources/views/Role/index.html.twig b/Resources/views/Role/index.html.twig index b6dd692bc..5ac43d05e 100644 --- a/Resources/views/Role/index.html.twig +++ b/Resources/views/Role/index.html.twig @@ -15,16 +15,16 @@
                                        {% for entity in entities %} - - + + @@ -35,7 +35,7 @@
                                        • - + Create a new entry
                                        • diff --git a/Resources/views/Role/new.html.twig b/Resources/views/Role/new.html.twig index a9ea41a1b..fd3c82044 100644 --- a/Resources/views/Role/new.html.twig +++ b/Resources/views/Role/new.html.twig @@ -7,7 +7,7 @@
                                          • - + Back to the list
                                          • diff --git a/Resources/views/Role/show.html.twig b/Resources/views/Role/show.html.twig index 99207becc..5a6956e76 100644 --- a/Resources/views/Role/show.html.twig +++ b/Resources/views/Role/show.html.twig @@ -11,7 +11,7 @@
                                        - + @@ -22,12 +22,12 @@
                                        • - + Back to the list
                                        • - + Edit
                                        • diff --git a/Resources/views/Status/edit.html.twig b/Resources/views/Status/edit.html.twig index f9c2f7bda..8c610c130 100644 --- a/Resources/views/Status/edit.html.twig +++ b/Resources/views/Status/edit.html.twig @@ -7,7 +7,7 @@
                                          • - + Back to the list
                                          • diff --git a/Resources/views/Status/index.html.twig b/Resources/views/Status/index.html.twig index 67d138ce9..38f34f955 100644 --- a/Resources/views/Status/index.html.twig +++ b/Resources/views/Status/index.html.twig @@ -15,16 +15,16 @@
                                        {% for entity in entities %} - - + + @@ -35,7 +35,7 @@
                                        • - + Create a new entry
                                        • diff --git a/Resources/views/Status/new.html.twig b/Resources/views/Status/new.html.twig index 7cd7093b1..bd2d824fa 100644 --- a/Resources/views/Status/new.html.twig +++ b/Resources/views/Status/new.html.twig @@ -7,7 +7,7 @@
                                          • - + Back to the list
                                          • diff --git a/Resources/views/Status/show.html.twig b/Resources/views/Status/show.html.twig index 2b56d32eb..8aa32d1a2 100644 --- a/Resources/views/Status/show.html.twig +++ b/Resources/views/Status/show.html.twig @@ -11,7 +11,7 @@
                                        - + @@ -22,12 +22,12 @@
                                        • - + Back to the list
                                        • - + Edit
                                        • From 2a10929d36e7bddc68c304ebd3492471e853310c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 19 Aug 2016 21:35:41 +0200 Subject: [PATCH 59/73] implementing the pagination api and the search preview --- Resources/config/services/search.yml | 1 + Resources/views/Event/list.html.twig | 13 +++++++++++++ Search/EventSearch.php | 25 ++++++++++++++++++++++--- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/Resources/config/services/search.yml b/Resources/config/services/search.yml index a1e0b2f17..2df3db26f 100644 --- a/Resources/config/services/search.yml +++ b/Resources/config/services/search.yml @@ -6,6 +6,7 @@ services: - "@chill_event.repository.event" - "@chill.main.security.authorization.helper" - "@templating" + - "@chill_main.paginator_factory" tags: - { name: chill.search, alias: 'event_regular' } diff --git a/Resources/views/Event/list.html.twig b/Resources/views/Event/list.html.twig index 10d274e2d..6da14a82f 100644 --- a/Resources/views/Event/list.html.twig +++ b/Resources/views/Event/list.html.twig @@ -2,6 +2,7 @@

                                          {% transchoice total with { '%pattern%' : pattern } %}%total% events match the search %pattern%{% endtranschoice %}

                                          +

                                          {{ 'Results %start%-%end% of %total%'|trans({ '%start%' : start, '%end%': start + events|length, '%total%' : total } ) }}

                                          {% if events|length > 0 %}
                                        {{ 'Name'|trans }}
                                        {{ entity.id }}{{ entity.name }}{{ entity.id }}{{ entity.name|localize_translatable_string }} {{ entity.active }}
                                        Name{{ entity.name }}{{ entity.name|localize_translatable_string }}
                                        Active
                                        {{ entity.id }}{{ entity.name }}{{ entity.id }}{{ entity.name|localize_translatable_string }} {{ entity.active }}
                                        Name{{ entity.name }}{{ entity.name|localize_translatable_string }}
                                        Active
                                        {{ entity.id }}{{ entity.name }}{{ entity.id }}{{ entity.name|localize_translatable_string }} {{ entity.active }}
                                        Name{{ entity.name }}{{ entity.name|localize_translatable_string }}
                                        Active
                                        @@ -48,5 +49,17 @@ {{ 'New event'|trans }} + + {% if preview == true and events|length < total %} +
                                      • + + {{ 'See all results'|trans }} +
                                      • + {% endif %} + + +{% if preview == false %} +{{ chill_pagination(paginator) }} +{% endif %} diff --git a/Search/EventSearch.php b/Search/EventSearch.php index d04d0e3eb..baf379a5d 100644 --- a/Search/EventSearch.php +++ b/Search/EventSearch.php @@ -10,6 +10,8 @@ use Chill\MainBundle\Security\Authorization\AuthorizationHelper; use Symfony\Component\Templating\EngineInterface as TemplatingEngine; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Security\Core\Role\Role; +use Chill\MainBundle\Pagination\PaginatorFactory; +use Chill\MainBundle\Search\SearchInterface; /** * Search within Events. @@ -55,18 +57,27 @@ class EventSearch extends AbstractSearch */ private $templating; + /** + * + * @var PaginatorFactory + */ + private $paginationFactory; + + const NAME = 'event_regular'; public function __construct( TokenStorageInterface $tokenStorage, EntityRepository $eventRepository, AuthorizationHelper $authorizationHelper, - TemplatingEngine $templating + TemplatingEngine $templating, + PaginatorFactory $paginatorFactory ) { $this->user = $tokenStorage->getToken()->getUser(); $this->er = $eventRepository; $this->helper = $authorizationHelper; $this->templating = $templating; + $this->paginationFactory = $paginatorFactory; } public function supports($domain) @@ -84,13 +95,21 @@ class EventSearch extends AbstractSearch return 3000; } - public function renderResult(array $terms, $start = 0, $limit = 50, array $options = array()) + public function renderResult(array $terms, $start = 0, $limit = 50, + array $options = array()) { + $total = $this->count($terms); + $paginator = $this->paginationFactory->create($total); + return $this->templating->render('ChillEventBundle:Event:list.html.twig', array( 'events' => $this->search($terms, $start, $limit, $options), 'pattern' => $this->recomposePattern($terms, $this->getAvailableTerms(), $terms['_domain']), - 'total' => $this->count($terms) + 'total' => $total, + 'start' => $start, + 'preview' => $options[SearchInterface::SEARCH_PREVIEW], + 'paginator' => $paginator, + 'search_name' => self::NAME )); } From 82b0fad8deee144d38e7970d3ba7f7c981c28b86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 25 Aug 2016 22:18:40 +0200 Subject: [PATCH 60/73] renaming SearchInterface::SEARCH_PREVIEW => SEARCH_PREVIEW_OPTION --- Search/EventSearch.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Search/EventSearch.php b/Search/EventSearch.php index baf379a5d..ae900b4c3 100644 --- a/Search/EventSearch.php +++ b/Search/EventSearch.php @@ -15,17 +15,17 @@ use Chill\MainBundle\Search\SearchInterface; /** * Search within Events. - * + * * available terms : * - name: to search within the name * - date: search the event at a the given date * - date-from: search the event after the given date * - date-to : search the event before the given date - * + * * Default terms search within the name, but the term "name" has precedence. This - * means that if the search string is `@event xyz name:"abc"`, the searched + * means that if the search string is `@event xyz name:"abc"`, the searched * string will be "abc" and not xyz - * + * * * @author Julien Fastré * @author Champs Libres @@ -34,7 +34,7 @@ class EventSearch extends AbstractSearch { /** - * + * * @var EntityRepository */ private $er; @@ -47,7 +47,7 @@ class EventSearch extends AbstractSearch /** * - * @var AuthorizationHelper + * @var AuthorizationHelper */ private $helper; @@ -95,25 +95,25 @@ class EventSearch extends AbstractSearch return 3000; } - public function renderResult(array $terms, $start = 0, $limit = 50, + public function renderResult(array $terms, $start = 0, $limit = 50, array $options = array()) { $total = $this->count($terms); $paginator = $this->paginationFactory->create($total); - return $this->templating->render('ChillEventBundle:Event:list.html.twig', - array( + return $this->templating->render('ChillEventBundle:Event:list.html.twig', + array( 'events' => $this->search($terms, $start, $limit, $options), 'pattern' => $this->recomposePattern($terms, $this->getAvailableTerms(), $terms['_domain']), 'total' => $total, 'start' => $start, - 'preview' => $options[SearchInterface::SEARCH_PREVIEW], + 'preview' => $options[SearchInterface::SEARCH_PREVIEW_OPTION], 'paginator' => $paginator, 'search_name' => self::NAME )); } - protected function getAvailableTerms() + protected function getAvailableTerms() { return array('date-from', 'date-to', 'name', 'date'); } @@ -157,7 +157,7 @@ class EventSearch extends AbstractSearch $n = 0; $orWhere = $qb->expr()->orX(); foreach ($reachableCenters as $center) { - $circles = $this->helper->getReachableScopes($this->user, + $circles = $this->helper->getReachableScopes($this->user, new Role('CHILL_EVENT_SEE'), $center); $where = $qb->expr()->andX( $qb->expr()->eq('e.center', ':center_'.$n), @@ -180,7 +180,7 @@ class EventSearch extends AbstractSearch $where = $qb->expr()->like('UNACCENT(LOWER(e.name))', ':name'); $qb->setParameter('name', '%'.$name.'%'); - $qb->andWhere($where); + $qb->andWhere($where); } if (isset($terms['date'])) { From 99c1d488e3504bbf8c3d52eb1dffd9b767b1a233 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 2 Sep 2016 08:24:25 +0200 Subject: [PATCH 61/73] adding condition for displaying message with number of result Now, the message "Result x-y of z" displays only if the number of events in result is > 0 --- Resources/views/Event/list.html.twig | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Resources/views/Event/list.html.twig b/Resources/views/Event/list.html.twig index 6da14a82f..6c78a49e1 100644 --- a/Resources/views/Event/list.html.twig +++ b/Resources/views/Event/list.html.twig @@ -2,9 +2,10 @@

                                        {% transchoice total with { '%pattern%' : pattern } %}%total% events match the search %pattern%{% endtranschoice %}

                                        -

                                        {{ 'Results %start%-%end% of %total%'|trans({ '%start%' : start, '%end%': start + events|length, '%total%' : total } ) }}

                                        - {% if events|length > 0 %} + +

                                        {{ 'Results %start%-%end% of %total%'|trans({ '%start%' : start, '%end%': start + events|length, '%total%' : total } ) }}

                                        +
                                        From 6c1586e37053343788fc025dab858ca10803de4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Sun, 20 Nov 2016 22:45:02 +0100 Subject: [PATCH 62/73] adding CI to project --- .gitlab-ci.yml | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 000000000..36433bea7 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,60 @@ +.test_definition: &test_definition + services: + - chill/database:latest + before_script: + - composer config github-oauth.github.com $GITHUB_TOKEN + - composer install + - cp Resources/test/Fixtures/App/config/parameters.gitlab-ci.yml Tests/Fixtures/App/config/parameters.yml + - php Resources/test/Fixtures/App/console --env=test cache:warmup + - php Resources/test/Fixtures/App/console doctrine:migrations:migrate --env=test --no-interaction + - php Resources/test/Fixtures/App/console doctrine:fixtures:load --env=test --no-interaction + + +stages: + - build-doc + - deploy-doc + - test + - deploy + + + + +test:php-5.6: + stage: test + <<: *test_definition + image: chill/ci-image:php-5.6 + script: phpunit + +test:php-7: + stage: test + <<: *test_definition + image: chill/ci-image:php-7 + script: phpunit + +# deploy documentation +api-doc-build: + stage: build-doc + environment: api-doc + image: chill/ci-image:php-7 + before_script: + - mkdir api-doc + script: apigen generate --destination api-doc/$CI_PROJECT_NAME/$CI_BUILD_REF_NAME + artifacts: + paths: + - "api-doc/" + name: api + expire_in: '2h' + only: + - master + - tags + +deploy-packagist: + stage: deploy + image: chill/ci-image:php-7 + before_script: + # test that PACKAGIST USERNAME and PACKAGIST_TOKEN variable are set + - if [ -z ${PACKAGIST_USERNAME+x} ]; then echo "Please set PACKAGIST_USERNAME variable"; exit -1; fi + - if [ -z ${PACKAGIST_TOKEN+x} ]; then echo "Please set PACKAGIST_TOKEN variable"; exit -1; fi + script: + - STATUSCODE=$(curl -XPOST -H'content-type:application/json' "https://packagist.org/api/update-package?username=$PACKAGIST_USERNAME&apiToken=$PACKAGIST_TOKEN" -d"{\"repository\":{\"url\":\"$CI_PROJECT_URL.git\"}}" --silent --output /dev/stderr --write-out "%{http_code}") + - if [ $STATUSCODE = "202" ]; then exit 0; else exit $STATUSCODE; fi From a8115853308c52fc395d72eed76060974b45b193 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Sun, 20 Nov 2016 22:49:38 +0100 Subject: [PATCH 63/73] adding phpdoc --- phpdoc.dist.xml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 phpdoc.dist.xml diff --git a/phpdoc.dist.xml b/phpdoc.dist.xml new file mode 100644 index 000000000..30c71f606 --- /dev/null +++ b/phpdoc.dist.xml @@ -0,0 +1,15 @@ + + + + data/output + Chill\MainBundle + + + data/output + + + . + Tests/Fixtures/App/AppKernel.php + Resources/test/* + + From cb4396b6d16b01654c7a9f77862eb67a4d4c9928 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Sun, 20 Nov 2016 22:54:50 +0100 Subject: [PATCH 64/73] replacing phpDocumentor by apigen --- apigen.neon | 12 ++++++++++++ phpdoc.dist.xml | 15 --------------- 2 files changed, 12 insertions(+), 15 deletions(-) create mode 100644 apigen.neon delete mode 100644 phpdoc.dist.xml diff --git a/apigen.neon b/apigen.neon new file mode 100644 index 000000000..e651150f6 --- /dev/null +++ b/apigen.neon @@ -0,0 +1,12 @@ +# configuration for apigen + + +source: + - . + +exclude: + - vendor/* + - Resource/test/* + +title: Chill EventBundle + diff --git a/phpdoc.dist.xml b/phpdoc.dist.xml deleted file mode 100644 index 30c71f606..000000000 --- a/phpdoc.dist.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - data/output - Chill\MainBundle - - - data/output - - - . - Tests/Fixtures/App/AppKernel.php - Resources/test/* - - From 209aa24866e7be33832d11cdd449f6dc0e1b29c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Sun, 20 Nov 2016 23:03:19 +0100 Subject: [PATCH 65/73] fixing error in CI before_secript --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 36433bea7..7d6e38953 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,7 +4,7 @@ before_script: - composer config github-oauth.github.com $GITHUB_TOKEN - composer install - - cp Resources/test/Fixtures/App/config/parameters.gitlab-ci.yml Tests/Fixtures/App/config/parameters.yml + - cp Resources/test/Fixtures/App/config/parameters.gitlab-ci.yml Resources/test/Fixtures/App/config/parameters.yml - php Resources/test/Fixtures/App/console --env=test cache:warmup - php Resources/test/Fixtures/App/console doctrine:migrations:migrate --env=test --no-interaction - php Resources/test/Fixtures/App/console doctrine:fixtures:load --env=test --no-interaction From 8e6f2d4355543f93710f1d1bf6c2db29ab3f5f81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 21 Nov 2016 22:36:02 +0100 Subject: [PATCH 66/73] fix tests --- Tests/Search/EventSearchTest.php | 176 ++++++++++++++++++++++++++----- 1 file changed, 149 insertions(+), 27 deletions(-) diff --git a/Tests/Search/EventSearchTest.php b/Tests/Search/EventSearchTest.php index ab5e732c9..bb31a7bfa 100644 --- a/Tests/Search/EventSearchTest.php +++ b/Tests/Search/EventSearchTest.php @@ -167,7 +167,7 @@ class EventSearchTest extends WebTestCase 'q' => '@events' )); - $this->assertGreaterThan(2, $crawler->filter('table.events tr')->count(), + $this->assertGreaterThanOrEqual(2, $crawler->filter('table.events tr')->count(), 'assert than more than 2 tr are present'); } @@ -205,49 +205,171 @@ class EventSearchTest extends WebTestCase 'assert that the word "printemps" is present'); } - public function testSearchByDate() + public function testSearchByDateDateFromOnly() { // search with date from $crawler = $this->client->request('GET', '/fr/search', array( 'q' => '@events date-from:2016-05-30' )); + /* @var $dateFrom \DateTime the date from in DateTime */ + $dateFrom = \DateTime::createFromFormat("Y-m-d", "2016-05-30"); - $this->assertEquals( - 1, - $crawler->filter('tr:contains("Printemps")')->count(), - 'assert that the word "printemps" is present'); - $this->assertEquals( - 1, - $crawler->filter('tr:contains("Hiver")')->count(), - 'assert that the word "Hiver" is present'); + $dates = $this->iterateOnRowsToFindDate($crawler->filter("tr")); + foreach($dates as $date) { + $this->assertGreaterThanOrEqual($dateFrom, $date); + } + + // click on link "Voir tous les résultats" + $crawlerAllResults = $this->client->click($crawler + ->selectLink("Voir tous les résultats")->link()); + $dates = $this->iterateOnRowsToFindDate($crawlerAllResults->filter("tr")); + + foreach ($dates as $date) { + $this->assertGreaterThanOrEqual($dateFrom, $date); + } + + //iterate on pagination + $crawlerAllResults->filter(".pagination a")->each(function($a, $i) use ($dateFrom) { + $page = $this->client->click($a->link()); + $dates = $this->iterateOnRowsToFindDate($page->filter("tr")); + + foreach($dates as $date) { + $this->assertGreaterThanOrEqual($dateFrom, $date); + } + }); + } + + public function testSearchByDateDateBetween() + { // serach with date from **and** date-to $crawler = $this->client->request('GET', '/fr/search', array( 'q' => '@events date-from:2016-05-30 date-to:2016-06-20' )); - - $this->assertEquals( - 1, - $crawler->filter('tr:contains("Printemps")')->count(), - 'assert that the word "printemps" is present'); - $this->assertEquals( - 0, - $crawler->filter('tr:contains("Hiver")')->count(), - 'assert that the word "Hiver" is not present'); + + /* @var $dateFrom \DateTime the date from in DateTime */ + $dateFrom = \DateTime::createFromFormat("Y-m-d", "2016-05-30"); + $dateTo = \DateTime::createFromFormat("Y-m-d", "2016-06-20"); + + $dates = $this->iterateOnRowsToFindDate($crawler->filter("tr")); + + foreach($dates as $date) { + $this->assertGreaterThanOrEqual($dateFrom, $date); + $this->assertLessThanOrEqual($dateTo, $date); + } + + // there should not have any other results, but if any other bundle + // add some other event, we go on next pages + + if ($crawler->selectLink("Voir tous les résultats")->count() == 0) { + return ; + } + + // click on link "Voir tous les résultats" + $crawlerAllResults = $this->client->click($crawler + ->selectLink("Voir tous les résultats")->link()); + $dates = $this->iterateOnRowsToFindDate($crawlerAllResults->filter("tr")); + + foreach ($dates as $date) { + $this->assertGreaterThanOrEqual($dateFrom, $date); + $this->assertLessThanOrEqual($dateTo, $date); + } + + //iterate on pagination + $crawlerAllResults->filter(".pagination a")->each(function($a, $i) use ($dateFrom) { + $page = $this->client->click($a->link()); + $dates = $this->iterateOnRowsToFindDate($page->filter("tr")); + + foreach($dates as $date) { + $this->assertGreaterThanOrEqual($dateFrom, $date); + $this->assertLessThanOrEqual($dateTo, $date); + } + }); + } + + public function testSearchByDateDateTo() + { // serach with date from **and** date-to $crawler = $this->client->request('GET', '/fr/search', array( 'q' => '@events date:2016-05-30' )); - $this->assertEquals( - 1, - $crawler->filter('tr:contains("Printemps")')->count(), - 'assert that the word "printemps" is present'); - $this->assertEquals( - 0, - $crawler->filter('tr:contains("Hiver")')->count(), - 'assert that the word "Hiver" is not present'); + /* @var $dateFrom \DateTime the date from in DateTime */ + $dateTo = \DateTime::createFromFormat("Y-m-d", "2016-05-30"); + + $dates = $this->iterateOnRowsToFindDate($crawler->filter("tr")); + + foreach($dates as $date) { + $this->assertLessThanOrEqual($dateTo, $date); + } + + if ($crawler->selectLink("Voir tous les résultats")->count() == 0) { + return ; + } + + // click on link "Voir tous les résultats" + $crawlerAllResults = $this->client->click($crawler + ->selectLink("Voir tous les résultats")->link()); + $dates = $this->iterateOnRowsToFindDate($crawlerAllResults->filter("tr")); + + foreach ($dates as $date) { + $this->assertLessThanOrEqual($dateTo, $date); + } + + //iterate on pagination + $crawlerAllResults->filter(".pagination a")->each(function($a, $i) use ($dateFrom) { + $page = $this->client->click($a->link()); + $dates = $this->iterateOnRowsToFindDate($page->filter("tr")); + + foreach($dates as $date) { + $this->assertLessThanOrEqual($dateTo, $date); + } + }); + + } + + /** + * this function iterate on row from results of events and return the content + * of the second column (which should contains the date) in DateTime objects + * + * @param \Symfony\Component\DomCrawler\Crawler $trs + * @return \DateTime[] + */ + private function iterateOnRowsToFindDate(\Symfony\Component\DomCrawler\Crawler $trs) + { + $months = array( + "janvier" => 1, + "février" => 2, + "mars" => 3, + "avril" => 4, + "mai" => 5, + "juin" => 6, + "juillet" => 7, + "août" => 8, + "septembre" => 9, + "octobre" => 10, + "novembre" => 11, + "décembre" => 12 + ); + + + $results = $trs->each(function($tr, $i) use ($months) { + // we skip the first row + if ($i > 0) { + // get the second node, which should contains a date + $tdDate = $tr->filter("td")->eq(1); + // transform the date, which should be in french, into a DateTime object + $parts = explode(" ", $tdDate->text()); + return \DateTime::createFromFormat("Y-m-d", $parts[2]. + "-".$months[$parts[1]]."-".$parts[0]); + } + }); + + // remove the first row + unset($results[0]); + + return $results; } /** From 7763bddc8004aefac6b387584dddcdc3316aada4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 14 Dec 2016 16:20:55 +0100 Subject: [PATCH 67/73] adding deploy doc stage --- .gitlab-ci.yml | 28 +++++++++++++++------------- apigen.neon | 2 +- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7d6e38953..45154b95a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -11,10 +11,10 @@ stages: - - build-doc - - deploy-doc - test - deploy + - build-doc + - deploy-doc @@ -31,6 +31,18 @@ test:php-7: image: chill/ci-image:php-7 script: phpunit + +deploy-packagist: + stage: deploy + image: chill/ci-image:php-7 + before_script: + # test that PACKAGIST USERNAME and PACKAGIST_TOKEN variable are set + - if [ -z ${PACKAGIST_USERNAME+x} ]; then echo "Please set PACKAGIST_USERNAME variable"; exit -1; fi + - if [ -z ${PACKAGIST_TOKEN+x} ]; then echo "Please set PACKAGIST_TOKEN variable"; exit -1; fi + script: + - STATUSCODE=$(curl -XPOST -H'content-type:application/json' "https://packagist.org/api/update-package?username=$PACKAGIST_USERNAME&apiToken=$PACKAGIST_TOKEN" -d"{\"repository\":{\"url\":\"$CI_PROJECT_URL.git\"}}" --silent --output /dev/stderr --write-out "%{http_code}") + - if [ $STATUSCODE = "202" ]; then exit 0; else exit $STATUSCODE; fi + # deploy documentation api-doc-build: stage: build-doc @@ -47,14 +59,4 @@ api-doc-build: only: - master - tags - -deploy-packagist: - stage: deploy - image: chill/ci-image:php-7 - before_script: - # test that PACKAGIST USERNAME and PACKAGIST_TOKEN variable are set - - if [ -z ${PACKAGIST_USERNAME+x} ]; then echo "Please set PACKAGIST_USERNAME variable"; exit -1; fi - - if [ -z ${PACKAGIST_TOKEN+x} ]; then echo "Please set PACKAGIST_TOKEN variable"; exit -1; fi - script: - - STATUSCODE=$(curl -XPOST -H'content-type:application/json' "https://packagist.org/api/update-package?username=$PACKAGIST_USERNAME&apiToken=$PACKAGIST_TOKEN" -d"{\"repository\":{\"url\":\"$CI_PROJECT_URL.git\"}}" --silent --output /dev/stderr --write-out "%{http_code}") - - if [ $STATUSCODE = "202" ]; then exit 0; else exit $STATUSCODE; fi + diff --git a/apigen.neon b/apigen.neon index e651150f6..7b4c4afc0 100644 --- a/apigen.neon +++ b/apigen.neon @@ -6,7 +6,7 @@ source: exclude: - vendor/* - - Resource/test/* + - Resources/test/* title: Chill EventBundle From 98b6174cd212b359849cc9eb9c577f1cdb8f0d0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 14 Dec 2016 16:27:42 +0100 Subject: [PATCH 68/73] fixing deploy-doc stage --- .gitlab-ci.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 45154b95a..a84bc1602 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -60,3 +60,16 @@ api-doc-build: - master - tags +api-doc-deploy: + stage: deploy-doc + image: pallet/swiftclient:latest + before_script: + # test that CONTAINER_API variable is set + - if [ -z ${CONTAINER_API+x} ]; then echo "Please set CONTAINER_API variable"; exit -1; fi + # go to api-doc to have and url with PROJECT/BUILD + - cd api-doc + # upload, and keep files during 1 year + script: "swift upload --header \"X-Delete-After: 31536000\" $CONTAINER_API $CI_BUILD_REF_NAME/$CI_PROJECT_NAME" + only: + - master + - tags From 7a6b2c3fe7af2f5659cbf44386862b9e2628f7f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 14 Dec 2016 16:36:34 +0100 Subject: [PATCH 69/73] fixing path in deploy-doc stage --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a84bc1602..183d218e6 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -50,7 +50,7 @@ api-doc-build: image: chill/ci-image:php-7 before_script: - mkdir api-doc - script: apigen generate --destination api-doc/$CI_PROJECT_NAME/$CI_BUILD_REF_NAME + script: apigen generate --destination api-doc/$CI_BUILD_REF_NAME/$CI_PROJECT_NAME artifacts: paths: - "api-doc/" From 6eef0fcf88915bbd60b2efe28a1e6c065499eb21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Sun, 18 Dec 2016 22:46:18 +0100 Subject: [PATCH 70/73] removing memory limit on composer install --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 183d218e6..ffd3e3a9f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,7 +3,7 @@ - chill/database:latest before_script: - composer config github-oauth.github.com $GITHUB_TOKEN - - composer install + - php -d memory_limit=-1 /usr/local/bin/composer install - cp Resources/test/Fixtures/App/config/parameters.gitlab-ci.yml Resources/test/Fixtures/App/config/parameters.yml - php Resources/test/Fixtures/App/console --env=test cache:warmup - php Resources/test/Fixtures/App/console doctrine:migrations:migrate --env=test --no-interaction From 21974a048e0ebce1996164f39b09fcfac2eabf1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 19 Apr 2017 21:43:42 +0200 Subject: [PATCH 71/73] fix translation and add role hierarchy --- Resources/translations/messages.fr.yml | 7 +++++++ Security/Authorization/EventVoter.php | 10 ++++++++-- Security/Authorization/ParticipationVoter.php | 9 +++++++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Resources/translations/messages.fr.yml b/Resources/translations/messages.fr.yml index 0a38cf10b..d2b2d533c 100644 --- a/Resources/translations/messages.fr.yml +++ b/Resources/translations/messages.fr.yml @@ -42,3 +42,10 @@ The participations were created: Les participations ont été créées #search Event search: Recherche d'événements '%total% events match the search %pattern%' : '{0} Aucun événement ne correspond aux termes de recherche "%pattern%" | {1} Un événement a été trouvé par la recherche "%pattern%" | ]1,Inf] %total% événements correspondent aux termes de recherche "%pattern%".' + +CHILL_EVENT_UPDATE: Modifier un événement +CHILL_EVENT_CREATE: Créer un événement +CHILL_EVENT_PARTICIPATION_CREATE: Créer une participation à un événement +CHILL_EVENT_PARTICIPATION_UPDATE: Modifier une participation à un événement +CHILL_EVENT_SEE: Voir un événement +CHILL_EVENT_SEE_DETAILS: Voir les détails d'un événement diff --git a/Security/Authorization/EventVoter.php b/Security/Authorization/EventVoter.php index dc7a63971..8f74e649a 100644 --- a/Security/Authorization/EventVoter.php +++ b/Security/Authorization/EventVoter.php @@ -5,7 +5,7 @@ namespace Chill\EventBundle\Security\Authorization; use Chill\MainBundle\Security\Authorization\AbstractChillVoter; -use Chill\MainBundle\Security\ProvideRoleInterface; +use Chill\MainBundle\Security\ProvideRoleHierarchyInterface; use Chill\EventBundle\Entity\Event; use Chill\MainBundle\Security\Authorization\AuthorizationHelper; use Chill\MainBundle\Entity\User; @@ -16,7 +16,7 @@ use Chill\MainBundle\Entity\User; * @author Julien Fastré * @author Champs Libres */ -class EventVoter extends AbstractChillVoter implements ProvideRoleInterface +class EventVoter extends AbstractChillVoter implements ProvideRoleHierarchyInterface { const SEE = 'CHILL_EVENT_SEE'; @@ -60,5 +60,11 @@ class EventVoter extends AbstractChillVoter implements ProvideRoleInterface { return null; } + + + public function getRolesWithHierarchy() + { + return [ 'Event' => $this->getRoles() ]; + } } diff --git a/Security/Authorization/ParticipationVoter.php b/Security/Authorization/ParticipationVoter.php index e8ba27548..385796a71 100644 --- a/Security/Authorization/ParticipationVoter.php +++ b/Security/Authorization/ParticipationVoter.php @@ -19,7 +19,7 @@ namespace Chill\EventBundle\Security\Authorization; -use Chill\MainBundle\Security\ProvideRoleInterface; +use Chill\MainBundle\Security\ProvideRoleHierarchyInterface; use Chill\MainBundle\Security\Authorization\AbstractChillVoter; use Chill\MainBundle\Security\Authorization\AuthorizationHelper; use Chill\EventBundle\Entity\Participation; @@ -30,7 +30,7 @@ use Chill\MainBundle\Entity\User; * * @author Julien Fastré */ -class ParticipationVoter extends AbstractChillVoter implements ProvideRoleInterface +class ParticipationVoter extends AbstractChillVoter implements ProvideRoleHierarchyInterface { /** * @@ -78,5 +78,10 @@ class ParticipationVoter extends AbstractChillVoter implements ProvideRoleInterf { return null; } + + public function getRolesWithHierarchy() + { + return [ 'Event' => $this->getRoles() ]; + } } From f0c145f1be58b3fbe4ef9e61d91807cc240ec0d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 19 Apr 2017 21:43:54 +0200 Subject: [PATCH 72/73] allow dev packages and prefer-stable --- composer.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 14fc5af95..0a887a2d0 100644 --- a/composer.json +++ b/composer.json @@ -57,5 +57,7 @@ }, "extra": { "app-migrations-dir": "Resources/test/Fixtures/App/DoctrineMigrations" - } + }, + "minimum-stability": "dev", + "prefer-stable": true } From 8cc95fb4280c46d83096f8a0daabf9e4e82e6673 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 18 Mar 2021 12:46:40 +0100 Subject: [PATCH 73/73] Prepare for moving into monorepo --- .gitignore => src/Bundle/ChillEvent/.gitignore | 0 .gitlab-ci.yml => src/Bundle/ChillEvent/.gitlab-ci.yml | 0 .../Bundle/ChillEvent/ChillEventBundle.php | 0 .../Bundle/ChillEvent/Controller}/EventController.php | 0 .../Bundle/ChillEvent/Controller}/EventTypeController.php | 0 .../Bundle/ChillEvent/Controller}/ParticipationController.php | 0 .../Bundle/ChillEvent/Controller}/RoleController.php | 0 .../Bundle/ChillEvent/Controller}/StatusController.php | 0 .../Bundle/ChillEvent/DataFixtures}/ORM/LoadEventTypes.php | 0 .../Bundle/ChillEvent/DataFixtures}/ORM/LoadParticipation.php | 0 .../Bundle/ChillEvent/DataFixtures}/ORM/LoadRolesACL.php | 0 .../ChillEvent/DependencyInjection}/ChillEventExtension.php | 0 .../Bundle/ChillEvent/DependencyInjection}/Configuration.php | 0 {Entity => src/Bundle/ChillEvent/Entity}/Event.php | 0 {Entity => src/Bundle/ChillEvent/Entity}/EventType.php | 0 {Entity => src/Bundle/ChillEvent/Entity}/Participation.php | 0 {Entity => src/Bundle/ChillEvent/Entity}/Role.php | 0 {Entity => src/Bundle/ChillEvent/Entity}/Status.php | 0 {Form => src/Bundle/ChillEvent/Form}/EventType.php | 0 {Form => src/Bundle/ChillEvent/Form}/EventTypeType.php | 0 {Form => src/Bundle/ChillEvent/Form}/ParticipationType.php | 0 {Form => src/Bundle/ChillEvent/Form}/RoleType.php | 0 {Form => src/Bundle/ChillEvent/Form}/StatusType.php | 0 {Form => src/Bundle/ChillEvent/Form}/Type/PickEventType.php | 0 {Form => src/Bundle/ChillEvent/Form}/Type/PickRoleType.php | 0 {Form => src/Bundle/ChillEvent/Form}/Type/PickStatusType.php | 0 LICENSE.txt => src/Bundle/ChillEvent/LICENSE.txt | 0 README.md => src/Bundle/ChillEvent/README.md | 0 .../Bundle/ChillEvent/Resources}/config/doctrine/Event.orm.yml | 0 .../ChillEvent/Resources}/config/doctrine/EventType.orm.yml | 0 .../ChillEvent/Resources}/config/doctrine/Participation.orm.yml | 0 .../Bundle/ChillEvent/Resources}/config/doctrine/Role.orm.yml | 0 .../Bundle/ChillEvent/Resources}/config/doctrine/Status.orm.yml | 0 {Resources => src/Bundle/ChillEvent/Resources}/config/routing.yml | 0 .../Bundle/ChillEvent/Resources}/config/routing/event.yml | 0 .../Bundle/ChillEvent/Resources}/config/routing/eventtype.yml | 0 .../Bundle/ChillEvent/Resources}/config/routing/participation.yml | 0 .../Bundle/ChillEvent/Resources}/config/routing/role.yml | 0 .../Bundle/ChillEvent/Resources}/config/routing/status.yml | 0 .../ChillEvent/Resources}/config/services/authorization.yml | 0 .../Bundle/ChillEvent/Resources}/config/services/forms.yml | 0 .../Bundle/ChillEvent/Resources}/config/services/repositories.yml | 0 .../Bundle/ChillEvent/Resources}/config/services/search.yml | 0 .../Bundle/ChillEvent/Resources}/config/validation.yml | 0 .../ChillEvent/Resources}/migrations/Version20160318111334.php | 0 .../Bundle/ChillEvent/Resources}/test/Fixtures/App/AppKernel.php | 0 .../ChillEvent/Resources}/test/Fixtures/App/config/config.yml | 0 .../Resources}/test/Fixtures/App/config/config_test.yml | 0 .../Resources}/test/Fixtures/App/config/parameters.gitlab-ci.yml | 0 .../ChillEvent/Resources}/test/Fixtures/App/config/parameters.yml | 0 .../Resources}/test/Fixtures/App/config/parameters.yml.dist | 0 .../ChillEvent/Resources}/test/Fixtures/App/config/routing.yml | 0 .../Bundle/ChillEvent/Resources}/test/Fixtures/App/console | 0 {Resources => src/Bundle/ChillEvent/Resources}/test/bootstrap.php | 0 .../Bundle/ChillEvent/Resources}/translations/messages.fr.yml | 0 .../Bundle/ChillEvent/Resources}/views/Event/edit.html.twig | 0 .../Bundle/ChillEvent/Resources}/views/Event/index.html.twig | 0 .../Bundle/ChillEvent/Resources}/views/Event/list.html.twig | 0 .../Bundle/ChillEvent/Resources}/views/Event/new.html.twig | 0 .../Bundle/ChillEvent/Resources}/views/Event/show.html.twig | 0 .../Bundle/ChillEvent/Resources}/views/EventType/edit.html.twig | 0 .../Bundle/ChillEvent/Resources}/views/EventType/index.html.twig | 0 .../Bundle/ChillEvent/Resources}/views/EventType/new.html.twig | 0 .../Bundle/ChillEvent/Resources}/views/EventType/show.html.twig | 0 .../views/Participation/_ignored_participations.html.twig | 0 .../Resources}/views/Participation/edit-multiple.html.twig | 0 .../ChillEvent/Resources}/views/Participation/edit.html.twig | 0 .../Resources}/views/Participation/new-multiple.html.twig | 0 .../ChillEvent/Resources}/views/Participation/new.html.twig | 0 .../Bundle/ChillEvent/Resources}/views/Role/edit.html.twig | 0 .../Bundle/ChillEvent/Resources}/views/Role/index.html.twig | 0 .../Bundle/ChillEvent/Resources}/views/Role/new.html.twig | 0 .../Bundle/ChillEvent/Resources}/views/Role/show.html.twig | 0 .../Bundle/ChillEvent/Resources}/views/Status/edit.html.twig | 0 .../Bundle/ChillEvent/Resources}/views/Status/index.html.twig | 0 .../Bundle/ChillEvent/Resources}/views/Status/new.html.twig | 0 .../Bundle/ChillEvent/Resources}/views/Status/show.html.twig | 0 .../Bundle/ChillEvent/Resources}/views/layout.html.twig | 0 {Search => src/Bundle/ChillEvent/Search}/EventSearch.php | 0 .../Bundle/ChillEvent/Security}/Authorization/EventVoter.php | 0 .../ChillEvent/Security}/Authorization/ParticipationVoter.php | 0 .../Bundle/ChillEvent/Tests}/Controller/EventControllerTest.php | 0 .../ChillEvent/Tests}/Controller/EventTypeControllerTest.php | 0 .../ChillEvent/Tests}/Controller/ParticipationControllerTest.php | 0 .../Bundle/ChillEvent/Tests}/Controller/RoleControllerTest.php | 0 .../Bundle/ChillEvent/Tests}/Controller/StatusControllerTest.php | 0 {Tests => src/Bundle/ChillEvent/Tests}/Search/EventSearchTest.php | 0 apigen.neon => src/Bundle/ChillEvent/apigen.neon | 0 composer.json => src/Bundle/ChillEvent/composer.json | 0 phpunit.xml.dist => src/Bundle/ChillEvent/phpunit.xml.dist | 0 90 files changed, 0 insertions(+), 0 deletions(-) rename .gitignore => src/Bundle/ChillEvent/.gitignore (100%) rename .gitlab-ci.yml => src/Bundle/ChillEvent/.gitlab-ci.yml (100%) rename ChillEventBundle.php => src/Bundle/ChillEvent/ChillEventBundle.php (100%) rename {Controller => src/Bundle/ChillEvent/Controller}/EventController.php (100%) rename {Controller => src/Bundle/ChillEvent/Controller}/EventTypeController.php (100%) rename {Controller => src/Bundle/ChillEvent/Controller}/ParticipationController.php (100%) rename {Controller => src/Bundle/ChillEvent/Controller}/RoleController.php (100%) rename {Controller => src/Bundle/ChillEvent/Controller}/StatusController.php (100%) rename {DataFixtures => src/Bundle/ChillEvent/DataFixtures}/ORM/LoadEventTypes.php (100%) rename {DataFixtures => src/Bundle/ChillEvent/DataFixtures}/ORM/LoadParticipation.php (100%) rename {DataFixtures => src/Bundle/ChillEvent/DataFixtures}/ORM/LoadRolesACL.php (100%) rename {DependencyInjection => src/Bundle/ChillEvent/DependencyInjection}/ChillEventExtension.php (100%) rename {DependencyInjection => src/Bundle/ChillEvent/DependencyInjection}/Configuration.php (100%) rename {Entity => src/Bundle/ChillEvent/Entity}/Event.php (100%) rename {Entity => src/Bundle/ChillEvent/Entity}/EventType.php (100%) rename {Entity => src/Bundle/ChillEvent/Entity}/Participation.php (100%) rename {Entity => src/Bundle/ChillEvent/Entity}/Role.php (100%) rename {Entity => src/Bundle/ChillEvent/Entity}/Status.php (100%) rename {Form => src/Bundle/ChillEvent/Form}/EventType.php (100%) rename {Form => src/Bundle/ChillEvent/Form}/EventTypeType.php (100%) rename {Form => src/Bundle/ChillEvent/Form}/ParticipationType.php (100%) rename {Form => src/Bundle/ChillEvent/Form}/RoleType.php (100%) rename {Form => src/Bundle/ChillEvent/Form}/StatusType.php (100%) rename {Form => src/Bundle/ChillEvent/Form}/Type/PickEventType.php (100%) rename {Form => src/Bundle/ChillEvent/Form}/Type/PickRoleType.php (100%) rename {Form => src/Bundle/ChillEvent/Form}/Type/PickStatusType.php (100%) rename LICENSE.txt => src/Bundle/ChillEvent/LICENSE.txt (100%) rename README.md => src/Bundle/ChillEvent/README.md (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/config/doctrine/Event.orm.yml (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/config/doctrine/EventType.orm.yml (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/config/doctrine/Participation.orm.yml (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/config/doctrine/Role.orm.yml (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/config/doctrine/Status.orm.yml (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/config/routing.yml (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/config/routing/event.yml (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/config/routing/eventtype.yml (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/config/routing/participation.yml (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/config/routing/role.yml (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/config/routing/status.yml (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/config/services/authorization.yml (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/config/services/forms.yml (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/config/services/repositories.yml (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/config/services/search.yml (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/config/validation.yml (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/migrations/Version20160318111334.php (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/test/Fixtures/App/AppKernel.php (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/test/Fixtures/App/config/config.yml (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/test/Fixtures/App/config/config_test.yml (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/test/Fixtures/App/config/parameters.gitlab-ci.yml (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/test/Fixtures/App/config/parameters.yml (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/test/Fixtures/App/config/parameters.yml.dist (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/test/Fixtures/App/config/routing.yml (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/test/Fixtures/App/console (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/test/bootstrap.php (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/translations/messages.fr.yml (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/views/Event/edit.html.twig (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/views/Event/index.html.twig (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/views/Event/list.html.twig (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/views/Event/new.html.twig (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/views/Event/show.html.twig (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/views/EventType/edit.html.twig (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/views/EventType/index.html.twig (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/views/EventType/new.html.twig (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/views/EventType/show.html.twig (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/views/Participation/_ignored_participations.html.twig (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/views/Participation/edit-multiple.html.twig (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/views/Participation/edit.html.twig (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/views/Participation/new-multiple.html.twig (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/views/Participation/new.html.twig (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/views/Role/edit.html.twig (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/views/Role/index.html.twig (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/views/Role/new.html.twig (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/views/Role/show.html.twig (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/views/Status/edit.html.twig (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/views/Status/index.html.twig (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/views/Status/new.html.twig (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/views/Status/show.html.twig (100%) rename {Resources => src/Bundle/ChillEvent/Resources}/views/layout.html.twig (100%) rename {Search => src/Bundle/ChillEvent/Search}/EventSearch.php (100%) rename {Security => src/Bundle/ChillEvent/Security}/Authorization/EventVoter.php (100%) rename {Security => src/Bundle/ChillEvent/Security}/Authorization/ParticipationVoter.php (100%) rename {Tests => src/Bundle/ChillEvent/Tests}/Controller/EventControllerTest.php (100%) rename {Tests => src/Bundle/ChillEvent/Tests}/Controller/EventTypeControllerTest.php (100%) rename {Tests => src/Bundle/ChillEvent/Tests}/Controller/ParticipationControllerTest.php (100%) rename {Tests => src/Bundle/ChillEvent/Tests}/Controller/RoleControllerTest.php (100%) rename {Tests => src/Bundle/ChillEvent/Tests}/Controller/StatusControllerTest.php (100%) rename {Tests => src/Bundle/ChillEvent/Tests}/Search/EventSearchTest.php (100%) rename apigen.neon => src/Bundle/ChillEvent/apigen.neon (100%) rename composer.json => src/Bundle/ChillEvent/composer.json (100%) rename phpunit.xml.dist => src/Bundle/ChillEvent/phpunit.xml.dist (100%) diff --git a/.gitignore b/src/Bundle/ChillEvent/.gitignore similarity index 100% rename from .gitignore rename to src/Bundle/ChillEvent/.gitignore diff --git a/.gitlab-ci.yml b/src/Bundle/ChillEvent/.gitlab-ci.yml similarity index 100% rename from .gitlab-ci.yml rename to src/Bundle/ChillEvent/.gitlab-ci.yml diff --git a/ChillEventBundle.php b/src/Bundle/ChillEvent/ChillEventBundle.php similarity index 100% rename from ChillEventBundle.php rename to src/Bundle/ChillEvent/ChillEventBundle.php diff --git a/Controller/EventController.php b/src/Bundle/ChillEvent/Controller/EventController.php similarity index 100% rename from Controller/EventController.php rename to src/Bundle/ChillEvent/Controller/EventController.php diff --git a/Controller/EventTypeController.php b/src/Bundle/ChillEvent/Controller/EventTypeController.php similarity index 100% rename from Controller/EventTypeController.php rename to src/Bundle/ChillEvent/Controller/EventTypeController.php diff --git a/Controller/ParticipationController.php b/src/Bundle/ChillEvent/Controller/ParticipationController.php similarity index 100% rename from Controller/ParticipationController.php rename to src/Bundle/ChillEvent/Controller/ParticipationController.php diff --git a/Controller/RoleController.php b/src/Bundle/ChillEvent/Controller/RoleController.php similarity index 100% rename from Controller/RoleController.php rename to src/Bundle/ChillEvent/Controller/RoleController.php diff --git a/Controller/StatusController.php b/src/Bundle/ChillEvent/Controller/StatusController.php similarity index 100% rename from Controller/StatusController.php rename to src/Bundle/ChillEvent/Controller/StatusController.php diff --git a/DataFixtures/ORM/LoadEventTypes.php b/src/Bundle/ChillEvent/DataFixtures/ORM/LoadEventTypes.php similarity index 100% rename from DataFixtures/ORM/LoadEventTypes.php rename to src/Bundle/ChillEvent/DataFixtures/ORM/LoadEventTypes.php diff --git a/DataFixtures/ORM/LoadParticipation.php b/src/Bundle/ChillEvent/DataFixtures/ORM/LoadParticipation.php similarity index 100% rename from DataFixtures/ORM/LoadParticipation.php rename to src/Bundle/ChillEvent/DataFixtures/ORM/LoadParticipation.php diff --git a/DataFixtures/ORM/LoadRolesACL.php b/src/Bundle/ChillEvent/DataFixtures/ORM/LoadRolesACL.php similarity index 100% rename from DataFixtures/ORM/LoadRolesACL.php rename to src/Bundle/ChillEvent/DataFixtures/ORM/LoadRolesACL.php diff --git a/DependencyInjection/ChillEventExtension.php b/src/Bundle/ChillEvent/DependencyInjection/ChillEventExtension.php similarity index 100% rename from DependencyInjection/ChillEventExtension.php rename to src/Bundle/ChillEvent/DependencyInjection/ChillEventExtension.php diff --git a/DependencyInjection/Configuration.php b/src/Bundle/ChillEvent/DependencyInjection/Configuration.php similarity index 100% rename from DependencyInjection/Configuration.php rename to src/Bundle/ChillEvent/DependencyInjection/Configuration.php diff --git a/Entity/Event.php b/src/Bundle/ChillEvent/Entity/Event.php similarity index 100% rename from Entity/Event.php rename to src/Bundle/ChillEvent/Entity/Event.php diff --git a/Entity/EventType.php b/src/Bundle/ChillEvent/Entity/EventType.php similarity index 100% rename from Entity/EventType.php rename to src/Bundle/ChillEvent/Entity/EventType.php diff --git a/Entity/Participation.php b/src/Bundle/ChillEvent/Entity/Participation.php similarity index 100% rename from Entity/Participation.php rename to src/Bundle/ChillEvent/Entity/Participation.php diff --git a/Entity/Role.php b/src/Bundle/ChillEvent/Entity/Role.php similarity index 100% rename from Entity/Role.php rename to src/Bundle/ChillEvent/Entity/Role.php diff --git a/Entity/Status.php b/src/Bundle/ChillEvent/Entity/Status.php similarity index 100% rename from Entity/Status.php rename to src/Bundle/ChillEvent/Entity/Status.php diff --git a/Form/EventType.php b/src/Bundle/ChillEvent/Form/EventType.php similarity index 100% rename from Form/EventType.php rename to src/Bundle/ChillEvent/Form/EventType.php diff --git a/Form/EventTypeType.php b/src/Bundle/ChillEvent/Form/EventTypeType.php similarity index 100% rename from Form/EventTypeType.php rename to src/Bundle/ChillEvent/Form/EventTypeType.php diff --git a/Form/ParticipationType.php b/src/Bundle/ChillEvent/Form/ParticipationType.php similarity index 100% rename from Form/ParticipationType.php rename to src/Bundle/ChillEvent/Form/ParticipationType.php diff --git a/Form/RoleType.php b/src/Bundle/ChillEvent/Form/RoleType.php similarity index 100% rename from Form/RoleType.php rename to src/Bundle/ChillEvent/Form/RoleType.php diff --git a/Form/StatusType.php b/src/Bundle/ChillEvent/Form/StatusType.php similarity index 100% rename from Form/StatusType.php rename to src/Bundle/ChillEvent/Form/StatusType.php diff --git a/Form/Type/PickEventType.php b/src/Bundle/ChillEvent/Form/Type/PickEventType.php similarity index 100% rename from Form/Type/PickEventType.php rename to src/Bundle/ChillEvent/Form/Type/PickEventType.php diff --git a/Form/Type/PickRoleType.php b/src/Bundle/ChillEvent/Form/Type/PickRoleType.php similarity index 100% rename from Form/Type/PickRoleType.php rename to src/Bundle/ChillEvent/Form/Type/PickRoleType.php diff --git a/Form/Type/PickStatusType.php b/src/Bundle/ChillEvent/Form/Type/PickStatusType.php similarity index 100% rename from Form/Type/PickStatusType.php rename to src/Bundle/ChillEvent/Form/Type/PickStatusType.php diff --git a/LICENSE.txt b/src/Bundle/ChillEvent/LICENSE.txt similarity index 100% rename from LICENSE.txt rename to src/Bundle/ChillEvent/LICENSE.txt diff --git a/README.md b/src/Bundle/ChillEvent/README.md similarity index 100% rename from README.md rename to src/Bundle/ChillEvent/README.md diff --git a/Resources/config/doctrine/Event.orm.yml b/src/Bundle/ChillEvent/Resources/config/doctrine/Event.orm.yml similarity index 100% rename from Resources/config/doctrine/Event.orm.yml rename to src/Bundle/ChillEvent/Resources/config/doctrine/Event.orm.yml diff --git a/Resources/config/doctrine/EventType.orm.yml b/src/Bundle/ChillEvent/Resources/config/doctrine/EventType.orm.yml similarity index 100% rename from Resources/config/doctrine/EventType.orm.yml rename to src/Bundle/ChillEvent/Resources/config/doctrine/EventType.orm.yml diff --git a/Resources/config/doctrine/Participation.orm.yml b/src/Bundle/ChillEvent/Resources/config/doctrine/Participation.orm.yml similarity index 100% rename from Resources/config/doctrine/Participation.orm.yml rename to src/Bundle/ChillEvent/Resources/config/doctrine/Participation.orm.yml diff --git a/Resources/config/doctrine/Role.orm.yml b/src/Bundle/ChillEvent/Resources/config/doctrine/Role.orm.yml similarity index 100% rename from Resources/config/doctrine/Role.orm.yml rename to src/Bundle/ChillEvent/Resources/config/doctrine/Role.orm.yml diff --git a/Resources/config/doctrine/Status.orm.yml b/src/Bundle/ChillEvent/Resources/config/doctrine/Status.orm.yml similarity index 100% rename from Resources/config/doctrine/Status.orm.yml rename to src/Bundle/ChillEvent/Resources/config/doctrine/Status.orm.yml diff --git a/Resources/config/routing.yml b/src/Bundle/ChillEvent/Resources/config/routing.yml similarity index 100% rename from Resources/config/routing.yml rename to src/Bundle/ChillEvent/Resources/config/routing.yml diff --git a/Resources/config/routing/event.yml b/src/Bundle/ChillEvent/Resources/config/routing/event.yml similarity index 100% rename from Resources/config/routing/event.yml rename to src/Bundle/ChillEvent/Resources/config/routing/event.yml diff --git a/Resources/config/routing/eventtype.yml b/src/Bundle/ChillEvent/Resources/config/routing/eventtype.yml similarity index 100% rename from Resources/config/routing/eventtype.yml rename to src/Bundle/ChillEvent/Resources/config/routing/eventtype.yml diff --git a/Resources/config/routing/participation.yml b/src/Bundle/ChillEvent/Resources/config/routing/participation.yml similarity index 100% rename from Resources/config/routing/participation.yml rename to src/Bundle/ChillEvent/Resources/config/routing/participation.yml diff --git a/Resources/config/routing/role.yml b/src/Bundle/ChillEvent/Resources/config/routing/role.yml similarity index 100% rename from Resources/config/routing/role.yml rename to src/Bundle/ChillEvent/Resources/config/routing/role.yml diff --git a/Resources/config/routing/status.yml b/src/Bundle/ChillEvent/Resources/config/routing/status.yml similarity index 100% rename from Resources/config/routing/status.yml rename to src/Bundle/ChillEvent/Resources/config/routing/status.yml diff --git a/Resources/config/services/authorization.yml b/src/Bundle/ChillEvent/Resources/config/services/authorization.yml similarity index 100% rename from Resources/config/services/authorization.yml rename to src/Bundle/ChillEvent/Resources/config/services/authorization.yml diff --git a/Resources/config/services/forms.yml b/src/Bundle/ChillEvent/Resources/config/services/forms.yml similarity index 100% rename from Resources/config/services/forms.yml rename to src/Bundle/ChillEvent/Resources/config/services/forms.yml diff --git a/Resources/config/services/repositories.yml b/src/Bundle/ChillEvent/Resources/config/services/repositories.yml similarity index 100% rename from Resources/config/services/repositories.yml rename to src/Bundle/ChillEvent/Resources/config/services/repositories.yml diff --git a/Resources/config/services/search.yml b/src/Bundle/ChillEvent/Resources/config/services/search.yml similarity index 100% rename from Resources/config/services/search.yml rename to src/Bundle/ChillEvent/Resources/config/services/search.yml diff --git a/Resources/config/validation.yml b/src/Bundle/ChillEvent/Resources/config/validation.yml similarity index 100% rename from Resources/config/validation.yml rename to src/Bundle/ChillEvent/Resources/config/validation.yml diff --git a/Resources/migrations/Version20160318111334.php b/src/Bundle/ChillEvent/Resources/migrations/Version20160318111334.php similarity index 100% rename from Resources/migrations/Version20160318111334.php rename to src/Bundle/ChillEvent/Resources/migrations/Version20160318111334.php diff --git a/Resources/test/Fixtures/App/AppKernel.php b/src/Bundle/ChillEvent/Resources/test/Fixtures/App/AppKernel.php similarity index 100% rename from Resources/test/Fixtures/App/AppKernel.php rename to src/Bundle/ChillEvent/Resources/test/Fixtures/App/AppKernel.php diff --git a/Resources/test/Fixtures/App/config/config.yml b/src/Bundle/ChillEvent/Resources/test/Fixtures/App/config/config.yml similarity index 100% rename from Resources/test/Fixtures/App/config/config.yml rename to src/Bundle/ChillEvent/Resources/test/Fixtures/App/config/config.yml diff --git a/Resources/test/Fixtures/App/config/config_test.yml b/src/Bundle/ChillEvent/Resources/test/Fixtures/App/config/config_test.yml similarity index 100% rename from Resources/test/Fixtures/App/config/config_test.yml rename to src/Bundle/ChillEvent/Resources/test/Fixtures/App/config/config_test.yml diff --git a/Resources/test/Fixtures/App/config/parameters.gitlab-ci.yml b/src/Bundle/ChillEvent/Resources/test/Fixtures/App/config/parameters.gitlab-ci.yml similarity index 100% rename from Resources/test/Fixtures/App/config/parameters.gitlab-ci.yml rename to src/Bundle/ChillEvent/Resources/test/Fixtures/App/config/parameters.gitlab-ci.yml diff --git a/Resources/test/Fixtures/App/config/parameters.yml b/src/Bundle/ChillEvent/Resources/test/Fixtures/App/config/parameters.yml similarity index 100% rename from Resources/test/Fixtures/App/config/parameters.yml rename to src/Bundle/ChillEvent/Resources/test/Fixtures/App/config/parameters.yml diff --git a/Resources/test/Fixtures/App/config/parameters.yml.dist b/src/Bundle/ChillEvent/Resources/test/Fixtures/App/config/parameters.yml.dist similarity index 100% rename from Resources/test/Fixtures/App/config/parameters.yml.dist rename to src/Bundle/ChillEvent/Resources/test/Fixtures/App/config/parameters.yml.dist diff --git a/Resources/test/Fixtures/App/config/routing.yml b/src/Bundle/ChillEvent/Resources/test/Fixtures/App/config/routing.yml similarity index 100% rename from Resources/test/Fixtures/App/config/routing.yml rename to src/Bundle/ChillEvent/Resources/test/Fixtures/App/config/routing.yml diff --git a/Resources/test/Fixtures/App/console b/src/Bundle/ChillEvent/Resources/test/Fixtures/App/console similarity index 100% rename from Resources/test/Fixtures/App/console rename to src/Bundle/ChillEvent/Resources/test/Fixtures/App/console diff --git a/Resources/test/bootstrap.php b/src/Bundle/ChillEvent/Resources/test/bootstrap.php similarity index 100% rename from Resources/test/bootstrap.php rename to src/Bundle/ChillEvent/Resources/test/bootstrap.php diff --git a/Resources/translations/messages.fr.yml b/src/Bundle/ChillEvent/Resources/translations/messages.fr.yml similarity index 100% rename from Resources/translations/messages.fr.yml rename to src/Bundle/ChillEvent/Resources/translations/messages.fr.yml diff --git a/Resources/views/Event/edit.html.twig b/src/Bundle/ChillEvent/Resources/views/Event/edit.html.twig similarity index 100% rename from Resources/views/Event/edit.html.twig rename to src/Bundle/ChillEvent/Resources/views/Event/edit.html.twig diff --git a/Resources/views/Event/index.html.twig b/src/Bundle/ChillEvent/Resources/views/Event/index.html.twig similarity index 100% rename from Resources/views/Event/index.html.twig rename to src/Bundle/ChillEvent/Resources/views/Event/index.html.twig diff --git a/Resources/views/Event/list.html.twig b/src/Bundle/ChillEvent/Resources/views/Event/list.html.twig similarity index 100% rename from Resources/views/Event/list.html.twig rename to src/Bundle/ChillEvent/Resources/views/Event/list.html.twig diff --git a/Resources/views/Event/new.html.twig b/src/Bundle/ChillEvent/Resources/views/Event/new.html.twig similarity index 100% rename from Resources/views/Event/new.html.twig rename to src/Bundle/ChillEvent/Resources/views/Event/new.html.twig diff --git a/Resources/views/Event/show.html.twig b/src/Bundle/ChillEvent/Resources/views/Event/show.html.twig similarity index 100% rename from Resources/views/Event/show.html.twig rename to src/Bundle/ChillEvent/Resources/views/Event/show.html.twig diff --git a/Resources/views/EventType/edit.html.twig b/src/Bundle/ChillEvent/Resources/views/EventType/edit.html.twig similarity index 100% rename from Resources/views/EventType/edit.html.twig rename to src/Bundle/ChillEvent/Resources/views/EventType/edit.html.twig diff --git a/Resources/views/EventType/index.html.twig b/src/Bundle/ChillEvent/Resources/views/EventType/index.html.twig similarity index 100% rename from Resources/views/EventType/index.html.twig rename to src/Bundle/ChillEvent/Resources/views/EventType/index.html.twig diff --git a/Resources/views/EventType/new.html.twig b/src/Bundle/ChillEvent/Resources/views/EventType/new.html.twig similarity index 100% rename from Resources/views/EventType/new.html.twig rename to src/Bundle/ChillEvent/Resources/views/EventType/new.html.twig diff --git a/Resources/views/EventType/show.html.twig b/src/Bundle/ChillEvent/Resources/views/EventType/show.html.twig similarity index 100% rename from Resources/views/EventType/show.html.twig rename to src/Bundle/ChillEvent/Resources/views/EventType/show.html.twig diff --git a/Resources/views/Participation/_ignored_participations.html.twig b/src/Bundle/ChillEvent/Resources/views/Participation/_ignored_participations.html.twig similarity index 100% rename from Resources/views/Participation/_ignored_participations.html.twig rename to src/Bundle/ChillEvent/Resources/views/Participation/_ignored_participations.html.twig diff --git a/Resources/views/Participation/edit-multiple.html.twig b/src/Bundle/ChillEvent/Resources/views/Participation/edit-multiple.html.twig similarity index 100% rename from Resources/views/Participation/edit-multiple.html.twig rename to src/Bundle/ChillEvent/Resources/views/Participation/edit-multiple.html.twig diff --git a/Resources/views/Participation/edit.html.twig b/src/Bundle/ChillEvent/Resources/views/Participation/edit.html.twig similarity index 100% rename from Resources/views/Participation/edit.html.twig rename to src/Bundle/ChillEvent/Resources/views/Participation/edit.html.twig diff --git a/Resources/views/Participation/new-multiple.html.twig b/src/Bundle/ChillEvent/Resources/views/Participation/new-multiple.html.twig similarity index 100% rename from Resources/views/Participation/new-multiple.html.twig rename to src/Bundle/ChillEvent/Resources/views/Participation/new-multiple.html.twig diff --git a/Resources/views/Participation/new.html.twig b/src/Bundle/ChillEvent/Resources/views/Participation/new.html.twig similarity index 100% rename from Resources/views/Participation/new.html.twig rename to src/Bundle/ChillEvent/Resources/views/Participation/new.html.twig diff --git a/Resources/views/Role/edit.html.twig b/src/Bundle/ChillEvent/Resources/views/Role/edit.html.twig similarity index 100% rename from Resources/views/Role/edit.html.twig rename to src/Bundle/ChillEvent/Resources/views/Role/edit.html.twig diff --git a/Resources/views/Role/index.html.twig b/src/Bundle/ChillEvent/Resources/views/Role/index.html.twig similarity index 100% rename from Resources/views/Role/index.html.twig rename to src/Bundle/ChillEvent/Resources/views/Role/index.html.twig diff --git a/Resources/views/Role/new.html.twig b/src/Bundle/ChillEvent/Resources/views/Role/new.html.twig similarity index 100% rename from Resources/views/Role/new.html.twig rename to src/Bundle/ChillEvent/Resources/views/Role/new.html.twig diff --git a/Resources/views/Role/show.html.twig b/src/Bundle/ChillEvent/Resources/views/Role/show.html.twig similarity index 100% rename from Resources/views/Role/show.html.twig rename to src/Bundle/ChillEvent/Resources/views/Role/show.html.twig diff --git a/Resources/views/Status/edit.html.twig b/src/Bundle/ChillEvent/Resources/views/Status/edit.html.twig similarity index 100% rename from Resources/views/Status/edit.html.twig rename to src/Bundle/ChillEvent/Resources/views/Status/edit.html.twig diff --git a/Resources/views/Status/index.html.twig b/src/Bundle/ChillEvent/Resources/views/Status/index.html.twig similarity index 100% rename from Resources/views/Status/index.html.twig rename to src/Bundle/ChillEvent/Resources/views/Status/index.html.twig diff --git a/Resources/views/Status/new.html.twig b/src/Bundle/ChillEvent/Resources/views/Status/new.html.twig similarity index 100% rename from Resources/views/Status/new.html.twig rename to src/Bundle/ChillEvent/Resources/views/Status/new.html.twig diff --git a/Resources/views/Status/show.html.twig b/src/Bundle/ChillEvent/Resources/views/Status/show.html.twig similarity index 100% rename from Resources/views/Status/show.html.twig rename to src/Bundle/ChillEvent/Resources/views/Status/show.html.twig diff --git a/Resources/views/layout.html.twig b/src/Bundle/ChillEvent/Resources/views/layout.html.twig similarity index 100% rename from Resources/views/layout.html.twig rename to src/Bundle/ChillEvent/Resources/views/layout.html.twig diff --git a/Search/EventSearch.php b/src/Bundle/ChillEvent/Search/EventSearch.php similarity index 100% rename from Search/EventSearch.php rename to src/Bundle/ChillEvent/Search/EventSearch.php diff --git a/Security/Authorization/EventVoter.php b/src/Bundle/ChillEvent/Security/Authorization/EventVoter.php similarity index 100% rename from Security/Authorization/EventVoter.php rename to src/Bundle/ChillEvent/Security/Authorization/EventVoter.php diff --git a/Security/Authorization/ParticipationVoter.php b/src/Bundle/ChillEvent/Security/Authorization/ParticipationVoter.php similarity index 100% rename from Security/Authorization/ParticipationVoter.php rename to src/Bundle/ChillEvent/Security/Authorization/ParticipationVoter.php diff --git a/Tests/Controller/EventControllerTest.php b/src/Bundle/ChillEvent/Tests/Controller/EventControllerTest.php similarity index 100% rename from Tests/Controller/EventControllerTest.php rename to src/Bundle/ChillEvent/Tests/Controller/EventControllerTest.php diff --git a/Tests/Controller/EventTypeControllerTest.php b/src/Bundle/ChillEvent/Tests/Controller/EventTypeControllerTest.php similarity index 100% rename from Tests/Controller/EventTypeControllerTest.php rename to src/Bundle/ChillEvent/Tests/Controller/EventTypeControllerTest.php diff --git a/Tests/Controller/ParticipationControllerTest.php b/src/Bundle/ChillEvent/Tests/Controller/ParticipationControllerTest.php similarity index 100% rename from Tests/Controller/ParticipationControllerTest.php rename to src/Bundle/ChillEvent/Tests/Controller/ParticipationControllerTest.php diff --git a/Tests/Controller/RoleControllerTest.php b/src/Bundle/ChillEvent/Tests/Controller/RoleControllerTest.php similarity index 100% rename from Tests/Controller/RoleControllerTest.php rename to src/Bundle/ChillEvent/Tests/Controller/RoleControllerTest.php diff --git a/Tests/Controller/StatusControllerTest.php b/src/Bundle/ChillEvent/Tests/Controller/StatusControllerTest.php similarity index 100% rename from Tests/Controller/StatusControllerTest.php rename to src/Bundle/ChillEvent/Tests/Controller/StatusControllerTest.php diff --git a/Tests/Search/EventSearchTest.php b/src/Bundle/ChillEvent/Tests/Search/EventSearchTest.php similarity index 100% rename from Tests/Search/EventSearchTest.php rename to src/Bundle/ChillEvent/Tests/Search/EventSearchTest.php diff --git a/apigen.neon b/src/Bundle/ChillEvent/apigen.neon similarity index 100% rename from apigen.neon rename to src/Bundle/ChillEvent/apigen.neon diff --git a/composer.json b/src/Bundle/ChillEvent/composer.json similarity index 100% rename from composer.json rename to src/Bundle/ChillEvent/composer.json diff --git a/phpunit.xml.dist b/src/Bundle/ChillEvent/phpunit.xml.dist similarity index 100% rename from phpunit.xml.dist rename to src/Bundle/ChillEvent/phpunit.xml.dist