From 3528a56399dbb8cd37b8dcdaa207dab26edd7eee Mon Sep 17 00:00:00 2001 From: Lucas Porto Date: Tue, 24 Feb 2015 10:02:32 -0300 Subject: [PATCH 1/4] Class Controller Application controller --- Exe2/ConsumptionController.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Exe2/ConsumptionController.php diff --git a/Exe2/ConsumptionController.php b/Exe2/ConsumptionController.php new file mode 100644 index 0000000..878a3e2 --- /dev/null +++ b/Exe2/ConsumptionController.php @@ -0,0 +1,34 @@ + + */ +class ConsumptionController { + private $model; + + /** + * + * Contructor + * + */ + public function __construct($model) { + $this->model = $model; + } + + /** + * + * Exec calc the consuption + * + * @param array $request Form's informations + */ + public function calc($request) { + if (isset($request['fuelQtd']) && isset($request['milesQtd'])) { + $this->model->set($request['fuelQtd'], $request['milesQtd']); + } + } +} +?> \ No newline at end of file From 53c101fe4ff0b4e689a562669174e942c7496104 Mon Sep 17 00:00:00 2001 From: Lucas Porto Date: Tue, 24 Feb 2015 10:04:22 -0300 Subject: [PATCH 2/4] Class Model Application Model --- Exe2/ConsumptionModel.php | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Exe2/ConsumptionModel.php diff --git a/Exe2/ConsumptionModel.php b/Exe2/ConsumptionModel.php new file mode 100644 index 0000000..dab7943 --- /dev/null +++ b/Exe2/ConsumptionModel.php @@ -0,0 +1,37 @@ + + */ +class ConsumptionModel { + private $milesQtd = 0; + private $fuelQtd = 0; + + /** + * + * Get Fuel Consuption + * + * @return float Fuel Consumption + */ + public function get() { + return round($this->milesQtd / $this->fuelQtd, 2); + } + + /** + * + * Set parameters values to calc the consuption + * + * @param float $fuelQtd Qtd Fuel + * @param float $milesQtd Qtd Miles + */ + public function set($fuelQtd, $milesQtd) { + $this->fuelQtd = $fuelQtd; + $this->milesQtd = $milesQtd; + } + +} +?> \ No newline at end of file From 9466caa919de8dade0434c35c722365bd2bad433 Mon Sep 17 00:00:00 2001 From: Lucas Porto Date: Tue, 24 Feb 2015 10:04:48 -0300 Subject: [PATCH 3/4] Class View Application View --- Exe2/ConsumptionView.php | 43 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Exe2/ConsumptionView.php diff --git a/Exe2/ConsumptionView.php b/Exe2/ConsumptionView.php new file mode 100644 index 0000000..4afd522 --- /dev/null +++ b/Exe2/ConsumptionView.php @@ -0,0 +1,43 @@ + + */ +class ConsumptionView { + private $calc; + + /** + * + * Contructor + * + */ + public function __construct(ConsumptionModel $calc) { + $this->calc = $calc; + } + + + /** + * + * Output + * + * @return HTML - form and fields + */ + public function output() { + $html = '
+ +
+ +
+ +
+ +
'; + + return $html; + } +} +?> \ No newline at end of file From e0aa5445edc13840cf52c473bcf0c0f0a6aecf24 Mon Sep 17 00:00:00 2001 From: Lucas Porto Date: Tue, 24 Feb 2015 10:05:10 -0300 Subject: [PATCH 4/4] Application Main application fuel consumption. --- Exe2/index.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Exe2/index.php diff --git a/Exe2/index.php b/Exe2/index.php new file mode 100644 index 0000000..58c723f --- /dev/null +++ b/Exe2/index.php @@ -0,0 +1,15 @@ +{$_GET['action']}($_POST); + +$gallonView = new ConsumptionView($model); + +echo $gallonView->output(); +?> \ No newline at end of file