@@ -34,8 +34,8 @@ discard block |
||
34 | 34 | } |
35 | 35 | |
36 | 36 | return $this->filter( |
37 | - "INSERT INTO " . $table . |
|
38 | - " (" . implode(", ", $quotedFields) . ") VALUES (" . implode(', ', $valueFields) . ")" |
|
37 | + "INSERT INTO ".$table. |
|
38 | + " (".implode(", ", $quotedFields).") VALUES (".implode(', ', $valueFields).")" |
|
39 | 39 | ); |
40 | 40 | } |
41 | 41 | |
@@ -77,10 +77,10 @@ discard block |
||
77 | 77 | } |
78 | 78 | } |
79 | 79 | |
80 | - return $this->filter("UPDATE " . |
|
81 | - $model->getDBStoreInformation()['quoted_table'] . |
|
82 | - " SET " . implode(', ', $valueFields) . |
|
83 | - " WHERE " . implode(' AND ', $conditions) |
|
80 | + return $this->filter("UPDATE ". |
|
81 | + $model->getDBStoreInformation()['quoted_table']. |
|
82 | + " SET ".implode(', ', $valueFields). |
|
83 | + " WHERE ".implode(' AND ', $conditions) |
|
84 | 84 | ); |
85 | 85 | } |
86 | 86 |
@@ -6,10 +6,16 @@ discard block |
||
6 | 6 | |
7 | 7 | private $db; |
8 | 8 | |
9 | + /** |
|
10 | + * @param \ntentan\atiaa\Driver $driver |
|
11 | + */ |
|
9 | 12 | public function setDriver($driver) { |
10 | 13 | $this->db = $driver; |
11 | 14 | } |
12 | 15 | |
16 | + /** |
|
17 | + * @param string $query |
|
18 | + */ |
|
13 | 19 | private function filter($query) { |
14 | 20 | return $query; |
15 | 21 | } |
@@ -39,6 +45,11 @@ discard block |
||
39 | 45 | ); |
40 | 46 | } |
41 | 47 | |
48 | + /** |
|
49 | + * @param QueryParameters $parameters |
|
50 | + * |
|
51 | + * @return string |
|
52 | + */ |
|
42 | 53 | public function getBulkUpdateQuery($data, $parameters) { |
43 | 54 | $updateData = []; |
44 | 55 | foreach ($data as $field => $value) { |
@@ -84,6 +95,11 @@ discard block |
||
84 | 95 | ); |
85 | 96 | } |
86 | 97 | |
98 | + /** |
|
99 | + * @param QueryParameters $parameters |
|
100 | + * |
|
101 | + * @return string |
|
102 | + */ |
|
87 | 103 | public function getSelectQuery($parameters) { |
88 | 104 | return $this->filter(sprintf( |
89 | 105 | "SELECT %s FROM %s%s%s%s%s", |
@@ -97,6 +113,11 @@ discard block |
||
97 | 113 | ); |
98 | 114 | } |
99 | 115 | |
116 | + /** |
|
117 | + * @param QueryParameters $parameters |
|
118 | + * |
|
119 | + * @return string |
|
120 | + */ |
|
100 | 121 | public function getCountQuery($parameters) { |
101 | 122 | return $this->filter(sprintf( |
102 | 123 | "SELECT count(*) as count FROM %s%s", |
@@ -106,6 +127,11 @@ discard block |
||
106 | 127 | ); |
107 | 128 | } |
108 | 129 | |
130 | + /** |
|
131 | + * @param QueryParameters $parameters |
|
132 | + * |
|
133 | + * @return string |
|
134 | + */ |
|
109 | 135 | public function getDeleteQuery($parameters) { |
110 | 136 | return $this->filter(sprintf( |
111 | 137 | "DELETE FROM %s%s", |
@@ -67,7 +67,7 @@ |
||
67 | 67 | } |
68 | 68 | |
69 | 69 | public static function getInstance() { |
70 | - if(self::$instance === null) throw new NibiiException("A context has not yet been initialized"); |
|
70 | + if (self::$instance === null) throw new NibiiException("A context has not yet been initialized"); |
|
71 | 71 | return self::$instance; |
72 | 72 | } |
73 | 73 |
@@ -67,7 +67,9 @@ |
||
67 | 67 | } |
68 | 68 | |
69 | 69 | public static function getInstance() { |
70 | - if(self::$instance === null) throw new NibiiException("A context has not yet been initialized"); |
|
70 | + if(self::$instance === null) { |
|
71 | + throw new NibiiException("A context has not yet been initialized"); |
|
72 | + } |
|
71 | 73 | return self::$instance; |
72 | 74 | } |
73 | 75 |
@@ -68,7 +68,7 @@ |
||
68 | 68 | } |
69 | 69 | |
70 | 70 | return $this->evaluateResult( |
71 | - $field, $testItem->count() === 0, "The value of " . implode(', ', $field['name']) . " must be unique" |
|
71 | + $field, $testItem->count() === 0, "The value of ".implode(', ', $field['name'])." must be unique" |
|
72 | 72 | ); |
73 | 73 | } |
74 | 74 |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | |
132 | 132 | /** |
133 | 133 | * @method |
134 | - * @param type $name |
|
134 | + * @param string $name |
|
135 | 135 | * @param type $arguments |
136 | 136 | * @return type |
137 | 137 | */ |
@@ -160,6 +160,10 @@ discard block |
||
160 | 160 | return $this->retrieveItem($name); |
161 | 161 | } |
162 | 162 | |
163 | + /** |
|
164 | + * @param Relationship[] $relationships |
|
165 | + * @param integer $depth |
|
166 | + */ |
|
163 | 167 | private function expandArrayValue($array, $relationships, $depth, $index = null) { |
164 | 168 | foreach ($relationships as $name => $relationship) { |
165 | 169 | $array[$name] = $this->fetchRelatedFields($relationship, $index)->toArray($depth); |
@@ -319,6 +323,9 @@ discard block |
||
319 | 323 | |
320 | 324 | } |
321 | 325 | |
326 | + /** |
|
327 | + * @param string $id |
|
328 | + */ |
|
322 | 329 | public function postSaveCallback($id) { |
323 | 330 | |
324 | 331 | } |
@@ -26,8 +26,8 @@ |
||
26 | 26 | |
27 | 27 | namespace ntentan\nibii\relationships; |
28 | 28 | |
29 | -use ntentan\utils\Text; |
|
30 | 29 | use ntentan\nibii\ORMContext; |
30 | +use ntentan\utils\Text; |
|
31 | 31 | |
32 | 32 | class BelongsToRelationship extends \ntentan\nibii\Relationship { |
33 | 33 |
@@ -41,7 +41,7 @@ |
||
41 | 41 | public function prepareQuery($data) { |
42 | 42 | // @todo throw an exception when the data doesn't have the local key |
43 | 43 | $query = $this->getQuery(); |
44 | - if($this->queryPrepared){ |
|
44 | + if ($this->queryPrepared) { |
|
45 | 45 | $query->setBoundData($this->options['foreign_key'], $data[$this->options['local_key']]); |
46 | 46 | } else { |
47 | 47 | $query->setTable($this->getModelInstance()->getDBStoreInformation()['quoted_table']) |
@@ -26,9 +26,8 @@ |
||
26 | 26 | |
27 | 27 | namespace ntentan\nibii\relationships; |
28 | 28 | |
29 | -use ntentan\nibii\QueryParameters; |
|
30 | -use ntentan\utils\Text; |
|
31 | 29 | use ntentan\nibii\ORMContext; |
30 | +use ntentan\utils\Text; |
|
32 | 31 | |
33 | 32 | class HasManyRelationship extends \ntentan\nibii\Relationship |
34 | 33 | { |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | { |
44 | 44 | // @todo throw an exception when the data doesn't have the local key |
45 | 45 | $query = $this->getQuery(); |
46 | - if($this->queryPrepared) { |
|
46 | + if ($this->queryPrepared) { |
|
47 | 47 | $query->setBoundData($this->options['foreign_key'], $data[$this->options['local_key']]); |
48 | 48 | } else { |
49 | 49 | $query->setTable($this->getModelInstance()->getDBStoreInformation()['quoted_table']) |
@@ -55,10 +55,10 @@ discard block |
||
55 | 55 | |
56 | 56 | public function runSetup() |
57 | 57 | { |
58 | - if($this->options['foreign_key'] == null) { |
|
59 | - $this->options['foreign_key'] = Text::singularize($this->setupTable) . '_id'; |
|
58 | + if ($this->options['foreign_key'] == null) { |
|
59 | + $this->options['foreign_key'] = Text::singularize($this->setupTable).'_id'; |
|
60 | 60 | } |
61 | - if($this->options['local_key'] == null) { |
|
61 | + if ($this->options['local_key'] == null) { |
|
62 | 62 | $this->options['local_key'] = $this->setupPrimaryKey[0]; |
63 | 63 | } |
64 | 64 | } |
@@ -26,9 +26,8 @@ |
||
26 | 26 | |
27 | 27 | namespace ntentan\nibii\relationships; |
28 | 28 | |
29 | -use ntentan\utils\Text; |
|
30 | 29 | use ntentan\nibii\ORMContext; |
31 | -use ntentan\nibii\QueryParameters; |
|
30 | +use ntentan\utils\Text; |
|
32 | 31 | |
33 | 32 | class ManyHaveManyRelationship extends \ntentan\nibii\Relationship { |
34 | 33 |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | $filter = $junctionModel->fields($this->options['junction_foreign_key']) |
45 | 45 | ->filterBy($this->options['junction_local_key'], $data[$this->options['local_key']]) |
46 | 46 | ->fetch(); |
47 | - if($filter->count() == 0) { |
|
47 | + if ($filter->count() == 0) { |
|
48 | 48 | return null; |
49 | 49 | } |
50 | 50 | $foreignKeys = []; |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | |
55 | 55 | // @todo throw an exception when the data doesn't have the local key |
56 | 56 | $query = $this->getQuery(); |
57 | - if($this->queryPrepared){ |
|
57 | + if ($this->queryPrepared) { |
|
58 | 58 | $query->setBoundData($this->options['foreign_key'], $foreignKeys); |
59 | 59 | } else { |
60 | 60 | $query = $this->getQuery() |
@@ -88,12 +88,12 @@ discard block |
||
88 | 88 | |
89 | 89 | if (!isset($this->options['junction_local_key'])) { |
90 | 90 | $this->options['junction_local_key'] = |
91 | - Text::singularize($this->setupTable) . '_id'; |
|
91 | + Text::singularize($this->setupTable).'_id'; |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | if (!isset($this->options['junction_foreign_key'])) { |
95 | 95 | $this->options['junction_foreign_key'] = |
96 | - Text::singularize($foreignModel->getDBStoreInformation()['table']) . '_id'; |
|
96 | + Text::singularize($foreignModel->getDBStoreInformation()['table']).'_id'; |
|
97 | 97 | } |
98 | 98 | } |
99 | 99 |
@@ -60,7 +60,7 @@ |
||
60 | 60 | } |
61 | 61 | |
62 | 62 | public function getQuery() { |
63 | - if(!$this->query) { |
|
63 | + if (!$this->query) { |
|
64 | 64 | $this->query = new QueryParameters(); |
65 | 65 | } |
66 | 66 | return $this->query; |
@@ -67,11 +67,11 @@ discard block |
||
67 | 67 | } |
68 | 68 | |
69 | 69 | public function getWhereClause() { |
70 | - if($this->whereClause) { |
|
71 | - foreach($this->boundArrays as $boundArray) { |
|
70 | + if ($this->whereClause) { |
|
71 | + foreach ($this->boundArrays as $boundArray) { |
|
72 | 72 | $where = ""; |
73 | 73 | $comma = ""; |
74 | - for($i = 0; $i < count($this->boundData[$boundArray]); $i++) { |
|
74 | + for ($i = 0; $i < count($this->boundData[$boundArray]); $i++) { |
|
75 | 75 | $where .= "{$comma}:{$boundArray}_{$i}"; |
76 | 76 | $comma = ', '; |
77 | 77 | } |
@@ -82,11 +82,11 @@ discard block |
||
82 | 82 | } |
83 | 83 | |
84 | 84 | public function getBoundData() { |
85 | - if($this->preparedBoundData === false) { |
|
85 | + if ($this->preparedBoundData === false) { |
|
86 | 86 | $this->preparedBoundData = []; |
87 | - foreach($this->boundData as $key => $value) { |
|
88 | - if(in_array($key, $this->boundArrays)) { |
|
89 | - foreach($value as $i => $v) { |
|
87 | + foreach ($this->boundData as $key => $value) { |
|
88 | + if (in_array($key, $this->boundArrays)) { |
|
89 | + foreach ($value as $i => $v) { |
|
90 | 90 | $this->preparedBoundData["{$key}_{$i}"] = $v; |
91 | 91 | } |
92 | 92 | } else { |
@@ -98,10 +98,10 @@ discard block |
||
98 | 98 | } |
99 | 99 | |
100 | 100 | public function setBoundData($key, $value) { |
101 | - if(isset($this->boundData[$key])){ |
|
101 | + if (isset($this->boundData[$key])) { |
|
102 | 102 | $isArray = is_array($value); |
103 | 103 | $boundArray = in_array($key, $this->boundArrays); |
104 | - if($isArray && !$boundArray) { |
|
104 | + if ($isArray && !$boundArray) { |
|
105 | 105 | throw new NibiiException("{$key} cannot be bound to an array"); |
106 | 106 | } else if (!$isArray && $boundArray) { |
107 | 107 | throw new NibiiException("{$key} must be bound to an array"); |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | } |
115 | 115 | |
116 | 116 | public function getSorts() { |
117 | - return count($this->sorts) ? " ORDER BY " . implode(", ", $this->sorts) : null; |
|
117 | + return count($this->sorts) ? " ORDER BY ".implode(", ", $this->sorts) : null; |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | public function addFilter($field, $values = null) { |