Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added configuration module

  • Loading branch information...
commit a3ff16f7ae790c7003e8a97688348e68e3c1e1b0 1 parent 794dd6b
@dutow authored
View
112 Controller/Admin/ConfigurationController.php
@@ -0,0 +1,112 @@
+<?php
+
+namespace Eotvos\VersenyrBundle\Controller\Admin;
+
+use Eotvos\VersenyrBundle\Entity\Configuration;
+use Eotvos\VersenyrBundle\Form\Type\ConfigurationType;
+
+use Symfony\Bundle\FrameworkBundle\Controller\Controller;
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
+
+/**
+ * Minimal admin interface for configurations.
+ *
+ * @author Zsolt Parragi <zsolt.parragi@cancellar.hu>
+ * @copyright 2012 Cancellar
+ * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
+ * @version Release: v0.1
+ *
+ * @Route("/admin/configuration");
+ */
+class ConfigurationController extends Controller
+{
+ /**
+ * Shows configuration list
+ *
+ * @return array template parameters
+ *
+ * @Route("/", name = "admin_configuration_index" )
+ * @Template
+ */
+ public function indexAction()
+ {
+
+ $em = $this->getDoctrine()->getEntityManager();
+ $repo = $this->getDoctrine()
+ ->getRepository('EotvosVersenyrBundle:Configuration')
+ ;
+
+ $request = $this->get('request');
+ $type = $request->query->get('type', 'all');
+
+ if (!in_array($type, array('all'))) {
+ throw $this->createNotFoundException("Bad parameter");
+ }
+
+ switch ($type) {
+
+ case 'all':
+ $configurations = $repo->findAll();
+ break;
+ }
+
+ return array(
+ 'configurations' => $configurations,
+ );
+ }
+
+ /**
+ * Editing a configuration
+ *
+ * @param int $id Id of the configuration
+ *
+ * @return array of template parameters
+ *
+ * @Route("/edit/{id}", name = "admin_configuration_edit" )
+ * @Template
+ */
+ public function editAction($id)
+ {
+ if (!is_numeric($id)) {
+ throw $this->createNotFoundException("Configuration not found");
+ }
+
+ $em = $this->getDoctrine()->getEntityManager();
+ $repo = $this->getDoctrine()
+ ->getRepository('EotvosVersenyrBundle:Configuration')
+ ;
+
+ $configuration = $repo->findOneById($id);
+
+ if (!$configuration) {
+ throw $this->createNotFoundException("Configuration not found");
+ }
+
+ $form = $this->createForm(new ConfigurationType($this->container), $configuration);
+
+ $request = $this->get('request');
+
+ if ($request->getMethod() == 'POST') {
+ $form->bindRequest($request);
+ if ($form->isValid()) {
+
+ $configuration = $form->getData();
+
+ if ($configuration->getId()!=$id) {
+ throw $this->createNotFoundException("Don't forge stupid updates");
+ }
+
+ $em->flush();
+
+ return $this->redirect($this->generateUrl('admin_configuration_index'));
+ }
+ }
+
+ return array(
+ 'configuration' => $configuration,
+ 'form' => $form->createView(),
+ );
+ }
+
+}
View
9 Cwm/VersenyrAdminModule.php
@@ -12,10 +12,11 @@ class VersenyrAdminModule implements AdminModuleInterface
public function constructMenu(Menu $menu, $container)
{
$router = $container->get('router');
- $menu->addChild(new MenuItem('Alkalmak', $router->generate('admin_term_index'), 1));
- $menu->addChild(new MenuItem('Oldalak', $router->generate('admin_textpage_index'), 2));
- $menu->addChild(new MenuItem('Megoldasok', $router->generate('admin_submission_index'), 3));
- $menu->addChild(new MenuItem('Felhasznalok', $router->generate('admin_user_index'), 10));
+ $menu->addChild(new MenuItem('admin.heading.term', $router->generate('admin_term_index'), 1));
+ $menu->addChild(new MenuItem('admin.heading.textpage', $router->generate('admin_textpage_index'), 2));
+ $menu->addChild(new MenuItem('admin.heading.submission', $router->generate('admin_submission_index'), 3));
+ $menu->addChild(new MenuItem('admin.heading.configuration', $router->generate('admin_configuration_index'), 4));
+ $menu->addChild(new MenuItem('admin.heading.user', $router->generate('admin_user_index'), 10));
}
}
View
14 DataFixtures/ORM/ConfigurationFixture.php
@@ -58,6 +58,20 @@ public function load(ObjectManager $om)
$conf->setValue('http://versenyr.info');
$om->persist($conf);
+ $conf = new Configuration();
+ $conf->setName('eotvos.versenyr.admin.contact');
+ $conf->setValue('contact@example.com');
+ $om->persist($conf);
+
+ $conf = new Configuration();
+ $conf->setName('eotvos.versenyr.sender.email');
+ $conf->setValue('noreply@example.com');
+ $om->persist($conf);
+
+ $conf = new Configuration();
+ $conf->setName('eotvos.versenyr.sender.title');
+ $conf->setValue('VersenyR Mailer');
+ $om->persist($conf);
$om->flush();
}
View
68 Form/Type/ConfigurationType.php
@@ -0,0 +1,68 @@
+<?php
+
+namespace Eotvos\VersenyrBundle\Form\Type;
+
+use Eotvos\VersenyrBundle\Entity as Entity;
+
+use Symfony\Component\Form\AbstractType;
+use Symfony\Component\Form\FormBuilder;
+
+use Symfony\Component\DependencyInjection\ContainerInterface;
+
+/**
+ * Form type for user registration. Data modification is handled by different forms.
+ *
+ * @uses AbstractType
+ * @author Zsolt Parragi <zsolt.parragi@cancellar.hu>
+ * @copyright 2012 Cancellar
+ * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
+ * @version Release: v0.1
+ */
+class ConfigurationType extends AbstractType
+{
+
+ public function __construct(ContainerInterface $container)
+ {
+ $this->container = $container;
+ }
+
+ /**
+ * Builds the form.
+ *
+ * @param FormBuilder $builder builder
+ * @param array $options form options
+ *
+ * @return void
+ */
+ public function buildForm(FormBuilder $builder, array $options)
+ {
+ $builder->add('value', 'text');
+
+ }
+
+ /**
+ * Returns the name of the form type.
+ *
+ * @return string
+ */
+ public function getName()
+ {
+ return 'configuration_form';
+ }
+
+ /**
+ * Default options.
+ *
+ * @param array $options form options
+ *
+ * @return array options
+ */
+ public function getDefaultOptions(array $options)
+ {
+ return array(
+ 'data_class' => 'Eotvos\VersenyrBundle\Entity\Configuration',
+ );
+ }
+
+}
+
View
21 Resources/translations/messages.hu.yml
@@ -176,7 +176,7 @@ admin:
advances:
yes: 'IGEN'
no: 'NEM'
-
+
user:
display:
list: 'Felhasznalok'
@@ -206,3 +206,22 @@ admin:
admin: 'Admin'
tester: 'Tesztelo'
user: 'Versenyzo'
+
+ configuration:
+ fields:
+ value: 'Ertek'
+ name: 'Nev'
+ id: 'ID'
+ display:
+ list: 'Konfiguracios beallitasok'
+ actions:
+ edit: 'Szerkeszt'
+
+ heading:
+ term: 'Alkalmak'
+ textpage: 'Oldalak'
+ submission: 'Megoldasok'
+ configuration: 'Konfiguracio'
+ user: 'Felhasznalok'
+
+ logout: 'Kijelentkezes'
View
19 Resources/views/Admin/Configuration/edit.html.twig
@@ -0,0 +1,19 @@
+{% extends 'CancellarAdminBundle::layout.html.twig' %}
+
+{% form_theme form 'CancellarAdminBundle::form.html.twig' %}
+
+{% block main %}
+<h2>{{ 'admin.configuration.display.edit'|trans }} {{ configuration.name }}</h2>
+<form class="wide" action="{{ path('admin_configuration_edit', { 'id': configuration.id } ) }}" method="post" {{ form_enctype(form) }}>
+ <fieldset>
+ <legend>{{ 'admin.configuration.label.fields'|trans }}</legend>
+ {{ form_row(form.value) }}
+ <div class="formrow row_required">
+ <p class="inputholder">
+ <input type="submit" value="{{ 'admin.configuration.actions.save'|trans }}" class="button" />
+ </p>
+ </div>
+ </fieldset>
+ {{ form_rest(form) }}
+</form>
+{% endblock %}
View
27 Resources/views/Admin/Configuration/index.html.twig
@@ -0,0 +1,27 @@
+{% extends 'CancellarAdminBundle::layout.html.twig' %}
+
+{% block main %}
+<h2>{% trans %}admin.configuration.display.list{% endtrans %}</h2>
+<table class="standard" style="width:100%;">
+ <thead>
+ <tr>
+ <th>{% trans %}admin.configuration.fields.id{% endtrans %}</th>
+ <th>{% trans %}admin.configuration.fields.name{% endtrans %}</th>
+ <th>{% trans %}admin.configuration.fields.value{% endtrans %}</th>
+ <th>{% trans %}admin.actions{% endtrans %}</th>
+ </tr>
+ </thead>
+ <tbody>
+ {% for row in configurations %}
+ <tr>
+ <td>{{ row.id }}</td>
+ <td>{{ row.name|trans }}</td>
+ <td>{{ row.value }}</td>
+ <td>
+ <a href="{{ path('admin_configuration_edit', { id: row.id }) }}">{% trans %}admin.configuration.actions.edit{% endtrans %}</a>
+ </td>
+ </tr>
+ {% endfor %}
+ </tbody>
+</table>
+{% endblock %}
Please sign in to comment.
Something went wrong with that request. Please try again.