<commit_before><?php
defined('BASEPATH') OR exit('No direct script access allowed');

use Symfony\Component\HttpFoundation\Request;

use Nurmanhabib\WilayahIndonesia\Sources\DatabaseSource;

class Dashboard extends Admin {

    public function __construct()
    {
        parent::__construct();
        
        $this->load->helper('article');
        $this->load->model('Mod_user', 'model');
        $this->load->model('Mod_sendarticle');
        $this->load->model('category/Mod_category');

        $this->status = array(
            'publish'   => 'Publish',
            'draft'     => 'Draft',
        );

        $this->type = array(
            'public'        => 'Public',
            'private'       => 'Private',
        );
        
        $this->load->library('WilayahIndonesia', null, 'wilayah');

        $hostname = getenv('AUTH_DB_HOST') ?: 'localhost';
        $username = getenv('AUTH_DB_USERNAME') ?: 'root';
        $password = getenv('AUTH_DB_PASSWORD') ?: '';
        $database = getenv('AUTH_DB_DATABASE') ?: 'portal_learning';

        $source = new DatabaseSource($hostname, $username, $password, $database);
        $this->wilayah->setSource($source);
    }

    public function index()
    {
        $user       = auth()->getUser();
        $request    = Request::createFromGlobals();
        $articles   = Model\Portal\Article::published()
                        ->contributor($user->id)
                        ->latest('date')
                        ->get();

        $drafts     = Model\Portal\Article::onlyDrafts()
                        ->contributor($user->id)
                        ->latest('date')
                        ->get();

        $data['artikel']    = pagination($articles, 4, 'dashboard');
        $data['drafts']     = pagination($drafts, 4, 'dashboard');
        $data['links']      = $this->Mod_link->read();
        
        $this->template->set('sidebar');
        $this->template->set_layout('privatepage');              
        $this->template->build('index', $data);
    }

    public function article()
    {
        $cat_slider = config('privatepage_slider');
        $cat_1      = config('privatepage_category_1');
        $cat_2      = config('privatepage_category_2');
        $cat_3      = config('privatepage_category_3');
        $cat_4      = config('privatepage_category_4');

        $privatepage_slider_title      = Model\Portal\Category::find($cat_slider);
        $privatepage_slider            = Model\Portal\Article::categoryId($cat_slider);

        $privatepage_category_1_title  = Model\Portal\Category::find($cat_1);
        $privatepage_category_1_a      = Model\Portal\Article::onlyRegistered()->categoryId($cat_1)->take(3)->latest('date');
        $privatepage_category_1_b      = Model\Portal\Article::onlyRegistered()->categoryId($cat_1)->take(3)->skip(2)->latest('date');

        $privatepage_category_2_title  = Model\Portal\Category::find($cat_2);
        $privatepage_category_2_a      = Model\Portal\Article::onlyRegistered()->categoryId($cat_2)->take(3)->latest('date');
        $privatepage_category_2_b      = Model\Portal\Article::onlyRegistered()->categoryId($cat_2)->take(3)->skip(2)->latest('date');

        $privatepage_category_3_title  = Model\Portal\Category::find($cat_3);
        $privatepage_category_3_a      = Model\Portal\Article::onlyRegistered()->categoryId($cat_3)->take(3)->latest('date');
        $privatepage_category_3_b      = Model\Portal\Article::onlyRegistered()->categoryId($cat_3)->take(3)->skip(2)->latest('date');

        $privatepage_category_4_title  = Model\Portal\Category::find($cat_4);
        $privatepage_category_4_a      = Model\Portal\Article::onlyRegistered()->categoryId($cat_4)->take(3)->latest('date');
        $privatepage_category_4_b      = Model\Portal\Article::onlyRegistered()->categoryId($cat_4)->take(3)->skip(2)->latest('date');

        $data = array(
            'privatepage_slider_title'      => $privatepage_slider_title ? $privatepage_slider_title->name : '',
            'privatepage_slider'            => $privatepage_slider->count() ? $privatepage_slider->take(9)->latest('date')->get() : collect([]),

            'privatepage_category_1_title'  => $privatepage_category_1_title ? $privatepage_category_1_title->name : 'No Category',
            'privatepage_category_1_a'      => $privatepage_category_1_a->count() ? $privatepage_category_1_a->get() : collect([]),
            'privatepage_category_1_b'      => $privatepage_category_1_b->count() ? $privatepage_category_1_a->get() : collect([]),

            'privatepage_category_2_title'  => $privatepage_category_2_title ? $privatepage_category_2_title->name : 'No Category',
            'privatepage_category_2_a'      => $privatepage_category_2_a->count() ? $privatepage_category_2_a->get() : collect([]),
            'privatepage_category_2_b'      => $privatepage_category_2_b->count() ? $privatepage_category_2_b->get() : collect([]),

            'privatepage_category_3_title'  => $privatepage_category_3_title ? $privatepage_category_3_title->name : 'No Category',
            'privatepage_category_3_a'      => $privatepage_category_3_a->count() ? $privatepage_category_3_a->get() : collect([]),
            'privatepage_category_3_b'      => $privatepage_category_3_b->count() ? $privatepage_category_3_b->get() : collect([]),

            'privatepage_category_4_title'  => $privatepage_category_4_title ? $privatepage_category_4_title->name : 'No Category',
            'privatepage_category_4_a'      => $privatepage_category_4_a->count() ? $privatepage_category_4_a->get() : collect([]),
            'privatepage_category_4_b'      => $privatepage_category_4_b->count() ? $privatepage_category_4_b->get() : collect([]),

            'links'                         => $this->Mod_link->read(),
        );

        $latests    = Model\Portal\Article::registered()->latest('date')
                        ->limit(15)
                        ->get();
        $data['latest']     = $latests;
        $this->template->set('active', 'artikel');
        $this->template->set('sidebar', FALSE);
        $this->template->set_layout('privatepage');            
        $this->template->build('articlePrivate', $data);
    }

    public function sendArticle()
    {
        $this->form_validation->set_rules('title', 'Title', 'required');
        $this->form_validation->set_rules('content', 'Content', 'required');

        if ($this->form_validation->run() == FALSE) {
            $data['categories_checkbox']    = $this->Mod_category->generateCheckbox();
            $data['status'] = $this->status;

            $this->template->set('sidebar');            
            $this->template->set_layout('privatepage');
            $this->template->build('create', $data);
        } else {
            $data   = array(
                'title'             => set_value('title'),
                'content'           => $this->input->post('content'),
                'contributor_id'    => auth()->getUser()->id,
            );

            $categories = set_value('categories', array());
            $status     = set_value('status', 'draft');
            $type       = set_value('type', 'private');

            if (isset($_FILES['featured']) && $_FILES['featured']['tmp_name']) {
                $featured_image = $_FILES['featured'];
            } else {
                $featured_image = null;
            }

            $id = $this->Mod_sendarticle->send($data, $status, $type, $featured_image, $categories);

            set_message_success('Artikel berhasil dibuat.');<commit_msg>Add set active to dashboard. Add custom-tiny<commit_after><?php
defined('BASEPATH') OR exit('No direct script access allowed');

use Symfony\Component\HttpFoundation\Request;

use Nurmanhabib\WilayahIndonesia\Sources\DatabaseSource;

class Dashboard extends Admin {

    public function __construct()
    {
        parent::__construct();
        
        $this->load->helper('article');
        $this->load->model('Mod_user', 'model');
        $this->load->model('Mod_sendarticle');
        $this->load->model('category/Mod_category');

        $this->template->set('active', 'dashboard');
        $this->template->add_script('javascript/custom-tiny.js');

        $this->status = array(
            'publish'   => 'Publish',
            'draft'     => 'Draft',
        );

        $this->type = array(
            'public'        => 'Public',
            'private'       => 'Private',
        );
        
        $this->load->library('WilayahIndonesia', null, 'wilayah');

        $hostname = getenv('AUTH_DB_HOST') ?: 'localhost';
        $username = getenv('AUTH_DB_USERNAME') ?: 'root';
        $password = getenv('<PASSWORD>_DB_PASSWORD') ?: '';
        $database = getenv('AUTH_DB_DATABASE') ?: 'portal_learning';

        $source = new DatabaseSource($hostname, $username, $password, $database);
        $this->wilayah->setSource($source);
    }

    public function index()
    {
        $user       = auth()->getUser();
        $request    = Request::createFromGlobals();
        $articles   = Model\Portal\Article::published()
                        ->contributor($user->id)
                        ->latest('date')
                        ->get();

        $drafts     = Model\Portal\Article::onlyDrafts()
                        ->contributor($user->id)
                        ->latest('date')
                        ->get();

        $data['artikel']    = pagination($articles, 4, 'dashboard');
        $data['drafts']     = pagination($drafts, 4, 'dashboard');
        $data['links']      = $this->Mod_link->read();
        
        $this->template->set('sidebar');
        $this->template->set_layout('privatepage');              
        $this->template->build('index', $data);
    }

    public function article()
    {
        $cat_slider = config('privatepage_slider');
        $cat_1      = config('privatepage_category_1');
        $cat_2      = config('privatepage_category_2');
        $cat_3      = config('privatepage_category_3');
        $cat_4      = config('privatepage_category_4');

        $privatepage_slider_title      = Model\Portal\Category::find($cat_slider);
        $privatepage_slider            = Model\Portal\Article::categoryId($cat_slider);

        $privatepage_category_1_title  = Model\Portal\Category::find($cat_1);
        $privatepage_category_1_a      = Model\Portal\Article::onlyRegistered()->categoryId($cat_1)->take(3)->latest('date');
        $privatepage_category_1_b      = Model\Portal\Article::onlyRegistered()->categoryId($cat_1)->take(3)->skip(2)->latest('date');

        $privatepage_category_2_title  = Model\Portal\Category::find($cat_2);
        $privatepage_category_2_a      = Model\Portal\Article::onlyRegistered()->categoryId($cat_2)->take(3)->latest('date');
        $privatepage_category_2_b      = Model\Portal\Article::onlyRegistered()->categoryId($cat_2)->take(3)->skip(2)->latest('date');

        $privatepage_category_3_title  = Model\Portal\Category::find($cat_3);
        $privatepage_category_3_a      = Model\Portal\Article::onlyRegistered()->categoryId($cat_3)->take(3)->latest('date');
        $privatepage_category_3_b      = Model\Portal\Article::onlyRegistered()->categoryId($cat_3)->take(3)->skip(2)->latest('date');

        $privatepage_category_4_title  = Model\Portal\Category::find($cat_4);
        $privatepage_category_4_a      = Model\Portal\Article::onlyRegistered()->categoryId($cat_4)->take(3)->latest('date');
        $privatepage_category_4_b      = Model\Portal\Article::onlyRegistered()->categoryId($cat_4)->take(3)->skip(2)->latest('date');

        $data = array(
            'privatepage_slider_title'      => $privatepage_slider_title ? $privatepage_slider_title->name : '',
            'privatepage_slider'            => $privatepage_slider->count() ? $privatepage_slider->take(9)->latest('date')->get() : collect([]),

            'privatepage_category_1_title'  => $privatepage_category_1_title ? $privatepage_category_1_title->name : 'No Category',
            'privatepage_category_1_a'      => $privatepage_category_1_a->count() ? $privatepage_category_1_a->get() : collect([]),
            'privatepage_category_1_b'      => $privatepage_category_1_b->count() ? $privatepage_category_1_a->get() : collect([]),

            'privatepage_category_2_title'  => $privatepage_category_2_title ? $privatepage_category_2_title->name : 'No Category',
            'privatepage_category_2_a'      => $privatepage_category_2_a->count() ? $privatepage_category_2_a->get() : collect([]),
            'privatepage_category_2_b'      => $privatepage_category_2_b->count() ? $privatepage_category_2_b->get() : collect([]),

            'privatepage_category_3_title'  => $privatepage_category_3_title ? $privatepage_category_3_title->name : 'No Category',
            'privatepage_category_3_a'      => $privatepage_category_3_a->count() ? $privatepage_category_3_a->get() : collect([]),
            'privatepage_category_3_b'      => $privatepage_category_3_b->count() ? $privatepage_category_3_b->get() : collect([]),

            'privatepage_category_4_title'  => $privatepage_category_4_title ? $privatepage_category_4_title->name : 'No Category',
            'privatepage_category_4_a'      => $privatepage_category_4_a->count() ? $privatepage_category_4_a->get() : collect([]),
            'privatepage_category_4_b'      => $privatepage_category_4_b->count() ? $privatepage_category_4_b->get() : collect([]),

            'links'                         => $this->Mod_link->read(),
        );

        $latests    = Model\Portal\Article::registered()->latest('date')
                        ->limit(15)
                        ->get();
        $data['latest']     = $latests;
        $this->template->set('active', 'artikel');
        $this->template->set('sidebar', FALSE);
        $this->template->set_layout('privatepage');            
        $this->template->build('articlePrivate', $data);
    }

    public function sendArticle()
    {
        $this->form_validation->set_rules('title', 'Title', 'required');
        $this->form_validation->set_rules('content', 'Content', 'required');

        if ($this->form_validation->run() == FALSE) {
            $data['categories_checkbox']    = $this->Mod_category->generateCheckbox();
            $data['status'] = $this->status;

            $this->template->set('sidebar');
            $this->template->set_layout('privatepage');
            $this->template->build('create', $data);
        } else {
            $data   = array(
                'title'             => set_value('title'),
                'content'           => $this->input->post('content'),
                'contributor_id'    => auth()->getUser()->id,
            );

            $categories = set_value('categories', array());
            $status     = set_value('status', 'draft');
            $type       = set_value('type', 'private');

            if (isset($_FILES['featured']) && $_FILES['featured']['tmp_name']) {
                $featured_image = $_FILES['featured'];
            } else {
                $featured_image = null;
            }

            $id = $this->Mod_sendarticle->send($data, $status, $type, $featured_image, $categories);

            set_message_success('Artikel berhasil dibuat.');
{'fraction_non_alphanumeric': 0.16411392817571532, 'fraction_numerical': 0.011079971322427166, 'mean_word_length': 2.6760900814566364, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 288, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '416522', 'n_tokens_mistral': 4574, 'n_tokens_neox': 4444, 'n_words': 530}