GitHub PullRequestReviewCommentEvent at 2014-01-30 11:50:03
Repository: pim-community-dev
Actor: fitn
Payload: {"comment":{"url":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/comments/9302729","id":9302729,"diff_hunk":"@@ -0,0 +1,133 @@\n+<?php\n+\n+namespace Pim\\Bundle\\EnrichBundle\\Controller;\n+\n+use Symfony\\Component\\HttpFoundation\\Request;\n+use Symfony\\Bundle\\FrameworkBundle\\Templating\\EngineInterface;\n+use Symfony\\Component\\Security\\Core\\SecurityContextInterface;\n+use Symfony\\Component\\Routing\\RouterInterface;\n+use Symfony\\Component\\Form\\FormFactoryInterface;\n+use Symfony\\Component\\Validator\\ValidatorInterface;\n+use Symfony\\Component\\Translation\\TranslatorInterface;\n+use Symfony\\Bridge\\Doctrine\\RegistryInterface;\n+use Oro\\Bundle\\DataGridBundle\\Datagrid\\Manager as DatagridManager;\n+use Oro\\Bundle\\UserBundle\\Entity\\User;\n+use Pim\\Bundle\\EnrichBundle\\Entity\\DatagridConfiguration;\n+use Pim\\Bundle\\EnrichBundle\\AbstractController\\AbstractDoctrineController;\n+\n+/**\n+ * Datagrid configuration controller\n+ *\n+ * @author    Gildas Quemener <gildas@akeneo.com>\n+ * @copyright 2014 Akeneo SAS (http://www.akeneo.com)\n+ * @license   http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)\n+ */\n+class DatagridController extends AbstractDoctrineController\n+{\n+    /** @var DatagridManager */\n+    protected $manager;\n+\n+    /**\n+     * Constructor\n+     *\n+     * @param Request                  $request\n+     * @param EngineInterface          $templating\n+     * @param RouterInterface          $router\n+     * @param SecurityContextInterface $securityContext\n+     * @param FormFactoryInterface     $formFactory\n+     * @param ValidatorInterface       $validator\n+     * @param TranslatorInterface      $translator\n+     * @param DatagridManager          $manager\n+     */\n+    public function __construct(\n+        Request $request,\n+        EngineInterface $templating,\n+        RouterInterface $router,\n+        SecurityContextInterface $securityContext,\n+        FormFactoryInterface $formFactory,\n+        ValidatorInterface $validator,\n+        TranslatorInterface $translator,\n+        RegistryInterface $doctrine,\n+        DatagridManager $manager\n+    ) {\n+        parent::__construct($request, $templating, $router, $securityContext, $formFactory, $validator, $translator, $doctrine);\n+\n+        $this->manager = $manager;\n+    }\n+\n+    /**\n+     * {@inheritdoc}\n+     */\n+    public function editAction(Request $request, $alias)\n+    {\n+        $user    = $this->getUser();\n+        $columns = $this->getColumnChoices($alias);\n+\n+        if (null === $configuration = $this->getDatagridConfiguration($alias, $user)) {\n+            $configuration = new DatagridConfiguration();\n+            $configuration->setUser($user);\n+            $configuration->setDatagridAlias($alias);\n+            $configuration->setColumns(array_keys($columns));\n+        }\n+\n+        $form = $this->createForm('pim_catalog_datagrid_configuration', $configuration, [\n+            'columns' => $this->sortArrayByArray($columns, $configuration->getColumns()),\n+            'action'  => $this->generateUrl('pim_catalog_datagrid_edit', ['alias' => $alias]),\n+        ]);\n+\n+        if ($request->isMethod('POST')) {\n+            $form->submit($request);\n+            if ($form->isValid()) {\n+                $em = $this->getEntityManager();\n+                $em->persist($configuration);\n+                $em->flush();\n+\n+                return $this->redirectToRoute('pim_enrich_product_index');\n+            }\n+        }\n+\n+        return $this->render('PimEnrichBundle:Datagrid:edit.html.twig', [\n+            'form' => $form->createView(),\n+        ]);\n+    }\n+\n+    protected function sortArrayByArray($array, $orderArray)\n+    {\n+        $ordered = [];\n+        foreach ($orderArray as $key) {\n+            if (array_key_exists($key, $array)) {\n+                $ordered[$key] = $array[$key];\n+                unset($array[$key]);\n+            }\n+        }\n+\n+        return $ordered + $array;\n+    }\n+\n+    protected function getColumnChoices($alias)\n+    {\n+        return $this\n+            ->manager\n+            ->getDatagrid($alias)\n+            ->getAcceptor()\n+            ->getConfig()\n+            ->offsetGetByPath('[availableColumns]');\n+    }\n+\n+    protected function getEntityManager()","path":"src/Pim/Bundle/EnrichBundle/Controller/DatagridController.php","position":117,"original_position":117,"commit_id":"b8e8557f79288553bd0eb5834a27fd7be5fb1712","original_commit_id":"b8e8557f79288553bd0eb5834a27fd7be5fb1712","user":{"login":"fitn","id":2131005,"avatar_url":"https://gravatar.com/avatar/daa55101043f4b63e82527b065a99c0d?d=https%3A%2F%2Fidenticons.github.com%2Fac3bf70634f25976ce0bd403b81c31f3.png&r=x","gravatar_id":"daa55101043f4b63e82527b065a99c0d","url":"https://api.github.com/users/fitn","html_url":"https://github.com/fitn","followers_url":"https://api.github.com/users/fitn/followers","following_url":"https://api.github.com/users/fitn/following{/other_user}","gists_url":"https://api.github.com/users/fitn/gists{/gist_id}","starred_url":"https://api.github.com/users/fitn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fitn/subscriptions","organizations_url":"https://api.github.com/users/fitn/orgs","repos_url":"https://api.github.com/users/fitn/repos","events_url":"https://api.github.com/users/fitn/events{/privacy}","received_events_url":"https://api.github.com/users/fitn/received_events","type":"User","site_admin":false},"body":"Please add phpdoc","created_at":"2014-01-30T11:50:03Z","updated_at":"2014-01-30T11:50:03Z","html_url":"https://github.com/akeneo/pim-community-dev/pull/687#discussion_r9302729","pull_request_url":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/687","_links":{"self":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/comments/9302729"},"html":{"href":"https://github.com/akeneo/pim-community-dev/pull/687#discussion_r9302729"},"pull_request":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/687"}}}}