Finds orders by subject, optionally filtered by user and/or type (default order).

@param object        $subject
@param UserInterface $user
@param string        $type
@param int           $hydrationMode
@return \Ekyna\Component\Sale\Order\OrderInterface[]
164239
public function findBySubject(
        $subject,
        UserInterface $user = null,
        $type = OrderTypes::TYPE_ORDER,
        $hydrationMode = Query::HYDRATE_OBJECT
    ) {
        $item = $this->itemHelper->transform($subject);

        $qb = $this->getCollectionQueryBuilder();
        $qb
            ->join('o.items', 'i')
            ->andWhere($qb->expr()->eq('o.type', ':type'))
            ->andWhere($qb->expr()->eq('i.subjectData', ':subject_data'))
            ->andWhere($qb->expr()->eq('i.subjectType', ':subject_type'))
            ->addOrderBy('o.updatedAt', 'desc')
            ->groupBy('o.id')
        ;
        if (null !== $user) {
            $qb->andWhere($qb->expr()->eq('o.user', ':user'));
        }

        $query = $qb
            ->getQuery()
            ->setParameter('type', $type)
            ->setParameter('subject_type', $item->getSubjectType())
            ->setParameter('subject_data', $item->getSubjectData(), Type::JSON_ARRAY)
        ;
        if (null !== $user) {
            $query->setParameter('user', $user);
        }

        return $query->getResult($hydrationMode);
    }
428215
public function findDraft($user)
    {
        if ($user instanceof UserInterface) {
            $user = $user->getId();
        }

        return $this->findOneDraftBy(['user' => $user]);
    }
1220185
public function afterCreate(\Magento\Sales\Api\OrderCustomerManagementInterface $subject, $customer)
    {
        //New Automation enrolment to queue
        $this->automation->newCustomerAutomation($customer);

        return $customer;
    }
9190
public function getEntities(array $options = [], $hydrationMode = AbstractQuery::HYDRATE_OBJECT)
    {
        $options = EntityRepositoryOptionsResolver::createAndResolve($options);
        return $this->getQueryBuilder($options['filters'], $options['sorting'])
            ->getQuery()
            ->execute(null, $hydrationMode);
    }
799360
public function accept(StatefulSubjectInterface $subject)
    {
        $execution_context = $subject->getExecutionContext();
        $parameters = $execution_context->getParameters();

        if (is_array($parameters)) {
            $params = $parameters;
        } elseif (is_object($parameters) && is_callable(array($parameters, 'toArray'))) {
            $params = $parameters->toArray();
        } else {
            throw new RuntimeError(
                'The $subject->getExecutionContext()->getParameters() must return array or object with toArray method.'
            );
        }

        $transition_acceptable = $this->expression_service->evaluate(
            $this->options->get('expression'),
            array_merge(
                $params,
                [
                    'subject' => $subject,
                    'current_user' => $this->environment->getUser(),
                ]
            )
        );

        return (bool)$transition_acceptable;
    }
1143408
public function hydrate(ObjectInterface $object, Property $property, GenerationContext $context): ObjectInterface
    {
        $instance = $object->getInstance();
        try {
            $this->propertyAccessor->setValue($instance, $property->getName(), $property->getValue());
        } catch (SymfonyNoSuchPropertyException $exception) {
            throw HydrationExceptionFactory::createForCouldNotHydrateObjectWithProperty($object, $property, 0, $exception);
        } catch (SymfonyAccessException $exception) {
            throw HydrationExceptionFactory::createForInaccessibleProperty($object, $property, 0, $exception);
        } catch (SymfonyInvalidArgumentException $exception) {
            throw HydrationExceptionFactory::createForInvalidProperty($object, $property, 0, $exception);
        } catch (SymfonyPropertyAccessException $exception) {
            throw HydrationExceptionFactory::create($object, $property, 0, $exception);
        } catch (TypeError $error) {
            throw HydrationExceptionFactory::createForInvalidProperty($object, $property, 0, $error);
        }

        return new SimpleObject($object->getId(), $instance);
    }
611425
public function findByUser(User $user, $executeQuery = true)
    {
        $queryBuilder = $this->createQueryBuilder('p')
            ->andWhere('p.user = :userId')
            ->setParameter('userId', $user->getId())
        ;

        return $executeQuery ? $queryBuilder->getQuery()->getResult() : $queryBuilder->getQuery();
    }
1095165
public function findUserInbox(UserInterface $user): InboxInterface
    {
        /** @var InboxInterface $inbox */
        if (!$inbox = $this->repository->findOneBy(['user' => $user])) {
            $class = $this->repository->getClassName();
            $inbox = new $class();
            $inbox->setUser($user);
            $this->repository->add($inbox);
        }

        return $inbox;
    }
761122
private function serializeRestrictions(User $user)
    {
        return [
            'disabled' => !$user->isEnabled(),
            'removed' => $user->isRemoved(),
            'dates' => DateRangeNormalizer::normalize($user->getInitDate(), $user->getExpirationDate()),
        ];
    }
363722
private function getRoles(UserInterface $user, TokenInterface $token)
    {
        $roles = $user->getRoles();

        foreach ($token->getRoles(false) as $role) {
            if ($role instanceof SwitchUserRole) {
                $roles[] = $role;

                break;
            }
        }

        return $roles;
    }
317763
protected function getCoinsEntry(UserInterface $user)
    {
        $class = $this->getGameOptions()->getEntityBillingClass();
        $accEntityManager = $this->getBillingEntityManager();

        /** @var \GameBackend\Entity\CrossFire\Repository\Billing $repository */
        $repository = $accEntityManager->getRepository($class);
        return $repository->getEntry4User($user);
    }
158582
public function getQuestionnairesByUser(UserInterface $user)
    {
        $questionnaires = $this->createQueryBuilder('us')
            ->where('us.user = :user')
            ->setParameter('user', $user)
            ->getQuery()
            ->getResult();

        $resource = array();
        $now = new \DateTime();

        /** @var UserSessionInterface $questionnaire */
        foreach ($questionnaires as $questionnaire) {
            $configuration = $questionnaire->getConfiguration();

            if (!is_null($configuration->getEndAt())) {
                continue;
            }

            if ($configuration->getMaxQuestions() - $configuration->getQuestions()->count() == 0) {
                if (is_null($configuration->getStartAt()) || $configuration->getStartAt() <= $now) {
                    $resource[] = $questionnaire;
                }
            }
        }

        return $resource;
    }
1137014
protected function isCreator($subject, UserInterface $user)
    {
        return $subject instanceof BlameableInterface &&
               $subject->getCreatedBy() === $user->getUsername();
    }
366560
public function getResumableDeliveries(User $user)
    {
        $deliveryExecutionService = ServiceProxy::singleton();
        $resumable = array();
        foreach ($this->getResumableStates() as $state) {
            foreach ($deliveryExecutionService->getDeliveryExecutionsByStatus($user->getIdentifier(), $state) as $execution) {
                $delivery = $execution->getDelivery();
                if ($delivery->exists()) {
                    $resumable[] = $execution;
                }
            }
        }
        return $resumable;
    }
1014313
public function findCouponsByOrder(OrderInterface $order)
    {
        $orderCoupons = $this
            ->createQueryBuilder('oc')
            ->where('oc.order = :order')
            ->setParameter('order', $order)
            ->getQuery()
            ->getResult();

        return array_map(function (OrderCouponInterface $orderCoupon) {
            return $orderCoupon->getCoupon();
        }, $orderCoupons);
    }
458799
public function getSupportedMethods(ShippingSubjectInterface $subject): array
    {
        /** @var ShipmentInterface $subject */
        Assert::isInstanceOf($subject, ShipmentInterface::class);
        Assert::true($this->supports($subject));

        /** @var OrderInterface $order */
        $order = $subject->getOrder();

        $zones = $this->zoneMatcher->matchAll($order->getShippingAddress(), Scope::SHIPPING);
        if (empty($zones)) {
            return [];
        }

        $methods = [];

        $shippingMethods = $this->shippingMethodRepository->findEnabledForZonesAndChannel($zones, $order->getChannel());
        foreach ($shippingMethods as $shippingMethod) {
            if ($this->eligibilityChecker->isEligible($subject, $shippingMethod)) {
                $methods[] = $shippingMethod;
            }
        }

        return $methods;
    }
1255614
protected function prepareData(RequestInterface $request, User $user)
    {
        $userId = $user->getIdentifier();
        if ($userId === null) {
            $userId = get_class($user);
        }

        return [
            RequestLogService::USER_ID => $userId,
            RequestLogService::USER_ROLES => ','. implode(',', $user->getRoles()). ',',
            RequestLogService::ACTION => $request->getUri()->getPath(),
            RequestLogService::EVENT_TIME => microtime(true),
            RequestLogService::DETAILS => json_encode([
                'method' => $request->getMethod(),
                'query' => $request->getUri()->getQuery(),
            ]),
        ];
    }