findDonor: initial implementation.
This seems to work and all existing tests for it pass: ok 134 - findDonor: no search criteria dies ok 135 - findDonor: 1 lookup of known missing succeeds ... ok 136 - findDonor: ... but finds nothing. ok 137 - findDonor: 2 lookup of known missing succeeds ... ok 138 - findDonor: ... but finds nothing. ok 139 - findDonor: 1 and'ed criteria succeeds ... ok 140 - findDonor: ... but finds nothing. ok 141 - findDonor: 2 and'ed criteria succeeds ... ok 142 - findDonor: ... but finds nothing. ok 143 - findDonor: 1 valid multiple criteria succeeds ... ok 144 - findDonor: ... and finds right entry. ok 145 - findDonor: 2 valid multiple criteria succeeds ... ok 146 - findDonor: ... and finds right entry. ok 147 - findDonor: 3 valid multiple criteria succeeds ... ok 148 - findDonor: ... and finds right entry. ok 149 - findDonor: single criteria find expecting multiple records succeeds... ok 150 - findDonor: ... and finds the right entires.
This commit is contained in:
		
							parent
							
								
									7e6e96d95f
								
							
						
					
					
						commit
						cb38348048
					
				
					 1 changed files with 64 additions and 0 deletions
				
			
		|  | @ -893,6 +893,70 @@ sub fulfillRequest($$) { | ||||||
|   } |   } | ||||||
|   return $fulfillRecord->{$requestId}{id}; |   return $fulfillRecord->{$requestId}{id}; | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | ###################################################################### | ||||||
|  | 
 | ||||||
|  | =begin findDonor | ||||||
|  | 
 | ||||||
|  | Arguments: | ||||||
|  | 
 | ||||||
|  | =over | ||||||
|  | 
 | ||||||
|  | =item $parmas | ||||||
|  | 
 | ||||||
|  | A hash reference, the following keys are considered, and are "anded" together | ||||||
|  | -- in that the donor sought must have all these criteria to be found. | ||||||
|  | 
 | ||||||
|  | =over | ||||||
|  | 
 | ||||||
|  | =item emailAddress | ||||||
|  | 
 | ||||||
|  |    A string containing an email_address from email_address table. | ||||||
|  | 
 | ||||||
|  | =item ledgerEntityId | ||||||
|  | 
 | ||||||
|  |    A string containing a ledger_entity_id from the donor table. | ||||||
|  |    undefined.  undef is returned if there is no unfulfilled request of | ||||||
|  |    requestType in the database for supporter identified by | ||||||
|  |    C<$params->{donorId}> | ||||||
|  | 
 | ||||||
|  | =back | ||||||
|  | 
 | ||||||
|  | =back | ||||||
|  | 
 | ||||||
|  | Returns a list of donorIds that meets the criteria, or none if not found. | ||||||
|  | 
 | ||||||
|  | =cut | ||||||
|  | 
 | ||||||
|  | sub findDonor($$) { | ||||||
|  |   my($self, $params) = @_; | ||||||
|  |   die "findDonor: no search criteria given" | ||||||
|  |     unless defined $params->{ledgerEntityId} or defined $params->{emailAddress}; | ||||||
|  | 
 | ||||||
|  |   my @donorIds; | ||||||
|  |   if (not defined $params->{emailAddress}) { | ||||||
|  |     my $ledgerEntityId = $params->{ledgerEntityId}; | ||||||
|  |     # Simple case: just lookup without a join. | ||||||
|  |     my $val = $self->dbh()->selectall_hashref("SELECT id, ledger_entity_id from donor where ledger_entity_id = " . | ||||||
|  |                                               $self->dbh->quote($ledgerEntityId), | ||||||
|  |                                               "ledger_entity_id"); | ||||||
|  |     # As Connor MacLeod said,  "There can be only one!" | ||||||
|  |     #  (because of  "ledger_entity_id" varchar(300) NOT NULL UNIQUE,) | ||||||
|  |     push(@donorIds, $val->{$ledgerEntityId}{id}) | ||||||
|  |       if (defined $val and defined $val->{$ledgerEntityId} and defined $val->{$ledgerEntityId}{id}); | ||||||
|  |   } else { | ||||||
|  |     my $sql = "SELECT d.id from donor d, email_address ea, donor_email_address_mapping eam " . | ||||||
|  |               "WHERE eam.email_address_id = ea.id AND d.id = eam.donor_id AND " . | ||||||
|  |               "ea.email_address = " . $self->dbh->quote($params->{emailAddress}); | ||||||
|  | 
 | ||||||
|  |     $sql .= " AND d.ledger_entity_id = " . $self->dbh->quote($params->{ledgerEntityId}) | ||||||
|  |       if (defined $params->{ledgerEntityId}); | ||||||
|  | 
 | ||||||
|  |     my $val = $self->dbh()->selectall_hashref($sql, 'id'); | ||||||
|  |     push(@donorIds, keys %{$val}) if (defined $val); | ||||||
|  |   } | ||||||
|  |   return(@donorIds); | ||||||
|  | } | ||||||
| ###################################################################### | ###################################################################### | ||||||
| 
 | 
 | ||||||
| =back | =back | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Bradley M. Kuhn
						Bradley M. Kuhn