@@ -26,18 +26,24 @@ discard block |
||
26 | 26 | return $this->parseString($this->_string, $this->_values); |
27 | 27 | } |
28 | 28 | |
29 | + /** |
|
30 | + * @param Nip_DB_Query_Condition $condition |
|
31 | + */ |
|
29 | 32 | public function and_($condition) |
30 | 33 | { |
31 | 34 | return new Nip_DB_Query_AndCondition($this, $condition); |
32 | 35 | } |
33 | 36 | |
37 | + /** |
|
38 | + * @param Nip_DB_Query_Condition $condition |
|
39 | + */ |
|
34 | 40 | public function or_($condition) |
35 | 41 | { |
36 | 42 | return new Nip_DB_Query_OrCondition($this, $condition); |
37 | 43 | } |
38 | 44 | |
39 | 45 | /** |
40 | - * @return DB_Query |
|
46 | + * @return Wrapper |
|
41 | 47 | */ |
42 | 48 | public function getQuery() |
43 | 49 | { |
@@ -46,7 +52,7 @@ discard block |
||
46 | 52 | |
47 | 53 | /** |
48 | 54 | * @param Wrapper $query |
49 | - * @return DB_Query_Condition |
|
55 | + * @return Nip_DB_Query_Condition |
|
50 | 56 | */ |
51 | 57 | public function setQuery($query) |
52 | 58 | { |
@@ -106,6 +112,9 @@ discard block |
||
106 | 112 | return strpos($condition, ' AND ') || strpos($condition, ' OR ') ? '(' . $condition . ')' : $condition; |
107 | 113 | } |
108 | 114 | |
115 | + /** |
|
116 | + * @param Query $value |
|
117 | + */ |
|
109 | 118 | protected function parseValueQuery($value) |
110 | 119 | { |
111 | 120 | return "(" . $value->assemble() . ")"; |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * @param string $against |
31 | 31 | * @param string $alias |
32 | 32 | * @param boolean $boolean_mode |
33 | - * @return Nip_DB_Wrapper |
|
33 | + * @return Query |
|
34 | 34 | */ |
35 | 35 | public function match($fields, $against, $alias, $boolean_mode = true) |
36 | 36 | { |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | * @param mixed $table the table to be joined, given as simple string or name - alias pair |
61 | 61 | * @param string $on |
62 | 62 | * @param string $type SQL join type (INNER, OUTER, LEFT INNER, etc.) |
63 | - * @return Nip_DB_Wrapper |
|
63 | + * @return Nip_DB_Query_Select |
|
64 | 64 | */ |
65 | 65 | public function join($table, $on = false, $type = '') |
66 | 66 | { |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | * |
85 | 85 | * @param array $fields |
86 | 86 | * @param boolean $rollup suport for modifier WITH ROLLUP |
87 | - * @return Nip_DB_Wrapper |
|
87 | + * @return Nip_DB_Query_Select |
|
88 | 88 | */ |
89 | 89 | public function group($fields, $rollup = false) |
90 | 90 | { |
@@ -5,236 +5,236 @@ discard block |
||
5 | 5 | class Nip_DB_Query_Select extends _Abstract |
6 | 6 | { |
7 | 7 | |
8 | - public function __call($name, $arguments) |
|
9 | - { |
|
10 | - if (in_array($name, array('min', 'max', 'count', 'avg', 'sum'))) { |
|
11 | - $input = reset($arguments); |
|
12 | - |
|
13 | - if (is_array($input)) { |
|
14 | - $input[] = false; |
|
15 | - } else { |
|
16 | - $input = array($input, $arguments[1], $arguments[2]); |
|
17 | - } |
|
18 | - |
|
19 | - $input[0] = strtoupper($name) . '(' . $this->protect($input[0]) . ')'; |
|
20 | - |
|
21 | - return $this->cols($input); |
|
22 | - } |
|
23 | - return parent::__call($name, $arguments); |
|
24 | - } |
|
25 | - |
|
26 | - /** |
|
27 | - * Inserts FULLTEXT statement into $this->select and $this->where |
|
28 | - * |
|
29 | - * @param mixed $fields |
|
30 | - * @param string $against |
|
31 | - * @param string $alias |
|
32 | - * @param boolean $boolean_mode |
|
33 | - * @return Nip_DB_Wrapper |
|
34 | - */ |
|
35 | - public function match($fields, $against, $alias, $boolean_mode = true) |
|
36 | - { |
|
37 | - if (!is_array($fields)) { |
|
38 | - $fields = array(); |
|
39 | - } |
|
40 | - |
|
41 | - $match = array(); |
|
42 | - foreach ($fields as $itemField) { |
|
43 | - if (!is_array($itemField)) { |
|
44 | - $itemField = array($itemField); |
|
45 | - |
|
46 | - $field = isset($itemField[0]) ? $itemField[0] : false; |
|
47 | - $protected = isset($itemField[1]) ? $itemField[1] : true; |
|
48 | - |
|
49 | - $match[] = $protected ? $this->protect($field) : $field; |
|
50 | - } |
|
51 | - } |
|
52 | - $match = "MATCH(" . implode(",", $match) . ") AGAINST ('" . $against . "'" . ($boolean_mode ? " IN BOOLEAN MODE" : "") . ")"; |
|
53 | - |
|
54 | - return $this->cols(array($match, $alias, false))->where(array($match)); |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * Inserts JOIN entry for the last table inserted by $this->from() |
|
59 | - * |
|
60 | - * @param mixed $table the table to be joined, given as simple string or name - alias pair |
|
61 | - * @param string $on |
|
62 | - * @param string $type SQL join type (INNER, OUTER, LEFT INNER, etc.) |
|
63 | - * @return Nip_DB_Wrapper |
|
64 | - */ |
|
65 | - public function join($table, $on = false, $type = '') |
|
66 | - { |
|
67 | - $lastTable = end($this->_parts['from']); |
|
68 | - |
|
69 | - if (!$lastTable) { |
|
70 | - trigger_error('No previous table to JOIN', E_USER_ERROR); |
|
71 | - } |
|
72 | - |
|
73 | - if (is_array($lastTable)) { |
|
74 | - $lastTable = $lastTable[1]; |
|
75 | - } |
|
76 | - |
|
77 | - $this->_parts['join'][$lastTable][] = array($table, $on, $type); |
|
78 | - |
|
79 | - return $this; |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * Sets the group paramater for the query |
|
84 | - * |
|
85 | - * @param array $fields |
|
86 | - * @param boolean $rollup suport for modifier WITH ROLLUP |
|
87 | - * @return Nip_DB_Wrapper |
|
88 | - */ |
|
89 | - public function group($fields, $rollup = false) |
|
90 | - { |
|
91 | - $this->_parts['group']['fields'] = $fields; |
|
92 | - $this->_parts['group']['rollup'] = $rollup; |
|
93 | - return $this; |
|
94 | - } |
|
95 | - |
|
96 | - public function assemble() |
|
97 | - { |
|
98 | - $select = $this->parseCols(); |
|
99 | - $options = $this->parseOptions(); |
|
100 | - $from = $this->parseFrom(); |
|
101 | - |
|
102 | - $where = $this->parseWhere(); |
|
103 | - $group = $this->parseGroup(); |
|
104 | - $having = $this->parseHaving(); |
|
105 | - |
|
106 | - $order = $this->parseOrder(); |
|
107 | - |
|
108 | - $query = "SELECT"; |
|
109 | - |
|
110 | - if (!empty($options)) { |
|
111 | - $query .= " $options"; |
|
112 | - } |
|
113 | - |
|
114 | - if (!empty($select)) { |
|
115 | - $query .= " $select"; |
|
116 | - } |
|
117 | - |
|
118 | - if (!empty($from)) { |
|
119 | - $query .= " FROM $from"; |
|
120 | - } |
|
121 | - |
|
122 | - if (!empty($where)) { |
|
123 | - $query .= " WHERE $where"; |
|
124 | - } |
|
125 | - |
|
126 | - if (!empty($group)) { |
|
127 | - $query .= " GROUP BY $group"; |
|
128 | - } |
|
129 | - |
|
130 | - if (!empty($having)) { |
|
131 | - $query .= " HAVING $having"; |
|
132 | - } |
|
133 | - |
|
134 | - if (!empty($order)) { |
|
135 | - $query .= " ORDER BY $order"; |
|
136 | - } |
|
137 | - |
|
138 | - if (!empty($this->_parts['limit'])) { |
|
139 | - $query .= " LIMIT {$this->_parts['limit']}"; |
|
140 | - } |
|
141 | - |
|
142 | - return $query; |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * Parses SELECT entries |
|
147 | - * |
|
148 | - * @return string |
|
149 | - */ |
|
150 | - protected function parseCols() |
|
151 | - { |
|
152 | - if (!isset($this->_parts['cols']) OR !is_array($this->_parts['cols']) OR count($this->_parts['cols']) < 1) { |
|
153 | - return '*'; |
|
154 | - } else { |
|
155 | - $selectParts = array(); |
|
156 | - |
|
157 | - foreach ($this->_parts['cols'] as $itemSelect) { |
|
158 | - if (is_array($itemSelect)) { |
|
159 | - $field = isset($itemSelect[0]) ? $itemSelect[0] : false; |
|
160 | - $alias = isset($itemSelect[1]) ? $itemSelect[1] : false; |
|
161 | - $protected = isset($itemSelect[2]) ? $itemSelect[2] : true; |
|
162 | - |
|
163 | - $selectParts[] = ($protected ? $this->protect($field) : $field) . (!empty($alias) ? ' AS ' . $this->protect($alias) : ''); |
|
164 | - } else { |
|
165 | - $selectParts[] = $itemSelect; |
|
166 | - } |
|
167 | - } |
|
168 | - |
|
169 | - return implode(', ', $selectParts); |
|
170 | - } |
|
171 | - } |
|
172 | - |
|
173 | - public function parseOptions() |
|
174 | - { |
|
175 | - if (!empty($this->_parts['options'])) { |
|
176 | - return implode(" ", array_map("strtoupper", $this->_parts['options'])); |
|
177 | - } |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * Parses FROM entries |
|
182 | - * @return string |
|
183 | - */ |
|
184 | - private function parseFrom() |
|
185 | - { |
|
186 | - if (!empty($this->_parts['from'])) { |
|
187 | - $parts = array(); |
|
188 | - |
|
189 | - foreach ($this->_parts['from'] as $key => $item) { |
|
190 | - if (is_array($item)) { |
|
191 | - $table = isset($item[0]) ? $item[0] : false; |
|
192 | - $alias = isset($item[1]) ? $item[1] : false; |
|
193 | - |
|
194 | - if (is_object($table)) { |
|
195 | - if (!$alias) { |
|
196 | - trigger_error('Select statements in for need aliases defined', E_USER_ERROR); |
|
197 | - } |
|
198 | - $parts[$key] = '(' . $table . ') AS ' . $this->protect($alias) . $this->parseJoin($alias); |
|
199 | - } else { |
|
200 | - $parts[$key] = $this->protect($table) . ' AS ' . $this->protect((!empty($alias) ? $alias : $table)) . $this->parseJoin($alias); |
|
201 | - } |
|
202 | - } elseif (!strpos($item, ' ')) { |
|
203 | - $parts[] = $this->protect($item) . $this->parseJoin($item); |
|
204 | - } else { |
|
205 | - $parts[] = $item; |
|
206 | - } |
|
207 | - } |
|
208 | - |
|
209 | - return implode(", ", array_unique($parts)); |
|
210 | - } |
|
211 | - } |
|
212 | - |
|
213 | - /** |
|
214 | - * Parses JOIN entries for a given table |
|
215 | - * Concatenates $this->join entries for input table |
|
216 | - * |
|
217 | - * @param string $table table to build JOIN statement for |
|
218 | - * @return string |
|
219 | - */ |
|
220 | - private function parseJoin($table) |
|
221 | - { |
|
222 | - $result = ''; |
|
223 | - |
|
224 | - if (isset($this->_parts['join'][$table])) { |
|
225 | - foreach ($this->_parts['join'][$table] as $join) { |
|
226 | - if (!is_array($join[0])) { |
|
227 | - $join[0] = array($join[0]); |
|
228 | - } |
|
229 | - |
|
230 | - $joinTable = isset($join[0][0]) ? $join[0][0] : false; |
|
231 | - $joinAlias = isset($join[0][1]) ? $join[0][1] : false; |
|
232 | - $joinOn = isset($join[1]) ? $join[1] : false; |
|
233 | - |
|
234 | - |
|
235 | - $joinType = isset($join[2]) ? $join[2] : ''; |
|
236 | - |
|
237 | - $result .= ( $joinType ? ' ' . strtoupper($joinType) : '') . ' JOIN '; |
|
8 | + public function __call($name, $arguments) |
|
9 | + { |
|
10 | + if (in_array($name, array('min', 'max', 'count', 'avg', 'sum'))) { |
|
11 | + $input = reset($arguments); |
|
12 | + |
|
13 | + if (is_array($input)) { |
|
14 | + $input[] = false; |
|
15 | + } else { |
|
16 | + $input = array($input, $arguments[1], $arguments[2]); |
|
17 | + } |
|
18 | + |
|
19 | + $input[0] = strtoupper($name) . '(' . $this->protect($input[0]) . ')'; |
|
20 | + |
|
21 | + return $this->cols($input); |
|
22 | + } |
|
23 | + return parent::__call($name, $arguments); |
|
24 | + } |
|
25 | + |
|
26 | + /** |
|
27 | + * Inserts FULLTEXT statement into $this->select and $this->where |
|
28 | + * |
|
29 | + * @param mixed $fields |
|
30 | + * @param string $against |
|
31 | + * @param string $alias |
|
32 | + * @param boolean $boolean_mode |
|
33 | + * @return Nip_DB_Wrapper |
|
34 | + */ |
|
35 | + public function match($fields, $against, $alias, $boolean_mode = true) |
|
36 | + { |
|
37 | + if (!is_array($fields)) { |
|
38 | + $fields = array(); |
|
39 | + } |
|
40 | + |
|
41 | + $match = array(); |
|
42 | + foreach ($fields as $itemField) { |
|
43 | + if (!is_array($itemField)) { |
|
44 | + $itemField = array($itemField); |
|
45 | + |
|
46 | + $field = isset($itemField[0]) ? $itemField[0] : false; |
|
47 | + $protected = isset($itemField[1]) ? $itemField[1] : true; |
|
48 | + |
|
49 | + $match[] = $protected ? $this->protect($field) : $field; |
|
50 | + } |
|
51 | + } |
|
52 | + $match = "MATCH(" . implode(",", $match) . ") AGAINST ('" . $against . "'" . ($boolean_mode ? " IN BOOLEAN MODE" : "") . ")"; |
|
53 | + |
|
54 | + return $this->cols(array($match, $alias, false))->where(array($match)); |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * Inserts JOIN entry for the last table inserted by $this->from() |
|
59 | + * |
|
60 | + * @param mixed $table the table to be joined, given as simple string or name - alias pair |
|
61 | + * @param string $on |
|
62 | + * @param string $type SQL join type (INNER, OUTER, LEFT INNER, etc.) |
|
63 | + * @return Nip_DB_Wrapper |
|
64 | + */ |
|
65 | + public function join($table, $on = false, $type = '') |
|
66 | + { |
|
67 | + $lastTable = end($this->_parts['from']); |
|
68 | + |
|
69 | + if (!$lastTable) { |
|
70 | + trigger_error('No previous table to JOIN', E_USER_ERROR); |
|
71 | + } |
|
72 | + |
|
73 | + if (is_array($lastTable)) { |
|
74 | + $lastTable = $lastTable[1]; |
|
75 | + } |
|
76 | + |
|
77 | + $this->_parts['join'][$lastTable][] = array($table, $on, $type); |
|
78 | + |
|
79 | + return $this; |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * Sets the group paramater for the query |
|
84 | + * |
|
85 | + * @param array $fields |
|
86 | + * @param boolean $rollup suport for modifier WITH ROLLUP |
|
87 | + * @return Nip_DB_Wrapper |
|
88 | + */ |
|
89 | + public function group($fields, $rollup = false) |
|
90 | + { |
|
91 | + $this->_parts['group']['fields'] = $fields; |
|
92 | + $this->_parts['group']['rollup'] = $rollup; |
|
93 | + return $this; |
|
94 | + } |
|
95 | + |
|
96 | + public function assemble() |
|
97 | + { |
|
98 | + $select = $this->parseCols(); |
|
99 | + $options = $this->parseOptions(); |
|
100 | + $from = $this->parseFrom(); |
|
101 | + |
|
102 | + $where = $this->parseWhere(); |
|
103 | + $group = $this->parseGroup(); |
|
104 | + $having = $this->parseHaving(); |
|
105 | + |
|
106 | + $order = $this->parseOrder(); |
|
107 | + |
|
108 | + $query = "SELECT"; |
|
109 | + |
|
110 | + if (!empty($options)) { |
|
111 | + $query .= " $options"; |
|
112 | + } |
|
113 | + |
|
114 | + if (!empty($select)) { |
|
115 | + $query .= " $select"; |
|
116 | + } |
|
117 | + |
|
118 | + if (!empty($from)) { |
|
119 | + $query .= " FROM $from"; |
|
120 | + } |
|
121 | + |
|
122 | + if (!empty($where)) { |
|
123 | + $query .= " WHERE $where"; |
|
124 | + } |
|
125 | + |
|
126 | + if (!empty($group)) { |
|
127 | + $query .= " GROUP BY $group"; |
|
128 | + } |
|
129 | + |
|
130 | + if (!empty($having)) { |
|
131 | + $query .= " HAVING $having"; |
|
132 | + } |
|
133 | + |
|
134 | + if (!empty($order)) { |
|
135 | + $query .= " ORDER BY $order"; |
|
136 | + } |
|
137 | + |
|
138 | + if (!empty($this->_parts['limit'])) { |
|
139 | + $query .= " LIMIT {$this->_parts['limit']}"; |
|
140 | + } |
|
141 | + |
|
142 | + return $query; |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * Parses SELECT entries |
|
147 | + * |
|
148 | + * @return string |
|
149 | + */ |
|
150 | + protected function parseCols() |
|
151 | + { |
|
152 | + if (!isset($this->_parts['cols']) OR !is_array($this->_parts['cols']) OR count($this->_parts['cols']) < 1) { |
|
153 | + return '*'; |
|
154 | + } else { |
|
155 | + $selectParts = array(); |
|
156 | + |
|
157 | + foreach ($this->_parts['cols'] as $itemSelect) { |
|
158 | + if (is_array($itemSelect)) { |
|
159 | + $field = isset($itemSelect[0]) ? $itemSelect[0] : false; |
|
160 | + $alias = isset($itemSelect[1]) ? $itemSelect[1] : false; |
|
161 | + $protected = isset($itemSelect[2]) ? $itemSelect[2] : true; |
|
162 | + |
|
163 | + $selectParts[] = ($protected ? $this->protect($field) : $field) . (!empty($alias) ? ' AS ' . $this->protect($alias) : ''); |
|
164 | + } else { |
|
165 | + $selectParts[] = $itemSelect; |
|
166 | + } |
|
167 | + } |
|
168 | + |
|
169 | + return implode(', ', $selectParts); |
|
170 | + } |
|
171 | + } |
|
172 | + |
|
173 | + public function parseOptions() |
|
174 | + { |
|
175 | + if (!empty($this->_parts['options'])) { |
|
176 | + return implode(" ", array_map("strtoupper", $this->_parts['options'])); |
|
177 | + } |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + * Parses FROM entries |
|
182 | + * @return string |
|
183 | + */ |
|
184 | + private function parseFrom() |
|
185 | + { |
|
186 | + if (!empty($this->_parts['from'])) { |
|
187 | + $parts = array(); |
|
188 | + |
|
189 | + foreach ($this->_parts['from'] as $key => $item) { |
|
190 | + if (is_array($item)) { |
|
191 | + $table = isset($item[0]) ? $item[0] : false; |
|
192 | + $alias = isset($item[1]) ? $item[1] : false; |
|
193 | + |
|
194 | + if (is_object($table)) { |
|
195 | + if (!$alias) { |
|
196 | + trigger_error('Select statements in for need aliases defined', E_USER_ERROR); |
|
197 | + } |
|
198 | + $parts[$key] = '(' . $table . ') AS ' . $this->protect($alias) . $this->parseJoin($alias); |
|
199 | + } else { |
|
200 | + $parts[$key] = $this->protect($table) . ' AS ' . $this->protect((!empty($alias) ? $alias : $table)) . $this->parseJoin($alias); |
|
201 | + } |
|
202 | + } elseif (!strpos($item, ' ')) { |
|
203 | + $parts[] = $this->protect($item) . $this->parseJoin($item); |
|
204 | + } else { |
|
205 | + $parts[] = $item; |
|
206 | + } |
|
207 | + } |
|
208 | + |
|
209 | + return implode(", ", array_unique($parts)); |
|
210 | + } |
|
211 | + } |
|
212 | + |
|
213 | + /** |
|
214 | + * Parses JOIN entries for a given table |
|
215 | + * Concatenates $this->join entries for input table |
|
216 | + * |
|
217 | + * @param string $table table to build JOIN statement for |
|
218 | + * @return string |
|
219 | + */ |
|
220 | + private function parseJoin($table) |
|
221 | + { |
|
222 | + $result = ''; |
|
223 | + |
|
224 | + if (isset($this->_parts['join'][$table])) { |
|
225 | + foreach ($this->_parts['join'][$table] as $join) { |
|
226 | + if (!is_array($join[0])) { |
|
227 | + $join[0] = array($join[0]); |
|
228 | + } |
|
229 | + |
|
230 | + $joinTable = isset($join[0][0]) ? $join[0][0] : false; |
|
231 | + $joinAlias = isset($join[0][1]) ? $join[0][1] : false; |
|
232 | + $joinOn = isset($join[1]) ? $join[1] : false; |
|
233 | + |
|
234 | + |
|
235 | + $joinType = isset($join[2]) ? $join[2] : ''; |
|
236 | + |
|
237 | + $result .= ( $joinType ? ' ' . strtoupper($joinType) : '') . ' JOIN '; |
|
238 | 238 | if (strpos($joinTable, '(') !== false) { |
239 | 239 | $result .= $joinTable; |
240 | 240 | } else { |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | } |
243 | 243 | $result .= (!empty($joinAlias) ? ' AS ' . $this->protect($joinAlias) : ''); |
244 | 244 | |
245 | - if ($joinOn) { |
|
245 | + if ($joinOn) { |
|
246 | 246 | $result .= ' ON '; |
247 | 247 | if (is_array($joinOn)) { |
248 | 248 | $result .= $this->protect($table . '.' . $joinOn[0]) . ' = ' . $this->protect($joinTable . '.' . $joinOn[1]); |
@@ -251,48 +251,48 @@ discard block |
||
251 | 251 | } |
252 | 252 | } |
253 | 253 | |
254 | - } |
|
255 | - } |
|
256 | - |
|
257 | - return $result; |
|
258 | - } |
|
254 | + } |
|
255 | + } |
|
259 | 256 | |
260 | - /** |
|
261 | - * Parses GROUP entries |
|
262 | - * |
|
263 | - * @uses $this->group['fields'] array with elements to group by |
|
264 | - * @return string |
|
265 | - */ |
|
266 | - private function parseGroup() |
|
267 | - { |
|
257 | + return $result; |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * Parses GROUP entries |
|
262 | + * |
|
263 | + * @uses $this->group['fields'] array with elements to group by |
|
264 | + * @return string |
|
265 | + */ |
|
266 | + private function parseGroup() |
|
267 | + { |
|
268 | 268 | $group = ''; |
269 | - if (isset ($this->_parts['group']['fields'])) { |
|
269 | + if (isset ($this->_parts['group']['fields'])) { |
|
270 | 270 | if (is_array($this->_parts['group']['fields'])) { |
271 | - $groupFields = array(); |
|
272 | - foreach ($this->_parts['group']['fields'] as $field) { |
|
273 | - $field = is_array($field) ? $field : array($field); |
|
274 | - $column = isset($field[0]) ? $field[0] : false; |
|
275 | - $type = isset($field[1]) ? $field[1] : ''; |
|
271 | + $groupFields = array(); |
|
272 | + foreach ($this->_parts['group']['fields'] as $field) { |
|
273 | + $field = is_array($field) ? $field : array($field); |
|
274 | + $column = isset($field[0]) ? $field[0] : false; |
|
275 | + $type = isset($field[1]) ? $field[1] : ''; |
|
276 | 276 | |
277 | - $groupFields[] = $this->protect($column) . ($type ? ' ' . strtoupper($type) : ''); |
|
278 | - } |
|
277 | + $groupFields[] = $this->protect($column) . ($type ? ' ' . strtoupper($type) : ''); |
|
278 | + } |
|
279 | 279 | |
280 | - $group .= implode(', ', $groupFields); |
|
280 | + $group .= implode(', ', $groupFields); |
|
281 | 281 | } else { |
282 | 282 | $group .= $this->_parts['group']['fields']; |
283 | 283 | } |
284 | 284 | } |
285 | 285 | |
286 | - if (isset($this->_parts['group']['rollup']) && $this->_parts['group']['rollup'] !== false) { |
|
287 | - $group .= ' WITH ROLLUP'; |
|
288 | - } |
|
286 | + if (isset($this->_parts['group']['rollup']) && $this->_parts['group']['rollup'] !== false) { |
|
287 | + $group .= ' WITH ROLLUP'; |
|
288 | + } |
|
289 | 289 | |
290 | - return $group; |
|
291 | - } |
|
290 | + return $group; |
|
291 | + } |
|
292 | 292 | |
293 | - public function union($query) |
|
294 | - { |
|
295 | - return new Nip_DB_Query_SelectUnion($this, $query); |
|
296 | - } |
|
293 | + public function union($query) |
|
294 | + { |
|
295 | + return new Nip_DB_Query_SelectUnion($this, $query); |
|
296 | + } |
|
297 | 297 | |
298 | 298 | } |
299 | 299 | \ No newline at end of file |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | |
235 | 235 | $joinType = isset($join[2]) ? $join[2] : ''; |
236 | 236 | |
237 | - $result .= ( $joinType ? ' ' . strtoupper($joinType) : '') . ' JOIN '; |
|
237 | + $result .= ($joinType ? ' ' . strtoupper($joinType) : '') . ' JOIN '; |
|
238 | 238 | if (strpos($joinTable, '(') !== false) { |
239 | 239 | $result .= $joinTable; |
240 | 240 | } else { |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | if (is_array($joinOn)) { |
248 | 248 | $result .= $this->protect($table . '.' . $joinOn[0]) . ' = ' . $this->protect($joinTable . '.' . $joinOn[1]); |
249 | 249 | } else { |
250 | - $result .= '('. $joinOn .')'; |
|
250 | + $result .= '(' . $joinOn . ')'; |
|
251 | 251 | } |
252 | 252 | } |
253 | 253 |
@@ -7,6 +7,9 @@ |
||
7 | 7 | protected $_adapter; |
8 | 8 | protected $_results = array(); |
9 | 9 | |
10 | + /** |
|
11 | + * @param Nip_DB_Adapters_Abstract $adapter |
|
12 | + */ |
|
10 | 13 | public function __construct($data, $adapter) |
11 | 14 | { |
12 | 15 | $this->_data = $data; |
@@ -3,53 +3,53 @@ |
||
3 | 3 | class Nip_DB_Result |
4 | 4 | { |
5 | 5 | |
6 | - protected $_data; |
|
7 | - protected $_adapter; |
|
8 | - protected $_results = array(); |
|
9 | - |
|
10 | - public function __construct($data, $adapter) |
|
11 | - { |
|
12 | - $this->_data = $data; |
|
13 | - $this->_adapter = $adapter; |
|
14 | - } |
|
15 | - |
|
16 | - public function __destruct() |
|
17 | - { |
|
18 | - if ($this->_data && !is_bool($this->_data)) { |
|
19 | - $this->_adapter->freeResults($this->_data); |
|
20 | - } |
|
21 | - } |
|
22 | - |
|
23 | - /** |
|
24 | - * Fetches row from current result set |
|
25 | - * @return array |
|
26 | - */ |
|
27 | - public function fetchResult() |
|
28 | - { |
|
29 | - try { |
|
30 | - return $this->_adapter->fetchAssoc($this->_data); |
|
31 | - } catch (Nip_DB_Exception $e) { |
|
32 | - $e->log(); |
|
33 | - } |
|
34 | - } |
|
35 | - |
|
36 | - /** |
|
37 | - * Fetches all rows from current result set |
|
38 | - * @return array |
|
39 | - */ |
|
40 | - public function fetchResults() |
|
41 | - { |
|
42 | - if (count($this->_results) == 0) { |
|
43 | - while ($result = $this->fetchResult()) { |
|
44 | - $this->_results[] = $result; |
|
45 | - } |
|
46 | - } |
|
47 | - return $this->_results; |
|
48 | - } |
|
49 | - |
|
50 | - public function numRows() |
|
51 | - { |
|
52 | - return $this->_adapter->numRows($this->_data); |
|
53 | - } |
|
6 | + protected $_data; |
|
7 | + protected $_adapter; |
|
8 | + protected $_results = array(); |
|
9 | + |
|
10 | + public function __construct($data, $adapter) |
|
11 | + { |
|
12 | + $this->_data = $data; |
|
13 | + $this->_adapter = $adapter; |
|
14 | + } |
|
15 | + |
|
16 | + public function __destruct() |
|
17 | + { |
|
18 | + if ($this->_data && !is_bool($this->_data)) { |
|
19 | + $this->_adapter->freeResults($this->_data); |
|
20 | + } |
|
21 | + } |
|
22 | + |
|
23 | + /** |
|
24 | + * Fetches row from current result set |
|
25 | + * @return array |
|
26 | + */ |
|
27 | + public function fetchResult() |
|
28 | + { |
|
29 | + try { |
|
30 | + return $this->_adapter->fetchAssoc($this->_data); |
|
31 | + } catch (Nip_DB_Exception $e) { |
|
32 | + $e->log(); |
|
33 | + } |
|
34 | + } |
|
35 | + |
|
36 | + /** |
|
37 | + * Fetches all rows from current result set |
|
38 | + * @return array |
|
39 | + */ |
|
40 | + public function fetchResults() |
|
41 | + { |
|
42 | + if (count($this->_results) == 0) { |
|
43 | + while ($result = $this->fetchResult()) { |
|
44 | + $this->_results[] = $result; |
|
45 | + } |
|
46 | + } |
|
47 | + return $this->_results; |
|
48 | + } |
|
49 | + |
|
50 | + public function numRows() |
|
51 | + { |
|
52 | + return $this->_adapter->numRows($this->_data); |
|
53 | + } |
|
54 | 54 | |
55 | 55 | } |
56 | 56 | \ No newline at end of file |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | * Instantiates database engine adapter |
15 | 15 | * |
16 | 16 | * @param string $adapter |
17 | - * @param string $db_prefix |
|
17 | + * @param string $prefix |
|
18 | 18 | */ |
19 | 19 | public function __construct($adapter = false, $prefix = false) |
20 | 20 | { |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
68 | - * @param mixed $database |
|
68 | + * @param string $database |
|
69 | 69 | */ |
70 | 70 | public function setDatabase($database) |
71 | 71 | { |
@@ -118,7 +118,7 @@ |
||
118 | 118 | { |
119 | 119 | $this->_queries[] = $query; |
120 | 120 | |
121 | - $query = (string)$query; |
|
121 | + $query = (string) $query; |
|
122 | 122 | $query = $this->getAdapter()->execute($query); |
123 | 123 | $result = new Nip_DB_Result($query, $this->getAdapter()); |
124 | 124 |
@@ -70,6 +70,9 @@ discard block |
||
70 | 70 | throw new \Nip_Dispatcher_ForwardException; |
71 | 71 | } |
72 | 72 | |
73 | + /** |
|
74 | + * @param Request $request |
|
75 | + */ |
|
73 | 76 | public function generateController($request) |
74 | 77 | { |
75 | 78 | $controllerClass = $this->getFullControllerNameFromRequest($request); |
@@ -142,6 +145,9 @@ discard block |
||
142 | 145 | return $this->getControllerName($name); |
143 | 146 | } |
144 | 147 | |
148 | + /** |
|
149 | + * @param boolean $name |
|
150 | + */ |
|
145 | 151 | public static function formatActionName($name) |
146 | 152 | { |
147 | 153 | $name = inflector()->camelize($name); |
@@ -77,6 +77,9 @@ discard block |
||
77 | 77 | $this->setName($name); |
78 | 78 | } |
79 | 79 | |
80 | + /** |
|
81 | + * @param string $name |
|
82 | + */ |
|
80 | 83 | public function setName($name) |
81 | 84 | { |
82 | 85 | $this->name = $name; |
@@ -226,6 +229,10 @@ discard block |
||
226 | 229 | $this->crop($x0, $y0, $cWidth, $cHeight, $cWidth, $cHeight); |
227 | 230 | } |
228 | 231 | |
232 | + /** |
|
233 | + * @param double $x |
|
234 | + * @param double $y |
|
235 | + */ |
|
229 | 236 | public function crop($x, $y, $dwidth, $dheight, $swidth, $sheight) |
230 | 237 | { |
231 | 238 | $image = imagecreatetruecolor($dwidth, $dheight); |
@@ -372,6 +379,9 @@ discard block |
||
372 | 379 | return $this->_width; |
373 | 380 | } |
374 | 381 | |
382 | + /** |
|
383 | + * @return integer |
|
384 | + */ |
|
375 | 385 | public function getHeight() |
376 | 386 | { |
377 | 387 | if (!$this->_height && $this->_resource) { |
@@ -11,209 +11,209 @@ discard block |
||
11 | 11 | class Nip_File_Image extends Nip_File_Handler |
12 | 12 | { |
13 | 13 | |
14 | - public $extensions = array("jpg", "jpeg", "gif", "png"); |
|
15 | - public $quality = 90; |
|
16 | - public $type = 'jpg'; |
|
17 | - public $max_width = false; |
|
18 | - public $errors = array(); |
|
19 | - protected $_resource; |
|
20 | - protected $_file; |
|
21 | - protected $_upload; |
|
22 | - protected $_width; |
|
23 | - protected $_height; |
|
24 | - |
|
25 | - public function setResourceFromUpload($upload) |
|
26 | - { |
|
27 | - $this->_upload = $upload; |
|
28 | - $this->setResourceFromFile($upload['tmp_name']); |
|
29 | - } |
|
30 | - |
|
31 | - public function setResourceFromFile($path) |
|
32 | - { |
|
33 | - $this->_file = $path; |
|
34 | - if (file_exists($path)) { |
|
35 | - $details = getimagesize($path); |
|
36 | - |
|
37 | - switch ($details['mime']) { |
|
38 | - case 'image/gif': |
|
39 | - $this->type = 'gif'; |
|
40 | - if (imagetypes() & IMG_GIF) { |
|
41 | - $this->_resource = imagecreatefromgif($path); |
|
42 | - } |
|
43 | - break; |
|
44 | - case 'image/jpeg': |
|
45 | - $this->type = 'jpg'; |
|
46 | - if (imagetypes() & IMG_JPG) { |
|
47 | - $this->_resource = imagecreatefromjpeg($path); |
|
48 | - } |
|
49 | - break; |
|
50 | - case 'image/png': |
|
51 | - $this->type = 'png'; |
|
52 | - if (imagetypes() & IMG_PNG) { |
|
53 | - $this->_resource = imagecreatefrompng($path); |
|
54 | - } |
|
55 | - break; |
|
56 | - } |
|
57 | - |
|
58 | - $this->getWidth(); |
|
59 | - $this->getHeight(); |
|
60 | - |
|
61 | - return true; |
|
62 | - } else { |
|
63 | - trigger_error("Cannot find file $path", E_USER_ERROR); |
|
64 | - } |
|
65 | - |
|
66 | - return false; |
|
67 | - } |
|
68 | - |
|
69 | - public function setResource($gdImage) |
|
70 | - { |
|
71 | - $this->_resource = $gdImage; |
|
72 | - } |
|
73 | - |
|
74 | - public function setBaseName($name) |
|
75 | - { |
|
76 | - $name = $name . '.' . $this->type; |
|
77 | - $this->setName($name); |
|
78 | - } |
|
79 | - |
|
80 | - public function setName($name) |
|
81 | - { |
|
82 | - $this->name = $name; |
|
83 | - $this->url = dirname($this->url) . '/' . $this->name; |
|
84 | - $this->path = dirname($this->path) . '/' . $this->name; |
|
85 | - } |
|
86 | - |
|
87 | - public function save() |
|
88 | - { |
|
89 | - if (Nip_File_System::instance()->createDirectory(dirname($this->path))) { |
|
90 | - |
|
91 | - switch ($this->type) { |
|
92 | - case 'png': |
|
93 | - if ($this->quality > 9) { |
|
94 | - if ($this->quality < 100) { |
|
95 | - $this->quality = $this->quality / 10; |
|
96 | - } else { |
|
97 | - $this->quality = 9; |
|
98 | - } |
|
99 | - } |
|
100 | - $this->quality = abs($this->quality - 9); |
|
101 | - $this->quality = 0; |
|
102 | - |
|
103 | - $newImg = imagecreatetruecolor($this->_width, $this->_height); |
|
104 | - imagealphablending($newImg, false); |
|
105 | - imagesavealpha($newImg, true); |
|
106 | - |
|
107 | - imagecopyresampled($newImg, $this->_resource, 0, 0, 0, 0, $this->_width, $this->_height, $this->_width, $this->_height); |
|
108 | - |
|
109 | - $return = imagepng($newImg, $this->path, $this->quality); |
|
110 | - break; |
|
111 | - case 'jpg': |
|
112 | - default: |
|
113 | - $return = imagejpeg($this->_resource, $this->path, $this->quality); |
|
114 | - break; |
|
115 | - } |
|
116 | - |
|
117 | - if ($return) { |
|
118 | - chmod($this->path, 0777); |
|
119 | - return true; |
|
120 | - } |
|
121 | - $this->errors[] = 'Error saving file'; |
|
122 | - } else { |
|
123 | - $this->errors[] = 'Error creating directory'; |
|
124 | - } |
|
125 | - return false; |
|
126 | - } |
|
127 | - |
|
128 | - public function grayscaleFade() |
|
129 | - { |
|
130 | - $this->grayscaleFilter(); |
|
131 | - imagefilter($this->_resource, IMG_FILTER_BRIGHTNESS, 50); |
|
132 | - } |
|
133 | - |
|
134 | - public function grayscaleFilter() |
|
135 | - { |
|
136 | - imagefilter($this->_resource, IMG_FILTER_GRAYSCALE); |
|
137 | - } |
|
138 | - |
|
139 | - public function resize($max_width = false, $max_height = false) |
|
140 | - { |
|
141 | - if (!$max_width) { |
|
142 | - if ($this->max_width) { |
|
143 | - $max_width = $this->max_width; |
|
144 | - } else { |
|
145 | - $max_width = $this->getWidth(); |
|
146 | - } |
|
147 | - } |
|
14 | + public $extensions = array("jpg", "jpeg", "gif", "png"); |
|
15 | + public $quality = 90; |
|
16 | + public $type = 'jpg'; |
|
17 | + public $max_width = false; |
|
18 | + public $errors = array(); |
|
19 | + protected $_resource; |
|
20 | + protected $_file; |
|
21 | + protected $_upload; |
|
22 | + protected $_width; |
|
23 | + protected $_height; |
|
24 | + |
|
25 | + public function setResourceFromUpload($upload) |
|
26 | + { |
|
27 | + $this->_upload = $upload; |
|
28 | + $this->setResourceFromFile($upload['tmp_name']); |
|
29 | + } |
|
30 | + |
|
31 | + public function setResourceFromFile($path) |
|
32 | + { |
|
33 | + $this->_file = $path; |
|
34 | + if (file_exists($path)) { |
|
35 | + $details = getimagesize($path); |
|
36 | + |
|
37 | + switch ($details['mime']) { |
|
38 | + case 'image/gif': |
|
39 | + $this->type = 'gif'; |
|
40 | + if (imagetypes() & IMG_GIF) { |
|
41 | + $this->_resource = imagecreatefromgif($path); |
|
42 | + } |
|
43 | + break; |
|
44 | + case 'image/jpeg': |
|
45 | + $this->type = 'jpg'; |
|
46 | + if (imagetypes() & IMG_JPG) { |
|
47 | + $this->_resource = imagecreatefromjpeg($path); |
|
48 | + } |
|
49 | + break; |
|
50 | + case 'image/png': |
|
51 | + $this->type = 'png'; |
|
52 | + if (imagetypes() & IMG_PNG) { |
|
53 | + $this->_resource = imagecreatefrompng($path); |
|
54 | + } |
|
55 | + break; |
|
56 | + } |
|
57 | + |
|
58 | + $this->getWidth(); |
|
59 | + $this->getHeight(); |
|
60 | + |
|
61 | + return true; |
|
62 | + } else { |
|
63 | + trigger_error("Cannot find file $path", E_USER_ERROR); |
|
64 | + } |
|
65 | + |
|
66 | + return false; |
|
67 | + } |
|
68 | + |
|
69 | + public function setResource($gdImage) |
|
70 | + { |
|
71 | + $this->_resource = $gdImage; |
|
72 | + } |
|
73 | + |
|
74 | + public function setBaseName($name) |
|
75 | + { |
|
76 | + $name = $name . '.' . $this->type; |
|
77 | + $this->setName($name); |
|
78 | + } |
|
79 | + |
|
80 | + public function setName($name) |
|
81 | + { |
|
82 | + $this->name = $name; |
|
83 | + $this->url = dirname($this->url) . '/' . $this->name; |
|
84 | + $this->path = dirname($this->path) . '/' . $this->name; |
|
85 | + } |
|
86 | + |
|
87 | + public function save() |
|
88 | + { |
|
89 | + if (Nip_File_System::instance()->createDirectory(dirname($this->path))) { |
|
90 | + |
|
91 | + switch ($this->type) { |
|
92 | + case 'png': |
|
93 | + if ($this->quality > 9) { |
|
94 | + if ($this->quality < 100) { |
|
95 | + $this->quality = $this->quality / 10; |
|
96 | + } else { |
|
97 | + $this->quality = 9; |
|
98 | + } |
|
99 | + } |
|
100 | + $this->quality = abs($this->quality - 9); |
|
101 | + $this->quality = 0; |
|
102 | + |
|
103 | + $newImg = imagecreatetruecolor($this->_width, $this->_height); |
|
104 | + imagealphablending($newImg, false); |
|
105 | + imagesavealpha($newImg, true); |
|
106 | + |
|
107 | + imagecopyresampled($newImg, $this->_resource, 0, 0, 0, 0, $this->_width, $this->_height, $this->_width, $this->_height); |
|
108 | + |
|
109 | + $return = imagepng($newImg, $this->path, $this->quality); |
|
110 | + break; |
|
111 | + case 'jpg': |
|
112 | + default: |
|
113 | + $return = imagejpeg($this->_resource, $this->path, $this->quality); |
|
114 | + break; |
|
115 | + } |
|
116 | + |
|
117 | + if ($return) { |
|
118 | + chmod($this->path, 0777); |
|
119 | + return true; |
|
120 | + } |
|
121 | + $this->errors[] = 'Error saving file'; |
|
122 | + } else { |
|
123 | + $this->errors[] = 'Error creating directory'; |
|
124 | + } |
|
125 | + return false; |
|
126 | + } |
|
127 | + |
|
128 | + public function grayscaleFade() |
|
129 | + { |
|
130 | + $this->grayscaleFilter(); |
|
131 | + imagefilter($this->_resource, IMG_FILTER_BRIGHTNESS, 50); |
|
132 | + } |
|
133 | + |
|
134 | + public function grayscaleFilter() |
|
135 | + { |
|
136 | + imagefilter($this->_resource, IMG_FILTER_GRAYSCALE); |
|
137 | + } |
|
138 | + |
|
139 | + public function resize($max_width = false, $max_height = false) |
|
140 | + { |
|
141 | + if (!$max_width) { |
|
142 | + if ($this->max_width) { |
|
143 | + $max_width = $this->max_width; |
|
144 | + } else { |
|
145 | + $max_width = $this->getWidth(); |
|
146 | + } |
|
147 | + } |
|
148 | 148 | |
149 | - if (!$max_height) { |
|
150 | - if ($this->max_height) { |
|
151 | - $max_height = $this->max_height; |
|
152 | - } else { |
|
153 | - $max_height = $this->getHeight(); |
|
154 | - } |
|
155 | - } |
|
149 | + if (!$max_height) { |
|
150 | + if ($this->max_height) { |
|
151 | + $max_height = $this->max_height; |
|
152 | + } else { |
|
153 | + $max_height = $this->getHeight(); |
|
154 | + } |
|
155 | + } |
|
156 | 156 | |
157 | 157 | $ratio = $this->getRatio(); |
158 | 158 | $target_ratio = $max_width/$max_height; |
159 | 159 | |
160 | 160 | if ($ratio>$target_ratio){ |
161 | - $new_width = $max_width; |
|
161 | + $new_width = $max_width; |
|
162 | 162 | $new_height=round($max_width/$ratio); |
163 | 163 | } else { |
164 | - $new_height = $max_height; |
|
164 | + $new_height = $max_height; |
|
165 | 165 | $new_width = round($max_height * $ratio); |
166 | 166 | } |
167 | 167 | |
168 | - $image = imagecreatetruecolor($new_width, $new_height); |
|
169 | - imagealphablending($image, false); |
|
170 | - imagesavealpha($image, true); |
|
168 | + $image = imagecreatetruecolor($new_width, $new_height); |
|
169 | + imagealphablending($image, false); |
|
170 | + imagesavealpha($image, true); |
|
171 | 171 | |
172 | - imagecopyresampled($image, $this->_resource, 0, 0, 0, 0, $new_width, $new_height, $this->getWidth(), $this->getHeight()); |
|
172 | + imagecopyresampled($image, $this->_resource, 0, 0, 0, 0, $new_width, $new_height, $this->getWidth(), $this->getHeight()); |
|
173 | 173 | |
174 | - $this->_width = $new_width; |
|
175 | - $this->_height = $new_height; |
|
176 | - $this->_resource = $image; |
|
174 | + $this->_width = $new_width; |
|
175 | + $this->_height = $new_height; |
|
176 | + $this->_resource = $image; |
|
177 | 177 | |
178 | - return $this; |
|
179 | - } |
|
178 | + return $this; |
|
179 | + } |
|
180 | 180 | |
181 | - public function resizeToLarge($max_width = false, $max_height = false) |
|
182 | - { |
|
183 | - if (!$max_width) { |
|
181 | + public function resizeToLarge($max_width = false, $max_height = false) |
|
182 | + { |
|
183 | + if (!$max_width) { |
|
184 | 184 | $max_width = $this->getWidth(); |
185 | - } |
|
185 | + } |
|
186 | 186 | |
187 | - if (!$max_height) { |
|
187 | + if (!$max_height) { |
|
188 | 188 | $max_height = $this->getHeight(); |
189 | - } |
|
189 | + } |
|
190 | 190 | |
191 | 191 | $sourceRatio = $this->getRatio(); |
192 | 192 | $target_ratio = $max_width/$max_height; |
193 | 193 | |
194 | 194 | if ($sourceRatio>$target_ratio){ |
195 | - $new_height = $max_height; |
|
195 | + $new_height = $max_height; |
|
196 | 196 | $new_width = ( int ) ($max_height * $sourceRatio); |
197 | 197 | } else { |
198 | 198 | $new_width = $max_width; |
199 | 199 | $new_height = ( int ) ($max_width / $sourceRatio); |
200 | 200 | } |
201 | 201 | |
202 | - $image = imagecreatetruecolor($new_width, $new_height); |
|
203 | - imagealphablending($image, false); |
|
204 | - imagesavealpha($image, true); |
|
202 | + $image = imagecreatetruecolor($new_width, $new_height); |
|
203 | + imagealphablending($image, false); |
|
204 | + imagesavealpha($image, true); |
|
205 | 205 | |
206 | - imagecopyresampled($image, $this->_resource, 0, 0, 0, 0, $new_width, $new_height, $this->getWidth(), $this->getHeight()); |
|
206 | + imagecopyresampled($image, $this->_resource, 0, 0, 0, 0, $new_width, $new_height, $this->getWidth(), $this->getHeight()); |
|
207 | 207 | |
208 | - $this->_width = $new_width; |
|
209 | - $this->_height = $new_height; |
|
210 | - $this->_resource = $image; |
|
208 | + $this->_width = $new_width; |
|
209 | + $this->_height = $new_height; |
|
210 | + $this->_resource = $image; |
|
211 | 211 | |
212 | - return $this; |
|
213 | - } |
|
212 | + return $this; |
|
213 | + } |
|
214 | 214 | |
215 | - public function cropToCenter($cWidth, $cHeight) |
|
216 | - { |
|
215 | + public function cropToCenter($cWidth, $cHeight) |
|
216 | + { |
|
217 | 217 | |
218 | 218 | $this->resizeToLarge($cWidth, $cHeight); |
219 | 219 | |
@@ -223,162 +223,162 @@ discard block |
||
223 | 223 | $x0 = round(abs(($width - $cWidth) / 2),0); |
224 | 224 | $y0 = round(abs(($height - $cHeight) / 2),0); |
225 | 225 | |
226 | - $this->crop($x0, $y0, $cWidth, $cHeight, $cWidth, $cHeight); |
|
227 | - } |
|
226 | + $this->crop($x0, $y0, $cWidth, $cHeight, $cWidth, $cHeight); |
|
227 | + } |
|
228 | 228 | |
229 | - public function crop($x, $y, $dwidth, $dheight, $swidth, $sheight) |
|
230 | - { |
|
231 | - $image = imagecreatetruecolor($dwidth, $dheight); |
|
232 | - imagealphablending($image, false); |
|
233 | - imagesavealpha($image, true); |
|
229 | + public function crop($x, $y, $dwidth, $dheight, $swidth, $sheight) |
|
230 | + { |
|
231 | + $image = imagecreatetruecolor($dwidth, $dheight); |
|
232 | + imagealphablending($image, false); |
|
233 | + imagesavealpha($image, true); |
|
234 | 234 | |
235 | - imagecopyresampled($image, $this->_resource, |
|
235 | + imagecopyresampled($image, $this->_resource, |
|
236 | 236 | 0, 0, |
237 | 237 | $x, $y, |
238 | 238 | $dwidth, $dheight, |
239 | 239 | $swidth, $sheight); |
240 | 240 | |
241 | - $this->_width = $dwidth; |
|
242 | - $this->_height = $dheight; |
|
243 | - $this->_resource = $image; |
|
244 | - } |
|
245 | - |
|
246 | - public function unsharpMask($amount = 80, $radius = 0.5, $threshold = 3) |
|
247 | - { |
|
248 | - $img = &$this->_resource; |
|
249 | - |
|
250 | - if ($amount > 500) { |
|
251 | - $amount = 500; |
|
252 | - } |
|
253 | - $amount = $amount * 0.016; |
|
254 | - if ($radius > 50) { |
|
255 | - $radius = 50; |
|
256 | - } |
|
257 | - $radius = $radius * 2; |
|
258 | - if ($threshold > 255) { |
|
259 | - $threshold = 255; |
|
260 | - } |
|
261 | - |
|
262 | - $radius = abs(round($radius)); |
|
263 | - if ($radius == 0) { |
|
264 | - return; |
|
265 | - } |
|
266 | - |
|
267 | - $w = $this->_width; |
|
268 | - $h = $this->_height; |
|
269 | - |
|
270 | - $imgCanvas = imagecreatetruecolor($w, $h); |
|
271 | - $imgBlur = imagecreatetruecolor($w, $h); |
|
272 | - |
|
273 | - if (function_exists('imageconvolution')) { |
|
274 | - $matrix = array(array(1, 2, 1), array(2, 4, 2), array(1, 2, 1)); |
|
275 | - imagecopy($imgBlur, $img, 0, 0, 0, 0, $w, $h); |
|
276 | - imageconvolution($imgBlur, $matrix, 16, 0); |
|
277 | - } else { |
|
278 | - for ($i = 0; $i < $radius; $i++) { |
|
279 | - imagecopy($imgBlur, $img, 0, 0, 1, 0, $w - 1, $h); |
|
280 | - imagecopymerge($imgBlur, $img, 1, 0, 0, 0, $w, $h, 50); |
|
281 | - imagecopymerge($imgBlur, $img, 0, 0, 0, 0, $w, $h, 50); |
|
282 | - imagecopy($imgCanvas, $imgBlur, 0, 0, 0, 0, $w, $h); |
|
283 | - |
|
284 | - imagecopymerge($imgBlur, $imgCanvas, 0, 0, 0, 1, $w, $h - 1, 33.33333); |
|
285 | - imagecopymerge($imgBlur, $imgCanvas, 0, 1, 0, 0, $w, $h, 25); |
|
286 | - } |
|
287 | - } |
|
288 | - |
|
289 | - if ($threshold > 0) { |
|
290 | - for ($x = 0; $x < $w - 1; $x++) { |
|
291 | - for ($y = 0; $y < $h; $y++) { |
|
292 | - |
|
293 | - $rgbOrig = ImageColorAt($img, $x, $y); |
|
294 | - $rOrig = (($rgbOrig >> 16) & 0xFF); |
|
295 | - $gOrig = (($rgbOrig >> 8) & 0xFF); |
|
296 | - $bOrig = ($rgbOrig & 0xFF); |
|
297 | - |
|
298 | - $rgbBlur = ImageColorAt($imgBlur, $x, $y); |
|
299 | - |
|
300 | - $rBlur = (($rgbBlur >> 16) & 0xFF); |
|
301 | - $gBlur = (($rgbBlur >> 8) & 0xFF); |
|
302 | - $bBlur = ($rgbBlur & 0xFF); |
|
303 | - |
|
304 | - $rNew = (abs($rOrig - $rBlur) >= $threshold) ? max(0, min(255, ($amount * ($rOrig - $rBlur)) + $rOrig)) : $rOrig; |
|
305 | - $gNew = (abs($gOrig - $gBlur) >= $threshold) ? max(0, min(255, ($amount * ($gOrig - $gBlur)) + $gOrig)) : $gOrig; |
|
306 | - $bNew = (abs($bOrig - $bBlur) >= $threshold) ? max(0, min(255, ($amount * ($bOrig - $bBlur)) + $bOrig)) : $bOrig; |
|
307 | - |
|
308 | - if (($rOrig != $rNew) || ($gOrig != $gNew) || ($bOrig != $bNew)) { |
|
309 | - $pixCol = ImageColorAllocate($img, $rNew, $gNew, $bNew); |
|
310 | - ImageSetPixel($img, $x, $y, $pixCol); |
|
311 | - } |
|
312 | - } |
|
313 | - } |
|
314 | - } else { |
|
315 | - for ($x = 0; $x < $w; $x++) { |
|
316 | - for ($y = 0; $y < $h; $y++) { |
|
317 | - $rgbOrig = ImageColorAt($img, $x, $y); |
|
318 | - $rOrig = (($rgbOrig >> 16) & 0xFF); |
|
319 | - $gOrig = (($rgbOrig >> 8) & 0xFF); |
|
320 | - $bOrig = ($rgbOrig & 0xFF); |
|
321 | - |
|
322 | - $rgbBlur = ImageColorAt($imgBlur, $x, $y); |
|
323 | - |
|
324 | - $rBlur = (($rgbBlur >> 16) & 0xFF); |
|
325 | - $gBlur = (($rgbBlur >> 8) & 0xFF); |
|
326 | - $bBlur = ($rgbBlur & 0xFF); |
|
327 | - |
|
328 | - $rNew = ($amount * ($rOrig - $rBlur)) + $rOrig; |
|
329 | - if ($rNew > 255) { |
|
330 | - $rNew = 255; |
|
331 | - } elseif ($rNew < 0) { |
|
332 | - $rNew = 0; |
|
333 | - } |
|
334 | - $gNew = ($amount * ($gOrig - $gBlur)) + $gOrig; |
|
335 | - if ($gNew > 255) { |
|
336 | - $gNew = 255; |
|
337 | - } elseif ($gNew < 0) { |
|
338 | - $gNew = 0; |
|
339 | - } |
|
340 | - $bNew = ($amount * ($bOrig - $bBlur)) + $bOrig; |
|
341 | - if ($bNew > 255) { |
|
342 | - $bNew = 255; |
|
343 | - } elseif ($bNew < 0) { |
|
344 | - $bNew = 0; |
|
345 | - } |
|
346 | - $rgbNew = ($rNew << 16) + ($gNew << 8) + $bNew; |
|
347 | - ImageSetPixel($img, $x, $y, $rgbNew); |
|
348 | - } |
|
349 | - } |
|
350 | - } |
|
351 | - |
|
352 | - imagedestroy($imgCanvas); |
|
353 | - imagedestroy($imgBlur); |
|
354 | - |
|
355 | - return $this; |
|
356 | - } |
|
357 | - |
|
358 | - public function copyResource(Nip_File_Image $image) |
|
359 | - { |
|
360 | - $this->_width = $image->getWidth(); |
|
361 | - $this->_height = $image->getHeight(); |
|
362 | - $this->_resource = $image->getResource(); |
|
363 | - |
|
364 | - return $this; |
|
365 | - } |
|
366 | - |
|
367 | - public function getWidth() |
|
368 | - { |
|
369 | - if (!$this->_width && $this->_resource) { |
|
370 | - $this->_width = imagesx($this->_resource); |
|
371 | - } |
|
372 | - return $this->_width; |
|
373 | - } |
|
374 | - |
|
375 | - public function getHeight() |
|
376 | - { |
|
377 | - if (!$this->_height && $this->_resource) { |
|
378 | - $this->_height = imagesy($this->_resource); |
|
379 | - } |
|
380 | - return $this->_height; |
|
381 | - } |
|
241 | + $this->_width = $dwidth; |
|
242 | + $this->_height = $dheight; |
|
243 | + $this->_resource = $image; |
|
244 | + } |
|
245 | + |
|
246 | + public function unsharpMask($amount = 80, $radius = 0.5, $threshold = 3) |
|
247 | + { |
|
248 | + $img = &$this->_resource; |
|
249 | + |
|
250 | + if ($amount > 500) { |
|
251 | + $amount = 500; |
|
252 | + } |
|
253 | + $amount = $amount * 0.016; |
|
254 | + if ($radius > 50) { |
|
255 | + $radius = 50; |
|
256 | + } |
|
257 | + $radius = $radius * 2; |
|
258 | + if ($threshold > 255) { |
|
259 | + $threshold = 255; |
|
260 | + } |
|
261 | + |
|
262 | + $radius = abs(round($radius)); |
|
263 | + if ($radius == 0) { |
|
264 | + return; |
|
265 | + } |
|
266 | + |
|
267 | + $w = $this->_width; |
|
268 | + $h = $this->_height; |
|
269 | + |
|
270 | + $imgCanvas = imagecreatetruecolor($w, $h); |
|
271 | + $imgBlur = imagecreatetruecolor($w, $h); |
|
272 | + |
|
273 | + if (function_exists('imageconvolution')) { |
|
274 | + $matrix = array(array(1, 2, 1), array(2, 4, 2), array(1, 2, 1)); |
|
275 | + imagecopy($imgBlur, $img, 0, 0, 0, 0, $w, $h); |
|
276 | + imageconvolution($imgBlur, $matrix, 16, 0); |
|
277 | + } else { |
|
278 | + for ($i = 0; $i < $radius; $i++) { |
|
279 | + imagecopy($imgBlur, $img, 0, 0, 1, 0, $w - 1, $h); |
|
280 | + imagecopymerge($imgBlur, $img, 1, 0, 0, 0, $w, $h, 50); |
|
281 | + imagecopymerge($imgBlur, $img, 0, 0, 0, 0, $w, $h, 50); |
|
282 | + imagecopy($imgCanvas, $imgBlur, 0, 0, 0, 0, $w, $h); |
|
283 | + |
|
284 | + imagecopymerge($imgBlur, $imgCanvas, 0, 0, 0, 1, $w, $h - 1, 33.33333); |
|
285 | + imagecopymerge($imgBlur, $imgCanvas, 0, 1, 0, 0, $w, $h, 25); |
|
286 | + } |
|
287 | + } |
|
288 | + |
|
289 | + if ($threshold > 0) { |
|
290 | + for ($x = 0; $x < $w - 1; $x++) { |
|
291 | + for ($y = 0; $y < $h; $y++) { |
|
292 | + |
|
293 | + $rgbOrig = ImageColorAt($img, $x, $y); |
|
294 | + $rOrig = (($rgbOrig >> 16) & 0xFF); |
|
295 | + $gOrig = (($rgbOrig >> 8) & 0xFF); |
|
296 | + $bOrig = ($rgbOrig & 0xFF); |
|
297 | + |
|
298 | + $rgbBlur = ImageColorAt($imgBlur, $x, $y); |
|
299 | + |
|
300 | + $rBlur = (($rgbBlur >> 16) & 0xFF); |
|
301 | + $gBlur = (($rgbBlur >> 8) & 0xFF); |
|
302 | + $bBlur = ($rgbBlur & 0xFF); |
|
303 | + |
|
304 | + $rNew = (abs($rOrig - $rBlur) >= $threshold) ? max(0, min(255, ($amount * ($rOrig - $rBlur)) + $rOrig)) : $rOrig; |
|
305 | + $gNew = (abs($gOrig - $gBlur) >= $threshold) ? max(0, min(255, ($amount * ($gOrig - $gBlur)) + $gOrig)) : $gOrig; |
|
306 | + $bNew = (abs($bOrig - $bBlur) >= $threshold) ? max(0, min(255, ($amount * ($bOrig - $bBlur)) + $bOrig)) : $bOrig; |
|
307 | + |
|
308 | + if (($rOrig != $rNew) || ($gOrig != $gNew) || ($bOrig != $bNew)) { |
|
309 | + $pixCol = ImageColorAllocate($img, $rNew, $gNew, $bNew); |
|
310 | + ImageSetPixel($img, $x, $y, $pixCol); |
|
311 | + } |
|
312 | + } |
|
313 | + } |
|
314 | + } else { |
|
315 | + for ($x = 0; $x < $w; $x++) { |
|
316 | + for ($y = 0; $y < $h; $y++) { |
|
317 | + $rgbOrig = ImageColorAt($img, $x, $y); |
|
318 | + $rOrig = (($rgbOrig >> 16) & 0xFF); |
|
319 | + $gOrig = (($rgbOrig >> 8) & 0xFF); |
|
320 | + $bOrig = ($rgbOrig & 0xFF); |
|
321 | + |
|
322 | + $rgbBlur = ImageColorAt($imgBlur, $x, $y); |
|
323 | + |
|
324 | + $rBlur = (($rgbBlur >> 16) & 0xFF); |
|
325 | + $gBlur = (($rgbBlur >> 8) & 0xFF); |
|
326 | + $bBlur = ($rgbBlur & 0xFF); |
|
327 | + |
|
328 | + $rNew = ($amount * ($rOrig - $rBlur)) + $rOrig; |
|
329 | + if ($rNew > 255) { |
|
330 | + $rNew = 255; |
|
331 | + } elseif ($rNew < 0) { |
|
332 | + $rNew = 0; |
|
333 | + } |
|
334 | + $gNew = ($amount * ($gOrig - $gBlur)) + $gOrig; |
|
335 | + if ($gNew > 255) { |
|
336 | + $gNew = 255; |
|
337 | + } elseif ($gNew < 0) { |
|
338 | + $gNew = 0; |
|
339 | + } |
|
340 | + $bNew = ($amount * ($bOrig - $bBlur)) + $bOrig; |
|
341 | + if ($bNew > 255) { |
|
342 | + $bNew = 255; |
|
343 | + } elseif ($bNew < 0) { |
|
344 | + $bNew = 0; |
|
345 | + } |
|
346 | + $rgbNew = ($rNew << 16) + ($gNew << 8) + $bNew; |
|
347 | + ImageSetPixel($img, $x, $y, $rgbNew); |
|
348 | + } |
|
349 | + } |
|
350 | + } |
|
351 | + |
|
352 | + imagedestroy($imgCanvas); |
|
353 | + imagedestroy($imgBlur); |
|
354 | + |
|
355 | + return $this; |
|
356 | + } |
|
357 | + |
|
358 | + public function copyResource(Nip_File_Image $image) |
|
359 | + { |
|
360 | + $this->_width = $image->getWidth(); |
|
361 | + $this->_height = $image->getHeight(); |
|
362 | + $this->_resource = $image->getResource(); |
|
363 | + |
|
364 | + return $this; |
|
365 | + } |
|
366 | + |
|
367 | + public function getWidth() |
|
368 | + { |
|
369 | + if (!$this->_width && $this->_resource) { |
|
370 | + $this->_width = imagesx($this->_resource); |
|
371 | + } |
|
372 | + return $this->_width; |
|
373 | + } |
|
374 | + |
|
375 | + public function getHeight() |
|
376 | + { |
|
377 | + if (!$this->_height && $this->_resource) { |
|
378 | + $this->_height = imagesy($this->_resource); |
|
379 | + } |
|
380 | + return $this->_height; |
|
381 | + } |
|
382 | 382 | |
383 | 383 | public function getRatio() |
384 | 384 | { |
@@ -386,14 +386,14 @@ discard block |
||
386 | 386 | } |
387 | 387 | |
388 | 388 | public function getResource() |
389 | - { |
|
390 | - return $this->_resource; |
|
391 | - } |
|
392 | - |
|
393 | - public function getFile() |
|
394 | - { |
|
395 | - return $this->_file; |
|
396 | - } |
|
389 | + { |
|
390 | + return $this->_resource; |
|
391 | + } |
|
392 | + |
|
393 | + public function getFile() |
|
394 | + { |
|
395 | + return $this->_file; |
|
396 | + } |
|
397 | 397 | |
398 | 398 | public function getExtension() { |
399 | 399 | return Nip_File_System::instance()->getExtension($this->path); |
@@ -155,11 +155,11 @@ discard block |
||
155 | 155 | } |
156 | 156 | |
157 | 157 | $ratio = $this->getRatio(); |
158 | - $target_ratio = $max_width/$max_height; |
|
158 | + $target_ratio = $max_width / $max_height; |
|
159 | 159 | |
160 | - if ($ratio>$target_ratio){ |
|
160 | + if ($ratio > $target_ratio) { |
|
161 | 161 | $new_width = $max_width; |
162 | - $new_height=round($max_width/$ratio); |
|
162 | + $new_height = round($max_width / $ratio); |
|
163 | 163 | } else { |
164 | 164 | $new_height = $max_height; |
165 | 165 | $new_width = round($max_height * $ratio); |
@@ -189,14 +189,14 @@ discard block |
||
189 | 189 | } |
190 | 190 | |
191 | 191 | $sourceRatio = $this->getRatio(); |
192 | - $target_ratio = $max_width/$max_height; |
|
192 | + $target_ratio = $max_width / $max_height; |
|
193 | 193 | |
194 | - if ($sourceRatio>$target_ratio){ |
|
194 | + if ($sourceRatio > $target_ratio) { |
|
195 | 195 | $new_height = $max_height; |
196 | - $new_width = ( int ) ($max_height * $sourceRatio); |
|
196 | + $new_width = (int) ($max_height * $sourceRatio); |
|
197 | 197 | } else { |
198 | 198 | $new_width = $max_width; |
199 | - $new_height = ( int ) ($max_width / $sourceRatio); |
|
199 | + $new_height = (int) ($max_width / $sourceRatio); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | $image = imagecreatetruecolor($new_width, $new_height); |
@@ -220,8 +220,8 @@ discard block |
||
220 | 220 | $width = $this->getWidth(); |
221 | 221 | $height = $this->getHeight(); |
222 | 222 | |
223 | - $x0 = round(abs(($width - $cWidth) / 2),0); |
|
224 | - $y0 = round(abs(($height - $cHeight) / 2),0); |
|
223 | + $x0 = round(abs(($width - $cWidth) / 2), 0); |
|
224 | + $y0 = round(abs(($height - $cHeight) / 2), 0); |
|
225 | 225 | |
226 | 226 | $this->crop($x0, $y0, $cWidth, $cHeight, $cWidth, $cHeight); |
227 | 227 | } |
@@ -382,7 +382,7 @@ discard block |
||
382 | 382 | |
383 | 383 | public function getRatio() |
384 | 384 | { |
385 | - return $this->getWidth()/$this->getHeight(); |
|
385 | + return $this->getWidth() / $this->getHeight(); |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | public function getResource() |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | * |
47 | 47 | * @param string $file |
48 | 48 | * @param array $extensions |
49 | - * @return mixed |
|
49 | + * @return string|false |
|
50 | 50 | */ |
51 | 51 | public function getUploadErrorNo($file, $extensions = array()) |
52 | 52 | { |
@@ -199,6 +199,9 @@ discard block |
||
199 | 199 | return $this; |
200 | 200 | } |
201 | 201 | |
202 | + /** |
|
203 | + * @param string $path |
|
204 | + */ |
|
202 | 205 | public function deleteFile($path) |
203 | 206 | { |
204 | 207 | if (file_exists($path)) { |
@@ -31,10 +31,10 @@ |
||
31 | 31 | |
32 | 32 | $errorCode = $this->getUploadErrorNo($file, $extensions); |
33 | 33 | if (is_int($errorCode)) { |
34 | - $translateSlug = 'general.errors.upload.code-'.$errorCode; |
|
34 | + $translateSlug = 'general.errors.upload.code-' . $errorCode; |
|
35 | 35 | return Nip_I18n::instance()->hasTranslation($translateSlug) ? __($translateSlug) : $this->_uploadErrors[$errorCode]; |
36 | 36 | } elseif (is_string($errorCode)) { |
37 | - $translateSlug = 'general.errors.upload.'.$errorCode; |
|
37 | + $translateSlug = 'general.errors.upload.' . $errorCode; |
|
38 | 38 | return Nip_I18n::instance()->hasTranslation($translateSlug) ? __($translateSlug) : $messages[$errorCode]; |
39 | 39 | } |
40 | 40 |
@@ -271,6 +271,7 @@ discard block |
||
271 | 271 | } |
272 | 272 | |
273 | 273 | /** |
274 | + * @param string $type |
|
274 | 275 | * @return Nip_Form_Element_Abstract |
275 | 276 | */ |
276 | 277 | public function getNewElement($type) |
@@ -317,6 +318,9 @@ discard block |
||
317 | 318 | return $this; |
318 | 319 | } |
319 | 320 | |
321 | + /** |
|
322 | + * @param string $key |
|
323 | + */ |
|
320 | 324 | public function getOption($key) |
321 | 325 | { |
322 | 326 | $key = (string) $key; |
@@ -352,6 +356,9 @@ discard block |
||
352 | 356 | return $this; |
353 | 357 | } |
354 | 358 | |
359 | + /** |
|
360 | + * @param string $class |
|
361 | + */ |
|
355 | 362 | public function hasClass($class) { |
356 | 363 | return in_array($class, explode(' ', $this->getAttrib('class'))); |
357 | 364 | } |
@@ -388,6 +395,11 @@ discard block |
||
388 | 395 | return $this->addAttribs($attribs); |
389 | 396 | } |
390 | 397 | |
398 | + /** |
|
399 | + * @param string $key |
|
400 | + * |
|
401 | + * @return string |
|
402 | + */ |
|
391 | 403 | public function getAttrib($key) |
392 | 404 | { |
393 | 405 | $key = (string) $key; |
@@ -568,6 +580,9 @@ discard block |
||
568 | 580 | return $messages; |
569 | 581 | } |
570 | 582 | |
583 | + /** |
|
584 | + * @param string $name |
|
585 | + */ |
|
571 | 586 | public function getMessageTemplate($name) |
572 | 587 | { |
573 | 588 | return $this->_messageTemplates[$name]; |
@@ -601,7 +616,7 @@ discard block |
||
601 | 616 | } |
602 | 617 | |
603 | 618 | /** |
604 | - * @return Nip_Form_Renderer |
|
619 | + * @return Nip_Form_Abstract |
|
605 | 620 | */ |
606 | 621 | public function setRendererType($type) |
607 | 622 | { |
@@ -614,6 +629,9 @@ discard block |
||
614 | 629 | return $this->_cache[$key]; |
615 | 630 | } |
616 | 631 | |
632 | + /** |
|
633 | + * @param string $key |
|
634 | + */ |
|
617 | 635 | public function setCache($key, $value) |
618 | 636 | { |
619 | 637 | $this->_cache[$key] = $value; |
@@ -636,11 +636,11 @@ |
||
636 | 636 | |
637 | 637 | public function getControllerView() |
638 | 638 | { |
639 | - if (!$this->_controllerView) { |
|
640 | - $this->_controllerView = Nip_FrontController::instance()->getDispatcher()->getCurrentController()->getView(); |
|
641 | - } |
|
639 | + if (!$this->_controllerView) { |
|
640 | + $this->_controllerView = Nip_FrontController::instance()->getDispatcher()->getCurrentController()->getView(); |
|
641 | + } |
|
642 | 642 | |
643 | - return $this->_controllerView; |
|
643 | + return $this->_controllerView; |
|
644 | 644 | } |
645 | 645 | |
646 | 646 | } |
647 | 647 | \ No newline at end of file |
@@ -50,11 +50,11 @@ discard block |
||
50 | 50 | $isRequired = $arguments[2]; |
51 | 51 | return $this->add($name, $label, $type, $isRequired); |
52 | 52 | } else { |
53 | - trigger_error('Undefined element type for add operation: ['.$type.']', E_USER_ERROR); |
|
53 | + trigger_error('Undefined element type for add operation: [' . $type . ']', E_USER_ERROR); |
|
54 | 54 | } |
55 | 55 | } |
56 | 56 | |
57 | - trigger_error('Call to undefined method: ['.$name.']', E_USER_ERROR); |
|
57 | + trigger_error('Call to undefined method: [' . $name . ']', E_USER_ERROR); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | public function __get($name) |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | |
171 | 171 | public function addButton($name, $label = false, $type = 'button') |
172 | 172 | { |
173 | - $class = 'Nip_Form_Button_'.ucfirst($type); |
|
173 | + $class = 'Nip_Form_Button_' . ucfirst($type); |
|
174 | 174 | $this->_buttons[$name] = new $class($this); |
175 | 175 | $this->_buttons[$name]->setName($name) |
176 | 176 | ->setLabel($label); |
@@ -302,7 +302,7 @@ discard block |
||
302 | 302 | */ |
303 | 303 | public function getElementClassName($type) |
304 | 304 | { |
305 | - return 'Nip_Form_Element_'.ucfirst($type); |
|
305 | + return 'Nip_Form_Element_' . ucfirst($type); |
|
306 | 306 | $element = new $className($this); |
307 | 307 | return $element; |
308 | 308 | } |
@@ -594,7 +594,7 @@ discard block |
||
594 | 594 | */ |
595 | 595 | public function getNewRenderer($type = 'basic') |
596 | 596 | { |
597 | - $name = 'Nip_Form_Renderer_'.ucfirst($type); |
|
597 | + $name = 'Nip_Form_Renderer_' . ucfirst($type); |
|
598 | 598 | $renderer = new $name(); |
599 | 599 | $renderer->setForm($this); |
600 | 600 | return $renderer; |
@@ -30,6 +30,9 @@ discard block |
||
30 | 30 | return $this; |
31 | 31 | } |
32 | 32 | |
33 | + /** |
|
34 | + * @return Nip_Form_Button_Abstract |
|
35 | + */ |
|
33 | 36 | public function getName() { |
34 | 37 | return $this->getAttrib('name'); |
35 | 38 | } |
@@ -75,7 +78,7 @@ discard block |
||
75 | 78 | } |
76 | 79 | |
77 | 80 | /** |
78 | - * @return Nip_Form_Element_Abstract |
|
81 | + * @return Nip_Form_Button_Abstract |
|
79 | 82 | */ |
80 | 83 | public function setAttrib($key, $value) { |
81 | 84 | $key = (string) $key; |
@@ -85,7 +88,7 @@ discard block |
||
85 | 88 | |
86 | 89 | /** |
87 | 90 | * @param array $attribs |
88 | - * @return Nip_Form_Element_Abstract |
|
91 | + * @return Nip_Form_Button_Abstract |
|
89 | 92 | */ |
90 | 93 | public function addAttribs(array $attribs) { |
91 | 94 | foreach ($attribs as $key => $value) { |
@@ -96,13 +99,18 @@ discard block |
||
96 | 99 | |
97 | 100 | /** |
98 | 101 | * @param array $attribs |
99 | - * @return Nip_Form_Element_Abstract |
|
102 | + * @return Nip_Form_Button_Abstract |
|
100 | 103 | */ |
101 | 104 | public function setAttribs(array $attribs) { |
102 | 105 | $this->clearAttribs(); |
103 | 106 | return $this->addAttribs($attribs); |
104 | 107 | } |
105 | 108 | |
109 | + /** |
|
110 | + * @param string $key |
|
111 | + * |
|
112 | + * @return string |
|
113 | + */ |
|
106 | 114 | public function getAttrib($key) { |
107 | 115 | $key = (string) $key; |
108 | 116 | if (!isset($this->_attribs[$key])) { |
@@ -136,7 +144,7 @@ discard block |
||
136 | 144 | } |
137 | 145 | |
138 | 146 | /** |
139 | - * @return Nip_Form_Element_Abstract |
|
147 | + * @return Nip_Form_Button_Abstract |
|
140 | 148 | */ |
141 | 149 | public function clearAttribs() { |
142 | 150 | $this->_attribs = array(); |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | } |
14 | 14 | |
15 | 15 | public function init() { |
16 | - $this->addClass('btn','btn-primary'); |
|
16 | + $this->addClass('btn', 'btn-primary'); |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | public function setId($id) { |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | /** |
78 | 78 | * @return Nip_Form_Element_Abstract |
79 | 79 | */ |
80 | - public function setAttrib($key, $value) { |
|
80 | + public function setAttrib($key, $value) { |
|
81 | 81 | $key = (string) $key; |
82 | 82 | $this->_attribs[$key] = $value; |
83 | 83 | return $this; |