/**
  * Creates the Calendar Data (Free/Busy Time)
  *
  * This creates the blocked and reserved period data for use by the calendar.
  * It uses data from the reservations table and creates a JSON string
  * containing the data. This data is read by the calendar JS and plotted
  * accordingly.
  *
  * This function handles new and existing reservations, new reservations do
  * not exist in the reservations tables so we have to build the selected
  * information, such as the id, start and end dates.
  *
  * @deprecated
  * @param   request type indicates if this is a new or existing reservation.
  * @param   request id the reservation id.
  * @param   request start_datetime   the selected reservation start date
  * @param   request end_datetime   the selected reservation end date
  * @return   json    returns json array information containing reserved_periods and blocked_periods
  */
 public function calendarJsonAction()
 {
     $type = $this->_getParam('type', '');
     $model = new RM_Reservations();
     $config = new RM_Config();
     // if the type = new then there will be no id in the live db to check
     if ($type == "new") {
         // build the reservation info...
         $reservation->id = $this->_getParam('id', '');
         $reservation->start_datetime = $this->_getParam('start_datetime', '');
         $reservation->end_datetime = $this->_getParam('end_datetime', '');
     } else {
         $id = $this->_getParam('id', '');
         $reservation = $model->find($id)->current();
     }
     $reservations = $model->fetchAllLinkedByUnit($reservation);
     $jsonDisabledPeriods = array();
     foreach ($reservations as $period) {
         if ($period->id == $reservation->id) {
             continue;
         }
         $jsonPeriod = new stdClass();
         $jsonPeriod->start_date = $config->convertDates($period->start_datetime, RM_Config::JS_DATEFORMAT, RM_Config::PHP_DATEFORMAT);
         $jsonPeriod->end_date = $config->convertDates($period->end_datetime, RM_Config::JS_DATEFORMAT, RM_Config::PHP_DATEFORMAT);
         $jsonDisabledPeriods[] = clone $jsonPeriod;
     }
     $jsonReservation = new stdClass();
     $jsonReservation->start_date = $config->convertDates($reservation->start_datetime, RM_Config::JS_DATEFORMAT, RM_Config::PHP_DATEFORMAT);
     $jsonReservation->end_date = $config->convertDates($reservation->end_datetime, RM_Config::JS_DATEFORMAT, RM_Config::PHP_DATEFORMAT);
     $jsonReservations[] = $jsonReservation;
     $json = "{\n            reserved_periods: " . Zend_Json::encode($jsonReservations) . ",\n            blocked_periods: " . Zend_Json::encode($jsonDisabledPeriods) . "\n        }";
     return array('data' => $json, 'encoded' => true);
 }