Commit AdminTool as branch admintool
authorhiroto@hiroto.keio.w3.org
Wed, 29 Feb 2012 13:49:54 +0900
branchadmintool
changeset 218 a8ae4bfe9e5e
parent 213 c4ea0d585c03
Commit AdminTool as branch
app/config/routing.yml
deps
src/Org/W3/Cg/Pub/SpecBundle/Controller/SpecPGController.php
src/Org/W3/Cg/Pub/SpecBundle/Form/SpecPGType.php
src/Org/W3/Cg/Pub/SpecBundle/Resources/config/routing/specpg.yml
src/Org/W3/Cg/Pub/SpecBundle/Resources/views/SpecPG/edit.html.twig
src/Org/W3/Cg/Pub/SpecBundle/Resources/views/SpecPG/index.html.twig
src/Org/W3/Cg/Pub/SpecBundle/Resources/views/SpecPG/new.html.twig
src/Org/W3/Cg/Pub/SpecBundle/Resources/views/SpecPG/show.html.twig
src/Org/W3/Cg/Pub/SpecBundle/Tests/Controller/SpecPGControllerTest.php
--- a/app/config/routing.yml	Tue Feb 28 00:10:15 2012 +0900
+++ b/app/config/routing.yml	Wed Feb 29 13:49:54 2012 +0900
@@ -5,6 +5,10 @@
 report:
     pattern: /reports/
     defaults: { _controller: OrgW3CgPubSpecBundle:Report:index }
+    
+SpecPGAdmin:
+    resource: "@OrgW3CgPubSpecBundle/Resources/config/routing/specpg.yml"
+    prefix: /admin
 
 index:
     pattern: /
--- a/deps	Tue Feb 28 00:10:15 2012 +0900
+++ b/deps	Wed Feb 29 13:49:54 2012 +0900
@@ -1,6 +1,6 @@
 [symfony]
     git=http://github.com/symfony/symfony.git
-    version=v2.0.4
+    version=v2.0.9
 
 [twig]
     git=http://github.com/fabpot/Twig.git
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Org/W3/Cg/Pub/SpecBundle/Controller/SpecPGController.php	Wed Feb 29 13:49:54 2012 +0900
@@ -0,0 +1,195 @@
+<?php
+
+namespace Org\W3\Cg\Pub\SpecBundle\Controller;
+
+use Symfony\Bundle\FrameworkBundle\Controller\Controller;
+
+use Org\W3\Cg\Pub\SpecBundle\Entity\SpecPG;
+use Org\W3\Cg\Pub\SpecBundle\Form\SpecPGType;
+use Org\W3\Cg\Pub\UserGroupBundle;
+
+/**
+ * SpecPG controller.
+ *
+ */
+class SpecPGController extends Controller
+{
+    /**
+     * Lists all SpecPG entities.
+     *
+     */
+    public function indexAction()
+    {
+        $em = $this->getDoctrine()->getEntityManager();
+        $entities = $em->getRepository('OrgW3CgPubSpecBundle:Spec')->findAll();
+foreach($entities as $entry){
+   $pg_entities = $em->getRepository('OrgW3CgPubSpecBundle:SpecPG')->findBySpec($entry->getId());
+   $arraybuf=array();
+   foreach($pg_entities as $pg){
+   array_push($arraybuf, \W3_ProposedGroup::getProposedGroupById($pg->getGrcode())); 
+}
+$groups[$entry->getId()]=$arraybuf;
+}
+        return $this->render('OrgW3CgPubSpecBundle:SpecPG:index.html.twig', array(
+            'entities' => $entities,
+            'groups' => $groups
+        ));
+    }
+
+    /**
+     * Finds and displays a SpecPG entity.
+     *
+     */
+    public function showAction($id)
+    {
+        $em = $this->getDoctrine()->getEntityManager();
+
+        $entity = $em->getRepository('OrgW3CgPubSpecBundle:SpecPG')->find($id);
+
+        if (!$entity) {
+            throw $this->createNotFoundException('Unable to find SpecPG entity.');
+        }
+
+        $deleteForm = $this->createDeleteForm($id);
+
+        return $this->render('OrgW3CgPubSpecBundle:SpecPG:show.html.twig', array(
+            'entity'      => $entity,
+            'delete_form' => $deleteForm->createView(),
+
+        ));
+    }
+
+    /**
+     * Displays a form to create a new SpecPG entity.
+     *
+     */
+    public function newAction()
+    {
+        $entity = new SpecPG();
+        $form   = $this->createForm(new SpecPGType(), $entity);
+
+        return $this->render('OrgW3CgPubSpecBundle:SpecPG:new.html.twig', array(
+            'entity' => $entity,
+            'form'   => $form->createView()
+        ));
+    }
+
+    /**
+     * Creates a new SpecPG entity.
+     *
+     */
+    public function createAction()
+    {
+        $entity  = new SpecPG();
+        $request = $this->getRequest();
+        $form    = $this->createForm(new SpecPGType(), $entity);
+        $form->bindRequest($request);
+
+        if ($form->isValid()) {
+            $em = $this->getDoctrine()->getEntityManager();
+            $em->persist($entity);
+            $em->flush();
+
+            return $this->redirect($this->generateUrl('admin_specpg_show', array('id' => $entity->getId())));
+            
+        }
+
+        return $this->render('OrgW3CgPubSpecBundle:SpecPG:new.html.twig', array(
+            'entity' => $entity,
+            'form'   => $form->createView()
+        ));
+    }
+
+    /**
+     * Displays a form to edit an existing SpecPG entity.
+     *
+     */
+    public function editAction($id)
+    {
+        $em = $this->getDoctrine()->getEntityManager();
+
+        $entity = $em->getRepository('OrgW3CgPubSpecBundle:SpecPG')->find($id);
+
+        if (!$entity) {
+            throw $this->createNotFoundException('Unable to find SpecPG entity.');
+        }
+
+        $editForm = $this->createForm(new SpecPGType(), $entity);
+        $deleteForm = $this->createDeleteForm($id);
+
+        return $this->render('OrgW3CgPubSpecBundle:SpecPG:edit.html.twig', array(
+            'entity'      => $entity,
+            'edit_form'   => $editForm->createView(),
+            'delete_form' => $deleteForm->createView(),
+        ));
+    }
+
+    /**
+     * Edits an existing SpecPG entity.
+     *
+     */
+    public function updateAction($id)
+    {
+        $em = $this->getDoctrine()->getEntityManager();
+
+        $entity = $em->getRepository('OrgW3CgPubSpecBundle:SpecPG')->find($id);
+
+        if (!$entity) {
+            throw $this->createNotFoundException('Unable to find SpecPG entity.');
+        }
+
+        $editForm   = $this->createForm(new SpecPGType(), $entity);
+        $deleteForm = $this->createDeleteForm($id);
+
+        $request = $this->getRequest();
+
+        $editForm->bindRequest($request);
+
+        if ($editForm->isValid()) {
+            $em->persist($entity);
+            $em->flush();
+
+            return $this->redirect($this->generateUrl('admin_specpg_edit', array('id' => $id)));
+        }
+
+        return $this->render('OrgW3CgPubSpecBundle:SpecPG:edit.html.twig', array(
+            'entity'      => $entity,
+            'edit_form'   => $editForm->createView(),
+            'delete_form' => $deleteForm->createView(),
+        ));
+    }
+
+    /**
+     * Deletes a SpecPG entity.
+     *
+     */
+    public function deleteAction($id)
+    {
+        $form = $this->createDeleteForm($id);
+        $request = $this->getRequest();
+
+        $form->bindRequest($request);
+
+        if ($form->isValid()) {
+            $em = $this->getDoctrine()->getEntityManager();
+            $entity = $em->getRepository('OrgW3CgPubSpecBundle:SpecPG')->find($id);
+
+            if (!$entity) {
+                throw $this->createNotFoundException('Unable to find SpecPG entity.');
+            }
+
+            $em->remove($entity);
+            $em->flush();
+        }
+
+        return $this->redirect($this->generateUrl('admin_specpg'));
+    }
+
+    private function createDeleteForm($id)
+    {
+        return $this->createFormBuilder(array('id' => $id))
+            ->add('id', 'hidden')
+            ->getForm()
+        ;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Org/W3/Cg/Pub/SpecBundle/Form/SpecPGType.php	Wed Feb 29 13:49:54 2012 +0900
@@ -0,0 +1,22 @@
+<?php
+
+namespace Org\W3\Cg\Pub\SpecBundle\Form;
+
+use Symfony\Component\Form\AbstractType;
+use Symfony\Component\Form\FormBuilder;
+
+class SpecPGType extends AbstractType
+{
+    public function buildForm(FormBuilder $builder, array $options)
+    {
+        $builder
+            ->add('grcode')
+            ->add('spec')
+        ;
+    }
+
+    public function getName()
+    {
+        return 'org_w3_cg_pub_specbundle_specpgtype';
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Org/W3/Cg/Pub/SpecBundle/Resources/config/routing/specpg.yml	Wed Feb 29 13:49:54 2012 +0900
@@ -0,0 +1,30 @@
+admin_specpg:
+    pattern:  /
+    defaults: { _controller: "OrgW3CgPubSpecBundle:SpecPG:index" }
+
+admin_specpg_show:
+    pattern:  /{id}/show
+    defaults: { _controller: "OrgW3CgPubSpecBundle:SpecPG:show" }
+
+admin_specpg_new:
+    pattern:  /new
+    defaults: { _controller: "OrgW3CgPubSpecBundle:SpecPG:new" }
+
+admin_specpg_create:
+    pattern:  /create
+    defaults: { _controller: "OrgW3CgPubSpecBundle:SpecPG:create" }
+    requirements: { _method: post }
+
+admin_specpg_edit:
+    pattern:  /{id}/edit
+    defaults: { _controller: "OrgW3CgPubSpecBundle:SpecPG:edit" }
+
+admin_specpg_update:
+    pattern:  /{id}/update
+    defaults: { _controller: "OrgW3CgPubSpecBundle:SpecPG:update" }
+    requirements: { _method: post }
+
+admin_specpg_delete:
+    pattern:  /{id}/delete
+    defaults: { _controller: "OrgW3CgPubSpecBundle:SpecPG:delete" }
+    requirements: { _method: post }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Org/W3/Cg/Pub/SpecBundle/Resources/views/SpecPG/edit.html.twig	Wed Feb 29 13:49:54 2012 +0900
@@ -0,0 +1,22 @@
+<h1>SpecPG edit</h1>
+
+<form action="{{ path('admin_specpg_update', { 'id': entity.id }) }}" method="post" {{ form_enctype(edit_form) }}>
+    {{ form_widget(edit_form) }}
+    <p>
+        <button type="submit">Edit</button>
+    </p>
+</form>
+
+<ul class="record_actions">
+    <li>
+        <a href="{{ path('admin_specpg') }}">
+            Back to the list
+        </a>
+    </li>
+    <li>
+        <form action="{{ path('admin_specpg_delete', { 'id': entity.id }) }}" method="post">
+            {{ form_widget(delete_form) }}
+            <button type="submit">Delete</button>
+        </form>
+    </li>
+</ul>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Org/W3/Cg/Pub/SpecBundle/Resources/views/SpecPG/index.html.twig	Wed Feb 29 13:49:54 2012 +0900
@@ -0,0 +1,37 @@
+<h1>SpecPG list</h1>
+
+<table class="records_list">
+    <thead>
+        <tr>
+            <th>Spec</th>
+            <th>Group</th>
+            <th>Actions</th>
+        </tr>
+    </thead>
+    <tbody>
+    {% for entity in entities %}
+        <tr>
+            <td><a href="{{ path('admin_specpg_show', { 'id': entity.id }) }}">{{ entity.title }}</a></td>
+            <td>{{ groups[entity.id][0] }}</td>
+            <td>
+                <ul>
+                    <li>
+                        <a href="{{ path('admin_specpg_show', { 'id': entity.id }) }}">show</a>
+                    </li>
+                    <li>
+                        <a href="{{ path('admin_specpg_edit', { 'id': entity.id }) }}">edit</a>
+                    </li>
+                </ul>
+            </td>
+        </tr>
+    {% endfor %}
+    </tbody>
+</table>
+
+<ul>
+    <li>
+        <a href="{{ path('admin_specpg_new') }}">
+            Create a new entry
+        </a>
+    </li>
+</ul>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Org/W3/Cg/Pub/SpecBundle/Resources/views/SpecPG/new.html.twig	Wed Feb 29 13:49:54 2012 +0900
@@ -0,0 +1,16 @@
+<h1>SpecPG creation</h1>
+
+<form action="{{ path('admin_specpg_create') }}" method="post" {{ form_enctype(form) }}>
+    {{ form_widget(form) }}
+    <p>
+        <button type="submit">Create</button>
+    </p>
+</form>
+
+<ul class="record_actions">
+    <li>
+        <a href="{{ path('admin_specpg') }}">
+            Back to the list
+        </a>
+    </li>
+</ul>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Org/W3/Cg/Pub/SpecBundle/Resources/views/SpecPG/show.html.twig	Wed Feb 29 13:49:54 2012 +0900
@@ -0,0 +1,33 @@
+<h1>SpecPG</h1>
+
+<table class="record_properties">
+    <tbody>
+        <tr>
+            <th>Id</th>
+            <td>{{ entity.id }}</td>
+        </tr>
+        <tr>
+            <th>Grcode</th>
+            <td>{{ entity.grcode }}</td>
+        </tr>
+    </tbody>
+</table>
+
+<ul class="record_actions">
+    <li>
+        <a href="{{ path('admin_specpg') }}">
+            Back to the list
+        </a>
+    </li>
+    <li>
+        <a href="{{ path('admin_specpg_edit', { 'id': entity.id }) }}">
+            Edit
+        </a>
+    </li>
+    <li>
+        <form action="{{ path('admin_specpg_delete', { 'id': entity.id }) }}" method="post">
+            {{ form_widget(delete_form) }}
+            <button type="submit">Delete</button>
+        </form>
+    </li>
+</ul>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Org/W3/Cg/Pub/SpecBundle/Tests/Controller/SpecPGControllerTest.php	Wed Feb 29 13:49:54 2012 +0900
@@ -0,0 +1,54 @@
+<?php
+
+namespace Org\W3\Cg\Pub\SpecBundle\Tests\Controller;
+
+use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
+
+class SpecPGControllerTest extends WebTestCase
+{
+    /*
+    public function testCompleteScenario()
+    {
+        // Create a new client to browse the application
+        $client = static::createClient();
+
+        // Create a new entry in the database
+        $crawler = $client->request('GET', '/admin/specpg/');
+        $this->assertTrue(200 === $client->getResponse()->getStatusCode());
+        $crawler = $client->click($crawler->selectLink('Create a new entry')->link());
+
+        // Fill in the form and submit it
+        $form = $crawler->selectButton('Create')->form(array(
+            'specpg[field_name]'  => 'Test',
+            // ... other fields to fill
+        ));
+
+        $client->submit($form);
+        $crawler = $client->followRedirect();
+
+        // Check data in the show view
+        $this->assertTrue($crawler->filter('td:contains("Test")')->count() > 0);
+
+        // Edit the entity
+        $crawler = $client->click($crawler->selectLink('Edit')->link());
+
+        $form = $crawler->selectButton('Edit')->form(array(
+            'specpg[field_name]'  => 'Foo',
+            // ... other fields to fill
+        ));
+
+        $client->submit($form);
+        $crawler = $client->followRedirect();
+
+        // Check the element contains an attribute with value equals "Foo"
+        $this->assertTrue($crawler->filter('[value="Foo"]')->count() > 0);
+
+        // 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());
+    }
+    */
+}
\ No newline at end of file