Skip to content
This repository has been archived by the owner on May 29, 2023. It is now read-only.

Commit

Permalink
Ref #23: Add and modify many files to create an make CRUD of strip wo…
Browse files Browse the repository at this point in the history
…rk. Commit way to big, won't happen again.
  • Loading branch information
hundrex committed Feb 5, 2018
1 parent 23aa645 commit 5deba30
Show file tree
Hide file tree
Showing 18 changed files with 725 additions and 17 deletions.
33 changes: 18 additions & 15 deletions app/Resources/views/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<a href="/">
<div class="row">
<div class="col media">
<img id="website-logo" class="align-self-end" src="{{ asset('images/en-tete.png') }}">
<img id="website-logo" class="align-self-end" src="{{ asset('images/en-tete.png') }}">
</div>
<div id="website-title" class="col text-right align-self-center">
<span>Succube SARL</span>
Expand Down Expand Up @@ -83,19 +83,22 @@
{% set account = app.session.get('account') %}
<ul class="navbar-nav">
{% if account.isAdmin() %}
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Administration
</a>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="{{ path('account_list') }}">
Manage users
</a>
<a class="dropdown-item" href="{{ path('contentwarning_list') }}">
Manage content warnings
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Administration
</a>
</div>
</li>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="{{ path('account_list') }}">
Manage users
</a>
<a class="dropdown-item" href="{{ path('contentwarning_list') }}">
Manage content warnings
</a>
<a class="dropdown-item" href="{{ path('strip_list') }}">
Manage strips
</a>
</div>
</li>
{% endif %}
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Expand Down Expand Up @@ -144,10 +147,10 @@
<div class="container-fluid">
<div class="row justify-content-center">
<div id="body-box" class="col-sm-12 col-md-8 col-lg-6 strip-box">
{% block body %}{% endblock %}
</div>
{% block body %}{% endblock %}
</div>
</div>
</div>
<footer class="footer">
<div class="container">
<span class="footer-element-needing-separator">
Expand Down
21 changes: 21 additions & 0 deletions app/Resources/views/strip/edit.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% extends 'base.html.twig' %}

{% block body %}
<h1>Strip edit</h1>

{{ form_start(edit_form) }}
{{ form_widget(edit_form) }}
<input type="submit" value="Edit" />
{{ form_end(edit_form) }}

<ul>
<li>
<a href="{{ path('strip_list') }}">Back to the list</a>
</li>
<li>
{{ form_start(delete_form) }}
<input type="submit" value="Delete">
{{ form_end(delete_form) }}
</li>
</ul>
{% endblock %}
53 changes: 53 additions & 0 deletions app/Resources/views/strip/list.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{% extends 'base.html.twig' %}

{% block body %}
<h1>Strips list</h1>

<table>
<thead>
<tr>
<th>Id</th>
<th>Creation Date</th>
<th>Publication Date</th>
<th>Title</th>
<th>Author</th>
<th>Content Warnings</th>
<th>Stripelements</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for strip in strips %}
<tr>
<td><a href="{{ path('strip_show', { 'id': strip.id }) }}">{{ strip.id }}</a></td>
<td>{{ strip.creationDate|date('Y-m-d H:i:s') }}</td>
<td>{{ strip.publicationDate|date('Y-m-d H:i:s') }}</td>
<td>{{ strip.title }}</td>
<td>{{ strip.author }}</td>
<td>
{% for contentWarning in strip.contentWarnings%}
<a href="{{ path('contentwarning_show', { 'label': contentWarning.label }) }}">{{ contentWarning.label }}</a>
{% endfor %}
</td>
<td>{{ strip.stripElements|join(', ') }}</td>
<td>
<ul>
<li>
<a href="{{ path('strip_show', { 'id': strip.id }) }}">show</a>
</li>
<li>
<a href="{{ path('strip_edit', { 'id': strip.id }) }}">edit</a>
</li>
</ul>
</td>
</tr>
{% endfor %}
</tbody>
</table>

<ul>
<li>
<a href="{{ path('strip_new') }}">Create a new strip</a>
</li>
</ul>
{% endblock %}
16 changes: 16 additions & 0 deletions app/Resources/views/strip/new.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{% extends 'base.html.twig' %}

{% block body %}
<h1>Strip creation</h1>

{{ form_start(form) }}
{{ form_widget(form) }}
<input type="submit" value="Create" />
{{ form_end(form) }}

<ul>
<li>
<a href="{{ path('strip_list') }}">Back to the list</a>
</li>
</ul>
{% endblock %}
48 changes: 48 additions & 0 deletions app/Resources/views/strip/show.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{% extends 'base.html.twig' %}

{% block body %}
<h1>Strip</h1>

<table>
<tbody>
<tr>
<th>Id</th>
<td>{{ strip.id }}</td>
</tr>
<tr>
<th>Creationdate</th>
<td>{% if strip.creationDate %}{{ strip.creationDate|date('Y-m-d H:i:s') }}{% endif %}</td>
</tr>
<tr>
<th>Publicationdate</th>
<td>{% if strip.publicationDate %}{{ strip.publicationDate|date('Y-m-d H:i:s') }}{% endif %}</td>
</tr>
<tr>
<th>Title</th>
<td>{{ strip.title }}</td>
</tr>
<tr>
<th>Slug</th>
<td>{{ strip.slug }}</td>
</tr>
<tr>
<th>Stripelements</th>
<td>{% if strip.stripElements %}{{ strip.stripElements|join(', ') }}{% endif %}</td>
</tr>
</tbody>
</table>

<ul>
<li>
<a href="{{ path('strip_list') }}">Back to the list</a>
</li>
<li>
<a href="{{ path('strip_edit', { 'id': strip.id }) }}">Edit</a>
</li>
<li>
{{ form_start(delete_form) }}
<input type="submit" value="Delete">
{{ form_end(delete_form) }}
</li>
</ul>
{% endblock %}
6 changes: 6 additions & 0 deletions app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ imports:
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: en
strips_directory: '%kernel.project_dir%/web/images/strips'

framework:
#esi: ~
Expand Down Expand Up @@ -62,6 +63,11 @@ doctrine:
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true

stof_doctrine_extensions:
orm:
default:
sluggable: true

# Swiftmailer Configuration
swiftmailer:
transport: '%mailer_transport%'
Expand Down
138 changes: 137 additions & 1 deletion src/AppBundle/Controller/AdministrationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\Session;
use AppBundle\Entity\ContentWarning;
use AppBundle\Entity\Strip;

/**
* Administration controller.
Expand All @@ -16,6 +17,7 @@
*/
class AdministrationController extends Controller {

// Methods for Account administration
/**
* Lists all account entities.
*
Expand All @@ -39,6 +41,7 @@ public function listAccountAction() {
}
}

// Methods for Content Warnings Administration
/**
* Lists all contentWarning entities.
*
Expand Down Expand Up @@ -137,7 +140,7 @@ public function editContentWarningAction(Request $request, ContentWarning $conte
/**
* Deletes a contentWarning entity.
*
* @Route("/{id}", name="contentwarning_delete")
* @Route("/contentwarnings/{id}", name="contentwarning_delete")
* @Method("DELETE")
*/
public function deleteContentWarningAction(Request $request, ContentWarning $contentWarning) {
Expand Down Expand Up @@ -174,5 +177,138 @@ private function createContentWarningDeleteForm(ContentWarning $contentWarning)
->getForm()
;
}

// Methods for Stips administration
/**
* Lists all strip entities.
*
* @Route("/strips", name="strip_list")
* @Method("GET")
*/
public function listStripAction() {
$em = $this->getDoctrine()->getManager();

$strips = $em->getRepository('AppBundle:Strip')->findAll();

return $this->render('strip/list.html.twig', array(
'strips' => $strips,
));
}

/**
* Creates a new strip entity.
*
* @Route("/strips/new", name="strip_new")
* @Method({"GET", "POST"})
*/
public function newStripAction(Request $request) {
$strip = new Strip();
$form = $this->createForm('AppBundle\Form\StripType', $strip);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
/**
* Process to gather images uploaded for the strip,
* save them with uniques names, and save those strings
* in strip attribute stripElements
*/
$images = $strip->getStripElements();
$filenames = [];
foreach ($images as $image) {
$name = md5(uniqid()) . '.' . $image->guessExtension();
array_push($filenames, $name);
// Is moving image in loop going to break the loop ?
$image->move(
$this->getParameter('strips_directory'),
$name
);
}
$strip->setStripElements($filenames);

$em = $this->getDoctrine()->getManager();
$em->persist($strip);
$em->flush();

return $this->redirectToRoute('strip_show', array('id' => $strip->getId()));
}

return $this->render('strip/new.html.twig', array(
'strip' => $strip,
'form' => $form->createView(),
));
}

/**
* Finds and displays a strip entity.
*
* @Route("strips/{id}", name="strip_show")
* @Method("GET")
*/
public function showStripAction(Strip $strip) {
$deleteForm = $this->createDeleteForm($strip);

return $this->render('strip/show.html.twig', array(
'strip' => $strip,
'delete_form' => $deleteForm->createView(),
));
}

/**
* Displays a form to edit an existing strip entity.
*
* @Route("/strips/{id}/edit", name="strip_edit")
* @Method({"GET", "POST"})
*/
public function editStripAction(Request $request, Strip $strip) {
$deleteForm = $this->createDeleteForm($strip);
$editForm = $this->createForm('AppBundle\Form\StripType', $strip);
$editForm->handleRequest($request);

if ($editForm->isSubmitted() && $editForm->isValid()) {
$this->getDoctrine()->getManager()->flush();

return $this->redirectToRoute('strip_edit', array('id' => $strip->getId()));
}

return $this->render('strip/edit.html.twig', array(
'strip' => $strip,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
}

/**
* Deletes a strip entity.
*
* @Route("/strips/{id}", name="strip_delete")
* @Method("DELETE")
*/
public function deleteStripAction(Request $request, Strip $strip) {
$form = $this->createDeleteForm($strip);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->remove($strip);
$em->flush();
}

return $this->redirectToRoute('strip_index');
}

/**
* Creates a form to delete a strip entity.
*
* @param Strip $strip The strip entity
*
* @return \Symfony\Component\Form\Form The form
*/
private function createDeleteForm(Strip $strip) {
return $this->createFormBuilder()
->setAction($this->generateUrl('strip_delete', array('id' => $strip->getId())))
->setMethod('DELETE')
->getForm()
;
}

}
Loading

0 comments on commit 5deba30

Please sign in to comment.