~mparic/+junk/openauctionlive

« back to all changes in this revision

Viewing changes to app/models/bid.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:
28
28
    var $order = array('bid_amount DESC');
29
29
    
30
30
    var $validate = array(
31
 
        'bidder_id' => array('rule' => array('numeric')),
32
 
        'item_id' => array('rule' => array('numeric')),
33
 
        'amount' => array('rule' => array('money'))
 
31
        'bid_amount' => array(
 
32
                        'money' => array(
 
33
                                'rule' => array('money'),
 
34
                                'message' => 'Not a valid monetary amount'
 
35
                        ),
 
36
                        'numeric' => array(
 
37
                                'rule' => array('numeric'),
 
38
                                'message' => 'Must be in XX or XX.XX format; no $ or letters'
 
39
                        ),
 
40
                        'notEmpty' => array(
 
41
                                'rule' => array('notempty'),
 
42
                                'message' => 'Amount Required',
 
43
                                'required' => true
 
44
                        )
 
45
                ),
 
46
        'bidder_id' => array(
 
47
                        'numeric' => array(
 
48
                                'rule' => array('numeric'),
 
49
                                'message' => 'Bidder ID must be a number'
 
50
                        ),
 
51
                        'validBidder' => array(
 
52
                                'rule' => array('validBidder'),
 
53
                                'message' => 'Not a Valid Bidder ID',
 
54
                                'last' => true,
 
55
                        )
 
56
                ),
 
57
                'item_id' => array(
 
58
                        'numeric' => array(
 
59
                                'rule' => array('numeric'),
 
60
                                'message' => 'Item ID must be a number'
 
61
                        ),
 
62
                        'validItem' => array(
 
63
                                'rule' => array('validItem'),
 
64
                                'message' => 'Not a Valid Item ID',
 
65
                                'last' => true
 
66
                        ),
 
67
                        'isDuplicateEntry' => array(
 
68
                                'rule' => array('isDuplicateEntry'),
 
69
                                'message' => 'Duplicate Bid Entry'
 
70
                        )
 
71
                )  
34
72
      );
 
73
          
 
74
        function isDuplicateEntry() {
 
75
                $params = array('conditions'=>array('Bid.bidder_id'=>$this->data['Bid']['bidder_id'],'Bid.item_id'=>$this->data['Bid']['item_id']),'recursive'=>-1);
 
76
                $results = $this->find('first',$params);
 
77
                return (($results) ? false : true);
 
78
        }
 
79
        
 
80
        function validBidder() {
 
81
                $results = $this->Bidder->find('first',array('conditions' => array('Bidder.id' => $this->data['Bid']['bidder_id'])));
 
82
                return $results;
 
83
        }
 
84
        
 
85
        function validItem() {
 
86
                $results = $this->Item->find('first',array('conditions' => array('Item.id' => $this->data['Bid']['item_id'])));
 
87
                return $results;
 
88
        }
35
89
  
36
90
}