<?php
namespace App\Model\Table;

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

class SectionTable extends Table
{

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

        $this->setTable('section');
        $this->setDisplayField('section');
        $this->setPrimaryKey('id');

        $this->addBehavior('Timestamp');

        $this->belongsTo('MapDivisionSection', [
            'foreignKey' => 'id'
        ]);
        
    }

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

        return $validator;
    }
    

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