/**
  * 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;
 }
 public function getAllCategories()
 {
     $domain_name = $this->_domain_name;
     $query = "SELECT category FROM {$domain_name}";
     $next_token = "";
     $categories = array();
     do {
         $response = SimpleDbPersister::select($query, $next_token);
         $next_token = $response['NextToken'];
         $fetched_records = $response['Items'];
         foreach ($fetched_records as $index => $record) {
             array_push($categories, $record["Attributes"][0]["Value"]);
         }
     } while (empty($next_token) === FALSE);
     return $categories;
 }
 /**
  *	Query the simple DB
  *
  *	@param $query The simple db query to execute
  *
  *	@return $output Array of associative array. The keys in the
  *					associative array are the columns that are extracted
  *					from the query
  */
 private function query($query)
 {
     $output = array();
     $next_token = "";
     do {
         $result = SimpleDbPersister::select($query, $next_token);
         $items = $result["Items"];
         $next_token = $result["NextToken"];
         foreach ($items as $item) {
             $business_id = $item["Name"];
             $attributes = $item["Attributes"];
             $business_item = BusinessUtils::toArray($attributes);
             if (is_null($business_item) === TRUE) {
                 continue;
             }
             $output[$business_id] = $business_item;
         }
     } while (isset($next_token) === TRUE);
     return $output;
 }