forked from CakePHP-Copula/Copula
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathHttpSourceModel.php
More file actions
149 lines (134 loc) · 4.53 KB
/
Copy pathHttpSourceModel.php
File metadata and controls
149 lines (134 loc) · 4.53 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
/**
* Author: imsamurai <im.samuray@gmail.com>
* Date: 04.12.2012
* Time: 17:08:18
* Format: http://book.cakephp.org/2.0/en/models.html
*/
App::uses('AppModel', 'Model');
App::uses('HttpSourceUtility', 'HttpSource.Utility');
App::uses('HttpSource', 'HttpSource.Model/Datasource');
/**
* Model with patched methods to wirk with save()
*
* @package HttpSource
* @subpackage Model
*/
class HttpSourceModel extends AppModel {
/**
* Model name
*
* @var string
*/
public $name = 'HttpSource';
/**
* Sets credentials data
*
* @param array $credentials
*/
public function setCredentials(array $credentials = array()) {
$this->getDataSource()->setCredentials($credentials);
}
/**
* Returns true if the supplied field exists in the model's database table.
*
* @param string|array $name Name of field to look for, or an array of names
* @param boolean $checkVirtual checks if the field is declared as virtual
* @return mixed If $name is a string, returns a boolean indicating whether the field exists.
* If $name is an array of field names, returns the first field that exists,
* or false if none exist.
*/
public function hasField($name, $checkVirtual = false) {
return true;
}
/**
* Returns true if a record with particular ID exists.
*
* If $id is not passed it calls Model::getID() to obtain the current record ID,
* and then performs a Model::find('count') on the currently configured datasource
* to ascertain the existence of the record in persistent storage.
*
* @param integer|string $id ID of record to check for existence
* @param array $conditions Addiditional conditions
* @param bool $force If true will call exists method if datasource, return true otherwise
* @return boolean True if such a record exists
*/
public function exists($id = null, array $conditions = array(), $force = false) {
if ($id === null) {
$id = $this->getID();
}
if ($id === false) {
return false;
}
return $force ? $this->getDataSource()->exists($this, array($this->primaryKey => $id) + $conditions) : true;
}
/**
* Wrapper for save() to use update method datasource
*
* @param array $data Data to save.
* @param boolean|array $validate Either a boolean, or an array.
* If a boolean, indicates whether or not to validate before saving.
* If an array, allows control of validate, callbacks, and fieldList
* @param array $fieldList List of fields to allow to be written
* @return mixed On success Model::$data if its not empty or true, false on failure
* @link http://book.cakephp.org/2.0/en/models/saving-your-data.html
*/
public function update($data = null, $validate = true, $fieldList = array()) {
$this->id = true;
return $this->save($data, $validate, $fieldList);
}
/**
* Removes record for given ID. If no ID is given, the current ID is used. Returns true on success.
*
* @param integer|string $id ID of record to delete
* @param boolean $cascade Set to true to delete records that depend on this record (NOT USED)
* @return boolean True on success
* @link http://book.cakephp.org/2.0/en/models/deleting-data.html
*/
public function delete($id = null, $cascade = true) {
return parent::delete($id, false);
}
/**
* Deletes multiple model records based on a set of conditions.
*
* @param mixed $conditions Conditions to match
* @param boolean $cascade Set to true to delete records that depend on this record (NOT USED)
* @param boolean $callbacks Run callbacks (NOT USED)
* @return boolean True on success, false on failure
* @link http://book.cakephp.org/2.0/en/models/deleting-data.html#deleteall
*/
public function deleteAll($conditions, $cascade = true, $callbacks = false) {
return parent::deleteAll($conditions, false, false);
}
/**
* Explain query
*
* @param string $ds
* @param string $query
* @return string
*/
public function explain($ds, $query) {
return HttpSourceUtility::explainQuery($query);
}
/**
* Set parameters for endpoint wich handle transactions
*
*
* @param string $table
* @param array $params
* @param string $transactionsField
* @param string $method
*
*/
public function setTransactionParams($table, array $params = array(), $transactionsField = 'transactions', $method = HttpSource::METHOD_CREATE) {
$this->getDataSource()->setTransactionParams($table, $params, $transactionsField, $method);
}
/**
* Return transaction params
*
* @return array
*/
public function getTransactionParams() {
return $this->getDataSource()->getTransactionParams();
}
}