<?php
namespace App\Model\Table;

use Cake\ORM\Query;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;

class DivisionTable extends Table
{

    public function initialize(array $config)
    {
        parent::initialize($config);

        $this->setTable('division');
        $this->setDisplayField('division');
        $this->setPrimaryKey('id');
        $this->addBehavior('Timestamp');
        $this->belongsTo('Division', [
            'foreignKey' => 'id'
        ]);
        
    }

    public function validationDefault(Validator $validator)
    {
        $validator
            ->scalar('division')
            ->allowEmpty('division', 'create');

        return $validator;
    }
    

    public function getUser($sel=true) {
        $result = $this->find()
                ->select(['Division.id', 'Division.division'])
                ->hydrate(false)
                ->toArray();
        $userGroups = [];
        if($sel) {
            $userGroups[''] = __('Select');
        }
        foreach($result as $row) {
            $userGroups[$row['id']] = $row['division'];            
        }
        return $userGroups;
    }
    
}
