You are here

function appointment_calendar_view_date_form in Appointment Calendar 7

Implements hook_form().

1 string reference to 'appointment_calendar_view_date_form'
appointment_calendar_menu in ./appointment_calendar.module
Implements hook_menu().

File

./appointment_calendar_view.inc, line 11
Provides View page for selected date to change only slot capacity.

Code

function appointment_calendar_view_date_form($form, $form_state) {

  // Date edit page.
  $query = drupal_get_query_parameters();
  if (!empty($query['date'])) {
    global $base_url;
    $form['redirect'] = array(
      '#markup' => '<a href="' . $base_url . '/admin/config/appointment-calendar/settings">Goto Appointment Calendar Setting Page</a><br>',
    );
    $form['listredirect'] = array(
      '#markup' => '<a href="' . $base_url . '/admin/config/appointment-calendar/settings/list-date">Goto Appointment Calendar Listing Page</a>',
    );
    $form['appointment_slot_date'] = array(
      '#type' => 'textfield',
      '#title' => 'Date',
      '#default_value' => date('Y-m-d', $query['date']),
      '#disabled' => TRUE,
    );

    // Fetching Slot previous capacity filled.
    $capacity = appointment_calendar_slot_capacity($query['date']);
    $header = [
      'Slot Time',
      'No. Of Slots alloted',
      'Booked Slots',
      'Status',
    ];
    $i = 1;

    // Show slots and capacity.
    foreach (json_decode($capacity) as $key => $value) {

      // Check if any appointment booked.
      $date = db_like(date('Y-m-d', $query['date'])) . 'T' . $key;
      $explode_date = explode(':', $date);
      $date_query = db_select('field_data_appointment_date', 'ap');
      $date_query
        ->fields('ap', array(
        'appointment_date_value ',
      ));
      $date_query
        ->condition('ap.appointment_date_value', $explode_date[0] . ':00:00', '=');
      $date_queryresult = $date_query
        ->execute()
        ->fetchAll(PDO::FETCH_ASSOC);
      $slot_check = count($date_queryresult);
      if ($slot_check >= $value) {
        $row[$key]['slot'] = $key;
        $row[$key]['no_slots'] = $value;
        $row[$key]['booked_slots'] = $slot_check;
        $row[$key]['status'] = 'Booked';
      }
      else {
        $row[$key]['slot'] = $key;
        $row[$key]['no_slots'] = $value;
        $row[$key]['booked_slots'] = $slot_check;
        $row[$key]['status'] = 'Free';
      }
    }
    $output = theme('table', array(
      'header' => $header,
      'rows' => $row,
    ));
    $form['ouptut'] = array(
      '#markup' => $output,
    );
    return $form;
  }
}