Gender is taken from previous row

Created on 16 October 2023, about 1 year ago
Updated 17 October 2023, about 1 year ago

Problem/Motivation

Consider the following array coming from Daxko:

[
    {
      "id": "SES921183",
      "type": "session",
      "name": "Youth Basketball Coed Ages 8-10 Yrs.",
      "description": "There's no better place to learn the game of basketball than where it was invented. Kids who play basketball and engage in healthy competition discover so much more than their athletic abilities. We encourage kids to challenge themselves as players and people. Volunteer coaches lead players in drills and games designed to develop the fundamental skills of ball handling, dribbling, passing, shooting and defense. Ages 3-4 will have 30 minute clinic/scrimmage sessions on Saturdays. Ages 5-13 practice one night a week and play games on Saturday.",
      "restrictions": {
        "genders": [
          {
            "id": "F",
            "name": "Female"
          }
        ],
        "dob": {
          "start": "2012-12-04T00:00:00.0000000",
          "end": "2015-12-03T00:00:00.0000000"
        },
        "age": {
          "start": 8,
          "end": 10
        }
      }
    },
    {
      "id": "SES921176",
      "type": "session",
      "name": "Youth Basketball Coed Ages 5-7 Yrs.",
      "description": "There's no better place to learn the game of basketball than where it was invented. Kids who play basketball and engage in healthy competition discover so much more than their athletic abilities. We encourage kids to challenge themselves as players and people. Volunteer coaches lead players in drills and games designed to develop the fundamental skills of ball handling, dribbling, passing, shooting and defense. Ages 3-4 will have 30 minute clinic/scrimmage sessions on Saturdays. Ages 5-13 practice one night a week and play games on Saturday.",
      "restrictions": {
        "genders": [
          {
            "id": "M",
            "name": "Male"
          },
          {
            "id": "F",
            "name": "Female"
          }
        ],
        "dob": {
          "start": "2015-12-04T00:00:00.0000000",
          "end": "2018-12-03T00:00:00.0000000"
        },
        "age": {
          "start": 5,
          "end": 7
        }
      },
    }
]

Once the code processes first item, it reaches https://git.drupalcode.org/project/openy_daxko2/-/blob/main/src/OpenyAct...
and sets the $gender variable to be equal "Female":

if (isset($row['restrictions']['genders']) && count($row['restrictions']['genders']) == 1) {
  $gender = reset($row['restrictions']['genders']);
  $gender = $gender['name'];
}

Now the code processes second item, that has the following:

"genders": [
  {
    "id": "M",
    "name": "Male"
  },
  {
    "id": "F",
    "name": "Female"
  }
]

the condition count($row['restrictions']['genders']) == 1 will return FALSE thus the $gender variable won't be changed from the previous cycle run, passing "Female" to the results array.

Proposed resolution

Reset the $gender variable before the condition.

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡¦Ukraine Sardis

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024