/** * Get all last postions for users and its way points after a certain time * 1. Get the group of the user first user (parameter) * 2. Get all users of this group * 3. Get the last position of every user (no matter of date-time). But exclude the user given * in param $requestingUser * 4. Get all way points (for each user) for todays (!) track file (csv) after the given line (parameter) * - the line for each user is set in the parameter $keyUserValueLastPairs * - in case their is an unknown (probably new) user on the server in this group * > then the whole track is returned. It is the same as line = '' (not set) * * @param type $keyUserValueLastPairs for examples * - 'Lisa' * - 'Lisa=2013-03-03T15:48:47;Peter=2013-03-03T15:48:47' * @param type $isRequestingTracks true if the user wants to write a track * @param type $requestingUser if not null or empty then this user will be excluded in the returned * - position and * - tracks * @return string tracks as CSV line this * [positions] * user=Peter;lat=47.50457163540115;lon=11.071390274487026;bearing=171.61432;speed=0.7065948;altitude=1067.652498529502;accuracy=6.0;time=2013-03-03T15:48:47.484 * user=Lisa;lat=47.50451538021159;lon=11.071421406744932;bearing=173.14859;speed=0.0;altitude=1068.2914401409275;accuracy=6.0;time=2013-03-03T15:48:57.511 * [track-Peter] * lat=47.50457163540115;lon=11.071390274487026;bearing=171.61432;speed=0.7065948;altitude=1067.652498529502;accuracy=6.0;time=2013-03-03T15:48:47.484 * lat=47.50451538021159;lon=11.071421406744932;bearing=173.14859;speed=0.0;altitude=1068.2914401409275;accuracy=6.0;time=2013-03-03T15:48:57.511 * lat=47.50451538021159;lon=11.071521406744932;bearing=173.14859;speed=0.0;altitude=1068.2914401409275;accuracy=6.0;time=2013-03-03T15:48:57.511 * [track-Lisa] * lat=47.50457163540115;lon=11.071390274487026;bearing=171.61432;speed=0.7065948;altitude=1067.652498529502;accuracy=6.0;time=2013-03-03T15:48:47.484 * lat=47.50557163540115;lon=11.071390274487026;bearing=171.61432;speed=0.7065948;altitude=1067.652498529502;accuracy=6.0;time=2013-03-03T15:48:47.484 * lat=47.50651538021159;lon=11.071421406744932;bearing=173.14859;speed=0.0;altitude=1068.2914401409275;accuracy=6.0;time=2013-03-03T15:48:57.511 */ function getLastPostionsAndTracksIndividually($keyUserValueLastPairs, $isRequestingTracks, $requestingUser) { $resultBuffer = ''; //Read out key-value pairs (user - date/time) // Example: 'Lisa,2012-03-03T15:48:47.484;Peter,2012-03-03T16:48:47.484' if (isNullOrEmptyString($keyUserValueLastPairs)) { return $resultBuffer; } $user = ''; // this is the user that defines the group $arr = array(); $usersWithTimeArray = explode(';', $keyUserValueLastPairs); $countUsers = count($usersWithTimeArray); if ($countUsers < 1) { return $resultBuffer; } for ($i = 0; $i < $countUsers; $i++) { $userTimePair = $usersWithTimeArray[$i]; $userTimePair = trim($userTimePair); $keyValueArray = explode('=', $userTimePair); $countPair = count($keyValueArray); if ($countPair == 1) { // assume the user is given as parameter only if (isNullOrEmptyString($user)) { $user = $keyValueArray[0]; } continue; } if ($countPair != 2) { return $resultBuffer; } $keyUser = $keyValueArray[0]; $timeOfLastSentTrackPoint = $keyValueArray[1]; if (isNullOrEmptyString($user)) { $user = $keyUser; } // store Lisa > 'dateTime' for later usage to get the updated way points as csv $arr[$keyUser] = $timeOfLastSentTrackPoint; } // all last postions if (isNullOrEmptyString($requestingUser)) { $postions = getGroupPostions($user); } else { $postions = getGroupPostions($requestingUser, $requestingUser); } if (isNullOrEmptyString($postions)) { return $resultBuffer; } $resultBuffer .= "[positions]" . PHP_EOL . $postions; // Check wether the requester wants tracks if (isNullOrEmptyString($isRequestingTracks)) { // Set 'true" as default if not given as parameter $isRequestingTracks = 'true'; } $searchString = '/false|no/i'; if (preg_match($searchString, $isRequestingTracks, $matches)) { return $resultBuffer; } // get all users that have a track file for today $date = getDateForTimezoneOffset($user, '', true); $fileName = $date . '.csv'; $userLines = getUsersForDataFileName($user, $fileName, $requestingUser); // iterate through the track files of every found user and assable the return string if ($userLines != '') { $users = explode(PHP_EOL, $userLines); $count = count($users); for ($i = 0; $i < $count; $i++) { $userOfGroup = $users[$i]; // Every user has its own date-time (Lisa > 2012-03-03T15:48:47.484) // It might be that a user is not given in the parameter (with date-time). // This is the case if a new user joined the group in the mean time. // It does not matter. The date-time is not set means: all postions from // todays positions is added to the result buffer (positions as csv lines). if (array_key_exists($userOfGroup, $arr)) { $lastSentTrackPointTime = $arr[$userOfGroup]; } else { $lastSentTrackPointTime = ''; } // Get the updated positions as csv $trackAsCSV = getTrack($userOfGroup, $date, $lastSentTrackPointTime); if (isNullOrEmptyString($trackAsCSV)) { continue; } if (!isNullOrEmptyString($resultBuffer)) { $resultBuffer .= PHP_EOL; } $resultBuffer .= '[track-' . $userOfGroup . ']' . PHP_EOL . $trackAsCSV; } } return $resultBuffer; }
function test_writePostion() { appendTestMessage(NEW_LINE_LOG . " >> Tests writing of single position..." . NEW_LINE_LOG); appendTestMessage("Prepare: Create new user"); $ret = checkUser("dUser", "dPassword"); if ($ret) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Check parameter lat"); $ret = writePostion('', '', '', '', '', '', '', '', '', ''); if (!$ret) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Check parameter lon"); $ret = writePostion('', '', '47.50457163540115', '', '', '', '', '', '', ''); if (!$ret) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Prepare: Create new user"); $ret = checkUser("dUser", "dPassword"); if ($ret) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get tracks (individually 1) for user (no positions yet)"); $ret = getLastPostionsAndTracksIndividually(''); if (isNullOrEmptyString($ret)) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get tracks (individually 2) for user (no positions yet)"); $ret = getLastPostionsAndTracksIndividually('dUser'); if (isNullOrEmptyString($ret)) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get tracks (individually 3) for user (no positions yet)"); $ret = getLastPostionsAndTracksIndividually('dUser=2013-03-03 15:48:47.484', 'true'); if (isNullOrEmptyString($ret)) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Test helper function to write the postion.csv > new"); $ret = writePositionFile('dUser', 'test;test;test'); if ($ret) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } $testDateTime = getDateForTimezoneOffset('dUser', '', false); appendTestMessage("Write single position"); $csvLine = 'lat=47.50457163540115;lon=11.071390274487026;bearing=171.61432;speed=0.7065948;altitude=1067.652498529502;accuracy=6.0;time=' . $testDateTime; $ret = writePositionFile('dUser', $csvLine); if ($ret) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Write lat and lon"); $ret = writePostion('dUser', '', '42.50457163540115', '11.071390274487026', '', '', '', '', '2012-03-03T15:48:47.484', 'true'); if ($ret) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get tracks (individually 1) for user (one position yet) no track for today"); $ret = getLastPostionsAndTracksIndividually('dUser'); $expectedTracks = '[positions]' . PHP_EOL . 'user=dUser;lat=42.50457163540115;lon=11.071390274487026;time=2012-03-03T15:48:47.484'; if ($ret == $expectedTracks) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get tracks (individually 2) for user (one position yet) - track excluded because of time"); $ret = getLastPostionsAndTracksIndividually('dUser=2012-03-03T15:48:47.4841'); $expectedTracks = "[positions]" . PHP_EOL . 'user=dUser;lat=42.50457163540115;lon=11.071390274487026;time=2012-03-03T15:48:47.484'; if ($ret == $expectedTracks) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } $testDate = getDateForTimezoneOffset('dUser', '', true); appendTestMessage("Write lat and lon"); $ret = writePostion('dUser', '', '42.50457163540115', '11.071390274487026', '', '', '', '', $testDate . 'T15:48:47.484', 'true'); if ($ret) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } $today = getDateForTimezoneOffset('dUser', '', true); $gpxFileName = $today . '.csv'; appendTestMessage("Check for a data file (gpx) for this user"); $ret = getUsersForDataFileName('dUser', $gpxFileName); if ($ret == 'dUser') { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } // TODO: New appendTestMessage("Check for a data file (gpx) for this user. But exclude the user"); $ret = getUsersForDataFileName('dUser', $gpxFileName, 'dUser'); if ($ret == '') { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("View single position"); $csvLine0 = 'lat=42.50457163540115;lon=11.071390274487026;time=' . $testDate . 'T15:48:47.484'; $ret = getPosition('dUser'); if ($ret === $csvLine0) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("View single position (parameter = getGroupPostions"); $ret = getGroupPostions('dUser'); $expectedLine = 'user=dUser;' . $csvLine0; if ($ret === $expectedLine) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Write lat and lon"); $ret = writePostion('dUser', 'cGroup_changed', '43.50457163540115', '11.071390274487026', '171.61432', '0.7065948', '1067.652498529502', '6.0', $testDate . 'T15:48:48.484', 'true'); if ($ret) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get tracks individually for user (omit tracks)"); $ret = getLastPostionsAndTracksIndividually('dUser', 'false'); $expectedTracks = '[positions]' . PHP_EOL . 'user=dUser;lat=43.50457163540115;lon=11.071390274487026;bearing=171.61432;speed=0.7065948;altitude=1067.652498529502;accuracy=6.0;time=' . $testDate . 'T15:48:48.484'; if ($ret == $expectedTracks) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get tracks individually for user (omit tracks)"); $ret = getLastPostionsAndTracksIndividually('dUser', 'no'); $expectedTracks = '[positions]' . PHP_EOL . 'user=dUser;lat=43.50457163540115;lon=11.071390274487026;bearing=171.61432;speed=0.7065948;altitude=1067.652498529502;accuracy=6.0;time=' . $testDate . 'T15:48:48.484'; if ($ret == $expectedTracks) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get tracks individually for user (two positions yet no last time given)"); $ret = getLastPostionsAndTracksIndividually('dUser', 'true'); $expectedTracks = '[positions]' . PHP_EOL . 'user=dUser;lat=43.50457163540115;lon=11.071390274487026;bearing=171.61432;speed=0.7065948;altitude=1067.652498529502;accuracy=6.0;time=' . $testDate . 'T15:48:48.484' . PHP_EOL . '[track-dUser]' . PHP_EOL . 'lat=42.50457163540115;lon=11.071390274487026;time=' . $testDate . 'T15:48:47.484' . PHP_EOL . 'lat=43.50457163540115;lon=11.071390274487026;bearing=171.61432;speed=0.7065948;altitude=1067.652498529502;accuracy=6.0;time=' . $testDate . 'T15:48:48.484'; if ($ret == $expectedTracks) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("View single position"); $csvLine1 = 'lat=43.50457163540115;lon=11.071390274487026;bearing=171.61432;speed=0.7065948;altitude=1067.652498529502;accuracy=6.0;time=' . $testDate . 'T15:48:48.484'; $ret = getPosition('dUser'); if ($ret === $csvLine1) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Write empty multiline positions"); $ret = writePostions('dUser', 'cGroup_changed', '', 'true'); if (!$ret) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Write multiline positions"); $csvLine2 = 'lat=44.50457163540115;lon=11.071390274487026;bearing=171.61432;speed=0.7065948;altitude=1067.652498529502;accuracy=6.0;time=' . $testDate . 'T15:54:41.484'; $csvLine3 = 'lat=45.50457163540115;lon=11.071390274487026;bearing=171.61432;speed=0.7065948;altitude=1067.652498529502;accuracy=6.0;time=' . $testDate . 'T15:54:42.484'; $csvLine4 = 'lat=46.50457163540115;lon=11.071390274487026;bearing=171.61432;speed=0.7065948;altitude=1067.652498529502;accuracy=6.0;time=' . $testDate . 'T15:54:43.484'; $csvLines2_4 = $csvLine2 . PHP_EOL . $csvLine3 . PHP_EOL . $csvLine4; $csvLines0_4 = $csvLine0 . PHP_EOL . $csvLine1 . PHP_EOL . $csvLine2 . PHP_EOL . $csvLine3 . PHP_EOL . $csvLine4; $ret = writePostions('dUser', 'cGroup_changed', $csvLines2_4, 'true'); if ($ret) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("View single position set by multiline writing"); $ret = getPosition('dUser'); if ($ret === $csvLine4) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get tracks individally for user (five positions yet, last time given)"); $ret = getLastPostionsAndTracksIndividually('dUser='******'T15:48:48.484'); $expectedTracks = "[positions]" . PHP_EOL . 'user=dUser;' . $csvLine4 . PHP_EOL . '[track-dUser]' . PHP_EOL . $csvLine2 . PHP_EOL . $csvLine3 . PHP_EOL . $csvLine4; if ($ret == $expectedTracks) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("List tracks"); $ret = listTracks('dUser'); $expectedFileName = '2012-03-03.gpx'; if ($ret == $expectedFileName) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("List tracks"); $ret = listTracksCSV('dUser'); $expectedFileNames1 = $testDate . '.csv' . PHP_EOL . '2012-03-03.csv'; $expectedFileNames2 = '2012-03-03.csv' . PHP_EOL . $testDate . '.csv'; if ($ret === $expectedFileNames1 || $ret === $expectedFileNames2) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get track check empty parameter date"); $ret = getTrack('dUser', '', ''); if ($ret === $csvLines0_4) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get track"); $ret = getTrack('dUser', $today, ''); if ($ret === $csvLines0_4) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } // Review: This test seems to be double, see test somewhere above appendTestMessage("Get track after a certain line number only"); $ret = getTrack('dUser', $today, $testDate . 'T15:48:48.484'); if ($ret === $csvLines2_4) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get track after a certain line number (at end already)"); $ret = getTrack('dUser', $today, $testDate . 'T15:54:43.484'); if ($ret === '') { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get postions of group"); $ret = getPositions('cGroup_changed'); $expectedString = 'user=dUser;' . $csvLine4; if ($ret === $expectedString) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } // TODO: New appendTestMessage("Get postions of group. But exclude the user dUser"); $ret = getPositions('cGroup_changed', dUser); if ($ret === '') { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } // Add second user with same group appendTestMessage("Prepare: Create new user"); $ret = checkUser("eUser", "ePassword"); if ($ret) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Check for a data file (gpx) for this user. A second user is in the group but without this file."); $ret = getUsersForDataFileName('dUser', $gpxFileName); if ($ret == 'dUser') { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } // TODO: New appendTestMessage("Check for a data file (gpx) for this user. AND exclude the user. A second user is in the group but without this file."); $ret = getUsersForDataFileName('dUser', $gpxFileName, 'dUser'); if ($ret == '') { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Prepare: Write position new second user with same group"); $csvLine5 = 'lat=47.50457163540115;lon=11.071390274487026;bearing=171.61432;speed=0.7065948;altitude=1067.652498529502;accuracy=6.0;time=' . $testDate . 'T15:54:43.484'; $ret = writePostions('eUser', 'cGroup_changed', $csvLine5, 'true'); if ($ret) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Check for a data file (gpx) for this user. A second user is in the group now."); $ret = getUsersForDataFileName('dUser', $gpxFileName); $expectedUsers = 'dUser' . PHP_EOL . 'eUser'; $expectedUsers1 = 'eUser' . PHP_EOL . 'dUser'; if ($ret == $expectedUsers || $ret == $expectedUsers1) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } // TODO: New appendTestMessage("Check for a data file (gpx) for this user. But exclude the user. A second user is in the group now."); $ret = getUsersForDataFileName('dUser', $gpxFileName, 'dUser'); $expectedUsers = 'eUser'; if ($ret == $expectedUsers) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get postions of the two members of the group"); $ret = getPositions('cGroup_changed'); $expectedPostions = 'user=dUser;' . $csvLine4 . PHP_EOL . 'user=eUser;' . $csvLine5; $expectedPostions1 = 'user=eUser;' . $csvLine5 . PHP_EOL . 'user=dUser;' . $csvLine4; if ($ret === $expectedPostions || $ret === $expectedPostions1) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } // TODO: New appendTestMessage("Get postions of the two members of the group. Exclude user eUser"); $ret = getPositions('cGroup_changed', 'eUser'); $expectedPostions = 'user=dUser;' . $csvLine4; if ($ret === $expectedPostions) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get tracks individually for 2 users (last time given - 1)"); $ret = getLastPostionsAndTracksIndividually('dUser='******'T15:48:48.484'); $expectedTracks = "[positions]" . PHP_EOL . 'user=dUser;' . $csvLine4 . PHP_EOL . 'user=eUser;' . $csvLine5 . PHP_EOL . '[track-dUser]' . PHP_EOL . $csvLine2 . PHP_EOL . $csvLine3 . PHP_EOL . $csvLine4 . PHP_EOL . '[track-eUser]' . PHP_EOL . $csvLine5; $expectedTracks1 = "[positions]" . PHP_EOL . 'user=eUser;' . $csvLine5 . PHP_EOL . 'user=dUser;' . $csvLine4 . PHP_EOL . '[track-eUser]' . PHP_EOL . $csvLine5 . PHP_EOL . '[track-dUser]' . PHP_EOL . $csvLine2 . PHP_EOL . $csvLine3 . PHP_EOL . $csvLine4; if ($ret == $expectedTracks || $ret == $expectedTracks1) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get tracks individually for 2 users (last line given - 2)"); $ret = getLastPostionsAndTracksIndividually('dUser='******'T15:48:48.484;eUser'); $expectedTracks = "[positions]" . PHP_EOL . 'user=dUser;' . $csvLine4 . PHP_EOL . 'user=eUser;' . $csvLine5 . PHP_EOL . '[track-dUser]' . PHP_EOL . $csvLine2 . PHP_EOL . $csvLine3 . PHP_EOL . $csvLine4 . PHP_EOL . '[track-eUser]' . PHP_EOL . $csvLine5; $expectedTracks1 = "[positions]" . PHP_EOL . 'user=eUser;' . $csvLine5 . PHP_EOL . 'user=dUser;' . $csvLine4 . PHP_EOL . '[track-eUser]' . PHP_EOL . $csvLine5 . PHP_EOL . '[track-dUser]' . PHP_EOL . $csvLine2 . PHP_EOL . $csvLine3 . PHP_EOL . $csvLine4; if ($ret == $expectedTracks || $ret == $expectedTracks1) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get tracks individually for 2 users (last line given - 3)"); $ret = getLastPostionsAndTracksIndividually('dUser='******'T15:48:48.484;eUser='******'T15:54:42.484'); $expectedTracks = "[positions]" . PHP_EOL . 'user=dUser;' . $csvLine4 . PHP_EOL . 'user=eUser;' . $csvLine5 . PHP_EOL . '[track-dUser]' . PHP_EOL . $csvLine2 . PHP_EOL . $csvLine3 . PHP_EOL . $csvLine4 . PHP_EOL . '[track-eUser]' . PHP_EOL . $csvLine5; $expectedTracks1 = "[positions]" . PHP_EOL . 'user=eUser;' . $csvLine5 . PHP_EOL . 'user=dUser;' . $csvLine4 . PHP_EOL . '[track-eUser]' . PHP_EOL . $csvLine5 . PHP_EOL . '[track-dUser]' . PHP_EOL . $csvLine2 . PHP_EOL . $csvLine3 . PHP_EOL . $csvLine4; if ($ret == $expectedTracks || $ret == $expectedTracks1) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get tracks individually for 2 users (last line given - 4)"); $ret = getLastPostionsAndTracksIndividually('dUser='******'T15:48:48.484;eUser='******'T15:54:43.484'); $expectedTracks = "[positions]" . PHP_EOL . 'user=dUser;' . $csvLine4 . PHP_EOL . 'user=eUser;' . $csvLine5 . PHP_EOL . '[track-dUser]' . PHP_EOL . $csvLine2 . PHP_EOL . $csvLine3 . PHP_EOL . $csvLine4; $expectedTracks1 = "[positions]" . PHP_EOL . 'user=eUser;' . $csvLine5 . PHP_EOL . 'user=dUser;' . $csvLine4 . PHP_EOL . '[track-dUser]' . PHP_EOL . $csvLine2 . PHP_EOL . $csvLine3 . PHP_EOL . $csvLine4; if ($ret == $expectedTracks || $ret == $expectedTracks1) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get tracks individually for 2 users (last line given - 5)"); $ret = getLastPostionsAndTracksIndividually('dUser='******'T15:54:43.484' . ';eUser='******'T15:54:43.484'); $expectedTracks = "[positions]" . PHP_EOL . 'user=dUser;' . $csvLine4 . PHP_EOL . 'user=eUser;' . $csvLine5; $expectedTracks1 = "[positions]" . PHP_EOL . 'user=eUser;' . $csvLine5 . PHP_EOL . 'user=dUser;' . $csvLine4; if ($ret == $expectedTracks || $ret == $expectedTracks1) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get postions of the two members of the group (param = getGroupPostions"); $ret = getGroupPostions('dUser'); if ($ret === $expectedPostions || $ret === $expectedPostions1) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Util: write some csv files to create gpx (later)"); if (test_writeGpxFromCsv()) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Create gpx from csv and list. Check eUser"); $ret = listTracks('eUser'); $expected1 = "2013-03-10.gpx" . PHP_EOL . "2013-03-11.gpx"; $expected2 = "2013-03-11.gpx" . PHP_EOL . "2013-03-10.gpx"; if ($ret == $expected1 || $ret == $expected2) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Create gpx from csv and list. Check dUser"); $ret = listTracks('dUser'); $expected1 = "2013-03-10.gpx" . PHP_EOL . "2012-03-03.gpx"; $expected2 = "2012-03-03.gpx" . PHP_EOL . "2013-03-10.gpx"; if ($ret == $expected1 || $ret == $expected2) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Write multiline positions with different dates"); $csvLine6 = 'lat=44.50457163540115;lon=11.071390274487026;bearing=171.61432;speed=0.7065948;altitude=1067.652498529502;accuracy=6.0;time=2012-04-03T15:54:41.484'; $csvLine7 = 'lat=45.50457163540115;lon=11.071390274487026;bearing=171.61432;speed=0.7065948;altitude=1067.652498529502;accuracy=6.0;time=' . $testDate . 'T15:54:44.484'; $csvLine8 = 'lat=46.50457163540115;lon=11.071390274487026;bearing=171.61432;speed=0.7065948;altitude=1067.652498529502;accuracy=6.0;time=' . $testDate . 'T15:54:45.484'; $csvLines6_8 = $csvLine6 . PHP_EOL . $csvLine7 . PHP_EOL . $csvLine8; $csvLines0_8_dUser = $csvLine0 . PHP_EOL . $csvLine1 . PHP_EOL . $csvLine2 . PHP_EOL . $csvLine3 . PHP_EOL . $csvLine4 . PHP_EOL . $csvLine7 . PHP_EOL . $csvLine8; $ret = writePostions('dUser', 'cGroup_changed', $csvLines6_8, 'true'); if ($ret) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get tracks individually for 2 users all lines"); $ret = getLastPostionsAndTracksIndividually('dUser;eUser'); $expectedTracks = "[positions]" . PHP_EOL . 'user=dUser;' . $csvLine8 . PHP_EOL . 'user=eUser;' . $csvLine5 . PHP_EOL . '[track-dUser]' . PHP_EOL . $csvLines0_8_dUser . PHP_EOL . '[track-eUser]' . PHP_EOL . $csvLine5; $expectedTracks1 = "[positions]" . PHP_EOL . 'user=eUser;' . $csvLine5 . PHP_EOL . 'user=dUser;' . $csvLine8 . PHP_EOL . '[track-eUser]' . PHP_EOL . $csvLine5 . PHP_EOL . '[track-dUser]' . PHP_EOL . $csvLines0_8_dUser; if ($ret == $expectedTracks || $ret == $expectedTracks1) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get tracks individually for 2 users all lines"); $ret = getLastPostionsAndTracksIndividually('dUser='******'T15:54:44.484;eUser'); $expectedTracks = "[positions]" . PHP_EOL . 'user=dUser;' . $csvLine8 . PHP_EOL . 'user=eUser;' . $csvLine5 . PHP_EOL . '[track-dUser]' . PHP_EOL . $csvLine8 . PHP_EOL . '[track-eUser]' . PHP_EOL . $csvLine5; $expectedTracks1 = "[positions]" . PHP_EOL . 'user=eUser;' . $csvLine5 . PHP_EOL . 'user=dUser;' . $csvLine8 . PHP_EOL . '[track-eUser]' . PHP_EOL . $csvLine5 . PHP_EOL . '[track-dUser]' . PHP_EOL . $csvLine8; if ($ret == $expectedTracks || $ret == $expectedTracks1) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("List tracks"); $ret = listTracksCSV('dUser'); $expectedFileNames1 = $testDate . '.csv' . PHP_EOL . '2012-03-03.csv' . PHP_EOL . '2012-04-03.csv' . PHP_EOL . '2013-03-10.csv'; $searchString = '/' . $testDate . '.csv/i'; if (preg_match($searchString, $ret, $matches)) { $foundTime = $matches[0]; appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } $searchString = '/2012-03-03.csv/i'; if (preg_match($searchString, $ret, $matches)) { $foundTime = $matches[0]; appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } $searchString = '/2012-04-03.csv/i'; if (preg_match($searchString, $ret, $matches)) { $foundTime = $matches[0]; appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } $searchString = '/2013-03-10.csv/i'; if (preg_match($searchString, $ret, $matches)) { $foundTime = $matches[0]; appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Write multiline positions with different dates and track not stored"); $csvLine6 = 'lat=44.50457163540115;lon=11.071390274487026;bearing=171.61432;speed=0.7065948;altitude=1067.652498529502;accuracy=6.0;time=2012-04-03T15:54:41.484'; $csvLine7 = 'lat=45.50457163540115;lon=11.071390274487026;bearing=171.61432;speed=0.7065948;altitude=1067.652498529502;accuracy=6.0;time=' . $testDate . 'T15:54:44.484'; $csvLine8 = 'lat=46.50457163540115;lon=11.071390274487026;bearing=171.61432;speed=0.7065948;altitude=1067.652498529502;accuracy=6.0;time=' . $testDate . 'T15:54:45.484'; $csvLine9 = 'lat=46.50457163540115;lon=11.071390274487026;bearing=171.61432;speed=0.7065948;altitude=1067.652498529502;accuracy=6.0;time=' . $testDate . 'T15:54:46.484'; $csvLines6_9 = $csvLine6 . PHP_EOL . $csvLine7 . PHP_EOL . $csvLine8 . PHP_EOL . $csvLine9; $ret = writePostions('dUser', 'cGroup_changed', $csvLines6_9, 'false'); if ($ret) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } appendTestMessage("Get tracks individually for 2 users all lines"); $ret = getLastPostionsAndTracksIndividually('dUser;eUser'); $expectedTracks = "[positions]" . PHP_EOL . 'user=dUser;' . $csvLine9 . PHP_EOL . 'user=eUser;' . $csvLine5 . PHP_EOL . '[track-dUser]' . PHP_EOL . $csvLines0_8_dUser . PHP_EOL . '[track-eUser]' . PHP_EOL . $csvLine5; $expectedTracks1 = "[positions]" . PHP_EOL . 'user=eUser;' . $csvLine5 . PHP_EOL . 'user=dUser;' . $csvLine9 . PHP_EOL . '[track-eUser]' . PHP_EOL . $csvLine5 . PHP_EOL . '[track-dUser]' . PHP_EOL . $csvLines0_8_dUser; if ($ret == $expectedTracks || $ret == $expectedTracks1) { appendTestMessage("- ok"); } else { appendTestMessage("- failed"); return false; } return true; }
// Get a track for a user $getTrackForUser = getParam('getTrack'); if (!isNullOrEmptyString($getTrackForUser)) { $track = getTrack($getTrackForUser, getParam('date'), getParam('last')); if (isNullOrEmptyString($track)) { setServerError("Failed to get tracks for user {$getTrackForUser}."); return; } setServerResponse($track); return; } // Get all users (of a group) that have a given data file(name) $getUsersForFileName = getParam('getUsersForFileName'); if (!isNullOrEmptyString($getUsersForFileName)) { $fileName = getParam('filename'); $users = getUsersForDataFileName($user, $fileName); if (isNullOrEmptyString($getUsersForFileName)) { setServerError("Failed to get users for filename {$fileName} for user {$user}."); return; } setServerResponse($users); return; } // Get all users (of a group) that have a given data file(name) $getLastPostionsAndTracks = getParam('getLastPostionsAndTracksIndividually'); if (!isNullOrEmptyString($getLastPostionsAndTracks)) { // 1. Write the group if given $group = getParam('group'); // if (!isNullOrEmptyString($group)) { if (!writeGroupFile($user, $group)) { setServerError("Failed to change group for user {$user}.");