Example #1
0
 public static function from_age($age)
 {
     # Take a person's age (int) and return a new DOB object
     # suitable for him.
     return PiplApi_DOB::from_age_range($age, $age);
 }
Example #2
0
 public function __construct($search_params = array(), $configuration = NULL)
 {
     // Initiate a new request object with given query params.
     //
     // Each request must have at least one searchable parameter, meaning
     // a name (at least first and last name), email, phone or username.
     // Multiple query params are possible (for example querying by both email
     // and phone of the person).
     //
     // Args:
     //
     // first_name -- string, minimum 2 chars.
     // middle_name -- string.
     // last_name -- string, minimum 2 chars.
     // raw_name -- string, an unparsed name containing at least a first name
     //             and a last name.
     // email -- string.
     // phone -- string. A raw phone number.
     // username -- string, minimum 4 chars.
     // country -- string, a 2 letter country code from:
     //            http://en.wikipedia.org/wiki/ISO_3166-2
     // state -- string, a state code from:
     //          http://en.wikipedia.org/wiki/ISO_3166-2%3AUS
     //          http://en.wikipedia.org/wiki/ISO_3166-2%3ACA
     // city -- string.
     // raw_address -- string, an unparsed address.
     // from_age -- int.
     // to_age -- int.
     // person -- A PiplApi::Person object (available at containers.php).
     //           The person can contain every field allowed by the data-model
     //           (fields.php) and can hold multiple fields of
     //           the same type (for example: two emails, three addresses etc.)
     // search_pointer -- a pointer from a possible person, received from an API response object.
     //
     // Each of the arguments that should have a string that accepts both
     // strings.
     # Set default configuration
     if (is_null(self::$default_configuration)) {
         self::$default_configuration = new PiplApi_SearchRequestConfiguration();
     }
     $person = !empty($search_params['person']) ? $search_params['person'] : new PiplApi_Person();
     if (!empty($search_params['first_name']) || !empty($search_params['middle_name']) || !empty($search_params['last_name'])) {
         $first = !empty($search_params['first_name']) ? $search_params['first_name'] : NULL;
         $last = !empty($search_params['last_name']) ? $search_params['last_name'] : NULL;
         $middle = !empty($search_params['middle_name']) ? $search_params['middle_name'] : NULL;
         $name = new PiplApi_Name(array('first' => $first, 'middle' => $middle, 'last' => $last));
         $person->add_fields(array($name));
     }
     if (!empty($search_params['raw_name'])) {
         $person->add_fields(array(new PiplApi_Name(array('raw' => $search_params['raw_name']))));
     }
     if (!empty($search_params['email'])) {
         $person->add_fields(array(new PiplApi_Email(array('address' => $search_params['email']))));
     }
     if (!empty($search_params['phone'])) {
         $person->add_fields(array(PiplApi_Phone::from_text($search_params['phone'])));
     }
     if (!empty($search_params['username'])) {
         $person->add_fields(array(new PiplApi_Username(array('content' => $search_params['username']))));
     }
     if (!empty($search_params['country']) || !empty($search_params['state']) || !empty($search_params['city'])) {
         $country = !empty($search_params['country']) ? $search_params['country'] : NULL;
         $state = !empty($search_params['state']) ? $search_params['state'] : NULL;
         $city = !empty($search_params['city']) ? $search_params['city'] : NULL;
         $address = new PiplApi_Address(array('country' => $country, 'state' => $state, 'city' => $city));
         $person->add_fields(array($address));
     }
     if (!empty($search_params['raw_address'])) {
         $person->add_fields(array(new PiplApi_Address(array('raw' => $search_params['raw_address']))));
     }
     if (!empty($search_params['from_age']) || !empty($search_params['to_age'])) {
         $dob = PiplApi_DOB::from_age_range(!empty($search_params['from_age']) ? $search_params['from_age'] : 0, !empty($search_params['to_age']) ? $search_params['to_age'] : 1000);
         $person->add_fields(array($dob));
     }
     if (!empty($search_params['search_pointer'])) {
         $person->search_pointer = $search_params['search_pointer'];
     }
     $this->person = $person;
     $this->configuration = $configuration;
 }