2020-05-31 19:15:52 +00:00
|
|
|
<?php
|
2020-08-04 11:25:22 +00:00
|
|
|
|
2020-06-10 15:00:12 +00:00
|
|
|
/**
|
|
|
|
* @copyright 2020 Podlibre
|
|
|
|
* @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;
|
|
|
|
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
|
|
|
|
class LanguageModel extends Model
|
|
|
|
{
|
|
|
|
protected $table = 'languages';
|
|
|
|
protected $primaryKey = 'id';
|
|
|
|
|
2020-06-10 15:00:12 +00:00
|
|
|
protected $allowedFields = ['code', 'native_name'];
|
2020-05-31 19:15:52 +00:00
|
|
|
|
2020-08-04 11:25:22 +00:00
|
|
|
protected $returnType = \App\Entities\Language::class;
|
2020-05-31 19:15:52 +00:00
|
|
|
protected $useSoftDeletes = false;
|
|
|
|
|
|
|
|
protected $useTimestamps = false;
|
2020-09-04 09:09:26 +00:00
|
|
|
|
|
|
|
public function getLanguageOptions()
|
|
|
|
{
|
|
|
|
if (!($options = cache('language_options'))) {
|
|
|
|
$languages = $this->findAll();
|
|
|
|
|
|
|
|
$options = array_reduce(
|
|
|
|
$languages,
|
|
|
|
function ($result, $language) {
|
|
|
|
$result[$language->code] = $language->native_name;
|
|
|
|
return $result;
|
|
|
|
},
|
|
|
|
[]
|
|
|
|
);
|
|
|
|
|
|
|
|
cache()->save('language_options', $options, DECADE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $options;
|
|
|
|
}
|
2020-05-31 19:15:52 +00:00
|
|
|
}
|