/** * Return checkout status for currently loaded object. By default a numeric constant is returned. Possible values are: * __CA_OBJECTS_CHECKOUT_STATUS_AVAILABLE__ (0) * __CA_OBJECTS_CHECKOUT_STATUS_OUT__ (1) * __CA_OBJECTS_CHECKOUT_STATUS_OUT_WITH_RESERVATIONS__ (2) * __CA_OBJECTS_CHECKOUT_STATUS_RESERVED__ (3) * * If the returnAsText option is set then a text status value suitable for display is returned. For detailed information * about the current status use the returnAsArray option, which returns an array with the following elements: * * status = numeric status code * status_display = status display text * user_id = The user_id of the user who checked out the object (if status is __CA_OBJECTS_CHECKOUT_STATUS_OUT__ or __CA_OBJECTS_CHECKOUT_STATUS_OUT_WITH_RESERVATIONS__) * user_name = Displayable user name and email * checkout_date = Date of checkout (if status is __CA_OBJECTS_CHECKOUT_STATUS_OUT__ or __CA_OBJECTS_CHECKOUT_STATUS_OUT_WITH_RESERVATIONS__) as printable text * * @param array $pa_options Options include: * returnAsText = return status as displayable text [Default=false] * returnAsText = return detailed status information in an array [Default=false] * @return mixed Will return a numeric status code by default; status text for display if returnAsText option is set; or an array with details on the checkout if the returnAsArray option is set. Will return null if not object is loaded or if the object may not be checked out. */ public function getCheckoutStatus($pa_options = null) { if (!($vn_object_id = $this->getPrimaryKey())) { return null; } if (!$this->canBeCheckedOut()) { return null; } $vb_return_as_text = caGetOption('returnAsText', $pa_options, false); $vb_return_as_array = caGetOption('returnAsArray', $pa_options, false); $t_checkout = new ca_object_checkouts(); $va_is_out = $t_checkout->objectIsOut($vn_object_id); $va_reservations = $t_checkout->objectHasReservations($vn_object_id); $vn_num_reservations = sizeof($va_reservations); $vb_is_reserved = is_array($va_reservations) && sizeof($va_reservations); $va_info = array('user_name' => null, 'checkout_date' => null, 'user_id' => null, 'due_date' => null, 'checkout_notes' => null); if ($va_is_out) { $t_checkout->load($va_is_out['checkout_id']); $va_info['status'] = $vb_is_reserved ? __CA_OBJECTS_CHECKOUT_STATUS_OUT_WITH_RESERVATIONS__ : __CA_OBJECTS_CHECKOUT_STATUS_OUT__; $va_info['status_display'] = $vb_is_reserved ? $vn_num_reservations == 1 ? _t('Out; %1 reservation', $vn_num_reservations) : _t('Out; %1 reservations', $vn_num_reservations) : _t('Out'); $va_info['user_id'] = $va_is_out['user_id']; $va_info['checkout_date'] = $t_checkout->get('checkout_date', array('timeOmit' => true)); $va_info['checkout_notes'] = $t_checkout->get('checkout_notes'); $va_info['due_date'] = $t_checkout->get('checkout_date', array('timeOmit' => true)); $va_info['user_name'] = $t_checkout->get('ca_users.fname') . ' ' . $t_checkout->get('ca_users.lname') . (($vs_email = $t_checkout->get('ca_users.email')) ? " ({$vs_email})" : ''); } elseif ($vb_is_reserved) { $va_info['status'] = __CA_OBJECTS_CHECKOUT_STATUS_RESERVED__; $va_info['status_display'] = $vn_num_reservations == 1 ? _t('Reserved') : _t('%1 reservations', $vn_num_reservations); } else { $va_info['status'] = __CA_OBJECTS_CHECKOUT_STATUS_AVAILABLE__; $va_info['status_display'] = _t('Available'); } if ($vb_return_as_array) { return $va_info; } if ($vb_return_as_text) { return $va_info['status_display']; } return $va_info['status']; }