2014-11-02 14:58:12 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace FireflyIII\Shared\Toolkit;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class Form
|
|
|
|
|
*
|
|
|
|
|
* @package FireflyIII\Shared\Toolkit
|
|
|
|
|
*/
|
2014-11-12 22:37:09 +01:00
|
|
|
class Form
|
|
|
|
|
{
|
2014-11-02 14:58:12 +01:00
|
|
|
/**
|
|
|
|
|
* Takes any collection and tries to make a sensible select list compatible array of it.
|
|
|
|
|
*
|
2014-12-25 08:07:17 +01:00
|
|
|
* @param \Illuminate\Support\Collection $set
|
|
|
|
|
* @param bool $addEmpty
|
2014-11-02 14:58:12 +01:00
|
|
|
*
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
2014-12-25 08:07:17 +01:00
|
|
|
public function makeSelectList(\Illuminate\Support\Collection $set, $addEmpty = false)
|
2014-11-02 14:58:12 +01:00
|
|
|
{
|
|
|
|
|
$selectList = [];
|
2014-12-14 20:40:02 +01:00
|
|
|
if ($addEmpty) {
|
|
|
|
|
$selectList[0] = '(none)';
|
|
|
|
|
}
|
|
|
|
|
$fields = ['title', 'name', 'description'];
|
|
|
|
|
/** @var \Eloquent $entry */
|
2014-11-02 14:58:12 +01:00
|
|
|
foreach ($set as $entry) {
|
|
|
|
|
$id = intval($entry->id);
|
2014-12-15 18:16:48 +01:00
|
|
|
$title = null;
|
2014-11-02 14:58:12 +01:00
|
|
|
|
2014-12-14 20:40:02 +01:00
|
|
|
foreach ($fields as $field) {
|
|
|
|
|
if (is_null($title) && isset($entry->$field)) {
|
|
|
|
|
$title = $entry->$field;
|
2014-11-02 14:58:12 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$selectList[$id] = $title;
|
|
|
|
|
}
|
2014-11-12 22:37:09 +01:00
|
|
|
|
2014-12-14 20:40:02 +01:00
|
|
|
|
2014-11-02 14:58:12 +01:00
|
|
|
return $selectList;
|
|
|
|
|
}
|
2014-12-14 20:40:02 +01:00
|
|
|
}
|