| @@ -476,17 +476,19 @@ | ||
| 476 | 476 | return $rooms; |
| 477 | 477 | } |
| 478 | 478 | |
| 479 | 479 | /** |
| 480 | - * Finds a room by name. | |
| 480 | + * Finds a room (or multiple rooms) by name. | |
| 481 | 481 | * |
| 482 | 482 | * @param string $name The room name to look for. |
| 483 | + * @param bool $all True to return a list of matches. | |
| 483 | 484 | * |
| 484 | 485 | * @return array |
| 485 | 486 | * |
| 486 | 487 | * @since 1.16.10 (J) - 1.6.10 (WP) |
| 488 | + * @since 1.18.17 (J) - 1.8.17 (WP) added argument $all. | |
| 487 | 489 | */ |
| 488 | - public function getRoomByName(string $name) | |
| 490 | + public function getRoomByName(string $name, bool $all = false) | |
| 489 | 491 | { |
| 490 | 492 | $dbo = JFactory::getDbo(); |
| 491 | 493 | |
| 492 | 494 | $q = $dbo->getQuery(true) |
| @@ -498,8 +500,14 @@ | ||
| 498 | 500 | foreach (array_filter(preg_split("/[\s\-_.,]+/", $name)) as $nm_part) { |
| 499 | 501 | $q->where($dbo->qn('name') . ' LIKE ' . $dbo->q("%{$nm_part}%")); |
| 500 | 502 | } |
| 501 | 503 | |
| 504 | + if ($all) { | |
| 505 | + // match all records | |
| 506 | + $dbo->setQuery($q); | |
| 507 | + return $dbo->loadAssocList(); | |
| 508 | + } | |
| 509 | + | |
| 502 | 510 | $dbo->setQuery($q, 0, 1); |
| 503 | 511 | $record = $dbo->loadAssoc(); |
| 504 | 512 | |
| 505 | 513 | return $record ?? []; |
| @@ -990,9 +998,9 @@ | ||
| 990 | 998 | return false; |
| 991 | 999 | } |
| 992 | 1000 | |
| 993 | 1001 | // count injected rooms, if any |
| 994 | - $tot_rooms = count($this->room_ids); | |
| 1002 | + $tot_rooms = (int) (($params['rooms_count'] ?? 0) ?: count($this->room_ids)); | |
| 995 | 1003 | |
| 996 | 1004 | // build options array for TACVBO |
| 997 | 1005 | $options = [ |
| 998 | 1006 | 'hash' => md5('vbo.e4j.vbo'), |
| @@ -1069,9 +1077,9 @@ | ||
| 1069 | 1077 | } |
| 1070 | 1078 | |
| 1071 | 1079 | // optional filter by room IDs will be applied on this flow |
| 1072 | 1080 | $found_rids = array_keys($website_rates); |
| 1073 | - $unwanted_rids = $tot_rooms ? array_diff($found_rids, $this->room_ids) : []; | |
| 1081 | + $unwanted_rids = $this->room_ids ? array_diff($found_rids, $this->room_ids) : []; | |
| 1074 | 1082 | foreach ($unwanted_rids as $rid) { |
| 1075 | 1083 | unset($website_rates[$rid]); |
| 1076 | 1084 | } |
| 1077 | 1085 | |
| @@ -1078,8 +1086,20 @@ | ||
| 1078 | 1086 | return $website_rates; |
| 1079 | 1087 | } |
| 1080 | 1088 | |
| 1081 | 1089 | /** |
| 1090 | + * Returns the fully booked linear array of room IDs. | |
| 1091 | + * | |
| 1092 | + * @return array | |
| 1093 | + * | |
| 1094 | + * @since 1.18.8 (J) - 1.8.8 (WP) | |
| 1095 | + */ | |
| 1096 | + public function getFullyBooked() | |
| 1097 | + { | |
| 1098 | + return (array) $this->fully_booked; | |
| 1099 | + } | |
| 1100 | + | |
| 1101 | + /** | |
| 1082 | 1102 | * Finds the available suggestions in case of no availability previously occurred |
| 1083 | 1103 | * while getting the rates. This method should be called after getRates() so that |
| 1084 | 1104 | * a valid errorCode to be analized will be available, unless code is forced. |
| 1085 | 1105 | * Suggestions can include closest booking dates and/or different room-guest parties. |
| @@ -1247,9 +1267,9 @@ | ||
| 1247 | 1267 | } |
| 1248 | 1268 | } |
| 1249 | 1269 | } |
| 1250 | 1270 | |
| 1251 | - if (!count($avroom_nights)) { | |
| 1271 | + if (!$avroom_nights) { | |
| 1252 | 1272 | // no rooms available at all, there's no way to do anything |
| 1253 | 1273 | return []; |
| 1254 | 1274 | } |
| 1255 | 1275 | |
| @@ -1465,9 +1485,9 @@ | ||
| 1465 | 1485 | } |
| 1466 | 1486 | |
| 1467 | 1487 | // apply nights/transfers ratio limit (unless disabled) |
| 1468 | 1488 | $nights_transfers_ratio = $this->getNightsTransfersRatio(); |
| 1469 | - if ($nights_transfers_ratio > 0 && $nights_transfers_ratio < 100) { | |
| 1489 | + if ($nights_transfers_ratio > 0 && $nights_transfers_ratio <= 100) { | |
| 1470 | 1490 | // count and apply limits |
| 1471 | 1491 | foreach ($split_stay_sols as $k => $split_stay_sol) { |
| 1472 | 1492 | // count nights and transfers |
| 1473 | 1493 | $split_stay_transfers = count($split_stay_sol) - 1; |
| @@ -1487,9 +1507,9 @@ | ||
| 1487 | 1507 | // split stays have been disabled |
| 1488 | 1508 | $split_stay_sols = []; |
| 1489 | 1509 | } |
| 1490 | 1510 | |
| 1491 | - if ($altered_sols && count($split_stay_sols)) { | |
| 1511 | + if ($altered_sols && $split_stay_sols) { | |
| 1492 | 1512 | // restore the array keys |
| 1493 | 1513 | $split_stay_sols = array_values($split_stay_sols); |
| 1494 | 1514 | } |
| 1495 | 1515 | |
| @@ -2481,11 +2501,16 @@ | ||
| 2481 | 2501 | * @since 1.16.0 (J) - 1.6.0 (WP) |
| 2482 | 2502 | */ |
| 2483 | 2503 | public function getDefaultNightsTransfersRatio() |
| 2484 | 2504 | { |
| 2485 | - $config = VBOFactory::getConfig(); | |
| 2505 | + static $transferRatio = null; | |
| 2486 | 2506 | |
| 2487 | - return (int) $config->get('split_stay_ratio', 50); | |
| 2507 | + if ($transferRatio === null) { | |
| 2508 | + $config = VBOFactory::getConfig(); | |
| 2509 | + $transferRatio = (int) $config->get('split_stay_ratio', 50); | |
| 2510 | + } | |
| 2511 | + | |
| 2512 | + return $transferRatio; | |
| 2488 | 2513 | } |
| 2489 | 2514 | |
| 2490 | 2515 | /** |
| 2491 | 2516 | * Sets the nights/transfers ratio for split stays. Use it to start applying limits. |