<?php/** * Created by PhpStorm. * User: adv * Date: 22.05.17 * Time: 12:42 */namespace Slivki\Entity;use Doctrine\Common\Collections\ArrayCollection;class PhoneNumber extends Entity implements \JsonSerializable { const COUNT_SYMBOL_DIGIT = 6; protected $number; protected $link; protected $label; protected $geoLocations; protected $offer; public function __construct() { $this->geoLocations = new ArrayCollection(); } public function getNumber() { return $this->number; } public function setNumber($number) { $this->number = $number; } public function getLink() { return $this->link; } public function setLink($link) { $this->link = $link; } public function getLabel() { return $this->label; } public function setLabel($label) { $this->label = $label; } public function getGeoLocations() { return $this->geoLocations; } public function addGeoLocation(AbstractGeoLocationBase $geoLocation) { if (!$this->geoLocations->contains($geoLocation)) { $this->geoLocations->add($geoLocation); return true; } return false; } public function hasGeoLocation(AbstractGeoLocationBase $geoLocation) { return $this->geoLocations->contains($geoLocation); } public function removeGeoLocation(AbstractGeoLocationBase $geoLocation) { $this->geoLocations->removeElement($geoLocation); } public function getOffer() { return $this->offer; } public function setOffer(Offer $offer = null) { $this->offer = $offer; } public function jsonSerialize(): array { return [ 'ID' => $this->ID, 'number' => $this->number, 'link' => $this->link, 'label' => $this->label ]; } public function getShortPhoneNumber(): string { $arrayNumber = str_split($this->number); $count = 0; $finalShortPhone = ''; foreach ($arrayNumber as $symbol) { $finalShortPhone .= $symbol; if (\is_numeric($symbol)) { ++$count; } if ($count === self::COUNT_SYMBOL_DIGIT) { break; } } return $finalShortPhone; } public static function fromJSON($data) { $phoneNumber = new PhoneNumber(); $phoneNumber->setID($data->ID); $phoneNumber->setNumber($data->number); $phoneNumber->setLink($data->link); $phoneNumber->setLabel($data->label); return $phoneNumber; }}