コード例 #1
0
 /**
  * @dataProvider getNameFormatDataProvider
  *
  * @param array $nameFormats
  * @param string $locale
  * @param string $expectedFormat
  * @param string $defaultLocale
  */
 public function testGetNameFormat(array $nameFormats, $locale, $expectedFormat, $defaultLocale = null)
 {
     $this->localeSettings->expects($this->once())->method('getNameFormats')->will($this->returnValue($nameFormats));
     if (null !== $defaultLocale) {
         $this->localeSettings->expects($this->once())->method('getLocale')->will($this->returnValue($defaultLocale));
     } else {
         $this->localeSettings->expects($this->never())->method('getLocale');
     }
     $this->assertEquals($expectedFormat, $this->formatter->getNameFormat($locale));
 }
コード例 #2
0
 /**
  * @param string      $alias     Alias in SELECT or JOIN statement
  * @param string      $className Entity FQCN
  * @param string|null $locale
  *
  * @return string
  */
 public function getFormattedNameDQL($alias, $className, $locale = null)
 {
     $nameParts = array_fill_keys(array_keys($this->namePartsMap), null);
     $interfaces = class_implements($className);
     foreach ($this->namePartsMap as $part => $metadata) {
         if (in_array($metadata['interface'], $interfaces, true)) {
             $nameParts[$part] = $alias . '.' . $metadata['suggestedFieldName'];
         }
     }
     return $this->buildExpression($this->nameFormatter->getNameFormat(), $nameParts);
 }
コード例 #3
0
 /**
  * @param Notification $notification
  *
  * @return string
  */
 private function getFormattedUserName(Notification $notification)
 {
     $user = $notification->getAuthor();
     $userId = $this->userService->verifyDiamanteUserExists($user->getEmail());
     $user = empty($userId) ? $user : new User($userId, User::TYPE_DIAMANTE);
     $user = $this->userService->getByUser($user);
     $format = $this->nameFormatter->getNameFormat();
     $name = str_replace(array('%first_name%', '%last_name%', '%prefix%', '%middle_name%', '%suffix%'), array($user->getFirstName(), $user->getLastName(), '', '', ''), $format);
     return trim($name);
 }
コード例 #4
0
 /**
  * @param Notification $notification
  * @param Ticket $ticket
  *
  * @return string
  */
 private function getFormattedUserName(Notification $notification, Ticket $ticket)
 {
     $author = $notification->getAuthor();
     if (is_null($author)) {
         $reporterId = $ticket->getReporter()->getId();
         $user = $this->diamanteUserRepository->get($reporterId);
     } else {
         $user = $this->getUserDependingOnType($author);
     }
     $name = $this->nameFormatter->format($user);
     if (empty($name)) {
         $format = $this->nameFormatter->getNameFormat();
         $name = str_replace(array('%first_name%', '%last_name%', '%prefix%', '%middle_name%', '%suffix%'), array($user->getFirstName(), $user->getLastName(), '', '', ''), $format);
     }
     $name = preg_replace('/\\s+/', ' ', $name);
     return trim($name);
 }
コード例 #5
0
ファイル: NameFormatType.php プロジェクト: Maksold/platform
 /**
  * {@inheritdoc}
  */
 public function setDefaultOptions(OptionsResolverInterface $resolver)
 {
     $resolver->setDefaults(array('data' => $this->nameFormatter->getNameFormat()));
 }
コード例 #6
0
 /**
  * @param string      $alias     Alias in SELECT or JOIN statement
  * @param string      $className Entity FQCN
  * @param string|null $locale
  *
  * @return string
  */
 public function getFormattedNameDQL($alias, $className, $locale = null)
 {
     $nameFormat = $this->nameFormatter->getNameFormat();
     $nameParts = $this->extractNamePartsPaths($className, $alias);
     return $this->buildExpression($nameFormat, $nameParts);
 }