<?php

namespace App\Controllers;
use App\Models\DokumenModel;
use App\Models\TutorialModel;
use App\Models\InfoModel;
use App\Models\SaranModel;
use App\Models\PermintaanModel;

class Admin extends BaseController
{


    protected $dokumen;
    protected $tutorial;
    protected $infografis;
    protected $saran;
    protected $permintaan;

    public function __construct()
    {
        $this->dokumen = new DokumenModel();
        $this->tutorial = new TutorialModel();
        $this->infografis = new InfoModel();
        $this->saran = new SaranModel();
        $this->permintaan = new PermintaanModel();
    }


    public function admin()
    {
     return view('admin/home');
 }


    // -------------- Input Dokumen -----------------------//
 public function inputdokumen()
 {

    return view('admin/inputdokumen');
}

public function simpandoc()
{
    $data = [
        'n_dokumen'     => $this->request->getPost('n_dokumen'),
        't_dokumen'     => $this->request->getPost('t_dokumen'),
        'link_dokumen'  => $this->request->getPost('link_dokumen'),
        'ukuran'        => $this->request->getPost('ukuran'),
        'deskripsi'     => $this->request->getPost('deskripsi'),
    ];

     if ($this->dokumen->insert($data)) {
        return redirect()->back()->with('success', 'Inputan berhasil disimpan.');
    } else {
        return redirect()->back()->with('error', 'Inputan gagal disimpan.');
    }
}

    // ---------------- Batas Input Dokumen -----------------//



// --------------  INPUT TUTORIAL ---------------------//
public function inputtutor()
{

    return view('admin/inputtutor');
}

public function simtutor()
{
    $data = [
        'jenis'     => $this->request->getPost('jenis'),
        'judul'     => $this->request->getPost('judul'),
        'kategori'  => $this->request->getPost('kategori'),
        'isi'       => $this->request->getPost('isi'),
    ];

     if ($this->tutorial->insert($data)) {
        return redirect()->back()->with('success', 'Inputan berhasil disimpan.');
    } else {
        return redirect()->back()->with('error', 'Inputan gagal disimpan.');
    }
}
// ---------------- BATAS INPUT TUTORIAL ---------------//


// -------------------------  INFOGRAFIS ------------ //

public function inputgrafis()
{

    return view('admin/inputgrafis');
}

public function siminfografis()
{
    $data = [
        'jenis'  => $this->request->getPost('jenis'),
        'judul'  => $this->request->getPost('judul'),
        'keterangan'  => $this->request->getPost('keterangan'),
        'kategori'  => $this->request->getPost('kategori'),
        'kapasitas'  => $this->request->getPost('kapasitas'),
        'tautan'  => $this->request->getPost('tautan'),
     ];

     if ($this->infografis->insert($data)) {
        return redirect()->back()->with('success', 'Inputan berhasil disimpan.');
    } else {
        return redirect()->back()->with('error', 'Inputan gagal disimpan.');
    }

}


// ------------------------- BATAS INFOGRAFIS ------------ //

public function komentar()
{
    $data['saran'] = $this->saran
                    ->orderBy('id','DESC')
                    ->findAll();

    $data['permintaan'] = $this->permintaan->findAll();

    return view('admin/komentar',$data);
}




}
