Ejemplo n.º 1
0
 public function searchContacts(SearchObject $search)
 {
     if ($search == null) {
         return null;
     }
     //search contact by name
     if ($search->getName() != null) {
         if ($search->getFirstName() != null) {
             $result = $this->getContactByName($search->getFirstName(), $search->getName());
         } else {
             echo $search->getFirstName();
             $result = $this->getContactByName(null, $search->getName());
         }
         if ($result == []) {
             return null;
         }
         return $result;
     }
     //get contact by company
     if ($search->getCompany() != null) {
         $result = $this->getContactByCompany($search->getCompany());
         if ($result == []) {
             return null;
         }
         return $result;
     }
     //search by Type
     if ($search->getTypeName() != null && $search->getAddress() == null) {
         $typeId = $this->typeService->getTypeIdByLabel($search->getTypeName());
         if ($typeId != null && $typeId != -1) {
             $result = $this->getContactByTypeId($typeId);
             if ($result == []) {
                 return null;
             }
             return $result;
         }
     }
     //search by address + rayon
     if ($search->getAddress() != null && $search->getAddress()->getLatitude() != null && $search->getAddress()->getLongitude() != null && $search->getRayon() != null && $search->getTypeName() == null) {
         $result = $this->getContactsbyAddressAndRayon($search->getAddress(), $search->getRayon(), null, null);
         if ($result == []) {
             return null;
         }
         return $result;
     }
     //search by type + address + rayon
     if ($search->getAddress() != null && $search->getAddress()->getLatitude() != null && $search->getAddress()->getLongitude() != null && $search->getRayon() != null && $search->getTypeName() != null) {
         $typeId = $this->typeService->getTypeIdByLabel($search->getTypeName());
         if ($typeId != null && $typeId != -1) {
             $result = $this->getContactsbyAddressAndRayon($search->getAddress(), $search->getRayon(), $typeId, null);
             if ($result == []) {
                 return null;
             }
             return $result;
         }
     }
     //search by company + address + rayon
     if ($search->getAddress() != null && $search->getAddress()->getLatitude() != null && $search->getAddress()->getLongitude() != null && $search->getRayon() != null && $search->getCompany() != null) {
         $result = $this->getContactsbyAddressAndRayon($search->getAddress(), $search->getRayon(), null, $search->getCompany());
         if ($result == []) {
             return null;
         }
         return $result;
     }
     return null;
 }