/**
  * Saves current allocation to the db.
  * $mysqli : manual db connection (for transaction handling)
  * $bookingId : booking id for this allocation
  * Returns allocation id of newly created record
  * Throws AllocationException on resource conflict
  */
 function save($mysqli, $bookingId)
 {
     global $wpdb;
     // create the allocation if it doesn't exist
     if ($this->id == 0) {
         $allocationId = AllocationDBO::insertAllocation($mysqli, $bookingId, $this->resourceId, $this->name, $this->gender, $this->reqRoomSize, $this->reqRoomType);
         error_log("inserted allocation {$allocationId}");
         // then create the booking dates for the allocation
         AllocationDBO::insertBookingDates($mysqli, $allocationId, $this->bookingDates);
     } else {
         // update the existing allocation
         AllocationDBO::updateAllocation($mysqli, $this->id, $this->resourceId, $this->name, $this->gender, $this->resourceMap);
         error_log("updating allocation {$this->id}");
         // clear out those with blank statuses (these are dates now marked as 'available')
         foreach ($this->bookingDates as $dt => $bookingDate) {
             if ($bookingDate->status == '') {
                 unset($this->bookingDates[$dt]);
             }
         }
         // diff existing booking dates with the ones we want to save
         AllocationDBO::mergeUpdateBookingDates($mysqli, $this->id, $this->bookingDates);
     }
     return $allocationId;
 }