<?php

namespace Modules\Redd\Models;

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

class ProjectActivitiesModel extends Model
{

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

    protected $allowedFields = ['project_id', 'activity_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_activities');
        $builder->where('deleted_at', null);
        $result = $builder->get()->getResult();
        return $result;
    }

    public function getProjectActivities($project)
    {
        $builder = $this->db->table('redd_project_activities');
        $builder->select('redd_project_activities.*,')
                ->join('redd_projects', 'redd_projects.id=redd_project_activities.project_id')
                ->join('redd_activities', 'redd_activities.id=redd_project_activities.activity_id', 'left')
                ->where('redd_project_activities.deleted_at', null)
                ->where('redd_project_activities.project_id', $project);
        return $results = $builder->get()->getResult();
    }

    public function getByProject($projectId)
    {
        $builder = $this->db->table('redd_project_activities');
        $builder->select('redd_project_activities.*, redd_activities.name as activity_name, ')
                    ->join('redd_activities', 'redd_activities.id=redd_project_activities.activity_id', 'left')
                    ->where('redd_project_activities.deleted_at', null)
                    ->where('project_id', $projectId);
        return $results = $builder->get()->getResult();
    }
}