Source for file PolarPpd.class.php
Documentation is available at PolarPpd.class.php
* Class to parse Polar PPD file and insert / update data to database
* PPD file contains data related to 1 person (the user).
* This data comes from Polar Software.
* It includes list of sports.
* @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: PolarPpd.class.php 52 2009-03-17 15:15:30Z jp75018 $
* Class common to all Polar files
require_once ('PolarFile.class.php');
* To insert user related sports
require_once ('PolarSport.class.php');
* Class to parse Polar PPD file and insert / update data to database
* PPD file contains data related to 1 person (the user), including sports.
* The following fields are handled when present in PPD file :
* - birthdate : Birthdate (format : YYYY-MM-DD)
* - gender : 'male' or 'female'
* - height : Height in cm x 10
* - max_hr : Maximum heart rate (bpm)
* - rest_hr : Rest heart rate (bpm)
* - firstname : First name
* Person sports (for each sport) :
* - sport_id : Sport ID as in PDD files
* - abbreviation : Sport abbreviation
* - index : Standard sport index in ('running','cycling','swimming',
* 'ccskiing','walking','resting')
* @param string $fileName Polar PPD file name (full path name)
* @param integer $userId User ID (as in database)
* Insert person information into database
* - plw_sport (delete / insert)
* @param array $person Structure for person and sports :
* - 'personinfo' : Person fields
* - 'personsports' : Array of sport fields, indexed by
$info =
$person['personinfo'];
$spos =
$person['personsports'];
$request =
sprintf("UPDATE plw_user SET cre_date=cre_date, mod_date=NOW(), lastname=%s, firstname=%s, birthdate=%s, gender=%s, height=%s, rest_hr=%s, max_hr=%s, vo2max=%s WHERE id = %d",
$info['lastname'] !=
'' ?
$info['firstname'] !=
'' ?
$info['birthdate'] !=
'' ?
$info['birthdate'] :
'NULL',
$info['gender'] !=
'' ?
'\'' .
$info['gender'] .
'\'' :
'NULL',
$info['height'] >
0 ?
$info['height'] :
'NULL',
$info['rest_hr'] >
0 ?
$info['rest_hr'] :
'NULL',
$info['max_hr'] >
0 ?
$info['max_hr'] :
'NULL',
$info['vo2max'] >
0 ?
$info['vo2max'] :
'NULL',
// 2. Insert sports (delete first)
$request =
sprintf("DELETE FROM plw_sport WHERE user_id = %d",
$sport->insert_sports($this->userId, $spos);
$sport->set_default_sports($this->userId);
* Parse Polar PPD file (person information, including sports)
* Note : Not all information in file is used, only <personinfo> and
* <personsports> blocks are parsed.
* @return array Structure for person and sports :
* - 'personinfo' : Person fields
* - 'personsports' : Array of sport fields, indexed by
while ($line_no <
count($buffer))
$begin_block =
$line_no +
1;
$lg_block =
$line_no -
$begin_block -
1;
if (! trim($buffer[$end_block]))
$parse_func =
'_parse_block_' .
$block_name .
'_get';
$this->$parse_func(&$buffer, $begin_block, $lg_block);
* Parse <personinfo> block in PPD file
* @param string $buffer Buffer with PPD file content
* @param integer $start Line number of block in buffer
* @param integer $nb Number of lines in block
* @return array Fields of person
$person['birthdate'] =
$row[0];
$person['gender'] =
'female';
$person['gender'] =
'male';
$person['height'] =
10 *
$row[2];
$person['max_hr'] =
$row[0];
$person['rest_hr'] =
$row[3];
$person['vo2max'] =
$row[4];
$person['firstname'] =
trim($buffer[$start +
7]);
$person['lastname'] =
trim($buffer[$start +
8]);
* Parse <personsports> block in PPD file
* @param string $buffer Buffer with PPD file content
* @param integer $start Line number of block in buffer
* @param integer $nb Number of lines in block
* @return array Array of sports, indexed by sport ID
$sports[$sport_id]['name'] =
trim($buffer[$start +
$j +
2]);
$sports[$sport_id]['abbrev'] =
trim($buffer[$start +
$j +
3]);
Documentation generated on Sat, 28 Mar 2009 23:16:57 +0000 by phpDocumentor 1.4.1