-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbraintree_app_model.php
128 lines (102 loc) · 2.17 KB
/
braintree_app_model.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
/**
* Braintree App Model File
*
* Copyright (c) 2010 Anthony Putignano
*
* Distributed under the terms of the MIT License.
* Redistributions of files must retain the above copyright notice.
*
* PHP version 5.2
* CakePHP version 1.3
*
* @package braintree
* @subpackage braintree.models
* @copyright 2010 Anthony Putignano <[email protected]>
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
* @link http://github.com/anthonyp/braintree
*/
/**
* Braintree App Model Class
*
* @package braintree
* @subpackage braintree.models
*/
App::import('Vendor', 'Braintree.Braintree');
class BraintreeAppModel extends AppModel {
/**
* Adds the datasource to the connection manager if it's not already there,
* which it won't be if you've not added it to your app/config/database.php
* file.
*
* @param $id
* @param $table
* @param $ds
* @return void
*/
public function __construct ($id = false, $table = null, $ds = null) {
$sources = ConnectionManager::sourceList();
if (!in_array('braintree', $sources)) {
ConnectionManager::create('braintree', array('datasource' => 'Braintree.BraintreeSource'));
}
parent::__construct($id, $table, $ds);
}
/**
* beforeSave
*
* @return bool
*/
public function beforeSave () {
if (!parent::beforeSave()) {
return false;
}
return true;
}
/**
* beforeDelete
*
* @param bool $cascade
* @return bool
*/
public function beforeDelete ($cascade = true) {
if (!parent::beforeDelete($cascade)) {
return false;
}
return true;
}
/**
* afterDelete
*
* @return bool
*/
public function afterDelete () {
if (!parent::afterDelete()) {
return false;
}
return true;
}
/**
* Trims and uppercases a string
*
* @param string $string
* @return string
*/
public function standardizeString ($string) {
return strtoupper(trim($string));
}
/**
* Get options array for a field
*
* @param string $string
* @return array
*/
public function getOptions ($field) {
$name = '_' . $field . '_options';
if (isset($this->{$name})) {
return $this->{$name};
} else {
return array();
}
}
}
?>