MesuresTable.php 1.61 KB
<?php
namespace App\Model\Table;

use App\Model\Entity\Fichemetrologique;
use Cake\ORM\Query;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;

/**
 * MesuresTables Model
 *
 * @property \Cake\ORM\Association\BelongsTo $Fichemetrologiques
 */
class MesuresTable extends AppTable
{

    /**
     * Initialize method
     *
     * @param array $config
     *            The configuration for the Table.
     * @return void
     */
    public function initialize(array $config)
    {
        parent::initialize($config);
        
        $this->setTable('mesures');
        $this->setDisplayField('id');
        $this->setPrimaryKey('id');
        
        $this->addBehavior('Timestamp');
        
        $this->belongsTo('Fichemetrologiques', [
            'foreignKey' => 'fichemetrologique_id',
            'joinType' => 'INNER'
        ]);
    }

    /**
     * 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->notEmpty('valeur', 'Ce champ doit être rempli')->add('valeur', 'valid', [
            'rule' => 'numeric',
            'message' => 'Ce champ doit contenir des nombres'
        ]);
        $validator->notEmpty('erreur', 'Ce champ doit être rempli')->add('valeur', 'valid', [
            'rule' => 'numeric',
            'message' => 'Ce champ doit contenir des nombres'
        ]);
        
        return $validator;
    }
}