From 4ded6be2e893a6ff2c57baadc832690c6511f4cd Mon Sep 17 00:00:00 2001 From: Romina Suarez Date: Mon, 16 Apr 2018 19:09:06 -0300 Subject: [PATCH] =?UTF-8?q?Bugfix=20(isInActiveTargetedSurvey=20-=20Contac?= =?UTF-8?q?t)=20rename=20and=20only=20look=20for=20=E2=80=A6=20(#2767)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Bugfix (isInActiveTargetedSurvey - Contact) rename and only look for active surveys * Style(application/classes/Ushahidi/Repository/Contact.php) Fix array style --- .../classes/Ushahidi/Repository/Contact.php | 38 ++++++++++++------- src/Core/Entity/ContactRepository.php | 2 +- src/Core/Usecase/Message/ReceiveMessage.php | 2 +- .../Usecase/Message/ReceiveMessageSpec.php | 2 +- 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/application/classes/Ushahidi/Repository/Contact.php b/application/classes/Ushahidi/Repository/Contact.php index cefe2519c7..b433206b99 100644 --- a/application/classes/Ushahidi/Repository/Contact.php +++ b/application/classes/Ushahidi/Repository/Contact.php @@ -128,20 +128,30 @@ public function getByContact($contact, $type) return $this->getEntity($this->selectOne(compact('contact', 'type'))); } - public function isInTargetedSurvey($contact_id) - { - $query = DB::select('targeted_survey_state.contact_id', 'targeted_survey_state.form_id') - ->from('targeted_survey_state') - ->where('contact_id', '=', $contact_id); - - if($query->execute($this->db)->count() > 0) - { - Kohana::$log->add(Log::INFO, 'Contact is in a targeted survey: contact_id#'.print_r($contact_id, true)); - return true; - } - Kohana::$log->add(Log::INFO, 'Contact is NOT in a targeted survey: contact_id#'.print_r($contact_id, true)); - return false; - } + /** + * @param string $contact_id + * @return bool + */ + public function isInActiveTargetedSurvey($contact_id) + { + $query = DB::select('targeted_survey_state.contact_id', 'targeted_survey_state.form_id') + ->from('targeted_survey_state') + ->where('contact_id', '=', $contact_id) + ->and_where('survey_status', 'IN', + [ + Entity\TargetedSurveyState::PENDING_RESPONSE, + Entity\TargetedSurveyState::RECEIVED_RESPONSE + ] + ); + if($query->execute($this->db)->count() > 0) + { + Kohana::$log->add(Log::INFO, 'Contact is in a targeted survey: contact_id#'.print_r($contact_id, true)); + return true; + } + Kohana::$log->add(Log::INFO, 'Contact is NOT in a targeted survey: contact_id#'.print_r($contact_id, true)); + return false; + } + // ContactRepository public function getNotificationContacts($set_id, $limit = false, $offset = 0) diff --git a/src/Core/Entity/ContactRepository.php b/src/Core/Entity/ContactRepository.php index 50bbbe8739..ff33965cff 100644 --- a/src/Core/Entity/ContactRepository.php +++ b/src/Core/Entity/ContactRepository.php @@ -38,5 +38,5 @@ public function getNotificationContacts($set_id, $limit = false, $offset = 0); * @param string $contact * @return boolean */ - public function isInTargetedSurvey($contact); + public function isInActiveTargetedSurvey($contact); } diff --git a/src/Core/Usecase/Message/ReceiveMessage.php b/src/Core/Usecase/Message/ReceiveMessage.php index 2a46f3c199..04f5881675 100644 --- a/src/Core/Usecase/Message/ReceiveMessage.php +++ b/src/Core/Usecase/Message/ReceiveMessage.php @@ -307,7 +307,7 @@ protected function getContactEntity() protected function isContactInTargetedSurvey($contact_id) { - return $this->contact_repo->isInTargetedSurvey($contact_id); + return $this->contact_repo->isInActiveTargetedSurvey($contact_id); } /** diff --git a/tests/spec/Core/Usecase/Message/ReceiveMessageSpec.php b/tests/spec/Core/Usecase/Message/ReceiveMessageSpec.php index 4f15024398..a5c475db3f 100644 --- a/tests/spec/Core/Usecase/Message/ReceiveMessageSpec.php +++ b/tests/spec/Core/Usecase/Message/ReceiveMessageSpec.php @@ -70,7 +70,7 @@ private function setupMessageEntity($payload, $repo, $entity) private function tryLoadContactEntity($payload, $contact_id, $contactRepo, $contact) { // Called by ReceiveMessage::getContactEntity - $contactRepo->isInTargetedSurvey($contact_id)->willReturn((false)); + $contactRepo->isInActiveTargetedSurvey($contact_id)->willReturn((false)); $contactRepo->getByContact($payload['from'], $payload['contact_type'])->willReturn($contact); $contact->getId()->willReturn($contact_id); }