Exemplo n.º 1
0
 /**
  * Binds integration ID to query
  *
  * @param BuildAfter $event
  */
 public function statusGridBuildAfter(BuildAfter $event)
 {
     /** @var OrmDatasource $source */
     $source = $event->getDatagrid()->getDatasource();
     $params = $event->getDatagrid()->getParameters();
     if ($params->has('integrationId')) {
         $id = $params->get('integrationId');
         $source->getQueryBuilder()->setParameter('integrationId', $id);
     }
 }
Exemplo n.º 2
0
 /**
  * Add required filters
  *
  * @param BuildAfter $event
  */
 public function onBuildAfter(BuildAfter $event)
 {
     /** @var OrmDatasource $ormDataSource */
     $ormDataSource = $event->getDatagrid()->getDatasource();
     $queryBuilder = $ormDataSource->getQueryBuilder();
     $parameters = $event->getDatagrid()->getParameters();
     $this->factory->filterQueryByUserId($queryBuilder, $parameters->get('userId'));
     if ($parameters->has('emailIds')) {
         $emailIds = $parameters->get('emailIds');
         if (!is_array($emailIds)) {
             $emailIds = explode(',', $emailIds);
         }
         $queryBuilder->andWhere($queryBuilder->expr()->in('e.id', $emailIds));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function onBuildAfter(BuildAfter $event)
 {
     $datagrid = $event->getDatagrid();
     $dataSource = $event->getDatagrid()->getDatasource();
     if ($dataSource instanceof OrmDatasource) {
         $parameters = $datagrid->getParameters();
         $queryBuilder = $dataSource->getQueryBuilder();
         $params = array();
         foreach ($this->parameters as $fieldName) {
             $param = $parameters->get($fieldName, null);
             $params[$fieldName] = $param;
         }
         $queryBuilder->setParameters($params);
     }
 }
 /**
  * Set country translation query walker
  *
  * @param BuildAfter $event
  */
 public function onBuildAfter(BuildAfter $event)
 {
     $source = $event->getDatagrid()->getDatasource();
     if ($source instanceof OrmDatasource) {
         $source->getQueryBuilder()->getQuery()->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker');
     }
 }
Exemplo n.º 5
0
 /**
  * @param BuildAfter $event
  */
 public function onBuildAfter(BuildAfter $event)
 {
     /** @var OrmDatasource $dataSource */
     $datagrid = $event->getDatagrid();
     $config = $datagrid->getConfig();
     $configParameters = $config->toArray();
     if (!array_key_exists('extended_entity_name', $configParameters) || !$configParameters['extended_entity_name']) {
         return;
     }
     $targetClass = $configParameters['extended_entity_name'];
     $parameters = $datagrid->getParameters();
     $dataSource = $datagrid->getDatasource();
     $queryBuilder = $dataSource->getQueryBuilder();
     $alias = current($queryBuilder->getDQLPart('from'))->getAlias();
     if ($dataSource instanceof OrmDatasource && $parameters->has('activityId') && $parameters->has('activityClass')) {
         $id = $parameters->get('activityId');
         $class = $parameters->get('activityClass');
         $entityClass = $this->entityClassNameHelper->resolveEntityClass($class, true);
         $entity = $this->doctrineHelper->getEntity($entityClass, $id);
         if ($entity && $entity instanceof ActivityInterface) {
             $targetsArray = $entity->getActivityTargets($targetClass);
             $targetIds = [];
             foreach ($targetsArray as $target) {
                 $targetIds[] = $target->getId();
             }
             if ($targetIds) {
                 $queryBuilder->andWhere($queryBuilder->expr()->notIn(sprintf('%s.id', $alias), $targetIds));
             }
         }
     }
 }
Exemplo n.º 6
0
 /**
  * @param BuildAfter $event
  */
 public function onBuildAfter(BuildAfter $event)
 {
     $datagrid = $event->getDatagrid();
     $datasource = $datagrid->getDatasource();
     if (!$datasource instanceof ParameterBinderAwareInterface) {
         return;
     }
     $config = $datagrid->getConfig();
     $selectCellConfig = $config->offsetGetByPath(self::CELL_SELECTION_OPTION_PATH, []);
     if (!is_array($selectCellConfig) || empty($selectCellConfig)) {
         return;
     }
     $missingOptions = array_diff($this->requiredOptions, array_keys($selectCellConfig));
     if ($missingOptions) {
         throw new LogicException(sprintf('cellSelection options `%s` are required ', implode('`, `', $missingOptions)));
     }
     // Add frontend module to handle selection
     $requireJsModules = $config->offsetGetByPath(self::REQUIREJS_MODULES_MODULES_OPTION_PATH, []);
     if (!$requireJsModules || !is_array($requireJsModules)) {
         $requireJsModules = [];
     }
     if (!in_array(self::CELL_SELECTION_JS_MODULE, $requireJsModules)) {
         $requireJsModules[] = self::CELL_SELECTION_JS_MODULE;
     }
     $config->offsetSetByPath(self::REQUIREJS_MODULES_MODULES_OPTION_PATH, $requireJsModules);
 }
Exemplo n.º 7
0
 /**
  * @param BuildAfter $event
  */
 public function onBuildAfter(BuildAfter $event)
 {
     /** @var OrmDatasource $dataSource */
     $datagrid = $event->getDatagrid();
     $config = $datagrid->getConfig();
     $configParameters = $config->toArray();
     if (!array_key_exists('extended_entity_name', $configParameters) || !$configParameters['extended_entity_name']) {
         return;
     }
     $targetClass = $configParameters['extended_entity_name'];
     $parameters = $datagrid->getParameters();
     $dataSource = $datagrid->getDatasource();
     $queryBuilder = $dataSource->getQueryBuilder();
     $alias = current($queryBuilder->getDQLPart('from'))->getAlias();
     if ($dataSource instanceof OrmDatasource && $parameters->has('activityId')) {
         $activityId = $parameters->get('activityId');
         $email = $this->entityManager->getRepository('OroEmailBundle:Email')->find($activityId);
         if ($email) {
             $targetsArray = $email->getActivityTargets($targetClass);
             $targetIds = [];
             foreach ($targetsArray as $target) {
                 $targetIds[] = $target->getId();
             }
             if ($targetIds) {
                 $queryBuilder->andWhere($queryBuilder->expr()->notIn("{$alias}.id", $targetIds));
             }
         }
     }
 }
Exemplo n.º 8
0
 /**
  * Add required filters
  *
  * @param BuildAfter $event
  */
 public function onBuildAfter(BuildAfter $event)
 {
     $datagrid = $event->getDatagrid();
     /** @var OrmDatasource $ormDataSource */
     $ormDataSource = $datagrid->getDatasource();
     $queryBuilder = $ormDataSource->getQueryBuilder();
     $parameters = $datagrid->getParameters();
     if ($parameters->has('userId')) {
         $user = $this->entityManager->find('OroUserBundle:User', $parameters->get('userId'));
         $queryBuilder->andWhere('call.owner = :user')->setParameter('user', $user);
     }
     if ($parameters->has('contactId')) {
         $contact = $this->entityManager->find('OroCRMContactBundle:Contact', $parameters->get('contactId'));
         $queryBuilder->andWhere('call.relatedContact = :contact')->setParameter('contact', $contact);
     }
     if ($parameters->has('accountId')) {
         $account = $this->entityManager->find('OroCRMAccountBundle:Account', $parameters->get('accountId'));
         $queryBuilder->andWhere('(call.relatedAccount = :account OR :account MEMBER OF contact.accounts)')->setParameter('account', $account);
     }
     if ($parameters->has('callIds')) {
         $callIds = $parameters->get('callIds');
         if (!is_array($callIds)) {
             $callIds = explode(',', $callIds);
         }
         $queryBuilder->andWhere($queryBuilder->expr()->in('call.id', $callIds));
     }
 }
 /**
  * Add filters to where clause
  * Base query should looks as following:
  * (CASE WHEN (:relationParamName IS NOT NULL) THEN
  *       CASE WHEN (:relationParamName
  *              MEMBER OF alias.relationField OR alias.id IN (:data_in)) AND alias.id NOT IN (:data_not_in)
  *       THEN true ELSE false END
  *  ELSE
  *       CASE WHEN alias.id IN (:data_in) AND alias.id NOT IN (:data_not_in)
  *       THEN true ELSE false END
  *  END) as relationColumnName
  *
  * @param BuildAfter $event
  */
 public function onBuildAfter(BuildAfter $event)
 {
     $datagrid = $event->getDatagrid();
     $datasource = $datagrid->getDatasource();
     $parameters = $datagrid->getParameters();
     if ($datasource instanceof OrmDatasource) {
         /** @var QueryBuilder $query */
         $queryBuilder = $datasource->getQueryBuilder();
         $additionalParams = $parameters->get(ParameterBag::ADDITIONAL_PARAMETERS, []);
         $dataIn = [0];
         $dataOut = [0];
         if (isset($additionalParams[self::GRID_PARAM_DATA_IN])) {
             $filteredParams = array_filter($additionalParams[self::GRID_PARAM_DATA_IN]);
             if (!empty($filteredParams)) {
                 $dataIn = $additionalParams[self::GRID_PARAM_DATA_IN];
             }
         }
         if (isset($additionalParams[self::GRID_PARAM_DATA_NOT_IN])) {
             $filteredParams = array_filter($additionalParams[self::GRID_PARAM_DATA_NOT_IN]);
             if (!empty($filteredParams)) {
                 $dataOut = $additionalParams[self::GRID_PARAM_DATA_NOT_IN];
             }
         }
         $queryParameters = ['data_in' => $dataIn, 'data_not_in' => $dataOut];
         foreach ($this->parameterNames as $paramName) {
             $queryParameters[$paramName] = $parameters->get($paramName);
         }
         if (!$this->isEditMode) {
             unset($queryParameters['data_in'], $queryParameters['data_not_in']);
         }
         $queryBuilder->setParameters($queryParameters);
     }
 }
Exemplo n.º 10
0
 /**
  * @param BuildAfter $event
  */
 public function onBuildAfter(BuildAfter $event)
 {
     $datasource = $event->getDatagrid()->getDatasource();
     if ($datasource instanceof OrmDatasource) {
         $queryBuilder = $datasource->getQueryBuilder();
         $this->prepareQuery($queryBuilder, 'ce', 'cev', PropertyConfigContainer::TYPE_ENTITY);
     }
 }
 /**
  * Bound parameters in query builder
  *
  * @param BuildAfter $event
  */
 public function onBuildAfter(BuildAfter $event)
 {
     $datasource = $event->getDatagrid()->getDatasource();
     if ($datasource instanceof ParameterizableInterface) {
         $queryParameters = $this->prepareParameters();
         $datasource->setParameters($queryParameters);
     }
 }
Exemplo n.º 12
0
 /**
  * Add required filters
  *
  * @param BuildAfter $event
  */
 public function onBuildAfter(BuildAfter $event)
 {
     /** @var OrmDatasource $ormDataSource */
     $ormDataSource = $event->getDatagrid()->getDatasource();
     $queryBuilder = $ormDataSource->getQueryBuilder();
     $parameters = $event->getDatagrid()->getParameters();
     $alias = 'a';
     $queryBuilder->leftJoin('e.fromEmailAddress', $alias);
     $this->factory->prepareQuery($queryBuilder, $alias);
     if ($parameters->has('emailIds')) {
         $emailIds = $parameters->get('emailIds');
         if (!is_array($emailIds)) {
             $emailIds = explode(',', $emailIds);
         }
         $queryBuilder->andWhere($queryBuilder->expr()->in('e.id', $emailIds));
     }
 }
Exemplo n.º 13
0
 /**
  * @param BuildAfter $event
  */
 public function onBuildAfter(BuildAfter $event)
 {
     $datagrid = $event->getDatagrid();
     $datasource = $datagrid->getDatasource();
     if ($datasource instanceof OrmDatasource) {
         $this->parameters = $datagrid->getParameters();
         $queryBuilder = $datasource->getQueryBuilder();
         $this->prepareQuery($queryBuilder, 'cf', 'cfv_', PropertyConfigContainer::TYPE_FIELD);
     }
 }
Exemplo n.º 14
0
 /**
  * @param BuildAfter $event
  */
 public function onBuildAfter(BuildAfter $event)
 {
     $datagrid = $event->getDatagrid();
     $datasource = $datagrid->getDatasource();
     if ($datasource instanceof OrmDatasource) {
         $queryBuilder = $datasource->getQueryBuilder();
         $this->emailQueryFactory->applyAcl($queryBuilder);
         $this->emailQueryFactory->prepareQuery($queryBuilder);
     }
 }
 function it_does_nothing_when_datasource_is_not_an_orm_datasource(BuildAfter $event, DatagridInterface $datagrid, Acceptor $acceptor, DatagridConfiguration $config, DatasourceInterface $datasource, $requestParams)
 {
     $event->getDatagrid()->willReturn($datagrid);
     $datagrid->getDatasource()->willReturn($datasource);
     $datagrid->getAcceptor()->willReturn($acceptor);
     $acceptor->getConfig()->willReturn($config);
     $config->offsetGetByPath('[options][locale_parameter]')->willReturn(null);
     $requestParams->get(Argument::cetera())->shouldNotBeCalled();
     $this->onBuildAfter($event);
 }
 /**
  * @param BuildAfter $event
  */
 public function onBuildAfter(BuildAfter $event)
 {
     $datagrid = $event->getDatagrid();
     /** @var OrmDatasource $datasource */
     $datasource = $datagrid->getDatasource();
     $entityId = $datagrid->getParameters()->get('id');
     if ($entityId) {
         $datasource->bindParameters(['relation']);
     }
 }
 /**
  * @param BuildAfter $event
  */
 public function onBuildAfter(BuildAfter $event)
 {
     $datagrid = $event->getDatagrid();
     $datasource = $datagrid->getDatasource();
     if ($datasource instanceof OrmDatasource) {
         $parameters = $datagrid->getParameters();
         $userId = $parameters->get('userId');
         $this->emailGridHelper->updateDatasource($datasource, $userId);
         $this->emailGridHelper->handleRefresh($parameters, $userId);
     }
 }
 /**
  * Add locale parameter to the querybuilder
  *
  * @param BuildAfter $event
  */
 public function onBuildAfter(BuildAfter $event)
 {
     $datagrid = $event->getDatagrid();
     $datasource = $datagrid->getDatasource();
     $config = $datagrid->getAcceptor()->getConfig();
     $localeParameter = $config->offsetGetByPath(self::LOCALE_PARAMETER);
     if ($localeParameter && $datasource instanceof Datasource) {
         $queryBuilder = $datasource->getQueryBuilder();
         $queryBuilder->setParameter($localeParameter, $this->requestParams->get($localeParameter, null));
     }
 }
Exemplo n.º 19
0
 /**
  * Adjust query for tag-results-grid (tag search result grid)
  * after datasource has been built
  *
  * @param BuildAfter $event
  */
 public function onBuildAfter(BuildAfter $event)
 {
     $datagrid = $event->getDatagrid();
     $datasource = $datagrid->getDatasource();
     if ($datasource instanceof SearchDatasource) {
         $parameters = $datagrid->getParameters();
         $searchEntity = $parameters->get('from', '*');
         $searchEntity = empty($searchEntity) ? '*' : $searchEntity;
         $searchString = $parameters->get('search', '');
         $datasource->getQuery()->from($searchEntity)->andWhere(Indexer::TEXT_ALL_DATA_FIELD, Query::OPERATOR_CONTAINS, $searchString, Query::TYPE_TEXT);
     }
 }
Exemplo n.º 20
0
 /**
  * Mailbox grids have to be manually filtered because mailbox access is determined by access to different entity.
  *
  * @param BuildAfter $event
  */
 public function onBuildAfter(BuildAfter $event)
 {
     /** @var OrmDatasource $ormDataSource */
     $ormDataSource = $event->getDatagrid()->getDatasource();
     $queryBuilder = $ormDataSource->getQueryBuilder();
     $parameters = $event->getDatagrid()->getParameters();
     /*
      * Mailbox grid accepts organization_ids parameters so mailboxes can be filtered by their organization.
      * If no organization is provided, all organizations editable by current users are used.
      */
     if ($parameters->has('organization_ids')) {
         $organizations = $parameters->get('organization_ids');
     } else {
         $organizations = $this->getAuthorisedOrganizationIds();
     }
     if (!empty($organizations)) {
         $queryBuilder->andWhere($queryBuilder->expr()->in('m.organization', $organizations));
     } else {
         $queryBuilder->andWhere('m.organization IS NULL');
     }
 }
Exemplo n.º 21
0
 /**
  * @param BuildAfter $event
  */
 public function onBuildAfter(BuildAfter $event)
 {
     $datagrid = $event->getDatagrid();
     $datasource = $datagrid->getDatasource();
     if ($datasource instanceof OrmDatasource) {
         $parameters = $datagrid->getParameters();
         $entityClass = $this->entityRoutingHelper->resolveEntityClass($parameters->get('entityClass'));
         $entityId = $parameters->get('entityId');
         // apply activity filter
         $this->activityManager->addFilterByTargetEntity($datasource->getQueryBuilder(), $entityClass, $entityId);
     }
 }
 /**
  * Adjust query for tag-results-grid (tag search result grid)
  * after datasource has been built
  *
  * @param BuildAfter $event
  */
 public function onBuildAfter(BuildAfter $event)
 {
     $datasource = $event->getDatagrid()->getDatasource();
     if ($datasource instanceof SearchDatasource) {
         /** @var $query Query */
         $query = new IndexerQuery($this->indexer, $this->indexer->select());
         $searchEntity = $this->requestParams->get('from', '*');
         $searchEntity = empty($searchEntity) ? '*' : $searchEntity;
         $searchString = $this->requestParams->get('search', '');
         $query->from($searchEntity)->andWhere(Indexer::TEXT_ALL_DATA_FIELD, '~', $searchString, 'text');
         $datasource->setQuery($query);
     }
 }
Exemplo n.º 23
0
 /**
  * @param BuildAfter $event
  */
 public function onBuildAfter(BuildAfter $event)
 {
     $datagrid = $event->getDatagrid();
     $datasource = $datagrid->getDatasource();
     if ($datasource instanceof OrmDatasource) {
         $parameters = $datagrid->getParameters();
         $userId = $parameters->get('userId');
         if (!$userId) {
             $userId = $this->securityFacade->getLoggedUserId();
         }
         $datasource->getQueryBuilder()->andWhere(sprintf('task.owner = %d', $userId));
     }
 }
 /**
  * Adjust query for tag-results-grid (tag search result grid)
  * after datasource has been built
  *
  * @param BuildAfter $event
  */
 public function onBuildAfter(BuildAfter $event)
 {
     $datasource = $event->getDatagrid()->getDatasource();
     if ($datasource instanceof OrmDatasource) {
         /** @var QueryBuilder $query */
         $queryBuilder = $datasource->getQueryBuilder();
         $queryBuilder->setParameter('tag', $this->requestParams->get('tag_id', 0));
         $searchEntity = $this->requestParams->get('from', '*');
         if ($searchEntity != '*' && !empty($searchEntity)) {
             $queryBuilder->andWhere('tt.alias = :alias')->setParameter('alias', $searchEntity);
         }
     }
 }
 /**
  * Binds datagrid parameters to datasource query on event.
  *
  * @param BuildAfter $event
  */
 public function onBuildAfter(BuildAfter $event)
 {
     $datagrid = $event->getDatagrid();
     $datasource = $datagrid->getDatasource();
     if (!$datasource instanceof ParameterBinderAwareInterface) {
         return;
     }
     $parameters = $datagrid->getConfig()->offsetGetByPath(self::DATASOURCE_BIND_PARAMETERS_PATH, []);
     if (!$parameters || !is_array($parameters)) {
         return;
     }
     $datasource->bindParameters($parameters);
 }
 /**
  * @param BuildAfter $event
  */
 public function onBuildAfter(BuildAfter $event)
 {
     $defaults = $this->context->getUser()->getProductGridFilters();
     if (empty($defaults)) {
         return;
     }
     $configuration = $event->getDatagrid()->getAcceptor()->getConfig();
     foreach ($configuration['filters']['columns'] as $code => $filter) {
         if (in_array($code, $this->disallowed)) {
             continue;
         }
         $configuration->offsetSetByPath(sprintf('%s[%s][enabled]', Configuration::COLUMNS_PATH, $code), in_array($code, $defaults));
     }
 }
 /**
  * @param BuildAfter $event
  */
 public function onBuildAfter(BuildAfter $event)
 {
     $datagrid = $event->getDatagrid();
     $datasource = $datagrid->getDatasource();
     if ($datasource instanceof OrmDatasource) {
         $parameters = $datagrid->getParameters();
         $entityClass = $this->entityRoutingHelper->decodeClassName($parameters->get('entityClass'));
         $entityId = $parameters->get('entityId');
         $this->emailGridHelper->updateDatasource($datasource, $entityId, $entityClass);
         if ($this->emailGridHelper->isUserEntity($entityClass)) {
             $this->emailGridHelper->handleRefresh($parameters, $entityId);
         }
     }
 }
 /**
  * @param BuildAfter $event
  */
 public function onBuildAfter(BuildAfter $event)
 {
     $datagrid = $event->getDatagrid();
     $parameters = $datagrid->getParameters();
     if (!$this->isApplicable($datagrid->getName(), $parameters)) {
         return;
     }
     if (!($emailCampaign = $parameters->get('emailCampaign', false))) {
         throw new \InvalidArgumentException('Parameter "emailCampaign" is missing');
     }
     $datasource = $datagrid->getDatasource();
     if ($datasource instanceof OrmDatasource) {
         $datasource->getQueryBuilder()->setParameter('emailCampaign', $emailCampaign);
     }
 }
 /**
  * Adjust query for tag-results-grid (tag search result grid)
  * after datasource has been built
  *
  * @param BuildAfter $event
  */
 public function onBuildAfter(BuildAfter $event)
 {
     $datagrid = $event->getDatagrid();
     $datasource = $datagrid->getDatasource();
     if ($datasource instanceof OrmDatasource) {
         $parameters = $datagrid->getParameters();
         $queryBuilder = $datasource->getQueryBuilder();
         $this->securityProvider->applyAcl($queryBuilder, 'tt');
         $queryBuilder->setParameter('tag', $parameters->get('tag_id', 0));
         $searchEntity = $parameters->get('from', '*');
         if ($searchEntity != '*' && !empty($searchEntity)) {
             $queryBuilder->andWhere('tt.alias = :alias')->setParameter('alias', $searchEntity);
         }
     }
 }
Exemplo n.º 30
0
 /**
  * Add marketingList instance to parameters.
  *
  * @param BuildAfter $event
  */
 public function onBuildAfter(BuildAfter $event)
 {
     $dataGrid = $event->getDatagrid();
     $dataGridName = $dataGrid->getName();
     $parameters = $dataGrid->getParameters();
     if (!$this->isApplicable($dataGridName, $parameters)) {
         return;
     }
     $dataSource = $dataGrid->getDatasource();
     if ($dataSource instanceof OrmDatasource) {
         $marketingListId = $this->marketingListHelper->getMarketingListIdByGridName($dataGridName);
         $marketingList = $this->marketingListHelper->getMarketingList($marketingListId);
         $dataSource->getQueryBuilder()->addSelect($marketingList->getId() . ' as marketingList')->setParameter('marketingListEntity', $marketingList);
     }
 }