/** * * @param Basket $Basket * @return set_selection */ public function load_basket(Basket $Basket) { foreach ($Basket->getElements() as $basket_element) { $this->add_element($basket_element->getRecord($this->app)); } return $this; }
/** * {@inheritdoc} */ public function getSubject() { if (!$this->basket) { throw new LogicException('You must set a basket before calling getSubject'); } return $this->app->trans('push::mail:: Reception de votre commande %title%', ['%title%' => $this->basket->getName()]); }
public function testGetRecordDetailAsGuest() { $this->authenticate(self::$DI['app'], self::$DI['user_guest']); $basket = new Basket(); $basket->setUser(self::$DI['user_guest']); $basket->setName('test'); self::$DI['app']['EM']->persist($basket); $element = new BasketElement(); $element->setRecord(self::$DI['record_1']); $element->setBasket($basket); $basket->addElement($element); self::$DI['app']['EM']->persist($element); self::$DI['app']['EM']->flush(); $this->XMLHTTPRequest('POST', '/prod/records/', ['env' => 'BASK', 'pos' => 0, 'query' => '', 'cont' => $basket->getId()]); $response = self::$DI['client']->getResponse(); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($response->getContent(), true); $this->assertArrayHasKey('desc', $data); $this->assertArrayHasKey('html_preview', $data); $this->assertArrayHasKey('current', $data); $this->assertArrayHasKey('others', $data); $this->assertArrayHasKey('history', $data); $this->assertArrayHasKey('popularity', $data); $this->assertArrayHasKey('tools', $data); $this->assertArrayHasKey('pos', $data); $this->assertArrayHasKey('title', $data); }
/** * * Returns an ArrayCollection containing three keys : * - self::BASKETS : an ArrayCollection of the actives baskets * (Non Archived) * - self::STORIES : an ArrayCollection of working stories * - self::VALIDATIONS : the validation people are waiting from me * * @return \Doctrine\Common\Collections\ArrayCollection */ public function getContent($sort) { /* @var $repo_baskets Alchemy\Phrasea\Model\Repositories\BasketRepository */ $repo_baskets = $this->app['repo.baskets']; $sort = in_array($sort, ['date', 'name']) ? $sort : 'name'; $ret = new ArrayCollection(); $baskets = $repo_baskets->findActiveByUser($this->app['authentication']->getUser(), $sort); // force creation of a default basket if (0 === count($baskets)) { $basket = new BasketEntity(); $basket->setName($this->app->trans('Default basket')); $basket->setUser($this->app['authentication']->getUser()); $this->app['EM']->persist($basket); $this->app['EM']->flush(); $baskets = [$basket]; } $validations = $repo_baskets->findActiveValidationByUser($this->app['authentication']->getUser(), $sort); /* @var $repo_stories Alchemy\Phrasea\Model\Repositories\StoryWZRepository */ $repo_stories = $this->app['repo.story-wz']; $stories = $repo_stories->findByUser($this->app, $this->app['authentication']->getUser(), $sort); $ret->set(self::BASKETS, $baskets); $ret->set(self::VALIDATIONS, $validations); $ret->set(self::STORIES, $stories); return $ret; }
/** * {@inheritdoc} */ public function getMessage() { if (!$this->pusher) { throw new LogicException('You must set a basket before calling getMessage'); } if (!$this->basket) { throw new LogicException('You must set a basket before calling getMessage'); } return $this->app->trans('You just received a push containing %quantity% documents from %user%', ['%quantity%' => count($this->basket->getElements()), '%user%' => $this->pusher->getDisplayName()]) . "\n" . $this->message; }
/** * @param Basket $basket * @param User $user * @return Token|null * @throws \Doctrine\ORM\NonUniqueResultException */ public function findValidationToken(Basket $basket, User $user) { $dql = 'SELECT t FROM Phraseanet:Token t WHERE t.type = :type AND t.user = :user AND t.data = :basket_id AND (t.expiration > CURRENT_TIMESTAMP() OR t.expiration IS NULL)'; $query = $this->_em->createQuery($dql); $query->setParameters([':type' => TokenManipulator::TYPE_VALIDATE, ':user' => $user, ':basket_id' => $basket->getId()]); return $query->getOneOrNullResult(); }
/** * Creates a new basket * * @param Application $app * @param Request $request * @return RedirectResponse */ public function createBasket(Application $app, Request $request) { $basket = null; try { $basket = new Basket(); $basket->setName($request->request->get('p0')); $basket->setUser($app['authentication']->getUser()); $app['EM']->persist($basket); $app['EM']->flush(); } catch (\Exception $e) { } return $app->redirectPath('get_client_baskets', ['courChuId' => null !== $basket ? $basket->getId() : '']); }
public function isOwner(Basket $basket, User $user) { return $basket->getUser()->getId() === $user->getId(); }
/** * @param Basket $basket * @param User $user * * @return Token */ public function createBasketAccessToken(Basket $basket, User $user) { return $this->create($user, self::TYPE_VIEW, null, $basket->getId()); }
/** * @param Basket $basket * @throws Exception */ private function assertAtLeastOneElementAgreed(Basket $basket) { foreach ($basket->getElements() as $element) { if (null !== $element->getUserValidationDatas($this->getAuthenticatedUser())->getAgreement()) { return; } } $message = $this->app->trans('You have to give your feedback at least on one document to send a report'); throw new Exception($message); }
/** * Retirve information about one basket * * @param Basket $basket * @return array */ public function list_basket(Basket $basket) { $ret = ['basket_id' => $basket->getId(), 'created_on' => $basket->getCreated()->format(DATE_ATOM), 'description' => (string) $basket->getDescription(), 'name' => $basket->getName(), 'pusher_usr_id' => $basket->getPusher() ? $basket->getPusher()->getId() : null, 'updated_on' => $basket->getUpdated()->format(DATE_ATOM), 'unread' => !$basket->getIsRead(), 'validation_basket' => !!$basket->getValidation()]; if ($basket->getValidation()) { $users = []; foreach ($basket->getValidation()->getParticipants() as $participant) { /* @var $participant ValidationParticipant */ $user = $participant->getUser(); $users[] = ['usr_id' => $user->getId(), 'usr_name' => $user->getDisplayName(), 'confirmed' => $participant->getIsConfirmed(), 'can_agree' => $participant->getCanAgree(), 'can_see_others' => $participant->getCanSeeOthers(), 'readonly' => $user->getId() != $this->app['authentication']->getUser()->getId()]; } $expires_on_atom = $basket->getValidation()->getExpires(); if ($expires_on_atom instanceof DateTime) { $expires_on_atom = $expires_on_atom->format(DATE_ATOM); } $ret = array_merge(['validation_users' => $users, 'expires_on' => $expires_on_atom, 'validation_infos' => $basket->getValidation()->getValidationString($this->app, $this->app['authentication']->getUser()), 'validation_confirmed' => $basket->getValidation()->getParticipant($this->app['authentication']->getUser())->getIsConfirmed(), 'validation_initiator' => $basket->getValidation()->isInitiator($this->app['authentication']->getUser())], $ret); } return $ret; }
private function insertTwoBasket(EntityManager $em, \Pimple $DI) { $basket1 = new Basket(); $basket1->setUser($this->getUser()); $basket1->setName('test'); $basket1->setDescription('description test'); $element = new BasketElement(); $element->setRecord($DI['record_1']); $basket1->addElement($element); $element->setBasket($basket1); $basket2 = new Basket(); $basket2->setUser($this->getUser()); $basket2->setName('test'); $basket2->setDescription('description test'); $basket3 = new Basket(); $basket3->setUser($this->getUserAlt1()); $basket3->setName('test'); $basket3->setDescription('description test'); $em->persist($basket1); $em->persist($element); $em->persist($basket2); $em->persist($basket3); $basket4 = new Basket(); $basket4->setName('test'); $basket4->setDescription('description'); $basket4->setUser($this->getUser()); foreach ([$DI['record_1'], $DI['record_2']] as $record) { $basketElement = new BasketElement(); $basketElement->setRecord($record); $basketElement->setBasket($basket4); $basket4->addElement($basketElement); $em->persist($basketElement); } $validationSession = new ValidationSession(); $validationSession->setBasket($basket4); $basket4->setValidation($validationSession); $expires = new \DateTime(); $expires->modify('+1 week'); $validationSession->setExpires($expires); $validationSession->setInitiator($this->getUser()); foreach ([$this->getUser(), $DI['user_alt1'], $DI['user_alt2']] as $user) { $validationParticipant = new ValidationParticipant(); $validationParticipant->setUser($user); $validationParticipant->setSession($validationSession); $validationParticipant->setCanAgree(true); $validationSession->addParticipant($validationParticipant); foreach ($basket4->getElements() as $basketElement) { $data = new ValidationData(); $data->setParticipant($validationParticipant); $validationParticipant->addData($data); $data->setBasketElement($basketElement); $em->persist($data); } $em->persist($validationParticipant); } $em->persist($basket4); }
public function validateAction(Request $request) { $ret = ['success' => false, 'message' => $this->app->trans('Unable to send the documents')]; $manager = $this->getEntityManager(); $manager->beginTransaction(); try { $pusher = $this->getPushFromRequest($request); $validation_name = $request->request->get('name', $this->app->trans('Validation from %user%', ['%user%' => $this->getAuthenticatedUser()->getDisplayName()])); $validation_description = $request->request->get('validation_description'); $participants = $request->request->get('participants'); if (!is_array($participants) || empty($participants)) { throw new ControllerException($this->app->trans('No participants specified')); } if (!is_array($pusher->get_elements()) || empty($pusher->get_elements())) { throw new ControllerException($this->app->trans('No elements to validate')); } if ($pusher->is_basket()) { $basket = $pusher->get_original_basket(); } else { $basket = new Basket(); $basket->setName($validation_name); $basket->setDescription($validation_description); $basket->setUser($this->getAuthenticatedUser()); $basket->setIsRead(false); $manager->persist($basket); foreach ($pusher->get_elements() as $element) { $basketElement = new BasketElement(); $basketElement->setRecord($element); $basketElement->setBasket($basket); $manager->persist($basketElement); $basket->addElement($basketElement); } $manager->flush(); } $manager->refresh($basket); if (!$basket->getValidation()) { $Validation = new ValidationSession(); $Validation->setInitiator($this->getAuthenticatedUser()); $Validation->setBasket($basket); $duration = (int) $request->request->get('duration'); if ($duration > 0) { $date = new \DateTime('+' . $duration . ' day' . ($duration > 1 ? 's' : '')); $Validation->setExpires($date); } $basket->setValidation($Validation); $manager->persist($Validation); } else { $Validation = $basket->getValidation(); } $found = false; foreach ($participants as $participant) { if ($participant['usr_id'] === $this->getAuthenticatedUser()->getId()) { $found = true; break; } } if (!$found) { $participants[] = ['see_others' => 1, 'usr_id' => $this->getAuthenticatedUser()->getId(), 'agree' => 0, 'HD' => 0]; } foreach ($participants as $key => $participant) { foreach (['see_others', 'usr_id', 'agree', 'HD'] as $mandatoryParam) { if (!array_key_exists($mandatoryParam, $participant)) { throw new ControllerException($this->app->trans('Missing mandatory parameter %parameter%', ['%parameter%' => $mandatoryParam])); } } try { /** @var User $participantUser */ $participantUser = $this->getUserRepository()->find($participant['usr_id']); } catch (\Exception $e) { throw new ControllerException($this->app->trans('Unknown user %usr_id%', ['%usr_id%' => $participant['usr_id']])); } try { $Validation->getParticipant($participantUser); continue; } catch (NotFoundHttpException $e) { } $validationParticipant = new ValidationParticipant(); $validationParticipant->setUser($participantUser); $validationParticipant->setSession($Validation); $validationParticipant->setCanAgree($participant['agree']); $validationParticipant->setCanSeeOthers($participant['see_others']); $manager->persist($validationParticipant); foreach ($basket->getElements() as $basketElement) { $validationData = new ValidationData(); $validationData->setParticipant($validationParticipant); $validationData->setBasketElement($basketElement); $basketElement->addValidationData($validationData); if ($participant['HD']) { $this->getAclForUser($participantUser)->grant_hd_on($basketElement->getRecord($this->app), $this->getAuthenticatedUser(), \ACL::GRANT_ACTION_VALIDATE); } else { $this->getAclForUser($participantUser)->grant_preview_on($basketElement->getRecord($this->app), $this->getAuthenticatedUser(), \ACL::GRANT_ACTION_VALIDATE); } $manager->merge($basketElement); $manager->persist($validationData); $this->getDataboxLogger($basketElement->getRecord($this->app)->get_databox())->log($basketElement->getRecord($this->app), \Session_Logger::EVENT_PUSH, $participantUser->getId(), ''); $validationParticipant->addData($validationData); } $validationParticipant = $manager->merge($validationParticipant); $manager->flush(); $arguments = ['basket' => $basket->getId()]; if (!$this->getConf()->get(['registry', 'actions', 'enable-push-authentication']) || !$request->get('force_authentication')) { $arguments['LOG'] = $this->getTokenManipulator()->createBasketAccessToken($basket, $participantUser); } $url = $this->app->url('lightbox_validation', $arguments); $receipt = $request->get('recept') ? $this->getAuthenticatedUser()->getEmail() : ''; $this->dispatch(PhraseaEvents::VALIDATION_CREATE, new ValidationEvent($validationParticipant, $basket, $url, $request->request->get('message'), $receipt, (int) $request->request->get('duration'))); } $manager->merge($basket); $manager->merge($Validation); $manager->flush(); $message = $this->app->trans('%quantity_records% records have been sent for validation to %quantity_users% users', ['%quantity_records%' => count($pusher->get_elements()), '%quantity_users%' => count($request->request->get('participants'))]); $ret = ['success' => true, 'message' => $message]; $manager->commit(); } catch (ControllerException $e) { $ret['message'] = $e->getMessage(); $manager->rollback(); } return $this->app->json($ret); }
/** * Retrieve information about one basket * * @param Basket $basket * * @return array */ private function list_basket(Application $app, Basket $basket) { $ret = ['basket_id' => $basket->getId(), 'owner' => $this->list_user($basket->getUser()), 'created_on' => $basket->getCreated()->format(DATE_ATOM), 'description' => (string) $basket->getDescription(), 'name' => $basket->getName(), 'pusher_usr_id' => $basket->getPusher() ? $basket->getPusher()->getId() : null, 'pusher' => $basket->getPusher() ? $this->list_user($basket->getPusher()) : null, 'updated_on' => $basket->getUpdated()->format(DATE_ATOM), 'unread' => !$basket->getIsRead(), 'validation_basket' => !!$basket->getValidation()]; if ($basket->getValidation()) { $users = array_map(function ($participant) use($app) { $user = $participant->getUser(); return ['usr_id' => $user->getId(), 'usr_name' => $user->getDisplayName(), 'confirmed' => $participant->getIsConfirmed(), 'can_agree' => $participant->getCanAgree(), 'can_see_others' => $participant->getCanSeeOthers(), 'readonly' => $user->getId() != $app['authentication']->getUser()->getId(), 'user' => $this->list_user($user)]; }, iterator_to_array($basket->getValidation()->getParticipants())); $expires_on_atom = $basket->getValidation()->getExpires(); if ($expires_on_atom instanceof \DateTime) { $expires_on_atom = $expires_on_atom->format(DATE_ATOM); } $ret = array_merge(['validation_users' => $users, 'expires_on' => $expires_on_atom, 'validation_infos' => $basket->getValidation()->getValidationString($app, $app['authentication']->getUser()), 'validation_confirmed' => $basket->getValidation()->getParticipant($app['authentication']->getUser())->getIsConfirmed(), 'validation_initiator' => $basket->getValidation()->isInitiator($app['authentication']->getUser()), 'validation_initiator_user' => $this->list_user($basket->getValidation()->getInitiator())], $ret); } return $ret; }
/** * Send an order * * @param Application $app * @param Request $request * @param integer $order_id * @return RedirectResponse|JsonResponse */ public function sendOrder(Application $app, Request $request, $order_id) { $success = false; if (null === ($order = $app['EM']->getRepository('Phraseanet:Order')->find($order_id))) { throw new NotFoundHttpException('Order not found'); } $basket = $order->getBasket(); if (null === $basket) { $basket = new Basket(); $basket->setName($app->trans('Commande du %date%', ['%date%' => $order->getCreatedOn()->format('Y-m-d')])); $basket->setUser($order->getUser()); $basket->setPusher($app['authentication']->getUser()); $app['EM']->persist($basket); $app['EM']->flush(); } $n = 0; $elements = $request->request->get('elements', []); foreach ($order->getElements() as $orderElement) { if (in_array($orderElement->getId(), $elements)) { $sbas_id = \phrasea::sbasFromBas($app, $orderElement->getBaseId()); $record = new \record_adapter($app, $sbas_id, $orderElement->getRecordId()); $basketElement = new BasketElement(); $basketElement->setRecord($record); $basketElement->setBasket($basket); $orderElement->setOrderMaster($app['authentication']->getUser()); $orderElement->setDeny(false); $orderElement->getOrder()->setBasket($basket); $basket->addElement($basketElement); $n++; $app['acl']->get($basket->getUser())->grant_hd_on($record, $app['authentication']->getUser(), 'order'); } } try { if ($n > 0) { $order->setTodo($order->getTodo() - $n); $app['events-manager']->trigger('__ORDER_DELIVER__', ['ssel_id' => $order->getBasket()->getId(), 'from' => $app['authentication']->getUser()->getId(), 'to' => $order->getUser()->getId(), 'n' => $n]); } $success = true; $app['EM']->persist($basket); $app['EM']->persist($orderElement); $app['EM']->persist($order); $app['EM']->flush(); } catch (\Exception $e) { } if ('json' === $app['request']->getRequestFormat()) { return $app->json(['success' => $success, 'msg' => $success ? $app->trans('Order has been sent') : $app->trans('An error occured while sending, please retry or contact an admin if problem persists'), 'order_id' => $order_id]); } return $app->redirectPath('prod_orders', ['success' => (int) $success, 'action' => 'send']); }
public function connect(Application $app) { $app['controller.prod.push'] = $this; $controllers = $app['controllers_factory']; $app['firewall']->addMandatoryAuthentication($controllers); $controllers->before(function (Request $request) use($app) { $app['firewall']->requireRight('push'); }); $userFormatter = $this->getUserFormatter($app); $listFormatter = $this->getListFormatter($app); $userSelection = $this->getUsersInSelectionExtractor(); $controllers->post('/sendform/', function (Application $app) use($userSelection) { $push = new RecordHelper\Push($app, $app['request']); $repository = $app['repo.usr-lists']; $RecommendedUsers = $userSelection($push->get_elements()); $params = ['push' => $push, 'message' => '', 'lists' => $repository->findUserLists($app['authentication']->getUser()), 'context' => 'Push', 'RecommendedUsers' => $RecommendedUsers]; return $app['twig']->render('prod/actions/Push.html.twig', $params); }); $controllers->post('/validateform/', function (Application $app) use($userSelection) { $push = new RecordHelper\Push($app, $app['request']); $repository = $app['repo.usr-lists']; $RecommendedUsers = $userSelection($push->get_elements()); $params = ['push' => $push, 'message' => '', 'lists' => $repository->findUserLists($app['authentication']->getUser()), 'context' => 'Feedback', 'RecommendedUsers' => $RecommendedUsers]; return $app['twig']->render('prod/actions/Push.html.twig', $params); }); $controllers->post('/send/', function (Application $app) { $request = $app['request']; $ret = ['success' => false, 'message' => $app->trans('Unable to send the documents')]; try { $pusher = new RecordHelper\Push($app, $app['request']); $push_name = $request->request->get('name', $app->trans('Push from %user%', ['%user%' => $app['authentication']->getUser()->getDisplayName()])); $push_description = $request->request->get('push_description'); $receivers = $request->request->get('participants'); if (!is_array($receivers) || count($receivers) === 0) { throw new ControllerException($app->trans('No receivers specified')); } if (!is_array($pusher->get_elements()) || count($pusher->get_elements()) === 0) { throw new ControllerException($app->trans('No elements to push')); } foreach ($receivers as $receiver) { try { $user_receiver = $app['repo.users']->find($receiver['usr_id']); } catch (\Exception $e) { throw new ControllerException($app->trans('Unknown user %user_id%', ['%user_id%' => $receiver['usr_id']])); } $Basket = new Basket(); $Basket->setName($push_name); $Basket->setDescription($push_description); $Basket->setUser($user_receiver); $Basket->setPusher($app['authentication']->getUser()); $Basket->setIsRead(false); $app['EM']->persist($Basket); foreach ($pusher->get_elements() as $element) { $BasketElement = new BasketElement(); $BasketElement->setRecord($element); $BasketElement->setBasket($Basket); $app['EM']->persist($BasketElement); $Basket->addElement($BasketElement); if ($receiver['HD']) { $app['acl']->get($user_receiver)->grant_hd_on($BasketElement->getRecord($app), $app['authentication']->getUser(), \ACL::GRANT_ACTION_PUSH); } else { $app['acl']->get($user_receiver)->grant_preview_on($BasketElement->getRecord($app), $app['authentication']->getUser(), \ACL::GRANT_ACTION_PUSH); } } $app['EM']->flush(); $arguments = ['basket' => $Basket->getId()]; if (!$app['conf']->get(['registry', 'actions', 'enable-push-authentication']) || !$request->get('force_authentication')) { $arguments['LOG'] = $app['manipulator.token']->createBasketAccessToken($Basket, $user_receiver); } $url = $app->url('lightbox_compare', $arguments); $receipt = $request->get('recept') ? $app['authentication']->getUser()->getEmail() : ''; $app['dispatcher']->dispatch(PhraseaEvents::BASKET_PUSH, new PushEvent($Basket, $request->request->get('message'), $url, $receipt)); } $app['phraseanet.logger']($BasketElement->getRecord($app)->get_databox())->log($BasketElement->getRecord($app), \Session_Logger::EVENT_VALIDATE, $user_receiver->getId(), ''); $app['EM']->flush(); $message = $app->trans('%quantity_records% records have been sent to %quantity_users% users', ['%quantity_records%' => count($pusher->get_elements()), '%quantity_users%' => count($receivers)]); $ret = ['success' => true, 'message' => $message]; } catch (ControllerException $e) { $ret['message'] = $e->getMessage() . $e->getFile() . $e->getLine(); } return $app->json($ret); })->bind('prod_push_send'); $controllers->post('/validate/', function (Application $app) { $request = $app['request']; $ret = ['success' => false, 'message' => $app->trans('Unable to send the documents')]; $app['EM']->beginTransaction(); try { $pusher = new RecordHelper\Push($app, $app['request']); $validation_name = $request->request->get('name', $app->trans('Validation from %user%', ['%user%' => $app['authentication']->getUser()->getDisplayName()])); $validation_description = $request->request->get('validation_description'); $participants = $request->request->get('participants'); if (!is_array($participants) || count($participants) === 0) { throw new ControllerException($app->trans('No participants specified')); } if (!is_array($pusher->get_elements()) || count($pusher->get_elements()) === 0) { throw new ControllerException($app->trans('No elements to validate')); } if ($pusher->is_basket()) { $Basket = $pusher->get_original_basket(); } else { $Basket = new Basket(); $Basket->setName($validation_name); $Basket->setDescription($validation_description); $Basket->setUser($app['authentication']->getUser()); $Basket->setIsRead(false); $app['EM']->persist($Basket); foreach ($pusher->get_elements() as $element) { $BasketElement = new BasketElement(); $BasketElement->setRecord($element); $BasketElement->setBasket($Basket); $app['EM']->persist($BasketElement); $Basket->addElement($BasketElement); } $app['EM']->flush(); } $app['EM']->refresh($Basket); if (!$Basket->getValidation()) { $Validation = new ValidationSession(); $Validation->setInitiator($app['authentication']->getUser()); $Validation->setBasket($Basket); $duration = (int) $request->request->get('duration'); if ($duration > 0) { $date = new \DateTime('+' . $duration . ' day' . ($duration > 1 ? 's' : '')); $Validation->setExpires($date); } $Basket->setValidation($Validation); $app['EM']->persist($Validation); } else { $Validation = $Basket->getValidation(); } $found = false; foreach ($participants as $participant) { if ($participant['usr_id'] === $app['authentication']->getUser()->getId()) { $found = true; break; } } if (!$found) { $participants[] = ['see_others' => 1, 'usr_id' => $app['authentication']->getUser()->getId(), 'agree' => 0, 'HD' => 0]; } foreach ($participants as $key => $participant) { foreach (['see_others', 'usr_id', 'agree', 'HD'] as $mandatoryParam) { if (!array_key_exists($mandatoryParam, $participant)) { throw new ControllerException($app->trans('Missing mandatory parameter %parameter%', ['%parameter%' => $mandatoryParam])); } } try { $participantUser = $app['repo.users']->find($participant['usr_id']); } catch (\Exception $e) { throw new ControllerException($app->trans('Unknown user %usr_id%', ['%usr_id%' => $participant['usr_id']])); } try { $Validation->getParticipant($participantUser); continue; } catch (NotFoundHttpException $e) { } $validationParticipant = new ValidationParticipant(); $validationParticipant->setUser($participantUser); $validationParticipant->setSession($Validation); $validationParticipant->setCanAgree($participant['agree']); $validationParticipant->setCanSeeOthers($participant['see_others']); $app['EM']->persist($validationParticipant); foreach ($Basket->getElements() as $BasketElement) { $ValidationData = new ValidationData(); $ValidationData->setParticipant($validationParticipant); $ValidationData->setBasketElement($BasketElement); $BasketElement->addValidationData($ValidationData); if ($participant['HD']) { $app['acl']->get($participantUser)->grant_hd_on($BasketElement->getRecord($app), $app['authentication']->getUser(), \ACL::GRANT_ACTION_VALIDATE); } else { $app['acl']->get($participantUser)->grant_preview_on($BasketElement->getRecord($app), $app['authentication']->getUser(), \ACL::GRANT_ACTION_VALIDATE); } $app['EM']->merge($BasketElement); $app['EM']->persist($ValidationData); $app['phraseanet.logger']($BasketElement->getRecord($app)->get_databox())->log($BasketElement->getRecord($app), \Session_Logger::EVENT_PUSH, $participantUser->getId(), ''); $validationParticipant->addData($ValidationData); } $validationParticipant = $app['EM']->merge($validationParticipant); $app['EM']->flush(); $arguments = ['basket' => $Basket->getId()]; if (!$app['conf']->get(['registry', 'actions', 'enable-push-authentication']) || !$request->get('force_authentication')) { $arguments['LOG'] = $app['manipulator.token']->createBasketAccessToken($Basket, $participantUser); } $url = $app->url('lightbox_validation', $arguments); $receipt = $request->get('recept') ? $app['authentication']->getUser()->getEmail() : ''; $app['dispatcher']->dispatch(PhraseaEvents::VALIDATION_CREATE, new ValidationEvent($validationParticipant, $Basket, $url, $request->request->get('message'), $receipt, (int) $request->request->get('duration'))); } $app['EM']->merge($Basket); $app['EM']->merge($Validation); $app['EM']->flush(); $message = $app->trans('%quantity_records% records have been sent for validation to %quantity_users% users', ['%quantity_records%' => count($pusher->get_elements()), '%quantity_users%' => count($request->request->get('participants'))]); $ret = ['success' => true, 'message' => $message]; $app['EM']->commit(); } catch (ControllerException $e) { $ret['message'] = $e->getMessage(); $app['EM']->rollback(); } return $app->json($ret); })->bind('prod_push_validate'); $controllers->get('/user/{usr_id}/', function (Application $app, $usr_id) use($userFormatter) { $datas = null; $request = $app['request']; $query = new $app['phraseanet.user-query'](); $query->on_bases_where_i_am($app['acl']->get($app['authentication']->getUser()), ['canpush']); $query->in([$usr_id]); $result = $query->include_phantoms()->limit(0, 1)->execute()->get_results(); if ($result) { foreach ($result as $user) { $datas = $userFormatter($user); } } return $app->json($datas); })->assert('usr_id', '\\d+'); $controllers->get('/list/{list_id}/', function (Application $app, $list_id) use($listFormatter) { $datas = null; $repository = $app['repo.usr-lists']; $list = $repository->findUserListByUserAndId($app['authentication']->getUser(), $list_id); if ($list) { $datas = $listFormatter($list); } return $app->json($datas); })->bind('prod_push_lists_list')->assert('list_id', '\\d+'); $controllers->post('/add-user/', function (Application $app, Request $request) use($userFormatter) { $result = ['success' => false, 'message' => '', 'user' => null]; try { if (!$app['acl']->get($app['authentication']->getUser())->has_right('manageusers')) { throw new ControllerException($app->trans('You are not allowed to add users')); } if (!$request->request->get('firstname')) { throw new ControllerException($app->trans('First name is required')); } if (!$request->request->get('lastname')) { throw new ControllerException($app->trans('Last name is required')); } if (!$request->request->get('email')) { throw new ControllerException($app->trans('Email is required')); } if (!\Swift_Validate::email($request->request->get('email'))) { throw new ControllerException($app->trans('Email is invalid')); } } catch (ControllerException $e) { $result['message'] = $e->getMessage(); return $app->json($result); } $user = null; $email = $request->request->get('email'); try { $user = $app['repo.users']->findByEmail($email); $result['message'] = $app->trans('User already exists'); $result['success'] = true; $result['user'] = $userFormatter($user); } catch (\Exception $e) { } if (!$user instanceof User) { try { $password = $app['random.medium']->generateString(128); $user = $app['manipulator.user']->createUser($email, $password, $email); $user->setFirstName($request->request->get('firstname'))->setLastName($request->request->get('lastname')); if ($request->request->get('company')) { $user->setCompany($request->request->get('company')); } if ($request->request->get('job')) { $user->setCompany($request->request->get('job')); } if ($request->request->get('form_geonameid')) { $app['manipulator.user']->setGeonameId($user, $request->request->get('form_geonameid')); } $result['message'] = $app->trans('User successfully created'); $result['success'] = true; $result['user'] = $userFormatter($user); } catch (\Exception $e) { $result['message'] = $app->trans('Error while creating user'); } } return $app->json($result); })->bind('prod_push_do_add_user'); $controllers->get('/add-user/', function (Application $app, Request $request) { $params = ['callback' => $request->query->get('callback')]; return $app['twig']->render('prod/User/Add.html.twig', $params); })->bind('prod_push_add_user'); $controllers->get('/search-user/', function (Application $app) use($userFormatter, $listFormatter) { $request = $app['request']; $query = $app['phraseanet.user-query']; $query->on_bases_where_i_am($app['acl']->get($app['authentication']->getUser()), ['canpush']); $query->like(\User_Query::LIKE_FIRSTNAME, $request->query->get('query'))->like(\User_Query::LIKE_LASTNAME, $request->query->get('query'))->like(\User_Query::LIKE_LOGIN, $request->query->get('query'))->like_match(\User_Query::LIKE_MATCH_OR); $result = $query->include_phantoms()->limit(0, 50)->execute()->get_results(); $repository = $app['repo.usr-lists']; $lists = $repository->findUserListLike($app['authentication']->getUser(), $request->query->get('query')); $datas = []; if ($lists) { foreach ($lists as $list) { $datas[] = $listFormatter($list); } } if ($result) { foreach ($result as $user) { $datas[] = $userFormatter($user); } } return $app->json($datas); }); $controllers->match('/edit-list/{list_id}/', function (Application $app, Request $request, $list_id) { $repository = $app['repo.usr-lists']; $list = $repository->findUserListByUserAndId($app['authentication']->getUser(), $list_id); $query = $app['phraseanet.user-query']; $query->on_bases_where_i_am($app['acl']->get($app['authentication']->getUser()), ['canpush']); if ($request->get('query')) { $query->like($request->get('like_field'), $request->get('query'))->like_match(\User_Query::LIKE_MATCH_OR); } if (is_array($request->get('Activity'))) { $query->haveActivities($request->get('Activity')); } if (is_array($request->get('Template'))) { $query->haveTemplate($request->get('Template')); } if (is_array($request->get('Company'))) { $query->inCompanies($request->get('Company')); } if (is_array($request->get('Country'))) { $query->inCountries($request->get('Country')); } if (is_array($request->get('Position'))) { $query->havePositions($request->get('Position')); } $sort = $request->get('srt', 'usr_creationdate'); $ord = $request->get('ord', 'desc'); $perPage = 10; $offset_start = Max(((int) $request->get('page') - 1) * $perPage, 0); $query->sort_by($sort, $ord); $results = $query->include_phantoms()->limit($offset_start, $perPage)->execute()->get_results(); $params = ['query' => $query, 'results' => $results, 'list' => $list, 'sort' => $sort, 'ord' => $ord]; if ($request->get('type') === 'fragment') { return new Response($app['twig']->render('prod/actions/Feedback/ResultTable.html.twig', $params)); } else { return new Response($app['twig']->render('prod/actions/Feedback/list.html.twig', $params)); } })->bind('prod_push_list_edit')->assert('list_id', '\\d+'); return $controllers; }
/** * Send an order * * @param Request $request * @param integer $order_id * @return RedirectResponse|JsonResponse */ public function sendOrder(Request $request, $order_id) { $success = false; /** @var Order $order */ if (null === ($order = $this->getOrderRepository()->find($order_id))) { throw new NotFoundHttpException('Order not found'); } $manager = $this->getEntityManager(); $basket = $order->getBasket(); if (null === $basket) { $basket = new Basket(); $basket->setName($this->app->trans('Commande du %date%', ['%date%' => $order->getCreatedOn()->format('Y-m-d')])); $basket->setUser($order->getUser()); $basket->setPusher($this->getAuthenticatedUser()); $manager->persist($basket); $manager->flush(); } $n = 0; $elements = $request->request->get('elements', []); foreach ($order->getElements() as $orderElement) { if (in_array($orderElement->getId(), $elements)) { $sbas_id = \phrasea::sbasFromBas($this->app, $orderElement->getBaseId()); $record = new \record_adapter($this->app, $sbas_id, $orderElement->getRecordId()); $basketElement = new BasketElement(); $basketElement->setRecord($record); $basketElement->setBasket($basket); $orderElement->setOrderMaster($this->getAuthenticatedUser()); $orderElement->setDeny(false); $orderElement->getOrder()->setBasket($basket); $basket->addElement($basketElement); $n++; $this->getAclForUser($basket->getUser())->grant_hd_on($record, $this->getAuthenticatedUser(), 'order'); } } try { if ($n > 0) { $order->setTodo($order->getTodo() - $n); $this->dispatch(PhraseaEvents::ORDER_DELIVER, new OrderDeliveryEvent($order, $this->getAuthenticatedUser(), $n)); } $success = true; // There was a basketElement persist here. Seems useless as all entities are managed. $manager->persist($basket); $manager->persist($order); $manager->flush(); } catch (\Exception $e) { } if ('json' === $request->getRequestFormat()) { return $this->app->json(['success' => $success, 'msg' => $success ? $this->app->trans('Order has been sent') : $this->app->trans('An error occured while sending, please retry or contact an admin if problem persists'), 'order_id' => $order_id]); } return $this->app->redirectPath('prod_orders', ['success' => (int) $success, 'action' => 'send']); }
/** * Change the description of one basket * * @param Request $request * @param Basket $basket * * @return Response */ public function setBasketDescriptionAction(Request $request, Basket $basket) { $basket->setDescription($request->get('description')); /** @var EntityManager $em */ $em = $this->app['orm.em']; $em->persist($basket); $em->flush(); return Result::create($request, ["basket" => $this->listBasket($basket)])->createResponse(); }
public function addElements(Request $request, Basket $basket) { $n = 0; $records = RecordsRequest::fromRequest($this->app, $request, true); $em = $this->getEntityManager(); foreach ($records as $record) { if ($basket->hasRecord($this->app, $record)) { continue; } $basket_element = new BasketElement(); $basket_element->setRecord($record); $basket_element->setBasket($basket); $em->persist($basket_element); $basket->addElement($basket_element); if (null !== ($validationSession = $basket->getValidation())) { $participants = $validationSession->getParticipants(); foreach ($participants as $participant) { $validationData = new ValidationData(); $validationData->setParticipant($participant); $validationData->setBasketElement($basket_element); $em->persist($validationData); } } $n++; } $em->flush(); $data = ['success' => true, 'message' => $this->app->trans('%quantity% records added', ['%quantity%' => $n])]; if ($request->getRequestFormat() === 'json') { return $this->app->json($data); } return $this->app->redirectPath('prod_workzone_show'); }
/** * {@inheritDoc} */ public function getSize(\Alchemy\Phrasea\Application $app) { $this->__initializer__ && $this->__initializer__->__invoke($this, 'getSize', array($app)); return parent::getSize($app); }