/var/www/vhosts/ihelp.ro/_OLD/src/Model/Table
Edit: /var/www/vhosts/ihelp.ro/_OLD/src/Model/Table/UsersTable.php (3435B)
setTable('users');
$this->setDisplayField('id');
$this->setPrimaryKey('id');
$this->addBehavior('Timestamp');
$this->belongsTo('Roles', [
'foreignKey' => 'role_id',
'joinType' => 'INNER',
]);
$this->hasMany('Causes', [
'foreignKey' => 'user_id',
]);
$this->hasMany('Messages', [
'foreignKey' => 'user_id',
]);
$this->hasMany('Orders', [
'foreignKey' => 'user_id',
]);
$this->hasMany('PaymentLogs', [
'foreignKey' => 'user_id',
]);
$this->hasMany('ProductFavorites', [
'foreignKey' => 'user_id',
]);
$this->hasMany('Products', [
'foreignKey' => 'user_id',
]);
$this->hasMany('Causes', [
'foreignKey' => 'user_id',
]);
$this->hasOne('Profiles', [
'foreignKey' => 'user_id',
]);
}
/*
*
*/
public function beforeSave(EventInterface $event, EntityInterface $entity, ArrayObject $options)
{
if (empty($entity->id)) {
$entity->uuid = hexdec(uniqid());
if (empty($entity->role_id)) {
$entity->role_id = 3;
}
}
}
/**
* Default validation rules.
*
* @param \Cake\Validation\Validator $validator Validator instance.
* @return \Cake\Validation\Validator
*/
public function validationDefault(Validator $validator): Validator
{
$validator
->integer('id')
->allowEmptyString('id', null, 'create');
$validator
->email('email')
->requirePresence('email', 'create')
->notEmptyString('email');
$validator
->scalar('password')
->maxLength('password', 255)
->requirePresence('password', 'create')
->notEmptyString('password');
$validator
->boolean('accept_gdpr')
->requirePresence('accept_gdpr', 'create')
->notEmptyString('accept_gdpr');
$validator
->boolean('is_active')
->requirePresence('is_active', null, 'create')
->notEmptyString('is_active');
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): RulesChecker
{
$rules->add($rules->isUnique(['email']), ['errorField' => 'email']);
$rules->add($rules->isUnique(['uuid']), ['errorField' => 'uuid']);
$rules->add($rules->existsIn(['role_id'], 'Roles'), ['errorField' => 'role_id']);
return $rules;
}
}