Newer
Older

Yassine Doghri
committed

Yassine Doghri
committed
declare(strict_types=1);
/**
* @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/
*/

Yassine Doghri
committed
use App\Entities\Language;
use CodeIgniter\Model;
class LanguageModel extends Model
{

Yassine Doghri
committed
/**
* @var string
*/
protected $table = 'languages';

Yassine Doghri
committed
/**
* @var string
*/
protected $primaryKey = 'id';

Yassine Doghri
committed
/**
* @var string[]
*/
protected $allowedFields = ['code', 'native_name'];

Yassine Doghri
committed
/**
* @var string
*/
protected $returnType = Language::class;

Yassine Doghri
committed
/**
* @var bool
*/
protected $useSoftDeletes = false;

Yassine Doghri
committed
/**
* @var bool
*/
protected $useTimestamps = false;
/**
* @return array<string, string>
*/
public function getLanguageOptions(): array
if (! ($options = cache('language_options'))) {
$languages = $this->findAll();
$options = array_reduce(
$languages,
function (array $result, Language $language): array {
$result[$language->code] = $language->native_name;
return $result;
},

Yassine Doghri
committed
[],
);
cache()
->save('language_options', $options, DECADE);
}
return $options;
}