本文整理汇总了PHP中Sonata\AdminBundle\Datagrid\ProxyQueryInterface::execute方法的典型用法代码示例。如果您正苦于以下问题:PHP ProxyQueryInterface::execute方法的具体用法?PHP ProxyQueryInterface::execute怎么用?PHP ProxyQueryInterface::execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sonata\AdminBundle\Datagrid\ProxyQueryInterface
的用法示例。
在下文中一共展示了ProxyQueryInterface::execute方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: batchActionActivate
public function batchActionActivate(ProxyQueryInterface $selectedModelQuery)
{
$users = $selectedModelQuery->execute();
$modelManager = $this->admin->getModelManager();
$hostname = $this->container->getParameter('hostname');
$hostDirectory = $this->container->getParameter('directory');
try {
foreach ($users as $user) {
$userIsLocked = $user->isLocked();
if ($userIsLocked == true) {
$user->setEnabled(true);
$user->setLocked(false);
if (null === $user->getConfirmationToken()) {
$tokenGenerator = $this->container->get("fos_user.util.token_generator");
$user->setConfirmationToken($tokenGenerator->generateToken());
}
$user->setPasswordRequestedAt(new \DateTime('now'));
$modelManager->update($user);
$activationUrl = $hostname . $hostDirectory . "resetting/reset/" . $user->getConfirmationToken();
$message = \Swift_Message::newInstance()->setSubject('Welcome to Zeega!')->setFrom(array('noreply@zeega.org' => 'Zeega'))->setTo($user->getEmail())->setBody($this->renderView('ZeegaAdminBundle:Users:account_activated.txt.twig', array('username' => $user->getDisplayName(), 'activationURL' => $activationUrl)));
$this->get('mailer')->send($message);
}
}
} catch (\Exception $e) {
$this->get('session')->setFlash('sonata_flash_error', 'Something went wrong...');
return new RedirectResponse($this->admin->generateUrl('list', $this->admin->getFilterParameters()));
}
$this->get('session')->setFlash('sonata_flash_success', 'The users were activated successfully.');
return new RedirectResponse($this->admin->generateUrl('list', $this->admin->getFilterParameters()));
}
示例2: batchActionCancelled
/**
* @param ProxyQueryInterface $query
*
* @throws AccessDeniedException
*
* @return RedirectResponse
*/
public function batchActionCancelled(ProxyQueryInterface $query)
{
if (false === $this->admin->isGranted('EDIT')) {
throw new AccessDeniedException();
}
foreach ($query->execute() as $message) {
$this->getMessageManager()->cancel($message);
}
return new RedirectResponse($this->admin->generateUrl('list', $this->admin->getFilterParameters()));
}
示例3: preBatchAction
public function preBatchAction($actionName, ProxyQueryInterface $query, array &$idx, $allElements)
{
if ($actionName == 'delete') {
$query->andWhere($query->expr()->in('o.id', '?1'))->setParameter(1, $idx);
$serviceGroups = $query->execute();
foreach ($serviceGroups as $serviceGroup) {
$this->preRemove($serviceGroup);
}
}
}
示例4: commentChangeStatus
/**
* @param ProxyQueryInterface $query
* @param $status
*
* @return RedirectResponse
*
* @throws AccessDeniedException
*/
protected function commentChangeStatus(ProxyQueryInterface $query, $status)
{
if (false === $this->admin->isGranted('EDIT')) {
throw new AccessDeniedException();
}
foreach ($query->execute() as $comment) {
$comment->setStatus($status);
$this->admin->getModelManager()->update($comment);
}
return new RedirectResponse($this->admin->generateUrl('list', $this->admin->getFilterParameters()));
}
示例5: batchActionDelete
public function batchActionDelete(ProxyQueryInterface $query)
{
$this->admin->checkAccess('batchDelete');
try {
$this->deleteItems($query->execute());
$this->addFlash('sonata_flash_success', 'flash_batch_delete_success');
} catch (ModelManagerException $e) {
$this->handleModelManagerException($e);
$this->addFlash('sonata_flash_error', 'flash_batch_delete_error');
}
return new RedirectResponse($this->admin->generateUrl('list', array('filter' => $this->admin->getFilterParameters())));
}
示例6: batchActionSendEmail
public function batchActionSendEmail(ProxyQueryInterface $query)
{
if (!$this->admin->isGranted('ROLE_EMAIL_ADMIN')) {
throw $this->createAccessDeniedException();
}
$modelManager = $this->admin->getModelManager();
$emailSender = $this->get('bcp.email_sender');
$contactProvider = $this->get('bcp.contact_provider');
$templating = $this->get('templating');
$from = $this->getParameter('newsletter_from');
$selectedEmails = $query->execute();
$errors = array();
try {
foreach ($selectedEmails as $email) {
if (null === $email->getEmailFrom()) {
$email->setEmailFrom($from);
} else {
$from = $email->getEmailFrom();
}
$emails = in_array('all', $email->getContacts()) ? $contactProvider->getContactsEmail() : $email->getContacts();
$subject = sprintf('[BCP] %s', $email->getSubject());
$body = $templating->render('@App/Utils/email_structure.html.twig', array('body' => $email->getBody()));
if (!empty($emails)) {
foreach ($emails as $to) {
$sent = $emailSender->send($from, array($to), $subject, $body);
if (!$sent) {
$errors[] = sprintf('%s - %s', $subject, $to);
}
}
$email->setSent(new \Datetime());
$modelManager->update($email);
} else {
$errors[] = sprintf('%s - %s', $subject, $this->admin->trans('email_to_empty'));
}
}
if (!empty($errors)) {
$error = $this->admin->trans('flash_batch_send_email_error');
$error .= '<ul>';
foreach ($errors as $err) {
$error .= sprintf('<li>%s</li>', $err);
}
$error .= '</ul>';
$this->addFlash('sonata_flash_error', $error, $this->admin->flashIcon);
} else {
$this->addFlash('sonata_flash_success', $this->admin->trans('flash_batch_send_email_success'), $this->admin->flashIcon);
}
} catch (ModelManagerException $e) {
$this->handleModelManagerException($e);
$this->addFlash('sonata_flash_error', $this->admin->trans('flash_batch_send_email_error'), $this->admin->flashIcon);
}
return $this->redirect($this->admin->generateUrl('list', $this->admin->getFilterParameters()));
}
示例7: batchActionExtend
public function batchActionExtend(ProxyQueryInterface $selectedModelQuery)
{
if ($this->admin->isGranted('EDIT') === false || $this->admin->isGranted('DELETE') === false) {
throw new AccessDeniedException();
}
$modelManager = $this->admin->getModelManager();
$selectedModels = $selectedModelQuery->execute();
try {
foreach ($selectedModels as $selectedModel) {
$selectedModel->extend();
$modelManager->update($selectedModel);
}
} catch (Exception $e) {
$this->get('session')->getFlashBag()->add('sonata_flash_error', $e->getMessage());
return new RedirectResponse($this->admin->generateUrl('list', $this->admin->getFilterParameters()));
}
$this->get('session')->getFlashBag()->add('sonata_flash_success', sprintf('The selected jobs validity has been extended until %s.', date('m/d/Y', time() + 86400 * 30)));
return new RedirectResponse($this->admin->generateUrl('list', $this->admin->getFilterParameters()));
}
示例8: batchActionDeactivate
public function batchActionDeactivate(ProxyQueryInterface $selectedModelQuery)
{
if ($this->admin->isGranted('EDIT') === false || $this->admin->isGranted('DELETE') === false) {
throw new AccessDeniedException();
}
$request = $this->get('request');
$modelManager = $this->admin->getModelManager();
$selectedModels = $selectedModelQuery->execute();
try {
foreach ($selectedModels as $selectedModel) {
$selectedModel->deactivate();
$modelManager->update($selectedModel);
}
} catch (Exception $e) {
$this->get('session')->getFlashBag()->add('sonata_flash_error', $e->getMessage());
return new RedirectResponse($this->admin->generateUrl('list', $this->admin->getFilterParameters()));
}
$this->get('session')->getFlashBag()->add('sonata_flash_success', sprintf('The selected accounts have been deactivated'));
return new RedirectResponse($this->admin->generateUrl('list', $this->admin->getFilterParameters()));
}
示例9: batchActionDispatch
public function batchActionDispatch(ProxyQueryInterface $selectedModelQuery)
{
if (!$this->admin->isGranted('EDIT')) {
throw new AccessDeniedException();
}
$modelManager = $this->admin->getModelManager();
$selectedModels = $selectedModelQuery->execute();
$eventDispatcher = $this->get('event_dispatcher');
$i = 0;
try {
foreach ($selectedModels as $selectedModel) {
if ($selectedModel->getDispatchStatus() == Order::DISPATCH_STATUS_DISPATCHED) {
$this->addFlash('sonata_flash_error', sprintf('Order %d has already been dispatched.', $selectedModel->getId()));
continue;
}
if ($selectedModel->getDispatchStatus() == Order::DISPATCH_STATUS_UNDISPATCHABLE) {
$this->addFlash('sonata_flash_error', sprintf('Order %d is not dispatchable.', $selectedModel->getId()));
continue;
}
if ($selectedModel->getStatus() != GetHumanStatus::STATUS_AUTHORIZED) {
$this->addFlash('sonata_flash_error', sprintf('Order %d has not been authorized.', $selectedModel->getId()));
continue;
}
if ($selectedModel->getDispatchStatus() == Order::DISPATCH_STATUS_PROCESSING) {
$selectedModel->setDispatchStatus(Order::DISPATCH_STATUS_DISPATCHED);
$eventDispatcher->dispatch('event.dispatch', new GenericEvent(null, ['order' => $selectedModel]));
$i++;
}
}
$modelManager->update($selectedModel);
} catch (\Exception $e) {
$this->addFlash('sonata_flash_error', 'flash_batch_merge_error');
return new RedirectResponse($this->admin->generateUrl('list', $this->admin->getFilterParameters()));
}
if ($i > 0) {
$this->addFlash('sonata_flash_success', sprintf('Marked %d orders as dispatched.', $i));
}
return new RedirectResponse($this->admin->generateUrl('list', $this->admin->getFilterParameters()));
}
示例10: batchDelete
/**
* {@inheritDoc}
*
* @throws ModelManagerException if anything goes wrong during query execution.
*/
public function batchDelete($class, ProxyQueryInterface $queryProxy)
{
try {
$i = 0;
$res = $queryProxy->execute();
foreach ($res as $object) {
$this->dm->remove($object);
if (++$i % 20 == 0) {
$this->dm->flush();
$this->dm->clear();
}
}
$this->dm->flush();
$this->dm->clear();
} catch (\Exception $e) {
throw new ModelManagerException('', 0, $e);
}
}
示例11: batchActionCacheClear
/**
* @param ProxyQueryInterface $selectedModelQuery
* @return RedirectResponse
* @throws AccessDeniedException
*/
public function batchActionCacheClear(ProxyQueryInterface $selectedModelQuery)
{
if ($this->admin->isGranted('PUBLISH') === false) {
throw new AccessDeniedException();
}
$modelManager = $this->admin->getModelManager();
$selectedModels = $selectedModelQuery->execute();
// do the merge work here
try {
foreach ($selectedModels as $selectedModel) {
/** @var \Networking\InitCmsBundle\Lib\PhpCacheInterface $phpCache */
$phpCache = $this->get('networking_init_cms.lib.php_cache');
if ($phpCache->isActive()) {
/** @var PageInterface $selectedModel */
$cacheKey = $selectedModel->getLocale() . $selectedModel->getFullPath();
$phpCache->delete($cacheKey);
}
}
} catch (\Exception $e) {
$this->get('session')->getFlashBag()->add('sonata_flash_error', 'flash_batch_cache_clear_error');
return new RedirectResponse($this->admin->generateUrl('list', $this->admin->getFilterParameters()));
}
$this->get('session')->getFlashBag()->add('sonata_flash_success', 'flash_batch_cache_clear_success');
return new RedirectResponse($this->admin->generateUrl('list', $this->admin->getFilterParameters()));
}
示例12: batchActionNewsletterAndFacebook
public function batchActionNewsletterAndFacebook(ProxyQueryInterface $query)
{
if (!$this->admin->isGranted('ROLE_POST_ADMIN')) {
throw $this->createAccessDeniedException();
}
$selectedPosts = $query->execute();
try {
$this->shareNewsletter($selectedPosts);
$this->publishOnFacebook($selectedPosts);
} catch (ModelManagerException $e) {
$this->handleModelManagerException($e);
$this->addFlash('sonata_flash_error', $this->admin->trans('flash_batch_newsletter_error'), $this->admin->flashNewsletterIcon);
}
return $this->redirect($this->admin->generateUrl('list', $this->admin->getFilterParameters()));
}