diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Push.php b/lib/Alchemy/Phrasea/Controller/Prod/Push.php index aaa737e202..a83349b3ba 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Push.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Push.php @@ -55,7 +55,7 @@ class Push implements ControllerProviderInterface try { $em = $app['Core']->getEntityManager(); - + $pusher = new RecordHelper\Push($app['Core'], $app['request']); $user = $app['Core']->getAuthenticatedUser(); @@ -75,7 +75,7 @@ class Push implements ControllerProviderInterface { throw new ControllerException(_('No receivers specified')); } - + if (!is_array($pusher->get_elements()) || count($pusher->get_elements()) === 0) { throw new ControllerException(_('No elements to push')); @@ -106,14 +106,14 @@ class Push implements ControllerProviderInterface $BasketElement->setRecord($element); $BasketElement->setBasket($Basket); - - if($receiver['HD']) + + if ($receiver['HD']) { $user_receiver->ACL()->grant_hd_on( $BasketElement->getRecord() , $user , \ACL::GRANT_ACTION_PUSH - ); + ); } else { @@ -121,9 +121,9 @@ class Push implements ControllerProviderInterface $BasketElement->getRecord() , $user , \ACL::GRANT_ACTION_PUSH - ); + ); } - + $em->persist($BasketElement); } } @@ -163,19 +163,19 @@ class Push implements ControllerProviderInterface try { - $pusher = new RecordHelper\Push($app['Core'], $app['request']); - $user = $app['Core']->getAuthenticatedUser(); + $pusher = new RecordHelper\Push($app['Core'], $app['request']); + $user = $app['Core']->getAuthenticatedUser(); - $em = $app['Core']->getEntityManager(); + $em = $app['Core']->getEntityManager(); - $repository = $em->getRepository('\Entities\Basket'); + $repository = $em->getRepository('\Entities\Basket'); - $validation_name = $request->get( - 'validation_name' - , sprintf(_('Validation from %s'), $user->get_display_name()) - ); - - $validation_description = $request->get('validation_description'); + $validation_name = $request->get( + 'validation_name' + , sprintf(_('Validation from %s'), $user->get_display_name()) + ); + + $validation_description = $request->get('validation_description'); $participants = $request->get('participants'); @@ -183,121 +183,121 @@ class Push implements ControllerProviderInterface { throw new ControllerException(_('No participants specified')); } - + if (!is_array($pusher->get_elements()) || count($pusher->get_elements()) === 0) { throw new ControllerException(_('No elements to validate')); } - - if ($pusher->is_basket()) - { - $Basket = $pusher->get_original_basket(); - } - else - { - $Basket = new \Entities\Basket(); - $Basket->setName($validation_name); - $Basket->setDescription($validation_description); - $Basket->setOwner($user); - $em->persist($Basket); - - foreach ($pusher->get_elements() as $element) + if ($pusher->is_basket()) { - $BasketElement = new \Entities\BasketElement(); - $BasketElement->setRecord($element); - $BasketElement->setBasket($Basket); - - $em->persist($BasketElement); + $Basket = $pusher->get_original_basket(); } + else + { + $Basket = new \Entities\Basket(); + $Basket->setName($validation_name); + $Basket->setDescription($validation_description); + $Basket->setOwner($user); + + $em->persist($Basket); + + foreach ($pusher->get_elements() as $element) + { + $BasketElement = new \Entities\BasketElement(); + $BasketElement->setRecord($element); + $BasketElement->setBasket($Basket); + + $em->persist($BasketElement); + } + + $em->flush(); + } + + if (!$Basket->getValidation()) + { + $Validation = new \Entities\ValidationSession(); + $Validation->setInitiator($app['Core']->getAuthenticatedUser()); + $Validation->setBasket($Basket); + + $Basket->setValidation($Validation); + $em->persist($Validation); + } + else + { + $Validation = $Basket->getValidation(); + } + + + $appbox = \appbox::get_instance(); + + foreach ($participants as $participant) + { + try + { + $participant_user = \User_Adapter::getInstance($participant['usr_id'], $appbox); + } + catch (\Exception $e) + { + throw new ControllerException(sprintf(_('Unknown user %d'), $receiver['usr_id'])); + } + + try + { + $Participant = $Validation->getParticipant($participant_user); + continue; + } + catch (\Exception_NotFound $e) + { + + } + + $Participant = new \Entities\ValidationParticipant(); + $Participant->setUser($participant_user); + $Participant->setSession($Validation); + + $Participant->setCanAgree($participant['agree']); + $Participant->setCanSeeOthers($participant['see_others']); + + $em->persist($Participant); + + foreach ($Basket->getElements() as $BasketElement) + { + $ValidationData = new \Entities\ValidationData(); + $ValidationData->setParticipant($Participant); + $validationData->setBasketElement($BasketElement); + $BasketElement->addValidationData($ValidationData); + + if ($participant['HD']) + { + $participant_user->ACL()->grant_hd_on( + $BasketElement->getRecord() + , $user + , \ACL::GRANT_ACTION_VALIDATE + ); + } + else + { + $participant_user->ACL()->grant_preview_on( + $BasketElement->getRecord() + , $user + , \ACL::GRANT_ACTION_VALIDATE + ); + } + + $em->merge($BasketElement); + $em->persists($ValidationData); + + $Participant->addValidationData($ValidationData); + } + + $em->merge($Participant); + } + + $em->merge($Basket); + $em->merge($Validation); $em->flush(); - } - - if (!$Basket->getValidation()) - { - $Validation = new \Entities\ValidationSession(); - $Validation->setInitiator($app['Core']->getAuthenticatedUser()); - $Validation->setBasket($Basket); - - $Basket->setValidation($Validation); - $em->persist($Validation); - } - else - { - $Validation = $Basket->getValidation(); - } - - - $appbox = \appbox::get_instance(); - - foreach ($participants as $participant) - { - try - { - $participant_user = \User_Adapter::getInstance($participant['usr_id'], $appbox); - } - catch(\Exception $e) - { - throw new ControllerException(sprintf(_('Unknown user %d'), $receiver['usr_id'])); - } - - try - { - $Participant = $Validation->getParticipant($participant_user); - continue; - } - catch (\Exception_NotFound $e) - { - - } - - $Participant = new \Entities\ValidationParticipant(); - $Participant->setUser($participant_user); - $Participant->setSession($Validation); - - $Participant->setCanAgree($participant['agree']); - $Participant->setCanSeeOthers($participant['see_others']); - - $em->persist($Participant); - - foreach ($Basket->getElements() as $BasketElement) - { - $ValidationData = new \Entities\ValidationData(); - $ValidationData->setParticipant($Participant); - $validationData->setBasketElement($BasketElement); - $BasketElement->addValidationData($ValidationData); - - if($participant['HD']) - { - $participant_user->ACL()->grant_hd_on( - $BasketElement->getRecord() - , $user - , \ACL::GRANT_ACTION_VALIDATE - ); - } - else - { - $participant_user->ACL()->grant_preview_on( - $BasketElement->getRecord() - , $user - , \ACL::GRANT_ACTION_VALIDATE - ); - } - - $em->merge($BasketElement); - $em->persists($ValidationData); - - $Participant->addValidationData($ValidationData); - } - - $em->merge($Participant); - } - - $em->merge($Basket); - $em->merge($Validation); - - $em->flush(); $message = sprintf( _('%1$d records have been sent to %2$d users') @@ -327,9 +327,18 @@ class Push implements ControllerProviderInterface $em = $app['Core']->getEntityManager(); $user = $app['Core']->getAuthenticatedUser(); - $pusher = new RecordHelper\Push($app['Core'], $app['request']); + $query = new \User_Query(\appbox::get_instance()); - $result = $pusher->search($request->get('query')); + $query->on_bases_where_i_am($user->ACL(), array('canpush')); + + $query->like(\User_Query::LIKE_FIRSTNAME, $request->get('query')) + ->like(\User_Query::LIKE_LASTNAME, $request->get('query')) + ->like(\User_Query::LIKE_LOGIN, $request->get('query')) + ->like_match(\User_Query::LIKE_MATCH_OR); + + $result = $query->include_phantoms() + ->limit(0, 50) + ->execute()->get_results(); $repository = $em->getRepository('\Entities\UsrList'); @@ -337,25 +346,31 @@ class Push implements ControllerProviderInterface $datas = array(); - foreach ($lists as $list) + if ($lists) { - $datas[] = array( - 'type' => 'LIST' - , 'name' => $list->getName() - , 'quantity' => $list->getUsers()->count() - ); + foreach ($lists as $list) + { + $datas[] = array( + 'type' => 'LIST' + , 'name' => $list->getName() + , 'quantity' => $list->getUsers()->count() + ); + } } - foreach ($result as $user) + if ($result) { - $datas[] = array( - 'type' => 'USER' - , 'usr_id' => $user->get_id() - , 'firstname' => $user->get_firstname() - , 'lastname' => $user->get_lastname() - , 'email' => $user->get_email() - , 'display_name' => $user->get_display_name() - ); + foreach ($result as $user) + { + $datas[] = array( + 'type' => 'USER' + , 'usr_id' => $user->get_id() + , 'firstname' => $user->get_firstname() + , 'lastname' => $user->get_lastname() + , 'email' => $user->get_email() + , 'display_name' => $user->get_display_name() + ); + } } $Json = $app['Core']['Serializer']->serialize($datas, 'json');