pagination export csv cakephp

Solutions on MaxInterview for pagination export csv cakephp by the best coders in the world

showing results for - "pagination export csv cakephp"
Nickolas
21 Oct 2019
1// model
2public function get_data_guest_export($conditions, $page, $limit, $lang){
3        $all_settings = array(
4            'conditions' => $conditions,
5            'contain' => array(
6				'Member' => array(
7					'fields' => array(
8						'Member.first_name',
9						'Member.last_name',
10					),
11				),
12				'BuildingFacility' => array(
13					'fields' => array(
14						'BuildingFacility.id',
15					),
16					'BuildingFacilityLanguage' => array(
17						'conditions' => array(
18							'BuildingFacilityLanguage.alias' => $lang,
19						),
20					),
21					'BuildingPost' => array(
22						'BuildingPostLanguage' => array(
23							'conditions' => array(
24								'BuildingPostLanguage.alias' => $lang,
25							),
26						),
27					),
28				),
29				'Company' => array(
30					'CompanyLanguage' => array(
31						'conditions' => array(
32							'CompanyLanguage.alias' => $lang,
33						),
34					),
35				),
36				'CreatedBy',
37				'UpdatedBy'
38            ), 
39            'order' => array('Member.id DESC'),
40            'limit' => $limit,
41            'page' => $page
42        );
43
44		return $this->find('all', $all_settings);
45	}
46	
47	// __('id'),
48	// __d('building', 'building_post'),
49	// __d('building', 'building_facility'),
50	// __('name'),
51	// __d('member','name'),
52	// __d('building','date'),
53	// __d('building','time'),
54	// __('enabled'),
55	// __('created'),
56	// __('created_by'),
57	// __('updated'),
58	// __('updated_by'),
59
60    public function format_data_guest_export($data, $row) {
61
62        return array(
63            @$row['MemberBookFacility']['id'],
64			isset($row['BuildingFacility']['BuildingPost']['BuildingPostLanguage']) && !empty($row['BuildingFacility']['BuildingPost']['BuildingPostLanguage']) ? reset($row['BuildingFacility']['BuildingPost']['BuildingPostLanguage'])['title'] : '',
65			isset($row['BuildingFacility']['BuildingFacilityLanguage']) && !empty($row['BuildingFacility']['BuildingFacilityLanguage']) ? reset($row['BuildingFacility']['BuildingFacilityLanguage'])['title'] : '',
66			isset($row['Company']['CompanyLanguage']) && !empty($row['Company']['CompanyLanguage']) ? reset($row['Company']['CompanyLanguage'])['name'] : '',
67			$row['Member']['first_name'] . " " . $row['Member']['last_name'],
68			isset($row['MemberBookFacility']['date']) 	? $row['MemberBookFacility']['date'] : '',
69			isset($row['MemberBookFacility']['time']) 	? $row['MemberBookFacility']['time'] : '',
70		    $row['MemberBookFacility']['enabled'] == 1 ? 'Y' : 'N',
71            isset($row['MemberBookFacility']["created"]) ? $row['MemberBookFacility']["created"] : '',
72            isset($row['CreatedBy']["email"]) ? $row['CreatedBy']["email"] : '',
73            isset($row['MemberBookFacility']["updated"]) ? $row['MemberBookFacility']["updated"] : '',
74            isset($row['UpdatedBy']["email"]) ? $row['UpdatedBy']["email"] : '',
75        );
76	}
77
78
79
80// controller
81
82public function admin_guest_export(){
83		$this->disableCache();
84
85		if( $this->request->is('get') ) {
86            $limit = 1000;
87
88            $header = array(
89                __('id'),
90                __d('building', 'building_post'),
91				__d('building', 'building_facility'),
92				__('name'),
93				__d('member','name'),
94                __d('building','date'),
95                __d('building','time'),
96				__('enabled'),
97                __('created'),
98                __('created_by'),
99                __('updated'),
100                __('updated_by'),
101            );
102
103            try{
104                $file_name = 'member_book_facility_' . date('Y-m-d h-i');
105				$data_binding = array();
106
107                // export xls
108                if ($this->request->type == "xls") {
109                    $this->ExcelSpout->setup_export_excel($header, 'Member.Member', $data_binding, $this->request->conditions, $limit, $file_name, $this->lang18);
110                } else {
111					
112                    $this->Common->setup_export_csv($header, 'Member.MemberBookFacility', $data_binding, $this->request->conditions, $limit, $file_name, $this->lang18, 1);
113                }
114				exit;
115				
116            } catch ( Exception $e ) {
117                $this->LogFile->writeLog($this->LogFile->get_system_error(), $e->getMessage());
118                $this->Session->setFlash(__('export_csv_fail') . ": " . $e->getMessage(), 'flash/error');
119            }
120		}
121	}
122
123