/** * 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); }
/** * @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 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); } } } } }
/** * @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); }
/** * @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 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 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 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; }
/** * @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); }
/** * {@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); }
/** * @dataProvider formatDataProvider * @param string $format * @param string $expected * @param object $person */ public function testFormat($format, $expected, $person) { $this->localeSettings->expects($this->once())->method('getLocale')->will($this->returnValue(LocaleConfiguration::DEFAULT_LOCALE)); $this->localeSettings->expects($this->once())->method('getNameFormats')->will($this->returnValue(array(LocaleConfiguration::DEFAULT_LOCALE => $format))); $this->assertEquals($expected, $this->formatter->format($person)); }
/** * @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))]; }