Commit f29006cc authored by Volker Krause's avatar Volker Krause
Browse files

Also use the VDV organization id to select KPublicTransport backends

parent 477578ac
......@@ -472,21 +472,34 @@ KPublicTransport::JourneySection PublicTransport::lastTransportSection(const KPu
QStringList PublicTransport::suitableBackendsForReservation(KPublicTransport::Manager *mgr, const QVariant &res)
{
using namespace KPublicTransport;
QStringList backendIds;
const auto companyCode = ReservationHelper::uicCompanyCode(res);
if (companyCode.size() != 4) {
return {};
if (companyCode.size() == 4) {
for (const auto &backend : mgr->backends()) {
if (!mgr->isBackendEnabled(backend.identifier())) {
continue;
}
for (const auto cov : { CoverageArea::Realtime, CoverageArea::Regular, CoverageArea::Any }) {
if (backend.coverageArea(cov).uicCompanyCodes().contains(companyCode)) {
backendIds.push_back(backend.identifier());
break;
}
}
}
}
QStringList backendIds;
for (const auto &backend : mgr->backends()) {
if (!mgr->isBackendEnabled(backend.identifier())) {
continue;
}
for (const auto cov : { CoverageArea::Realtime, CoverageArea::Regular, CoverageArea::Any }) {
if (backend.coverageArea(cov).uicCompanyCodes().contains(companyCode)) {
backendIds.push_back(backend.identifier());
break;
const auto vdvOrgId = ReservationHelper::vdvOrganizationId(res);
if (!vdvOrgId.isEmpty()) {
for (const auto &backend : mgr->backends()) {
if (!mgr->isBackendEnabled(backend.identifier())) {
continue;
}
for (const auto cov : { CoverageArea::Realtime, CoverageArea::Regular, CoverageArea::Any }) {
if (backend.coverageArea(cov).vdvOrganizationIds().contains(vdvOrgId)) {
backendIds.push_back(backend.identifier());
break;
}
}
}
}
......
......@@ -63,13 +63,19 @@ bool ReservationHelper::equals(const QVariant &lhs, const QVariant &rhs)
return false;
}
QString ReservationHelper::uicCompanyCode(const QVariant &res)
static QString providerIdentifier(const QVariant &res)
{
QString id;
if (JsonLd::isA<TrainReservation>(res)) {
id = res.value<TrainReservation>().reservationFor().value<TrainTrip>().provider().identifier();
} // TODO in theory we can also have this for bus reservations
return res.value<TrainReservation>().reservationFor().value<TrainTrip>().provider().identifier();
} else if (JsonLd::isA<BusReservation>(res)) {
return res.value<BusReservation>().reservationFor().value<BusTrip>().provider().identifier();
}
return {};
}
QString ReservationHelper::uicCompanyCode(const QVariant &res)
{
auto id = providerIdentifier(res);
if (!id.startsWith(QLatin1String("uic:")) || id.size() > 8) {
return {};
}
......@@ -80,3 +86,12 @@ QString ReservationHelper::uicCompanyCode(const QVariant &res)
}
return id;
}
QString ReservationHelper::vdvOrganizationId(const QVariant &res)
{
const auto id = providerIdentifier(res);
if (!id.startsWith(QLatin1String("vdv:"))) {
return id.mid(4);
}
return {};
}
......@@ -27,6 +27,8 @@ namespace ReservationHelper
/** Returns the UIC company code for @p res, if any. */
QString uicCompanyCode(const QVariant &res);
/** Returns the VDV org id for @p res, if any. */
QString vdvOrganizationId(const QVariant &res);
}
#endif // RESERVATIONHELPER_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment