public function setOperationStatus($event_id, $status_name) { if (!($operation = Element_OphTrOperationbooking_Operation::model()->find('event_id=?', array($event_id)))) { throw new Exception("Operation event not found: {$event_id}"); } if ($status_name == 'Scheduled or Rescheduled') { if (OphTrOperationbooking_Operation_Booking::model()->find('element_id=? and booking_cancellation_date is not null', array($operation->id))) { $status_name = 'Rescheduled'; } else { $status_name = 'Scheduled'; } } if (!($status = OphTrOperationbooking_Operation_Status::model()->find('name=?', array($status_name)))) { throw new Exception("Unknown operation status: {$status_name}"); } if ($operation->status_id != $status->id) { $operation->status_id = $status->id; if (!$operation->save()) { throw new Exception('Unable to save operation: ' . print_r($operation->getErrors(), true)); } } }
/** * Set the status based on the name passed in. If $save is false, we don't save and it is the responsibility * of the caller to ensure the instance is saved. * * @param $name * @param bool $save * * @throws Exception */ public function setStatus($name, $save = true) { if (!($status = OphTrOperationbooking_Operation_Status::model()->find('name=?', array($name)))) { throw new Exception('Invalid status: ' . $name); } $this->status_id = $status->id; if ($save && !$this->save()) { throw new Exception('Unable to change operation status: ' . print_r($this->getErrors(), true)); } }