static function getSlots() { $config = CRM_Booking_BAO_BookingConfig::getConfig(); $bookedColour = CRM_Utils_Array::value('slot_booked_colour', $config); $provisionalColour = CRM_Utils_Array::value('slot_provisional_colour', $config); $booking = NULL; if (!empty($_GET['booking_id'])) { $bookingId = CRM_Utils_Type::escape($_GET['booking_id'], 'String'); } $timeshift = CRM_Utils_Type::escape($_GET['timeshift'], 'String'); $from = CRM_Utils_Type::escape($_GET['from'], 'String'); $to = CRM_Utils_Type::escape($_GET['to'], 'String'); $slots = array("data" => array()); $results = CRM_Booking_BAO_Slot::getSlotBetweenDate($from, $to); foreach ($results as $key => $slot) { if ($bookingId != CRM_Utils_Array::value('booking_id', $slot)) { //do not thing $params = array('id' => CRM_Utils_Array::value('booking_id', $slot)); CRM_Booking_BAO_Booking::retrieve($params, $booking); $bookingStatus = CRM_Utils_Array::value('status_id', $booking); $displayName = CRM_Contact_BAO_Contact::displayName(CRM_Utils_Array::value('primary_contact_id', $booking)); $data = array("id" => $key, "start_date" => CRM_Utils_Array::value('start', $slot), "end_date" => CRM_Utils_Array::value('end', $slot), "text" => CRM_Utils_Array::value('booking_id', $slot) . ' : ' . $displayName, "resource_id" => CRM_Utils_Array::value('resource_id', $slot), "configuration_id" => CRM_Utils_Array::value('config_id', $slot), "price" => CRM_Booking_BAO_Slot::calulatePrice($slot['config_id'], $slot['quantity']), "quantity" => CRM_Utils_Array::value('quantity', $slot), "note" => CRM_Utils_Array::value('note', $slot), "readonly" => true, "booking_id" => CRM_Utils_Array::value('booking_id', $slot)); if ($bookingStatus == 1) { //Provisional, TODO: Fixed to get the value from the name i.e provisional $data['color'] = $provisionalColour; } else { $data['color'] = $bookedColour; } array_push($slots['data'], $data); } } echo json_encode($slots); CRM_Utils_System::civiExit(); }
/** * * * @return void * @author */ static function getSlotDetailsOrderByResourceBetweenDate($from, $to) { $slots = array(); $slotsResult = CRM_Booking_BAO_Slot::getSlotBetweenDate($from, $to); foreach ($slotsResult as $key => $slotItem) { //get booking detail $params = array('booking_id' => $slotItem['booking_id']); $bookingResult = civicrm_api3('Booking', 'get', $params); $bookingValues = CRM_Utils_Array::value('values', $bookingResult); foreach ($bookingValues as $k1 => $booking) { //set booking detail $slotItem['function_title'] = $booking['title']; $slotItem['note'] = isset($booking['note']) ? $booking['note'] : NULL; $slotItem['estimated_participant'] = isset($booking['participants_estimate']) ? $booking['participants_estimate'] : NULL; //get contacts detail if (isset($booking['primary_contact_id'])) { $paramsContact = array('contact_id' => $booking['primary_contact_id']); $contactResult = civicrm_api3('Contact', 'get', $paramsContact); $contactValue = CRM_Utils_Array::value('values', $contactResult); foreach ($contactValue as $k2 => $primaryContact) { //set primary contact $slotItem['primary_contact'] = $primaryContact['display_name']; } } if (isset($booking['secondary_contact_id'])) { $paramsContact = array('contact_id' => $booking['secondary_contact_id']); $contactResult = civicrm_api3('Contact', 'get', $paramsContact); $contactValue = CRM_Utils_Array::value('values', $contactResult); foreach ($contactValue as $k2 => $secondContact) { //set secondary contact $slotItem['secondary_contact'] = $secondContact['display_name']; } } } $slotItem['resource_config_label'] = CRM_Core_DAO::getFieldValue('CRM_Booking_DAO_ResourceConfigOption', $slotItem['config_id'], 'label', 'id'); //get resource config detail $slotItem['resource_label'] = CRM_Core_DAO::getFieldValue('CRM_Booking_DAO_Resource', $slotItem['resource_id'], 'label', 'id'); //get sub slot $subSlots = array(); $params = array('slot_id' => $slotItem['id'], 'entity_table' => 'civicrm_booking_sub_slot'); $subSlotResult = civicrm_api3('SubSlot', 'get', $params); $subSlotValues = CRM_Utils_Array::value('values', $subSlotResult); foreach ($subSlotValues as $k1 => $subSlotItem) { //set sub slot detail if ($subSlotItem['is_deleted'] == 0) { $subSlots[$k1]['sub_resource_label'] = CRM_Core_DAO::getFieldValue('CRM_Booking_DAO_Resource', $subSlotItem['resource_id'], 'label', 'id'); $subSlots[$k1]['sub_resource_config_label'] = CRM_Core_DAO::getFieldValue('CRM_Booking_DAO_ResourceConfigOption', $subSlotItem['config_id'], 'label', 'id'); $subSlots[$k1]['time_required'] = $subSlotItem['time_required']; $subSlots[$k1]['quantity'] = $subSlotItem['quantity']; $subSlots[$k1]['booking_id'] = $slotItem['booking_id']; $subSlots[$k1]['primary_contact'] = $slotItem['primary_contact']; $subSlots[$k1]['secondary_contact'] = isset($slotItem['secondary_contact']) ? $slotItem['secondary_contact'] : NULL; $subSlots[$k1]['note'] = isset($subSlotItem['note']) ? $subSlotItem['note'] : NULL; } } //final setting values $slotItem['sub_resources'] = !empty($subSlots) ? $subSlots : NULL; $slots[$key] = $slotItem; } //rearrange items by resource $orderResource = array(); foreach ($slots as $key => $slotItem) { //retrieve resource_labels $tempArray = array('id' => CRM_Utils_Array::value('resource_id', $slotItem), 'label' => CRM_Utils_Array::value('resource_label', $slotItem), 'slot' => array(), 'subslot' => array()); if (!array_search($tempArray, $orderResource)) { $orderResource[$key] = $tempArray; } } foreach ($orderResource as $key => $resItem) { foreach ($slots as $k1 => $slotItem) { if ($resItem['label'] == $slotItem['resource_label']) { $orderResource[$key]['slot'][] = $slotItem; if (!empty($slotItem['sub_resources'])) { $orderResource[$key]['subslot'][] = $slotItem['sub_resources']; } } } } return $orderResource; }