Source for file PolarSport.class.php
Documentation is available at PolarSport.class.php
* Class to get sports of a user
* @author Jean-Philippe Brunon <jp75018@free.fr>
* @copyright 2007-2009 Jean-Philippe Brunon
* @license http://www.opensource.org/licenses/gpl-license.php GPL
* @version $Id: PolarSport.class.php 33 2009-03-06 22:47:22Z jp75018 $
* General configuration file
require_once ('conf/config.php');
* Default sport names, abbrev, and name parser are language dependant
require_once ('lang/strings_' .
$GLOBALS['lang'] .
'.inc.php');
* Standard Polar sport ID for running
define('SPORT_ID_RUNNING', 1);
* Standard Polar sport ID for cycling
define('SPORT_ID_CYCLING', 2);
* Standard Polar sport ID for swimming
define('SPORT_ID_SWIMMING', 3);
* Class to get sports of a user
* Complete user's sports with default sports (running, cycling, swimming)
* Call this method in personal file (.PPD) load
* It completes sport records with standard 'index' string before inserting
* 'index' can be: 'running', 'cycling', 'swimming',
* 'ccskiing' (cross country skiing), 'walking', 'snowshoe', 'resting'.
* (running, cycling, swimming are standard Polar sports).
* @param integer $user_id User ID (in database)
* @param array $sport_tab List of sports indexed by sport ID.
* - 'name' : Full name of sport as defined by user
* - 'abbrev' : Abbreviation of sport as defined by user
* @return boolean true on success, else false (no user)
$request =
sprintf("SELECT id FROM plw_user WHERE id = %d", $user_id);
// 2. Compute standard 'index' string
while (list
($sport_id, $sport) =
each($sport_tab))
$sports[$sport_id] =
$sport;
$sports[$sport_id]['index'] =
if ($sports[$sport_id]['index'] ==
'unksport')
$sports[$sport_id]['index'] =
'running';
$sports[$sport_id]['index'] =
'cycling';
$sports[$sport_id]['index'] =
'swimming';
unset
($sports[$sport_id]['id']);
// 3. Insert sports into database
while (list
($sport_id, $sport) =
each($sports))
$request =
sprintf("INSERT INTO plw_sport(user_id, id, name, abbrev, sport_index) VALUES(%d, %d, '%s', %s, %s)",
$user_id, $sport_id, $sport['name'],
$sport['abbrev'] !=
'' ?
'\'' .
$sport['abbrev'] .
'\'' :
'NULL',
$sport['index'] !=
'' ?
'\'' .
$sport['index'] .
'\'' :
'NULL');
* Complete user's sports with default sports (running, cycling, swimming)
* - After creating a new user
* - In personal file (.PPD) load in case a standard sport is missing
* @param integer $user_id User ID (in database)
* @return boolean true on success, else false (no user)
$request =
sprintf("SELECT id FROM plw_user WHERE id = %d", $user_id);
// 3. Insert missing default sports into database
while (list
($i, $std_sport) =
each($std_sports))
while (list
($sport_id, $sport) =
each($sports))
if ($sport['index'] ==
$std_sport)
$request =
sprintf("INSERT INTO plw_sport(user_id, id, name, abbrev, sport_index) VALUES(%d, %d, '%s', '%s', '%s')",
$user_id, $i, ucfirst($GLOBALS['val_sport'][$std_sport]),
ucfirst($GLOBALS['val_abbr_sport'][$std_sport]),
* Get list of sports for one user
* @param integer $user_id User ID (in database)
* @return array List of sports indexed by sport ID.
* - 'name' : Full name of sport as defined by user
* - 'abbrev' : Abbreviation of sport as defined by user
* - 'index' : Sport standard index common to all users
$request =
sprintf("SELECT id, name, abbrev, sport_index FROM plw_sport WHERE user_id = %d ORDER BY id",
$sports[$row['id']] =
$row;
$sports[$row['id']]['index'] =
$row['sport_index'];
unset
($sports[$row['id']]['id']);
unset
($sports[$row['id']]['sport_index']);
* Parse sport name to get sport index
* Use $GLOBALS['val_regexp_sport'] array (language dependant) and use
* @param string $name Sport name to parse
* @return string Sport index ('unksport' if no regexp match)
$sport_index =
'unksport';
// 1. Normalize sport name
'áàâäãåçéèêëíìîïóòôöõñúùûüýÿ', 'aaaaaaceeeeiiiiooooonuuuuyy');
// All but digits and letters are seprators => Convert to single ' '
// 2. Loop on known sports until match
reset($GLOBALS['val_regexp_sport']);
while (list
($index, $reg_exp) =
each($GLOBALS['val_regexp_sport']))
Documentation generated on Sat, 28 Mar 2009 23:16:59 +0000 by phpDocumentor 1.4.1