mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-12 20:43:25 +00:00
Move user search in push controller
This commit is contained in:
@@ -55,7 +55,7 @@ class Push implements ControllerProviderInterface
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
$em = $app['Core']->getEntityManager();
|
$em = $app['Core']->getEntityManager();
|
||||||
|
|
||||||
$pusher = new RecordHelper\Push($app['Core'], $app['request']);
|
$pusher = new RecordHelper\Push($app['Core'], $app['request']);
|
||||||
|
|
||||||
$user = $app['Core']->getAuthenticatedUser();
|
$user = $app['Core']->getAuthenticatedUser();
|
||||||
@@ -75,7 +75,7 @@ class Push implements ControllerProviderInterface
|
|||||||
{
|
{
|
||||||
throw new ControllerException(_('No receivers specified'));
|
throw new ControllerException(_('No receivers specified'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_array($pusher->get_elements()) || count($pusher->get_elements()) === 0)
|
if (!is_array($pusher->get_elements()) || count($pusher->get_elements()) === 0)
|
||||||
{
|
{
|
||||||
throw new ControllerException(_('No elements to push'));
|
throw new ControllerException(_('No elements to push'));
|
||||||
@@ -106,14 +106,14 @@ class Push implements ControllerProviderInterface
|
|||||||
$BasketElement->setRecord($element);
|
$BasketElement->setRecord($element);
|
||||||
$BasketElement->setBasket($Basket);
|
$BasketElement->setBasket($Basket);
|
||||||
|
|
||||||
|
|
||||||
if($receiver['HD'])
|
if ($receiver['HD'])
|
||||||
{
|
{
|
||||||
$user_receiver->ACL()->grant_hd_on(
|
$user_receiver->ACL()->grant_hd_on(
|
||||||
$BasketElement->getRecord()
|
$BasketElement->getRecord()
|
||||||
, $user
|
, $user
|
||||||
, \ACL::GRANT_ACTION_PUSH
|
, \ACL::GRANT_ACTION_PUSH
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -121,9 +121,9 @@ class Push implements ControllerProviderInterface
|
|||||||
$BasketElement->getRecord()
|
$BasketElement->getRecord()
|
||||||
, $user
|
, $user
|
||||||
, \ACL::GRANT_ACTION_PUSH
|
, \ACL::GRANT_ACTION_PUSH
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$em->persist($BasketElement);
|
$em->persist($BasketElement);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -163,19 +163,19 @@ class Push implements ControllerProviderInterface
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$pusher = new RecordHelper\Push($app['Core'], $app['request']);
|
$pusher = new RecordHelper\Push($app['Core'], $app['request']);
|
||||||
$user = $app['Core']->getAuthenticatedUser();
|
$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 = $request->get(
|
||||||
'validation_name'
|
'validation_name'
|
||||||
, sprintf(_('Validation from %s'), $user->get_display_name())
|
, sprintf(_('Validation from %s'), $user->get_display_name())
|
||||||
);
|
);
|
||||||
|
|
||||||
$validation_description = $request->get('validation_description');
|
$validation_description = $request->get('validation_description');
|
||||||
|
|
||||||
$participants = $request->get('participants');
|
$participants = $request->get('participants');
|
||||||
|
|
||||||
@@ -183,121 +183,121 @@ class Push implements ControllerProviderInterface
|
|||||||
{
|
{
|
||||||
throw new ControllerException(_('No participants specified'));
|
throw new ControllerException(_('No participants specified'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_array($pusher->get_elements()) || count($pusher->get_elements()) === 0)
|
if (!is_array($pusher->get_elements()) || count($pusher->get_elements()) === 0)
|
||||||
{
|
{
|
||||||
throw new ControllerException(_('No elements to validate'));
|
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);
|
if ($pusher->is_basket())
|
||||||
|
|
||||||
foreach ($pusher->get_elements() as $element)
|
|
||||||
{
|
{
|
||||||
$BasketElement = new \Entities\BasketElement();
|
$Basket = $pusher->get_original_basket();
|
||||||
$BasketElement->setRecord($element);
|
|
||||||
$BasketElement->setBasket($Basket);
|
|
||||||
|
|
||||||
$em->persist($BasketElement);
|
|
||||||
}
|
}
|
||||||
|
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();
|
$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(
|
$message = sprintf(
|
||||||
_('%1$d records have been sent to %2$d users')
|
_('%1$d records have been sent to %2$d users')
|
||||||
@@ -327,9 +327,18 @@ class Push implements ControllerProviderInterface
|
|||||||
$em = $app['Core']->getEntityManager();
|
$em = $app['Core']->getEntityManager();
|
||||||
$user = $app['Core']->getAuthenticatedUser();
|
$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');
|
$repository = $em->getRepository('\Entities\UsrList');
|
||||||
|
|
||||||
@@ -337,25 +346,31 @@ class Push implements ControllerProviderInterface
|
|||||||
|
|
||||||
$datas = array();
|
$datas = array();
|
||||||
|
|
||||||
foreach ($lists as $list)
|
if ($lists)
|
||||||
{
|
{
|
||||||
$datas[] = array(
|
foreach ($lists as $list)
|
||||||
'type' => 'LIST'
|
{
|
||||||
, 'name' => $list->getName()
|
$datas[] = array(
|
||||||
, 'quantity' => $list->getUsers()->count()
|
'type' => 'LIST'
|
||||||
);
|
, 'name' => $list->getName()
|
||||||
|
, 'quantity' => $list->getUsers()->count()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($result as $user)
|
if ($result)
|
||||||
{
|
{
|
||||||
$datas[] = array(
|
foreach ($result as $user)
|
||||||
'type' => 'USER'
|
{
|
||||||
, 'usr_id' => $user->get_id()
|
$datas[] = array(
|
||||||
, 'firstname' => $user->get_firstname()
|
'type' => 'USER'
|
||||||
, 'lastname' => $user->get_lastname()
|
, 'usr_id' => $user->get_id()
|
||||||
, 'email' => $user->get_email()
|
, 'firstname' => $user->get_firstname()
|
||||||
, 'display_name' => $user->get_display_name()
|
, 'lastname' => $user->get_lastname()
|
||||||
);
|
, 'email' => $user->get_email()
|
||||||
|
, 'display_name' => $user->get_display_name()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$Json = $app['Core']['Serializer']->serialize($datas, 'json');
|
$Json = $app['Core']['Serializer']->serialize($datas, 'json');
|
||||||
|
Reference in New Issue
Block a user