Subversion Repositories eFlore/Applications.cel

Rev

Rev 1015 | Rev 1920 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1015 Rev 1628
Line 152... Line 152...
152
					if (file_exists($resource_file)) {
152
					if (file_exists($resource_file)) {
153
						include_once $resource_file;
153
						include_once $resource_file;
154
						if (class_exists($resource_class)) {
154
						if (class_exists($resource_class)) {
155
							$service = new $resource_class($this->config);
155
							$service = new $resource_class($this->config);
156
							if (method_exists($service,'updateElement')) { // Update element
156
							if (method_exists($service,'updateElement')) { // Update element
-
 
157
								$ret_value = false;
-
 
158
								try {
157
								// TODO : a voir le retour ...
159
									// TODO : a voir le retour ...
158
								if ($service->updateElement($this->uid, $pairs)) {
160
									$ret_value = $service->updateElement($this->uid, $pairs);
-
 
161
									if($ret_value) $this->created();
-
 
162
									else $this->badRequest();
-
 
163
								} catch (Exception $e) {
159
									$this->created();
164
									$this->badRequest($e);
160
								}
165
								}
161
							}
166
							}
162
						}
167
						}
163
					}
168
					}
164
				} else { // get all elements of a ressource
169
				} else { // get all elements of a ressource
Line 204... Line 209...
204
			if (file_exists($resource_file)) {
209
			if (file_exists($resource_file)) {
205
				include_once $resource_file;
210
				include_once $resource_file;
206
				if (class_exists($resource_class)) {
211
				if (class_exists($resource_class)) {
207
					$service = new $resource_class($this->config);
212
					$service = new $resource_class($this->config);
208
					if (method_exists($service,'createElement')) { // Create a new element
213
					if (method_exists($service,'createElement')) { // Create a new element
-
 
214
						$ret_value = false;
-
 
215
						try {
209
						if ($service->createElement($pairs)) {
216
							$ret_value = $service->createElement($pairs);
-
 
217
							if($ret_value) $this->created();
-
 
218
							else $this->badRequest();
-
 
219
						} catch (Exception $e) {
210
							$this->created();
220
							$this->badRequest($e);
211
						}
221
						}
212
					}
222
					}
213
				}
223
				}
214
			}
224
			}
215
		} else {
225
		} else {
Line 252... Line 262...
252
	}
262
	}
Line 253... Line 263...
253
 
263
 
254
	/**
264
	/**
255
	 * Send a HTTP 400 response header.
265
	 * Send a HTTP 400 response header.
256
	 */
266
	 */
257
	private function badRequest() {
267
	private function badRequest(Exception $e = NULL) {
-
 
268
		header('HTTP/1.0 400 Bad Request');
258
		header('HTTP/1.0 400 Bad Request');
269
		if($e) echo $e->getMessage();
Line 259... Line 270...
259
	}
270
	}
260
 
271
 
261
	/**
272
	/**