<?php

namespace Ministra\Lib;

use Ministra\Lib\bd5c9022e9a9029209e5fd05775ea272\B4291b8d8fa2d898727b1f446db1e661e;
use Ministra\Lib\bd5c9022e9a9029209e5fd05775ea272\bcb5276dcc10d28aee463111bf6dfaa1;
class VideoCategory
{
    private $language;
    public function setLocale($language)
    {
        $this->language = $language;
        \Ministra\Lib\bd5c9022e9a9029209e5fd05775ea272\bcb5276dcc10d28aee463111bf6dfaa1::getInstance()->bee6d7e4182de9ac66296efe779be679($this->language);
    }
    public function getById($id, $pretty_id = false)
    {
        if ($pretty_id) {
            $categories = $this->getAll($pretty_id);
            $categories = \array_filter($categories, function ($category) use($id) {
                return $id == $category['id'];
            });
            if (empty($categories)) {
                return;
            }
            $categories = \array_values($categories);
            $category = \Ministra\Lib\bd5c9022e9a9029209e5fd05775ea272\B4291b8d8fa2d898727b1f446db1e661e::getInstance()->from('media_category')->where(['category_name' => $categories[0]['original_title']])->get()->first();
            if (!empty($category)) {
                $category['id'] = $id;
            }
            return $category;
        }
        return \Ministra\Lib\bd5c9022e9a9029209e5fd05775ea272\B4291b8d8fa2d898727b1f446db1e661e::getInstance()->from('media_category')->where(['id' => (int) $id])->get()->first();
    }
    public function getAll($pretty_id = false)
    {
        $categories = \Ministra\Lib\bd5c9022e9a9029209e5fd05775ea272\B4291b8d8fa2d898727b1f446db1e661e::getInstance()->from('media_category')->orderby('num')->get()->all();
        $categories = \array_map(function ($item) use($pretty_id) {
            if ($pretty_id) {
                $item['id'] = \preg_replace('/_/i', '-', $item['category_alias']);
            }
            $item['original_title'] = $item['category_name'];
            $item['title'] = \_($item['category_name']);
            $item['censored'] = (bool) $item['censored'];
            return $item;
        }, $categories);
        return $categories;
    }
}
