Browse files

CSV view for calendars

  • Loading branch information...
1 parent f3418ef commit a630a2ceba43b016d031fa57a1f86df16d007e04 @tareko committed Dec 9, 2012
Showing with 59 additions and 3 deletions.
  1. +1 −1 app/Controller/ShiftsController.php
  2. +48 −2 app/View/Helper/CalendarHelper.php
  3. +10 −0 app/View/Shifts/csv/calendar_view.ctp
View
2 app/Controller/ShiftsController.php
@@ -189,7 +189,7 @@ function calendarEdit() {
}
function calendarView() {
- $this->Prg->commonProcess();
+ $this->Prg->commonProcess();
$this->loadModel('Calendar');
$this->loadModel('Profile');
View
50 app/View/Helper/CalendarHelper.php
@@ -274,5 +274,51 @@ function makeCalendarPdf($masterSet) {
return $output;
}
-}
-?>
+
+
+ function makeCalendarCsv($masterSet) {
+ //Create variables
+ $i = 1;
+ $header = null;
+ $output = array();
+ $calendar = $masterSet['calendar'];
+ $startDate = $calendar['Calendar']['start_date'];
+ $endDate = $calendar['Calendar']['end_date'];
+ $k = $startDate;
+
+ // Create headers
+ $output[] = array($calendar['Calendar']['name']);
+ $temp_headers[] = "Date";
+
+ foreach ($masterSet['ShiftsType'] as $shiftsType) {
+ $temp_headers[] = $masterSet['locations'][$shiftsType['ShiftsType']['location_id']]['location'];
+ }
+ $output[] = $temp_headers;
+ $output1[] = "";
+
+ foreach ($masterSet['ShiftsType'] as $shiftsType) {
+ $output1[] = $shiftsType['ShiftsType']['times'];
+ }
+ $output[] = $output1;
+
+
+ //Output Days of the month
+ while ($k <= $calendar['Calendar']['end_date']) {
+ $output1 = null;
+ $output1[] = date('Y-m-d', strtotime($k));
+ foreach ($masterSet['ShiftsType'] as $shiftsType) {
+ if (isset($masterSet[$k][$shiftsType['ShiftsType']['location_id']][$shiftsType['ShiftsType']['id']])) {
+ $output1[] = $masterSet[$k][$shiftsType['ShiftsType']['location_id']][$shiftsType['ShiftsType']['id']]['name'];
+ }
+ else {
+ $output1[] = "";
+ }
+ }
+ // Enter physician names into record, spaced with comma
+ $output[] = $output1;
+ $k = date('Y-m-d', strtotime("$k + 1 day"));
+ }
+
+ return $output;
+ }
+}
View
10 app/View/Shifts/csv/calendar_view.ctp
@@ -0,0 +1,10 @@
+<?php
+// Loop through the data array
+
+$data = $this->Calendar->makeCalendarCsv($masterSet);
+
+ foreach ($data as $row)
+{
+ // Echo all values in a row comma separated
+ echo implode(",",$row)."\n";
+}

0 comments on commit a630a2c

Please sign in to comment.