/** * saves the new reservation selection * * @return JSON */ public function insertJsonAction() { // get the data $data = Zend_Json::decode($this->_getParam('data')); $unitID = $data['cid']; $userID = $data['uid']; $start = $data['start']; $end = $data['end']; // get the unit object $unitModel = new RM_Units(); $unit = $unitModel->get($unitID); // convert the date selection to a period object $periodObj = new RM_Reservation_Period(new RM_Date(strtotime($start)), new RM_Date(strtotime($end))); // check if the dates are allowed $reservationModel = new RM_ReservationDetails(); $currentReservationCount = $reservationModel->getReservationCount($unit, $periodObj); if ($currentReservationCount > 0) { return array('data' => array('success' => false, 'message' => RM_Environment::getInstance()->getTranslation(RM_Environment::TRANSLATE_MAIN)->_('Admin.Reservations.Edit', 'InvalidSelection'))); die; } $unitDetails = null; // reset the unit array for safe keeping $unitDetails = array(new RM_Reservation_Details($unit, $periodObj, new RM_Reservation_Persons())); $userModel = new RM_Users(); $user = $userModel->find($userID)->current(); // get the "system user" // get a reservation ID $reservationID = RM_Reservations::createReservationID(); $reservationModel = new RM_Reservations(); $result = $reservationModel->insertNewReservation($user, $unitDetails, 0, 1, $reservationID); if (!$result) { return array('data' => array('success' => false, 'message' => RM_Environment::getInstance()->getTranslation(RM_Environment::TRANSLATE_ERRORS)->_('Admin.Reservation.Edit', 'ServerError'))); } else { // mark the new block as paid $reservation = $reservationModel->find($reservationID)->current(); if ($userID === "") { $reservationModel->markPaid($reservation); } $idArray = explode("-", $reservationID); $id = (int) $idArray[1]; // check time $ad = true; // all day $starttime = explode(" ", $start); if ($starttime[1] !== "00:00:00") { $ad = false; } $endtime = explode(" ", $end); if ($endtime[1] !== "00:00:00") { $ad = false; } return array('data' => array("success" => true, "message" => RM_Environment::getInstance()->getTranslation(RM_Environment::TRANSLATE_MAIN)->_('Admin.Reservation.Edit', "LoadedData"), "data" => array("id" => $id, "cid" => $unitID, "uid" => (int) $userID, "title" => $reservationID, "start" => $start, "end" => $end, "ad" => $ad))); } }
/** * Return JSON data for the chart * * @return string */ function getData() { $config = new RM_Config(); $units = $this->_getUnits(); $datetimes = $this->_getDatetimes(); $reservationDetailsModel = new RM_ReservationDetails(); // for fusion charts we need xml, so the data needs to be formatted // so that the json data can render the xml using an xtemplate. // we need:- // array dates containing all dates of the period we need to chart. // array units containing 'name', 'color', array: 'data' containing the unit reservation count for each period $jsonSeries = new stdClass(); $jsonDates = new stdClass(); $feildsArray = array(); $jsonSeriesArray = array(); $jsonChartDataArray = array(); $feildsArray[] = 'date'; // this loop, loops through the units once to get the series data foreach ($units as $unit) { $feildsArray[] = 'unit' . $unit->getId(); $jsonSeries->yField = 'unit' . $unit->getId(); $jsonSeries->displayName = $unit->name; $jsonSeries->type = 'line'; // the graph type $jsonSeries->style = '{color: 0x' . $unit->color . '}'; // the graph type $jsonSeriesArray[] = clone $jsonSeries; } // this loop, loops through all dates and gets the data for each period for ($i = 0; $i < count($datetimes) - 1; $i++) { // get the date $date = $config->convertDates($datetimes[$i], RM_Config::PHP_DATEFORMAT, RM_Config::HUMAN_MONTH_DATEFORMAT); $chartData = array(); $chartData['date'] = $date; // loop through each unit foreach ($units as $unit) { $SdateParts = explode("-", $datetimes[$i]); $startDatetimes = mktime(0, 0, 0, (int) $SdateParts[1], (int) $SdateParts[2], (int) $SdateParts[0]); // set the endDatetimes to the last day of the month $EdateParts = explode("-", $datetimes[$i + 1]); $endDatetimes = mktime(0, 0, 0, (int) $EdateParts[1], (int) $SdateParts[2], (int) $EdateParts[0]); //mktime($hour, $minute, $second, $month, $day, $year) $period = new RM_Reservation_Period(new RM_Date($datetimes[$i]), new RM_Date($datetimes[$i + 1])); $count = $reservationDetailsModel->getReservationCount($unit, $period); $chartData['unit' . $unit->getId()] = $count; } //$chartData->units = $dataArray; $jsonChartDataArray[] = $chartData; } $returnData = new stdClass(); // fields: array containing all the fields ie: 'date', 'unit1', 'unit2', 'unit3' // // series: array containing objects for each series item:- // type: 'line',displayName: 'Unit 1',yField: 'unit1',style: {color:0x99BBE8} // note yField = the field name. // // data should contain the data:- // data: [ // {date:'Jul 07', unit1: 9, unit2: 11, unit3: 4}, // {date:'Aug 07', unit1: 5, unit2: 0, unit3: 3}, // {date:'Sep 07', unit1: 4, unit2: 0, unit3: 4}, // {date:'Oct 07', unit1: 8, unit2: 5, unit3: 5}, // {date:'Nov 07', unit1: 4, unit2: 6, unit3: 6}, // {date:'Dec 07', unit1: 0, unit2: 8, unit3: 7}, // {date:'Jan 08', unit1: 0, unit2: 11, unit3: 0}, // {date:'Feb 08', unit1: 8, unit2: 15, unit3: 7} // ] $returnData->fields = $feildsArray; $returnData->series = $jsonSeriesArray; $returnData->data = $jsonChartDataArray; return $returnData; }