Skip to content

Commit

Permalink
Bugfix (isInActiveTargetedSurvey - Contact) rename and only look for … (
Browse files Browse the repository at this point in the history
#2767)

* Bugfix (isInActiveTargetedSurvey - Contact) rename and only look for active surveys

* Style(application/classes/Ushahidi/Repository/Contact.php) Fix array style
  • Loading branch information
rowasc authored Apr 16, 2018
1 parent e3777f2 commit 4ded6be
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
38 changes: 24 additions & 14 deletions application/classes/Ushahidi/Repository/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Entity/ContactRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion src/Core/Usecase/Message/ReceiveMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/spec/Core/Usecase/Message/ReceiveMessageSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 4ded6be

Please sign in to comment.