<?php namespace App\Models;

use CodeIgniter\Database\ConnectionInterface;
use CodeIgniter\Model;

class ApplicationModel extends Model
{
    protected $table = 'courseapplications';

    protected $allowedFields = ['applicationID','scheduleID','courseID','studentID','appStatus','dateCreated'];

    public function getSearchedStudents($courseId,$dateFrom,$dateTo,$status){

    //  return $arr= array("name"=>"Charles");

      $db      = \Config\Database::connect();
      $builder = $db->table('courseapplications');

      $builder->select('applicationID,scheduleID,courses.courseID,users.userID,appStatus,courseName,firstName,secondName,surName,phone,email');
      //,courseName,firstName,secondName,surName,phone,email
       $builder->join('users', 'courseapplications.studentID = users.userID');
      $builder->join('courses', 'courseapplications.courseID = courses.courseID');
      if($courseId!=10000){
        $builder->where(['courseapplications.courseId'=> $courseId]);
      }
      $where="date(courseapplications.dateCreated)>='$dateFrom' AND date(courseapplications.dateCreated)<='$dateTo' AND  courseapplications.appStatus=$status";
      $builder->where($where);

      $query = $builder->get();


      return $query->getResult();

    }





}
