findOneBy() public method

public findOneBy ( array $criteria, array $orderBy = null )
$criteria array
$orderBy array
Example #1
0
 public function actionImage()
 {
     if (substr($this->url, 0, 7) === self::DIRECTORY_CACHE . '/') {
         $this->cached = true;
         $this->url = substr($this->url, 7);
     }
     if (($entity = $this->fileRepository->findOneBy(array('path' => $this->url))) === null) {
         throw new \Nette\Application\BadRequestException(sprintf('File \'%s\' does not exist.', $this->url));
     }
     $image = Image::fromFile($entity->getFilePath());
     $this->session->close();
     // resize
     if ($this->size && $this->size !== 'default') {
         if (strpos($this->size, 'x') !== false) {
             $format = explode('x', $this->size);
             $width = $format[0] !== '?' ? $format[0] : null;
             $height = $format[1] !== '?' ? $format[1] : null;
             $image->resize($width, $height, $this->format !== 'default' ? $this->format : Image::FIT);
         }
     }
     if (!$this->type) {
         $this->type = substr($entity->getName(), strrpos($entity->getName(), '.'));
     }
     $type = $this->type === 'jpg' ? Image::JPEG : $this->type === 'gif' ? Image::GIF : Image::PNG;
     $file = sprintf('%s/%s/%s/%s/%s/%s', $this->cacheDir, self::DIRECTORY_CACHE, $this->size, $this->format, $this->type, $entity->getPath());
     $dir = dirname($file);
     umask(00);
     @mkdir($dir, 0777, true);
     $image->save($file, 90, $type);
     $image->send($type, 90);
 }
 /**
  * @inheritdoc
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     ini_set('memory_limit', '4G');
     $lang = $input->getArgument(self::LANGUAGE_ARGUMENT);
     /** @var Language $language */
     if (($language = $this->languagesRepository->findOneBy(['shortCode' => $lang])) === NULL) {
         $output->writeln("<error>Unknown language {$lang} given!");
         return 1;
     }
     $index = $this->elastic->getIndex('dwarf');
     $type = $index->getType($language->getShortCode() . '_screenplay');
     /** @var Season[] $seasons */
     $seasons = $this->seasonsRepository->findBy(['language' => $language]);
     foreach ($seasons as $season) {
         $output->writeln("Importing season {$season->getNumber()}...");
         foreach ($season->getEpisodes() as $episode) {
             foreach ($episode->getScenarios() as $screenplay) {
                 if ($screenplay->getCharacter() !== NULL) {
                     $document = new Document($screenplay->getId(), ['text' => $screenplay->getText(), 'episode' => ['id' => $episode->getId(), 'number' => $episode->getNumber(), 'name' => $episode->getName(), 'slug' => $episode->getSlug()], 'season' => ['id' => $season->getId(), 'number' => $season->getNumber()], 'character' => ['name' => $screenplay->getCharacter()->getName(), 'slug' => $screenplay->getCharacter()->getSLug()], 'line' => $screenplay->getLine()], $type, $index);
                     $type->addDocument($document);
                 }
             }
         }
     }
 }
Example #3
0
 /**
  * @param \Nette\Application\UI\Form $form
  * @param string $resetKey
  */
 protected function save(Form $form, $resetKey)
 {
     $user = $this->userRepository->findOneBy(array('resetKey' => $resetKey));
     $user->removeResetKey($resetKey);
     $user->setPassword($form['password']->getValue());
     $this->entityManager->flush();
     $this->securityManager->sendNewPassword($user);
 }
Example #4
0
 /**
  * @param \Nette\Application\UI\Form $form
  * @param callable $resetLinkCallback
  */
 protected function save(Form $form, $resetLinkCallback)
 {
     /** @var \Venne\Security\User $user */
     $user = $this->userRepository->findOneBy(array('email' => $form['email']->value));
     if (!$user) {
         $form->addError($form->getTranslator()->translate('User with email %email% does not exist.', null, array('email' => $form['email']->value)));
         return;
     }
     $key = $user->resetPassword();
     $url = Callback::invoke($resetLinkCallback, $key);
     $this->entityManager->persist($user);
     $this->entityManager->flush($user);
     $this->securityManager->sendRecoveryUrl($user, $url);
 }
Example #5
0
 /**
  * Finds an entity by criteria array.
  * @param array $criteria
  * @param array $orderBy
  * @return object
  * @throws IOException
  */
 public function findOneBy(array $criteria, array $orderBy = null)
 {
     $result = parent::findOneBy($criteria, $orderBy);
     if ($result === NULL) {
         throw new IOException('Not found', 404);
     }
     return $result;
 }
Example #6
0
 /**
  * @param string[] $credentials
  * @return \Nette\Security\Identity
  */
 public function authenticate(array $credentials)
 {
     list($username, $password) = $credentials;
     /** @var User $user */
     $user = $this->userRepository->findOneBy(array('email' => $username, 'published' => 1));
     if (!$user) {
         throw new AuthenticationException('The username is incorrect.', self::IDENTITY_NOT_FOUND);
     }
     if (!$user->verifyByPassword($password)) {
         throw new AuthenticationException('The password is incorrect.', self::INVALID_CREDENTIAL);
     }
     if ($user->needsRehash()) {
         $user->setPassword($password);
         $this->entityManager->flush($user);
     }
     return new Identity($user->getId(), $user->getRoles(), array('email' => $user->getEmail()));
 }
 public function addSongFromCLI(\SplFileInfo $file, string $genreName = null)
 {
     if (isset($this->genreCache[$genreName])) {
         $genreId = $this->genreCache[$genreName];
     } else {
         $genreId = $this->genresRepository->findOneBy(['name' => $genreName])->getId();
         $this->genreCache[$genreName] = $genreId;
     }
     $this->addSong(File::fromSplFileInfo($file), $genreId, true);
 }
Example #8
0
 public function loadState(array $params)
 {
     parent::loadState($params);
     if (isset($params['key'])) {
         $this->resetUser = $this->userRepository->findOneBy(array('resetKey' => $params['key']));
         if ($this->resetUser === null) {
             $this->onError($this, new ResetKeyNotFoundException());
         }
     }
 }
Example #9
0
 /**
  * @param string $type
  * @param string|null $action
  * @param string|null $message
  * @return \Venne\Notifications\NotificationType
  */
 private function getTypeEntity($type, $action = null, $message = null)
 {
     if (($typeEntity = $this->typeRepository->findOneBy(array('type' => $type, 'action' => $action, 'message' => $message))) === null) {
         $typeEntity = new NotificationType();
         $typeEntity->type = $type;
         $typeEntity->action = $action;
         $typeEntity->message = $message;
         $this->entityManager->persist($typeEntity);
         $this->entityManager->flush($typeEntity);
     }
     return $typeEntity;
 }
 /**
  * @param AMQPMessage $message
  * @return bool
  */
 public function process(AMQPMessage $message)
 {
     $ids = Json::decode((string) $message->body, Json::FORCE_ARRAY);
     /** @var Screenplay[] $documents */
     $documents = [];
     foreach ($ids as $id) {
         /** @var Screenplay|NULL $screenplay */
         $screenplay = $this->scenariosRepository->find($id);
         if ($screenplay === NULL) {
             $this->onError("Screenplay with ID #{$id} not found!");
             return FALSE;
         }
         $documents[] = $this->createDocument($screenplay);
     }
     /** @var Index $indexEntity */
     $indexEntity = $this->indicesRepository->findOneBy([], ['createdAt' => 'DESC']);
     $index = $this->client->getIndex($indexEntity->getName());
     $type = $index->getType('screenplay');
     $type->addDocuments($documents);
     return TRUE;
 }
 /**
  * @param array $street
  * @param PartCity $partCity
  */
 protected function parseStreet($street, PartCity $partCity)
 {
     $code = isset($street['kod']) ? (string) $street['kod'] : NULL;
     $title = isset($street['nazev']) ? (string) $street['nazev'] : NULL;
     $street = $this->streetRepository->findOneBy(['code' => $code, 'partCity' => $partCity]);
     if (!$street) {
         $street = new Street();
         $street->code = $code;
     }
     $street->title = $title;
     $street->partCity = $partCity;
     $this->em->persist($street);
     $this->em->flush();
 }
Example #12
0
 public function loadState(array $params)
 {
     if (isset($params['registration'])) {
         $this->registration = $this->registrationRepository->findOneBy(array('id' => $params['registration'], 'enabled' => true));
         if ($this->registration === null) {
             $this->error();
         }
         if (isset($params['hash'])) {
             $this->invitation = $this->invitationRepository->findOneBy(array('hash' => $params['hash'], 'registration' => $params['registration']));
             if ($this->invitation === null) {
                 $this->error();
             }
         }
     }
     parent::loadState($params);
 }
 /**
  * @inheritdoc
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $languageArgument = $input->getArgument(self::LANGUAGE_ARGUMENT);
     /** @var Language $language */
     if (($language = $this->languagesRepository->findOneBy(['shortCode' => $languageArgument])) === NULL) {
         $output->writeln("<error>Unknown language {$languageArgument}</error>");
         return 1;
     }
     /** @var Season $season */
     foreach ($this->seasonsRepository->findBy(['language' => $language]) as $season) {
         foreach ($season->getEpisodes() as $episode) {
             $file = "S{$season->getNumber()}E{$episode->getNumber()}{$language->getShortCode()}.txt";
             $handle = fopen($this->scenariosDir . '/' . $file, 'r');
             if ($handle) {
                 $screenplayLine = 1;
                 while (($line = fgets($handle)) !== FALSE) {
                     $name = Strings::before($line, ':');
                     $isCharacter = $name && !in_array($name, self::KNOWN_NON_CHARACTERS, TRUE) && str_word_count($name, 0) < 3 ? TRUE : FALSE;
                     /** @var Character|NULL $character */
                     $character = $isCharacter ? $this->charactersRepository->findOneBy(['slug' => Strings::webalize($name), 'language' => $language]) : NULL;
                     if ($isCharacter && $character === NULL) {
                         $character = new Character(Strings::capitalize($name), $language);
                         $this->entityManager->persist($character);
                         $this->entityManager->flush($character);
                     }
                     $text = $isCharacter ? str_replace($name . ': ', '', $line) : $line;
                     $text = Strings::trim($text);
                     if (empty($text)) {
                         continue;
                     }
                     $screenplay = new Screenplay($episode, $text, $character, $screenplayLine, !$isCharacter);
                     $this->entityManager->persist($screenplay);
                     $this->entityManager->flush($screenplay);
                     $screenplayLine++;
                 }
                 fclose($handle);
             } else {
                 $output->writeln("<error>Scénář {$file} neexistuje!</error>");
                 return 1;
             }
         }
     }
     return 0;
 }
 /**
  * @param int $cityId
  * @return array
  */
 protected function streetWithoutRegions($cityId, $title = NULL)
 {
     $data = [];
     if ($title) {
         $criteria = ['partCity.city.code' => $cityId, 'title LIKE' => '%' . $title . '%'];
     } else {
         $criteria = ['partCity.city.code' => $cityId];
     }
     $streets = $this->streetRepository->findBy($criteria, ['title' => Criteria::ASC, 'id' => Criteria::ASC]);
     foreach ($streets as $street) {
         if (is_numeric($street->title) || array_key_exists($street->title, $this->tempArray)) {
             continue;
         }
         $this->tempArray[$street->title] = 1;
         $data[] = ['streetId' => $street->id, 'title' => Strings::capitalize($street->title), 'code' => $street->code];
     }
     $city = $this->cityRepository->findOneBy(['code' => $cityId]);
     return ['city' => $city ? $city->title : NULL, 'streets' => $data];
 }
Example #15
0
 private function askEmail(QuestionHelper $helper, InputInterface $input, OutputInterface $output)
 {
     $question = new Question('New user email: ');
     $question->setValidator(function ($answer) {
         if (!Validators::is($answer, 'email')) {
             throw new \RuntimeException('The E-mail address must have valid format');
         }
         try {
             $user = $this->userRepository->findOneBy(['email' => $answer]);
         } catch (\Exception $e) {
             throw new \RuntimeException('An error occurred while searching for E-mail address. Try it again.');
         }
         if ($user !== null) {
             throw new \RuntimeException(sprintf('User with E-mail "%s" already exists', $answer));
         }
         return $answer;
     });
     $question->setMaxAttempts(null);
     // unlimited number of attempts
     return $helper->ask($input, $output, $question);
 }
Example #16
0
 private function askUrlPath(QuestionHelper $helper, InputInterface $input, OutputInterface $output)
 {
     $question = new Question('Url path: ');
     $question->setValidator(function ($answer) {
         if (!Validators::is($answer, 'unicode:1..')) {
             throw new \RuntimeException('The Url path must be string');
         }
         try {
             $url = $this->urlRepository->findOneBy(['urlPath' => $answer]);
         } catch (\Exception $e) {
             throw new \RuntimeException('An error occurred while searching for url path. Try it again.');
         }
         if ($url !== null) {
             throw new \RuntimeException(sprintf('Url with path "%s" already exists', $answer));
         }
         return $answer;
     });
     $question->setMaxAttempts(null);
     // unlimited number of attempts
     return $helper->ask($input, $output, $question);
 }
 /**
  * @param $inputLanguage
  * @return Language|NULL
  */
 private function findLanguage($inputLanguage)
 {
     return $this->languagesRepository->findOneBy(['shortCode' => $inputLanguage]);
 }
Example #18
0
 /**
  * Vraci uzivatele podle ID
  * @param int $id user_id
  * @return Entities\User
  */
 public function getUserById($id)
 {
     return $this->repository->findOneBy(['id' => $id]);
 }
Example #19
0
 /**
  * @param $shortCode
  * @return Language|NULL
  */
 public function findByShortName($shortCode)
 {
     return $this->languagesRepository->findOneBy(['shortCode' => $shortCode]);
 }
Example #20
0
 /**
  * @return Index|NULL
  */
 private function findNewestIndex()
 {
     return $this->indicesRepository->findOneBy([], ['createdAt' => 'desc']);
 }
Example #21
0
 /**
  * @param string $slug
  * @return Character|NULL
  */
 public function findBySlug($slug)
 {
     return $this->charactersRepository->findOneBy(['slug' => $slug]);
 }
Example #22
0
 /**
  * @param string $title Webalize nazev clanku
  * @return Entities\Article|NULL Vraci clanek dle web nazvu
  */
 public function getByTitle($title)
 {
     $title = Strings::webalize($title);
     return $this->myArticleRepository->findOneBy(['webalizeTitle' => $title]);
 }
Example #23
0
 public function findOneBy($array)
 {
     return $this->repository->findOneBy($array);
 }
Example #24
0
 /**
  * @param string $slug
  * @return Search|NULL
  */
 public function search($slug)
 {
     return $this->searchesRepository->findOneBy(['slug' => $slug]);
 }