Example #1
0
 /**
  * Get the repository from the registry
  * We have to do this here because the call to registry::getRepository
  * requires the database to be setup which is a problem for using managers in console commands
  *
  * @return EntityRepository
  */
 protected function getRepository()
 {
     if (!$this->repository) {
         $this->repository = $this->registry->getRepository($this->class);
     }
     return $this->repository;
 }
Example #2
0
 /**
  * @param Request $request
  *
  * @return bool|User
  */
 public function tryAddUser(Request $request)
 {
     $params = $request->request->all();
     if (!isset($params['user']['id'])) {
         return false;
     }
     $user = $this->_doctrine->getRepository('SiteBundle:User')->findOneBy(['vk' => $params['user']['id']]);
     if ($user) {
         return $user;
     }
     $user = new User();
     $user->setName($params['user']['first_name']);
     $user->setLastname($params['user']['last_name']);
     $user->setVk($params['user']['id']);
     $user->setPassword($this->_generatePassword($params['user']['id']));
     $user->setUsername($this->_generateUserName($params['user']['id']));
     $user->setRole($this->_defaultRole());
     $user->setPhone('');
     $user->setPhoto('');
     $user->setEmail('');
     $em = $this->_doctrine->getManager();
     $em->persist($user);
     $em->flush();
     return $user;
 }
 /**
  * Read available User/Host requirements from database
  *
  * @return array
  */
 public function getRights()
 {
     /** @var UserHostRepository $repository */
     $repository = $this->doctrine->getRepository($this->bundleName . ':UserHost');
     $result = $repository->findAllSelect();
     return $result;
 }
 /**
  * @param $date
  * @param $item
  * @param $precision 
  * @param $route_new
  * @param $route_show 
  */
 public function renderDay($date, $item, $project, $precision, $route_new, $route_show)
 {
     $start = new \DateTime($date);
     $end = (new \DateTime($date))->modify('+1 day');
     $bookings = $this->doctrine->getRepository($this->entity)->createQueryBuilder('b')->select('b')->where('b.start <= :start and b.end >= :end')->orwhere('b.end >= :start and b.end <= :end')->orwhere('b.start >= :start and b.start <= :end')->andWhere('b.item = :item')->orderBy('b.start', 'ASC')->setParameters(array('start' => $start, 'end' => $end, 'item' => $item))->getQuery()->getResult();
     return $this->environment->render('SladBookingBundle:Calendar:day.html.twig', array('date' => new \DateTime($date), 'item' => $item, 'project' => $project, 'bookings' => $bookings, 'precision' => $precision, 'route_new' => $route_new, 'route_show' => $route_show));
 }
Example #5
0
 public function loadUserByUsername($username)
 {
     if (!$username) {
         return null;
     }
     return $this->_doctrine->getRepository('SiteBundle:User')->findOneBy(['username' => $username]);
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->output = $output;
     $this->institutionMediaService = $this->getContainer()->get('services.institution.media');
     $this->fileSystem = $this->institutionMediaService->getFilesystem();
     $this->logoSizes = $this->institutionMediaService->getSizesByType(InstitutionMediaService::LOGO_TYPE_IMAGE);
     $this->featuredMediaSizes = $this->institutionMediaService->getSizesByType(InstitutionMediaService::FEATURED_TYPE_IMAGE);
     $this->gallerySizes = $this->institutionMediaService->getSizesByType(InstitutionMediaService::GALLERY_TYPE_IMAGE);
     // loop through all institutions
     $this->doctrine = $this->getContainer()->get('doctrine');
     $institutions = $this->doctrine->getRepository('InstitutionBundle:Institution')->findAll();
     foreach ($institutions as $_institution) {
         $this->output->writeln('Migrating images of institution #' . $_institution->getId());
         $this->output->write("    ");
         // migrate logo
         $this->migrateLogo($_institution);
         $this->output->write("    ");
         // migrate banner
         $this->migrateFeaturedMedia($_institution);
         $this->output->write("    ");
         // migrate gallery
         $this->migrateGallery($_institution);
         $this->output->write("    ");
         // migrate clinic logos
         foreach ($_institution->getInstitutionMedicalCenters() as $imc) {
             $this->migrateClinicLogo($imc);
             $this->output->write("    ");
         }
         $this->output->writeln('All Done.');
     }
     $this->output->writeln('END OF SCRIPT');
 }
 public function getCode($bannerType, $place = null, $referenceId = null)
 {
     $bannerRepository = $this->doctrine->getRepository('AciliaBannerBundle:Banner');
     $bannerTag = '';
     if ($place == null) {
         $place = $this->place;
     }
     // If Place is not defined, Ad can't be shown
     if (null === $place) {
         return $bannerTag;
     }
     if ($referenceId === false) {
         $referenceId = null;
     } elseif ($referenceId == null) {
         $referenceId = $this->referenceId;
     }
     $context = $this->getContext();
     // Get URL
     $currentUrl = $this->requestStack->getMasterRequest()->getPathInfo();
     // Get resource and context
     $event = new ResourceBannerEvent();
     $this->dispatcher->dispatch(ResourceBannerEvent::NAME, $event);
     if ($event->isAvailable()) {
         $resource = $event->getResource();
         // Overwrite ad context if required
         if ($event->getContext() != null) {
             $context = $event->getContext();
         }
         // Banner identifier key
         $key = 'Banner:' . $resource . ':' . $context . ':' . $place . ':' . $bannerType . ':' . $referenceId . ':' . sha1($currentUrl);
         if (isset($this->instances[$key])) {
             return $this->instances[$key];
         }
         $bannerTag = $this->memcache->get($key);
         if ($this->memcache->notFound()) {
             // Create Banner Tag
             $bannerTag = new BannerTag();
             $bannerTag->setResource($resource)->setBannerType($bannerType)->setPlace($place)->setContext($context)->setReferenceId($referenceId)->setCacheKey($key);
             if ($bannerRepository->isPageAvailable($bannerTag, $currentUrl, $this->getType('none'))) {
                 return '<!-- BANNER BEGIN - This page has it\'s Ads Disabled - BANNER END -->';
             }
             // Fill Banner Tag
             $bannerRepository->fillBannerTag($bannerTag, $currentUrl, $this->getType($bannerTag->getBannerType()));
             $fallbacks = $this->fallbacks;
             while ($bannerTag->isEmpty() && count($fallbacks) > 0) {
                 $fallback = array_slice($fallbacks, 0, 1);
                 array_shift($fallbacks);
                 $place = key($fallback);
                 $referenceId = $fallback[$place];
                 $bannerTag->setPlace($place)->setReferenceId($referenceId);
                 // Fill Banner Tag
                 $bannerRepository->fillBannerTag($bannerTag, $currentUrl, $this->getType($bannerTag->getBannerType()));
             }
             // Save on Memcache and internally
             $this->instances[$key] = $bannerTag;
             $this->memcache->set($key, $bannerTag, 60);
         }
     }
     return $bannerTag;
 }
 /**
  * reverseTransform
  *
  * @param integer $idx
  *
  * @return \Erichard\DmsBundle\Entity\DocumentNode|null|object
  */
 public function reverseTransform($idx)
 {
     if (null === $idx) {
         return null;
     }
     return $this->registry->getRepository('Erichard\\DmsBundle\\Entity\\DocumentNode')->find($idx);
 }
 /**
  * @param Registry      $manager,
  * @param RequestStack  $requestStack,
  * @param ObjectManager $persistence
  *
  * @InjectParams({
  *     "manager"        = @Inject("doctrine"),
  *     "requestStack"   = @Inject("request_stack"),
  *     "persistence"    = @Inject("claroline.persistence.object_manager")
  * })
  */
 public function __construct(Registry $manager, RequestStack $requestStack, ObjectManager $persistence)
 {
     $this->manager = $persistence;
     $this->request = $requestStack->getCurrentRequest();
     $this->content = $manager->getRepository('ClarolineCoreBundle:Content');
     $this->translations = $manager->getRepository('ClarolineCoreBundle:ContentTranslation');
 }
 /**
  * Looks for the object that corresponds to the selected 'id' of the current entity.
  *
  * @param array $entityConfig
  * @param mixed $itemId
  *
  * @return object The entity
  *
  * @throws EntityNotFoundException
  */
 private function findCurrentItem(array $entityConfig, $itemId)
 {
     if (null === ($entity = $this->doctrine->getRepository($entityConfig['class'])->find($itemId))) {
         throw new EntityNotFoundException(array('entity' => $entityConfig, 'entity_id' => $itemId));
     }
     return $entity;
 }
Example #11
0
 /**
  * @param int         $nodeId
  * @param null|string $type
  *
  * @return NodeReferenceInterface
  */
 public function loadNode($nodeId, $type = null)
 {
     if (is_null($type)) {
         $node = $this->registry->getRepository('ClasticNodeBundle:Node')->find($nodeId);
         $type = $node->getType();
     }
     return $this->registry->getRepository($this->getEntityName($type))->findOneBy(array('node' => $nodeId));
 }
Example #12
0
 private function canYouDoIt(Comment $comment, User $user)
 {
     $commentOwner = $this->doctrine->getRepository('AppBundle:User')->findOneBy(array('email' => $comment->getAuthorEmail()));
     if (in_array("ROLE_ADMIN", $commentOwner->getRoles()) || $comment->getArticle()->getAuthorEmail() !== $user->getEmail()) {
         return false;
     }
     return true;
 }
 /**
  * @param RemoveDojoCommand $command
  */
 public function handle(RemoveDojoCommand $command)
 {
     $dojo = $this->doctrine->getRepository('CoderDojoWebsiteBundle:Dojo')->find($command->getId());
     $this->doctrine->remove($dojo);
     $this->doctrine->flush();
     $event = new DojoRemovedEvent($command->getId());
     $this->eventRecorder->record($event);
 }
Example #14
0
 /**
  * @param mixed $context
  */
 protected function executeAction($context)
 {
     $settingsClass = $this->contextAccessor->getValue($context, $this->processType);
     $settingsClass = $this->processStorage->getProcess($settingsClass)->getSettingsEntityFQCN();
     $email = $this->contextAccessor->getValue($context, $this->email);
     $results = $this->doctrine->getRepository('OroEmailBundle:Mailbox')->findBySettingsClassAndEmail($settingsClass, $email);
     $this->contextAccessor->setValue($context, $this->attribute, $results);
 }
 /**
  * Fetches the data associated to the given parser parameters.
  * 
  * @param string $function
  * @param string $parser
  * @param object $target
  * 
  * @return mixed
  * Returns the associated cache data or null if it not exists.
  */
 public function get($function, $parser, $target)
 {
     $cacheKey = $this->buildCacheKey($function, $parser, $target);
     $cacheEntry = $this->doctrine->getRepository('PHPSanitizer\\ProjectBundle\\Entity\\AnalysesParsersCache')->findOneBy(array('key' => $cacheKey));
     if ($cacheEntry === null) {
         return null;
     }
     return $cacheEntry->getData();
 }
 /**
  * Sets search repository
  *
  * @param AbstractSearch $search
  */
 protected function handleRepository(AbstractSearch $search)
 {
     $entityClass = $search->getOption('entityClass');
     $entityManagerName = $search->getOption('entityManagerName');
     if (null === $entityClass) {
         throw new \InvalidArgumentException('Option entityClass must be set');
     }
     $search->setRepository($this->doctrine->getRepository($entityClass, $entityManagerName));
 }
 /**
  * Constructor
  *
  * @param Registry $doctrineRegistry
  * @param JiraService $jiraService
  */
 public function __construct(Registry $doctrineRegistry, JiraService $jiraService, Filesystem $fileSystem)
 {
     $this->settingsRepository = $doctrineRegistry->getRepository('MDVPriorityBundle:Settings');
     $this->issueRepository = $doctrineRegistry->getRepository('MDVPriorityBundle:Issue');
     $this->voteRepository = $doctrineRegistry->getRepository('MDVPriorityBundle:Vote');
     $this->stakeholderRepository = $doctrineRegistry->getRepository('MDVPriorityBundle:Stakeholder');
     $this->priorityRepository = $doctrineRegistry->getRepository('MDVPriorityBundle:Priority');
     $this->jiraService = $jiraService;
     $this->fileSystem = $fileSystem;
 }
Example #18
0
 public function printCategoriesList()
 {
     // żeby nie robiło dwuch zapytać o to samo
     if (!isset($this->categoriesList)) {
         $CategoryRepo = $this->doctrine->getRepository('AirBlogBundle:Category');
         $this->categoriesList = $CategoryRepo->findAll();
     }
     //renderowanie szablonu views/Template/categoriesList
     return $this->environment->render('AirBlogBundle:Template:categoriesList.html.twig', array('categoriesList' => $this->categoriesList));
 }
 /**
  * @param array $entityInf
  * @param int   $parentId
  * @return array
  */
 public function getEntities($entityInf, $parentId)
 {
     /** @var EntityRepository $repository */
     $repository = $this->doctrine->getRepository($entityInf['class']);
     /** @var QueryBuilder $queryBuilder */
     $queryBuilder = $repository->createQueryBuilder('e');
     $queryBuilder->where($queryBuilder->expr()->eq('e.' . $entityInf['parent_property'], ':parentId'))->orderBy('e.' . $entityInf['order_property'], $entityInf['order_direction'])->setParameter('parentId', $parentId);
     $this->setCallback($repository, $queryBuilder, $entityInf);
     return $queryBuilder->getQuery()->getResult();
 }
 /**
  * {@inheritdoc}
  */
 public function setDefaultOptions(OptionsResolverInterface $resolver)
 {
     $choices = function (Options $options) {
         if (empty($options['entity_class'])) {
             return [];
         }
         return $this->aclHelper->apply($this->doctrine->getRepository('OroTagBundle:Tag')->createQueryBuilder('t')->join('t.tagging', 'tagging')->where('tagging.entityName = :entity')->setParameter('entity', $options['entity_class']))->getResult();
     };
     $resolver->setDefaults(['class' => 'OroTagBundle:Tag', 'property' => 'name', 'entity_class' => null, 'choices' => $choices]);
 }
 public function getAllianceCorps(Character $char, Registry $doctrine)
 {
     $leaderCorp = $doctrine->getRepository('AppBundle:Corporation')->findByCorpName($char->getCorporationName());
     if ($leaderCorp === null) {
         // this is bad
         return false;
     }
     $registeredAllianceCorps = $doctrine->getRepository('AppBundle:Corporation')->findCorporationsByAlliance($leaderCorp->getCorporationDetails()->getAllianceName());
     return $registeredAllianceCorps;
 }
Example #22
0
 /**
  * @dataProvider autoCompleteHandlerProvider
  * @param boolean $active
  * @param string $handlerName
  */
 public function testAutoCompleteHandler($active, $handlerName, $query)
 {
     $user = $this->registry->getRepository('OroUserBundle:User')->findOneBy(['username' => 'simple_user2']);
     $user->setEnabled($active);
     $this->registry->getManager()->flush();
     $this->client->request('GET', $this->getUrl('oro_email_mailbox_users_search', ['organizationId' => $user->getOrganization()->getId()]), array('page' => 1, 'per_page' => 10, 'name' => $handlerName, 'query' => $query));
     $result = $this->client->getResponse();
     $arr = $this->getJsonResponseContent($result, 200);
     $this->assertCount((int) $active, $arr['results']);
 }
 public function validate($value, Constraint $constraint)
 {
     //$value = $entity->getName();
     $institution = $this->doctrine->getRepository('InstitutionBundle:Institution')->findOneBy(array('name' => $value));
     if (!$institution) {
         return;
     }
     $this->context->addViolation($constraint->message, array('{{ field }}' => $value));
     return;
 }
 /**
  * 
  * @param array $inquiryIds
  * @param unknown_type $status
  */
 public function updateInquiriesStatus(array $inquiryIds, $status)
 {
     $inquiries = $this->doctrine->getRepository('InstitutionBundle:InstitutionInquiry')->findById($inquiryIds);
     $em = $this->doctrine->getEntityManager();
     foreach ($inquiries as $inquiry) {
         $inquiry->setStatus($status);
         $em->persist($inquiry);
     }
     return $em->flush();
 }
 /**
  * @param $item
  * @param  string                    $start
  * @param  int                       $months
  * @return string
  * @throws \InvalidArgumentException
  */
 public function renderCalendar($item, $start = 'now', $months = 1)
 {
     if (intval($months) === 0) {
         throw new \InvalidArgumentException('Month number should be integer');
     }
     $now = new \DateTime($start);
     $end = new \DateTime();
     $end->add(new \DateInterval('P' . $months . 'M'));
     $bookings = $this->doctrine->getRepository($this->entity)->createQueryBuilder('b')->select('b')->where('b.start >= :now')->orWhere('b.start <= :end')->orWhere('b.end >= :now')->andWhere('b.item = :item')->orderBy('b.start', 'ASC')->setParameters(array('now' => $now, 'end' => $end, 'item' => $item))->getQuery()->getResult();
     return $this->environment->render('MelifaroBookingBundle:Calendar:month.html.twig', array('bookings' => $bookings, 'start' => $start, 'months' => $months));
 }
 /**
  * @param mixed $value The value in the transformed representation
  * @return mixed The value in the original representation
  * @throws TransformationFailedException When the transformation fails.
  */
 public function reverseTransform($username)
 {
     if (!$username) {
         return null;
     }
     $user = $this->registry->getRepository('AppBundle:User')->findOneBy(array('username' => $username));
     if (!$user) {
         throw new TransformationFailedException($this->translator->trans('user.unknownusername'));
     }
     return $user;
 }
 /**
  * et entity assuming the value is the id and then return it
  * @param type $sourceFieldValue
  * @param Reference $source
  * @param Reference $destination
  * @return type
  * @throws \Exception
  */
 public function forward($sourceFieldValue, $field, $source, $destination)
 {
     $entityClass = $this->getEntityClass();
     if (!$entityClass) {
         $entityClass = get_class($destination);
     }
     $repository = $this->doctrine->getRepository($entityClass);
     if (!$repository) {
         throw new TransformationException('Could not resolve doctrine entity from destination type');
     }
     return $repository->find($sourceFieldValue);
 }
Example #28
0
 /**
  * Get email entities from owner entity
  *
  * @param object $entity
  * @return array
  */
 public function getEmailsByOwnerEntity($entity)
 {
     $ownerColumnName = null;
     foreach ($this->emailOwnerStorage->getProviders() as $provider) {
         if ($this->activityListChainProvider->isSupportedTargetEntity($entity) && $provider->getEmailOwnerClass() === ClassUtils::getClass($entity)) {
             $ownerColumnName = $this->emailOwnerStorage->getEmailOwnerFieldName($provider);
             break;
         }
     }
     if ($ownerColumnName === null) {
         return [];
     }
     return $this->registry->getRepository('OroEmailBundle:Email')->getEmailsByOwnerEntity($entity, $ownerColumnName);
 }
Example #29
0
 /**
  * Apply custom ACL checks
  *
  * @param QueryBuilder $qb
  */
 public function applyAcl(QueryBuilder $qb)
 {
     $user = $this->securityFacade->getLoggedUser();
     $organization = $this->securityFacade->getOrganization();
     $mailboxIds = $this->doctrine->getRepository('OroEmailBundle:Mailbox')->findAvailableMailboxIds($user, $organization);
     $uoCheck = $qb->expr()->andX($qb->expr()->eq('eu.owner', ':owner'), $qb->expr()->eq('eu.organization ', ':organization'));
     if (!empty($mailboxIds)) {
         $qb->andWhere($qb->expr()->orX($uoCheck, $qb->expr()->in('eu.mailboxOwner', ':mailboxIds')));
         $qb->setParameter('mailboxIds', $mailboxIds);
     } else {
         $qb->andWhere($uoCheck);
     }
     $qb->setParameter('owner', $user->getId());
     $qb->setParameter('organization', $organization->getId());
 }
 /**
  * @param string $ticket
  * @param string $email
  * @return bool
  */
 public function validate($ticket, $email = null)
 {
     if (!$ticket) {
         throw new \InvalidArgumentException('Invalid ticket');
     }
     /** @var RegistrationApplicationRepository $registrationApplicationRepo */
     $registrationApplicationRepo = $this->doctrine->getRepository('RegistrarBundle:RegistrationApplication');
     if ($registrationApplication = $registrationApplicationRepo->getUnexpired($email, $ticket)) {
         $this->expireRegistrationApplication($registrationApplication);
         return true;
     } else {
         throw new \RuntimeException('Invalid ticket');
     }
     return false;
 }