public function __construct()
 {
     $this->_accessKey = '88b43206bc04bb027f1e14ab428ac830';
     $this->_secret = 'b316e31501577669aac92578252053e5';
     $this->token = '4e6c3665df07a9905e28467c551355a5a1';
     $objServerInfo = new \services\helpers\ServerInfo();
     $this->_serviceurl = $objServerInfo->getScheme() . "://" . $objServerInfo->getHost() . APPLICATION_BASE;
 }
 /** Function to get dog Profile 
  * @param  int $dogId id of the dog
  * @return array
  **/
 public function getDogProfile($dogId)
 {
     $dog = $this->_redbeans->load($this->_name, $dogId);
     if ($dog) {
         $objServerInfo = new \services\helpers\ServerInfo();
         $dogProfile = $dog->export(false);
         $dogUrl = $objServerInfo->getScheme() . "://" . $objServerInfo->getHost() . APPLICATION_BASE . 'dogimages/' . $dog['dog_pic'];
         $picPath = APPLICATION_DIR . "/dogimages/{$dog['dog_pic']}";
         $dogProfile['dog_pic'] = @is_file($picPath) ? $dogUrl : null;
         return $dogProfile;
     }
     return array();
 }
 /**
  *Function to search having with given location
  * @param  string $query location for which experts are to be searched
  * @return array
  * **/
 public function searchUsersByLocation($query)
 {
     $sql = "SELECT u.id,u.first_name,u.last_name ,u.phone ,GROUP_CONCAT(p.name) as speciality " . "FROM `users` u " . "INNER JOIN `users_profiles` up ON u.id = up.users_id " . "INNER JOIN profiles p ON up.profiles_id = p.id " . "WHERE city LIKE :query OR country LIKE :query OR address LIKE :query " . "GROUP BY u.id";
     $profiles = \R::getAll($sql, array(':query' => "%{$query}%"));
     $objServerInfo = new \services\helpers\ServerInfo();
     $usersProfiles = array();
     foreach ($profiles as $profile) {
         $profilepic = $objServerInfo->getScheme() . "://" . $objServerInfo->getHost() . APPLICATION_BASE . 'images/' . $profile['id'] . '_pp.jpg';
         $picPath = APPLICATION_DIR . "/images/{$profile['id']}_pp.jpg";
         $profile['profilepic'] = @is_file($picPath) ? $profilepic : null;
         $profile['speciality'] = explode(",", $profile['speciality']);
         $usersProfiles[] = $profile;
     }
     return $usersProfiles;
 }
 /**
  * Public function to get nearby events
  * @param string $longitude longitude of current user location
  * @param string $latitude  latitude of current user location
  * @return array
  * **/
 public function getEventNearbyEvents($longitude, $latitude)
 {
     $qry = "SELECT e.*,(((acos(sin((:lat*pi()/180)) * \r\n             sin((e.`Latitude`*pi()/180))+cos((:lat*pi()/180)) * \r\n             cos((e.`Latitude`*pi()/180)) * cos(((:long- e.`Longitude`)* \r\n             pi()/180))))*180/pi())*60*1.1515\r\n        ) as distance ,u.first_name,u.last_name,u.id as userid,\r\n        COUNT( IF( upe.participation_id = 1, 1, NULL ) ) as num_users_psyes,COUNT( IF( upe.participation_id = 3, 1, NULL ) )as num_users_psmaybe\r\n        FROM `events` e\r\n        INNER JOIN users u on u.id = e.users_id\r\n        LEFT JOIN `users_events_participation` upe ON upe.events_id = e.id\r\n        GROUP BY e.id\r\n        HAVING distance <= 19 ORDER BY distance";
     // distance in miles 30 kms
     $rowset = \R::getAll($qry, array(':lat' => $latitude, ':long' => $longitude));
     $return = array();
     $objServerInfo = new \services\helpers\ServerInfo();
     if ($rowset) {
         foreach ($rowset as $row) {
             unset($row['status']);
             unset($row['users_id']);
             unset($row['distance']);
             $profileUrl = $objServerInfo->getScheme() . "://" . $objServerInfo->getHost() . '/images/' . $row['userid'] . "_pp.jpg";
             $profilePic = @getimagesize($profileUrl) ? $profileUrl : null;
             $row['profilepic'] = $profilePic;
             $return[] = $row;
         }
     }
     return $return;
 }
 /**
  * Function to get dogs owned by user
  * @param int $userId id of the user
  * @return array 
  * **/
 public function getUserOwnedDogs($userId)
 {
     $query = "SELECT d.id as dogid,dog_pic,name,gender,date_of_birth,dog_breed_id,db.breed_name " . "FROM dogs d " . "INNER JOIN dog_breed db ON db.id = d.dog_breed_id " . "WHERE users_id = :userid";
     $userOwnedDogs = \R::getAll($query, array(':userid' => $userId));
     $return = array();
     $objServerInfo = new \services\helpers\ServerInfo();
     foreach ($userOwnedDogs as $dog) {
         $dogUrl = $objServerInfo->getScheme() . "://" . $objServerInfo->getHost() . APPLICATION_BASE . 'dogimages/' . $dog['dog_pic'];
         $picPath = APPLICATION_DIR . "/dogimages/{$dog['dog_pic']}";
         $dog['dog_pic'] = @is_file($picPath) ? $dogUrl : null;
         $return[] = $dog;
     }
     return $return;
 }