Esempio n. 1
0
 public function apply(Application $app, Request $request)
 {
     $records = RecordsRequest::fromRequest($app, $request, false, ['candeleterecord']);
     $datas = ['success' => false, 'message' => ''];
     try {
         if (null === $request->request->get('base_id')) {
             $datas['message'] = $app->trans('Missing target collection');
             return $app->json($datas);
         }
         if (!$app['acl']->get($app['authentication']->getUser())->has_right_on_base($request->request->get('base_id'), 'canaddrecord')) {
             $datas['message'] = $app->trans("You do not have the permission to move records to %collection%", ['%collection%', \phrasea::bas_labels($request->request->get('base_id'), $app)]);
             return $app->json($datas);
         }
         try {
             $collection = \collection::get_from_base_id($app, $request->request->get('base_id'));
         } catch (\Exception_Databox_CollectionNotFound $e) {
             $datas['message'] = $app->trans('Invalid target collection');
             return $app->json($datas);
         }
         foreach ($records as $record) {
             $record->move_to_collection($collection, $app['phraseanet.appbox']);
             if ($request->request->get("chg_coll_son") == "1") {
                 foreach ($record->get_children() as $child) {
                     if ($app['acl']->get($app['authentication']->getUser())->has_right_on_base($child->get_base_id(), 'candeleterecord')) {
                         $child->move_to_collection($collection, $app['phraseanet.appbox']);
                     }
                 }
             }
         }
         $ret = ['success' => true, 'message' => $app->trans('Records have been successfuly moved')];
     } catch (\Exception $e) {
         $ret = ['success' => false, 'message' => $app->trans('An error occured')];
     }
     return $app->json($ret);
 }
Esempio n. 2
0
 public function createFeedEntryAction(Request $request)
 {
     $feed = $this->getFeedRepository()->find($request->request->get('feed_id'));
     if (null === $feed) {
         $this->app->abort(404, "Feed not found");
     }
     $user = $this->getAuthenticatedUser();
     $publisher = $this->getFeedPublisherRepository()->findOneBy(['feed' => $feed, 'user' => $user]);
     if ('' === ($title = trim($request->request->get('title', '')))) {
         $this->app->abort(400, "Bad request");
     }
     if (!$feed->isPublisher($user)) {
         $this->app->abort(403, 'Unauthorized action');
     }
     $entry = new FeedEntry();
     $entry->setAuthorEmail($request->request->get('author_mail'))->setAuthorName($request->request->get('author_name'))->setTitle($title)->setFeed($feed)->setPublisher($publisher)->setSubtitle($request->request->get('subtitle', ''));
     $feed->addEntry($entry);
     $publishing = RecordsRequest::fromRequest($this->app, $request, true, [], ['bas_chupub']);
     $manager = $this->getEntityManager();
     foreach ($publishing as $record) {
         $item = new FeedItem();
         $item->setEntry($entry)->setRecordId($record->get_record_id())->setSbasId($record->get_sbas_id());
         $entry->addItem($item);
         $manager->persist($item);
     }
     $manager->persist($entry);
     $manager->persist($feed);
     $manager->flush();
     $this->dispatch(PhraseaEvents::FEED_ENTRY_CREATE, new FeedEntryEvent($entry, $request->request->get('notify')));
     return $this->app->json(['error' => false, 'message' => false]);
 }
Esempio n. 3
0
 public function addElementsAction(Request $request, $sbas_id, $record_id)
 {
     $Story = new \record_adapter($this->app, $sbas_id, $record_id);
     if (!$this->getAclForUser()->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($this->app, $request, true);
     foreach ($records as $record) {
         if ($Story->hasChild($record)) {
             continue;
         }
         $Story->appendChild($record);
         $n++;
     }
     $this->dispatch(PhraseaEvents::RECORD_EDIT, new RecordEdit($Story));
     $data = ['success' => true, 'message' => $this->app->trans('%quantity% records added', ['%quantity%' => $n])];
     if ($request->getRequestFormat() == 'json') {
         return $this->app->json($data);
     }
     return $this->app->redirectPath('prod_stories_story', ['sbas_id' => $sbas_id, 'record_id' => $record_id]);
 }
Esempio n. 4
0
 public function connect(Application $app)
 {
     $app['controller.prod.feed'] = $this;
     $controllers = $app['controllers_factory'];
     $app['firewall']->addMandatoryAuthentication($controllers);
     $controllers->post('/requestavailable/', function (Application $app, Request $request) {
         $feeds = $app['EM']->getRepository('Phraseanet:Feed')->getAllForUser($app['acl']->get($app['authentication']->getUser()));
         $publishing = RecordsRequest::fromRequest($app, $request, true, [], ['bas_chupub']);
         return $app['twig']->render('prod/actions/publish/publish.html.twig', ['publishing' => $publishing, 'feeds' => $feeds]);
     });
     $controllers->post('/entry/create/', function (Application $app, Request $request) {
         $feed = $app['EM']->getRepository('Phraseanet:Feed')->find($request->request->get('feed_id'));
         if (null === $feed) {
             $app->abort(404, "Feed not found");
         }
         $publisher = $app['EM']->getRepository('Phraseanet:FeedPublisher')->findOneBy(['feed' => $feed, 'user' => $app['authentication']->getUser()]);
         if ('' === ($title = trim($request->request->get('title', '')))) {
             $app->abort(400, "Bad request");
         }
         if (!$feed->isPublisher($app['authentication']->getUser())) {
             $app->abort(403, 'Unathorized action');
         }
         $entry = new FeedEntry();
         $entry->setAuthorEmail($request->request->get('author_mail'))->setAuthorName($request->request->get('author_name'))->setTitle($title)->setFeed($feed)->setPublisher($publisher)->setSubtitle($request->request->get('subtitle', ''));
         $feed->addEntry($entry);
         $publishing = RecordsRequest::fromRequest($app, $request, true, [], ['bas_chupub']);
         foreach ($publishing as $record) {
             $item = new FeedItem();
             $item->setEntry($entry)->setRecordId($record->get_record_id())->setSbasId($record->get_sbas_id());
             $entry->addItem($item);
             $app['EM']->persist($item);
         }
         $app['EM']->persist($entry);
         $app['EM']->persist($feed);
         $app['EM']->flush();
         $app['events-manager']->trigger('__FEED_ENTRY_CREATE__', ['entry_id' => $entry->getId(), 'notify_email' => (bool) $request->request->get('notify')], $entry);
         $datas = ['error' => false, 'message' => false];
         return $app->json($datas);
     })->bind('prod_feeds_entry_create')->before(function (Request $request) use($app) {
         $app['firewall']->requireRight('bas_chupub');
     });
     $controllers->get('/entry/{id}/edit/', function (Application $app, Request $request, $id) {
         $entry = $app['EM']->getRepository('Phraseanet:FeedEntry')->find($id);
         if (!$entry->isPublisher($app['authentication']->getUser())) {
             throw new AccessDeniedHttpException();
         }
         $feeds = $app['EM']->getRepository('Phraseanet:Feed')->getAllForUser($app['acl']->get($app['authentication']->getUser()));
         $datas = $app['twig']->render('prod/actions/publish/publish_edit.html.twig', ['entry' => $entry, 'feeds' => $feeds]);
         return new Response($datas);
     })->bind('feed_entry_edit')->assert('id', '\\d+')->before(function (Request $request) use($app) {
         $app['firewall']->requireRight('bas_chupub');
     });
     $controllers->post('/entry/{id}/update/', function (Application $app, Request $request, $id) {
         $datas = ['error' => true, 'message' => '', 'datas' => ''];
         $entry = $app['EM']->getRepository('Phraseanet:FeedEntry')->find($id);
         if (null === $entry) {
             $app->abort(404, 'Entry not found');
         }
         if (!$entry->isPublisher($app['authentication']->getUser())) {
             $app->abort(403, 'Unathorized action');
         }
         if ('' === ($title = trim($request->request->get('title', '')))) {
             $app->abort(400, "Bad request");
         }
         $entry->setAuthorEmail($request->request->get('author_mail'))->setAuthorName($request->request->get('author_name'))->setTitle($title)->setSubtitle($request->request->get('subtitle', ''));
         $currentFeedId = $entry->getFeed()->getId();
         $new_feed_id = $request->request->get('feed_id', $currentFeedId);
         if ($currentFeedId !== (int) $new_feed_id) {
             $new_feed = $app['EM']->getRepository('Phraseanet:Feed')->find($new_feed_id);
             if ($new_feed === null) {
                 $app->abort(404, 'Feed not found');
             }
             if (!$new_feed->isPublisher($app['authentication']->getUser())) {
                 $app->abort(403, 'You are not publisher of this feed');
             }
             $entry->setFeed($new_feed);
         }
         $items = explode(';', $request->request->get('sorted_lst'));
         foreach ($items as $item_sort) {
             $item_sort_datas = explode('_', $item_sort);
             if (count($item_sort_datas) != 2) {
                 continue;
             }
             $item = $app['EM']->getRepository('Phraseanet:FeedItem')->find($item_sort_datas[0]);
             $item->setOrd($item_sort_datas[1]);
             $app['EM']->persist($item);
         }
         $app['EM']->persist($entry);
         $app['EM']->flush();
         return $app->json(['error' => false, 'message' => 'succes', 'datas' => $app['twig']->render('prod/feeds/entry.html.twig', ['entry' => $entry])]);
     })->bind('prod_feeds_entry_update')->assert('id', '\\d+')->before(function (Request $request) use($app) {
         $app['firewall']->requireRight('bas_chupub');
     });
     $controllers->post('/entry/{id}/delete/', function (Application $app, Request $request, $id) {
         $datas = ['error' => true, 'message' => ''];
         $entry = $app['EM']->getRepository('Phraseanet:FeedEntry')->find($id);
         if (null === $entry) {
             $app->abort(404, 'Entry not found');
         }
         if (!$entry->isPublisher($app['authentication']->getUser()) && $entry->getFeed()->isOwner($app['authentication']->getUser()) === false) {
             $app->abort(403, $app->trans('Action Forbidden : You are not the publisher'));
         }
         $app['EM']->remove($entry);
         $app['EM']->flush();
         return $app->json(['error' => false, 'message' => 'succes']);
     })->bind('prod_feeds_entry_delete')->assert('id', '\\d+')->before(function (Request $request) use($app) {
         $app['firewall']->requireRight('bas_chupub');
     });
     $controllers->get('/', function (Application $app, Request $request) {
         $request = $app['request'];
         $page = (int) $request->query->get('page');
         $page = $page > 0 ? $page : 1;
         $feeds = $app['EM']->getRepository('Phraseanet:Feed')->getAllForUser($app['acl']->get($app['authentication']->getUser()));
         $datas = $app['twig']->render('prod/feeds/feeds.html.twig', ['feeds' => $feeds, 'feed' => new Aggregate($app['EM'], $feeds), 'page' => $page]);
         return new Response($datas);
     })->bind('prod_feeds');
     $controllers->get('/feed/{id}/', function (Application $app, Request $request, $id) {
         $page = (int) $request->query->get('page');
         $page = $page > 0 ? $page : 1;
         $feed = $app['EM']->getRepository('Phraseanet:Feed')->find($id);
         if (!$feed->isAccessible($app['authentication']->getUser(), $app)) {
             $app->abort(404, 'Feed not found');
         }
         $feeds = $app['EM']->getRepository('Phraseanet:Feed')->getAllForUser($app['acl']->get($app['authentication']->getUser()));
         $datas = $app['twig']->render('prod/feeds/feeds.html.twig', ['feed' => $feed, 'feeds' => $feeds, 'page' => $page]);
         return new Response($datas);
     })->bind('prod_feeds_feed')->assert('id', '\\d+');
     $controllers->get('/subscribe/aggregated/', function (Application $app, Request $request) {
         $renew = $request->query->get('renew') === 'true';
         $feeds = $app['EM']->getRepository('Phraseanet:Feed')->getAllForUser($app['acl']->get($app['authentication']->getUser()));
         $link = $app['feed.aggregate-link-generator']->generate(new Aggregate($app['EM'], $feeds), $app['authentication']->getUser(), AggregateLinkGenerator::FORMAT_RSS, null, $renew);
         $output = ['texte' => '<p>' . $app->trans('publication::Voici votre fil RSS personnel. Il vous permettra d\'etre tenu au courrant des publications.') . '</p><p>' . $app->trans('publications::Ne le partagez pas, il est strictement confidentiel') . '</p>
         <div><input type="text" readonly="readonly" class="input_select_copy" value="' . $link->getURI() . '"/></div>', 'titre' => $app->trans('publications::votre rss personnel')];
         return $app->json($output);
     })->bind('prod_feeds_subscribe_aggregated');
     $controllers->get('/subscribe/{id}/', function (Application $app, Request $request, $id) {
         $renew = $request->query->get('renew') === 'true';
         $feed = $app['EM']->getRepository('Phraseanet:Feed')->find($id);
         if (!$feed->isAccessible($app['authentication']->getUser(), $app)) {
             $app->abort(404, 'Feed not found');
         }
         $link = $app['feed.user-link-generator']->generate($feed, $app['authentication']->getUser(), FeedLinkGenerator::FORMAT_RSS, null, $renew);
         $output = ['texte' => '<p>' . $app->trans('publication::Voici votre fil RSS personnel. Il vous permettra d\'etre tenu au courrant des publications.') . '</p><p>' . $app->trans('publications::Ne le partagez pas, il est strictement confidentiel') . '</p>
         <div><input type="text" style="width:100%" value="' . $link->getURI() . '"/></div>', 'titre' => $app->trans('publications::votre rss personnel')];
         return $app->json($output);
     })->bind('prod_feeds_subscribe_feed')->assert('id', '\\d+');
     return $controllers;
 }
Esempio n. 5
0
 public function addElements(Request $request, Basket $basket)
 {
     $n = 0;
     $records = RecordsRequest::fromRequest($this->app, $request, true);
     $em = $this->getEntityManager();
     foreach ($records as $record) {
         if ($basket->hasRecord($this->app, $record)) {
             continue;
         }
         $basket_element = new BasketElement();
         $basket_element->setRecord($record);
         $basket_element->setBasket($basket);
         $em->persist($basket_element);
         $basket->addElement($basket_element);
         if (null !== ($validationSession = $basket->getValidation())) {
             $participants = $validationSession->getParticipants();
             foreach ($participants as $participant) {
                 $validationData = new ValidationData();
                 $validationData->setParticipant($participant);
                 $validationData->setBasketElement($basket_element);
                 $em->persist($validationData);
             }
         }
         $n++;
     }
     $em->flush();
     $data = ['success' => true, 'message' => $this->app->trans('%quantity% records added', ['%quantity%' => $n])];
     if ($request->getRequestFormat() === 'json') {
         return $this->app->json($data);
     }
     return $this->app->redirectPath('prod_workzone_show');
 }
Esempio n. 6
0
 /**
  *  Renew url list of records
  *
  * @param Application $app
  * @param Request     $request
  *
  * @return JsonResponse
  */
 public function renewUrl(Application $app, Request $request)
 {
     $records = RecordsRequest::fromRequest($app, $request, !!$request->request->get('renew_children_url'));
     $renewed = [];
     foreach ($records as $record) {
         $renewed[$record->get_serialize_key()] = (string) $record->get_preview()->renew_url();
     }
     return $app->json($renewed);
 }
Esempio n. 7
0
 public function connect(Application $app)
 {
     $app['controller.prod.tools'] = $this;
     $controllers = $app['controllers_factory'];
     $app['firewall']->addMandatoryAuthentication($controllers);
     $controllers->before(function (Request $request) use($app) {
         $app['firewall']->requireRight('doctools');
     });
     $controllers->get('/', function (Application $app, Request $request) {
         $records = RecordsRequest::fromRequest($app, $request, false);
         $metadatas = false;
         $record = null;
         if (count($records) == 1) {
             $record = $records->first();
             if (!$record->is_grouping()) {
                 try {
                     $metadatas = $app['exiftool.reader']->files($record->get_subdef('document')->get_pathfile())->first()->getMetadatas();
                 } catch (PHPExiftoolException $e) {
                 } catch (\Exception_Media_SubdefNotFound $e) {
                 }
             }
         }
         $var = ['records' => $records, 'record' => $record, 'metadatas' => $metadatas];
         return $app['twig']->render('prod/actions/Tools/index.html.twig', $var);
     });
     $controllers->post('/rotate/', function (Application $app, Request $request) {
         $return = ['success' => true, 'errorMessage' => ''];
         $records = RecordsRequest::fromRequest($app, $request, false);
         $rotation = in_array($request->request->get('rotation'), ['-90', '90', '180']) ? $request->request->get('rotation', 90) : 90;
         foreach ($records as $record) {
             foreach ($record->get_subdefs() as $name => $subdef) {
                 if ($name == 'document') {
                     continue;
                 }
                 try {
                     $subdef->rotate($rotation, $app['media-alchemyst'], $app['mediavorus']);
                 } catch (\Exception $e) {
                 }
             }
         }
         return $app->json($return);
     })->bind('prod_tools_rotate');
     $controllers->post('/image/', function (Application $app, Request $request) {
         $return = ['success' => true];
         $selection = RecordsRequest::fromRequest($app, $request, false, ['canmodifrecord']);
         foreach ($selection as $record) {
             $substituted = false;
             foreach ($record->get_subdefs() as $subdef) {
                 if ($subdef->is_substituted()) {
                     $substituted = true;
                     break;
                 }
             }
             if (!$substituted || $request->request->get('ForceThumbSubstit') == '1') {
                 $record->rebuild_subdefs();
             }
         }
         return $app->json($return);
     })->bind('prod_tools_image');
     $controllers->post('/hddoc/', function (Application $app, Request $request) {
         $success = false;
         $message = $app->trans('An error occured');
         if ($file = $request->files->get('newHD')) {
             if ($file->isValid()) {
                 $fileName = $file->getClientOriginalName();
                 try {
                     $tempoDir = tempnam(sys_get_temp_dir(), 'substit');
                     unlink($tempoDir);
                     mkdir($tempoDir);
                     $tempoFile = $tempoDir . DIRECTORY_SEPARATOR . $fileName;
                     if (false === rename($file->getPathname(), $tempoFile)) {
                         throw new RuntimeException('Error while renaming file');
                     }
                     $record = new \record_adapter($app, $request->get('sbas_id'), $request->get('record_id'));
                     $media = $app['mediavorus']->guess($tempoFile);
                     $app['subdef.substituer']->substitute($record, 'document', $media);
                     $app['phraseanet.logger']($record->get_databox())->log($record, \Session_Logger::EVENT_SUBSTITUTE, 'HD', '');
                     if ((int) $request->request->get('ccfilename') === 1) {
                         $record->set_original_name($fileName);
                         $app['phraseanet.SE']->updateRecord($record);
                     }
                     unlink($tempoFile);
                     rmdir($tempoDir);
                     $success = true;
                     $message = $app->trans('Document has been successfully substitued');
                 } catch (\Exception $e) {
                     $message = $app->trans('file is not valid');
                 }
             } else {
                 $message = $app->trans('file is not valid');
             }
         } else {
             $app->abort(400, 'Missing file parameter');
         }
         return $app['twig']->render('prod/actions/Tools/iframeUpload.html.twig', ['success' => $success, 'message' => $message]);
     })->bind('prod_tools_hd_substitution');
     $controllers->post('/chgthumb/', function (Application $app, Request $request) {
         $success = false;
         $message = $app->trans('An error occured');
         if ($file = $request->files->get('newThumb')) {
             if ($file->isValid()) {
                 try {
                     $fileName = $file->getClientOriginalName();
                     $tempoDir = tempnam(sys_get_temp_dir(), 'substit');
                     unlink($tempoDir);
                     mkdir($tempoDir);
                     $tempoFile = $tempoDir . DIRECTORY_SEPARATOR . $fileName;
                     if (false === rename($file->getPathname(), $tempoFile)) {
                         throw new RuntimeException('Error while renaming file');
                     }
                     $record = new \record_adapter($app, $request->get('sbas_id'), $request->get('record_id'));
                     $media = $app['mediavorus']->guess($tempoFile);
                     $app['subdef.substituer']->substitute($record, 'thumbnail', $media);
                     $app['phraseanet.logger']($record->get_databox())->log($record, \Session_Logger::EVENT_SUBSTITUTE, 'thumbnail', '');
                     unlink($tempoFile);
                     rmdir($tempoDir);
                     $success = true;
                     $message = $app->trans('Thumbnail has been successfully substitued');
                 } catch (\Exception $e) {
                     $message = $app->trans('file is not valid');
                 }
             } else {
                 $message = $app->trans('file is not valid');
             }
         } else {
             $app->abort(400, 'Missing file parameter');
         }
         return $app['twig']->render('prod/actions/Tools/iframeUpload.html.twig', ['success' => $success, 'message' => $message]);
     })->bind('prod_tools_thumbnail_substitution');
     $controllers->post('/thumb-extractor/confirm-box/', function (Application $app, Request $request) {
         $return = ['error' => false, 'datas' => ''];
         $template = 'prod/actions/Tools/confirm.html.twig';
         try {
             $record = new \record_adapter($app, $request->request->get('sbas_id'), $request->request->get('record_id'));
             $var = ['video_title' => $record->get_title(), 'image' => $request->request->get('image', '')];
             $return['datas'] = $app['twig']->render($template, $var);
         } catch (\Exception $e) {
             $return['datas'] = $app->trans('an error occured');
             $return['error'] = true;
         }
         return $app->json($return);
     });
     $controllers->post('/thumb-extractor/apply/', function (Application $app, Request $request) {
         $return = ['success' => false, 'message' => ''];
         try {
             $record = new \record_adapter($app, $request->request->get('sbas_id'), $request->request->get('record_id'));
             $dataUri = DataURI\Parser::parse($request->request->get('image', ''));
             $path = $app['root.path'] . '/tmp';
             $name = sprintf('extractor_thumb_%s', $record->get_serialize_key());
             $fileName = sprintf('%s/%s.png', $path, $name);
             file_put_contents($fileName, $dataUri->getData());
             $media = $app['mediavorus']->guess($fileName);
             $app['subdef.substituer']->substitute($record, 'thumbnail', $media);
             $app['phraseanet.logger']($record->get_databox())->log($record, \Session_Logger::EVENT_SUBSTITUTE, 'thumbnail', '');
             unset($media);
             $app['filesystem']->remove($fileName);
             $return['success'] = true;
         } catch (\Exception $e) {
             $return['message'] = $e->getMessage();
         }
         return $app->json($return);
     });
     return $controllers;
 }
Esempio n. 8
0
 /**
  * Change record type
  *
  * @param  Application $app
  * @param  Request     $request
  * @return type
  */
 public function changeType(Application $app, Request $request)
 {
     $typeLst = $request->request->get('types', []);
     $records = RecordsRequest::fromRequest($app, $request, false, ['canmodifrecord']);
     $forceType = $request->request->get('force_types', '');
     $updated = [];
     foreach ($records as $record) {
         try {
             $recordType = !empty($forceType) ? $forceType : (isset($typeLst[$record->get_serialize_key()]) ? $typeLst[$record->get_serialize_key()] : null);
             if ($recordType) {
                 $record->set_type($recordType);
                 $updated[$record->get_serialize_key()] = $recordType;
             }
         } catch (\Exception $e) {
         }
     }
     return $app->json(['success' => true, 'updated' => $updated], 201);
 }
 public function testSimpleStoryFlattenAndPreserve()
 {
     $story = $this->getStoryWZ();
     $request = new Request(['story' => $story->getId()]);
     $records = RecordsRequest::fromRequest(self::$DI['app'], $request, RecordsRequest::FLATTEN_YES_PRESERVE_STORIES);
     $this->assertEquals(1 + $story->getRecord(self::$DI['app'])->get_children()->get_count(), count($records));
     $this->assertEquals(1, count($records->received()));
     $this->assertEquals(1, count($records->stories()));
     $this->assertInstanceOf('\\record_adapter', $records->singleStory());
     $this->assertTrue($records->isSingleStory());
     $this->assertCount(1, $records->databoxes());
     $serialized = $records->serializedList();
     $this->assertEquals($story->getRecord(self::$DI['app'])->get_serialize_key(), $serialized);
 }
Esempio n. 10
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;
 }
Esempio n. 11
0
 public function applyAction(Request $request)
 {
     $records = RecordsRequest::fromRequest($this->app, $request, RecordsRequest::FLATTEN_YES_PRESERVE_STORIES, ['canmodifrecord']);
     $databoxes = $records->databoxes();
     if (count($databoxes) !== 1) {
         throw new \Exception('Unable to edit on multiple databoxes');
     }
     /** @var \databox $databox */
     $databox = reset($databoxes);
     if ($request->request->get('act_option') == 'SAVEGRP' && $request->request->get('newrepresent') && $records->isSingleStory()) {
         try {
             $reg_record = $records->singleStory();
             $newsubdef_reg = new \record_adapter($this->app, $reg_record->get_sbas_id(), $request->request->get('newrepresent'));
             foreach ($newsubdef_reg->get_subdefs() as $name => $value) {
                 if (!in_array($name, ['thumbnail', 'preview'])) {
                     continue;
                 }
                 if ($value->get_type() !== \media_subdef::TYPE_IMAGE) {
                     continue;
                 }
                 $media = $this->app->getMediaFromUri($value->get_pathfile());
                 $this->getSubDefinitionSubstituer()->substitute($reg_record, $name, $media);
                 $this->getDispatcher()->dispatch(PhraseaEvents::RECORD_EDIT, new RecordEdit($reg_record));
                 $this->getDataboxLogger($reg_record->get_databox())->log($reg_record, \Session_Logger::EVENT_SUBSTITUTE, $name == 'document' ? 'HD' : $name, '');
             }
         } catch (\Exception $e) {
         }
     }
     if (!is_array($request->request->get('mds'))) {
         return $this->app->json(['message' => '', 'error' => false]);
     }
     $elements = $records->toArray();
     foreach ($request->request->get('mds') as $rec) {
         try {
             $record = $databox->get_record($rec['record_id']);
         } catch (\Exception $e) {
             continue;
         }
         $key = $record->get_serialize_key();
         if (!array_key_exists($key, $elements)) {
             continue;
         }
         $statbits = $rec['status'];
         $editDirty = $rec['edit'];
         if ($editDirty == '0') {
             $editDirty = false;
         } else {
             $editDirty = true;
         }
         if (isset($rec['metadatas']) && is_array($rec['metadatas'])) {
             $record->set_metadatas($rec['metadatas']);
             $this->getDispatcher()->dispatch(PhraseaEvents::RECORD_EDIT, new RecordEdit($record));
         }
         $newstat = $record->get_status();
         $statbits = ltrim($statbits, 'x');
         if (!in_array($statbits, ['', 'null'])) {
             $mask_and = ltrim(str_replace(['x', '0', '1', 'z'], ['1', 'z', '0', '1'], $statbits), '0');
             if ($mask_and != '') {
                 $newstat = \databox_status::operation_and_not($newstat, $mask_and);
             }
             $mask_or = ltrim(str_replace('x', '0', $statbits), '0');
             if ($mask_or != '') {
                 $newstat = \databox_status::operation_or($newstat, $mask_or);
             }
             $record->set_binary_status($newstat);
         }
         $record->write_metas()->get_collection()->reset_stamp($record->get_record_id());
         if ($statbits != '') {
             $this->getDataboxLogger($databox)->log($record, \Session_Logger::EVENT_STATUS, '', '');
         }
         if ($editDirty) {
             $this->getDataboxLogger($databox)->log($record, \Session_Logger::EVENT_EDIT, '', '');
         }
     }
     return $this->app->json(['success' => true]);
 }
Esempio n. 12
0
 public function imageAction(Request $request)
 {
     $return = ['success' => true];
     $force = $request->request->get('force_substitution') == '1';
     $selection = RecordsRequest::fromRequest($this->app, $request, false, array('canmodifrecord'));
     foreach ($selection as $record) {
         $substituted = false;
         foreach ($record->get_subdefs() as $subdef) {
             if ($subdef->is_substituted()) {
                 $substituted = true;
                 if ($force) {
                     // unset flag
                     $subdef->set_substituted(false);
                 }
                 break;
             }
         }
         if (!$substituted || $force) {
             $record->rebuild_subdefs();
         }
     }
     return $this->app->json($return);
 }
Esempio n. 13
0
 /**
  * Create a new order
  *
  * @param Application $app
  * @param Request     $request
  *
  * @return RedirectResponse|JsonResponse
  */
 public function createOrder(Application $app, Request $request)
 {
     $success = false;
     $collectionHasOrderAdmins = new ArrayCollection();
     $toRemove = [];
     $records = RecordsRequest::fromRequest($app, $request, true, ['cancmd']);
     $hasOneAdmin = [];
     if (!$records->isEmpty()) {
         $order = new OrderEntity();
         $order->setUser($app['authentication']->getUser());
         $order->setDeadline(null !== ($deadLine = $request->request->get('deadline')) ? new \DateTime($deadLine) : $deadLine);
         $order->setOrderUsage($request->request->get('use', ''));
         foreach ($records as $key => $record) {
             if ($collectionHasOrderAdmins->containsKey($record->get_base_id())) {
                 if (!$collectionHasOrderAdmins->get($record->get_base_id())) {
                     $records->remove($key);
                 }
             }
             if (!isset($hasOneAdmin[$record->get_base_id()])) {
                 $query = new \User_Query($app);
                 $hasOneAdmin[$record->get_base_id()] = (bool) count($query->on_base_ids([$record->get_base_id()])->who_have_right(['order_master'])->execute()->get_results());
             }
             $collectionHasOrderAdmins->set($record->get_base_id(), $hasOneAdmin[$record->get_base_id()]);
             if (!$hasOneAdmin[$record->get_base_id()]) {
                 $toRemove[] = $key;
             } else {
                 $orderElement = new OrderElement();
                 $order->addElement($orderElement);
                 $orderElement->setOrder($order);
                 $orderElement->setBaseId($record->get_base_id());
                 $orderElement->setRecordId($record->get_record_id());
                 $app['EM']->persist($orderElement);
             }
         }
         foreach ($toRemove as $key) {
             if ($records->containsKey($key)) {
                 $records->remove($key);
             }
         }
         $noAdmins = $collectionHasOrderAdmins->forAll(function ($key, $hasAdmin) {
             return false === $hasAdmin;
         });
         if ($noAdmins) {
             $msg = $app->trans('There is no one to validate orders, please contact an administrator');
         }
         $order->setTodo($order->getElements()->count());
         try {
             $app['events-manager']->trigger('__NEW_ORDER__', ['order_id' => $order->getId(), 'usr_id' => $order->getUser()->getId()]);
             $success = true;
             $app['EM']->persist($order);
             $app['EM']->flush();
         } catch (\Exception $e) {
         }
         if ($success) {
             $msg = $app->trans('The records have been properly ordered');
         } else {
             $msg = $app->trans('An error occured');
         }
     } else {
         $msg = $app->trans('There is no record eligible for an order');
     }
     if ('json' === $app['request']->getRequestFormat()) {
         return $app->json(['success' => $success, 'msg' => $msg]);
     }
     return $app->redirectPath('prod_orders', ['success' => (int) $success, 'action' => 'send']);
 }
Esempio n. 14
0
 public function connect(Application $app)
 {
     $app['controller.prod.edit'] = $this;
     $controllers = $app['controllers_factory'];
     $app['firewall']->addMandatoryAuthentication($controllers);
     $controllers->before(function (Request $request) use($app) {
         $app['firewall']->requireNotGuest()->requireRight('modifyrecord');
     });
     $controllers->post('/', function (Application $app, Request $request) {
         $records = RecordsRequest::fromRequest($app, $request, RecordsRequest::FLATTEN_YES_PRESERVE_STORIES, ['canmodifrecord']);
         $thesaurus = false;
         $status = $ids = $elements = $suggValues = $fields = $JSFields = [];
         $databox = null;
         $multipleDataboxes = count($records->databoxes()) > 1;
         if (1 === count($records->databoxes())) {
             $databoxes = $records->databoxes();
             $databox = array_pop($databoxes);
             /**
              * generate javascript fields
              */
             foreach ($databox->get_meta_structure() as $meta) {
                 $fields[] = $meta;
                 $separator = $meta->get_separator();
                 /** @Ignore */
                 $JSFields[$meta->get_id()] = ['meta_struct_id' => $meta->get_id(), 'name' => $meta->get_name(), '_status' => 0, '_value' => '', '_sgval' => [], 'required' => $meta->is_required(), 'label' => $meta->get_label($app['locale']), 'readonly' => $meta->is_readonly(), 'type' => $meta->get_type(), 'format' => '', 'explain' => '', 'tbranch' => $meta->get_tbranch(), 'maxLength' => $meta->get_tag()->getMaxLength(), 'minLength' => $meta->get_tag()->getMinLength(), 'multi' => $meta->is_multi(), 'separator' => $separator, 'vocabularyControl' => $meta->getVocabularyControl() ? $meta->getVocabularyControl()->getType() : null, 'vocabularyRestricted' => $meta->getVocabularyControl() ? $meta->isVocabularyRestricted() : false];
                 if (trim($meta->get_tbranch()) !== '') {
                     $thesaurus = true;
                 }
             }
             /**
              * generate javascript sugg values
              */
             foreach ($records->collections() as $collection) {
                 /* @var $record record_adapter */
                 $suggValues['b' . $collection->get_base_id()] = [];
                 if ($sxe = simplexml_load_string($collection->get_prefs())) {
                     $z = $sxe->xpath('/baseprefs/sugestedValues');
                     if (!$z || !is_array($z)) {
                         continue;
                     }
                     foreach ($z[0] as $ki => $vi) {
                         // les champs
                         $field = $databox->get_meta_structure()->get_element_by_name($ki);
                         if (!$field || !$vi) {
                             continue;
                         }
                         $suggValues['b' . $collection->get_base_id()][$field->get_id()] = [];
                         foreach ($vi->value as $oneValue) {
                             $suggValues['b' . $collection->get_base_id()][$field->get_id()][] = (string) $oneValue;
                         }
                     }
                 }
                 unset($collection);
             }
             /**
              * generate javascript status
              */
             if ($app['acl']->get($app['authentication']->getUser())->has_right('changestatus')) {
                 $dbstatus = \databox_status::getDisplayStatus($app);
                 if (isset($dbstatus[$databox->get_sbas_id()])) {
                     foreach ($dbstatus[$databox->get_sbas_id()] as $n => $statbit) {
                         $status[$n] = [];
                         $status[$n]['label0'] = $statbit['labels_off_i18n'][$app['locale']];
                         $status[$n]['label1'] = $statbit['labels_on_i18n'][$app['locale']];
                         $status[$n]['img_off'] = $statbit['img_off'];
                         $status[$n]['img_on'] = $statbit['img_on'];
                         $status[$n]['_value'] = 0;
                     }
                 }
             }
             /**
              * generate javascript elements
              */
             foreach ($databox->get_meta_structure() as $field) {
                 $databox_fields[$field->get_id()] = ['dirty' => false, 'meta_struct_id' => $field->get_id(), 'values' => []];
             }
             foreach ($records as $record) {
                 $indice = $record->get_number();
                 $elements[$indice] = ['bid' => $record->get_base_id(), 'rid' => $record->get_record_id(), 'sselcont_id' => null, '_selected' => false, 'fields' => $databox_fields];
                 $elements[$indice]['statbits'] = [];
                 if ($app['acl']->get($app['authentication']->getUser())->has_right_on_base($record->get_base_id(), 'chgstatus')) {
                     foreach ($status as $n => $s) {
                         $tmp_val = substr(strrev($record->get_status()), $n, 1);
                         $elements[$indice]['statbits'][$n]['value'] = $tmp_val == '1' ? '1' : '0';
                         $elements[$indice]['statbits'][$n]['dirty'] = false;
                     }
                 }
                 $elements[$indice]['originalname'] = $record->get_original_name();
                 foreach ($record->get_caption()->get_fields(null, true) as $field) {
                     $meta_struct_id = $field->get_meta_struct_id();
                     if (!isset($JSFields[$meta_struct_id])) {
                         continue;
                     }
                     $values = [];
                     foreach ($field->get_values() as $value) {
                         $type = $id = null;
                         if ($value->getVocabularyType()) {
                             $type = $value->getVocabularyType()->getType();
                             $id = $value->getVocabularyId();
                         }
                         $values[$value->getId()] = ['meta_id' => $value->getId(), 'value' => $value->getValue(), 'vocabularyId' => $id, 'vocabularyType' => $type];
                     }
                     $elements[$indice]['fields'][$meta_struct_id] = ['dirty' => false, 'meta_struct_id' => $meta_struct_id, 'values' => $values];
                 }
                 $elements[$indice]['subdefs'] = [];
                 $thumbnail = $record->get_thumbnail();
                 $elements[$indice]['subdefs']['thumbnail'] = ['url' => $thumbnail->get_url(), 'w' => $thumbnail->get_width(), 'h' => $thumbnail->get_height()];
                 $elements[$indice]['preview'] = $app['twig']->render('common/preview.html.twig', ['record' => $record]);
                 $elements[$indice]['type'] = $record->get_type();
             }
         }
         $params = ['multipleDataboxes' => $multipleDataboxes, 'recordsRequest' => $records, 'databox' => $databox, 'JSonStatus' => json_encode($status), 'JSonRecords' => json_encode($elements), 'JSonFields' => json_encode($JSFields), 'JSonIds' => json_encode(array_keys($elements)), 'status' => $status, 'fields' => $fields, 'JSonSuggValues' => json_encode($suggValues), 'thesaurus' => $thesaurus];
         return $app['twig']->render('prod/actions/edit_default.html.twig', $params);
     });
     $controllers->get('/vocabulary/{vocabulary}/', function (Application $app, Request $request, $vocabulary) {
         $datas = ['success' => false, 'message' => '', 'results' => []];
         $sbas_id = (int) $request->query->get('sbas_id');
         try {
             if ($sbas_id === 0) {
                 throw new \Exception('Invalid sbas_id');
             }
             $VC = VocabularyController::get($app, $vocabulary);
             $databox = $app['phraseanet.appbox']->get_databox($sbas_id);
         } catch (\Exception $e) {
             $datas['message'] = $app->trans('Vocabulary not found');
             return $app->json($datas);
         }
         $query = $request->query->get('query');
         $results = $VC->find($query, $app['authentication']->getUser(), $databox);
         $list = [];
         foreach ($results as $Term) {
             /* @var $Term \Alchemy\Phrasea\Vocabulary\Term */
             $list[] = ['id' => $Term->getId(), 'context' => $Term->getContext(), 'value' => $Term->getValue()];
         }
         $datas['success'] = true;
         $datas['results'] = $list;
         return $app->json($datas);
     });
     $controllers->post('/apply/', function (Application $app, Request $request) {
         $records = RecordsRequest::fromRequest($app, $request, RecordsRequest::FLATTEN_YES_PRESERVE_STORIES, ['canmodifrecord']);
         if (count($records->databoxes()) !== 1) {
             throw new \Exception('Unable to edit on multiple databoxes');
         }
         if ($request->request->get('act_option') == 'SAVEGRP' && $request->request->get('newrepresent') && $records->isSingleStory()) {
             try {
                 $reg_record = $records->singleStory();
                 $newsubdef_reg = new \record_adapter($app, $reg_record->get_sbas_id(), $request->request->get('newrepresent'));
                 if ($newsubdef_reg->get_type() !== 'image') {
                     throw new \Exception('A reg image must come from image data');
                 }
                 foreach ($newsubdef_reg->get_subdefs() as $name => $value) {
                     if (!in_array($name, ['thumbnail', 'preview'])) {
                         continue;
                     }
                     $media = $app['mediavorus']->guess($value->get_pathfile());
                     $app['subdef.substituer']->substitute($reg_record, $name, $media);
                     $app['phraseanet.logger']($reg_record->get_databox())->log($reg_record, \Session_Logger::EVENT_SUBSTITUTE, $name == 'document' ? 'HD' : $name, '');
                 }
             } catch (\Exception $e) {
             }
         }
         if (!is_array($request->request->get('mds'))) {
             return $app->json(['message' => '', 'error' => false]);
         }
         $databoxes = $records->databoxes();
         $databox = array_pop($databoxes);
         $meta_struct = $databox->get_meta_structure();
         $write_edit_el = false;
         $date_obj = new \DateTime();
         foreach ($meta_struct->get_elements() as $meta_struct_el) {
             if ($meta_struct_el->get_tag() instanceof TfEditdate) {
                 $write_edit_el = $meta_struct_el;
             }
         }
         $elements = $records->toArray();
         foreach ($request->request->get('mds') as $rec) {
             try {
                 $record = $databox->get_record($rec['record_id']);
             } catch (\Exception $e) {
                 continue;
             }
             $key = $record->get_serialize_key();
             if (!array_key_exists($key, $elements)) {
                 continue;
             }
             $statbits = $rec['status'];
             $editDirty = $rec['edit'];
             if ($editDirty == '0') {
                 $editDirty = false;
             } else {
                 $editDirty = true;
             }
             if (is_array($rec['metadatas'])) {
                 $record->set_metadatas($rec['metadatas']);
             }
             /**
              * todo : this should not work
              */
             if ($write_edit_el instanceof \databox_field) {
                 $fields = $record->get_caption()->get_fields([$write_edit_el->get_name()], true);
                 $field = array_pop($fields);
                 $meta_id = null;
                 if ($field && !$field->is_multi()) {
                     $values = $field->get_values();
                     $meta_id = array_pop($values)->getId();
                 }
                 $metas = [['meta_struct_id' => $write_edit_el->get_id(), 'meta_id' => $meta_id, 'value' => $date_obj->format('Y-m-d h:i:s')]];
                 $record->set_metadatas($metas, true);
             }
             $newstat = $record->get_status();
             $statbits = ltrim($statbits, 'x');
             if (!in_array($statbits, ['', 'null'])) {
                 $mask_and = ltrim(str_replace(['x', '0', '1', 'z'], ['1', 'z', '0', '1'], $statbits), '0');
                 if ($mask_and != '') {
                     $newstat = \databox_status::operation_and_not($app, $newstat, $mask_and);
                 }
                 $mask_or = ltrim(str_replace('x', '0', $statbits), '0');
                 if ($mask_or != '') {
                     $newstat = \databox_status::operation_or($app, $newstat, $mask_or);
                 }
                 $record->set_binary_status($newstat);
             }
             $record->write_metas()->get_collection()->reset_stamp($record->get_record_id());
             if ($statbits != '') {
                 $app['phraseanet.logger']($record->get_databox())->log($record, \Session_Logger::EVENT_STATUS, '', '');
             }
             if ($editDirty) {
                 $app['phraseanet.logger']($record->get_databox())->log($record, \Session_Logger::EVENT_EDIT, '', '');
             }
         }
         return $app->json(['success' => true]);
     });
     return $controllers;
 }