Exemplo n.º 1
0
 public function attachStories(Request $request)
 {
     if (!$request->request->get('stories')) {
         throw new BadRequestHttpException('Missing parameters stories');
     }
     $storyWZRepo = $this->getStoryWZRepository();
     $alreadyFixed = $done = 0;
     $stories = $request->request->get('stories', []);
     $user = $this->getAuthenticatedUser();
     $acl = $this->getAclForUser($user);
     $manager = $this->getEntityManager();
     foreach ($stories as $element) {
         $element = explode('_', $element);
         $story = new \record_adapter($this->app, $element[0], $element[1]);
         if (!$story->isStory()) {
             throw new \Exception('You can only attach stories');
         }
         if (!$acl->has_access_to_base($story->get_base_id())) {
             throw new AccessDeniedHttpException('You do not have access to this Story');
         }
         if ($storyWZRepo->findUserStory($this->app, $user, $story)) {
             $alreadyFixed++;
             continue;
         }
         $storyWZ = new StoryWZ();
         $storyWZ->setUser($user);
         $storyWZ->setRecord($story);
         $manager->persist($storyWZ);
         $done++;
     }
     $manager->flush();
     if ($alreadyFixed === 0) {
         if ($done <= 1) {
             $message = $this->app->trans('%quantity% Story attached to the WorkZone', ['%quantity%' => $done]);
         } else {
             $message = $this->app->trans('%quantity% Stories attached to the WorkZone', ['%quantity%' => $done]);
         }
     } else {
         if ($done <= 1) {
             $message = $this->app->trans('%quantity% Story attached to the WorkZone, %quantity_already% already attached', ['%quantity%' => $done, '%quantity_already%' => $alreadyFixed]);
         } else {
             $message = $this->app->trans('%quantity% Stories attached to the WorkZone, %quantity_already% already attached', ['%quantity%' => $done, '%quantity_already%' => $alreadyFixed]);
         }
     }
     if ($request->getRequestFormat() == 'json') {
         return $this->app->json(['success' => true, 'message' => $message]);
     }
     return $this->app->redirectPath('prod_workzone_show');
 }
Exemplo n.º 2
0
 public function postCreateFormAction(Request $request)
 {
     $collection = \collection::get_from_base_id($this->app, $request->request->get('base_id'));
     if (!$this->getAclForUser()->has_right_on_base($collection->get_base_id(), 'canaddrecord')) {
         throw new AccessDeniedHttpException('You can not create a story on this collection');
     }
     $story = \record_adapter::createStory($this->app, $collection);
     $records = RecordsRequest::fromRequest($this->app, $request, true);
     foreach ($records as $record) {
         if ($story->hasChild($record)) {
             continue;
         }
         $story->appendChild($record);
     }
     $metadatas = [];
     foreach ($collection->get_databox()->get_meta_structure() as $meta) {
         if ($meta->get_thumbtitle()) {
             $value = $request->request->get('name');
         } else {
             continue;
         }
         $metadatas[] = ['meta_struct_id' => $meta->get_id(), 'meta_id' => null, 'value' => $value];
         break;
     }
     $story->set_metadatas($metadatas)->rebuild_subdefs();
     $storyWZ = new StoryWZ();
     $storyWZ->setUser($this->getAuthenticatedUser());
     $storyWZ->setRecord($story);
     $manager = $this->getEntityManager();
     $manager->persist($storyWZ);
     $manager->flush();
     if ($request->getRequestFormat() == 'json') {
         $data = ['success' => true, 'message' => $this->app->trans('Story created'), 'WorkZone' => $storyWZ->getId(), 'story' => ['sbas_id' => $story->get_sbas_id(), 'record_id' => $story->get_record_id()]];
         return $this->app->json($data);
     }
     return $this->app->redirectPath('prod_stories_story', ['sbas_id' => $storyWZ->getSbasId(), 'record_id' => $storyWZ->getRecordId()]);
 }
 private function insertOneStoryInWz(EntityManager $em, \Pimple $DI)
 {
     $story = new StoryWZ();
     $story->setRecord($DI['record_story_1']);
     $story->setUser($DI['user']);
     $em->persist($story);
 }
Exemplo n.º 4
0
 public function connect(Application $app)
 {
     $app['controller.prod.story'] = $this;
     $controllers = $app['controllers_factory'];
     $app['firewall']->addMandatoryAuthentication($controllers);
     $controllers->get('/create/', function (Application $app) {
         return $app['twig']->render('prod/Story/Create.html.twig', []);
     })->bind('prod_stories_create');
     $controllers->post('/', function (Application $app, Request $request) {
         /* @var $request \Symfony\Component\HttpFoundation\Request */
         $collection = \collection::get_from_base_id($app, $request->request->get('base_id'));
         if (!$app['acl']->get($app['authentication']->getUser())->has_right_on_base($collection->get_base_id(), 'canaddrecord')) {
             throw new AccessDeniedHttpException('You can not create a story on this collection');
         }
         $Story = \record_adapter::createStory($app, $collection);
         $records = RecordsRequest::fromRequest($app, $request, true);
         foreach ($records as $record) {
             if ($Story->hasChild($record)) {
                 continue;
             }
             $Story->appendChild($record);
         }
         $metadatas = [];
         foreach ($collection->get_databox()->get_meta_structure() as $meta) {
             if ($meta->get_thumbtitle()) {
                 $value = $request->request->get('name');
             } else {
                 continue;
             }
             $metadatas[] = ['meta_struct_id' => $meta->get_id(), 'meta_id' => null, 'value' => $value];
             break;
         }
         $Story->set_metadatas($metadatas)->rebuild_subdefs();
         $StoryWZ = new StoryWZ();
         $StoryWZ->setUser($app['authentication']->getUser());
         $StoryWZ->setRecord($Story);
         $app['EM']->persist($StoryWZ);
         $app['EM']->flush();
         if ($request->getRequestFormat() == 'json') {
             $data = ['success' => true, 'message' => $app->trans('Story created'), 'WorkZone' => $StoryWZ->getId(), 'story' => ['sbas_id' => $Story->get_sbas_id(), 'record_id' => $Story->get_record_id()]];
             return $app->json($data);
         } else {
             return $app->redirectPath('prod_stories_story', ['sbas_id' => $StoryWZ->getSbasId(), 'record_id' => $StoryWZ->getRecordId()]);
         }
     })->bind('prod_stories_do_create');
     $controllers->get('/{sbas_id}/{record_id}/', function (Application $app, $sbas_id, $record_id) {
         $Story = new \record_adapter($app, $sbas_id, $record_id);
         $html = $app['twig']->render('prod/WorkZone/Story.html.twig', ['Story' => $Story]);
         return new Response($html);
     })->bind('prod_stories_story')->assert('sbas_id', '\\d+')->assert('record_id', '\\d+');
     $controllers->post('/{sbas_id}/{record_id}/addElements/', function (Application $app, Request $request, $sbas_id, $record_id) {
         $Story = new \record_adapter($app, $sbas_id, $record_id);
         if (!$app['acl']->get($app['authentication']->getUser())->has_right_on_base($Story->get_base_id(), 'canmodifrecord')) {
             throw new AccessDeniedHttpException('You can not add document to this Story');
         }
         $n = 0;
         $records = RecordsRequest::fromRequest($app, $request, true);
         foreach ($records as $record) {
             if ($Story->hasChild($record)) {
                 continue;
             }
             $Story->appendChild($record);
             $n++;
         }
         $data = ['success' => true, 'message' => $app->trans('%quantity% records added', ['%quantity%' => $n])];
         if ($request->getRequestFormat() == 'json') {
             return $app->json($data);
         } else {
             return $app->redirectPath('prod_stories_story', ['sbas_id' => $sbas_id, 'record_id' => $record_id]);
         }
     })->assert('sbas_id', '\\d+')->assert('record_id', '\\d+');
     $controllers->post('/{sbas_id}/{record_id}/delete/{child_sbas_id}/{child_record_id}/', function (Application $app, Request $request, $sbas_id, $record_id, $child_sbas_id, $child_record_id) {
         $Story = new \record_adapter($app, $sbas_id, $record_id);
         $record = new \record_adapter($app, $child_sbas_id, $child_record_id);
         if (!$app['acl']->get($app['authentication']->getUser())->has_right_on_base($Story->get_base_id(), 'canmodifrecord')) {
             throw new AccessDeniedHttpException('You can not add document to this Story');
         }
         $Story->removeChild($record);
         $data = ['success' => true, 'message' => $app->trans('Record removed from story')];
         if ($request->getRequestFormat() == 'json') {
             return $app->json($data);
         } else {
             return $app->redirectPath('prod_stories_story', ['sbas_id' => $sbas_id, 'record_id' => $record_id]);
         }
     })->bind('prod_stories_story_remove_element')->assert('sbas_id', '\\d+')->assert('record_id', '\\d+')->assert('child_sbas_id', '\\d+')->assert('child_record_id', '\\d+');
     /**
      * Get the Basket reorder form
      */
     $controllers->get('/{sbas_id}/{record_id}/reorder/', function (Application $app, $sbas_id, $record_id) {
         $story = new \record_adapter($app, $sbas_id, $record_id);
         if (!$story->is_grouping()) {
             throw new \Exception('This is not a story');
         }
         return new Response($app['twig']->render('prod/Story/Reorder.html.twig', ['story' => $story]));
     })->bind('prod_stories_story_reorder')->assert('sbas_id', '\\d+')->assert('record_id', '\\d+');
     $controllers->post('/{sbas_id}/{record_id}/reorder/', function (Application $app, $sbas_id, $record_id) {
         $ret = ['success' => false, 'message' => $app->trans('An error occured')];
         try {
             $story = new \record_adapter($app, $sbas_id, $record_id);
             if (!$story->is_grouping()) {
                 throw new \Exception('This is not a story');
             }
             if (!$app['acl']->get($app['authentication']->getUser())->has_right_on_base($story->get_base_id(), 'canmodifrecord')) {
                 throw new ControllerException($app->trans('You can not edit this story'));
             }
             $sql = 'UPDATE regroup SET ord = :ord
           WHERE rid_parent = :parent_id AND rid_child = :children_id';
             $stmt = $story->get_databox()->get_connection()->prepare($sql);
             foreach ($app['request']->request->get('element') as $record_id => $ord) {
                 $params = [':ord' => $ord, ':parent_id' => $story->get_record_id(), ':children_id' => $record_id];
                 $stmt->execute($params);
             }
             $stmt->closeCursor();
             $ret = ['success' => true, 'message' => $app->trans('Story updated')];
         } catch (ControllerException $e) {
             $ret = ['success' => false, 'message' => $e->getMessage()];
         } catch (\Exception $e) {
         }
         return $app->json($ret);
     })->assert('sbas_id', '\\d+')->assert('record_id', '\\d+');
     return $controllers;
 }
 /**
  * {@inheritDoc}
  */
 public function getCreated()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getCreated', array());
     return parent::getCreated();
 }