public function getMenu() { $criteria = new Criteria(); $criteria->orderBy(['hierarchy' => 'asc']); $criteria->andWhere($criteria->expr()->eq('parent', null)); return $this->adminMenuRepository->matching($criteria); }
/** * view the property selected, if tenant ask for more informations, as him to register * @return ViewModel */ public function visualizaAction() { //save new tenant or get the tenant prior registered if ($this->getRequest()->isPost()) { //getting posible tenant prior registered $criterio = new Criteria(); $criterio->where($criterio->expr()->eq('nome', $this->getRequest()->getPost('nome')))->andWhere($criterio->expr()->eq('email', $this->getRequest()->getPost('email')))->andWhere($criterio->expr()->eq('foneCelular', $this->getRequest()->getPost('telefone'))); $locatario = $this->getEm()->getRepository('MyClasses\\Entities\\Locatario')->matching($criterio); //if quantity of tenants by criteria above is zero... if (!$locatario->count()) { //...register new tenant... $locatario = new Locatario(); $locatario->setNome($this->getRequest()->getPost('nome')); $locatario->setEmail($this->getRequest()->getPost('email')); $locatario->setFoneCelular($this->getRequest()->getPost('telefone')); $this->getEm()->persist($locatario); $this->getEm()->flush(); //...else, get the tenant prior registered } else { $locatario = $locatario->first(); } $this->sessao->locatario = $locatario; } //get the property and send to view if ($this->Params('id')) { $imovel = $this->getEm()->getRepository("MyClasses\\Entities\\Imovel")->find($this->Params('id')); return new ViewModel(array('imovel' => $imovel, 'mais' => $this->Params('mais'), 'locatario' => $this->sessao->locatario)); } }
/** * Returns the report's criteria * * @param ReportConfiguration $configuration * * @return Criteria */ protected function getCriteria(ReportConfiguration $configuration) { $criteria = new Criteria(); $criteria->where($criteria->expr()->gte('createdAt', $configuration->getStartDate())); $criteria->andWhere($criteria->expr()->lte('createdAt', $configuration->getEndDate())); return $criteria; }
public function getProductReviews(ProductInterface $product) : Collection { $criteria = new Criteria(); $criteria->where($criteria->expr()->eq('product', $product)); $criteria->andWhere($criteria->expr()->eq('enabled', true)); return $this->matching($criteria); }
private function findPreviousOrdersToday() : Collection { $today = Carbon::now()->startOfDay(); $criteria = new Criteria(); $criteria->where($criteria->expr()->gte('updatedAt', $today)); $criteria->andWhere($criteria->expr()->eq('confirmed', true)); return $this->orderRepository->matching($criteria); }
public function resolve(int $currentShopId, string $url) : ShopInterface { $criteria = new Criteria(); $criteria->where($criteria->expr()->eq('id', $currentShopId)); $criteria->orWhere($criteria->expr()->eq('url', $url)); $criteria->orWhere($criteria->expr()->gte('id', 1)); return $this->matching($criteria)->first(); }
/** * list the projects * @return \Zend\View\Model\ViewModel */ public function indexAction() { $usuario = $this->getEm()->getRepository('MyClasses\\Entities\\AclUsuario')->findOneBy(array("id" => $this->identity()[0]->getId())); if ($this->identity()[1] == "adm") { $criterio = new Criteria(); $criterio->where($criterio->expr()->eq('usuario', $usuario))->orWhere($criterio->expr()->isNull('usuario')); $projetos = $this->getEm()->getRepository('MyClasses\\Entities\\Projeto')->matching($criterio); } else { $projetos = $usuario->getProjetos(); } return new ViewModel(array('projetos' => $projetos)); }
/** * @param DataStructure\Query\Query $queries * * @return mixed */ public function query(DataStructure\Query\Query $queries) { $logicFunc = 'andWhere'; if ($queries instanceof DataStructure\OrQuery) { $logicFunc = 'orWhere'; } foreach ($queries as $query) { if ($this->isExcludedProperty($query->getProperty())) { continue; } $value = $this->unlockSpecialProperty($query->getProperty(), $query->getValue()); if ($query instanceof Expression\Equal) { $this->criteria->{$logicFunc}(Criteria::expr()->eq($query->getProperty(), $value)); } elseif ($query instanceof Expression\NotEqual) { $this->criteria->{$logicFunc}(Criteria::expr()->neq($query->getProperty(), $value)); } elseif ($query instanceof Expression\GreaterThan) { $this->criteria->{$logicFunc}(Criteria::expr()->gt($query->getProperty(), $value)); } elseif ($query instanceof Expression\GreaterThanEqual) { $this->criteria->{$logicFunc}(Criteria::expr()->gte($query->getProperty(), $value)); } elseif ($query instanceof Expression\LesserThan) { $this->criteria->{$logicFunc}(Criteria::expr()->lt($query->getProperty(), $value)); } elseif ($query instanceof Expression\LesserThanEqual) { $this->criteria->{$logicFunc}(Criteria::expr()->lte($query->getProperty(), $value)); } elseif ($query instanceof Expression\In) { $this->criteria->{$logicFunc}(Criteria::expr()->in($query->getProperty(), $value)); } elseif ($query instanceof Expression\NotIn) { $this->criteria->{$logicFunc}(Criteria::expr()->notIn($query->getProperty(), $query->getValue())); } } }
/** * @Rest\View * @Rest\Get("/goals") */ public function getGoalsAction(Request $request) { $user_id = $request->get('user_id'); if ($user_id == 0) { $user = $this->container->get('security.context')->getToken()->getUser(); } else { $user = $this->getDoctrine()->getRepository('AcmeUserBundle:User')->find($user_id); } if (!$user) { throw $this->createNotFoundException('user.not_found'); } /** @var $user User */ $goals = $user->getGoals()->matching(Criteria::create()->where(Criteria::expr()->eq('isDeleted', 0))); if ($user_id != 0 && $user != $this->container->get('security.context')->getToken()->getUser()) { $goals = $goals->matching(Criteria::create()->where(Criteria::expr()->eq('isPrivate', 0))); } $response = []; foreach ($goals as $goal) { $oneGoal = ['title' => $goal->getName(), 'id' => $goal->getId()]; $oneGoal['actions'] = []; $oneGoal['images'] = []; foreach ($goal->getImages() as $image) { $oneGoal['images'][] = ['webPath' => $image->getWebPath()]; } foreach ($goal->getActions() as $action) { $oneGoal['actions'][] = ['title' => $action->getTitle()]; } $response[] = $oneGoal; } return $response; }
/** * @param User $user * @param int $limit * @return Collection|Game[] */ public function findAvailableForUser(User $user, $limit) { $criteria = new Criteria(); $expr = Criteria::expr(); $criteria->where($expr->neq('user1', $user))->andWhere($expr->isNull('user2'))->setMaxResults($limit)->orderBy(['id' => 'DESC']); return $this->matching($criteria); }
public function subactionComplete(SubactionProgressEvent $event, $name, EventDispatcher $dispatcher) { $action = $event->getSubaction()->getAction(); $user = $event->getUser(); $userAction = $this->em->getRepository('AcmeEdelaBundle:UserAction')->findOneBy(array('user' => $user, 'action' => $action)); $userTime = $user->getCurrentDateTime(); $dayStart = clone $userTime; $dayFinish = clone $userTime; $dayStart->modify('today midnight'); $dayFinish->modify('tomorrow midnight'); $existingProgress = $this->em->getRepository('AcmeEdelaBundle:UserActionProgress')->matching(Criteria::create()->where(Criteria::expr()->eq('userAction', $userAction))->andWhere(Criteria::expr()->gte('createdAt', $dayStart))->andWhere(Criteria::expr()->lte('createdAt', $dayFinish))); $dispatch = null; if (!$existingProgress->count() && $action->getSubactions()->count() == count($this->em->getRepository('AcmeEdelaBundle:Action')->getSubactions($action->getId(), $user, null, true))) { $progress = new UserActionProgress(); $progress->setUserAction($userAction); $progress->setResult(1); $this->em->persist($progress); $dispatch = true; } elseif ($existingProgress->count()) { $this->em->remove($existingProgress->first()); $dispatch = false; } $this->em->flush(); if ($dispatch !== null) { $event = new ActionEvent($action, $user, $dispatch); $dispatcher->dispatch($this->completeEvent, $event); } }
/** * @Rest\View * @Rest\Get("/payment/history") */ public function getPaymentsHistoryAction(Request $request) { /** @var User $currentUser */ $currentUser = $this->container->get('security.context')->getToken()->getUser(); $transactions = $currentUser->getTransactions()->matching(Criteria::create()->where(Criteria::expr()->eq('isProcessed', 1))); return $transactions; }
/** * Confirm email * * @return \Zend\Http\Response */ public function confirmAction() { $confirm = $this->params('confirm'); try { if (!$confirm) { //$this->getResponse()->setStatusCode(404); throw new \Exception('Invalid confirmation code'); } /** * @var \Doctrine\ORM\EntityManager $objectManager */ $objectManager = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager'); /** @var \User\Entity\User $user */ $user = $objectManager->getRepository('User\\Entity\\User')->findOneBy(array('confirm' => $confirm)); if (!$user) { throw new \Exception('Invalid confirmation code'); } $user->activate(); $objectManager->persist($user); $objectManager->flush(); $criteria = Criteria::create()->where(Criteria::expr()->eq('provider', 'equals')); $user->getAuths()->matching($criteria)->first()->login($this->getServiceLocator()); $this->flashMessenger()->addSuccessMessage("You've successfully activated your account"); } catch (\Exception $exception) { $this->flashMessenger()->addErrorMessage($exception->getMessage()); } return $this->redirect()->toRoute('home'); }
/** * @param array $criteria * @param null $order * @param null $limit * @param null $offset * * @return static[] */ public static function loadWhere(array $criteria, $order = null, $limit = null, $offset = null) { $crit = Criteria::create(); if ($order) { $crit->orderBy($order); } $crit->setMaxResults($limit); $crit->setFirstResult($offset); foreach ($criteria as $k => $v) { if ($v instanceof Criteria) { $crit->andWhere($crit->getWhereExpression()); } elseif ($v instanceof Expression) { $crit->andWhere($v); } elseif (is_array($v)) { $expr = Criteria::expr(); $crit->andWhere($expr->andX($expr->in($k, $v))); } else { $expr = Criteria::expr(); $crit->andWhere($expr->andX($expr->eq($k, $v))); } } $entities = static::getEntityManager()->getRepository(get_called_class())->matching($crit)->toArray(); foreach ($entities as $entity) { /** * @var $entity static */ $entity->setExists(true); $entity->setPersistedData(call_user_func('get_object_vars', $entity)); } return $entities; }
/** * {@inheritdoc} */ public function getOfferingsForTeachingReminders($daysInAdvance) { $now = time(); $startDate = new \DateTime(); $startDate->setTimezone(new \DateTimeZone('UTC')); $startDate->setTimestamp($now); $startDate->modify("midnight +{$daysInAdvance} days"); $daysInAdvance++; $endDate = new \DateTime(); $endDate->setTimezone(new \DateTimeZone('UTC')); $endDate->setTimestamp($now); $endDate->modify("midnight +{$daysInAdvance} days"); $criteria = Criteria::create(); $expr = Criteria::expr(); $criteria->where($expr->andX($expr->eq('deleted', 0), $expr->gte('startDate', $startDate), $expr->lt('startDate', $endDate))); $offerings = $this->getRepository()->matching($criteria); // filter out any offerings belonging to unpublished events // and with deleted parentage $offerings->filter(function (OfferingInterface $offering) { $session = $offering->getSession(); $course = $session->getCourse(); $publishEvent = $offering->getSession()->getPublishEvent(); $school = $course->getSchool(); return isset($publishEvent) && isset($school) && !$session->isDeleted() && !$course->isDeleted(); }); return $offerings; }
/** * @Rest\View * @Rest\Get("/profile/short") */ public function getShortProfileAction(Request $request) { /** @var User $currentUser */ $currentUser = $this->container->get('security.context')->getToken()->getUser(); $em = $this->getDoctrine()->getManager(); return ['id' => $currentUser->getId(), 'name' => $currentUser->getFullname(), 'exp' => $currentUser->getExpBill(), 'total_exp' => $currentUser->getExpTotal(), 'bill' => $currentUser->getBill(), 'available_dayoffs' => $em->getRepository('AcmeUserBundle:User')->getAvailableDayoffs($currentUser), 'notifications' => $currentUser->getNotifications()->matching(Criteria::create()->where(Criteria::expr()->isNull('readAt')))]; }
public function createService(ServiceLocatorInterface $serviceLocator) { $entityManager = $serviceLocator->get('entity-manager'); $languageEntity = $serviceLocator->get('lang-entity'); $criteria = new Criteria(); $criteria->where($criteria->expr()->gt('status', 0))->orderBy(['status' => Criteria::DESC]); $language = new \Application\Service\Invokable\Language(); $languageClassName = get_class($languageEntity); $activeLanguages = $entityManager->getRepository($languageClassName)->matching($criteria); $language->setActiveLanguages($activeLanguages); $defaultLanguage = $entityManager->getRepository($languageClassName)->findOneByStatus(Lang::STATUS_DEFAULT); $defaultLanguage = $defaultLanguage ?: new Lang(); $language->setDefaultLanguage($defaultLanguage); $request = $serviceLocator->get('Request'); $router = $serviceLocator->get('Router'); $match = $router->match($request); if ($match) { $matchedLangIso = $match->getParam('lang', $defaultLanguage->getIsoCode()); if ($matchedLangIso) { $currentLanguage = $entityManager->getRepository($languageClassName)->findOneByIsoCode($matchedLangIso); } } $currentLanguage = isset($currentLanguage) ? $currentLanguage : new Lang(); $language->setCurrentLanguage($currentLanguage); return $language; }
public function indexAction() { $viewmodel = new ViewModel(); $return = array(); if ($this->flashMessenger()->hasErrorMessages()) { $return['error'] = $this->flashMessenger()->getErrorMessages(); } if ($this->flashMessenger()->hasSuccessMessages()) { $return['success'] = $this->flashMessenger()->getSuccessMessages(); } $this->flashMessenger()->clearMessages(); $objectManager = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager'); $criteria = Criteria::create()->andWhere(Criteria::expr()->isNull('parent')); $criteria->orderBy(array("place" => Criteria::ASC)); $rootcategories = $objectManager->getRepository('Application\\Entity\\Category')->matching($criteria); $subcategories = array(); foreach ($rootcategories as $category) { $criteria = Criteria::create()->andWhere(Criteria::expr()->eq('parent', $category)); $criteria->orderBy(array("place" => Criteria::ASC)); $subcategories[$category->getId()] = $objectManager->getRepository('Application\\Entity\\Category')->matching($criteria); } $events = array(); $models = array(); $fields = array(); foreach ($objectManager->getRepository('Application\\Entity\\Category')->findAll() as $cat) { $models[$cat->getId()] = count($objectManager->getRepository('Application\\Entity\\PredefinedEvent')->findBy(array('category' => $cat->getId(), 'parent' => null))); $fields[$cat->getId()] = count($objectManager->getRepository('Application\\Entity\\CustomField')->findBy(array('category' => $cat->getId()))); } $viewmodel->setVariables(array('categories' => $rootcategories, 'subcategories' => $subcategories, 'events' => $events, 'models' => $models, 'fields' => $fields, 'messages' => $return)); $this->layout()->title = "Personnalisation > Catégories"; return $viewmodel; }
/** * generates the suggestion entries for an given date and user * * @param EntityManager $manager * @param \DateTime $currentDate * @param User $user * * @return array|\TrainingScheduleBundle\Entity\Training[] */ public static function generateOwnTrainingSuggestion(EntityManager $manager, \DateTime $currentDate, User $user) { // last weekday is the given date minus 7 weekdays $currentDate = $currentDate->setTime(0, 0, 0); $currentTmp = new \DateTime($currentDate->format("d-m-Y")); $minusSeven = new \DateTime($currentDate->format("d-m-Y")); $minusSeven = $minusSeven->modify('-7 day'); // find the given trainingsDay if exist /** @var TrainingDayRepository $trainingDayRepository */ $trainingDayRepository = $manager->getRepository('TrainingScheduleBundle:TrainingDay'); $expr = Criteria::expr(); $criteria = Criteria::create(); $criteria->where($expr->gte('date', $minusSeven)); $criteria->andWhere($expr->lte('date', $currentTmp)); $criteria->andWhere($expr->eq('user', $user)); /** @var LazyCriteriaCollection $trainingDays */ $trainingDays = $trainingDayRepository->matching($criteria); count($trainingDays); if ($trainingDays == null) { return array(); } $result = array(); foreach ($trainingDays as $trainingDay) { foreach ($trainingDay->getTrainings() as $training) { if (count($result) <= 6) { $result[] = $training; } } } /** @var Training[] $trainings */ return $result; }
/** * setup form * * * @access public * @param string $name ,default is null * @param array $options ,default is null */ public function __construct($name = null, $options = null) { $this->query = $options['query']; unset($options['query']); $this->organizationType = $options['organizationType']; unset($options['organizationType']); parent::__construct($name, $options); $this->setAttribute('class', 'form form-horizontal'); $types = array(); $atcTypes = array(Role::PROCTOR_ROLE, Role::TEST_CENTER_ADMIN_ROLE); $atpTypes = array(Role::TRAINING_MANAGER_ROLE); if ($this->organizationType === Organization::TYPE_ATC) { $types = $atcTypes; } elseif ($this->organizationType === Organization::TYPE_ATP) { $types = $atpTypes; } else { $types = array_merge($atpTypes, $atcTypes); } $this->add(array('name' => 'user', 'type' => 'DoctrineModule\\Form\\Element\\ObjectSelect', 'attributes' => array('class' => 'form-control chosen-select', 'required' => 'required'), 'options' => array('label' => 'User', 'object_manager' => $this->query->entityManager, 'target_class' => 'Users\\Entity\\User', 'property' => 'fullName', 'is_method' => true, 'find_method' => array('name' => 'findBy', 'params' => array('criteria' => array())), 'display_empty_item' => true, 'empty_item_label' => self::EMPTY_SELECT_VALUE))); $criteria = Criteria::create(); $expr = Criteria::expr(); if (count($types) > 0) { $criteria->andWhere($expr->in("name", $types)); } $this->add(array('name' => 'role', 'type' => 'DoctrineModule\\Form\\Element\\ObjectSelect', 'attributes' => array('class' => 'form-control', 'required' => 'required'), 'options' => array('label' => 'Role', 'object_manager' => $this->query->entityManager, 'target_class' => 'Users\\Entity\\Role', 'property' => 'name', 'is_method' => false, 'find_method' => array('name' => 'matching', 'params' => array('criteria' => $criteria)), 'display_empty_item' => true, 'empty_item_label' => self::EMPTY_SELECT_VALUE))); $this->add(array('name' => 'organization', 'type' => 'Zend\\Form\\Element\\Hidden')); $this->add(array('name' => 'id', 'type' => 'Zend\\Form\\Element\\Hidden')); $this->add(array('name' => 'Create', 'type' => 'Zend\\Form\\Element\\Submit', 'attributes' => array('class' => 'btn btn-success', 'value' => 'Add'))); $this->add(array('name' => 'reset', 'type' => 'Zend\\Form\\Element', 'attributes' => array('class' => 'btn btn-danger resetButton', 'value' => 'Reset', 'type' => 'button'))); }
/** * @Route("/wotr/test/{id}") * @ParamConverter("post", class="WotRBundle:Game", options={"repository_method" = "getCurrentGame"}) * @param Game $game * @param Request $request * @return \Symfony\Component\HttpFoundation\RedirectResponse|Response */ public function testAction(Game $game, Request $request) { $em = $this->getDoctrine()->getManager(); // $startNations = $em->getRepository('WotRBundle:NationDetails') // ->findAll(); // foreach( $startNations as $sN ) { // $n = new NationCopy($sN,$game); // $em->persist($n); // } // $em->flush(); // exit(); $nations = $game->getNations(); // foreach( $nations as $n ) // { // echo $n->getId(); // } // // $nations->filter( // function ($n) { // return $n->getName() == 'Dwarves'; // } // ); // $c = Criteria::create(); $e = Criteria::expr(); $c->where($e->eq('name', 'Dwarves')); $nations = $nations->matching($c); /** @var Nation $n */ foreach ($nations as $n) { echo $n->getName(); } return new Response('<body>Test</body>'); }
public function findByTag($tagstring) { $criteria = new Criteria(); $criteria->andWhere(Criteria::expr()->contains('t.name', "%" . $tagstring . "%")); $queryBuilder = $this->_em->createQueryBuilder()->select('p')->distinct(true)->from($this->getEntityName(), "p")->leftJoin('Product\\Entity\\ProductTags', 'pt', \Doctrine\ORM\Query\Expr\Join::WITH, 'p.id = pt.idProduct')->leftJoin('Product\\Entity\\Tags', 't', \Doctrine\ORM\Query\Expr\Join::WITH, 't.id = pt.idTag')->addCriteria($criteria)->orderBy("p.creationdate", "ASC")->getQuery(); return $queryBuilder->getArrayResult(); }
public function testUsersWithFacebookLogin() { $criteria = new Criteria(); $criteria->where($criteria->expr()->neq('facebook_id', null)); $users = $this->getUserRepository()->matching($criteria); $this->assertCount(8, $users); }
/** * * @param \DateTime $startDate beginning >= * @param \DateTime $endDate end <= * @param $type - type of the StatisticEntryFilter * * @return StatisticEntry[] * * Note: can be replaced with DQL if performance issues are notable */ public function getStatisticForRangeAndType(\DateTime $startDate, \DateTime $endDate, $type = null) { /** @var TrainingDayRepository $trainingDayRepository */ $trainingDayRepository = $this->manager->getRepository('TrainingScheduleBundle:TrainingDay'); $expr = Criteria::expr(); $criteria = Criteria::create(); $criteria->where($expr->gte('date', $startDate)); $criteria->andWhere($expr->lte('date', $endDate)); $criteria->andWhere($expr->eq('user', $this->userToken->getUser())); /** @var LazyCriteriaCollection $trainingDays */ $trainingDays = $trainingDayRepository->matching($criteria); $result = array(); /** @var TrainingDay $trainingDay * */ foreach ($trainingDays as $trainingDay) { foreach ($trainingDay->getStatistics() as $statistic) { /** @var StatisticEntry $statistic */ if ($type != null) { if ($statistic->getName() === $type) { $result[] = $statistic; } } else { $result[] = $statistic; } } } return $result; }
/** * Returns the context for the given email * * @param Email $email * * @return array */ public function getEmailContext(Email $email) { $criteria = Criteria::create(); $criteria->andWhere(Criteria::expr()->eq('id', $email->getId())); $qb = $this->activityManager->getActivityTargetsQueryBuilder($this->class, $criteria); if (null === $qb) { return []; } $result = $qb->getQuery()->getResult(); if (empty($result)) { return $result; } $currentUser = $this->securityFacade->getLoggedUser(); $currentUserClass = ClassUtils::getClass($currentUser); $currentUserId = $currentUser->getId(); $result = array_values(array_filter($result, function ($item) use($currentUserClass, $currentUserId) { return !($item['entity'] === $currentUserClass && $item['id'] == $currentUserId); })); foreach ($result as &$item) { $route = $this->configManager->getEntityMetadata($item['entity'])->getRoute(); $item['entityId'] = $email->getId(); $item['targetId'] = $item['id']; $item['targetClassName'] = $this->entityClassNameHelper->getUrlSafeClassName($item['entity']); $item['icon'] = $this->configManager->getProvider('entity')->getConfig($item['entity'])->get('icon'); $item['link'] = $route ? $this->router->generate($route, ['id' => $item['id']]) : null; unset($item['id'], $item['entity']); } return $result; }
public function testLteDateComparison() { $this->loadFixture(); $repository = $this->_em->getRepository('Doctrine\\Tests\\Models\\Generic\\DateTimeModel'); $dates = $repository->matching(new Criteria(Criteria::expr()->lte('datetime', new \DateTime('today')))); $this->assertEquals(2, count($dates)); }
/** * @Rest\View * @Rest\Patch("/tools/{id}") */ public function updateToolAction($id, Request $request) { /** @var $currentUser User */ $currentUser = $this->container->get('security.context')->getToken()->getUser(); $em = $this->getDoctrine()->getManager(); /** @var $tool Tool */ $tool = $em->find('AcmeEdelaBundle:Tool', $id); if (!$tool) { return $this->createNotFoundException(); } $userTool = $tool->getUserTools()->matching(Criteria::create()->where(Criteria::expr()->eq('user', $currentUser)))->first(); if (!$userTool) { $userTool = new UserTool(); $userTool->setUser($currentUser)->setTool($tool); } if ($request->get('is_enabled')) { if ($userTool->getIsAvailable() || !$tool->getCost() && $currentUser->getLevel() > $tool->getMinLevel()) { $userTool->setIsAvailable(true); $currentEnable = $userTool->getIsEnabled(); $userTool->setIsEnabled(!$currentEnable); } } if ($request->get('buy_exp')) { if (!$userTool->getIsAvailable() && $currentUser->getExpBill() >= $tool->getCost() && $currentUser->getLevel() >= $tool->getMinLevel()) { $em->getRepository('AcmeUserBundle:User')->spendExp($currentUser, $tool->getCost()); $userTool->setIsAvailable(true); } } $em->persist($userTool); $em->flush(); $serializer = $this->get('jms_serializer'); $toolArray = json_decode($serializer->serialize($tool, 'json'), true); $userToolArray = json_decode($serializer->serialize($userTool, 'json'), true); return ['success' => true, 'data' => array_merge($toolArray, $userToolArray)]; }
/** * {@inheritdoc} */ public function listAllByUserAndPeriod(User $user, Period $period) { $criteria = Criteria::create(); $expr = Criteria::expr(); $criteria->where($expr->andX($expr->eq('user', $user), $expr->gte('dateStarted', $period->getBegin()), $expr->lte('dateStarted', $period->getEnd()))); $workLogs = $this->matching($criteria); return $workLogs; }
/** * @param string $username * @return User | null */ public function getUserByUsername(string $username, $hydrate = true) { $criteria = Criteria::create(); $expr = Criteria::expr(); $criteria->where($expr->eq('username', $username)); $users = $this->getAll($criteria, $hydrate); return $users->getNextElement(); }
public function testGetEventListByTimeIntervalQueryBuilderWithAdditionalFiltersAsCriteria() { /** @var CalendarEventRepository $repo */ $repo = $this->em->getRepository('OroCalendarBundle:CalendarEvent'); $qb = $repo->getEventListByTimeIntervalQueryBuilder(1, new \DateTime(), new \DateTime(), false, new Criteria(Criteria::expr()->eq('allDay', true))); $this->assertEquals('SELECT c.id as calendar, e.id, e.title, e.description, e.start, e.end, e.allDay, e.createdAt, e.updatedAt' . ' FROM Oro\\Bundle\\CalendarBundle\\Entity\\CalendarEvent e' . ' INNER JOIN e.calendar c' . ' WHERE e.allDay = :allDay AND c.id = :id' . ' AND (' . '(e.start < :start AND e.end >= :start) OR ' . '(e.start <= :end AND e.end > :end) OR' . '(e.start >= :start AND e.end < :end))' . ' ORDER BY c.id, e.start ASC', $qb->getQuery()->getDQL()); $this->assertTrue($qb->getQuery()->getParameter('allDay')->getValue()); }