/** * Sets the $matches and $number_of_matches properties * * Executes the FindMatchingContact stored procedure via MinistryPlatform. * Also allows users to override the default stored procedure and the * parameters passed to the stored procedure. * * @param string $sp The name of the "Find Matching Contacts" Stored Procedure * * @return $this */ protected function setMatches() { $matching_fields = ["FirstName" => $this->first_name, "LastName" => $this->last_name]; $matching_fields = array_merge($matching_fields, $this->optional_fields); $this->matches = $this->mp->storedProcedure($this->sp, $matching_fields); if ($this->matches->getTableCount() > 0) { foreach ($this->matches->getTable(0) as $item) { if (is_array($item)) { $this->number_of_matches = count($this->matches->getTable(0)); } else { $this->number_of_matches = 1; } break; } } else { $this->number_of_matches = 0; } return $this; }