Skip to content

Instantly share code, notes, and snippets.

Created May 17, 2013 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/a97a2ef9d8f9a532caf0 to your computer and use it in GitHub Desktop.
Save anonymous/a97a2ef9d8f9a532caf0 to your computer and use it in GitHub Desktop.
public function Availability() {
$check = $this->Places - $this->Bookings()->Sum('NumSlots');
if ($check < 1) {
return "Unavailable";
} else {
return "Available";
}
}
public function getAvailablePlaces() {
return $this->Places - $this->Bookings()->Sum('NumSlots');
}
public function getAvailablePlacesDropDown() {
$placesremaining = $this->Places - $this->Bookings()->Sum('NumSlots');
$range = range(1, $placesremaining, 1);
$fieldset = new DropdownField('NumSlots', 'NumSlots', array_combine($range, $range));
return $fieldset;
}
@kinglozzer
Copy link

public $AvailablePlaces;

public function init() {
        parent::init();
        $this->AvailablePlaces = $this->Places - $this->Bookings()->Sum('NumSlots');
}

public function Availability() {
        if ($this->AvailablePlaces < 1) {
            return "Unavailable";
        } else {
            return "Available";
        }
}

public function getAvailablePlaces() {
    return $this->AvailablePlaces;
}

public function getAvailablePlacesDropDown() {
        $range = range(1, $this->AvailablePlaces, 1);
        $fieldset = new DropdownField('NumSlots', 'NumSlots', array_combine($range, $range));
        return $fieldset;

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment