restore showing phonenumber

This commit is contained in:
Julien Fastré 2022-03-02 13:48:48 +01:00
parent ed4cf67e79
commit 54ad7a4b8f
10 changed files with 37 additions and 40 deletions

View File

@ -11,6 +11,8 @@ declare(strict_types=1);
namespace Chill\MainBundle\Phonenumber; namespace Chill\MainBundle\Phonenumber;
use libphonenumber\PhoneNumber;
/** /**
* Helper to some task linked to phonenumber. * Helper to some task linked to phonenumber.
* *
@ -20,9 +22,9 @@ namespace Chill\MainBundle\Phonenumber;
*/ */
interface PhoneNumberHelperInterface interface PhoneNumberHelperInterface
{ {
public function denormalize(string $phoneNumber): string; public function denormalize(PhoneNumber $phoneNumber): string;
public function format(string $phonenumber): string; public function format(PhoneNumber $phonenumber): string;
/** /**
* Get type (mobile, landline, ...) for phone number. * Get type (mobile, landline, ...) for phone number.

View File

@ -45,6 +45,8 @@ final class PhonenumberHelper implements PhoneNumberHelperInterface
private Client $twilioClient; private Client $twilioClient;
private PhonenumberUtil $phoneNumberUtil;
public function __construct( public function __construct(
CacheItemPoolInterface $cacheUserData, CacheItemPoolInterface $cacheUserData,
ParameterBagInterface $parameterBag, ParameterBagInterface $parameterBag,
@ -67,17 +69,13 @@ final class PhonenumberHelper implements PhoneNumberHelperInterface
]); ]);
$this->isConfigured = true; $this->isConfigured = true;
} }
$this->phoneNumberUtil = PhoneNumberUtil::getInstance();
} }
public function denormalize(string $phoneNumber): string public function denormalize(PhoneNumber $phoneNumber): string
{ {
$phoneUtil = PhoneNumberUtil::getInstance(); return $this->format($phoneNumber);
return $phoneUtil
->format(
$phoneUtil->parse($phoneNumber),
PhoneNumberFormat::E164
);
} }
/** /**
@ -85,15 +83,10 @@ final class PhonenumberHelper implements PhoneNumberHelperInterface
* @return string * @return string
* @throws NumberParseException * @throws NumberParseException
*/ */
public function format(string $phoneNumber): string public function format(PhoneNumber $phoneNumber): string
{ {
$phoneUtil = PhoneNumberUtil::getInstance(); return $this->phoneNumberUtil
->formatOutOfCountryCallingNumber($phoneNumber, $this->config['default_carrier_code']);
return $phoneUtil
->format(
$phoneUtil->parse($phoneNumber, $this->config['default_carrier_code']),
PhoneNumberFormat::NATIONAL
);
} }
/** /**

View File

@ -7,6 +7,8 @@ services:
Chill\MainBundle\Phonenumber\PhonenumberHelper: ~ Chill\MainBundle\Phonenumber\PhonenumberHelper: ~
Chill\MainBundle\Phonenumber\Templating: ~
Chill\MainBundle\Validation\Validator\ValidPhonenumber: Chill\MainBundle\Validation\Validator\ValidPhonenumber:
tags: tags:
- { name: validator.constraint_validator } - { name: validator.constraint_validator }

View File

@ -148,14 +148,14 @@
{% endif %} {% endif %}
<li> <li>
{% if person.mobilenumber %} {% if person.mobilenumber %}
<i class="fa fa-li fa-mobile"></i><a href="{{ 'tel:' ~ person.mobilenumber|phone_number_format('E164') }}"> <i class="fa fa-li fa-mobile"></i><a href="{{ 'tel:' ~ person.mobilenumber }}">
{{ person.mobilenumber|phone_number_format('NATIONAL') }} {{ person.mobilenumber|chill_format_phonenumber }}
</a> </a>
{% else %} {% else %}
<i class="fa fa-li fa-phone"></i> <i class="fa fa-li fa-phone"></i>
{% if person.phonenumber %} {% if person.phonenumber %}
<a href="{{ 'tel:' ~ person.phonenumber|phone_number_format('E164') }}"> <a href="{{ 'tel:' ~ person.phonenumber }}">
{{ person.phonenumber|phone_number_format('NATIONAL') }} {{ person.phonenumber|chill_format_phonenumber }}
</a> </a>
{% else %} {% else %}
<span class="chill-no-data-statement">{{ 'No data given'|trans }}</span> <span class="chill-no-data-statement">{{ 'No data given'|trans }}</span>

View File

@ -25,15 +25,15 @@
{% if person.phonenumber %} {% if person.phonenumber %}
<span class="phonenumber d-block d-sm-inline-block"> <span class="phonenumber d-block d-sm-inline-block">
<i class="fa fa-fw fa-phone"></i> <i class="fa fa-fw fa-phone"></i>
<a href="{{ 'tel:' ~ person.phonenumber|phone_number_format('E164') }}" class="phone mr-3" title="{{ 'Phonenumber'|trans }}"> <a href="{{ 'tel:' ~ person.phonenumber }}" class="phone mr-3" title="{{ 'Phonenumber'|trans }}">
{{ person.phonenumber|phone_number_format('NATIONAL') }}</a> {{ person.phonenumber|chill_format_phonenumber }}</a>
</span> </span>
{% endif %} {% endif %}
{% if person.mobilenumber %} {% if person.mobilenumber %}
<span class="mobilenumber d-block d-sm-inline-block"> <span class="mobilenumber d-block d-sm-inline-block">
<i class="fa fa-fw fa-mobile"></i> <i class="fa fa-fw fa-mobile"></i>
<a href="{{ 'tel:' ~ person.mobilenumber|phone_number_format('E164') }}" class="phone mr-3" title="{{ 'Mobilenumber'|trans }}"> <a href="{{ 'tel:' ~ person.mobilenumber }}" class="phone mr-3" title="{{ 'Mobilenumber'|trans }}">
{{ person.mobilenumber|phone_number_format('NATIONAL') }}</a> {{ person.mobilenumber|chill_format_phonenumber }}</a>
</span> </span>
{% endif %} {% endif %}
{% if person.email %} {% if person.email %}

View File

@ -62,12 +62,12 @@
<ul> <ul>
{% if person.phonenumber is not empty %} {% if person.phonenumber is not empty %}
<li> <li>
<a href="tel:{{ person.phonenumber|phone_number_format('E164') }}"><img src="{{ asset('build/images/mobile-alt-solid.svg') }}">&nbsp;<pre>{{ person.phonenumber|phone_number_format('NATIONAL') }}</pre></a> <a href="tel:{{ person.phonenumber }}"><img src="{{ asset('build/images/mobile-alt-solid.svg') }}">&nbsp;<pre>{{ person.phonenumber|chill_format_phonenumber }}</pre></a>
</li> </li>
{% endif %} {% endif %}
{% if person.mobilenumber is not empty%} {% if person.mobilenumber is not empty%}
<li> <li>
<a href="tel:{{ person.mobilenumber|phone_number_format('E164') }}"><img src="{{ asset('build/images/phone-alt-solid.svg') }}">&nbsp;<pre>{{ person.mobilenumber|phone_number_format('NATIONAL') }}</pre></a> <a href="tel:{{ person.mobilenumber }}"><img src="{{ asset('build/images/phone-alt-solid.svg') }}">&nbsp;<pre>{{ person.mobilenumber|chill_format_phonenumber }}</pre></a>
</li> </li>
{% endif %} {% endif %}
</ul> </ul>

View File

@ -232,14 +232,14 @@ This view should receive those arguments:
{%- if chill_person.fields.phonenumber == 'visible' -%} {%- if chill_person.fields.phonenumber == 'visible' -%}
<dl> <dl>
<dt>{{ 'Phonenumber'|trans }}&nbsp;:</dt> <dt>{{ 'Phonenumber'|trans }}&nbsp;:</dt>
<dd>{% if person.phonenumber is not empty %}<a href="tel:{{ person.phonenumber|phone_number_format('E164') }}"><pre>{{ person.phonenumber|phone_number_format('NATIONAL') }}</pre></a>{% else %}<span class="chill-no-data-statement">{{ 'No data given'|trans }}{% endif %}</dd> <dd>{% if person.phonenumber is not empty %}<a href="tel:{{ person.phonenumber|phone_number_format }}">{{ person.phonenumber|chill_format_phonenumber }}</a>{% else %}<span class="chill-no-data-statement">{{ 'No data given'|trans }}{% endif %}</dd>
</dl> </dl>
{% endif %} {% endif %}
{%- if chill_person.fields.mobilenumber == 'visible' -%} {%- if chill_person.fields.mobilenumber == 'visible' -%}
<dl> <dl>
<dt>{{ 'Mobilenumber'|trans }}&nbsp;:</dt> <dt>{{ 'Mobilenumber'|trans }}&nbsp;:</dt>
<dd>{% if person.mobilenumber is not empty %}<a href="tel:{{ person.mobilenumber|phone_number_format('E164') }}">{{ person.mobilenumber|phone_number_format('NATIONAL') }}</a>{% else %}<span class="chill-no-data-statement">{{ 'No data given'|trans }}{% endif %}</dd> <dd>{% if person.mobilenumber is not empty %}<a href="tel:{{ person.mobilenumber|phone_number_format }}">{{ person.mobilenumber|chill_format_phonenumber }}</a>{% else %}<span class="chill-no-data-statement">{{ 'No data given'|trans }}{% endif %}</dd>
<p>{% if person.acceptSMS %}{{ 'Accept short text message'|trans }}{% endif %}</p> <p>{% if person.acceptSMS %}{{ 'Accept short text message'|trans }}{% endif %}</p>
</dl> </dl>
{% endif %} {% endif %}
@ -250,7 +250,7 @@ This view should receive those arguments:
<dt>{{ 'Others phone numbers'|trans }}&nbsp;:</dt> <dt>{{ 'Others phone numbers'|trans }}&nbsp;:</dt>
{% for el in person.otherPhoneNumbers %} {% for el in person.otherPhoneNumbers %}
{% if el.phonenumber is not empty %} {% if el.phonenumber is not empty %}
<dd>{% if el.description is not empty %}{{ el.description }}&nbsp;:&nbsp;{% endif %}<a href="tel:{{ el.phonenumber|phone_number_format('E164') }}">{{ el.phonenumber|phone_number_format('NATIONAL') }}</a></dd> <dd>{% if el.description is not empty %}{{ el.description }}&nbsp;:&nbsp;{% endif %}<a href="tel:{{ el.phonenumber }}">{{ el.phonenumber|chill_format_phonenumber }}</a></dd>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
</ul> </ul>
@ -317,4 +317,4 @@ This view should receive those arguments:
{% endif %} {% endif %}
</div> </div>
{% endblock %} {% endblock %}

View File

@ -23,10 +23,10 @@ final class Version20220215135509 extends AbstractMigration implements Container
$countryCode = $util->getCountryCodeForRegion($defaultCarriercode); $countryCode = $util->getCountryCodeForRegion($defaultCarriercode);
return sprintf('%s=CASE WHEN return sprintf('%s=CASE
LEFT(%s, 1) = \'0\' WHEN %s = \'\' THEN NULL
THEN WHEN LEFT(%s, 1) = \'0\'
\'%s\' || replace(replace(substr(%s, 2), \'(0)\', \'\'), \' \', \'\') THEN \'%s\' || replace(replace(substr(%s, 2), \'(0)\', \'\'), \' \', \'\')
ELSE replace(replace(%s, \'(0)\', \'\'),\' \', \'\') ELSE replace(replace(%s, \'(0)\', \'\'),\' \', \'\')
END', $field, $field, $countryCode, $field, $field); END', $field, $field, $countryCode, $field, $field);
} }

View File

@ -111,7 +111,7 @@
</li> </li>
<li><i class="fa fa-li fa-phone"></i> <li><i class="fa fa-li fa-phone"></i>
{% if thirdparty.telephone %} {% if thirdparty.telephone %}
<a href="{{ 'tel:' ~ thirdparty.telephone|phone_number_format('E164') }}">{{ thirdparty.telephone|phone_number_format('NATIONAL') }}</a> <a href="{{ 'tel:' ~ thirdparty.telephone }}">{{ thirdparty.telephone|chill_format_phonenumber }}</a>
{% else %} {% else %}
<span class="chill-no-data-statement">{{ 'thirdparty.No_phonenumber'|trans }}</span> <span class="chill-no-data-statement">{{ 'thirdparty.No_phonenumber'|trans }}</span>
{% endif %} {% endif %}
@ -136,7 +136,7 @@
</li> </li>
<li><i class="fa fa-li fa-phone"></i> <li><i class="fa fa-li fa-phone"></i>
{% if thirdparty.telephone %} {% if thirdparty.telephone %}
<a href="{{ 'tel:' ~ thirdparty.telephone|phone_number_format('E164') }}">{{ thirdparty.telephone|phone_number_format('NATIONAL') }}</a> <a href="{{ 'tel:' ~ thirdparty.telephone }}">{{ thirdparty.telephone|chill_format_phonenumber }}</a>
{% else %} {% else %}
<span class="chill-no-data-statement">{{ 'thirdparty.No_phonenumber'|trans }}</span> <span class="chill-no-data-statement">{{ 'thirdparty.No_phonenumber'|trans }}</span>
{% endif %} {% endif %}

View File

@ -69,8 +69,8 @@
{% if thirdParty.telephone == null %} {% if thirdParty.telephone == null %}
<span class="chill-no-data-statement">{{ 'No phone given'|trans }}</span> <span class="chill-no-data-statement">{{ 'No phone given'|trans }}</span>
{% else %} {% else %}
<a href="{{ 'tel:' ~ thirdParty.telephone|phone_number_format('E164') }}"> <a href="{{ 'tel:' ~ thirdParty.telephone }}">
{{ thirdParty.telephone|phone_number_format('NATIONAL') }} {{ thirdParty.telephone|chill_print_or_message("thirdparty.No_phonenumber") }}
</a> </a>
{% endif %} {% endif %}
</dd> </dd>