private function uniqueAppKey() { do { $appKey = str_shuffle("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"); $application = $this->userRepository->findBy(array('appKey' => $appKey)); } while ($application); return $appKey; }
/** * Return a similar articles by category * @param Article $article * @return Article array */ public function getSimilarArticlesByCategory(Article $article) { $category = $article->getCategory(); $similarArticles = $this->articleRepository->findBy(array('category' => $category), array('date' => 'ASC'), 3); unset($similarArticles[array_search($article, $similarArticles)]); return $similarArticles; }
public function findByUids($uids) { if (!is_array($uids)) { $uids = [$uids]; } return parent::findBy(['uid' => $uids]); }
public function buildMainMenu(Request $request, ItemInterface $root) { $root->addChild('Messages', ['route' => 'pjax_message_index'])->getParent()->addChild('New message', ['route' => 'pjax_message_new'])->getParent(); $latests = $root->addChild('latests', ['dropdown' => true]); /** @var Message $message */ foreach ($this->messageRepository->findBy([], array(), 4) as $message) { $latests->addChild($message->getId(), ['route' => 'pjax_message_show', 'routeParameters' => ['id' => $message->getId()], 'label' => 'message ' . $message->getId()]); } return $root; }
/** * Find objects by criteria * * @param array $criteria * @param array $options * * @return array */ public function findBy($criteria = array(), $options = array()) { $limit = $options["limit"] ? $options["limit"] : null; $offset = $options["offset"] ? $options["offset"] : null; $orderBy = array(); if ($options["sort"]) { $orderBy = array($options["sort"], $options["order"]); } return $this->repository->findBy($criteria, $orderBy, $limit, $offset); }
/** * @return ResourceViewModel * * @throws ForbiddenException * @throws NotFoundException */ public function post() { if (!$this->isGranted(UserMessagePermissions::START_CONVERSATION)) { throw new ForbiddenException('User must be logged on to start a conversation'); } $values = $this->validateIncomingData(ConversationInputFilter::class); /* @var MessageUserInterface[] $user */ $users = $this->userRepository->findBy(['id' => $values['participants']]); $conversation = new GroupConversationEntity($users); $this->conversationService->create($conversation); return new ResourceViewModel(['conversation' => $conversation], ['template' => 'conversations/conversation']); }
public function accountDeleteAction() { /**@var $campaign VkCampaigns*/ /**@var $vkAd VkAds*/ /**@var $vkAccount VkAccounts*/ /**@var $cabinet Cabinets*/ $vkAccountId = (int) $this->params()->fromRoute('vk_account_id', 0); if (!$vkAccountId) { return false; } $vkAccount = $this->vkAccountsRepository->findBy(['id' => $vkAccountId]); $vkAccount = reset($vkAccount); $this->getObjectManager()->remove($vkAccount); $allCabinets = $this->cabinetsRepository->findBy(['vk_account_id' => $vkAccountId]); $allClients = $this->getObjectManager()->getRepository('\\Socnet\\Entity\\VkClients')->findBy(['bidder_account_id' => $vkAccountId]); $campaigns = $this->campaignsRepository->findBy(['vk_account_id' => $vkAccountId]); foreach ($campaigns as $campaign) { $vkAds = $this->vkAdsRepository->findBy(['campaign_id' => $campaign->getId()]); foreach ($vkAds as $vkAd) { $this->getObjectManager()->remove($vkAd); } $this->getObjectManager()->remove($campaign); } foreach ($allClients as $allClient) { $this->getObjectManager()->remove($allClient); } foreach ($allCabinets as $allCabinet) { $this->getObjectManager()->remove($allCabinet); } $this->getObjectManager()->flush(); return $this->redirect()->toRoute('home'); }
/** * Filter the `kernel.request` event to catch redirect addresses * * @param GetResponseEvent $event * * @return void */ public function onKernelRequest(GetResponseEvent $event) { if (!$event->isMasterRequest()) { // don't do anything if it's not the master request return; } $request = $event->getRequest(); $redirects = $this->redirectRepository->findBy(array('enabled' => true), array('position' => 'ASC')); /** @var Redirect $redirect */ foreach ($redirects as $redirect) { if ($destinationUrl = $this->redirectMatchesRequest($redirect, $request)) { $event->setResponse(new RedirectResponse($destinationUrl, $redirect->getType())); return; } } return; }
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) { if ($this->criteriaRequiresDql($criteria) === FALSE && $this->criteriaRequiresDql((array) $orderBy) === FALSE) { return parent::findBy($criteria, $orderBy, $limit, $offset); } $qb = $this->createQueryBuilder('e')->whereCriteria($criteria)->autoJoinOrderBy((array) $orderBy); return $qb->getQuery()->setMaxResults($limit)->setFirstResult($offset)->getResult(); }
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) { if (!isset($criteria['enabled'])) { $criteria['enabled'] = true; } return parent::findBy($criteria, $orderBy, $limit, $offset); // TODO: Change the autogenerated stub }
public function getVotesForImage(Img $image) { $votes = $this->voteRepository->findBy(array("img" => $image)); $votesSum = 0; foreach ($votes as $vote) { /** @var \Vendor\GalleryBundle\Entity\ImgVote $vote */ $votesSum += $vote->getValue(); } return $votesSum; }
/** * Finds entities by a set of criteria with automatic join on section if need due to retro-compatibility. * * @param array $criteria An array of criteria ( field => value ). * @param array|null $orderBy Optional, an array of ordering criteria ( [field => direction] ). * @param integer|null $limit Optional, the max number of results. * @param integer|null $offset Optional, The starting index of results. * * @return Page[] An array of matching pages. */ public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) { if (false === PageQueryBuilder::hasJoinCriteria($criteria) && false === PageQueryBuilder::hasJoinCriteria($orderBy)) { return parent::findBy($criteria, $orderBy, $limit, $offset); } $query = $this->createQueryBuilder('p')->addSearchCriteria($criteria); if (false === empty($orderBy)) { $query->addMultipleOrderBy($orderBy); } return $query->setMaxResults($limit)->setFirstResult($offset)->getQuery()->getResult(); }
/** * {@inheritdoc} */ public function getAll($mediaId) { $media = $this->mediaManager->getEntityById($mediaId); $fileVersion = $this->getFileVersionForMedia($media); $formatOptions = $this->formatOptionsRepository->findBy(['fileVersion' => $fileVersion]); $formatOptionsArray = []; /** @var FormatOptions $formatOptionEntity */ foreach ($formatOptions as $formatOptionEntity) { $formatOptionsArray[$formatOptionEntity->getFormatKey()] = $this->entityToArray($formatOptionEntity); } return $formatOptionsArray; }
/** * {@inheritdoc} * * @throws EntityNotFoundException */ public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) { if (!array_key_exists('deletedAt', $criteria)) { $criteria['deletedAt'] = null; } elseif ($criteria['deletedAt'] === static::IGNORE_DELETE_AT) { unset($criteria['deletedAt']); } $result = parent::findBy($criteria, $orderBy, $limit, $offset); if (empty($result)) { throw new EntityNotFoundException(); } return $result; }
/** * * @return array */ public function getAllAsArray($criteria = null) { $list = array(); if ($criteria === null) { $list = parent::findAll(); } else { if ($criteria instanceof Criteria) { $list = parent::matching($criteria); } else { $list = parent::findBy($criteria); } } $res = array(); foreach ($list as $element) { $res[$element->getId()] = $element->getName(); } return $res; }
/** * Retreives settings from repository. * * @param SettingsOwnerInterface|null $owner * * @throws \Dmishh\Bundle\SettingsBundle\Exception\UnknownSerializerException * @return array */ private function getSettingsFromRepository(SettingsOwnerInterface $owner = null) { $settings = array(); foreach (array_keys($this->settingsConfiguration) as $name) { try { $this->validateSetting($name, $owner); $settings[$name] = null; } catch (WrongScopeException $e) { continue; } } /** @var Setting $setting */ foreach ($this->repository->findBy(array('ownerId' => $owner === null ? null : $owner->getSettingIdentifier())) as $setting) { if (array_key_exists($setting->getName(), $settings)) { $settings[$setting->getName()] = $this->serializer->unserialize($setting->getValue()); } } return $settings; }
protected function paginateObject(Request $request, EntityRepository $repository, $whereCriteria = null) { $curPage = $request->getRequestUri(); $page = $request->get('page', '1'); $maxr = $request->get('maxr', '10'); $skip = ($page - 1) * $maxr; $objects = $repository->findBy([], null, $maxr, $skip); $totalObjects = count($repository->findAll()); $payload = ["payload" => $objects]; $payload['pagination']['total'] = $totalObjects; $payload['pagination']['hasNext'] = false; $payload['pagination']['hasPrev'] = false; $payload['pagination']['currentPage'] = $page; $payload['pagination']['maxRecords'] = $maxr; if ($skip + $maxr < $totalObjects) { $payload['pagination']['nextPage'] = preg_replace("/page=\\d+/i", "page=" . ($page + 1), $curPage); $payload['pagination']['hasNext'] = true; } if ($skip > 0) { $payload['pagination']['prevPage'] = preg_replace("/page=\\d+/i", "page=" . ($page - 1), $curPage); $payload['pagination']['hasPrev'] = true; } return $payload; }
/** * Returns user notifications for the given user * * @param UserInterface $user * @param int $offset * @param int $limit * * @return UserNotification[] */ public function getUserNotifications(UserInterface $user, $offset, $limit = 10) { return $this->repository->findBy(['user' => $user], ['id' => 'DESC'], $limit, $offset); }
/** * @param array $criteria * @param array $orderBy * @param integer $limit * @param integer $offset * * @return ArrayCollection|ReportPoValueInterface[] */ public function findReportPoValuesBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) { return $this->repository->findBy($criteria, $orderBy, $limit, $offset); }
/** * @param array $criteria * @param array $orderBy * @param integer $limit * @param integer $offset * * @return ArrayCollection|AlertChangeTypeInterface[] */ public function findAlertChangeTypesBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) { return $this->repository->findBy($criteria, $orderBy, $limit, $offset); }
/** * {@inheritdoc} */ public function findManyNodesByType($type, TreeInterface $tree) { return $this->repository->findBy(array('tree' => $tree, 'type' => $type)); }
/** * @param array $criteria * @param array $orderBy * @param integer $limit * @param integer $offset * * @return ArrayCollection|UserMadeReminderInterface[] */ public function findUserMadeRemindersBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) { return $this->repository->findBy($criteria, $orderBy, $limit, $offset); }
/** * {@inheritdoc} */ public function findBy(array $criteria, array $orderBy = ['label' => 'ASC'], $limit = null, $offset = null) { return parent::findBy($criteria, $orderBy, $limit, $offset); }
/** * @param array $criteria * @param array $orderBy * @param integer $limit * @param integer $offset * * @return ArrayCollection|SessionLearningMaterialInterface[] */ public function findSessionLearningMaterialsBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) { return $this->repository->findBy($criteria, $orderBy, $limit, $offset); }
/** * @param array $criteria * @param array $orderBy * @param integer $limit * @param integer $offset * * @return ArrayCollection|MeshUserSelectionInterface[] */ public function findMeshUserSelectionsBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) { return $this->repository->findBy($criteria, $orderBy, $limit, $offset); }
/** * {@inheritdoc} */ public function findManyTranslationsByNode(NodeInterface $node) { return $this->repository->findBy(array('node' => $node)); }
/** * Find By * * @param array $criteria * @param array $orderBy * @param null $limit * @param null $offset * * @return array */ public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) { $criteria = array_merge($criteria, array("deleted" => false)); return parent::findBy($criteria, $orderBy, $limit, $offset); }
function it_should_perform_search_query(ManagerRegistry $registry, EntityManager $em, EntityRepository $repo) { $query = ['foo' => 'bar']; $result = [['id' => 1, 'foo' => 'bar']]; $repo->findBy($query)->willReturn($result); $em->getRepository('foo')->willReturn($repo); $registry->getManager(null)->willReturn($em); $this->setRegistry($registry); $this->query($query)->shouldBe($result); }
/** * Get data by certain criteria */ public function getBy() { return $this->getConvertService()->objectCollectionToArray($this->nanoEntity->findBy($this->getQueryFromRequest(false))); }
/** * @param array $criteria * @param array $orderBy * @param integer $limit * @param integer $offset * * @return ArrayCollection|InstructionHoursInterface[] */ public function findInstructionHoursesBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) { return $this->repository->findBy($criteria, $orderBy, $limit, $offset); }