diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Story.php b/lib/Alchemy/Phrasea/Controller/Prod/Story.php index 6bee59b3d4..40f2363161 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Story.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Story.php @@ -219,91 +219,6 @@ class Story implements ControllerProviderInterface return new RedirectResponse('/'); } }); - - $controllers->post( - '/{sbas_id}/{record_id}/attach/' - , function(Application $app, Request $request, $sbas_id, $record_id) - { - $Story = new \record_adapter($sbas_id, $record_id); - - if (!$Story->is_grouping()) - throw new \Exception('You can only attach stories'); - - $user = $app['Core']->getAuthenticatedUser(); - - if (!$user->ACL()->has_access_to_base($Story->get_base_id())) - throw new \Exception_Forbidden('You do not have access to this Story'); - - $em = $app['Core']->getEntityManager(); - /* @var $em \Doctrine\ORM\EntityManager */ - $StoryWZ = new \Entities\StoryWZ(); - $StoryWZ->setUser($user); - $StoryWZ->setRecord($Story); - - $em->persist($StoryWZ); - - $em->flush(); - - $data = array( - 'success' => true - , 'message' => _('Story attached to the WorkZone') - , 'StoryWZ' => array( - 'id' => $StoryWZ->getId() - ) - ); - - if ($request->getRequestFormat() == 'json') - { - - $datas = $app['Core']['Serializer']->serialize($data, 'json'); - - return new Response($datas, 200, array('Content-type' => 'application/json')); - } - else - { - return new RedirectResponse('/{sbas_id}/{record_id}/'); - } - }); - $controllers->post( - '/{sbas_id}/{record_id}/detach/' - , function(Application $app, Request $request, $sbas_id, $record_id) - { - $Story = new \record_adapter($sbas_id, $record_id); - - $user = $app['Core']->getAuthenticatedUser(); - - $em = $app['Core']->getEntityManager(); - - $repository = $em->getRepository('\Entities\StoryWZ'); - - /* @var $repository \Repositories\StoryWZRepository */ - $StoryWZ = $repository->findUserStory($user, $Story); - - if (!$StoryWZ) - { - throw new \Exception_NotFound('Story not found'); - } - $em->remove($StoryWZ); - - $em->flush(); - - $data = array( - 'success' => true - , 'message' => _('Story detached from the WorkZone') - ); - - if ($request->getRequestFormat() == 'json') - { - $datas = $app['Core']['Serializer']->serialize($data, 'json'); - - return new Response($datas, 200, array('Content-type' => 'application/json')); - } - else - { - return new RedirectResponse('/'); - } - }); - // $controllers->post('/{basket_id}/delete/', function(Application $app, Request $request, $basket_id) // { // $em = $app['Core']->getEntityManager(); diff --git a/lib/Alchemy/Phrasea/Controller/Prod/WorkZone.php b/lib/Alchemy/Phrasea/Controller/Prod/WorkZone.php index 0dc38afd19..4edf8ddbd5 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/WorkZone.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/WorkZone.php @@ -50,6 +50,147 @@ class WorkZone implements ControllerProviderInterface return new Response($twig->render('prod/WorkZone/WorkZone.html.twig', $params)); }); + + $controllers->post( + '/attachStories/' + , function(Application $app, Request $request) + { + + + $user = $app['Core']->getAuthenticatedUser(); + + $em = $app['Core']->getEntityManager(); + /* @var $em \Doctrine\ORM\EntityManager */ + + $StoryWZRepo = $em->getRepository('\Entities\StoryWZ'); + + $alreadyFixed = $done = 0; + + foreach ($request->get('stories') as $element) + { + $element = explode('_', $element); + $Story = new \record_adapter($element[0], $element[1]); + + if (!$Story->is_grouping()) + throw new \Exception('You can only attach stories'); + + if (!$user->ACL()->has_access_to_base($Story->get_base_id())) + throw new \Exception_Forbidden('You do not have access to this Story'); + + + if ($StoryWZRepo->findUserStory($user, $Story)) + { + $alreadyFixed++; + continue; + } + + $StoryWZ = new \Entities\StoryWZ(); + $StoryWZ->setUser($user); + $StoryWZ->setRecord($Story); + + $em->persist($StoryWZ); + $done++; + } + + $em->flush(); + + if ($alreadyFixed === 0) + { + if ($done <= 1) + { + $message = sprintf( + _('%d Story attached to the WorkZone') + , $done + ); + } + else + { + $message = sprintf( + _('%d Stories attached to the WorkZone') + , $done + ); + } + } + else + { + if ($done <= 1) + { + $message = sprintf( + _('%1$d Story attached to the WorkZone, %2$d already attached') + , $done + , $alreadyFixed + ); + } + else + { + $message = sprintf( + _('%1$d Story attached to the WorkZone, %2$d already attached') + , $done + , $alreadyFixed + ); + } + } + + $data = array( + 'success' => true + , 'message' => $message + ); + + if ($request->getRequestFormat() == 'json') + { + + $datas = $app['Core']['Serializer']->serialize($data, 'json'); + + return new Response($datas, 200, array('Content-type' => 'application/json')); + } + else + { + return new RedirectResponse('/{sbas_id}/{record_id}/'); + } + }); + + + $controllers->post( + '/detachStory/{sbas_id}/{record_id}/' + , function(Application $app, Request $request, $sbas_id, $record_id) + { + $Story = new \record_adapter($sbas_id, $record_id); + + $user = $app['Core']->getAuthenticatedUser(); + + $em = $app['Core']->getEntityManager(); + + $repository = $em->getRepository('\Entities\StoryWZ'); + + /* @var $repository \Repositories\StoryWZRepository */ + $StoryWZ = $repository->findUserStory($user, $Story); + + if (!$StoryWZ) + { + throw new \Exception_NotFound('Story not found'); + } + $em->remove($StoryWZ); + + $em->flush(); + + $data = array( + 'success' => true + , 'message' => _('Story detached from the WorkZone') + ); + + if ($request->getRequestFormat() == 'json') + { + $datas = $app['Core']['Serializer']->serialize($data, 'json'); + + return new Response($datas, 200, array('Content-type' => 'application/json')); + } + else + { + return new RedirectResponse('/'); + } + }); + + return $controllers; } diff --git a/templates/web/prod/WorkZone/Macros.twig b/templates/web/prod/WorkZone/Macros.twig index 4fea15f450..f04f6dcd38 100644 --- a/templates/web/prod/WorkZone/Macros.twig +++ b/templates/web/prod/WorkZone/Macros.twig @@ -77,8 +77,10 @@
-