/** * Checks whether there are any business like the one being saved * * Rules for finding if two business are duplicates. If any one of the below * mentioned rules are satisfied, then the business data passed in as $data * param is a duplicate business. * * 1) Any business already saved should not have atleast one mobile number * same as the business being uploaded and status of business is * BUSINESS_VERIFIED_COMPLETE. * 2) Any business already saved should not have atleast one landline number * same as the business being uploaded and status of business is * BUSINESS_VERIFIED_COMPLETE. */ public static function exists($data) { $mobile_number = $data["mobile_number"]; $domain_name = Environment::getCoreAttirbutesDomain(); $mobile_number = CoreAttributesUtils::implode($mobile_number); $query = "SELECT status FROM {$domain_name} WHERE mobile_number " . "IN ({$mobile_number}) "; $result = SimpleDbPersister::select($query); $items = $result["Items"]; if (isset($items) === TRUE && $items[0]["Attributes"][0]["Value"] == "BUSINESS_VERIFIED_COMPLETE") { return TRUE; } //Landline number not set, so no need to check if (isset($data["landline_number"]) === FALSE) { return FALSE; } $landline_number = $data["landline_number"]; $landline_number = CoreAttributesUtils::implode($landline_number); $query = "SELECT status FROM {$domain_name} WHERE landline_number " . "IN ({$landline_number}) "; $result = SimpleDbPersister::select($query); $items = $result["Items"]; if (isset($items) === TRUE && $items[0]["Attributes"]["Value"] == "BUSINESS_VERIFIED_COMPLETE") { return TRUE; } return FALSE; }
return; } //If a new business entry, check whether it exists already if ($is_update_operation === FALSE && CoreAttributesUtils::exists($data) === TRUE) { $error_json = array("status" => "error", "error" => "Business already exists"); echo json_encode($error_json); return; } //If an update operation, don't re-generate business_id and set $replace to true if ($is_update_operation === TRUE) { $attributes = SimpleDbUtils::genSimpleDbAttributesArray($data, true); } else { $is_busines_id_already_taken = false; /* Check whether the unique business id that is generated is already not * taken. */ do { $business_id = BusinessIdGenerator::generate($data["pincode"]); $data["business_id"] = $business_id; $result = SimpleDbPersister::getAttributes($domain_name, $business_id, array("business_id")); $is_business_id_already_taken = empty($result) ? false : true; } while ($is_business_id_already_taken === TRUE); $attributes = SimpleDbUtils::genSimpleDbAttributesArray($data); } $message = CoreAttributesUtils::generateSMSMessage($data); SMS::send($sms_number, $message); $business_id = $data["business_id"]; SimpleDbPersister::save($domain_name, $business_id, $attributes); $success_json = array("status" => "success", "business_id" => $business_id, "created_by_user" => $data["created_by_user"], "created_time" => $data["created_time"]); echo json_encode($success_json); return;