namespace Lc\ShopBundle\Model; | namespace Lc\ShopBundle\Model; | ||||
use Doctrine\ORM\Mapping as ORM; | use Doctrine\ORM\Mapping as ORM; | ||||
use Lc\ShopBundle\Context\StatusInterface; | |||||
/** | /** | ||||
* @ORM\MappedSuperclass() | * @ORM\MappedSuperclass() | ||||
*/ | */ | ||||
abstract class Address extends AbstractEntity | |||||
abstract class Address extends AbstractEntity implements StatusInterface | |||||
{ | { | ||||
use StatusTrait; | |||||
const TYPE_INDIVIDUAL = 'individual'; | const TYPE_INDIVIDUAL = 'individual'; | ||||
const TYPE_LEGAL_PERSON = 'legal-person'; | const TYPE_LEGAL_PERSON = 'legal-person'; |
/** | /** | ||||
* @return Collection|Address[] | * @return Collection|Address[] | ||||
*/ | */ | ||||
public function getAddresses(): Collection | |||||
{ | |||||
return $this->addresses; | |||||
public function getAddresses($status = null): Collection | |||||
{ | |||||
if($status){ | |||||
$addressToReturn = new ArrayCollection(); | |||||
foreach ($this->addresses as $address){ | |||||
if($address->getStatus() == $status) { | |||||
$addressToReturn[] = $address; | |||||
} | |||||
} | |||||
return $addressToReturn; | |||||
}else{ | |||||
return $this->addresses; | |||||
} | |||||
} | } | ||||
public function addAddress(Address $address): self | public function addAddress(Address $address): self |
email: Email | email: Email | ||||
delivery: Livraison | delivery: Livraison | ||||
maintenance: Maintenance | maintenance: Maintenance | ||||
Address: | |||||
listLoopBesancon: Adresses de Besançon à spécifier (lat / long) | |||||
None: Aucune valeur | None: Aucune valeur | ||||
unit: Unité | unit: Unité | ||||
Address: | Address: | ||||
city: Commune | city: Commune | ||||
statusOptions: | |||||
offline: Désactiver | |||||
online: Activer | |||||
typeOptions: | typeOptions: | ||||
individual: Particulier | individual: Particulier | ||||
legal-person: Professionnel | legal-person: Professionnel |
<div class="col-12"> | <div class="col-12"> | ||||
{{ form_row(form.deliveryInfos) }} | {{ form_row(form.deliveryInfos) }} | ||||
</div> | </div> | ||||
<div class="col-12 {{ merchantUtils.getMerchantCurrent().isHubBesancon() ? '': 'hidden'}}"> | |||||
{{ form_row(form.inBesanconLoop) }} | |||||
</div> | |||||
<div class="col-6"> | <div class="col-6"> | ||||
{{ form_row(form.latitude) }} | {{ form_row(form.latitude) }} | ||||
</div> | </div> | ||||
<div class="col-6"> | <div class="col-6"> | ||||
{{ form_row(form.longitudeOverride) }} | {{ form_row(form.longitudeOverride) }} | ||||
</div> | </div> | ||||
<div class="col-12"> | |||||
{{ form_row(form.status) }} | |||||
<p class="callout callout-info"> | |||||
Sauf si vous savez ce que ce vous faites ce champ doit toujours être "Activer" | |||||
</p> | |||||
</div> | |||||
{{ form_row(form.country) }} | {{ form_row(form.country) }} | ||||
{% trans_default_domain 'lcshop' %} | {% trans_default_domain 'lcshop' %} | ||||
<div class="col-6 user-address-item"> | <div class="col-6 user-address-item"> | ||||
{% set button = '<button type="button" data-url="'~ path('easyadmin', {"action": 'editAddressUser', 'entity': 'User', 'id': entity.id, 'addressId': address.id})~'" class="btn btn-default btn-edit-user-address" >'~ 'action.edit'|trans ~'</button>' %} | {% set button = '<button type="button" data-url="'~ path('easyadmin', {"action": 'editAddressUser', 'entity': 'User', 'id': entity.id, 'addressId': address.id})~'" class="btn btn-default btn-edit-user-address" >'~ 'action.edit'|trans ~'</button>' %} | ||||
{{ macros.box_info('bg-info', 'address-card', address.summary, '', button) }} | |||||
{{ macros.box_info('bg-info', 'address-card', address.summary(true, true), '', button) }} | |||||
</div> | </div> |
<div class="col-5"> | <div class="col-5"> | ||||
<div class="row" id="user-addresses"> | <div class="row" id="user-addresses"> | ||||
{% for address in entity.addresses %} | {% for address in entity.addresses %} | ||||
{% if address.status >=0 %} | |||||
{% include '@LcShop/backend/user/block_useraddress.html.twig' %} | {% include '@LcShop/backend/user/block_useraddress.html.twig' %} | ||||
{% endif %} | |||||
{% endfor %} | {% endfor %} | ||||
</div> | </div> | ||||
<button type="button" data-url="{{ path('easyadmin', {"action": 'editAddressUser', 'entity': 'User', 'id': entity.id, 'addressId': 'new'}) }}" | <button type="button" data-url="{{ path('easyadmin', {"action": 'editAddressUser', 'entity': 'User', 'id': entity.id, 'addressId': 'new'}) }}" |
use EasyCorp\Bundle\EasyAdminBundle\Configuration\ConfigManager; | use EasyCorp\Bundle\EasyAdminBundle\Configuration\ConfigManager; | ||||
use Geocoder\Model\Coordinates; | use Geocoder\Model\Coordinates; | ||||
use Geocoder\Provider\Addok\Addok; | use Geocoder\Provider\Addok\Addok; | ||||
use Geocoder\Provider\GoogleMaps\GoogleMaps; | |||||
use Geocoder\Provider\Nominatim\Nominatim; | |||||
use Geocoder\Query\GeocodeQuery; | use Geocoder\Query\GeocodeQuery; | ||||
use Geocoder\Query\ReverseQuery; | use Geocoder\Query\ReverseQuery; | ||||
use Lc\ShopBundle\Context\ImageInterface; | use Lc\ShopBundle\Context\ImageInterface; | ||||
return $truncate; | return $truncate; | ||||
} | } | ||||
function stripAccents($stripAccents) | |||||
{ | |||||
return strtr($stripAccents,'àáâãäçèéêëìíîïñòóôõöùúûüýÿÀÁÂÃÄÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝ','aaaaaceeeeiiiinooooouuuuyyAAAAACEEEEIIIINOOOOOUUUUY'); | |||||
} | |||||
function cleanStringToCompare($string) | |||||
{ | |||||
return $this->stripAccents(trim(strtolower($string))) ; | |||||
} | |||||
public function isBot() | public function isBot() | ||||
{ | { | ||||
public function getGeocoderProvider() | public function getGeocoderProvider() | ||||
{ | { | ||||
$provider = false ; | |||||
$symfonyClient = new HttplugClient(); | $symfonyClient = new HttplugClient(); | ||||
$provider = new Addok($symfonyClient, 'https://api-adresse.data.gouv.fr') ; | |||||
$configGeocoderProvider = $this->parameterBag->get('geocoder.provider') ; | |||||
/* API du gouvernement */ | |||||
if($configGeocoderProvider == 'addok') { | |||||
$provider = new Addok($symfonyClient, 'https://api-adresse.data.gouv.fr') ; | |||||
} | |||||
/* Google Maps */ | |||||
elseif($configGeocoderProvider == 'googlemaps') { | |||||
$provider = new GoogleMaps($symfonyClient, null, $this->parameterBag->get('geocoder.api_key')) ; | |||||
} | |||||
/* Nominatim : OpenStreetMap */ | |||||
elseif($configGeocoderProvider == 'nominatim') { | |||||
$provider = Nominatim::withOpenStreetMapServer($symfonyClient, 'Mozilla/5.0 (platform; rv:geckoversion) Gecko/geckotrail Firefox/firefoxversion'); | |||||
} | |||||
if(!$provider) { | |||||
throw new \ErrorException('Aucun provider (geocoding) défini') ; | |||||
} | |||||
return $provider ; | return $provider ; | ||||
} | } | ||||
$provider = $this->getGeocoderProvider() ;; | $provider = $this->getGeocoderProvider() ;; | ||||
$query = GeocodeQuery::create($query)->withData('type', 'housenumber'); | $query = GeocodeQuery::create($query)->withData('type', 'housenumber'); | ||||
$results = $provider->geocodeQuery($query); | $results = $provider->geocodeQuery($query); | ||||
return $results->all() ; | |||||
$resultsToReturn = array(); | |||||
foreach($results as $result) { | |||||
if ($result->getStreetNumber() && strlen($result->getStreetNumber()) > 0) { | |||||
$resultsToReturn[] = $result; | |||||
} | |||||
} | |||||
return $resultsToReturn; | |||||
} | } | ||||
public function callReverseAddressApi($latitude, $longitude) | public function callReverseAddressApi($latitude, $longitude) |