2020-05-31 19:15:52 +00:00
|
|
|
<?php
|
2020-08-04 11:25:22 +00:00
|
|
|
|
2021-06-08 09:52:11 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2020-06-10 15:00:12 +00:00
|
|
|
/**
|
2022-02-19 16:06:11 +00:00
|
|
|
* @copyright 2020 Ad Aures
|
2020-06-10 15:00:12 +00:00
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
2020-05-31 19:15:52 +00:00
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
use App\Entities\Language;
|
2020-05-31 19:15:52 +00:00
|
|
|
use CodeIgniter\Model;
|
|
|
|
|
|
|
|
class LanguageModel extends Model
|
|
|
|
{
|
2021-05-06 14:00:48 +00:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
2020-05-31 19:15:52 +00:00
|
|
|
protected $table = 'languages';
|
2021-05-19 16:35:13 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
2020-05-31 19:15:52 +00:00
|
|
|
protected $primaryKey = 'id';
|
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
/**
|
2024-04-26 09:26:22 +00:00
|
|
|
* @var list<string>
|
2021-05-06 14:00:48 +00:00
|
|
|
*/
|
2020-06-10 15:00:12 +00:00
|
|
|
protected $allowedFields = ['code', 'native_name'];
|
2020-05-31 19:15:52 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $returnType = Language::class;
|
2021-05-19 16:35:13 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
2020-05-31 19:15:52 +00:00
|
|
|
protected $useSoftDeletes = false;
|
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
2020-05-31 19:15:52 +00:00
|
|
|
protected $useTimestamps = false;
|
2020-09-04 09:09:26 +00:00
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
/**
|
|
|
|
* @return array<string, string>
|
|
|
|
*/
|
|
|
|
public function getLanguageOptions(): array
|
2020-09-04 09:09:26 +00:00
|
|
|
{
|
2021-05-19 16:35:13 +00:00
|
|
|
if (! ($options = cache('language_options'))) {
|
2020-09-04 09:09:26 +00:00
|
|
|
$languages = $this->findAll();
|
|
|
|
|
|
|
|
$options = array_reduce(
|
|
|
|
$languages,
|
2022-09-28 14:00:05 +00:00
|
|
|
static function (array $result, Language $language): array {
|
2024-05-12 18:38:33 +00:00
|
|
|
$result[] = [
|
|
|
|
'value' => $language->code,
|
|
|
|
'label' => $language->native_name,
|
|
|
|
];
|
2020-09-04 09:09:26 +00:00
|
|
|
return $result;
|
|
|
|
},
|
2021-05-06 14:00:48 +00:00
|
|
|
[],
|
2020-09-04 09:09:26 +00:00
|
|
|
);
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
cache()
|
|
|
|
->save('language_options', $options, DECADE);
|
2020-09-04 09:09:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $options;
|
|
|
|
}
|
2020-05-31 19:15:52 +00:00
|
|
|
}
|