Skip to content

Commit

Permalink
fixed max inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
microlancer committed Jul 30, 2017
1 parent cbb0e60 commit 98aa5c9
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 41 deletions.
1 change: 1 addition & 0 deletions app/Model/Constants/DefaultInput.php
Expand Up @@ -5,6 +5,7 @@
class DefaultInput
{
const MIN_AMOUNT = 0.01;
const MAX_AMOUNT = 9999999;
const AMOUNT = '20.00';
const FREQUENCY = 'week';
const MONTH = 'January';
Expand Down
6 changes: 5 additions & 1 deletion app/Model/Form/Calculator.php
Expand Up @@ -22,7 +22,11 @@ public function getSanitizedInputs(HttpParams $params)
$amount = sprintf("%.2f", $params->get('amount', DefaultInput::AMOUNT));

if ($amount < DefaultInput::MIN_AMOUNT) {
$amount = DefaultInput::AMOUNT;
$amount = DefaultInput::MIN_AMOUNT;
}

if ($amount > DefaultInput::MAX_AMOUNT) {
$amount = DefaultInput::MAX_AMOUNT;
}

$freq = $params->get('freq', DefaultInput::FREQUENCY);
Expand Down
4 changes: 2 additions & 2 deletions app/Util/View.php
Expand Up @@ -7,12 +7,12 @@ class View

public function addVars(array $vars)
{
$this->vars += $vars;
$this->vars = array_merge($this->vars, $vars);
}

public function render($view, $vars = [])
{
$vars = $this->vars + $vars;
$vars = array_merge($this->vars, $vars);
include __DIR__ . '/../View/' . $view . '.phtml';
}
}
90 changes: 52 additions & 38 deletions app/View/index.phtml
@@ -1,59 +1,73 @@
<?php include('header.phtml'); ?>

<?php

?>
<h1><a href='/calculator' style=''><img src="<?=$vars['baseUrl']?>/images/bitcoin.png" width='35' style='margin-bottom:5px'></a> Bitcoin Savings Calculator</h1>

<h1>
<a href='/calculator' style=''>
<img src="<?=$vars['baseUrl']?>/images/bitcoin.png" width='35' style='margin-bottom:5px'>
</a>
Bitcoin Savings Calculator
</h1>

<h3>Savings Plan</h3>

<form method='get' class="form-inline">

What if I saved

What if I saved
$ <input class="form-control" style="width:100px" type='text' value='<?=$vars['amount']?>' size='6' name='amount'>
as bitcoin every
<select name='freq' class="form-control" style="width:90px">
<?php foreach ($vars['frequencies'] as $freqOption) { ?>
<option <?=($vars['freq'] == $freqOption ? 'selected="true"' : '')?>"><?=$freqOption?></option>
<?php } ?>
</select>
starting on
<select name='month' style="width:120px" class="form-control">
<?php foreach ($vars['months'] as $monthOption) { ?>
<option <?=($vars['month'] == $monthOption ? 'selected="true"' : '')?>"><?=$monthOption?></option>
<?php } ?>
</select>
<input name='day' type='text' size='4' value='<?=$vars['day']?>' style="width:45px" class="form-control"></input>,
<select name='year' style="width:90px" class="form-control">
<?php foreach ($vars['years'] as $yearOption) { ?>
<option <?=($vars['year'] == $yearOption ? 'selected="true"' : '')?>"><?=$yearOption?></option>
<?php } ?>
</select>
?

<button type='submit' class='btn btn-primary' value='Calculate'>Calculate</button>
<select name='freq' class="form-control" style="width:90px">
<?php foreach ($vars['frequencies'] as $freqOption) { ?>
<option <?=($vars['freq'] == $freqOption ? 'selected="true"' : '')?>"><?=$freqOption?></option>
<?php } ?>
</select>
starting on
<select name='month' style="width:120px" class="form-control">
<?php foreach ($vars['months'] as $monthOption) { ?>
<option <?=($vars['month'] == $monthOption ? 'selected="true"' : '')?>"><?=$monthOption?></option>
<?php } ?>
</select>
<input name='day' type='text' size='4' value='<?=$vars['day']?>' style="width:45px" class="form-control"></input>,
<select name='year' style="width:90px" class="form-control">
<?php foreach ($vars['years'] as $yearOption) { ?>
<option <?=($vars['year'] == $yearOption ? 'selected="true"' : '')?>"><?=$yearOption?></option>
<?php } ?>
</select>
?

<button type='submit' class='btn btn-primary' value='Calculate'>Calculate</button>
</form>

<h3>Results</h3>

<div class="alert alert-success lead" role="alert">
I would have <b><?=number_format($vars['totalCoins'], 4);?></b> bitcoin worth <b>$<?=number_format($vars['totalValue'], 2);?></b> today.
I would have <b><?=number_format($vars['totalCoins'], 4);?></b> bitcoin
worth <b>$<?=number_format($vars['totalValue'], 2);?></b> today.
</div>

<table class="table">
<tr style='background-color:lightblue;font-weight:bold'><td>Date</td><td>Spent So Far</td><td>Amount of Bitcoin I Own</td><td>Value of My Savings</td></tr>
<?php foreach ($vars['results'] as $result) { ?>
<tr>
<td><?=$result['dateCasual']?></td>
<td>$<?=number_format($result['totalSpent'], 2);?></td>
<td><?=number_format($result['totalCoins'], 4);?></td>
<td>$<?=number_format($result['totalValue'], 2);?></td></tr>
<?php } ?>
<tr style='background-color:lightblue;font-weight:bold'>
<td>Date</td>
<td>Spent So Far</td>
<td>Amount of Bitcoin I Own</td>
<td>Value of My Savings</td>
</tr>
<?php foreach ($vars['results'] as $result) { ?>
<tr>
<td><?=$result['dateCasual']?></td>
<td>$<?=number_format($result['totalSpent'], 2);?></td>
<td><?=number_format($result['totalCoins'], 4);?></td>
<td>$<?=number_format($result['totalValue'], 2);?></td>
</tr>
<?php } ?>
</table>

<p><i>*Note: Does not include transaction fees. All calculations rounded. Price data from CoinDesk API.</i></p>
<p><a href='https://github.com/thorie7912/bitcoin-calculator'>Help improve this calculator on GitHub!</a></p>
<p>
<i>*Note: Does not include transaction fees. All calculations rounded. Price data from CoinDesk API.</i>
</p>

<p>
<a href='https://github.com/thorie7912/bitcoin-calculator'>
Help improve this calculator on GitHub!
</a>
</p>

<?php include('footer.phtml'); ?>

0 comments on commit 98aa5c9

Please sign in to comment.