Class PolarDbQuery

Description

Class to query / update database to get various data

(day info, exercises, stats, ...)

Located in /class/PolarDbQuery.class.php (line 17)


	
			
Method Summary
void PolarDbQuery ()
boolean activate_user (integer $user_id, string $activ_code)
boolean change_user_password (integer $user_id, string $old_password, string $new_password)
boolean delete_day_info (integer $user_id, string $day)
boolean delete_exercise_by_day_rank (integer $user_id, string $day, integer $rank)
boolean delete_exercise_by_id (integer $id)
array get_day_info (integer $user_id, string $day)
array get_exercises_by_sport (integer $user_id, string $min_day, [string $max_day = null], [boolean $detail = true])
array get_exercises_stats (array $params, integer &$sum_nb_exe)
array get_exercise_info (integer $exe_id)
array get_exercise_laps (integer $exe_id, [string $lap_type = null])
array get_exercise_stats (integer $exe_id)
array get_global_stats (array $params)
array get_interval_training (integer $exe_id)
array get_last_exercises_summary ([array $params = null])
array get_last_members_summary ([array $params = null])
string get_read_rights (integer $publish_user_id, integer $logged_user_id, string &$nickname)
array get_stats_for_period (integer $user_id, string $min_day, string $max_day)
array get_user_info (integer $user_id)
array get_user_preferences (integer $user_id)
boolean insert_user (array $info, integer &$user_id, string &$activ_code)
array login_user (string $email, string $password, [ $email_cookie = false], [ $password_cookie = false])
boolean set_user_preferences (integer $user_id, array $prefs)
boolean update_user_info (integer $user_id, array $info)
Methods
Constructor PolarDbQuery (line 24)

Class constructor

void PolarDbQuery ()
activate_user (line 164)

Activate a new user

  • return: true on success, else false
boolean activate_user (integer $user_id, string $activ_code)
  • integer $user_id: ID of user to activate
  • string $activ_code: Activation code (32 chars)
change_user_password (line 113)

Update user password

  • return: true on success, else false
boolean change_user_password (integer $user_id, string $old_password, string $new_password)
  • integer $user_id: User ID
  • string $old_password: Old (current) user password
  • string $new_password: New user password
delete_day_info (line 899)

Delete day info from database (by user ID and day)

  • return: true on success, else false (no day info)
boolean delete_day_info (integer $user_id, string $day)
  • integer $user_id: User ID
  • string $day: day of day info (format : YYYY-MM-DD)
delete_exercise_by_day_rank (line 917)

Delete exercise and all related data from database by user ID, day, and rank

Note : Get exercise ID, then calls delete_exercise_by_id().

  • return: true on success, else false (no exercise)
boolean delete_exercise_by_day_rank (integer $user_id, string $day, integer $rank)
  • integer $user_id: User ID
  • string $day: day of exercise (format : YYYY-MM-DD)
  • integer $rank: Rank of exercise within day
delete_exercise_by_id (line 943)

Delete exercise and all related data from database by exercise ID

Note : Related data in tables :

  • plw_data : Exercise data as in HRM file (if recorded)
  • plw_stat : Exercise statistics (if recorded)
  • plw_int_training : Interval training elements (if type is int_training)
  • plw_lap : Exercise laps

  • return: true on success, else false (no exercise)
boolean delete_exercise_by_id (integer $id)
  • integer $id: Exercise ID
get_day_info (line 379)

Get day information data for a user

  • return: Day information (associative array with plw_day_info SQL table structure)
array get_day_info (integer $user_id, string $day)
  • integer $user_id: User ID
  • string $day: Day (format : YYYY-MM-DD)
get_exercises_by_sport (line 450)

Get exercises summary + sum / avg / max by sport within a period

Used to compute weekly statistics for instance.

Consider exercises in reports only.

  • return: Indexed by sport ID. For each sport :
    • 'nb' : Number of exercises
    • 'exe' : Array of exercises
    • 'elapsed' : Total duration in seconds * 10
    • 'real_distance' : Total real distance in meters
    • 'running_index' : Average Polar running index
    • 'max_hr' : Maximum heart rate in bpm
    • 'max_speed' : Maximum speed rate in km/h * 10
    • 'avg_cadence' : Average cadence in cycles / minute
    • 'max_cadence' : Maximum cadence in cycles / minute
    • 'ascend' : Total ascend in meters
    • 'energy' : Total energy -Polar- in Kcal
    • 'physio_energy' : Total physio energy -f(HR)- in Kcal
    • 'beat_sum' : Total number of heart beats
    For each exercise in 'exe' (if $detail = true) :
    • 'day' : Day of exercise (format : YYYY-MM-DD)
    • 'rank' : Rank of exercise in day
    • 'start_time' : Start time (format : HH:MM:SS)
    • 'elapsed' : Total duration in seconds * 10
    • 'real_distance' : Total real distance in meters
    • 'running_index' : Average Polar running index
    • 'max_hr' : Maximum heart rate in bpm
    • 'max_speed' : Maximum speed rate in km/h * 10
    • 'avg_cadence' : Average cadence in cycles / minute
    • 'max_cadence' : Maximum cadence in cycles / minute
    • 'ascend' : Total ascend in meters
    • 'energy' : Total energy -Polar- in Kcal
    • 'physio_energy' : Total physio energy -f(HR)- in Kcal
    • 'beat_sum' : Total number of heart beats
    • 'exercise_type' : exe type in ('training','contest')
array get_exercises_by_sport (integer $user_id, string $min_day, [string $max_day = null], [boolean $detail = true])
  • integer $user_id: User ID
  • string $min_day: First day in period (format : YYYY-MM-DD)
  • string $max_day: Last day in period (format : YYYY-MM-DD) If null, then period ends at current date.
  • boolean $detail: true to get exercises summary, else false
get_exercises_stats (line 833)

Get global statistics about online exercises

Consider all active members. Consider all online exercises having a matching sport ID (even unknown).

  • return: Associative array of records indexed by publish status ('all' if not splitted), 'public' and 'public-but-desc' are grouped as 'public'. then by sport index ('all' if not splitted). Each record is an associative array :
    • 'nb' => Number of exercises
    • 'elapsed' => Sum of exercices duration in seconds x 10
    • 'distance' => Sum of exercices distance in meters
    • 'ascend' => Sum of exercices ascend in meters
    Array is sorted by publish status, then by decreasing number of exercises for each sport.
array get_exercises_stats (array $params, integer &$sum_nb_exe)
  • array $params: Associative array of parameters :
    • 'max_age' : Only exercises newer than <max_age> days
    • 'min_elapsed' : Only exercises during at least <min_elapsed> minutes
    • 'publish_list' : Array of publish status to filter ('public' => 'public' or 'public-but-desc')
    • 'by_publish' : Split by publish status if true
    • 'sport_list' : Array of sport indexes to filter
    • 'by_sport' : Split by sport index if true
  • integer &$sum_nb_exe: Total nb of matching exercises
get_exercise_info (line 397)

Get exercise information

  • return: Exercise information (associative array with plw_exercise SQL table structure)
array get_exercise_info (integer $exe_id)
  • integer $exe_id: Exercise ID
get_exercise_laps (line 502)

Get all laps in an exercise

  • return: Array of laps indexed by lap number from 1. Each lap is an associative array with plw_lap SQL table structure. If $lap_type is null, associative array of lap types.
array get_exercise_laps (integer $exe_id, [string $lap_type = null])
  • integer $exe_id: Exercise ID
  • string $lap_type: Lap type in ('polar','distance','altitude','interval'). If null, all types are returned.
get_exercise_stats (line 566)

Get statistics for an exercise

Statistics are for heart rate, speed, cadence, and stride length depending on s_mode while recording.

  • return: Array of statistics indexed by type in ('hr','speed','cadence','stride'). For each type, statistics is an array of <value> => <nb of occurences in exercise>. <value> is bpm for 'hr', km/h * 10 for 'speed', cycles / minute for 'cadence', cm for 'stride'.
array get_exercise_stats (integer $exe_id)
  • integer $exe_id: Exercise ID
get_global_stats (line 750)

Get global statistics about active members / online exercises

Consider all active members. Consider all online exercises (even with none matching sport ID)

  • return: Associative arrays of records :
    • 'mbr' : active member count indexed by
    publish status ('all' if not splitted), 'public' and 'public-but-desc' are grouped as 'public'. Each record is an associative array :
    • 'nb' => Number of active members
    • 'exe' : Exercise count indexed by
    publish status ('all' if not splitted), 'public' and 'public-but-desc' are grouped as 'public'. Each record is an associative array :
    • 'nb' => Number of exercises
    • 'elapsed' => Sum of exercices duration in seconds x 10
    Both arrays are sorted by publish status;
array get_global_stats (array $params)
  • array $params: Associative array of parameters :
    • 'publish_list' : Array of publish status to filter ('public' => 'public' or 'public-but-desc')
    • 'by_publish' : Split by publish status if true
get_interval_training (line 535)

Get interval training elements in an exercise

  • return: Array of interval training elements indexed from 0. Each element is an associative array with plw_int_training SQL table structure.
array get_interval_training (integer $exe_id)
  • integer $exe_id: Exercise ID
get_last_exercises_summary (line 709)

Get last exercises of all public (and active) users.

Last means most recent exercise date / time. Exercises are sorted from most recent to less recent. Consider all online exercises having a matching sport ID (even unknown).

  • return: Array of exercises indexed from 0. Each exercise is an associative array :
    • 'user_id' : User ID
    • 'nickname' : User nickname
    • 'gender' : User gender in ('male','female')
    • 'birthdate' : User birthdate (YYYY-MM-DD)
    • 'weather' : Weather string
    • 'temperature' : Temperature in Celcius x 10
    • 'sport_index' : Sport index string
    • 'sport_name' : Sport name in case sport is unknown
    • 'exe_id' : Exercise ID
    • 'exe_type' : Exercise type string
    • 'day' : Exercise date (YYYY-MM-DD format)
    • 'start_time' : Exercise start time (HH:MI:SS format)
    • 'title' => Exercise title
    • 'monitor_type' => HR Monitor ID (polar_monitors.php)
    • 's_mode' => List of data measured (comma sep)
    • 'elapsed' => Exercice duration in seconds x 10
    • 'distance' => Exercice distance in meters
    • 'ascend' => Ascend in meters
array get_last_exercises_summary ([array $params = null])
  • array $params: Associative array of parameters :
    • 'max_exe' : Maximum number of exercises to return
    • 'max_age' : Only exercises newer than <max_age> days
    • 'min_elapsed' : Only exercises during at least <min_elapsed> minutes
get_last_members_summary (line 627)

Get last active and public members

Last means most recent members (registration date). Members are sorted from most recent to less recent.

  • return: Array of members indexed from 0. Each member is an associative array :
    • 'user_id' : User ID
    • 'nickname' : User nickname
    • 'gender' : User gender in ('male','female')
    • 'birthdate' : User birthdate (YYYY-MM-DD)
    • 'reg_date' : registration date (YYYY-MM-DD)
    • 'exe_nb' : Number of online exercises
array get_last_members_summary ([array $params = null])
  • array $params: Associative array of parameters :
    • 'max_mbr' : Maximum number of members to return
    • 'max_age' : Only members newer than <max_age> days
    • 'min_exe' : Only public members with at least <min_exe> public exercises are considered.
get_read_rights (line 261)

Get read rights on one user booknote for another user (or anonymous reader)

  • return: Read rights, one of :
    • null : <publish_user_id> does not exist
    • 'private' : No read rights
    • 'public' : Read rights
    • 'public-but-desc' : Read rights except descriptions
  • todo: Return day info display flag
  • todo: Add groups rights
string get_read_rights (integer $publish_user_id, integer $logged_user_id, string &$nickname)
  • integer $publish_user_id: ID of user owner of booknote
  • integer $logged_user_id: ID uf user logged in (null if anonymous)
  • string &$nickname: Nickname of <publish_user_id> user
get_stats_for_period (line 594)

Get statistics for all exercises within a period

Used to compute weekly statistics for instance.

Consider exercises in reports only.

Statistics are for heart rate, speed, cadence, and stride length depending on s_mode while recording.

  • return: Array of statistics as in get_exercise_stats().
array get_stats_for_period (integer $user_id, string $min_day, string $max_day)
  • integer $user_id: User ID
  • string $min_day: First day in period (format : YYYY-MM-DD)
  • string $max_day: Last day in period (format : YYYY-MM-DD)
get_user_info (line 35)

Get user information data

  • return: User information (associative array with plw_user SQL table structure)
array get_user_info (integer $user_id)
  • integer $user_id: User ID
get_user_preferences (line 300)

Get user preferences

  • return: User preferences : Associative array of preferences :
    • 'mailing_lists' : List of mailing lists
    • 'display_width' : Browser width in pixels
    • 'display_day_info' : Flag to display day info or not
    • 'home_exes_sums' : To display exes stats in home page
array get_user_preferences (integer $user_id)
  • integer $user_id: User ID
insert_user (line 138)

Create a new user (with inactive status)

  • return: true on success, else false
boolean insert_user (array $info, integer &$user_id, string &$activ_code)
  • array $info: Associative array of user fields :
    • 'nickname' : User nickname
    • 'email' : User email address
    • 'password' : User password
    • 'publish' : Publish status
  • integer &$user_id: ID of user created
  • string &$activ_code: Activation code (32 chars MD5 generated)
login_user (line 55)

Login user, get user information data

User status must be 'active'. Also set last visit timestamp and use user language.

  • return: User fields on success, else null
array login_user (string $email, string $password, [ $email_cookie = false], [ $password_cookie = false])
  • string $email: Email of user
  • string $password: Password of user
  • $email_cookie
  • $password_cookie
set_user_preferences (line 324)

Set user preferences

Insert preference if not exist, delete if value is '', else update value.

  • return: true on success, else false
boolean set_user_preferences (integer $user_id, array $prefs)
  • integer $user_id: User ID
  • array $prefs: User preferences : Associative array of preferences (see get_user_preferences)
update_user_info (line 200)

Update user fields

  • return: true on success, else false
boolean update_user_info (integer $user_id, array $info)
  • integer $user_id: User ID
  • array $info: Associative array of user fields :
    • 'nickname' : User nickname
    • 'publish' : Publish status
    • 'language' : Language
    • 'unit' : Unit (metric or us)
    • 'gender' : Gender
    • 'birthdate' : Birthdate dd/mm/yy[yy] (sep /,-,., ' ')
    • 'height' : Height in cm (decimal sep is . or ,)
    • 'weight' : Weight in kg (decimal sep is . or ,)
    • 'rest_hr' : Rest HR (bpm)
    • 'max_hr' : Max HR (bpm)
    • 'vo2max' : VO2max in ml/kg/min (decimal sep is . or ,)
    • 'vma' : MAS in km/h (decimal sep is . or ,)

Documentation generated on Sat, 28 Mar 2009 23:16:08 +0000 by phpDocumentor 1.4.1