<?php

namespace App\Models\Dashboard;

use App\Models\BaseModel;

class DashboardModel extends BaseModel
{
	protected $table            = 'link_dashboard';
    protected $primaryKey       = 'id';
    protected $allowedFields    = ['namadb', 'linkdb', 'id_user', 'wkt_upd'];

    // Validation
    protected $validationRules = [
		'namadb' => [
            'label' => 'nama dashboard',
            'rules' => 'required',
        ],
		'linkdb' => [
            'label' => 'link',
            'rules' => 'required',
        ],
    ];

    public function find_by_name($name)
    {
        $db = \Config\Database::connect();
        $builder = $db->table($this->table);
        $builder->select('link_dashboard.id, link_dashboard.namadb, link_dashboard.linkdb, link_dashboard.id_user, link_dashboard.wkt_upd, users.username');

        $builder->join('users', 'users.id = link_dashboard.id_user');
        $builder->where('namadb', $name);

        return $builder->get()->getRow();
    }
}