src/Entity/PhoneNumber.php line 13

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: adv
  5.  * Date: 22.05.17
  6.  * Time: 12:42
  7.  */
  8. namespace Slivki\Entity;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. class PhoneNumber extends Entity implements \JsonSerializable {
  11.     const COUNT_SYMBOL_DIGIT 6;
  12.     protected $number;
  13.     protected $link;
  14.     protected $label;
  15.     protected $geoLocations;
  16.     protected $offer;
  17.     public function __construct() {
  18.         $this->geoLocations = new ArrayCollection();
  19.     }
  20.     public function getNumber() {
  21.         return $this->number;
  22.     }
  23.     public function setNumber($number) {
  24.         $this->number $number;
  25.     }
  26.     public function getLink() {
  27.         return $this->link;
  28.     }
  29.     public function setLink($link) {
  30.         $this->link $link;
  31.     }
  32.     public function getLabel() {
  33.         return $this->label;
  34.     }
  35.     public function setLabel($label) {
  36.         $this->label $label;
  37.     }
  38.     public function getGeoLocations() {
  39.         return $this->geoLocations;
  40.     }
  41.     public function addGeoLocation(AbstractGeoLocationBase $geoLocation) {
  42.         if (!$this->geoLocations->contains($geoLocation)) {
  43.             $this->geoLocations->add($geoLocation);
  44.             return true;
  45.         }
  46.         return false;
  47.     }
  48.     public function hasGeoLocation(AbstractGeoLocationBase $geoLocation) {
  49.         return $this->geoLocations->contains($geoLocation);
  50.     }
  51.     public function removeGeoLocation(AbstractGeoLocationBase $geoLocation) {
  52.         $this->geoLocations->removeElement($geoLocation);
  53.     }
  54.     public function getOffer() {
  55.         return $this->offer;
  56.     }
  57.     public function setOffer(Offer $offer null) {
  58.         $this->offer $offer;
  59.     }
  60.     public function jsonSerialize(): array
  61.     {
  62.         return [
  63.             'ID' => $this->ID,
  64.             'number' => $this->number,
  65.             'link' => $this->link,
  66.             'label' => $this->label
  67.         ];
  68.     }
  69.     public function getShortPhoneNumber(): string
  70.     {
  71.         $arrayNumber str_split($this->number);
  72.         $count 0;
  73.         $finalShortPhone '';
  74.         foreach ($arrayNumber as $symbol) {
  75.             $finalShortPhone .= $symbol;
  76.             if (\is_numeric($symbol)) {
  77.                 ++$count;
  78.             }
  79.             if ($count === self::COUNT_SYMBOL_DIGIT) {
  80.                 break;
  81.             }
  82.         }
  83.         return $finalShortPhone;
  84.     }
  85.     public static function fromJSON($data) {
  86.         $phoneNumber = new PhoneNumber();
  87.         $phoneNumber->setID($data->ID);
  88.         $phoneNumber->setNumber($data->number);
  89.         $phoneNumber->setLink($data->link);
  90.         $phoneNumber->setLabel($data->label);
  91.         return $phoneNumber;
  92.     }
  93. }