diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Basket.php b/lib/Alchemy/Phrasea/Controller/Prod/Basket.php index d9049a7b33..5f7cfe5230 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Basket.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Basket.php @@ -126,20 +126,18 @@ class Basket implements ControllerProviderInterface public function displayBasket(Application $app, Request $request, $basket_id) { - $em = $app['phraseanet.core']->getEntityManager(); - - $basket = $em->getRepository('\Entities\Basket') - ->findUserBasket($basket_id, $app['phraseanet.core']->getAuthenticatedUser(), false); + $basket = $app['EM']->getRepository('\Entities\Basket') + ->findUserBasket($app, $basket_id, $app['phraseanet.user'], false); if ($basket->getIsRead() === false) { $basket->setIsRead(true); - $em->flush(); + $app['EM']->flush(); } if ($basket->getValidation()) { - if ($basket->getValidation()->getParticipant($app['phraseanet.core']->getAuthenticatedUser())->getIsAware() === false) { - $basket->getValidation()->getParticipant($app['phraseanet.core']->getAuthenticatedUser())->setIsAware(true); - $em->flush(); + if ($basket->getValidation()->getParticipant($app['phraseanet.user'], $app)->getIsAware() === false) { + $basket->getValidation()->getParticipant($app['phraseanet.user'], $app)->setIsAware(true); + $app['EM']->flush(); } } @@ -156,22 +154,20 @@ class Basket implements ControllerProviderInterface $request = $app['request']; /* @var $request \Symfony\Component\HttpFoundation\Request */ - $em = $app['phraseanet.core']->getEntityManager(); - $Basket = new BasketEntity(); $Basket->setName($request->request->get('name', '')); - $Basket->setOwner($app['phraseanet.core']->getAuthenticatedUser()); + $Basket->setOwner($app['phraseanet.user']); $Basket->setDescription($request->request->get('desc')); - $em->persist($Basket); + $app['EM']->persist($Basket); $n = 0; $records = RecordsRequest::fromRequest($app, $request, true); foreach ($records as $record) { - if ($Basket->hasRecord($record)) { + if ($Basket->hasRecord($app, $record)) { continue; } @@ -179,14 +175,14 @@ class Basket implements ControllerProviderInterface $basket_element->setRecord($record); $basket_element->setBasket($Basket); - $em->persist($basket_element); + $app['EM']->persist($basket_element); $Basket->addBasketElement($basket_element); - $n ++; + $n++; } - $em->flush(); + $app['EM']->flush(); if ($request->getRequestFormat() == 'json') { $data = array( @@ -205,13 +201,11 @@ class Basket implements ControllerProviderInterface public function deleteBasket(Application $app, Request $request, $basket_id) { - $em = $app['phraseanet.core']->getEntityManager(); + $basket = $app['EM']->getRepository('\Entities\Basket') + ->findUserBasket($app, $basket_id, $app['phraseanet.user'], true); - $basket = $em->getRepository('\Entities\Basket') - ->findUserBasket($basket_id, $app['phraseanet.core']->getAuthenticatedUser(), true); - - $em->remove($basket); - $em->flush(); + $app['EM']->remove($basket); + $app['EM']->flush(); $data = array( 'success' => true @@ -227,20 +221,17 @@ class Basket implements ControllerProviderInterface public function removeBasketElement(Application $app, Request $request, $basket_id, $basket_element_id) { - /* @var $em \Doctrine\ORM\EntityManager */ - $em = $app['phraseanet.core']->getEntityManager(); - - $basket = $em->getRepository('\Entities\Basket') - ->findUserBasket($basket_id, $app['phraseanet.core']->getAuthenticatedUser(), true); + $basket = $app['EM']->getRepository('\Entities\Basket') + ->findUserBasket($app, $basket_id, $app['phraseanet.user'], true); foreach ($basket->getElements() as $basket_element) { /* @var $basket_element \Entities\BasketElement */ if ($basket_element->getId() == $basket_element_id) { - $em->remove($basket_element); + $app['EM']->remove($basket_element); } } - $em->flush(); + $app['EM']->flush(); $data = array( 'success' => true @@ -259,16 +250,14 @@ class Basket implements ControllerProviderInterface $success = false; try { - $em = $app['phraseanet.core']->getEntityManager(); - - $basket = $em->getRepository('\Entities\Basket') - ->findUserBasket($basket_id, $app['phraseanet.core']->getAuthenticatedUser(), true); + $basket = $app['EM']->getRepository('\Entities\Basket') + ->findUserBasket($app, $basket_id, $app['phraseanet.user'], true); $basket->setName($request->request->get('name', '')); $basket->setDescription($request->request->get('description')); - $em->merge($basket); - $em->flush(); + $app['EM']->merge($basket); + $app['EM']->flush(); $success = true; $msg = _('Basket has been updated'); @@ -295,17 +284,18 @@ class Basket implements ControllerProviderInterface public function displayUpdateForm(Application $app, $basket_id) { - $basket = $app['phraseanet.core']->getEntityManager() + $basket = $app['EM'] ->getRepository('\Entities\Basket') - ->findUserBasket($basket_id, $app['phraseanet.core']->getAuthenticatedUser(), true); + ->findUserBasket($app, $basket_id, $app['phraseanet.user'], true); return $app['twig']->render('prod/Baskets/Update.html.twig', array('basket' => $basket)); } public function displayReorderForm(Application $app, $basket_id) { - $basket = $app['phraseanet.core']->getEntityManager()->getRepository('\Entities\Basket') - ->findUserBasket($basket_id, $app['phraseanet.core']->getAuthenticatedUser(), true); + $basket = $app['EM'] + ->getRepository('\Entities\Basket') + ->findUserBasket($app, $basket_id, $app['phraseanet.user'], true); return $app['twig']->render('prod/Baskets/Reorder.html.twig', array('basket' => $basket)); } @@ -314,11 +304,8 @@ class Basket implements ControllerProviderInterface { $ret = array('success' => false, 'message' => _('An error occured')); try { - /* @var $em \Doctrine\ORM\EntityManager */ - $em = $app['phraseanet.core']->getEntityManager(); - - $basket = $em->getRepository('\Entities\Basket') - ->findUserBasket($basket_id, $app['phraseanet.core']->getAuthenticatedUser(), true); + $basket = $app['EM']->getRepository('\Entities\Basket') + ->findUserBasket($app, $basket_id, $app['phraseanet.user'], true); $order = $app['request']->request->get('element'); @@ -327,11 +314,11 @@ class Basket implements ControllerProviderInterface if (isset($order[$basketElement->getId()])) { $basketElement->setOrd($order[$basketElement->getId()]); - $em->merge($basketElement); + $app['EM']->merge($basketElement); } } - $em->flush(); + $app['EM']->flush(); $ret = array('success' => true, 'message' => _('Basket updated')); } catch (\Exception $e) { @@ -342,17 +329,15 @@ class Basket implements ControllerProviderInterface public function archiveBasket(Application $app, Request $request, $basket_id) { - $em = $app['phraseanet.core']->getEntityManager(); + $basket = $app['EM']->getRepository('\Entities\Basket') + ->findUserBasket($app, $basket_id, $app['phraseanet.user'], true); - $basket = $em->getRepository('\Entities\Basket') - ->findUserBasket($basket_id, $app['phraseanet.core']->getAuthenticatedUser(), true); - - $archive_status = ! ! $request->request->get('archive'); + $archive_status = !!$request->request->get('archive'); $basket->setArchived($archive_status); - $em->merge($basket); - $em->flush(); + $app['EM']->merge($basket); + $app['EM']->flush(); if ($archive_status) { $message = _('Basket has been archived'); @@ -375,24 +360,22 @@ class Basket implements ControllerProviderInterface public function addElements(Application $app, Request $request, $basket_id) { - $em = $app['phraseanet.core']->getEntityManager(); - - $basket = $em->getRepository('\Entities\Basket') - ->findUserBasket($basket_id, $app['phraseanet.core']->getAuthenticatedUser(), true); + $basket = $app['EM']->getRepository('\Entities\Basket') + ->findUserBasket($app, $basket_id, $app['phraseanet.user'], true); $n = 0; $records = RecordsRequest::fromRequest($app, $request, true); foreach ($records as $record) { - if ($basket->hasRecord($record)) + if ($basket->hasRecord($app, $record)) continue; $basket_element = new BasketElement(); $basket_element->setRecord($record); $basket_element->setBasket($basket); - $em->persist($basket_element); + $app['EM']->persist($basket_element); $basket->addBasketElement($basket_element); @@ -405,14 +388,14 @@ class Basket implements ControllerProviderInterface $validationData->setParticipant($participant); $validationData->setBasketElement($basket_element); - $em->persist($validationData); + $app['EM']->persist($validationData); } } - $n ++; + $n++; } - $em->flush(); + $app['EM']->flush(); $data = array( 'success' => true @@ -428,20 +411,17 @@ class Basket implements ControllerProviderInterface public function stealElements(Application $app, Request $request, $basket_id) { - $em = $app['phraseanet.core']->getEntityManager(); + $basket = $app['EM']->getRepository('\Entities\Basket') + ->findUserBasket($app, $basket_id, $app['phraseanet.user'], true); - /* @var $em \Doctrine\ORM\EntityManager */ - $basket = $em->getRepository('\Entities\Basket') - ->findUserBasket($basket_id, $app['phraseanet.core']->getAuthenticatedUser(), true); - - $user = $app['phraseanet.core']->getAuthenticatedUser(); + $user = $app['phraseanet.user']; /* @var $user \User_Adapter */ $n = 0; foreach ($request->request->get('elements') as $bask_element_id) { try { - $basket_element = $em->getRepository('\Entities\BasketElement') + $basket_element = $app['EM']->getRepository('\Entities\BasketElement') ->findUserElement($bask_element_id, $user); } catch (\Exception $e) { continue; @@ -449,10 +429,10 @@ class Basket implements ControllerProviderInterface $basket_element->setBasket($basket); $basket->addBasketElement($basket_element); - $n ++; + $n++; } - $em->flush(); + $app['EM']->flush(); $data = array( 'success' => true diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Bridge.php b/lib/Alchemy/Phrasea/Controller/Prod/Bridge.php index 302e75ae23..0ffcfbe244 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Bridge.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Bridge.php @@ -46,13 +46,13 @@ class Bridge implements ControllerProviderInterface $controllers->post('/manager/' , function(Application $app) { - $route = new RecordHelper\Bridge($app['phraseanet.core'], $app['request']); + $route = new RecordHelper\Bridge($app, $app['request']); $appbox = $app['phraseanet.appbox']; - $user = \User_Adapter::getInstance($appbox->get_session()->get_usr_id(), $appbox); + $user = \User_Adapter::getInstance($appbox->get_session()->get_usr_id(), $app); $params = array( - 'user_accounts' => \Bridge_Account::get_accounts_by_user($appbox, $user) - , 'available_apis' => \Bridge_Api::get_availables($appbox) + 'user_accounts' => \Bridge_Account::get_accounts_by_user($app, $user) + , 'available_apis' => \Bridge_Api::get_availables($app) , 'route' => $route , 'current_account_id' => '' ); @@ -72,8 +72,8 @@ class Bridge implements ControllerProviderInterface $error_message = ''; try { $appbox = $app['phraseanet.appbox']; - $user = \User_Adapter::getInstance($appbox->get_session()->get_usr_id(), $appbox); - $api = \Bridge_Api::get_by_api_name($appbox, $api_name); + $user = \User_Adapter::getInstance($appbox->get_session()->get_usr_id(), $app); + $api = \Bridge_Api::get_by_api_name($app, $api_name); $connector = $api->get_connector(); $response = $connector->connect(); @@ -81,9 +81,9 @@ class Bridge implements ControllerProviderInterface $user_id = $connector->get_user_id(); try { - $account = \Bridge_Account::load_account_from_distant_id($appbox, $api, $user, $user_id); + $account = \Bridge_Account::load_account_from_distant_id($app, $api, $user, $user_id); } catch (\Bridge_Exception_AccountNotFound $e) { - $account = \Bridge_Account::create($appbox, $api, $user, $user_id, $connector->get_user_name()); + $account = \Bridge_Account::create($app, $api, $user, $user_id, $connector->get_user_name()); } $settings = $account->get_settings(); @@ -106,7 +106,7 @@ class Bridge implements ControllerProviderInterface $controllers->get('/adapter/{account_id}/logout/', function(Application $app, $account_id) { $appbox = $app['phraseanet.appbox']; - $account = \Bridge_Account::load_account($appbox, $account_id); + $account = \Bridge_Account::load_account($app, $account_id); $app['require_connection']($account); $account->get_api()->get_connector()->disconnect(); @@ -118,8 +118,8 @@ class Bridge implements ControllerProviderInterface $quantity = 10; $offset_start = max(($page - 1) * $quantity, 0); $appbox = $app['phraseanet.appbox']; - $account = \Bridge_Account::load_account($appbox, $account_id); - $elements = \Bridge_Element::get_elements_by_account($appbox, $account, $offset_start, $quantity); + $account = \Bridge_Account::load_account($app, $account_id); + $elements = \Bridge_Element::get_elements_by_account($app, $account, $offset_start, $quantity); $app['require_connection']($account); @@ -141,7 +141,7 @@ class Bridge implements ControllerProviderInterface $quantity = 5; $offset_start = max(($page - 1) * $quantity, 0); $appbox = $app['phraseanet.appbox']; - $account = \Bridge_Account::load_account($appbox, $account_id); + $account = \Bridge_Account::load_account($app, $account_id); $app['require_connection']($account); @@ -167,7 +167,7 @@ class Bridge implements ControllerProviderInterface $quantity = 5; $offset_start = max(($page - 1) * $quantity, 0); $appbox = $app['phraseanet.appbox']; - $account = \Bridge_Account::load_account($appbox, $account_id); + $account = \Bridge_Account::load_account($app, $account_id); $app['require_connection']($account); $elements = $account->get_api()->list_containers($type, $offset_start, $quantity); @@ -189,7 +189,7 @@ class Bridge implements ControllerProviderInterface , function(Application $app, $account_id, $action, $element_type) { $appbox = $app['phraseanet.appbox']; - $account = \Bridge_Account::load_account($appbox, $account_id); + $account = \Bridge_Account::load_account($app, $account_id); $app['require_connection']($account); $request = $app['request']; @@ -254,7 +254,7 @@ class Bridge implements ControllerProviderInterface $controllers->post('/action/{account_id}/{action}/{element_type}/' , function(Application $app, $account_id, $action, $element_type) { $appbox = $app['phraseanet.appbox']; - $account = \Bridge_Account::load_account($appbox, $account_id); + $account = \Bridge_Account::load_account($app, $account_id); $app['require_connection']($account); @@ -357,10 +357,10 @@ class Bridge implements ControllerProviderInterface $controllers->get('/upload/', function(Application $app) { $request = $app['request']; $appbox = $app['phraseanet.appbox']; - $account = \Bridge_Account::load_account($appbox, $request->query->get('account_id')); + $account = \Bridge_Account::load_account($app, $request->query->get('account_id')); $app['require_connection']($account); - $route = new RecordHelper\Bridge($app['phraseanet.core'], $app['request']); + $route = new RecordHelper\Bridge($app, $app['request']); $route->grep_records($account->get_api()->acceptable_records()); @@ -382,10 +382,10 @@ class Bridge implements ControllerProviderInterface $errors = array(); $request = $app['request']; $appbox = $app['phraseanet.appbox']; - $account = \Bridge_Account::load_account($appbox, $request->request->get('account_id')); + $account = \Bridge_Account::load_account($app, $request->request->get('account_id')); $app['require_connection']($account); - $route = new RecordHelper\Bridge($app['phraseanet.core'], $app['request']); + $route = new RecordHelper\Bridge($app, $app['request']); $route->grep_records($account->get_api()->acceptable_records()); $connector = $account->get_api()->get_connector(); @@ -415,62 +415,62 @@ class Bridge implements ControllerProviderInterface $datas = $connector->get_upload_datas($request, $record); $title = isset($datas["title"]) ? $datas["title"] : ''; $default_type = $connector->get_default_element_type(); - \Bridge_Element::create($appbox, $account, $record, $title, \Bridge_Element::STATUS_PENDING, $default_type, $datas); + \Bridge_Element::create($app, $account, $record, $title, \Bridge_Element::STATUS_PENDING, $default_type, $datas); } return $app->redirect('/prod/bridge/adapter/' . $account->get_id() . '/load-records/?notice=' . sprintf(_('%d elements en attente'), count($route->get_elements()))); }); +// +// $app->error(function(\Exception $e, $code) use ($app) { +// +// $request = $app['request']; +// +// if ($e instanceof \Bridge_Exception) { +// +// $params = array( +// 'message' => $e->getMessage() +// , 'file' => $e->getFile() +// , 'line' => $e->getLine() +// , 'r_method' => $request->getMethod() +// , 'r_action' => $request->getRequestUri() +// , 'r_parameters' => ($request->getMethod() == 'GET' ? array() : $request->request->all()) +// ); +// +// if ($e instanceof \Bridge_Exception_ApiConnectorNotConfigured) { +// $params = array_merge($params, array('account' => $app['current_account'])); +// +// $response = new Response($app['twig']->render('/prod/actions/Bridge/notconfigured.html.twig', $params), 200); +// } elseif ($e instanceof \Bridge_Exception_ApiConnectorNotConnected) { +// $params = array_merge($params, array('account' => $app['current_account'])); +// +// $response = new Response($app['twig']->render('/prod/actions/Bridge/disconnected.html.twig', $params), 200); +// } elseif ($e instanceof \Bridge_Exception_ApiConnectorAccessTokenFailed) { +// $params = array_merge($params, array('account' => $app['current_account'])); +// +// $response = new Response($app['twig']->render('/prod/actions/Bridge/disconnected.html.twig', $params), 200); +// } elseif ($e instanceof \Bridge_Exception_ApiDisabled) { +// $params = array_merge($params, array('api' => $e->get_api())); +// +// $response = new Response($app['twig']->render('/prod/actions/Bridge/deactivated.html.twig', $params), 200); +// } else { +// $response = new Response($app['twig']->render('/prod/actions/Bridge/error.html.twig', $params), 200); +// } +// +// $response->headers->set('Phrasea-StatusCode', 200); +// +// return $response; +// } +// }); - $app->error(function(\Exception $e, $code) use ($app) { - - $request = $app['request']; - - if ($e instanceof \Bridge_Exception) { - - $params = array( - 'message' => $e->getMessage() - , 'file' => $e->getFile() - , 'line' => $e->getLine() - , 'r_method' => $request->getMethod() - , 'r_action' => $request->getRequestUri() - , 'r_parameters' => ($request->getMethod() == 'GET' ? array() : $request->request->all()) - ); - - if ($e instanceof \Bridge_Exception_ApiConnectorNotConfigured) { - $params = array_merge($params, array('account' => $app['current_account'])); - - $response = new Response($app['twig']->render('/prod/actions/Bridge/notconfigured.html.twig', $params), 200); - } elseif ($e instanceof \Bridge_Exception_ApiConnectorNotConnected) { - $params = array_merge($params, array('account' => $app['current_account'])); - - $response = new Response($app['twig']->render('/prod/actions/Bridge/disconnected.html.twig', $params), 200); - } elseif ($e instanceof \Bridge_Exception_ApiConnectorAccessTokenFailed) { - $params = array_merge($params, array('account' => $app['current_account'])); - - $response = new Response($app['twig']->render('/prod/actions/Bridge/disconnected.html.twig', $params), 200); - } elseif ($e instanceof \Bridge_Exception_ApiDisabled) { - $params = array_merge($params, array('api' => $e->get_api())); - - $response = new Response($app['twig']->render('/prod/actions/Bridge/deactivated.html.twig', $params), 200); - } else { - $response = new Response($app['twig']->render('/prod/actions/Bridge/error.html.twig', $params), 200); - } - - $response->headers->set('Phrasea-StatusCode', 200); - - return $response; - } - }); - - /** - * Temporary fix for https://github.com/fabpot/Silex/issues/438 - */ - $app['dispatcher']->addListener(KernelEvents::RESPONSE, function(FilterResponseEvent $event){ - if ($event->getResponse()->headers->has('Phrasea-StatusCode')) { - $event->getResponse()->setStatusCode($event->getResponse()->headers->get('Phrasea-StatusCode')); - $event->getResponse()->headers->remove('Phrasea-StatusCode'); - } - }); +// /** +// * Temporary fix for https://github.com/fabpot/Silex/issues/438 +// */ +// $app['dispatcher']->addListener(KernelEvents::RESPONSE, function(FilterResponseEvent $event){ +// if ($event->getResponse()->headers->has('Phrasea-StatusCode')) { +// $event->getResponse()->setStatusCode($event->getResponse()->headers->get('Phrasea-StatusCode')); +// $event->getResponse()->headers->remove('Phrasea-StatusCode'); +// } +// }); return $controllers; } diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Edit.php b/lib/Alchemy/Phrasea/Controller/Prod/Edit.php index 589a7df1eb..44c16e6c2a 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Edit.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Edit.php @@ -11,6 +11,7 @@ namespace Alchemy\Phrasea\Controller\Prod; +use Alchemy\Phrasea\Vocabulary\Controller as VocabularyController; use Alchemy\Phrasea\Controller\RecordsRequest; use Alchemy\Phrasea\Metadata\Tag\TfEditdate; use Silex\Application; @@ -113,8 +114,8 @@ class Edit implements ControllerProviderInterface /** * generate javascript status */ - if ($app['phraseanet.core']->getAuthenticatedUser()->ACL()->has_right('changestatus')) { - $dbstatus = \databox_status::getDisplayStatus(); + if ($app['phraseanet.user']->ACL()->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] = array(); @@ -149,7 +150,7 @@ class Edit implements ControllerProviderInterface ); $elements[$indice]['statbits'] = array(); - if ($app['phraseanet.core']->getAuthenticatedUser()->ACL()->has_right_on_base($record->get_base_id(), 'chgstatus')) { + if ($app['phraseanet.user']->ACL()->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'; @@ -233,7 +234,7 @@ class Edit implements ControllerProviderInterface throw new \Exception('Invalid sbas_id'); } - $VC = \Alchemy\Phrasea\Vocabulary\Controller::get($vocabulary); + $VC = VocabularyController::get($app, $vocabulary); $databox = $app['phraseanet.appbox']->get_databox($sbas_id); } catch (\Exception $e) { $datas['message'] = _('Vocabulary not found'); @@ -243,7 +244,7 @@ class Edit implements ControllerProviderInterface $query = $request->query->get('query'); - $results = $VC->find($query, $app['phraseanet.core']->getAuthenticatedUser(), $databox); + $results = $VC->find($query, $app['phraseanet.user'], $databox); $list = array(); @@ -277,7 +278,7 @@ class Edit implements ControllerProviderInterface try { $reg_record = $records->singleStory(); - $newsubdef_reg = new \record_adapter($reg_record->get_sbas_id(), $request->request->get('newrepresent')); + $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'); @@ -287,8 +288,8 @@ class Edit implements ControllerProviderInterface if (!in_array($name, array('thumbnail', 'preview'))) { continue; } - $media = $app['phraseanet.core']['mediavorus']->guess($value->get_pathfile()); - $reg_record->substitute_subdef($name, $media); + $media = $app['mediavorus']->guess($value->get_pathfile()); + $reg_record->substitute_subdef($name, $media, $app); } } catch (\Exception $e) { @@ -296,7 +297,7 @@ class Edit implements ControllerProviderInterface } if (!is_array($request->get('mds'))) { - return $this; + return; } $databox = array_pop($records->databoxes()); @@ -367,13 +368,13 @@ class Edit implements ControllerProviderInterface if (!in_array($statbits, array('', 'null'))) { $mask_and = ltrim(str_replace(array('x', '0', '1', 'z'), array('1', 'z', '0', '1'), $statbits), '0'); if ($mask_and != '') { - $newstat = \databox_status::operation_and_not($newstat, $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($newstat, $mask_or); + $newstat = \databox_status::operation_or($app, $newstat, $mask_or); } $record->set_binary_status($newstat); diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Feed.php b/lib/Alchemy/Phrasea/Controller/Prod/Feed.php index db722c22b9..719599b1df 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Feed.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Feed.php @@ -33,8 +33,8 @@ class Feed implements ControllerProviderInterface * I got a selection of docs, which publications are available forthese docs ? */ $controllers->post('/requestavailable/', function(Application $app, Request $request) { - $user = $app['phraseanet.core']->getAuthenticatedUser(); - $feeds = \Feed_Collection::load_all($app['phraseanet.appbox'], $user); + $user = $app['phraseanet.user']; + $feeds = \Feed_Collection::load_all($app, $user); $publishing = RecordsRequest::fromRequest($app, $request, true, array(), array('bas_chupub')); return new Response($app['twig']->render('prod/actions/publish/publish.html.twig', array('publishing' => $publishing, 'feeds' => $feeds))); @@ -45,8 +45,8 @@ class Feed implements ControllerProviderInterface */ $controllers->post('/entry/create/', function(Application $app, Request $request) { try { - $user = $app['phraseanet.core']->getAuthenticatedUser(); - $feed = new \Feed_Adapter($app['phraseanet.appbox'], $request->request->get('feed_id')); + $user = $app['phraseanet.user']; + $feed = new \Feed_Adapter($app, $request->request->get('feed_id')); $publisher = \Feed_Publisher_Adapter::getPublisher($app['phraseanet.appbox'], $feed, $user); $title = $request->request->get('title'); @@ -54,7 +54,7 @@ class Feed implements ControllerProviderInterface $author_name = $request->request->get('author_name'); $author_mail = $request->request->get('author_mail'); - $entry = \Feed_Entry_Adapter::create($app['phraseanet.appbox'], $feed, $publisher, $title, $subtitle, $author_name, $author_mail); + $entry = \Feed_Entry_Adapter::create($app, $feed, $publisher, $title, $subtitle, $author_name, $author_mail); $publishing = RecordsRequest::fromRequest($app, $request, true, array(), array('bas_chupub')); @@ -71,15 +71,15 @@ class Feed implements ControllerProviderInterface $controllers->get('/entry/{id}/edit/', function(Application $app, Request $request, $id) { - $user = $app['phraseanet.core']->getAuthenticatedUser(); + $user = $app['phraseanet.user']; - $entry = \Feed_Entry_Adapter::load_from_id($app['phraseanet.appbox'], $id); + $entry = \Feed_Entry_Adapter::load_from_id($app, $id); if ($entry->get_publisher()->get_user()->get_id() !== $user->get_id()) { throw new \Exception_UnauthorizedAction(); } - $feeds = \Feed_Collection::load_all($app['phraseanet.appbox'], $user); + $feeds = \Feed_Collection::load_all($app, $user); $datas = $app['twig']->render('prod/actions/publish/publish_edit.html.twig', array('entry' => $entry, 'feeds' => $feeds)); @@ -91,9 +91,9 @@ class Feed implements ControllerProviderInterface try { $app['phraseanet.appbox']->get_connection()->beginTransaction(); - $user = $app['phraseanet.core']->getAuthenticatedUser(); + $user = $app['phraseanet.user']; - $entry = \Feed_Entry_Adapter::load_from_id($app['phraseanet.appbox'], $id); + $entry = \Feed_Entry_Adapter::load_from_id($app, $id); if ($entry->get_publisher()->get_user()->get_id() !== $user->get_id()) { throw new \Exception_UnauthorizedAction(); @@ -113,7 +113,7 @@ class Feed implements ControllerProviderInterface $new_feed_id = $request->request->get('feed_id', $current_feed_id); if ($current_feed_id != $new_feed_id) { try { - $new_feed = \Feed_Adapter::load_with_user($app['phraseanet.appbox'], $user, $new_feed_id); + $new_feed = \Feed_Adapter::load_with_user($app, $user, $new_feed_id); } catch (\Exception_NotFound $e) { throw new \Exception_Forbidden('You have no access to this feed'); } @@ -164,9 +164,9 @@ class Feed implements ControllerProviderInterface try { $app['phraseanet.appbox']->get_connection()->beginTransaction(); - $user = $app['phraseanet.core']->getAuthenticatedUser(); + $user = $app['phraseanet.user']; - $entry = \Feed_Entry_Adapter::load_from_id($app['phraseanet.appbox'], $id); + $entry = \Feed_Entry_Adapter::load_from_id($app, $id); if ($entry->get_publisher()->get_user()->get_id() !== $user->get_id() && $entry->get_feed()->is_owner($user) === false) { @@ -193,9 +193,9 @@ class Feed implements ControllerProviderInterface $page = (int) $request->query->get('page'); $page = $page > 0 ? $page : 1; - $user = $app['phraseanet.core']->getAuthenticatedUser(); + $user = $app['phraseanet.user']; - $feeds = \Feed_Collection::load_all($app['phraseanet.appbox'], $user); + $feeds = \Feed_Collection::load_all($app, $user); $datas = $app['twig']->render('prod/feeds/feeds.html.twig' , array( @@ -212,10 +212,10 @@ class Feed implements ControllerProviderInterface $page = (int) $request->query->get('page'); $page = $page > 0 ? $page : 1; - $user = $app['phraseanet.core']->getAuthenticatedUser(); + $user = $app['phraseanet.user']; - $feed = \Feed_Adapter::load_with_user($app['phraseanet.appbox'], $user, $id); - $feeds = \Feed_Collection::load_all($app['phraseanet.appbox'], $user); + $feed = \Feed_Adapter::load_with_user($app, $user, $id); + $feeds = \Feed_Collection::load_all($app, $user); $datas = $app['twig']->render('prod/feeds/feeds.html.twig', array('feed' => $feed, 'feeds' => $feeds, 'page' => $page)); @@ -225,9 +225,9 @@ class Feed implements ControllerProviderInterface $controllers->get('/subscribe/aggregated/', function(Application $app, Request $request) { $renew = ($request->query->get('renew') === 'true'); - $user = $app['phraseanet.core']->getAuthenticatedUser(); + $user = $app['phraseanet.user']; - $feeds = \Feed_Collection::load_all($app['phraseanet.appbox'], $user); + $feeds = \Feed_Collection::load_all($app, $user); $registry = $app['phraseanet.appbox']->get_registry(); $output = array( @@ -242,8 +242,8 @@ class Feed implements ControllerProviderInterface $controllers->get('/subscribe/{id}/', function(Application $app, Request $request, $id) { $renew = ($request->query->get('renew') === 'true'); - $user = $app['phraseanet.core']->getAuthenticatedUser(); - $feed = \Feed_Adapter::load_with_user($app['phraseanet.appbox'], $user, $id); + $user = $app['phraseanet.user']; + $feed = \Feed_Adapter::load_with_user($app, $user, $id); $registry = $app['phraseanet.appbox']->get_registry(); $output = array( diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Language.php b/lib/Alchemy/Phrasea/Controller/Prod/Language.php index 639bad53ae..c0b7c980f2 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Language.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Language.php @@ -27,7 +27,7 @@ class Language implements ControllerProviderInterface $controller = $app['controllers_factory']; $controller->get("/", function(Application $app) { - $registry = $app['phraseanet.core']->getRegistry(); + $registry = $app['phraseanet.registry']; $out = array(); $out['thesaurusBasesChanged'] = _('prod::recherche: Attention : la liste des bases selectionnees pour la recherche a ete changee.'); diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Lazaret.php b/lib/Alchemy/Phrasea/Controller/Prod/Lazaret.php index a5a98824da..0e2c10dd78 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Lazaret.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Lazaret.php @@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\Controller\Prod; use Entities\LazaretFile; use Alchemy\Phrasea\Border; +use Alchemy\Phrasea\Border\Attribute\AttributeInterface; use Silex\Application; use Silex\ControllerProviderInterface; use Symfony\Component\HttpFoundation\Request; @@ -168,15 +169,14 @@ class Lazaret implements ControllerProviderInterface */ public function listElement(Application $app, Request $request) { - $em = $app['phraseanet.core']->getEntityManager(); - $user = $app['phraseanet.core']->getAuthenticatedUser(); + $user = $app['phraseanet.user']; /* @var $user \User_Adapter */ $baseIds = array_keys($user->ACL()->get_granted_base(array('canaddrecord'))); $lazaretFiles = null; if (count($baseIds) > 0) { - $lazaretRepository = $em->getRepository('Entities\LazaretFile'); + $lazaretRepository = $app['EM']->getRepository('Entities\LazaretFile'); $lazaretFiles = $lazaretRepository->findPerPage( $baseIds, $request->query->get('offset', 0), $request->query->get('limit', 10) @@ -203,7 +203,7 @@ class Lazaret implements ControllerProviderInterface { $ret = array('success' => false, 'message' => '', 'result' => array()); - $lazaretFile = $app['phraseanet.core']['EM']->find('Entities\LazaretFile', $file_id); + $lazaretFile = $app['EM']->find('Entities\LazaretFile', $file_id); /* @var $lazaretFile \Entities\LazaretFile */ if (null === $lazaretFile) { @@ -217,7 +217,7 @@ class Lazaret implements ControllerProviderInterface 'base_id' => $lazaretFile->getBaseId(), 'created' => $lazaretFile->getCreated()->format(\DateTime::ATOM), 'updated' => $lazaretFile->getUpdated()->format(\DateTime::ATOM), - 'pathname' => $app['phraseanet.core']['Registry']->get('GV_RootPath') . 'tmp/lazaret/' . $lazaretFile->getFilename(), + 'pathname' => $app['phraseanet.registry']->get('GV_RootPath') . 'tmp/lazaret/' . $lazaretFile->getFilename(), 'sha256' => $lazaretFile->getSha256(), 'uuid' => $lazaretFile->getUuid(), ); @@ -253,7 +253,7 @@ class Lazaret implements ControllerProviderInterface } - $lazaretFile = $app['phraseanet.core']['EM']->find('Entities\LazaretFile', $file_id); + $lazaretFile = $app['EM']->find('Entities\LazaretFile', $file_id); /* @var $lazaretFile \Entities\LazaretFile */ if (null === $lazaretFile) { @@ -262,12 +262,12 @@ class Lazaret implements ControllerProviderInterface return $app->json($ret); } - $lazaretFileName = $app['phraseanet.core']['Registry']->get('GV_RootPath') . 'tmp/lazaret/' . $lazaretFile->getFilename(); - $lazaretThumbFileName = $app['phraseanet.core']['Registry']->get('GV_RootPath') . 'tmp/lazaret/' . $lazaretFile->getThumbFilename(); + $lazaretFileName = $app['phraseanet.registry']->get('GV_RootPath') . 'tmp/lazaret/' . $lazaretFile->getFilename(); + $lazaretThumbFileName = $app['phraseanet.registry']->get('GV_RootPath') . 'tmp/lazaret/' . $lazaretFile->getThumbFilename(); try { $borderFile = Border\File::buildFromPathfile( - $lazaretFileName, $lazaretFile->getCollection(), $lazaretFile->getOriginalName() + $lazaretFileName, $lazaretFile->getCollection($app), $app['mediavorus'], $lazaretFile->getOriginalName() ); $record = null; @@ -279,7 +279,7 @@ class Lazaret implements ControllerProviderInterface }; //Force creation record - $app['phraseanet.core']['border-manager']->process( + $app['border-manager']->process( $lazaretFile->getSession(), $borderFile, $callBack, Border\Manager::FORCE_RECORD ); @@ -295,26 +295,26 @@ class Lazaret implements ControllerProviderInterface } try { - $attribute = Border\Attribute\Factory::getFileAttribute($attr->getName(), $attr->getValue()); + $attribute = Border\Attribute\Factory::getFileAttribute($app, $attr->getName(), $attr->getValue()); } catch (\InvalidArgumentException $e) { continue; } - /* @var $attribute Border\Attribute\Attribute */ + /* @var $attribute AttributeInterface */ switch ($attribute->getName()) { - case Border\Attribute\Attribute::NAME_METADATA: + case AttributeInterface::NAME_METADATA: /** * @todo romain neutron */ break; - case Border\Attribute\Attribute::NAME_STORY: + case AttributeInterface::NAME_STORY: $attribute->getValue()->appendChild($record); break; - case Border\Attribute\Attribute::NAME_STATUS: + case AttributeInterface::NAME_STATUS: $record->set_binary_status($attribute->getValue()); break; - case Border\Attribute\Attribute::NAME_METAFIELD: + case AttributeInterface::NAME_METAFIELD: /** * @todo romain neutron */ @@ -324,8 +324,8 @@ class Lazaret implements ControllerProviderInterface } //Delete lazaret file - $app['phraseanet.core']['EM']->remove($lazaretFile); - $app['phraseanet.core']['EM']->flush(); + $app['EM']->remove($lazaretFile); + $app['EM']->flush(); $ret['success'] = true; } catch (\Exception $e) { @@ -354,7 +354,7 @@ class Lazaret implements ControllerProviderInterface { $ret = array('success' => false, 'message' => '', 'result' => array()); - $lazaretFile = $app['phraseanet.core']['EM']->find('Entities\LazaretFile', $file_id); + $lazaretFile = $app['EM']->find('Entities\LazaretFile', $file_id); /* @var $lazaretFile \Entities\LazaretFile */ if (null === $lazaretFile) { $ret['message'] = _('File is not present in quarantine anymore, please refresh'); @@ -374,11 +374,11 @@ class Lazaret implements ControllerProviderInterface protected function denyLazaretFile(Application $app, LazaretFile $lazaretFile) { - $lazaretFileName = $app['phraseanet.core']['Registry']->get('GV_RootPath') . 'tmp/lazaret/' . $lazaretFile->getFilename(); - $lazaretThumbFileName = $app['phraseanet.core']['Registry']->get('GV_RootPath') . 'tmp/lazaret/' . $lazaretFile->getThumbFilename(); + $lazaretFileName = $app['phraseanet.registry']->get('GV_RootPath') . 'tmp/lazaret/' . $lazaretFile->getFilename(); + $lazaretThumbFileName = $app['phraseanet.registry']->get('GV_RootPath') . 'tmp/lazaret/' . $lazaretFile->getThumbFilename(); - $app['phraseanet.core']['EM']->remove($lazaretFile); - $app['phraseanet.core']['EM']->flush(); + $app['EM']->remove($lazaretFile); + $app['EM']->flush(); try { $app['filesystem']->remove(array($lazaretFileName, $lazaretThumbFileName)); @@ -401,18 +401,18 @@ class Lazaret implements ControllerProviderInterface { $ret = array('success' => false, 'message' => '', 'result' => array()); - $lazaretFiles = $app['phraseanet.core']['EM']->getRepository('Entities\LazaretFile')->findAll(); + $lazaretFiles = $app['EM']->getRepository('Entities\LazaretFile')->findAll(); - $app['phraseanet.core']['EM']->beginTransaction(); + $app['EM']->beginTransaction(); try { foreach ($lazaretFiles as $lazaretFile) { $this->denyLazaretFile($app, $lazaretFile); } - $app['phraseanet.core']['EM']->commit(); + $app['EM']->commit(); $ret['success'] = true; } catch (\Exception $e) { - $app['phraseanet.core']['EM']->rollback(); + $app['EM']->rollback(); $ret['message'] = _('An error occured'); } @@ -439,7 +439,7 @@ class Lazaret implements ControllerProviderInterface return $app->json($ret); } - $lazaretFile = $app['phraseanet.core']['EM']->find('Entities\LazaretFile', $file_id); + $lazaretFile = $app['EM']->find('Entities\LazaretFile', $file_id); /* @var $lazaretFile \Entities\LazaretFile */ if (null === $lazaretFile) { @@ -451,7 +451,7 @@ class Lazaret implements ControllerProviderInterface $found = false; //Check if the choosen record is eligible to the substitution - foreach ($lazaretFile->getRecordsToSubstitute() as $record) { + foreach ($lazaretFile->getRecordsToSubstitute($app) as $record) { if ($record->get_record_id() !== (int) $recordId) { continue; } @@ -466,18 +466,18 @@ class Lazaret implements ControllerProviderInterface return $app->json($ret); } - $lazaretFileName = $app['phraseanet.core']['Registry']->get('GV_RootPath') . 'tmp/lazaret/' . $lazaretFile->getFilename(); - $lazaretThumbFileName = $app['phraseanet.core']['Registry']->get('GV_RootPath') . 'tmp/lazaret/' . $lazaretFile->getThumbFilename(); + $lazaretFileName = $app['phraseanet.registry']->get('GV_RootPath') . 'tmp/lazaret/' . $lazaretFile->getFilename(); + $lazaretThumbFileName = $app['phraseanet.registry']->get('GV_RootPath') . 'tmp/lazaret/' . $lazaretFile->getThumbFilename(); try { - $media = $app['phraseanet.core']['mediavorus']->guess(new \SplFileInfo($lazaretFileName)); + $media = $app['mediavorus']->guess($lazaretFileName); - $record = $lazaretFile->getCollection()->get_databox()->get_record($recordId); - $record->substitute_subdef('document', $media, $app['filesystem'], $app['phraseanet.core']['media-alchemyst'], $app['phraseanet.core']['mediavorus']); + $record = $lazaretFile->getCollection($app)->get_databox()->get_record($recordId); + $record->substitute_subdef('document', $media, $app); //Delete lazaret file - $app['phraseanet.core']['EM']->remove($lazaretFile); - $app['phraseanet.core']['EM']->flush(); + $app['EM']->remove($lazaretFile); + $app['EM']->flush(); $ret['success'] = true; } catch (\Exception $e) { @@ -504,7 +504,7 @@ class Lazaret implements ControllerProviderInterface */ public function thumbnailElement(Application $app, Request $request, $file_id) { - $lazaretFile = $app['phraseanet.core']['EM']->find('Entities\LazaretFile', $file_id); + $lazaretFile = $app['EM']->find('Entities\LazaretFile', $file_id); /* @var $lazaretFile \Entities\LazaretFile */ if (null === $lazaretFile) { @@ -512,10 +512,10 @@ class Lazaret implements ControllerProviderInterface return new Response(null, 404); } - $lazaretThumbFileName = $app['phraseanet.core']['Registry']->get('GV_RootPath') . 'tmp/lazaret/' . $lazaretFile->getThumbFilename(); + $lazaretThumbFileName = $app['phraseanet.registry']->get('GV_RootPath') . 'tmp/lazaret/' . $lazaretFile->getThumbFilename(); $response = \set_export::stream_file( - $lazaretThumbFileName, $lazaretFile->getOriginalName(), 'image/jpeg', 'inline' + $app['phraseanet.registry'], $lazaretThumbFileName, $lazaretFile->getOriginalName(), 'image/jpeg', 'inline' ); return $response; diff --git a/lib/Alchemy/Phrasea/Controller/Prod/MoveCollection.php b/lib/Alchemy/Phrasea/Controller/Prod/MoveCollection.php index 8e7e130eb7..0a476e9a84 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/MoveCollection.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/MoveCollection.php @@ -42,7 +42,7 @@ class MoveCollection implements ControllerProviderInterface return $databox->get_sbas_id(); }, $records->databoxes()); - $collections = $app['phraseanet.core']->getAuthenticatedUser()->ACL() + $collections = $app['phraseanet.user']->ACL() ->get_granted_base(array('canaddrecord'), $sbas_ids); $parameters = array( @@ -64,7 +64,7 @@ class MoveCollection implements ControllerProviderInterface ); try { - $user = $app['phraseanet.core']->getAuthenticatedUser(); + $user = $app['phraseanet.user']; if (null === $request->request->get('base_id')) { $datas['message'] = _('Missing target collection'); @@ -72,12 +72,12 @@ class MoveCollection implements ControllerProviderInterface } if ( ! $user->ACL()->has_right_on_base($request->request->get('base_id'), 'canaddrecord')) { - $datas['message'] = sprintf(_("You do not have the permission to move records to %s"), \phrasea::bas_names($move->getBaseIdDestination())); + $datas['message'] = sprintf(_("You do not have the permission to move records to %s"), \phrasea::bas_names($move->getBaseIdDestination(), $app)); return $app->json($datas); } try { - $collection = \collection::get_from_base_id($request->request->get('base_id')); + $collection = \collection::get_from_base_id($app, $request->request->get('base_id')); } catch (\Exception_Databox_CollectionNotFound $e) { $datas['message'] = _('Invalid target collection'); return $app->json($datas); diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Order.php b/lib/Alchemy/Phrasea/Controller/Prod/Order.php index a7263b1a6a..1f96bafff0 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Order.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Order.php @@ -50,7 +50,7 @@ class Order implements ControllerProviderInterface */ $controllers->get('/', $this->call('displayOrders')) ->before(function(Request $request) use ($app) { - $app['phraseanet.core']['Firewall']->requireOrdersAdmin($app); + $app['firewall']->requireOrdersAdmin($app); }) ->bind('prod_orders'); @@ -85,7 +85,7 @@ class Order implements ControllerProviderInterface */ $controllers->get('/{order_id}/', $this->call('displayOneOrder')) ->before(function(Request $request) use ($app) { - $app['phraseanet.core']['Firewall']->requireOrdersAdmin($app); + $app['firewall']->requireOrdersAdmin($app); }) ->bind('prod_order') ->assert('order_id', '\d+'); @@ -105,7 +105,7 @@ class Order implements ControllerProviderInterface */ $controllers->post('/{order_id}/send/', $this->call('sendOrder')) ->before(function(Request $request) use ($app) { - $app['phraseanet.core']['Firewall']->requireOrdersAdmin($app); + $app['firewall']->requireOrdersAdmin($app); }) ->bind('prod_order_send') ->assert('order_id', '\d+'); @@ -125,7 +125,7 @@ class Order implements ControllerProviderInterface */ $controllers->post('/{order_id}/deny/', $this->call('denyOrder')) ->before(function(Request $request) use ($app) { - $app['phraseanet.core']['Firewall']->requireOrdersAdmin($app); + $app['firewall']->requireOrdersAdmin($app); }) ->bind('prod_order_deny') ->assert('order_id', '\d+'); @@ -149,7 +149,7 @@ class Order implements ControllerProviderInterface try { $records = RecordsRequest::fromRequest($app, $request, true, array('cancmd')); - $query = new \User_Query($app['phraseanet.appbox']); + $query = new \User_Query($app); foreach ($records as $key => $record) { if ($collectionHasOrderAdmins->containsKey($record->get_base_id())) { @@ -185,7 +185,7 @@ class Order implements ControllerProviderInterface if (count($records) > 0) { \set_order::create( - $app['phraseanet.appbox'], $records, $app['phraseanet.core']->getAuthenticatedUser(), $request->request->get('use', ''), ( (null !== $deadLine = $request->request->get('deadline')) ? new \DateTime($deadLine) : $deadLine) + $app, $records, $app['phraseanet.user'], $request->request->get('use', ''), ( (null !== $deadLine = $request->request->get('deadline')) ? new \DateTime($deadLine) : $deadLine) ); $success = true; @@ -226,9 +226,9 @@ class Order implements ControllerProviderInterface $perPage = (int) $request->query->get('per-page', 10); $sort = $request->query->get('sort'); - $baseIds = array_keys($app['phraseanet.core']->getAuthenticatedUser()->ACL()->get_granted_base(array('order_master'))); + $baseIds = array_keys($app['phraseanet.user']->ACL()->get_granted_base(array('order_master'))); - $ordersList = \set_order::listOrders($app['phraseanet.appbox'], $baseIds, $offsetStart, $perPage, $sort); + $ordersList = \set_order::listOrders($app, $baseIds, $offsetStart, $perPage, $sort); $total = \set_order::countTotalOrder($app['phraseanet.appbox'], $baseIds); return $app['twig']->render('prod/orders/order_box.html.twig', array( @@ -252,7 +252,7 @@ class Order implements ControllerProviderInterface public function displayOneOrder(Application $app, Request $request, $order_id) { try { - $order = new \set_order($order_id); + $order = new \set_order($app, $order_id); } catch (\Exception_NotFound $e) { $app->abort(404); } @@ -275,13 +275,13 @@ class Order implements ControllerProviderInterface $success = false; try { - $order = new \set_order($order_id); + $order = new \set_order($app, $order_id); } catch (\Exception_NotFound $e) { $app->abort(404); } try { - $order->send_elements($request->request->get('elements', array()), ! ! $request->request->get('force', false)); + $order->send_elements($app, $request->request->get('elements', array()), ! ! $request->request->get('force', false)); $success = true; } catch (\Exception $e) { @@ -315,7 +315,7 @@ class Order implements ControllerProviderInterface $success = false; try { - $order = new \set_order($order_id); + $order = new \set_order($app, $order_id); } catch (\Exception_NotFound $e) { $app->abort(404); } diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Printer.php b/lib/Alchemy/Phrasea/Controller/Prod/Printer.php index 11d72c1b09..aa83b3efe0 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Printer.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Printer.php @@ -30,18 +30,18 @@ class Printer implements ControllerProviderInterface $controllers = $app['controllers_factory']; $controllers->post('/', function(Application $app) { - $printer = new RecordHelper\Printer($app['phraseanet.core'], $app['request']); + $printer = new RecordHelper\Printer($app, $app['request']); return $app['twig']->render('prod/actions/printer_default.html.twig', array('printer' => $printer, 'message' => '')); } ); $controllers->post('/print.pdf', function(Application $app) { - $printer = new RecordHelper\Printer($app['phraseanet.core'], $app['request']); + $printer = new RecordHelper\Printer($app, $app['request']); $request = $app['request']; - $session = \Session_Handler::getInstance($app['phraseanet.appbox']); + $session = \Session_Handler::getInstance($app); $layout = $request->request->get('lay'); @@ -49,7 +49,7 @@ class Printer implements ControllerProviderInterface $session->get_logger($record->get_databox()) ->log($record, \Session_Logger::EVENT_PRINT, $layout, ''); } - $PDF = new PDFExport($printer->get_elements(), $layout); + $PDF = new PDFExport($app, $printer->get_elements(), $layout); /** * diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Push.php b/lib/Alchemy/Phrasea/Controller/Prod/Push.php index d14bb56676..ddce94bab6 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Push.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Push.php @@ -51,7 +51,7 @@ class Push implements ControllerProviderInterface /* @var $entry \Entities\UsrListEntry */ $entries[] = array( 'Id' => $entry->getId(), - 'User' => $userFormatter($entry->getUser()) + 'User' => $userFormatter($entry->getUser($app)) ); } @@ -102,17 +102,16 @@ class Push implements ControllerProviderInterface $userSelection = $this->getUsersInSelectionExtractor(); $controllers->post('/sendform/', function(Application $app) use ($userSelection) { - $push = new RecordHelper\Push($app['phraseanet.core'], $app['request']); + $push = new RecordHelper\Push($app, $app['request']); - $em = $app['phraseanet.core']->getEntityManager(); - $repository = $em->getRepository('\Entities\UsrList'); + $repository = $app['EM']->getRepository('\Entities\UsrList'); $RecommendedUsers = $userSelection($push->get_elements()); $params = array( 'push' => $push, 'message' => '', - 'lists' => $repository->findUserLists($app['phraseanet.core']->getAuthenticatedUser()), + 'lists' => $repository->findUserLists($app['phraseanet.user']), 'context' => 'Push', 'RecommendedUsers' => $RecommendedUsers ); @@ -122,17 +121,16 @@ class Push implements ControllerProviderInterface ); $controllers->post('/validateform/', function(Application $app) use ($userSelection) { - $push = new RecordHelper\Push($app['phraseanet.core'], $app['request']); + $push = new RecordHelper\Push($app, $app['request']); - $em = $app['phraseanet.core']->getEntityManager(); - $repository = $em->getRepository('\Entities\UsrList'); + $repository = $app['EM']->getRepository('\Entities\UsrList'); $RecommendedUsers = $userSelection($push->get_elements()); $params = array( 'push' => $push, 'message' => '', - 'lists' => $repository->findUserLists($app['phraseanet.core']->getAuthenticatedUser()), + 'lists' => $repository->findUserLists($app['phraseanet.user']), 'context' => 'Feedback', 'RecommendedUsers' => $RecommendedUsers ); @@ -150,13 +148,11 @@ class Push implements ControllerProviderInterface ); try { - $em = $app['phraseanet.core']->getEntityManager(); + $registry = $app['phraseanet.registry']; - $registry = $app['phraseanet.core']->getRegistry(); + $pusher = new RecordHelper\Push($app, $app['request']); - $pusher = new RecordHelper\Push($app['phraseanet.core'], $app['request']); - - $user = $app['phraseanet.core']->getAuthenticatedUser(); + $user = $app['phraseanet.user']; $appbox = $app['phraseanet.appbox']; @@ -178,11 +174,11 @@ class Push implements ControllerProviderInterface throw new ControllerException(_('No elements to push')); } - $events_manager = $app['phraseanet.core']['events-manager']; + $events_manager = $app['events-manager']; foreach ($receivers as $receiver) { try { - $user_receiver = \User_Adapter::getInstance($receiver['usr_id'], $appbox); + $user_receiver = \User_Adapter::getInstance($receiver['usr_id'], $app); } catch (\Exception $e) { throw new ControllerException(sprintf(_('Unknown user %d'), $receiver['usr_id'])); } @@ -194,37 +190,37 @@ class Push implements ControllerProviderInterface $Basket->setPusher($user); $Basket->setIsRead(false); - $em->persist($Basket); + $app['EM']->persist($Basket); foreach ($pusher->get_elements() as $element) { $BasketElement = new \Entities\BasketElement(); $BasketElement->setRecord($element); $BasketElement->setBasket($Basket); - $em->persist($BasketElement); + $app['EM']->persist($BasketElement); $Basket->addBasketElement($BasketElement); if ($receiver['HD']) { $user_receiver->ACL()->grant_hd_on( - $BasketElement->getRecord() + $BasketElement->getRecord($app) , $user , \ACL::GRANT_ACTION_PUSH ); } else { $user_receiver->ACL()->grant_preview_on( - $BasketElement->getRecord() + $BasketElement->getRecord($app) , $user , \ACL::GRANT_ACTION_PUSH ); } } - $em->flush(); + $app['EM']->flush(); $url = $registry->get('GV_ServerName') . 'lightbox/index.php?LOG=' - . \random::getUrlToken(\random::TYPE_VIEW, $user_receiver->get_id(), null, $Basket->getId()); + . \random::getUrlToken($app, \random::TYPE_VIEW, $user_receiver->get_id(), null, $Basket->getId()); $params = array( 'from' => $user->get_id() @@ -241,10 +237,10 @@ class Push implements ControllerProviderInterface $events_manager->trigger('__PUSH_DATAS__', $params); } - $appbox->get_session()->get_logger($BasketElement->getRecord()->get_databox()) - ->log($BasketElement->getRecord(), \Session_Logger::EVENT_VALIDATE, $user_receiver->get_id(), ''); + $appbox->get_session()->get_logger($BasketElement->getRecord($app)->get_databox()) + ->log($BasketElement->getRecord($app), \Session_Logger::EVENT_VALIDATE, $user_receiver->get_id(), ''); - $em->flush(); + $app['EM']->flush(); $message = sprintf( _('%1$d records have been sent to %2$d users') @@ -273,20 +269,17 @@ class Push implements ControllerProviderInterface 'message' => _('Unable to send the documents') ); - $em = $app['phraseanet.core']->getEntityManager(); + $registry = $app['phraseanet.registry']; - $registry = $app['phraseanet.core']->getRegistry(); - - /* @var $em \Doctrine\ORM\EntityManager */ - $em->beginTransaction(); + $app['EM']->beginTransaction(); try { - $pusher = new RecordHelper\Push($app['phraseanet.core'], $app['request']); - $user = $app['phraseanet.core']->getAuthenticatedUser(); + $pusher = new RecordHelper\Push($app, $app['request']); + $user = $app['phraseanet.user']; - $events_manager = $app['phraseanet.core']['events-manager']; + $events_manager = $app['events-manager']; - $repository = $em->getRepository('\Entities\Basket'); + $repository = $app['EM']->getRepository('\Entities\Basket'); $validation_name = $request->request->get('name'); @@ -315,25 +308,25 @@ class Push implements ControllerProviderInterface $Basket->setOwner($user); $Basket->setIsRead(false); - $em->persist($Basket); + $app['EM']->persist($Basket); foreach ($pusher->get_elements() as $element) { $BasketElement = new \Entities\BasketElement(); $BasketElement->setRecord($element); $BasketElement->setBasket($Basket); - $em->persist($BasketElement); + $app['EM']->persist($BasketElement); $Basket->addBasketElement($BasketElement); } - $em->flush(); + $app['EM']->flush(); } - $em->refresh($Basket); + $app['EM']->refresh($Basket); if ( ! $Basket->getValidation()) { $Validation = new \Entities\ValidationSession(); - $Validation->setInitiator($app['phraseanet.core']->getAuthenticatedUser()); + $Validation->setInitiator($app['phraseanet.user']); $Validation->setBasket($Basket); $duration = (int) $request->request->get('duration'); @@ -344,7 +337,7 @@ class Push implements ControllerProviderInterface } $Basket->setValidation($Validation); - $em->persist($Validation); + $app['EM']->persist($Validation); } else { $Validation = $Basket->getValidation(); } @@ -375,13 +368,13 @@ class Push implements ControllerProviderInterface } try { - $participant_user = \User_Adapter::getInstance($participant['usr_id'], $appbox); + $participant_user = \User_Adapter::getInstance($participant['usr_id'], $app); } catch (\Exception $e) { throw new ControllerException(sprintf(_('Unknown user %d'), $receiver['usr_id'])); } try { - $Participant = $Validation->getParticipant($participant_user); + $Participant = $Validation->getParticipant($participant_user, $app); continue; } catch (\Exception_NotFound $e) { @@ -394,7 +387,7 @@ class Push implements ControllerProviderInterface $Participant->setCanAgree($participant['agree']); $Participant->setCanSeeOthers($participant['see_others']); - $em->persist($Participant); + $app['EM']->persist($Participant); foreach ($Basket->getElements() as $BasketElement) { $ValidationData = new \Entities\ValidationData(); @@ -404,34 +397,34 @@ class Push implements ControllerProviderInterface if ($participant['HD']) { $participant_user->ACL()->grant_hd_on( - $BasketElement->getRecord() + $BasketElement->getRecord($app) , $user , \ACL::GRANT_ACTION_VALIDATE ); } else { $participant_user->ACL()->grant_preview_on( - $BasketElement->getRecord() + $BasketElement->getRecord($app) , $user , \ACL::GRANT_ACTION_VALIDATE ); } - $em->merge($BasketElement); - $em->persist($ValidationData); + $app['EM']->merge($BasketElement); + $app['EM']->persist($ValidationData); - $appbox->get_session()->get_logger($BasketElement->getRecord()->get_databox()) - ->log($BasketElement->getRecord(), \Session_Logger::EVENT_PUSH, $participant_user->get_id(), ''); + $appbox->get_session()->get_logger($BasketElement->getRecord($app)->get_databox()) + ->log($BasketElement->getRecord($app), \Session_Logger::EVENT_PUSH, $participant_user->get_id(), ''); $Participant->addValidationData($ValidationData); } - $Participant = $em->merge($Participant); + $Participant = $app['EM']->merge($Participant); - $em->flush(); + $app['EM']->flush(); $url = $registry->get('GV_ServerName') . 'lightbox/index.php?LOG=' - . \random::getUrlToken(\random::TYPE_VIEW, $participant_user->get_id(), null, $Basket->getId()); + . \random::getUrlToken($app, \random::TYPE_VIEW, $participant_user->get_id(), null, $Basket->getId()); $params = array( 'from' => $user->get_id() @@ -448,10 +441,10 @@ class Push implements ControllerProviderInterface $events_manager->trigger('__PUSH_VALIDATION__', $params); } - $Basket = $em->merge($Basket); - $Validation = $em->merge($Validation); + $Basket = $app['EM']->merge($Basket); + $Validation = $app['EM']->merge($Validation); - $em->flush(); + $app['EM']->flush(); $message = sprintf( _('%1$d records have been sent for validation to %2$d users') @@ -464,10 +457,10 @@ class Push implements ControllerProviderInterface 'message' => $message ); - $em->commit(); + $app['EM']->commit(); } catch (ControllerException $e) { $ret['message'] = $e->getMessage(); - $em->rollback(); + $app['EM']->rollback(); } return $app->json($ret); @@ -479,10 +472,9 @@ class Push implements ControllerProviderInterface $datas = null; $request = $app['request']; - $em = $app['phraseanet.core']->getEntityManager(); - $user = $app['phraseanet.core']->getAuthenticatedUser(); + $user = $app['phraseanet.user']; - $query = new \User_Query($app['phraseanet.appbox']); + $query = new \User_Query($app); $query->on_bases_where_i_am($user->ACL(), array('canpush')); @@ -504,12 +496,11 @@ class Push implements ControllerProviderInterface $controllers->get('/list/{list_id}/', function(Application $app, $list_id) use ($listFormatter) { $datas = null; - $em = $app['phraseanet.core']->getEntityManager(); - $user = $app['phraseanet.core']->getAuthenticatedUser(); + $user = $app['phraseanet.user']; - $repository = $em->getRepository('\Entities\UsrList'); + $repository = $app['EM']->getRepository('\Entities\UsrList'); - $list = $repository->findUserListByUserAndId($user, $list_id); + $list = $repository->findUserListByUserAndId($app, $user, $list_id); if ($list) { $datas = $listFormatter($list); @@ -521,7 +512,7 @@ class Push implements ControllerProviderInterface $controllers->post('/add-user/', function(Application $app, Request $request) use ($userFormatter) { $result = array('success' => false, 'message' => '', 'user' => null); - $AdminUser = $app['phraseanet.core']->getAuthenticatedUser(); + $AdminUser = $app['phraseanet.user']; try { /* @var $AdminUser \User_Adapter */ @@ -551,8 +542,8 @@ class Push implements ControllerProviderInterface $email = $request->request->get('email'); try { - $usr_id = \User_Adapter::get_usr_id_from_email($email); - $user = \User_Adapter::getInstance($usr_id, $appbox); + $usr_id = \User_Adapter::get_usr_id_from_email($app, $email); + $user = \User_Adapter::getInstance($usr_id, $app); $result['message'] = _('User already exists'); $result['success'] = true; @@ -565,7 +556,7 @@ class Push implements ControllerProviderInterface try { $password = \random::generatePassword(); - $user = \User_Adapter::create($appbox, $email, $password, $email, false); + $user = \User_Adapter::create($app, $email, $password, $email, false); $user->set_firstname($request->request->get('firstname')) ->set_lastname($request->request->get('lastname')); @@ -596,10 +587,9 @@ class Push implements ControllerProviderInterface $controllers->get('/search-user/', function(Application $app) use ($userFormatter, $listFormatter) { $request = $app['request']; - $em = $app['phraseanet.core']->getEntityManager(); - $user = $app['phraseanet.core']->getAuthenticatedUser(); + $user = $app['phraseanet.user']; - $query = new \User_Query($app['phraseanet.appbox']); + $query = new \User_Query($app); $query->on_bases_where_i_am($user->ACL(), array('canpush')); @@ -612,7 +602,7 @@ class Push implements ControllerProviderInterface ->limit(0, 50) ->execute()->get_results(); - $repository = $em->getRepository('\Entities\UsrList'); + $repository = $app['EM']->getRepository('\Entities\UsrList'); $lists = $repository->findUserListLike($user, $request->query->get('query')); @@ -636,14 +626,13 @@ class Push implements ControllerProviderInterface $controllers->match('/edit-list/{list_id}/', function(Application $app, Request $request, $list_id) { - $user = $app['phraseanet.core']->getAuthenticatedUser(); - $em = $app['phraseanet.core']->getEntityManager(); + $user = $app['phraseanet.user']; - $repository = $em->getRepository('\Entities\UsrList'); + $repository = $app['EM']->getRepository('\Entities\UsrList'); - $list = $repository->findUserListByUserAndId($user, $list_id); + $list = $repository->findUserListByUserAndId($app, $user, $list_id); - $query = new \User_Query($app['phraseanet.appbox']); + $query = new \User_Query($app); $query->on_bases_where_i_am($user->ACL(), array('canpush')); diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Query.php b/lib/Alchemy/Phrasea/Controller/Prod/Query.php index 78d28ed564..beb5f34cde 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Query.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Query.php @@ -32,7 +32,7 @@ class Query implements ControllerProviderInterface $appbox = $app['phraseanet.appbox']; $registry = $appbox->get_registry(); - $user = $app['phraseanet.core']->getAuthenticatedUser(); + $user = $app['phraseanet.user']; $query = (string) $request->request->get('qry'); @@ -79,7 +79,7 @@ class Query implements ControllerProviderInterface $perPage = (int) $user->getPrefs('images_per_page'); - $search_engine = new \searchEngine_adapter($registry); + $search_engine = new \searchEngine_adapter($app); $search_engine->set_options($options); $page = (int) $request->request->get('pag'); @@ -165,7 +165,7 @@ class Query implements ControllerProviderInterface $prop = null; if ($search_engine->is_first_page()) { - $propals = $result->get_suggestions(); + $propals = $result->get_suggestions($app['phraseanet.appbox']->get_session()->get_I18n()); if (count($propals) > 0) { foreach ($propals as $prop_array) { if ($prop_array['value'] !== $query && $prop_array['hits'] > $result->get_count_total_results()) { diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Root.php b/lib/Alchemy/Phrasea/Controller/Prod/Root.php index 332a148ceb..aead25444f 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Root.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Root.php @@ -32,11 +32,11 @@ class Root implements ControllerProviderInterface $controllers->get('/', function(Application $app) { - \User_Adapter::updateClientInfos(1); + \User_Adapter::updateClientInfos($app, 1); $appbox = $app['phraseanet.appbox']; - $registry = $app['phraseanet.core']->getRegistry(); - $user = $app['phraseanet.core']->getAuthenticatedUser(); + $registry = $app['phraseanet.registry']; + $user = $app['phraseanet.user']; $cssPath = $registry->get('GV_RootPath') . 'www/skins/prod/'; $css = array(); @@ -63,7 +63,7 @@ class Root implements ControllerProviderInterface $cssfile = '000000'; } - $user_feeds = \Feed_Collection::load_all($appbox, $user); + $user_feeds = \Feed_Collection::load_all($app, $user); $feeds = array_merge(array($user_feeds->get_aggregate()), $user_feeds->get_feeds()); $thjslist = ""; @@ -71,9 +71,9 @@ class Root implements ControllerProviderInterface $queries_topics = ''; if ($registry->get('GV_client_render_topics') == 'popups') { - $queries_topics = \queries::dropdown_topics(); + $queries_topics = \queries::dropdown_topics($appbox->get_session()->get_I18n()); } elseif ($registry->get('GV_client_render_topics') == 'tree') { - $queries_topics = \queries::tree_topics(); + $queries_topics = \queries::tree_topics($appbox->get_session()->get_I18n()); } $sbas = $bas2sbas = array(); @@ -96,21 +96,21 @@ class Root implements ControllerProviderInterface $out = $app['twig']->render('prod/index.html.twig', array( 'module_name' => 'Production', - 'WorkZone' => new Helper\WorkZone($app['phraseanet.core'], $app['request']), - 'module_prod' => new Helper\Prod($app['phraseanet.core'], $app['request']), + 'WorkZone' => new Helper\WorkZone($app, $app['request']), + 'module_prod' => new Helper\Prod($app, $app['request']), 'cssfile' => $cssfile, 'module' => 'prod', - 'events' => $app['phraseanet.core']['events-manager'], + 'events' => $app['events-manager'], 'GV_defaultQuery_type' => $registry->get('GV_defaultQuery_type'), 'GV_multiAndReport' => $registry->get('GV_multiAndReport'), 'GV_thesaurus' => $registry->get('GV_thesaurus'), - 'cgus_agreement' => \databox_cgu::askAgreement(), + 'cgus_agreement' => \databox_cgu::askAgreement($app), 'css' => $css, 'feeds' => $feeds, 'GV_google_api' => $registry->get('GV_google_api'), 'queries_topics' => $queries_topics, - 'search_status' => \databox_status::getSearchStatus(), - 'queries_history' => \queries::history(), + 'search_status' => \databox_status::getSearchStatus($app), + 'queries_history' => \queries::history($app['phraseanet.appbox'], $app['phraseanet.user']->get_id()), 'thesau_js_list' => $thjslist, 'thesau_json_sbas' => json_encode($sbas), 'thesau_json_bas2sbas' => json_encode($bas2sbas), @@ -122,14 +122,14 @@ class Root implements ControllerProviderInterface $controllers->post('/multi-export/', function(Application $app, Request $request) { - $download = new \set_export($request->request->get('lst', ''), (int) $request->request->get('ssel'), $request->request->get('story')); + $download = new \set_export($app, $request->request->get('lst', ''), (int) $request->request->get('ssel'), $request->request->get('story')); return $app['twig']->render('common/dialog_export.html.twig', array( 'download' => $download, 'ssttid' => (int) $request->request->get('ssel'), 'lst' => $download->serialize_list(), - 'default_export_title' => $app['phraseanet.core']['Registry']->get('GV_default_export_title'), - 'choose_export_title' => $app['phraseanet.core']['Registry']->get('GV_choose_export_title') + 'default_export_title' => $app['phraseanet.registry']->get('GV_default_export_title'), + 'choose_export_title' => $app['phraseanet.registry']->get('GV_choose_export_title') )); }); diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Story.php b/lib/Alchemy/Phrasea/Controller/Prod/Story.php index 2b585c142d..60776b7bab 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Story.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Story.php @@ -36,17 +36,15 @@ class Story implements ControllerProviderInterface $controllers->post('/', function(Application $app, Request $request) { /* @var $request \Symfony\Component\HttpFoundation\Request */ - $em = $app['phraseanet.core']->getEntityManager(); + $user = $app['phraseanet.user']; - $user = $app['phraseanet.core']->getAuthenticatedUser(); + $collection = \collection::get_from_base_id($app, $request->request->get('base_id')); - $collection = \collection::get_from_base_id($request->request->get('base_id')); - - if ( ! $user->ACL()->has_right_on_base($collection->get_base_id(), 'canaddrecord')) { + if (!$user->ACL()->has_right_on_base($collection->get_base_id(), 'canaddrecord')) { throw new \Exception_Forbidden('You can not create a story on this collection'); } - $Story = \record_adapter::createStory($collection); + $Story = \record_adapter::createStory($app, $collection); foreach (explode(';', $request->request->get('lst')) as $sbas_rec) { $sbas_rec = explode('_', $sbas_rec); @@ -55,11 +53,11 @@ class Story implements ControllerProviderInterface continue; } - $record = new \record_adapter($sbas_rec[0], $sbas_rec[1]); + $record = new \record_adapter($app, $sbas_rec[0], $sbas_rec[1]); - if ( ! $user->ACL()->has_access_to_base($record->get_base_id()) - && ! $user->ACL()->has_hd_grant($record) - && ! $user->ACL()->has_preview_grant($record)) { + if (!$user->ACL()->has_access_to_base($record->get_base_id()) + && !$user->ACL()->has_hd_grant($record) + && !$user->ACL()->has_preview_grant($record)) { continue; } @@ -93,9 +91,9 @@ class Story implements ControllerProviderInterface $StoryWZ->setUser($user); $StoryWZ->setRecord($Story); - $em->persist($StoryWZ); + $app['EM']->persist($StoryWZ); - $em->flush(); + $app['EM']->flush(); if ($request->getRequestFormat() == 'json') { $data = array( @@ -115,7 +113,7 @@ class Story implements ControllerProviderInterface }); $controllers->get('/{sbas_id}/{record_id}/', function(Application $app, $sbas_id, $record_id) { - $Story = new \record_adapter($sbas_id, $record_id); + $Story = new \record_adapter($app, $sbas_id, $record_id); $html = $app['twig']->render('prod/WorkZone/Story.html.twig', array('Story' => $Story)); @@ -125,11 +123,11 @@ class Story implements ControllerProviderInterface $controllers->post( '/{sbas_id}/{record_id}/addElements/' , function(Application $app, Request $request, $sbas_id, $record_id) { - $Story = new \record_adapter($sbas_id, $record_id); + $Story = new \record_adapter($app, $sbas_id, $record_id); - $user = $app['phraseanet.core']->getAuthenticatedUser(); + $user = $app['phraseanet.user']; - if ( ! $user->ACL()->has_right_on_base($Story->get_base_id(), 'canmodifrecord')) + if (!$user->ACL()->has_right_on_base($Story->get_base_id(), 'canmodifrecord')) throw new \Exception_Forbidden('You can not add document to this Story'); /* @var $user \User_Adapter */ @@ -142,11 +140,11 @@ class Story implements ControllerProviderInterface if (count($sbas_rec) !== 2) continue; - $record = new \record_adapter($sbas_rec[0], $sbas_rec[1]); + $record = new \record_adapter($app, $sbas_rec[0], $sbas_rec[1]); - if ( ! $user->ACL()->has_access_to_base($record->get_base_id()) - && ! $user->ACL()->has_hd_grant($record) - && ! $user->ACL()->has_preview_grant($record)) { + if (!$user->ACL()->has_access_to_base($record->get_base_id()) + && !$user->ACL()->has_hd_grant($record) + && !$user->ACL()->has_preview_grant($record)) { continue; } @@ -155,7 +153,7 @@ class Story implements ControllerProviderInterface $Story->appendChild($record); - $n ++; + $n++; } $data = array( @@ -173,13 +171,13 @@ class Story implements ControllerProviderInterface $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($sbas_id, $record_id); + $Story = new \record_adapter($app, $sbas_id, $record_id); - $record = new \record_adapter($child_sbas_id, $child_record_id); + $record = new \record_adapter($app, $child_sbas_id, $child_record_id); - $user = $app['phraseanet.core']->getAuthenticatedUser(); + $user = $app['phraseanet.user']; - if ( ! $user->ACL()->has_right_on_base($Story->get_base_id(), 'canmodifrecord')) + if (!$user->ACL()->has_right_on_base($Story->get_base_id(), 'canmodifrecord')) throw new \Exception_Forbidden('You can not add document to this Story'); /* @var $user \User_Adapter */ @@ -205,15 +203,10 @@ class Story implements ControllerProviderInterface /** * Get the Basket reorder form */ - $controllers->get( - '/{sbas_id}/{record_id}/reorder/' - , function(Application $app, $sbas_id, $record_id) { - /* @var $em \Doctrine\ORM\EntityManager */ - $em = $app['phraseanet.core']->getEntityManager(); + $controllers->get('/{sbas_id}/{record_id}/reorder/', function(Application $app, $sbas_id, $record_id) { + $story = new \record_adapter($app, $sbas_id, $record_id); - $story = new \record_adapter($sbas_id, $record_id); - - if ( ! $story->is_grouping()) { + if (!$story->is_grouping()) { throw new \Exception('This is not a story'); } @@ -232,16 +225,16 @@ class Story implements ControllerProviderInterface , function(Application $app, $sbas_id, $record_id) { $ret = array('success' => false, 'message' => _('An error occured')); try { - $user = $app['phraseanet.core']->getAuthenticatedUser(); + $user = $app['phraseanet.user']; /* @var $user \User_Adapter */ - $story = new \record_adapter($sbas_id, $record_id); + $story = new \record_adapter($app, $sbas_id, $record_id); - if ( ! $story->is_grouping()) { + if (!$story->is_grouping()) { throw new \Exception('This is not a story'); } - if ( ! $user->ACL()->has_right_on_base($story->get_base_id(), 'canmodifrecord')) { + if (!$user->ACL()->has_right_on_base($story->get_base_id(), 'canmodifrecord')) { throw new ControllerException(_('You can not edit this story')); } diff --git a/lib/Alchemy/Phrasea/Controller/Prod/TOU.php b/lib/Alchemy/Phrasea/Controller/Prod/TOU.php index 7d62d1f34e..2d073cf8c6 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/TOU.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/TOU.php @@ -31,8 +31,8 @@ class TOU implements ControllerProviderInterface $ret = array('success' => false, 'message' => ''); try { - $user = $app['phraseanet.core']->getAuthenticatedUser(); - $session = \Session_Handler::getInstance($app['phraseanet.appbox']); + $user = $app['phraseanet.user']; + $session = \Session_Handler::getInstance($app); $databox = $app['phraseanet.appbox']->get_databox((int) $sbas_id); diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Tools.php b/lib/Alchemy/Phrasea/Controller/Prod/Tools.php index 15e6ccfa40..40c94fdc42 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Tools.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Tools.php @@ -39,7 +39,7 @@ class Tools implements ControllerProviderInterface if (count($records) == 1) { $record = $records->first(); - if ( ! $record->is_grouping()) { + if (!$record->is_grouping()) { try { $reader = new \PHPExiftool\Reader(); @@ -66,18 +66,22 @@ class Tools implements ControllerProviderInterface }); $controllers->post('/rotate/', function(Application $app, Request $request) { - $return = array('success' => false, 'errorMessage' => ''); + $return = array('success' => true, 'errorMessage' => ''); $records = RecordsRequest::fromRequest($app, $request, false); $rotation = in_array($request->request->get('rotation'), array('-90', '90', '180')) ? $request->request->get('rotation', 90) : 90; foreach ($records as $record) { - try { - $record->rotate_subdefs($rotation); - $return['success'] = true; - } catch (\Exception $e) { - $return['errorMessage'] = $e->getMessage(); + foreach ($record->get_subdefs() as $name => $subdef) { + if ($name == 'document') + continue; + + try { + $subdef->rotate($rotation, $app['media-alchemyst'], $app['mediavorus']); + } catch (\Exception $e) { + + } } } @@ -87,7 +91,7 @@ class Tools implements ControllerProviderInterface $controllers->post('/image/', function(Application $app, Request $request) { $return = array('success' => true); - $helper = new Helper\Record\Tools($app['phraseanet.core'], $request); + $helper = new Helper\Record\Tools($app, $request); $selection = $helper->get_elements(); @@ -101,7 +105,7 @@ class Tools implements ControllerProviderInterface } } - if ( ! $substituted || $request->request->get('ForceThumbSubstit') == '1') { + if (!$substituted || $request->request->get('ForceThumbSubstit') == '1') { $record->rebuild_subdefs(); } } @@ -130,13 +134,14 @@ class Tools implements ControllerProviderInterface try { $record = new \record_adapter( + $app, $request->request->get('sbas_id') , $request->request->get('record_id') ); - $media = $app['phraseanet.core']['mediavorus']->guess($tempoFile); + $media = $app['mediavorus']->guess($tempoFile); - $record->substitute_subdef('document', $media, $app['filesystem'], $app['phraseanet.core']['media-alchemyst'], $app['phraseanet.core']['mediavorus']); + $record->substitute_subdef('document', $media, $app); if ((int) $request->request->get('ccfilename') === 1) { $record->set_original_name($fileName); @@ -180,18 +185,19 @@ class Tools implements ControllerProviderInterface if ($size && $fileName && $file->isValid()) { try { - $rootPath = $app['phraseanet.core']->getRegistry()->get('GV_RootPath'); + $rootPath = $app['phraseanet.registry']->get('GV_RootPath'); $tmpFile = $rootPath . 'tmp/' . $fileName; rename($file->getPathname(), $tmpFile); $record = new \record_adapter( + $app, $request->request->get('sbas_id') , $request->request->get('record_id') ); - $media = $app['phraseanet.core']['mediavorus']->guess($file); + $media = $app['mediavorus']->guess($tmpFile); - $record->substitute_subdef('thumbnail', $media); + $record->substitute_subdef('thumbnail', $media, $app); $success = true; } catch (\Exception $e) { @@ -217,7 +223,7 @@ class Tools implements ControllerProviderInterface $template = 'prod/actions/Tools/confirm.html.twig'; try { - $record = new \record_adapter($request->request->get('sbas_id'), $request->request->get('record_id')); + $record = new \record_adapter($app, $request->request->get('sbas_id'), $request->request->get('record_id')); $var = array( 'video_title' => $record->get_title() , 'image' => $request->request->get('image', '') @@ -235,11 +241,11 @@ class Tools implements ControllerProviderInterface $return = array('success' => false, 'message' => ''); try { - $record = new \record_adapter($request->request->get('sbas_id'), $request->request->get('record_id')); + $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['phraseanet.core']->getRegistry()->get('GV_RootPath') . 'tmp'; + $path = $app['phraseanet.registry']->get('GV_RootPath') . 'tmp'; $name = sprintf('extractor_thumb_%s', $record->get_serialize_key()); @@ -247,9 +253,9 @@ class Tools implements ControllerProviderInterface file_put_contents($fileName, $dataUri->getData()); - $media = $app['phraseanet.core']['mediavorus']->guess(new \SplFileInfo($fileName)); + $media = $app['mediavorus']->guess($fileName); - $record->substitute_subdef('thumbnail', $media); + $record->substitute_subdef('thumbnail', $media, $app); unset($media); $app['filesystem']->remove($fileName); diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Tooltip.php b/lib/Alchemy/Phrasea/Controller/Prod/Tooltip.php index 3250822bdc..94b09decc7 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Tooltip.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Tooltip.php @@ -65,24 +65,22 @@ class Tooltip implements ControllerProviderInterface public function displayBasket(Application $app, $basket_id) { - $em = $app['phraseanet.core']->getEntityManager(); - - $basket = $em->getRepository('\Entities\Basket') - ->findUserBasket($basket_id, $app['phraseanet.core']->getAuthenticatedUser(), false); + $basket = $app['EM']->getRepository('\Entities\Basket') + ->findUserBasket($app, $basket_id, $app['phraseanet.user'], false); return $app['twig']->render('prod/Tooltip/Basket.html.twig', array('basket' => $basket)); } public function displayStory(Application $app, $sbas_id, $record_id) { - $Story = new \record_adapter($sbas_id, $record_id); + $Story = new \record_adapter($app, $sbas_id, $record_id); return $app['twig']->render('prod/Tooltip/Story.html.twig', array('Story' => $Story)); } public function displayUserBadge(Application $app, $usr_id) { - $user = \User_Adapter::getInstance($usr_id, $app['phraseanet.appbox']); + $user = \User_Adapter::getInstance($usr_id, $app); return $app['twig']->render( 'prod/Tooltip/User.html.twig' @@ -92,7 +90,7 @@ class Tooltip implements ControllerProviderInterface public function displayPreview(Application $app, $sbas_id, $record_id) { - $record = new \record_adapter($sbas_id, $record_id); + $record = new \record_adapter($app, $sbas_id, $record_id); return $app['twig']->render( 'prod/Tooltip/Preview.html.twig' @@ -103,13 +101,13 @@ class Tooltip implements ControllerProviderInterface public function displayCaption(Application $app, $sbas_id, $record_id, $context) { $number = (int) $app['request']->request->get('number'); - $record = new \record_adapter($sbas_id, $record_id, $number); + $record = new \record_adapter($app, $sbas_id, $record_id, $number); $search_engine = null; if ($context == 'answer') { if (($search_engine_options = unserialize($app['request']->request->get('options_serial'))) !== false) { - $search_engine = new \searchEngine_adapter($app['phraseanet.appbox']->get_registry()); + $search_engine = new \searchEngine_adapter($app); $search_engine->set_options($search_engine_options); } } @@ -127,7 +125,7 @@ class Tooltip implements ControllerProviderInterface public function displayTechnicalDatas(Application $app, $sbas_id, $record_id) { - $record = new \record_adapter($sbas_id, $record_id); + $record = new \record_adapter($app, $sbas_id, $record_id); return $app['twig']->render( 'prod/Tooltip/TechnicalDatas.html.twig' @@ -138,7 +136,7 @@ class Tooltip implements ControllerProviderInterface public function displayFieldInfos(Application $app, $sbas_id, $field_id) { $databox = $app['phraseanet.appbox']->get_databox((int) $sbas_id); - $field = \databox_field::get_instance($databox, $field_id); + $field = \databox_field::get_instance($app, $databox, $field_id); return $app['twig']->render( 'prod/Tooltip/DataboxField.html.twig' @@ -149,7 +147,7 @@ class Tooltip implements ControllerProviderInterface public function displayDCESInfos(Application $app, $sbas_id, $field_id) { $databox = $app['phraseanet.appbox']->get_databox((int) $sbas_id); - $field = \databox_field::get_instance($databox, $field_id); + $field = \databox_field::get_instance($app, $databox, $field_id); return $app['twig']->render( 'prod/Tooltip/DCESFieldInfo.html.twig' @@ -160,7 +158,7 @@ class Tooltip implements ControllerProviderInterface public function displayMetaRestrictions(Application $app, $sbas_id, $field_id) { $databox = $app['phraseanet.appbox']->get_databox((int) $sbas_id); - $field = \databox_field::get_instance($databox, $field_id); + $field = \databox_field::get_instance($app, $databox, $field_id); return $app['twig']->render( 'prod/Tooltip/DataboxFieldRestrictions.html.twig' diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Upload.php b/lib/Alchemy/Phrasea/Controller/Prod/Upload.php index 2a5d3b0e11..24beb432c7 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Upload.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Upload.php @@ -108,7 +108,7 @@ class Upload implements ControllerProviderInterface return $app['twig']->render( 'prod/upload/upload-flash.html.twig', array( 'sessionId' => session_id(), - 'collections' => $this->getGrantedCollections($app['phraseanet.core']->getAuthenticatedUser()), + 'collections' => $this->getGrantedCollections($app['phraseanet.user']), 'maxFileSize' => $maxFileSize, 'maxFileSizeReadable' => \p4string::format_octets($maxFileSize) ) @@ -129,7 +129,7 @@ class Upload implements ControllerProviderInterface return $app['twig']->render( 'prod/upload/upload.html.twig', array( - 'collections' => $this->getGrantedCollections($app['phraseanet.core']->getAuthenticatedUser()), + 'collections' => $this->getGrantedCollections($app['phraseanet.user']), 'maxFileSize' => $maxFileSize, 'maxFileSizeReadable' => \p4string::format_octets($maxFileSize) ) @@ -169,7 +169,7 @@ class Upload implements ControllerProviderInterface throw new \Exception_BadRequest('Missing base_id parameter'); } - if ( ! $app['phraseanet.core']->getAuthenticatedUser()->ACL()->has_right_on_base($base_id, 'canaddrecord')) { + if ( ! $app['phraseanet.user']->ACL()->has_right_on_base($base_id, 'canaddrecord')) { throw new \Exception_Forbidden('User is not allowed to add record on this collection'); } @@ -184,22 +184,15 @@ class Upload implements ControllerProviderInterface $uploadedFilename = $file->getRealPath(); $renamedFilename = $file->getRealPath() . '.' . pathinfo($file->getClientOriginalName(), PATHINFO_EXTENSION); - $originalname = $file->getClientOriginalName(); - $clientMimeType = $file->getClientMimeType(); - $size = $file->getSize(); - $error = $file->getError(); - $app['filesystem']->rename($uploadedFilename, $renamedFilename); - $file = new UploadedFile($renamedFilename, $originalname, $clientMimeType, $size, $error); - - $media = $app['phraseanet.core']['mediavorus']->guess($file); - $collection = \collection::get_from_base_id($base_id); + $media = $app['mediavorus']->guess($renamedFilename); + $collection = \collection::get_from_base_id($app, $base_id); $lazaretSession = new LazaretSession(); - $lazaretSession->setUsrId($app['phraseanet.core']->getAuthenticatedUser()->get_id()); + $lazaretSession->setUsrId($app['phraseanet.user']->get_id()); - $app['phraseanet.core']['EM']->persist($lazaretSession); + $app['EM']->persist($lazaretSession); $packageFile = new File($media, $collection, $file->getClientOriginalName()); @@ -212,7 +205,7 @@ class Upload implements ControllerProviderInterface foreach (range(0, 63) as $i) { $status .= isset($postStatus[$i]) ? ($postStatus[$i] ? '1' : '0') : '0'; } - $packageFile->addAttribute(new Status(strrev($status))); + $packageFile->addAttribute(new Status($app, strrev($status))); } $forceBehavior = $request->request->get('forceAction'); @@ -230,7 +223,7 @@ class Upload implements ControllerProviderInterface $elementCreated = $element; }; - $code = $app['phraseanet.core']['border-manager']->process( + $code = $app['border-manager']->process( $lazaretSession, $packageFile, $callback, $forceBehavior ); @@ -249,7 +242,7 @@ class Upload implements ControllerProviderInterface $appbox = $app['phraseanet.appbox']; - $eventsManager = $app['phraseanet.core']['events-manager']; + $eventsManager = $app['events-manager']; $eventsManager->trigger('__UPLOAD_QUARANTINE__', $params); $id = $elementCreated->getId(); diff --git a/lib/Alchemy/Phrasea/Controller/Prod/UserPreferences.php b/lib/Alchemy/Phrasea/Controller/Prod/UserPreferences.php index 223b2bc4ea..bbe4d6c20b 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/UserPreferences.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/UserPreferences.php @@ -37,7 +37,7 @@ class UserPreferences implements ControllerProviderInterface $ret = array('success' => false, 'message' => _('Error while saving preference')); try { - $user = $app['phraseanet.core']->getAuthenticatedUser(); + $user = $app['phraseanet.user']; $ret = $user->setPrefs($request->request->get('prop'), $request->request->get('value')); diff --git a/lib/Alchemy/Phrasea/Controller/Prod/UsrLists.php b/lib/Alchemy/Phrasea/Controller/Prod/UsrLists.php index d3ca848457..c0b8b962cc 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/UsrLists.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/UsrLists.php @@ -103,11 +103,9 @@ class UsrLists implements ControllerProviderInterface $lists = new ArrayCollection(); try { - $em = $app['phraseanet.core']->getEntityManager(); + $repository = $app['EM']->getRepository('\Entities\UsrList'); - $repository = $em->getRepository('\Entities\UsrList'); - - $lists = $repository->findUserLists($app['phraseanet.core']->getAuthenticatedUser()); + $lists = $repository->findUserLists($app['phraseanet.user']); $result = array(); @@ -116,24 +114,24 @@ class UsrLists implements ControllerProviderInterface foreach ($list->getOwners() as $owner) { $owners[] = array( - 'usr_id' => $owner->getUser()->get_id(), - 'display_name' => $owner->getUser()->get_display_name(), - 'position' => $owner->getUser()->get_position(), - 'job' => $owner->getUser()->get_job(), - 'company' => $owner->getUser()->get_company(), - 'email' => $owner->getUser()->get_email(), + 'usr_id' => $owner->getUser($app)->get_id(), + 'display_name' => $owner->getUser($app)->get_display_name(), + 'position' => $owner->getUser($app)->get_position(), + 'job' => $owner->getUser($app)->get_job(), + 'company' => $owner->getUser($app)->get_company(), + 'email' => $owner->getUser($app)->get_email(), 'role' => $owner->getRole() ); } foreach ($list->getEntries() as $entry) { $entries[] = array( - 'usr_id' => $owner->getUser()->get_id(), - 'display_name' => $owner->getUser()->get_display_name(), - 'position' => $owner->getUser()->get_position(), - 'job' => $owner->getUser()->get_job(), - 'company' => $owner->getUser()->get_company(), - 'email' => $owner->getUser()->get_email(), + 'usr_id' => $owner->getUser($app)->get_id(), + 'display_name' => $owner->getUser($app)->get_display_name(), + 'position' => $owner->getUser($app)->get_position(), + 'job' => $owner->getUser($app)->get_job(), + 'company' => $owner->getUser($app)->get_company(), + 'email' => $owner->getUser($app)->get_email(), ); } @@ -185,21 +183,19 @@ class UsrLists implements ControllerProviderInterface throw new ControllerException(_('List name is required')); } - $em = $app['phraseanet.core']->getEntityManager(); - $List = new UsrList(); $Owner = new UsrListOwner(); $Owner->setRole(UsrListOwner::ROLE_ADMIN); - $Owner->setUser($app['phraseanet.core']->getAuthenticatedUser()); + $Owner->setUser($app['phraseanet.user']); $Owner->setList($List); $List->setName($list_name); $List->addUsrListOwner($Owner); - $em->persist($Owner); - $em->persist($List); - $em->flush(); + $app['EM']->persist($Owner); + $app['EM']->persist($List); + $app['EM']->flush(); $datas = array( 'success' => true @@ -220,36 +216,35 @@ class UsrLists implements ControllerProviderInterface public function displayList(Application $app, Request $request, $list_id) { - $user = $app['phraseanet.core']->getAuthenticatedUser(); - $em = $app['phraseanet.core']->getEntityManager(); + $user = $app['phraseanet.user']; - $repository = $em->getRepository('\Entities\UsrList'); + $repository = $app['EM']->getRepository('\Entities\UsrList'); - $list = $repository->findUserListByUserAndId($user, $list_id); + $list = $repository->findUserListByUserAndId($app, $user, $list_id); $entries = new ArrayCollection(); $owners = new ArrayCollection(); foreach ($list->getOwners() as $owner) { $owners[] = array( - 'usr_id' => $owner->getUser()->get_id(), - 'display_name' => $owner->getUser()->get_display_name(), - 'position' => $owner->getUser()->get_position(), - 'job' => $owner->getUser()->get_job(), - 'company' => $owner->getUser()->get_company(), - 'email' => $owner->getUser()->get_email(), - 'role' => $owner->getRole() + 'usr_id' => $owner->getUser($app)->get_id(), + 'display_name' => $owner->getUser($app)->get_display_name(), + 'position' => $owner->getUser($app)->get_position(), + 'job' => $owner->getUser($app)->get_job(), + 'company' => $owner->getUser($app)->get_company(), + 'email' => $owner->getUser($app)->get_email(), + 'role' => $owner->getRole($app) ); } foreach ($list->getEntries() as $entry) { $entries[] = array( - 'usr_id' => $entry->getUser()->get_id(), - 'display_name' => $entry->getUser()->get_display_name(), - 'position' => $entry->getUser()->get_position(), - 'job' => $entry->getUser()->get_job(), - 'company' => $entry->getUser()->get_company(), - 'email' => $entry->getUser()->get_email(), + 'usr_id' => $entry->getUser($app)->get_id(), + 'display_name' => $entry->getUser($app)->get_display_name(), + 'position' => $entry->getUser($app)->get_position(), + 'job' => $entry->getUser($app)->get_job(), + 'company' => $entry->getUser($app)->get_company(), + 'email' => $entry->getUser($app)->get_email(), ); } @@ -281,20 +276,19 @@ class UsrLists implements ControllerProviderInterface throw new ControllerException(_('List name is required')); } - $user = $app['phraseanet.core']->getAuthenticatedUser(); - $em = $app['phraseanet.core']->getEntityManager(); + $user = $app['phraseanet.user']; - $repository = $em->getRepository('\Entities\UsrList'); + $repository = $app['EM']->getRepository('\Entities\UsrList'); - $list = $repository->findUserListByUserAndId($user, $list_id); + $list = $repository->findUserListByUserAndId($app, $user, $list_id); - if ($list->getOwner($user)->getRole() < UsrListOwner::ROLE_EDITOR) { + if ($list->getOwner($user, $app)->getRole() < UsrListOwner::ROLE_EDITOR) { throw new ControllerException(_('You are not authorized to do this')); } $list->setName($list_name); - $em->flush(); + $app['EM']->flush(); $datas = array( 'success' => true @@ -314,21 +308,19 @@ class UsrLists implements ControllerProviderInterface public function removeList(Application $app, $list_id) { - $em = $app['phraseanet.core']->getEntityManager(); - try { - $repository = $em->getRepository('\Entities\UsrList'); + $repository = $app['EM']->getRepository('\Entities\UsrList'); - $user = $app['phraseanet.core']->getAuthenticatedUser(); + $user = $app['phraseanet.user']; - $list = $repository->findUserListByUserAndId($user, $list_id); + $list = $repository->findUserListByUserAndId($app, $user, $list_id); - if ($list->getOwner($user)->getRole() < UsrListOwner::ROLE_ADMIN) { + if ($list->getOwner($user, $app)->getRole() < UsrListOwner::ROLE_ADMIN) { throw new ControllerException(_('You are not authorized to do this')); } - $em->remove($list); - $em->flush(); + $app['EM']->remove($list); + $app['EM']->flush(); $datas = array( 'success' => true @@ -352,26 +344,24 @@ class UsrLists implements ControllerProviderInterface public function removeUser(Application $app, $list_id, $usr_id) { - $em = $app['phraseanet.core']->getEntityManager(); - try { - $repository = $em->getRepository('\Entities\UsrList'); + $repository = $app['EM']->getRepository('\Entities\UsrList'); - $user = $app['phraseanet.core']->getAuthenticatedUser(); + $user = $app['phraseanet.user']; - $list = $repository->findUserListByUserAndId($user, $list_id); + $list = $repository->findUserListByUserAndId($app, $user, $list_id); /* @var $list \Entities\UsrList */ - if ($list->getOwner($user)->getRole() < UsrListOwner::ROLE_EDITOR) { + if ($list->getOwner($user, $app)->getRole() < UsrListOwner::ROLE_EDITOR) { throw new ControllerException(_('You are not authorized to do this')); } - $entry_repository = $em->getRepository('\Entities\UsrListEntry'); + $entry_repository = $app['EM']->getRepository('\Entities\UsrListEntry'); $user_entry = $entry_repository->findEntryByListAndUsrId($list, $usr_id); - $em->remove($user_entry); - $em->flush(); + $app['EM']->remove($user_entry); + $app['EM']->flush(); $datas = array( 'success' => true @@ -395,29 +385,28 @@ class UsrLists implements ControllerProviderInterface public function addUsers(Application $app, Request $request, $list_id) { - $em = $app['phraseanet.core']->getEntityManager(); - $user = $app['phraseanet.core']->getAuthenticatedUser(); + $user = $app['phraseanet.user']; try { if ( ! is_array($request->request->get('usr_ids'))) { throw new ControllerException('Invalid or missing parameter usr_ids'); } - $repository = $em->getRepository('\Entities\UsrList'); + $repository = $app['EM']->getRepository('\Entities\UsrList'); - $list = $repository->findUserListByUserAndId($user, $list_id); + $list = $repository->findUserListByUserAndId($app, $user, $list_id); /* @var $list \Entities\UsrList */ - if ($list->getOwner($user)->getRole() < UsrListOwner::ROLE_EDITOR) { + if ($list->getOwner($user, $app)->getRole() < UsrListOwner::ROLE_EDITOR) { throw new ControllerException(_('You are not authorized to do this')); } $inserted_usr_ids = array(); foreach ($request->request->get('usr_ids') as $usr_id) { - $user_entry = \User_Adapter::getInstance($usr_id, $app['phraseanet.appbox']); + $user_entry = \User_Adapter::getInstance($usr_id, $app); - if ($list->has($user_entry)) + if ($list->has($user_entry, $app)) continue; $entry = new UsrListEntry(); @@ -426,12 +415,12 @@ class UsrLists implements ControllerProviderInterface $list->addUsrListEntry($entry); - $em->persist($entry); + $app['EM']->persist($entry); $inserted_usr_ids[] = $user_entry->get_id(); } - $em->flush(); + $app['EM']->flush(); if (count($inserted_usr_ids) > 1) { $datas = array( @@ -464,18 +453,17 @@ class UsrLists implements ControllerProviderInterface public function displayShares(Application $app, Request $request, $list_id) { - $em = $app['phraseanet.core']->getEntityManager(); - $user = $app['phraseanet.core']->getAuthenticatedUser(); + $user = $app['phraseanet.user']; $list = null; try { - $repository = $em->getRepository('\Entities\UsrList'); + $repository = $app['EM']->getRepository('\Entities\UsrList'); - $list = $repository->findUserListByUserAndId($user, $list_id); + $list = $repository->findUserListByUserAndId($app, $user, $list_id); /* @var $list \Entities\UsrList */ - if ($list->getOwner($user)->getRole() < UsrListOwner::ROLE_ADMIN) { + if ($list->getOwner($user, $app)->getRole() < UsrListOwner::ROLE_ADMIN) { $list = null; throw new \Exception(_('You are not authorized to do this')); } @@ -488,8 +476,7 @@ class UsrLists implements ControllerProviderInterface public function shareWithUser(Application $app, $list_id, $usr_id) { - $em = $app['phraseanet.core']->getEntityManager(); - $user = $app['phraseanet.core']->getAuthenticatedUser(); + $user = $app['phraseanet.user']; $availableRoles = array( UsrListOwner::ROLE_USER, @@ -503,23 +490,23 @@ class UsrLists implements ControllerProviderInterface throw new \Exception_BadRequest('Role is invalid'); try { - $repository = $em->getRepository('\Entities\UsrList'); + $repository = $app['EM']->getRepository('\Entities\UsrList'); - $list = $repository->findUserListByUserAndId($user, $list_id); + $list = $repository->findUserListByUserAndId($app, $user, $list_id); /* @var $list \Entities\UsrList */ - if ($list->getOwner($user)->getRole() < UsrListOwner::ROLE_EDITOR) { + if ($list->getOwner($user, $app)->getRole() < UsrListOwner::ROLE_EDITOR) { throw new ControllerException(_('You are not authorized to do this')); } - $new_owner = \User_Adapter::getInstance($usr_id, $app['phraseanet.appbox']); + $new_owner = \User_Adapter::getInstance($usr_id, $app); - if ($list->hasAccess($new_owner)) { + if ($list->hasAccess($new_owner, $app)) { if ($new_owner->get_id() == $user->get_id()) { throw new ControllerException('You can not downgrade your Admin right'); } - $owner = $list->getOwner($new_owner); + $owner = $list->getOwner($new_owner, $app); } else { $owner = new UsrListOwner(); $owner->setList($list); @@ -527,14 +514,14 @@ class UsrLists implements ControllerProviderInterface $list->addUsrListOwner($owner); - $em->persist($owner); + $app['EM']->persist($owner); } $role = $app['request']->request->get('role'); $owner->setRole($role); - $em->flush(); + $app['EM']->flush(); $datas = array( 'success' => true @@ -558,25 +545,24 @@ class UsrLists implements ControllerProviderInterface public function unshareWithUser(Application $app, $list_id, $usr_id) { - $em = $app['phraseanet.core']->getEntityManager(); - $user = $app['phraseanet.core']->getAuthenticatedUser(); + $user = $app['phraseanet.user']; try { - $repository = $em->getRepository('\Entities\UsrList'); + $repository = $app['EM']->getRepository('\Entities\UsrList'); - $list = $repository->findUserListByUserAndId($user, $list_id); + $list = $repository->findUserListByUserAndId($app, $user, $list_id); /* @var $list \Entities\UsrList */ - if ($list->getOwner($user)->getRole() < UsrListOwner::ROLE_ADMIN) { + if ($list->getOwner($user, $app)->getRole() < UsrListOwner::ROLE_ADMIN) { throw new \Exception(_('You are not authorized to do this')); } - $owners_repository = $em->getRepository('\Entities\UsrListOwner'); + $owners_repository = $app['EM']->getRepository('\Entities\UsrListOwner'); $owner = $owners_repository->findByListAndUsrId($list, $usr_id); - $em->remove($owner); - $em->flush(); + $app['EM']->remove($owner); + $app['EM']->flush(); $datas = array( 'success' => true diff --git a/lib/Alchemy/Phrasea/Controller/Prod/WorkZone.php b/lib/Alchemy/Phrasea/Controller/Prod/WorkZone.php index 8dc73edf93..8a569f0818 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/WorkZone.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/WorkZone.php @@ -50,7 +50,7 @@ class WorkZone implements ControllerProviderInterface public function displayWorkzone(Application $app) { $params = array( - 'WorkZone' => new WorkzoneHelper($app['phraseanet.core'], $app['request']) + 'WorkZone' => new WorkzoneHelper($app, $app['request']) , 'selected_type' => $app['request']->query->get('type') , 'selected_id' => $app['request']->query->get('id') , 'srt' => $app['request']->query->get('sort') @@ -66,14 +66,11 @@ class WorkZone implements ControllerProviderInterface public function browserSearch(Application $app) { - $user = $app['phraseanet.core']->getAuthenticatedUser(); + $user = $app['phraseanet.user']; $request = $app['request']; - $em = $app['phraseanet.core']->getEntityManager(); - /* @var $em \Doctrine\ORM\EntityManager */ - - $BasketRepo = $em->getRepository('\Entities\Basket'); + $BasketRepo = $app['EM']->getRepository('\Entities\Basket'); $Page = (int) $request->query->get('Page', 0); @@ -107,10 +104,9 @@ class WorkZone implements ControllerProviderInterface public function browseBasket(Application $app, Request $request, $basket_id) { - $basket = $app['phraseanet.core'] - ->getEntityManager() + $basket = $app['EM'] ->getRepository('\Entities\Basket') - ->findUserBasket($basket_id, $app['phraseanet.core']->getAuthenticatedUser(), false); + ->findUserBasket($app, $basket_id, $app['phraseanet.user'], false); return $app['twig']->render('prod/WorkZone/Browser/Basket.html.twig', array('Basket' => $basket)); } @@ -121,12 +117,9 @@ class WorkZone implements ControllerProviderInterface throw new \Exception_BadRequest(); } - $user = $app['phraseanet.core']->getAuthenticatedUser(); + $user = $app['phraseanet.user']; - $em = $app['phraseanet.core']->getEntityManager(); - /* @var $em \Doctrine\ORM\EntityManager */ - - $StoryWZRepo = $em->getRepository('\Entities\StoryWZ'); + $StoryWZRepo = $app['EM']->getRepository('\Entities\StoryWZ'); $alreadyFixed = $done = 0; @@ -134,7 +127,7 @@ class WorkZone implements ControllerProviderInterface foreach ($stories as $element) { $element = explode('_', $element); - $Story = new \record_adapter($element[0], $element[1]); + $Story = new \record_adapter($app, $element[0], $element[1]); if ( ! $Story->is_grouping()) { throw new \Exception('You can only attach stories'); @@ -144,7 +137,7 @@ class WorkZone implements ControllerProviderInterface throw new \Exception_Forbidden('You do not have access to this Story'); } - if ($StoryWZRepo->findUserStory($user, $Story)) { + if ($StoryWZRepo->findUserStory($app, $user, $Story)) { $alreadyFixed ++; continue; } @@ -153,11 +146,11 @@ class WorkZone implements ControllerProviderInterface $StoryWZ->setUser($user); $StoryWZ->setRecord($Story); - $em->persist($StoryWZ); + $app['EM']->persist($StoryWZ); $done ++; } - $em->flush(); + $app['EM']->flush(); if ($alreadyFixed === 0) { if ($done <= 1) { @@ -199,23 +192,21 @@ class WorkZone implements ControllerProviderInterface public function detachStory(Application $app, Request $request, $sbas_id, $record_id) { - $Story = new \record_adapter($sbas_id, $record_id); + $Story = new \record_adapter($app, $sbas_id, $record_id); - $user = $app['phraseanet.core']->getAuthenticatedUser(); + $user = $app['phraseanet.user']; - $em = $app['phraseanet.core']->getEntityManager(); - - $repository = $em->getRepository('\Entities\StoryWZ'); + $repository = $app['EM']->getRepository('\Entities\StoryWZ'); /* @var $repository \Repositories\StoryWZRepository */ - $StoryWZ = $repository->findUserStory($user, $Story); + $StoryWZ = $repository->findUserStory($app, $user, $Story); if ( ! $StoryWZ) { throw new \Exception_NotFound('Story not found'); } - $em->remove($StoryWZ); - $em->flush(); + $app['EM']->remove($StoryWZ); + $app['EM']->flush(); if ($request->getRequestFormat() == 'json') { return $app->json(array(