Various code cleanup.

This commit is contained in:
James Cole
2016-04-27 19:21:47 +02:00
parent 84f299c33b
commit e3437ba697
9 changed files with 154 additions and 107 deletions

View File

@@ -20,31 +20,6 @@ use Session;
class ExpandedForm
{
/**
* @param $name
* @param null $value
* @param array $options
*
* @return string
*/
public function amountSmall(string $name, $value = null, array $options = []): string
{
$label = $this->label($name, $options);
$options = $this->expandOptionArray($name, $label, $options);
$classes = $this->getHolderClasses($name);
$value = $this->fillFieldValue($name, $value);
$options['step'] = 'any';
$options['min'] = '0.01';
$defaultCurrency = isset($options['currency']) ? $options['currency'] : Amt::getDefaultCurrency();
$currencies = Amt::getAllCurrencies();
unset($options['currency']);
unset($options['placeholder']);
$html = view('form.amount-small', compact('defaultCurrency', 'currencies', 'classes', 'name', 'value', 'options'))->render();
return $html;
}
/**
* @param $name
* @param null $value
@@ -70,6 +45,31 @@ class ExpandedForm
}
/**
* @param $name
* @param null $value
* @param array $options
*
* @return string
*/
public function amountSmall(string $name, $value = null, array $options = []): string
{
$label = $this->label($name, $options);
$options = $this->expandOptionArray($name, $label, $options);
$classes = $this->getHolderClasses($name);
$value = $this->fillFieldValue($name, $value);
$options['step'] = 'any';
$options['min'] = '0.01';
$defaultCurrency = isset($options['currency']) ? $options['currency'] : Amt::getDefaultCurrency();
$currencies = Amt::getAllCurrencies();
unset($options['currency']);
unset($options['placeholder']);
$html = view('form.amount-small', compact('defaultCurrency', 'currencies', 'classes', 'name', 'value', 'options'))->render();
return $html;
}
/**
* @param $name
* @param null $value
@@ -196,17 +196,38 @@ class ExpandedForm
* Takes any collection and tries to make a sensible select list compatible array of it.
*
* @param \Illuminate\Support\Collection $set
* @param bool $addEmpty
*
* @return array
*/
public function makeSelectList(Collection $set, bool $addEmpty = false): array
public function makeSelectList(Collection $set): array
{
$selectList = [];
if ($addEmpty) {
$selectList[0] = '(none)';
$fields = ['title', 'name', 'description'];
/** @var Eloquent $entry */
foreach ($set as $entry) {
$entryId = intval($entry->id);
$title = null;
foreach ($fields as $field) {
if (isset($entry->$field) && is_null($title)) {
$title = $entry->$field;
}
}
$selectList[$entryId] = $title;
}
$fields = ['title', 'name', 'description'];
return $selectList;
}
/**
* @param Collection $set
*
* @return array
*/
public function makeSelectListWithEmpty(Collection $set): array
{
$selectList[0] = '(none)';
$fields = ['title', 'name', 'description'];
/** @var Eloquent $entry */
foreach ($set as $entry) {
$entryId = intval($entry->id);