public function saveContactDetail(Doctor $doctor)
 {
     $contactIdsArray = array();
     $contactNumberArray = \json_decode($doctor->getContactNumber(), true);
     if (\is_array($contactNumberArray)) {
         if (isset($contactNumberArray['country_code'])) {
             $contactDetail = new ContactDetail();
             $contactDetail->setCountryCode(isset($contactNumberArray['country_code']) ? $contactNumberArray['country_code'] : NULL);
             $contactDetail->setAreaCode(isset($contactNumberArray['area_code']) ? $contactNumberArray['area_code'] : NULL);
             $contactDetail->setNumber($contactNumberArray['number']);
             $contactDetail->setType(ContactDetailTypes::PHONE);
             $doctor->addContactDetail($contactDetail);
         } else {
             foreach ($contactNumberArray as $each) {
                 if ($each['number']) {
                     $contactDetail = new ContactDetail();
                     $contactDetail->setNumber($each['number']);
                     $contactDetail->setType($this->getContactDetailType($each['type']));
                     $doctor->addContactDetail($contactDetail);
                 }
             }
         }
     }
     return $doctor;
 }
 public function saveContactDetail(InstitutionMedicalCenter $center)
 {
     $contactIdsArray = array();
     $contactNumber = $center->getContactNumber();
     $contactNumber = \json_decode($center->getContactNumber(), true);
     if (\is_array($contactNumber)) {
         if (isset($contactNumber['number'])) {
             $contactDetail = new ContactDetail();
             $contactDetail->setNumber(isset($contactNumber['country_code']) ? $contactNumber['country_code'] : '');
             $contactDetail->setAreaCode(isset($contactNumber['area_code']) ? $contactNumber['area_code'] : '');
             $contactDetail->setNumber($contactNumber['number']);
             $contactDetail->setType(ContactDetailTypes::PHONE);
             $center->addContactDetail($contactDetail);
         }
     }
     return $center;
 }
 public function contactDetailsToJSON(array $contactDetails = array())
 {
     $byType = array();
     foreach ($contactDetails as $contactDetailData) {
         if ($contactDetailData instanceof ContactDetail) {
             $contactDetailInstance = $contactDetailData;
         } elseif (\is_array($contactDetailData)) {
             // hydrated as array
             $contactDetailInstance = new ContactDetail();
             $contactDetailInstance->setCountryCode($contactDetailData['countryCode']);
             $contactDetailInstance->setAreaCode($contactDetailData['areaCode']);
             $contactDetailInstance->setNumber($contactDetailData['number']);
             $contactDetailInstance->setType($contactDetailData['type']);
         } else {
             // unknown type that we can't handle
             continue;
         }
         $byType[$contactDetailInstance->getType()] = array('type' => ContactDetailTypes::getTypeLabel($contactDetailInstance->getType()), 'number' => $contactDetailInstance->__toString());
     }
     if (!\count($byType)) {
         return null;
     }
     return \json_encode($byType);
 }
 public function contactDetailToString($contactDetail)
 {
     $contactDetailInstance = null;
     if ($contactDetail instanceof ContactDetail) {
         $contactDetailInstance = $contactDetail;
     } elseif (\is_array($contactDetail)) {
         // hydrated as array
         $contactDetailInstance = new ContactDetail();
         $contactDetailInstance->setCountryCode($contactDetail['countryCode']);
         $contactDetailInstance->setAreaCode($contactDetail['areaCode']);
         $contactDetailInstance->setNumber($contactDetail['number']);
         $contactDetailInstance->setType($contactDetail['type']);
     }
     return $contactDetailInstance ? $contactDetailInstance->__toString() : null;
 }
 private function doCleanUp(ContactDetail $contactDetail, $oldContactNumber = null, Country $country = null)
 {
     if ($oldContactNumber) {
         $oldContactDetail = $contactDetail->__toString();
         $parts = \json_decode($oldContactNumber, true);
         if ($parts) {
             $countryCode = isset($parts['country_code']) ? $parts['country_code'] : null;
             $areaCode = isset($parts['area_code']) ? $parts['area_code'] : null;
             $contactDetail->setCountryCode($countryCode);
             $contactDetail->setAreaCode($areaCode);
             $number = $parts['number'];
         }
     } else {
         // this data must have been entered through the new widget, we need them to verify this data
         $contactDetail->setFromNewWidget(true);
         $number = $contactDetail->getNumber();
     }
     if (!\is_numeric($number)) {
         $number = \preg_replace('/\\D/', '', $number);
     }
     $number = (int) $number;
     $contactDetail->setNumber($number);
     if (!$number || strlen($number) < 5) {
         $contactDetail->setIsInvalid(true);
     }
 }