PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.17
Yatra – Travel Booking & Tour Operator Software v3.0.17
3.0.17 3.0.16 3.0.15 3.0.14 3.0.14.1 3.0.14.2 3.0.12 3.0.13 3.0.11 3.0.10 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.5.1 3.0.4 3.0.3 3.0.2.9 3.0.2.7 3.0.2.8 3.0.2.6 trunk 1.0.0 2.0.0 All 85 releases
← All changes | app/Repositories/TripRepository.php +51 -12 3.0.15 → 3.0.17 View file →
@@ -691,20 +691,21 @@
691 691 foreach (array_unique($filters['age_suitability']) as $age) {
692 692 if (!is_string($age)) {
693 693 continue;
694 694 }
695 + $ageLimits = self::ageSuitabilityThresholds();
695 696 switch ($age) {
696 697 case 'family-friendly':
697 - $ageParts[] = '(t.age_min IS NULL OR t.age_min <= 5)';
698 + $ageParts[] = '(t.age_min IS NULL OR t.age_min <= ' . (int) $ageLimits['family_max'] . ')';
698 699 break;
699 700 case 'kids-friendly':
700 - $ageParts[] = '(t.age_min IS NULL OR t.age_min <= 12)';
701 + $ageParts[] = '(t.age_min IS NULL OR t.age_min <= ' . (int) $ageLimits['kids_max'] . ')';
701 702 break;
702 703 case 'senior-friendly':
703 - $ageParts[] = '(t.age_max IS NULL OR t.age_max >= 65)';
704 + $ageParts[] = '(t.age_max IS NULL OR t.age_max >= ' . (int) $ageLimits['senior_min'] . ')';
704 705 break;
705 706 case 'adults-only':
706 - $ageParts[] = 't.age_min >= 18';
707 + $ageParts[] = 't.age_min >= ' . (int) $ageLimits['adults_min'];
707 708 break;
708 709 }
709 710 }
710 711 if ($ageParts !== []) {
@@ -3730,16 +3731,48 @@
3730 3731 return 0;
3731 3732 }
3732 3733
3733 3734 /**
3735 + * Age thresholds behind the suitability filters.
3736 + *
3737 + * These were repeated as literals in six places — the filter query and the
3738 + * count query for each band — so an operator whose "kids" means under 18
3739 + * rather than under 12 had no way to say so, and changing it meant editing
3740 + * the same number in six spots and hoping none were missed.
3741 + *
3742 + * @return array{family_max:int, kids_max:int, senior_min:int, adults_min:int}
3743 + */
3744 + public static function ageSuitabilityThresholds(): array
3745 + {
3746 + $defaults = [
3747 + 'family_max' => 5,
3748 + 'kids_max' => 12,
3749 + 'senior_min' => 65,
3750 + 'adults_min' => 18,
3751 + ];
3752 +
3753 + $filtered = (array) apply_filters('yatra_age_suitability_thresholds', $defaults);
3754 +
3755 + foreach ($defaults as $key => $fallback) {
3756 + $filtered[$key] = isset($filtered[$key]) && is_numeric($filtered[$key])
3757 + ? (int) $filtered[$key]
3758 + : $fallback;
3759 + }
3760 +
3761 + return $filtered;
3762 + }
3763 +
3764 + /**
3734 3765 * Count family friendly trips
3735 3766 */
3736 3767 public function countByFamilyFriendly(): int
3737 3768 {
3738 3769 $table = $this->getTableName();
3770 + $limit = (int) self::ageSuitabilityThresholds()['family_max'];
3771 +
3739 3772 return (int) $this->wpdb->get_var(
3740 - "SELECT COUNT(*) FROM {$table}
3741 - WHERE status = 'publish' AND (age_min IS NULL OR age_min <= 5)"
3773 + "SELECT COUNT(*) FROM {$table}
3774 + WHERE status = 'publish' AND (age_min IS NULL OR age_min <= {$limit})"
3742 3775 );
3743 3776 }
3744 3777
3745 3778 /**
@@ -3747,11 +3780,13 @@
3747 3780 */
3748 3781 public function countByKidsFriendly(): int
3749 3782 {
3750 3783 $table = $this->getTableName();
3784 + $limit = (int) self::ageSuitabilityThresholds()['kids_max'];
3785 +
3751 3786 return (int) $this->wpdb->get_var(
3752 - "SELECT COUNT(*) FROM {$table}
3753 - WHERE status = 'publish' AND (age_min IS NULL OR age_min <= 12)"
3787 + "SELECT COUNT(*) FROM {$table}
3788 + WHERE status = 'publish' AND (age_min IS NULL OR age_min <= {$limit})"
3754 3789 );
3755 3790 }
3756 3791
3757 3792 /**
@@ -3759,11 +3794,13 @@
3759 3794 */
3760 3795 public function countBySeniorFriendly(): int
3761 3796 {
3762 3797 $table = $this->getTableName();
3798 + $limit = (int) self::ageSuitabilityThresholds()['senior_min'];
3799 +
3763 3800 return (int) $this->wpdb->get_var(
3764 - "SELECT COUNT(*) FROM {$table}
3765 - WHERE status = 'publish' AND (age_max IS NULL OR age_max >= 65)"
3801 + "SELECT COUNT(*) FROM {$table}
3802 + WHERE status = 'publish' AND (age_max IS NULL OR age_max >= {$limit})"
3766 3803 );
3767 3804 }
3768 3805
3769 3806 /**
@@ -3771,11 +3808,13 @@
3771 3808 */
3772 3809 public function countByAdultsOnly(): int
3773 3810 {
3774 3811 $table = $this->getTableName();
3812 + $limit = (int) self::ageSuitabilityThresholds()['adults_min'];
3813 +
3775 3814 return (int) $this->wpdb->get_var(
3776 - "SELECT COUNT(*) FROM {$table}
3777 - WHERE status = 'publish' AND age_min >= 18"
3815 + "SELECT COUNT(*) FROM {$table}
3816 + WHERE status = 'publish' AND age_min >= {$limit}"
3778 3817 );
3779 3818 }
3780 3819
3781 3820 /**