<?php
namespace App\Model\Table;

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

/**
 * Offices Model
 *
 * @method \App\Model\Entity\Office get($primaryKey, $options = [])
 * @method \App\Model\Entity\Office newEntity($data = null, array $options = [])
 * @method \App\Model\Entity\Office[] newEntities(array $data, array $options = [])
 * @method \App\Model\Entity\Office|bool save(\Cake\Datasource\EntityInterface $entity, $options = [])
 * @method \App\Model\Entity\Office patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
 * @method \App\Model\Entity\Office[] patchEntities($entities, array $data, array $options = [])
 * @method \App\Model\Entity\Office findOrCreate($search, callable $callback = null, $options = [])
 *
 * @mixin \Cake\ORM\Behavior\TimestampBehavior
 */
class OfficesTable extends Table
{

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

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

        $this->addBehavior('Timestamp');
    }

    /**
     * Default validation rules.
     *
     * @param \Cake\Validation\Validator $validator Validator instance.
     * @return \Cake\Validation\Validator
     */
    public function validationDefault(Validator $validator)
    {
        $validator
            ->integer('id')
            ->allowEmpty('id', 'create');

        $validator
            ->requirePresence('dst_name', 'create')
            ->notEmpty('dst_name');

        $validator
            ->requirePresence('dst_schluessel', 'create')
            ->notEmpty('dst_schluessel');

        $validator
            ->allowEmpty('dst_schulart');

        $validator
            ->requirePresence('dst_typ', 'create')
            ->notEmpty('dst_typ');

        $validator
            ->requirePresence('oe_typ', 'create')
            ->notEmpty('oe_typ');

        $validator
            ->allowEmpty('dst_kurz');

        $validator
            ->allowEmpty('dst_kurz_zusatz');

        $validator
            ->allowEmpty('dst_briefkopf_1');

        $validator
            ->allowEmpty('dst_briefkopf_2');

        $validator
            ->allowEmpty('dst_briefkopf_3');

        $validator
            ->allowEmpty('dst_briefkopf_4');

        $validator
            ->allowEmpty('dst_kommentar');

        $validator
            ->requirePresence('dst_ist_ausgelagert', 'create')
            ->notEmpty('dst_ist_ausgelagert');

        $validator
            ->requirePresence('dst_ist_mittelschule', 'create')
            ->notEmpty('dst_ist_mittelschule');

        $validator
            ->requirePresence('gkz_kennzahl', 'create')
            ->notEmpty('gkz_kennzahl');

        $validator
            ->requirePresence('lkz_kennzahl', 'create')
            ->notEmpty('lkz_kennzahl');

        $validator
            ->allowEmpty('asd_plz_strasse');

        $validator
            ->allowEmpty('adr_ort');

        $validator
            ->allowEmpty('adr_strasse');

        $validator
            ->allowEmpty('adr_hausnummer');

        $validator
            ->allowEmpty('adr_ortsteil');

        $validator
            ->allowEmpty('adr_plz_postfach');

        $validator
            ->allowEmpty('adr_postfach_ort');

        $validator
            ->allowEmpty('dst_ministerium_schluessel');

        $validator
            ->allowEmpty('dst_mb_schluessel');

        $validator
            ->allowEmpty('str_schluessel');

        $validator
            ->allowEmpty('str_lan_bezeichnung');

        $validator
            ->allowEmpty('str_art');

        $validator
            ->allowEmpty('seminar');

        $validator
            ->requirePresence('sst_name_offiziell', 'create')
            ->notEmpty('sst_name_offiziell');

        $validator
            ->requirePresence('sts_datum_genehmigung', 'create')
            ->notEmpty('sts_datum_genehmigung');

        $validator
            ->requirePresence('sts_schluessel', 'create')
            ->notEmpty('sts_schluessel');

        $validator
            ->allowEmpty('telefon');

        $validator
            ->allowEmpty('fax');

        $validator
            ->allowEmpty('email');

        $validator
            ->allowEmpty('web');

        $validator
            ->allowEmpty('bdg_schluessel');

        $validator
            ->allowEmpty('bdg_status');

        $validator
            ->allowEmpty('bdg_jg_von');

        $validator
            ->allowEmpty('bdg_jg_bis');

        $validator
            ->allowEmpty('bdg_bes_kreis');

        $validator
            ->allowEmpty('fsprofil');

        $validator
            ->allowEmpty('ffs_schluessel');

        $validator
            ->allowEmpty('dst_vkz');

        $validator
            ->allowEmpty('pu_schluessel');

        $validator
            ->allowEmpty('dst_pu');

        $validator
            ->allowEmpty('bv_schluessel');

        $validator
            ->allowEmpty('dst_bv');

        $validator
            ->allowEmpty('gt_betreuung');

        $validator
            ->allowEmpty('so_zusatzangebot');

        $validator
            ->allowEmpty('unterbringung');

        $validator
            ->allowEmpty('sja_schluessel');

        $validator
            ->allowEmpty('klassen_gesamt');

        $validator
            ->allowEmpty('lehrer_gesamt');

        $validator
            ->allowEmpty('lehrer_m');

        $validator
            ->allowEmpty('lehrer_w');

        $validator
            ->allowEmpty('lehrer_neben');

        $validator
            ->allowEmpty('abgaenger');

        $validator
            ->allowEmpty('schueler_gesamt');

        $validator
            ->allowEmpty('schueler_m');

        $validator
            ->allowEmpty('schuler_w');

        $validator
            ->allowEmpty('schueller_kolleg');

        $validator
            ->allowEmpty('schueler_bvj');

        $validator
            ->allowEmpty('schueler_bgj');

        $validator
            ->allowEmpty('stunden_insg');

        $validator
            ->allowEmpty('szjgst');

        $validator
            ->allowEmpty('szgst_klassen');

        $validator
            ->allowEmpty('szjgst_schueler');

        $validator
            ->allowEmpty('d_regierung');

        $validator
            ->allowEmpty('d_mb');

        $validator
            ->allowEmpty('d_schulamt');

        return $validator;
    }

    /**
     * Returns a rules checker object that will be used for validating
     * application integrity.
     *
     * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
     * @return \Cake\ORM\RulesChecker
     */
    public function buildRules(RulesChecker $rules)
    {
        //$rules->add($rules->isUnique(['email']));

        return $rules;
    }
}
