mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-01-08 07:03:23 -06:00
44 lines
1.0 KiB
PHP
44 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace FireflyIII\Shared\Toolkit;
|
|
|
|
|
|
/**
|
|
* Class Form
|
|
*
|
|
* @package FireflyIII\Shared\Toolkit
|
|
*/
|
|
class Form
|
|
{
|
|
/**
|
|
* Takes any collection and tries to make a sensible select list compatible array of it.
|
|
*
|
|
* @param \Illuminate\Support\Collection $set
|
|
* @param bool $addEmpty
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function makeSelectList(\Illuminate\Support\Collection $set, $addEmpty = false)
|
|
{
|
|
$selectList = [];
|
|
if ($addEmpty) {
|
|
$selectList[0] = '(none)';
|
|
}
|
|
$fields = ['title', 'name', 'description'];
|
|
/** @var \Eloquent $entry */
|
|
foreach ($set as $entry) {
|
|
$id = intval($entry->id);
|
|
$title = null;
|
|
|
|
foreach ($fields as $field) {
|
|
if (is_null($title) && isset($entry->$field)) {
|
|
$title = $entry->$field;
|
|
}
|
|
}
|
|
$selectList[$id] = $title;
|
|
}
|
|
|
|
|
|
return $selectList;
|
|
}
|
|
} |