/** * @param ConfigManager $configManager */ public function __construct(ConfigManager $configManager) { $this->configManager = $configManager; $this->em = $this->configManager->getEntityManager(); $this->options = $this->em->getRepository(OptionSet::ENTITY_NAME); $this->relations = $this->em->getRepository(OptionSetRelation::ENTITY_NAME); }
/** * @param string $entityClassName * @param array $excludedIds * @param integer $offset * * @return array */ protected function getRecordsToReset($entityClassName, array $excludedIds, $offset) { $qb = $this->em->getRepository($entityClassName)->createQueryBuilder('e'); if ($excludedIds) { $qb->andWhere($qb->expr()->notIn('e.id', $excludedIds)); } return $qb->setMaxResults(static::BATCH_SIZE)->setFirstResult($offset)->getQuery()->getResult(); }
/** * Search and return entities * * @param $search * @param $targetField * @return array */ protected function searchEntities($search, $targetField) { /** @var QueryBuilder $queryBuilder */ $queryBuilder = $this->entityManager->getRepository($this->entityName)->createQueryBuilder('e'); if ($this->isCustomField) { $targetField = ExtendConfigDumper::FIELD_PREFIX . $targetField; } $queryBuilder->where($queryBuilder->expr()->like('e.' . $targetField, $queryBuilder->expr()->literal($search . '%'))); return $queryBuilder->getQuery()->getArrayResult(); }
/** * @param string $entity * @param string $keyField * @param string $labelField * * @return array */ protected function getChoices($entity, $keyField, $labelField) { $queryBuilder = $this->entityManager->getRepository($entity)->createQueryBuilder('e'); //select only id and label fields $queryBuilder->select("e.{$keyField}, e.{$labelField}"); $result = $this->aclHelper->apply($queryBuilder)->getResult(); $choices = []; foreach ($result as $item) { $choices[$item[$keyField]] = $item[$labelField]; } return $choices; }
/** * @param FormEvent $event */ public function postSubmit(FormEvent $event) { $form = $event->getForm(); $configModel = $form->getConfig()->getOption('config_model'); $data = $event->getData(); $labelsToBeUpdated = []; foreach ($this->configManager->getProviders() as $provider) { $scope = $provider->getScope(); if (isset($data[$scope])) { $configId = $this->configManager->getConfigIdByModel($configModel, $scope); $config = $provider->getConfigById($configId); $translatable = $provider->getPropertyConfig()->getTranslatableValues($configId); foreach ($data[$scope] as $code => $value) { if (in_array($code, $translatable)) { // check if a label text was changed $labelKey = $config->get($code); if (!$configModel->getId()) { $labelsToBeUpdated[$labelKey] = $value; } elseif ($value != $this->translator->trans($labelKey)) { $labelsToBeUpdated[$labelKey] = $value; } // replace label text with label name in $value variable $value = $config->get($code); } $config->set($code, $value); } $this->configManager->persist($config); } } if ($form->isValid()) { // update changed labels if any if (!empty($labelsToBeUpdated)) { $locale = $this->translator->getLocale(); foreach ($labelsToBeUpdated as $labelKey => $labelText) { // save into translation table /** @var TranslationRepository $translationRepo */ $translationRepo = $this->em->getRepository(Translation::ENTITY_NAME); $translationRepo->saveValue($labelKey, $labelText, $locale, TranslationRepository::DEFAULT_DOMAIN, Translation::SCOPE_UI); } // mark translation cache dirty $this->dbTranslationMetadataCache->updateTimestamp($locale); } $this->configManager->flush(); } }
/** * @param string $entityClassName * @param array $ids * @param integer $offset * * @return array */ protected function getRecordsToRecalculate($entityClassName, $ids, $offset) { $entityRepository = $this->em->getRepository($entityClassName); return $entityRepository->findBy(['id' => $ids], ['id' => 'ASC'], self::BATCH_SIZE, $offset); }
/** * @return EmailOrigin[] */ protected function getOrigins() { $criteria = ['owner' => $this->securityContext->getToken()->getUser(), 'isActive' => true]; return $this->em->getRepository(self::EMAIL_ORIGIN)->findBy($criteria); }