~mparic/+junk/openauctionlive

« back to all changes in this revision

Viewing changes to app/controllers/items_controller.php

  • Committer: Michael Paric
  • Date: 2012-01-07 20:21:14 UTC
  • Revision ID: mparic@compbizsolutions.com-20120107202114-6q89jiel6y3rbwgc
Updated validation rules to prevent duplicate Bid and Bidder entries; updated return message color for successful form entry to differentiate from error; added simlink in img/ for image to be used in reports - just change what auction_logo.jpg points to instead of changing View code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 
4
4
        var $name = 'Items';
5
5
  
6
 
  var $components = array('DataHandler','ForceDownload');
 
6
        var $components = array('DataHandler','ForceDownload');
7
7
  
8
 
  function beforeRender(){
9
 
    
10
 
    $this->set('navigation','main_nav_' . $this->Auth->user('role'));
11
 
    
12
 
    $this->set('subNavigation','items_' . $this->Auth->user('role'));
13
 
    
14
 
  }
 
8
        function beforeRender(){    
 
9
        $this->set('navigation','main_nav_' . $this->Auth->user('role'));    
 
10
        $this->set('subNavigation','items_' . $this->Auth->user('role'));    
 
11
        }
15
12
 
16
13
        function index() {
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'));
22
19
        }
23
20
 
24
21
        function view($id = null) {
26
23
                        $this->Session->setFlash(__('Invalid item', true));
27
24
                        $this->redirect(array('action' => 'index'));
28
25
                }
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'));
32
29
        }
33
30
 
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'));
42
39
                        } else {
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'));
52
49
        }
53
50
 
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'));
60
57
                }
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'));
65
62
                        } else {
66
63
                                $this->Session->setFlash(__('The item could not be saved. Please, try again.', true));
83
80
                        $this->redirect(array('action'=>'index'));
84
81
                }
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'));
88
85
                }
89
86
                $this->Session->setFlash(__('Item was not deleted', true));
90
87
                $this->redirect(array('action' => 'index'));
91
88
        }
92
89
  
93
 
  function export_csv() {
94
 
    $formatted_items = array();
95
 
    
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);
100
 
 
101
 
    $x=0;
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']
112
 
                          );
113
 
      if ($item['Bid']) {
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']
124
 
                                 );
125
 
      }
126
 
      $x++;
127
 
    }
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');
131
 
    exit();
132
 
  }
133
 
 
 
90
        function export_csv() {
 
91
            $formatted_items = array();
 
92
            
 
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);
 
97
        
 
98
            $x=0;
 
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']
 
109
                                  );
 
110
              if ($item['Bid']) {
 
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']
 
121
                                         );
 
122
              }
 
123
              $x++;
 
124
            }
 
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');
 
128
            exit();
 
129
        }
134
130
 
135
131
}
136
132
?>
 
 
b'\\ No newline at end of file'