6
var $components = array('DataHandler','ForceDownload');
6
var $components = array('DataHandler','ForceDownload');
8
function beforeRender(){
10
$this->set('navigation','main_nav_' . $this->Auth->user('role'));
12
$this->set('subNavigation','items_' . $this->Auth->user('role'));
8
function beforeRender(){
9
$this->set('navigation','main_nav_' . $this->Auth->user('role'));
10
$this->set('subNavigation','items_' . $this->Auth->user('role'));
17
$this->checkForEvent();
18
$event = $this->Item->Event->find('first',array('conditions' => array('Event.id' => $this->Session->read('event_id'))));
19
$this->paginate = array('conditions' => array('Item.event_id' => $this->Session->read('event_id')));
20
$items = $this->paginate('Item');
21
$this->set(compact('items', 'event'));
14
$this->checkForEvent();
15
$event = $this->Item->Event->find('first',array('conditions' => array('Event.id' => $this->Session->read('event_id'))));
16
$this->paginate = array('conditions' => array('Item.event_id' => $this->Session->read('event_id')));
17
$items = $this->paginate('Item');
18
$this->set(compact('items', 'event'));
24
21
function view($id = null) {
26
23
$this->Session->setFlash(__('Invalid item', true));
27
24
$this->redirect(array('action' => 'index'));
29
$item = $this->Item->find('first',array('conditions' => array('Item.id' => $id)));
30
$bidder = $this->Item->Bid->Bidder->findById(@$item['Bid'][0]['bidder_id']);
26
$item = $this->Item->find('first',array('conditions' => array('Item.id' => $id)));
27
$bidder = $this->Item->Bid->Bidder->findById(@$item['Bid'][0]['bidder_id']);
31
28
$this->set(compact('item', 'bidder'));
34
31
function add($vendorId='') {
35
$this->isAuthorized();
36
$this->checkForEvent();
32
$this->isAuthorized();
33
$this->checkForEvent();
37
34
if (!empty($this->data)) {
38
35
$this->Item->create();
39
36
if ($this->Item->save($this->data)) {
40
$this->Session->setFlash(__('The item has been saved', true));
37
$this->Session->setFlash(__('The item has been saved', true),'default', array('class'=>'success-message'));
41
38
$this->redirect(array('action' => 'index'));
43
40
$this->Session->setFlash(__('The item could not be saved. See below.', true));
46
43
$itemCategories = $this->Item->ItemCategory->find('list');
47
44
$itemTypes = $this->Item->ItemType->find('list');
48
45
$vendors = $this->Item->Vendor->find('list');
49
$event = $this->Item->Event->find('first',array('conditions' => array('Event.id' => $this->Session->read('event_id'))));
50
setlocale(LC_MONETARY, 'en_US');
46
$event = $this->Item->Event->find('first',array('conditions' => array('Event.id' => $this->Session->read('event_id'))));
47
setlocale(LC_MONETARY, 'en_US');
51
48
$this->set(compact('itemCategories', 'itemTypes', 'vendors', 'event','vendorId'));
54
51
function edit($id = null) {
55
$this->isAuthorized();
56
$this->checkForEvent();
52
$this->isAuthorized();
53
$this->checkForEvent();
57
54
if (!$id && empty($this->data)) {
58
55
$this->Session->setFlash(__('Invalid item', true));
59
56
$this->redirect(array('action' => 'index'));
61
58
if (!empty($this->data)) {
62
59
if ($this->Item->save($this->data)) {
63
$this->Session->setFlash(__('The item has been saved', true));
60
$this->Session->setFlash(__('The item has been saved', true),'default', array('class'=>'success-message'));
64
61
$this->redirect(array('action' => 'index'));
66
63
$this->Session->setFlash(__('The item could not be saved. Please, try again.', true));
83
80
$this->redirect(array('action'=>'index'));
85
82
if ($this->Item->delete($id)) {
86
$this->Session->setFlash(__('Item deleted', true));
83
$this->Session->setFlash(__('Item deleted', true),'default', array('class'=>'success-message'));
87
84
$this->redirect(array('action'=>'index'));
89
86
$this->Session->setFlash(__('Item was not deleted', true));
90
87
$this->redirect(array('action' => 'index'));
93
function export_csv() {
94
$formatted_items = array();
96
$this->Item->recursive = 1;
97
$params = array('conditions' => array('Item.event_id' => $this->Session->read('event_id')),
98
'order' => array('Item.title' => 'asc'));
99
$items = $this->Item->find('all',$params);
102
foreach ($items as $item) {
103
$formatted_items[$x]['Item'] = array(
104
'item' => $item['Item']['title'],
105
'description' => $item['Item']['description'],
106
'item_id' => $item['Item']['id'],
107
'value' => number_format($item['Item']['value'],2),
108
'category' => $item['ItemCategory']['description'],
109
'type' => $item['ItemType']['description'],
110
'vendor' => $item['Vendor']['description'],
111
'event' => $item['Event']['title']
114
$bidInfo = $this->Item->Bid->findById($item['Bid'][0]['id']);
115
$formatted_items[$x]['Item'] += array(
116
'bidder_id' => $bidInfo['Bidder']['id'],
117
'bidder_first_name' => $bidInfo['Bidder']['first_name'],
118
'bidder_last_name' => $bidInfo['Bidder']['last_name'],
119
'bidder_business_name' => $bidInfo['Bidder']['business_name'],
120
'bidder_phone' => $bidInfo['Bidder']['phone'],
121
'bidder_email' => $bidInfo['Bidder']['email'],
122
'bid_amount' => $bidInfo['Bid']['bid_amount'],
123
'paid' => $bidInfo['Bid']['paid']
128
$fieldNames = array_keys($formatted_items[0]['Item']);
129
$csv_data = $this->DataHandler->createCSV($formatted_items,$fieldNames);
130
$this->ForceDownload->forceDownloadStream($csv_data,'csv','item_list.csv');
90
function export_csv() {
91
$formatted_items = array();
93
$this->Item->recursive = 1;
94
$params = array('conditions' => array('Item.event_id' => $this->Session->read('event_id')),
95
'order' => array('Item.title' => 'asc'));
96
$items = $this->Item->find('all',$params);
99
foreach ($items as $item) {
100
$formatted_items[$x]['Item'] = array(
101
'item' => $item['Item']['title'],
102
'description' => $item['Item']['description'],
103
'item_id' => $item['Item']['id'],
104
'value' => number_format($item['Item']['value'],2),
105
'category' => $item['ItemCategory']['description'],
106
'type' => $item['ItemType']['description'],
107
'vendor' => $item['Vendor']['description'],
108
'event' => $item['Event']['title']
111
$bidInfo = $this->Item->Bid->findById($item['Bid'][0]['id']);
112
$formatted_items[$x]['Item'] += array(
113
'bidder_id' => $bidInfo['Bidder']['id'],
114
'bidder_first_name' => $bidInfo['Bidder']['first_name'],
115
'bidder_last_name' => $bidInfo['Bidder']['last_name'],
116
'bidder_business_name' => $bidInfo['Bidder']['business_name'],
117
'bidder_phone' => $bidInfo['Bidder']['phone'],
118
'bidder_email' => $bidInfo['Bidder']['email'],
119
'bid_amount' => $bidInfo['Bid']['bid_amount'],
120
'paid' => $bidInfo['Bid']['paid']
125
$fieldNames = array_keys($formatted_items[0]['Item']);
126
$csv_data = $this->DataHandler->createCSV($formatted_items,$fieldNames);
127
$this->ForceDownload->forceDownloadStream($csv_data,'csv','item_list.csv');
b'\\ No newline at end of file'