Я пытаюсь расширить свой класс с помощью новой функции, я уже могу запрашивать данные истории пользователей, но теперь я хочу запрашивать несколько пользователей одновременно.
Я уже делаю нечто подобное, когда могу запросить последнюю позицию у нескольких пользователей - см. Ниже
/**
* Get last position of the user
* @param mixed $user string/int user identificator
* @return array associative array with these keys: status, timestamp, longitude, latitude
*/
public function getLastPosition($user) {
$this->_checkLoggedIn(__METHOD__);
$getLastPositionRequest = $this->_xml->getLastPositionRequest($this->application_id, $this->request_id, $user);
$getLastPositionResponse = $this->_transport->request(self::PATH_LAST_LOCATION, $getLastPositionRequest);
$return = $this->_xml->parseGetLastPositionResponse($getLastPositionResponse);
$this->request_id++;
$return['user_id'] = $user;
return $return;
}
/**
* Get mutiple positions at once
* @param array $users associative array of users username => user id
* @return array associative array of username => associative array with keys: status, timestamp, longitude, latitude
*/
public function getLastPositions($users)
{
$return = array();
$return1 = array();
$i=0;
foreach($users as $user => $id) {
$u=new UsersData();
$u->name=$user;
$u->data=$this->getLastPosition($id);
$return[$i] = $u;
$i = $i + 1;
//$return[$user]= $return1[$i];
}
return $return;
}
Вот мой запрос на получение истории, как я могу выполнить его, чтобы получить данные истории нескольких пользователей одновременно?
public function getHistoryQuery($user, $start_time, $end_time)
{
$this->_checkLoggedIn(__METHOD__);
$historyQueryRequest = $this->_xml->getHistoryQueryRequest($this->application_id, $this->request_id, $user, $start_time, $end_time);
$historyQueryResponse = $this->_transport->request('soap/gps/historyquery', $historyQueryRequest);
$return = $this->_xml->parseHistoryQueryResponse($historyQueryResponse);
$this->_request_id++;
return $return;
}
Вот функция parseHistoryQueryResponse, используемая в getHistoryQuery
/**
* Parse XML gps history response
*/
public function parseHistoryQueryResponse($historyQueryResponse)
{
$match = array(
'user' => 'User'
);
$x = $this->_match($match, $historyQueryResponse);
$chunks = explode('</n:GpsData>', $historyQueryResponse);
$match = array(
'timestamp' => 'Timestamp',
'longitude' => 'longitude',
'latitude' => 'latitude'
);
$data = array();
foreach($chunks as $chunk) {
$tmp = $this->_match($match, $chunk);
$tmp['timestamp'] = $tmp['timestamp'] / 1000;
$tmp['longitude'] = $tmp['longitude'] / 1000000;
$tmp['latitude'] = $tmp['latitude'] / 1000000;
if ($tmp['timestamp'] > 0) {
$data[] = $tmp;
}
}
return array(
'user' => $x['user'],
'data' => $data
);
}