From 979ad31d5b8584f32710df5c0141d84b6b696c41 Mon Sep 17 00:00:00 2001 From: Jeremy Guiselin <jeremy.guiselin@student.ecp.fr> Date: Mon, 19 Dec 2016 10:54:39 +0100 Subject: [PATCH] begin env prod for ansible + delete pack + add league on device --- .ansible/group_vars/app-db.yml | 4 - .ansible/group_vars/app-web.yml | 6 - .ansible/group_vars/env-dev.yml | 10 ++ .ansible/group_vars/env-prod.yml | 10 ++ .ansible/inventories/inventory_prod | 9 + .../betskills/virtualbox/synced_folders | 2 +- app/config/config.yml | 2 +- .../Controller/DefaultController.php | 30 +--- .../Controller/EntityBrowserController.php | 10 +- src/BackendBundle/Entity/LeagueOnDevice.php | 120 +++++++++++++ src/BackendBundle/Entity/Notification.php | 4 +- src/BackendBundle/Entity/Pack.php | 164 ------------------ src/BackendBundle/Form/PackType.php | 48 ----- .../Repository/PackRepository.php | 43 ----- .../views/layout/dashboard.html.twig | 1 - .../Resources/views/pack/form.html.twig | 58 ------- .../Resources/views/pack/list.html.twig | 52 ------ 17 files changed, 164 insertions(+), 409 deletions(-) create mode 100644 .ansible/group_vars/env-prod.yml create mode 100644 .ansible/inventories/inventory_prod create mode 100644 src/BackendBundle/Entity/LeagueOnDevice.php delete mode 100644 src/BackendBundle/Entity/Pack.php delete mode 100644 src/BackendBundle/Form/PackType.php delete mode 100644 src/BackendBundle/Repository/PackRepository.php delete mode 100644 src/BackendBundle/Resources/views/pack/form.html.twig delete mode 100644 src/BackendBundle/Resources/views/pack/list.html.twig diff --git a/.ansible/group_vars/app-db.yml b/.ansible/group_vars/app-db.yml index 1665a59..e69de29 100644 --- a/.ansible/group_vars/app-db.yml +++ b/.ansible/group_vars/app-db.yml @@ -1,4 +0,0 @@ -mysql_databases: - - name: betskills - collation: utf8_general_ci - encoding: utf8 \ No newline at end of file diff --git a/.ansible/group_vars/app-web.yml b/.ansible/group_vars/app-web.yml index c8347b4..c27e1f0 100644 --- a/.ansible/group_vars/app-web.yml +++ b/.ansible/group_vars/app-web.yml @@ -1,9 +1,3 @@ -apache_vhosts: - - servername: "betskills.dev" - documentroot: "/var/www/betskills/backend/web" - extra_parameters: | - SetEnv APPLICATION_ENV "development" - php_packages: - php7.0-common - php7.0-cli diff --git a/.ansible/group_vars/env-dev.yml b/.ansible/group_vars/env-dev.yml index e69de29..c25f3ef 100644 --- a/.ansible/group_vars/env-dev.yml +++ b/.ansible/group_vars/env-dev.yml @@ -0,0 +1,10 @@ +apache_vhosts: + - servername: "betskills.dev" + documentroot: "/var/www/betskills/backend/web" + extra_parameters: | + SetEnv APPLICATION_ENV "development" + +mysql_databases: + - name: betskills + collation: utf8_general_ci + encoding: utf8 \ No newline at end of file diff --git a/.ansible/group_vars/env-prod.yml b/.ansible/group_vars/env-prod.yml new file mode 100644 index 0000000..5fd835b --- /dev/null +++ b/.ansible/group_vars/env-prod.yml @@ -0,0 +1,10 @@ +apache_vhosts: + - servername: "backend.betskills.com 213.186.33.40:8080" + documentroot: "/var/www/betskills/backend/web" + extra_parameters: | + SetEnv APPLICATION_ENV "production" + +mysql_databases: + - name: betskilltsadmin + collation: utf8_general_ci + encoding: utf8 \ No newline at end of file diff --git a/.ansible/inventories/inventory_prod b/.ansible/inventories/inventory_prod new file mode 100644 index 0000000..3fa0bf7 --- /dev/null +++ b/.ansible/inventories/inventory_prod @@ -0,0 +1,9 @@ +[env-prod:children] +app-db +app-web + +[app-db] +default ansible_ssh_host=213.186.33.40 ansible_ssh_port=22 ansible_ssh_user=root + +[app-web] +default ansible_ssh_host=213.186.33.40 ansible_ssh_port=22 ansible_ssh_user=root \ No newline at end of file diff --git a/.vagrant/machines/betskills/virtualbox/synced_folders b/.vagrant/machines/betskills/virtualbox/synced_folders index 3799756..45c0953 100644 --- a/.vagrant/machines/betskills/virtualbox/synced_folders +++ b/.vagrant/machines/betskills/virtualbox/synced_folders @@ -1 +1 @@ -{"virtualbox":{"vagrant-root":{"id":"vagrant-root","owner":"www-data","mount_options":["dmode=775","fmode=775"],"guestpath":"/var/www/betskills/backend","hostpath":"/private/var/www/betskills/backend","disabled":false,"__vagrantfile":true}}} \ No newline at end of file +{"virtualbox":{"vagrant-root":{"id":"vagrant-root","owner":"www-data","mount_options":["dmode=775","fmode=775"],"guestpath":"/var/www/betskills/backend","hostpath":"/Users/jeremyguiselin/Projects/betskills/backend","disabled":false,"__vagrantfile":true}}} \ No newline at end of file diff --git a/app/config/config.yml b/app/config/config.yml index fa0e8a8..d6f7718 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -10,7 +10,7 @@ imports: parameters: locale: fr team_directory: '%kernel.root_dir%/../web/img/application/team' - pack_directory: '%kernel.root_dir%/../web/img/application/pack' + league_directory: '%kernel.root_dir%/../web/img/application/league' framework: #esi: ~ diff --git a/src/ApiBundle/Controller/DefaultController.php b/src/ApiBundle/Controller/DefaultController.php index 5e0e764..23298ae 100644 --- a/src/ApiBundle/Controller/DefaultController.php +++ b/src/ApiBundle/Controller/DefaultController.php @@ -38,33 +38,22 @@ class DefaultController extends FOSRestController } - /** - * @return Response - */ - public function getPacksAction() - { - $view = View::create() - ->setStatusCode(200) - ->setData($this->getPackRepository()->findAll()); - - return $this->handleView($view); - - } - /** * @param string $sport * @return Response * * GET Route annotation. - * @Get("/packs/{sport}") + * @Get("/leagues/{sport}") */ - public function getPacksBySportAction(string $sport) + public function getLeaguesBySportAction(string $sport) { try { - $packs = $this->getPackRepository()->findPacksBySport($sport); + $leagues = $this->getLeagueRepository()->findBy([ + 'sport' => $sport + ]); $view = View::create() ->setStatusCode(200) - ->setData($packs); + ->setData($leagues); return $this->handleView($view); } catch (\Exception $e) { @@ -75,8 +64,6 @@ class DefaultController extends FOSRestController return $this->handleView($view); } - - } /** @@ -243,11 +230,6 @@ class DefaultController extends FOSRestController return $this->getDoctrine()->getRepository('BackendBundle:League'); } - private function getPackRepository() - { - return $this->getDoctrine()->getRepository('BackendBundle:Pack'); - } - private function getLogger() { return $this->get('logger'); diff --git a/src/BackendBundle/Controller/EntityBrowserController.php b/src/BackendBundle/Controller/EntityBrowserController.php index eb21664..17ae9af 100644 --- a/src/BackendBundle/Controller/EntityBrowserController.php +++ b/src/BackendBundle/Controller/EntityBrowserController.php @@ -21,7 +21,7 @@ class EntityBrowserController extends Controller * @param int $page * @return Response * - * @Route("/admin/{name}/list/{page}", requirements={"name" = "league|prediction|pack|team"}) + * @Route("/admin/{name}/list/{page}", requirements={"name" = "league|prediction|team"}) */ public function listAction(string $name, Request $request, int $page) { @@ -64,7 +64,7 @@ class EntityBrowserController extends Controller * @param Request $request * @return Response * - * @Route("/admin/{name}/new", requirements={"name" = "league|prediction|pack|team"}) + * @Route("/admin/{name}/new", requirements={"name" = "league|prediction|team"}) */ public function newAction(string $name, Request $request) { @@ -104,7 +104,7 @@ class EntityBrowserController extends Controller * @param Request $request * @return Response * - * @Route("/admin/{name}/edit/{id}", requirements={"name" = "league|prediction|pack|team", "id"}) + * @Route("/admin/{name}/edit/{id}", requirements={"name" = "league|prediction|team", "id"}) */ public function editAction(string $name, int $id, Request $request) { @@ -142,7 +142,7 @@ class EntityBrowserController extends Controller * @param Request $request * @return JsonResponse * - * @Route("/admin/{name}/delete", requirements={"name" = "league|prediction|pack|team"}) + * @Route("/admin/{name}/delete", requirements={"name" = "league|prediction|team"}) */ public function deleteAction(string $name, Request $request) { @@ -211,7 +211,7 @@ class EntityBrowserController extends Controller private function setPicture(string $name, $element) { - if (in_array($name, ['team', 'pack'])) { + if (in_array($name, ['team', 'league'])) { /** @var File $file */ $file = $element->getPicture(); diff --git a/src/BackendBundle/Entity/LeagueOnDevice.php b/src/BackendBundle/Entity/LeagueOnDevice.php new file mode 100644 index 0000000..5d1a346 --- /dev/null +++ b/src/BackendBundle/Entity/LeagueOnDevice.php @@ -0,0 +1,120 @@ +<?php +/** + * Created by PhpStorm. + * User: jeremyguiselin + * Date: 19/12/2016 + * Time: 10:36 + */ + +namespace BackendBundle\Entity; + +use Doctrine\ORM\Mapping as ORM; + +/** + * LeagueOnDevice + * + * @ORM\Table(name="league_on_device") + * @ORM\Entity(repositoryClass="BackendBundle\Repository\LeagueOnDeviceRepository") + */ +class LeagueOnDevice +{ + + const STATUS_UNLOCK = 'unlock'; + const STATUS_LOCK = 'lock'; + + /** + * @var int + * + * @ORM\Column(name="id", type="integer") + * @ORM\Id + * @ORM\GeneratedValue(strategy="AUTO") + */ + private $id; + + /** + * @var Device + * + * @ORM\ManyToOne(targetEntity="BackendBundle\Entity\Device") + * @ORM\JoinColumn(nullable=false, onDelete="CASCADE") + */ + private $device; + + /** + * @var League + * + * @ORM\ManyToOne(targetEntity="BackendBundle\Entity\League") + * @ORM\JoinColumn(nullable=false, onDelete="CASCADE") + */ + private $league; + + /** + * @var string + * + * @ORM\Column(name="status", type="string", length=255) + */ + private $status = self::STATUS_LOCK; + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @param int $id + */ + public function setId($id) + { + $this->id = $id; + } + + /** + * @return Device + */ + public function getDevice() + { + return $this->device; + } + + /** + * @param Device $device + */ + public function setDevice($device) + { + $this->device = $device; + } + + /** + * @return League + */ + public function getLeague() + { + return $this->league; + } + + /** + * @param League $league + */ + public function setLeague($league) + { + $this->league = $league; + } + + /** + * @return string + */ + public function getStatus() + { + return $this->status; + } + + /** + * @param string $status + */ + public function setStatus($status) + { + $this->status = $status; + } +} \ No newline at end of file diff --git a/src/BackendBundle/Entity/Notification.php b/src/BackendBundle/Entity/Notification.php index 75c3dbf..ce7c64f 100644 --- a/src/BackendBundle/Entity/Notification.php +++ b/src/BackendBundle/Entity/Notification.php @@ -31,7 +31,7 @@ class Notification /** * @var string * - * @ORM\Column(name="content", type="text") + * @ORM\Column(type="text") */ private $frenchContent; @@ -45,7 +45,7 @@ class Notification /** * @var string * - * @ORM\Column(name="content", type="text") + * @ORM\Column(type="text") */ private $englishContent; diff --git a/src/BackendBundle/Entity/Pack.php b/src/BackendBundle/Entity/Pack.php deleted file mode 100644 index e3463bb..0000000 --- a/src/BackendBundle/Entity/Pack.php +++ /dev/null @@ -1,164 +0,0 @@ -<?php - -namespace BackendBundle\Entity; - -use Doctrine\Common\Collections\Collection; -use Doctrine\ORM\Mapping as ORM; -use Symfony\Component\Validator\Constraints as Assert; - -/** - * Pack - * - * @ORM\Table(name="pack") - * @ORM\Entity(repositoryClass="BackendBundle\Repository\PackRepository") - */ -class Pack -{ - /** - * @var int - * - * @ORM\Column(name="id", type="integer") - * @ORM\Id - * @ORM\GeneratedValue(strategy="AUTO") - */ - private $id; - - /** - * @var string - * - * @ORM\Column(name="name", type="string", length=255) - */ - private $name; - - /** - * @var int - * - * @ORM\Column(name="priceInCents", type="integer") - */ - private $priceInCents; - - /** - * @var League[] - * @ORM\ManyToMany(targetEntity="League", cascade={"all"}, fetch="EAGER") - * @ORM\JoinTable(name="pack_leagues", - * joinColumns={@ORM\JoinColumn(name="pack_id", referencedColumnName="id", onDelete="CASCADE")}, - * inverseJoinColumns={@ORM\JoinColumn(name="league_id", referencedColumnName="id", onDelete="CASCADE")} - * ) - */ - private $leagues; - - /** - * @ORM\Column(name="picture", type="string", length=255) - * - * @Assert\NotBlank(message="Veuillez uploader une image de l'équipe") - * @Assert\File(mimeTypes={"image/jpeg", "image/png"}) - */ - private $picture; - - - /** - * Get id - * - * @return int - */ - public function getId() - { - return $this->id; - } - - /** - * Set name - * - * @param string $name - * - * @return Pack - */ - public function setName($name) - { - $this->name = $name; - - return $this; - } - - /** - * Get name - * - * @return string - */ - public function getName() - { - return $this->name; - } - - /** - * Set priceInCents - * - * @param integer $priceInCents - * - * @return Pack - */ - public function setPriceInCents($priceInCents) - { - $this->priceInCents = $priceInCents; - - return $this; - } - - /** - * Get priceInCents - * - * @return int - */ - public function getPriceInCents() - { - return $this->priceInCents; - } - - /** - * @return League[] - */ - public function getLeagues() - { - return $this->leagues; - } - - /** - * @param Collection $leagues - */ - public function setLeagues(Collection $leagues) - { - $this->leagues = $leagues; - } - - public function removeLeagues(Collection $leagues) - { - foreach ($leagues as $league) { - $this->leagues->removeElement($league); - } - } - - public function addLeagues(Collection $leagues) - { - foreach ($leagues as $league) { - $this->leagues->add($league); - } - } - - /** - * @return mixed - */ - public function getPicture() - { - return $this->picture; - } - - /** - * @param mixed $picture - */ - public function setPicture($picture) - { - $this->picture = $picture; - } - -} - diff --git a/src/BackendBundle/Form/PackType.php b/src/BackendBundle/Form/PackType.php deleted file mode 100644 index 2940ef5..0000000 --- a/src/BackendBundle/Form/PackType.php +++ /dev/null @@ -1,48 +0,0 @@ -<?php - -namespace BackendBundle\Form; - -use BackendBundle\Form\Type\FloatType; -use Symfony\Bridge\Doctrine\Form\Type\EntityType; -use Symfony\Component\Form\AbstractType; -use Symfony\Component\Form\Extension\Core\Type\FileType; -use Symfony\Component\Form\Extension\Core\Type\TextType; -use Symfony\Component\Form\FormBuilderInterface; -use Symfony\Component\OptionsResolver\OptionsResolver; - -class PackType extends AbstractType -{ - public function buildForm(FormBuilderInterface $builder, array $options) - { - $builder - ->add('name', TextType::class, [ - 'label' => 'Nom', - ]) - ->add('priceInCents', FloatType::class, [ - 'label' => 'Prix (en centimes)' - ]) - ->add('leagues', EntityType::class, [ - 'label' => 'Ligues', - 'class' => 'BackendBundle\Entity\League', - 'choice_label' => 'name', - 'multiple' => true, - 'expanded' => false - ]) - ->add('picture', FileType::class, [ - 'label' => 'Image', - ]); - } - - public function configureOptions(OptionsResolver $resolver) - { - $resolver->setDefaults([ - 'data_class' => 'BackendBundle\Entity\Pack', - 'csrf_protection' => false, - ]); - } - - public function getName() - { - return 'backend_bundle_pack_type'; - } -} diff --git a/src/BackendBundle/Repository/PackRepository.php b/src/BackendBundle/Repository/PackRepository.php deleted file mode 100644 index 53ece9f..0000000 --- a/src/BackendBundle/Repository/PackRepository.php +++ /dev/null @@ -1,43 +0,0 @@ -<?php - -namespace BackendBundle\Repository; -use BackendBundle\Entity\Pack; -use Doctrine\ORM\EntityRepository; - -/** - * PackRepository - * - * This class was generated by the Doctrine ORM. Add your own custom - * repository methods below. - */ -class PackRepository extends EntityRepository -{ - public function alreadyExists(Pack $pack) : bool - { - return $this->findOneBy([ - 'name' => $pack->getName() - ]) !== null; - } - - public function getAll() - { - $qb = $this->createQueryBuilder('p'); - $qb->select('p'); - - return $qb; - - } - - public function findPacksBySport(string $sport) - { - $qb = $this->createQueryBuilder('p'); - $qb - - ->select('p') - ->join('p.leagues', 'l', 'WITH', 'l.sport = :sport') - ->setParameter('sport', $sport); - - return $qb->getQuery()->getResult(); - } - -} \ No newline at end of file diff --git a/src/BackendBundle/Resources/views/layout/dashboard.html.twig b/src/BackendBundle/Resources/views/layout/dashboard.html.twig index 394abc9..be90c8e 100644 --- a/src/BackendBundle/Resources/views/layout/dashboard.html.twig +++ b/src/BackendBundle/Resources/views/layout/dashboard.html.twig @@ -16,7 +16,6 @@ <ul class="nav navbar-nav"> <li><a href="{{ path('backend_entitybrowser_list', {'name': 'league', 'page': 1}) }}">Gestion des ligues</a></li> <li><a href="{{ path('backend_entitybrowser_list', {'name': 'prediction', 'page': 1}) }}">Gestion des prédictions</a></li> - <li><a href="{{ path('backend_entitybrowser_list', {'name': 'pack', 'page': 1}) }}">Gestion des packs</a></li> <li><a href="{{ path('backend_entitybrowser_list', {'name': 'team', 'page': 1}) }}">Gestion des équipes</a></li> <li><a href="{{ path('backend_notification_list', {'page': 1}) }}">Notifications</a></li> </ul> diff --git a/src/BackendBundle/Resources/views/pack/form.html.twig b/src/BackendBundle/Resources/views/pack/form.html.twig deleted file mode 100644 index 6c0f58a..0000000 --- a/src/BackendBundle/Resources/views/pack/form.html.twig +++ /dev/null @@ -1,58 +0,0 @@ -{% extends '@Backend/layout/dashboard.html.twig' %} - -{% block title %}Gestion de {{ name }}{% endblock %} - -{% block stylesheets %} - <script src="{{ asset('js/selectize.min.js') }}"></script> -{% endblock %} - -{% block subcontent %} - <div class="row"> - <div class="col-sm-8 col-sm-offset-2"> - <h3 class="text-center text-primary">Ajouter un nouveau ou éditer un {{ name | trans }}</h3> - {{ form_start(form, {'attr': {'class': 'form-horizontal'}}) }} - <div class="form-group is-empty has-primary"> - {{ form_label(form.name, null, {'label_attr': {'class': "col-sm-2 control-label"}}) }} - <div class="col-sm-10"> - {{ form_widget(form.name, {'attr' : {'class': "form-control"}}) }} - </div> - {{ form_errors(form.name) }} - </div> - - <div class="form-group is-empty has-primary"> - {{ form_label(form.priceInCents, null, {'label_attr': {'class': "col-sm-2 control-label"}}) }} - <div class="col-sm-10"> - {{ form_widget(form.priceInCents, {'attr' : {'class': "form-control"}}) }} - </div> - {{ form_errors(form.priceInCents) }} - </div> - - <div class="form-group"> - {{ form_label(form.leagues, null, {'label_attr': {'class': "col-sm-2 control-label"}}) }} - <div class="col-sm-10"> - <div class="checkbox"> - {{ form_widget(form.leagues, {'attr' : {'class' : "js-example-basic-multiple js-states form-control"}}) }} - {{ form_errors(form.leagues) }} - </div> - </div> - </div> - - <div class="form-group is-empty has-primary"> - {{ form_label(form.picture, null, {'label_attr': {'class': "col-sm-2 control-label"}}) }} - <div class="col-sm-10"> - {{ form_widget(form.picture, {'attr' : {'class': "form-control"}}) }} - </div> - {{ form_errors(form.picture) }} - </div> - - <button type="submit" class="modal-action modal-close waves-effect waves-green waves-light btn">Ajouter</button> - {{ form_end(form, {'render_rest': false}) }} - </div> - </div> -{% endblock %} - -{% block javascripts %} -<script type="text/javascript"> - $('select').selectize(); -</script> -{% endblock %} \ No newline at end of file diff --git a/src/BackendBundle/Resources/views/pack/list.html.twig b/src/BackendBundle/Resources/views/pack/list.html.twig deleted file mode 100644 index 650c950..0000000 --- a/src/BackendBundle/Resources/views/pack/list.html.twig +++ /dev/null @@ -1,52 +0,0 @@ -{% extends '@Backend/layout/dashboard.html.twig' %} - -{% block title %}Liste de {{ name | trans }}{% endblock %} - -{% block subcontent %} - <div class="row"> - <div class="col-sm-8 col-sm-offset-2"> - {% include '@Backend/entity-browser/buttons.html.twig' %} - <table class="table table-striped" cellspacing="0" width="50%"> - <thead> - <tr> - <th>#</th> - <th>Nom</th> - <th>Prix</th> - <th>Ligues</th> - <th>Modifier</th> - <th>Selectionner</th> - </tr> - </thead> - <tbody> - {% for element in elements %} - {% set leagues = [] %} - {% for league in element.leagues %} - {% set leagues = leagues|merge([league.name]) %} - {% endfor %} - <tr id="{{ element.id }}"> - <td>{{ element.id }}</td> - <td>{{ element.name }}</td> - <td>{{ element.priceInCents / 100 }}€</td> - <td>{{ leagues|join(', ') }}</td> - <td><a href="{{ path('backend_entitybrowser_edit', {'name': name, 'id': element.id}) }}" class="btn btn-info">Modifier<div class="ripple-container"></div></a></td> - <td> - <div class="checkbox"> - <label> - <input type="checkbox" data-id="{{ element.id }}"> - </label> - </div> - </td> - </tr> - {% endfor %} - </tbody> - </table> - - {% include '@Backend/entity-browser/paginator.html.twig' %} - - </div> - </div> -{% endblock %} - -{% block javascripts %} - <script src="{{ asset('js/ajax-select-and-delete.js') }}"></script> -{% endblock %} \ No newline at end of file -- GitLab