<?php
namespace App\Model\Table;

use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
class ProjectsTable extends Table
{

/**
* Initialize method
*
* @param array $config The configuration for the Table.
* @return void
*/
public function initialize(array $config)
{
parent::initialize($config);

$this->table('projects');
$this->displayField('name');
$this->primaryKey('id');


//$this->belongsTo('CrmCategories', [
//'foreignKey' => 'category_id',
//'type'=>'inner'
//
//]);

$this->belongsTo('Cmsusers', [
'foreignKey' => 'created_by',
'type'=>'inner'

]);

$this->belongsTo('Clients', [
'foreignKey' => 'client_id',
'type'=>'inner'

]);

$this->hasMany('ProjectHasTask', [
'foreignKey' => 'project_id',
'type'=>'right'

]);

$this->hasMany('Expenses', [
'foreignKey' => 'project_id',
'type'=>'inner'

]);

}
 public function validationDefault(Validator $validator)
    {
         $validator
             ->integer('client_id')
             ->notEmpty('client_id');
         
         $validator
             ->integer('rate_per_hour','This value must be integer')
             ->allowEmpty('rate_per_hour');
         
         $validator
             ->allowEmpty('progress'); 
         
         $validator
             ->notEmpty('project_name');
         
         $validator
             ->notEmpty('start_date');
         
         $validator
             ->notEmpty('deadline');
         
         $validator
             ->notEmpty('category_name');
         
         $validator
             ->notEmpty('phase');

         $validator
             ->allowEmpty('description');

        return $validator;
    }

}