/** * Apply name formatter to get entity's full name * * @param mixed $entity * @return string * @throws \RuntimeException */ protected function getFullName($entity) { if (!$this->nameFormatter) { throw new \RuntimeException('Name formatter must be configured'); } return $this->nameFormatter->format($entity); }
/** * @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)); }
/** * @param array $result * @param string $attrName * @param User $user */ protected function addUser(array &$result, $attrName, $user) { if ($user) { $result[$attrName] = $this->nameFormatter->format($user); $result[$attrName . '_id'] = $user->getId(); $result[$attrName . '_viewable'] = $this->securityFacade->isGranted('VIEW', $user); $avatar = $user->getAvatar(); $result[$attrName . '_avatar'] = $avatar ? $this->attachmentManager->getFilteredImageUrl($avatar, 'avatar_xsmall') : null; } }
/** * @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); }
/** * @param Collection $contacts * @param int|null $default * @return array */ protected function getInitialElements(Collection $contacts, $default) { $result = array(); if ($this->canViewContact) { /** @var Contact $contact */ foreach ($contacts as $contact) { $primaryPhone = $contact->getPrimaryPhone(); $primaryEmail = $contact->getPrimaryEmail(); $result[] = array('id' => $contact->getId(), 'label' => $this->nameFormatter->format($contact), 'link' => $this->router->generate('orocrm_contact_info', array('id' => $contact->getId())), 'extraData' => array(array('label' => 'Phone', 'value' => $primaryPhone ? $primaryPhone->getPhone() : null), array('label' => 'Email', 'value' => $primaryEmail ? $primaryEmail->getEmail() : null)), 'isDefault' => $default == $contact->getId()); } } return $result; }
/** * Format address * * @param AddressInterface $address * @param null|string $country * @param string $newLineSeparator * @return string */ public function format(AddressInterface $address, $country = null, $newLineSeparator = "\n") { if (!$country) { $country = null; if ($this->localeSettings->isFormatAddressByAddressCountry()) { $country = $address->getCountryIso2(); } else { $country = $this->localeSettings->getCountry(); } if (!$country) { $country = LocaleConfiguration::DEFAULT_COUNTRY; } } $format = $this->getAddressFormat($country); $countryLocale = $this->localeSettings->getLocaleByCountry($country); $formatted = preg_replace_callback('/%(\\w+)%/', function ($data) use($address, $countryLocale, $newLineSeparator) { $key = $data[1]; $lowerCaseKey = strtolower($key); if ('name' === $lowerCaseKey) { $value = $this->nameFormatter->format($address, $countryLocale); } elseif ('street' === $lowerCaseKey) { $value = trim($this->getValue($address, 'street') . ' ' . $this->getValue($address, 'street2')); } elseif ('street1' === $lowerCaseKey) { $value = $this->getValue($address, 'street'); } elseif ('country' === $lowerCaseKey) { $value = $this->getValue($address, 'countryName'); } elseif ('region' === $lowerCaseKey) { $value = $this->getValue($address, 'regionName'); } elseif ('region_code' === $lowerCaseKey) { $value = $this->getValue($address, 'regionCode'); if (!$value) { $value = $this->getValue($address, 'regionName'); } } else { $value = $this->getValue($address, $lowerCaseKey); } if ($value) { if ($key !== $lowerCaseKey) { $value = strtoupper($value); } return $value; } return ''; }, $format); $formatted = str_replace($newLineSeparator . $newLineSeparator, $newLineSeparator, str_replace('\\n', $newLineSeparator, $formatted)); $formatted = trim($formatted, $newLineSeparator); $formatted = preg_replace('/ +/', ' ', $formatted); $formatted = preg_replace('/ +\\n/', "\n", $formatted); return trim($formatted); }
/** * @param object $object * @param ClassMetadata $objectMetadata * * @return RecipientEntity */ public function createRecipientEntity($object, ClassMetadata $objectMetadata) { $identifiers = $objectMetadata->getIdentifierValues($object); if (count($identifiers) !== 1) { return null; } $organizationName = null; if ($this->getPropertyAccessor()->isReadable($object, static::ORGANIZATION_PROPERTY)) { $organization = $this->getPropertyAccessor()->getValue($object, static::ORGANIZATION_PROPERTY); if ($organization) { $organizationName = $organization->getName(); } } return new RecipientEntity($objectMetadata->name, reset($identifiers), $this->createRecipientEntityLabel($this->nameFormatter->format($object), $objectMetadata->name), $organizationName); }
/** * @param string $emailAddress * @param string|null $ownerClass * @param mixed|null $ownerId */ protected function preciseFullEmailAddress(&$emailAddress, $ownerClass = null, $ownerId = null) { if (!$this->emailAddressHelper->isFullEmailAddress($emailAddress)) { if (!empty($ownerClass) && !empty($ownerId)) { $owner = $this->entityRoutingHelper->getEntity($ownerClass, $ownerId); if ($owner) { $ownerName = $this->nameFormatter->format($owner); if (!empty($ownerName)) { $emailAddress = $this->emailAddressHelper->buildFullEmailAddress($emailAddress, $ownerName); return; } } } $repo = $this->emailAddressManager->getEmailAddressRepository($this->em); $emailAddressObj = $repo->findOneBy(array('email' => $emailAddress)); if ($emailAddressObj) { $owner = $emailAddressObj->getOwner(); if ($owner) { $ownerName = $this->nameFormatter->format($owner); if (!empty($ownerName)) { $emailAddress = $this->emailAddressHelper->buildFullEmailAddress($emailAddress, $ownerName); } } } } }
public function testNotifyWithEmptyAuthor() { $ticketUniqueId = UniqueId::generate(); $reporter = new UserAdapter(1, UserAdapter::TYPE_DIAMANTE); $assignee = new User(); $assignee->setId(2); $assignee->setEmail('*****@*****.**'); $author = null; $branch = new Branch('KEY', 'Name', 'Description'); $ticket = new Ticket($ticketUniqueId, new TicketSequenceNumber(1), 'Subject', 'Description', $branch, $reporter, $assignee, new Source(Source::WEB), new Priority(Priority::PRIORITY_MEDIUM), new Status(Status::NEW_ONE)); $notification = new TicketNotification((string) $ticketUniqueId, $author, 'Header', 'Subject', new \ArrayIterator(array('key' => 'value')), array('file.ext')); $message = new \Swift_Message(); $this->watchersService->expects($this->once())->method('getWatchers')->will($this->returnValue([new WatcherList($ticket, 'diamante_1')])); $this->diamanteUserRepository->expects($this->exactly(2))->method('get')->with(1)->will($this->returnValue($this->diamanteUser)); $this->configManager->expects($this->once())->method('get')->will($this->returnValue('*****@*****.**')); $this->nameFormatter->expects($this->once())->method('format')->with($this->diamanteUser)->will($this->returnValue('First Last')); $this->mailer->expects($this->once())->method('createMessage')->will($this->returnValue($message)); $this->ticketRepository->expects($this->once())->method('getByUniqueId')->with($ticketUniqueId)->will($this->returnValue($ticket)); $this->templateResolver->expects($this->any())->method('resolve')->will($this->returnValueMap(array(array($notification, TemplateResolver::TYPE_TXT, 'txt.template.html'), array($notification, TemplateResolver::TYPE_HTML, 'html.template.html')))); $optionsConstraint = $this->logicalAnd($this->arrayHasKey('changes'), $this->arrayHasKey('attachments'), $this->arrayHasKey('user'), $this->arrayHasKey('header'), $this->contains($notification->getChangeList()), $this->contains($notification->getAttachments()), $this->contains('First Last'), $this->contains($notification->getHeaderText())); $this->twig->expects($this->at(0))->method('render')->with('txt.template.html', $optionsConstraint)->will($this->returnValue('Rendered TXT template')); $this->twig->expects($this->at(1))->method('render')->with('html.template.html', $optionsConstraint)->will($this->returnValue('Rendered HTML template')); $this->mailer->expects($this->once())->method('send')->with($this->logicalAnd($this->isInstanceOf('\\Swift_Message'), $this->callback(function (\Swift_Message $other) use($notification) { $to = $other->getTo(); return false !== strpos($other->getSubject(), $notification->getSubject()) && false !== strpos($other->getSubject(), 'KEY-1') && false !== strpos($other->getBody(), 'Rendered TXT template') && array_key_exists('*****@*****.**', $to) && $other->getHeaders()->has('References') && false !== strpos($other->getHeaders()->get('References'), '*****@*****.**') && false !== strpos($other->getHeaders()->get('References'), '*****@*****.**'); }))); $this->messageReferenceRepository->expects($this->once())->method('findAllByTicket')->with($ticket)->will($this->returnValue(array(new MessageReference('*****@*****.**', $ticket), new MessageReference('*****@*****.**', $ticket)))); $this->messageReferenceRepository->expects($this->once())->method('store')->with($this->logicalAnd($this->isInstanceOf('\\Diamante\\DeskBundle\\Model\\Ticket\\EmailProcessing\\MessageReference'))); $notifier = new EmailNotifier($this->container, $this->twig, $this->mailer, $this->templateResolver, $this->ticketRepository, $this->messageReferenceRepository, $this->userService, $this->nameFormatter, $this->diamanteUserRepository, $this->configManager, $this->oroUserManager, $this->watchersService, $this->senderHost); $notifier->notify($notification); }
/** * @param object|null $owner * @param string $email * * @return string */ protected function formatEmail($owner, $email) { if (!$owner) { return $email; } $ownerName = $this->nameFormatter->format($owner); return $this->emailAddressHelper->buildFullEmailAddress($email, $ownerName); }
/** * @dataProvider formatDataProvider * @param string $format * @param string $regionCode * @param string $expected * @param bool $formatByCountry * @param string $street2 * @param string|null $separator */ public function testFormat($format, $regionCode, $expected, $formatByCountry = false, $street2 = 'apartment 10', $separator = "\n") { $address = new AddressStub($street2); $address->setRegionCode($regionCode); $locale = 'en'; $country = 'CA'; $addressFormats = [$country => [LocaleSettings::ADDRESS_FORMAT_KEY => $format]]; $this->localeSettings->expects($this->once())->method('getAddressFormats')->will($this->returnValue($addressFormats)); $this->localeSettings->expects($this->once())->method('isFormatAddressByAddressCountry')->will($this->returnValue($formatByCountry)); $this->localeSettings->expects($this->once())->method('getCountry')->will($this->returnValue($country)); if ($formatByCountry) { $this->localeSettings->expects($this->once())->method('getLocaleByCountry')->with($address->getCountryIso2())->will($this->returnValue($locale)); } else { $this->localeSettings->expects($this->once())->method('getLocaleByCountry')->with($country)->will($this->returnValue($locale)); } $this->nameFormatter->expects($this->once())->method('format')->with($address, $locale)->will($this->returnValue('Formatted User NAME')); $this->assertEquals($expected, $this->addressFormatter->format($address, null, $separator)); }
/** * @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); }
/** * @param ValueRenderEvent $fieldValueEvent */ public function beforeValueRender(ValueRenderEvent $fieldValueEvent) { $originalValue = $fieldValueEvent->getOriginalValue(); $metadata = $fieldValueEvent->getMetadata(); if ($originalValue instanceof AddressInterface) { $fieldValueEvent->setConvertedValue($this->addressFormatter->format($originalValue)); } elseif ($originalValue instanceof NamePrefixInterface || $originalValue instanceof FirstNameInterface || $originalValue instanceof MiddleNameInterface || $originalValue instanceof LastNameInterface || $originalValue instanceof NameSuffixInterface) { $fieldValueEvent->setConvertedValue($this->nameFormatter->format($originalValue)); } elseif ($originalValue instanceof \DateTime) { $dateType = $metadata->get('render_date_type'); $timeType = $metadata->get('render_time_type'); $dateTimePattern = $metadata->get('render_datetime_pattern'); $fieldValueEvent->setConvertedValue($this->dateTimeFormatter->format($originalValue, $dateType, $timeType, null, null, $dateTimePattern)); } elseif (is_numeric($originalValue)) { $numberStyle = $metadata->get('render_number_style'); if (!$numberStyle) { $numberStyle = 'default_style'; } $fieldValueEvent->setConvertedValue($this->numberFormatter->format($originalValue, $numberStyle)); } }
/** * @param string $emailAddress * @return string */ protected function preciseFullEmailAddress(&$emailAddress) { if (!EmailUtil::isFullEmailAddress($emailAddress)) { $repo = $this->emailAddressManager->getEmailAddressRepository($this->em); $emailAddressObj = $repo->findOneBy(array('email' => $emailAddress)); if ($emailAddressObj) { $owner = $emailAddressObj->getOwner(); if ($owner) { $emailAddress = EmailUtil::buildFullEmailAddress($emailAddress, $this->nameFormatter->format($owner)); } } } }
/** * @param array $result * @param object $user * @param bool $addValue */ protected function addUserFullName(array &$result, $user, $addValue) { if ($user instanceof FullNameInterface) { if ($addValue) { $val = $this->nameFormatter->format($user); } else { $val = ['type' => 'string', 'label' => $this->translator->trans('oro.email.emailtemplate.user_full_name')]; } $result['userFullName'] = $val; } elseif ($addValue) { $result['userFullName'] = ''; } }
/** * @param SecurityIdentityInterface $sid * * @return string */ protected function getFormattedName(SecurityIdentityInterface $sid) { if ($sid instanceof UserSecurityIdentity && $sid->getUsername()) { $user = $this->manager->getRepository('OroUserBundle:User')->findOneBy(['username' => $sid->getUsername()]); if ($user) { return $this->nameFormatter->format($user); } } elseif ($sid instanceof BusinessUnitSecurityIdentity) { $businessUnit = $this->manager->getRepository('OroOrganizationBundle:BusinessUnit')->find($sid->getId()); if ($businessUnit) { return $businessUnit->getName(); } } return ''; }
/** * Get email address prepared for sending. * * @param mixed $context * @param string|array $data * @return string */ protected function getEmailAddress($context, $data) { $name = null; $emailAddress = $this->contextAccessor->getValue($context, $data); if (is_array($data)) { $emailAddress = $this->contextAccessor->getValue($context, $data['email']); if (array_key_exists('name', $data)) { $data['name'] = $this->contextAccessor->getValue($context, $data['name']); if (is_object($data['name'])) { $name = $this->nameFormatter->format($data['name']); } else { $name = $data['name']; } } } return $this->emailAddressHelper->buildFullEmailAddress($emailAddress, $name); }
/** * @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); }
/** * {@inheritdoc} */ public function convertItem($user) { $result = []; foreach ($this->fields as $field) { $result[$field] = $this->getPropertyValue($field, $user); } $result['avatar'] = null; $avatar = $this->getPropertyValue('avatar', $user); if ($avatar) { $result['avatar'] = $this->attachmentManager->getFilteredImageUrl($avatar, UserSearchHandler::IMAGINE_AVATAR_FILTER); } if (!$this->nameFormatter) { throw new \RuntimeException('Name formatter must be configured'); } $result['fullName'] = $this->nameFormatter->format($user); return $result; }
public function testNotify() { $author = new ApiUser('*****@*****.**', 'password'); $notification = new UserNotification($author, 'Header'); $format = '%prefix% %first_name% %middle_name% %last_name% %suffix%'; $message = new \Swift_Message(); $this->mailer->expects($this->once())->method('createMessage')->will($this->returnValue($message)); $this->configManager->expects($this->once())->method('get')->will($this->returnValue('Mike The Bot')); $this->nameFormatter->expects($this->any())->method('format')->with($this->diamanteUser)->will($this->returnValue('First Last')); $this->userService->expects($this->once())->method('verifyDiamanteUserExists')->with($this->equalTo($author->getEmail()))->will($this->returnValue(1)); $this->userService->expects($this->once())->method('getByUser')->with($this->equalTo(new UserAdapter(1, UserAdapter::TYPE_DIAMANTE)))->will($this->returnValue($this->diamanteUser)); $this->nameFormatter->expects($this->once())->method('getNameFormat')->will($this->returnValue($format)); $this->templateResolver->expects($this->any())->method('resolve')->will($this->returnValueMap(array(array($notification, TemplateResolver::TYPE_TXT, 'txt.template.html'), array($notification, TemplateResolver::TYPE_HTML, 'html.template.html')))); $optionsConstraint = $this->logicalAnd($this->arrayHasKey('user'), $this->arrayHasKey('header'), $this->contains('First Last'), $this->contains($notification->getHeaderText())); $this->twig->expects($this->at(0))->method('render')->with('txt.template.html', $optionsConstraint)->will($this->returnValue('Rendered TXT template')); $this->twig->expects($this->at(1))->method('render')->with('html.template.html', $optionsConstraint)->will($this->returnValue('Rendered HTML template')); $this->mailer->expects($this->once())->method('send')->with($this->logicalAnd($this->isInstanceOf('\\Swift_Message'), $this->callback(function (\Swift_Message $other) use($notification) { $to = $other->getTo(); return false !== strpos($other->getBody(), 'Rendered TXT template') && array_key_exists('*****@*****.**', $to); }))); $notifier = new EmailNotifier($this->twig, $this->mailer, $this->templateResolver, $this->userService, $this->nameFormatter, $this->configManager, $this->senderEmail); $notifier->notify($notification); }
/** * {@inheritdoc} */ public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver->setDefaults(array('data' => $this->nameFormatter->getNameFormat())); }
/** * @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); }
/** * {@inheritdoc} */ protected function executeAction($context) { $this->contextAccessor->setValue($context, $this->options['attribute'], $this->formatter->format($this->contextAccessor->getValue($context, $this->options['object']))); }
/** * Formats person name according to locale settings. * * @param NamePrefixInterface|FirstNameInterface|MiddleNameInterface|LastNameInterface|NameSuffixInterface $person * @param string $locale * @return string */ public function format($person, $locale = null) { return $this->formatter->format($person, $locale); }
/** * @param User $user * @return array */ protected function createUserView(User $user) { return ['id' => $user->getId(), 'url' => $this->router->generate('oro_user_view', array('id' => $user->getId())), 'fullName' => $this->nameFormatter->format($user), 'avatar' => $user->getAvatar() ? $this->attachmentManager->getFilteredImageUrl($user->getAvatar(), 'avatar_xsmall') : null, 'permissions' => array('view' => $this->securityFacade->isGranted('VIEW', $user))]; }
/** * @dataProvider metadataProvider * * @param string $expectedDQL * @param string $nameFormat * @param string $className */ public function testGetFormattedNameDQL($expectedDQL, $nameFormat, $className) { $this->nameFormatter->expects($this->once())->method('getNameFormat')->will($this->returnValue($nameFormat)); $this->assertEquals($expectedDQL, $this->formatter->getFormattedNameDQL('a', $className)); }
/** * @param Crawler $crawler * @param User $owner */ public function assertViewPage(Crawler $crawler, User $owner) { $html = $crawler->filter('.user-info-state')->html(); $this->assertContains($this->formatter->format($owner), $html); }