PluginProbe
ShiftController Employee Shift Scheduling / 4.9.85
ShiftController Employee Shift Scheduling v4.9.85
4.9.97 4.9.96 4.9.95 4.9.74 4.9.75 4.9.76 4.9.77 4.9.78 4.9.84 4.9.85 4.9.87 4.9.91 4.9.92 trunk 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 3.2.4 All 38 releases
shiftcontroller / sh4 / schedule / html / view / download.php

download.php in ShiftController Employee Shift Scheduling 4.9.85, at sh4/schedule/html/view/download.php

108 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if (! defined('ABSPATH')) exit; // Exit if accessed directly
2 #[AllowDynamicProperties]
3 class SH4_Schedule_Html_View_Download
4 {
5 public function __construct(
6 HC3_Hooks $hooks,
7
8 HC3_Ui $ui,
9 HC3_Request $request,
10 HC3_Time $t,
11 HC3_Translate $translate,
12 HC3_Settings $settings,
13
14 SH4_Shifts_Presenter $shiftsPresenter,
15
16 SH4_Calendars_Presenter $calendarsPresenter,
17 SH4_Shifts_View_Widget $widget,
18 SH4_Schedule_Html_View_Common $common
19 )
20 {
21 $this->ui = $ui;
22 $this->t = $t;
23 $this->request = $request;
24 $this->translate = $translate;
25
26 $this->calendarsPresenter = $hooks->wrap( $calendarsPresenter );
27 $this->shiftsPresenter = $hooks->wrap( $shiftsPresenter );
28
29 $this->widget = $hooks->wrap( $widget );
30 $this->common = $hooks->wrap( $common );
31 $this->settings = $hooks->wrap($settings);
32
33 $this->self = $hooks->wrap( $this );
34 }
35
36 public function render()
37 {
38 $params = $this->request->getParams();
39 $startDate = $params['start'];
40
41 $shifts = $this->common->getShifts();
42
43 $iknow = array();
44 $hori = TRUE;
45
46 $allEmployees = $this->common->findAllEmployees();
47 $allCalendars = $this->common->findAllCalendars();
48
49 $session = HC3_Session::instance();
50 $separator = $session->getUserdata( 'pref_csv_separator' );
51
52 if( ! $separator ){
53 $separator = $this->settings->get( 'pref_csv_separator' );
54 }
55 if( ! $separator ){
56 $separator = ',';
57 }
58
59 $shiftsOut = array();
60 $header = array();
61
62 foreach( $shifts as $shift ){
63 $thisOut = $this->shiftsPresenter->export( $shift );
64
65 $thisHeader = array_keys( $thisOut );
66 foreach( $thisHeader as $th ){
67 if( ! isset($header[$th]) ){
68 $header[$th] = $th;
69 }
70 }
71
72 $shiftsOut[] = $thisOut;
73 }
74
75 $keys = array_keys( $header );
76 $out = array();
77 reset( $shiftsOut );
78 foreach( $shiftsOut as $shiftOut ){
79 $thisOut = array();
80
81 reset( $keys );
82 foreach( $keys as $k ){
83 if( isset($shiftOut[$k]) ){
84 $thisOut[$k] = $this->translate->translate( $shiftOut[$k] );
85 }
86 else {
87 $thisOut[$k] = NULL;
88 }
89 }
90
91 $thisOut = HC3_Functions::buildCsv( $thisOut, $separator );
92 $out[] = $thisOut;
93 }
94
95 if( $out ){
96 $header = HC3_Functions::buildCsv( $header, $separator );
97 $header = array_unshift( $out, $header );
98 }
99
100 $out = join("\n", $out);
101
102 $fileName = 'export';
103 $fileName .= '-' . date('Y-m-d_H-i') . '.csv';
104
105 HC3_Functions::pushDownload( $fileName, $out );
106 exit;
107 }
108 }