<?php

namespace Modules\Redd\Models;

use CodeIgniter\Model;
use CodeIgniter\I18n\Time;

class ProjectTypesModel extends Model
{

  protected $table = 'redd_project_types';
    protected $primaryKey = 'id';

    protected $allowedFields = ['project_id', 'project_type_id'];

    protected $returnType     = 'array';
    protected $useTimestamps  = true;
    protected $useSoftDeletes = true;
    
    protected $createdField  = 'created_at';
    protected $updatedField  = 'updated_at';
    protected $deletedField  = 'deleted_at';


    public function getAll()
    {
        $builder = $this->db->table('redd_project_types');
        $builder->where('deleted_at', null);
        $result = $builder->get()->getResult();
        return $result;
    }

    public function getByProject($projectId)
    {
      $builder = $this->db->table('redd_project_types');
      $builder->select('redd_types.name as type_name, redd_project_types.*')
              ->join('redd_types', 'redd_types.id=redd_project_types.project_type_id')
              ->where('redd_project_types.deleted_at', null)
              ->where('redd_project_types.project_id', $projectId);
        $result = $builder->get()->getResult();
        return $result;
    }

}