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