Skip to content
Snippets Groups Projects
LanguageModel.php 1.34 KiB
Newer Older
  • Learn to ignore specific revisions
  • /**
     * @copyright  2020 Podlibre
     * @license    https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
     * @link       https://castopod.org/
     */
    
    use CodeIgniter\Model;
    
    class LanguageModel extends Model
    {
    
        protected $table = 'languages';
    
        protected $primaryKey = 'id';
    
    
        protected $allowedFields = ['code', 'native_name'];
    
        /**
         * @var string
         */
        protected $returnType = Language::class;
    
        protected $useSoftDeletes = false;
    
    
        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;
                    },
    
                cache()
                    ->save('language_options', $options, DECADE);