/var/www/vhosts/ihelp.ro/httpdocs/src/Model/Table
Edit: /var/www/vhosts/ihelp.ro/httpdocs/src/Model/Table/UserAddressesTable.php (4183B)
setTable('user_addresses');
$this->setDisplayField('id');
$this->setPrimaryKey('id');
$this->addBehavior('Timestamp');
$this->belongsTo('Users', [
'foreignKey' => 'user_id',
'joinType' => 'INNER',
]);
$this->belongsTo('Cities', [
'foreignKey' => 'city_id',
'joinType' => 'INNER',
]);
$this->belongsTo('Counties', [
'foreignKey' => 'county_id',
'joinType' => 'INNER',
]);
}
/**
* Default validation rules.
*/
public function validationDefault(Validator $validator): Validator
{
$validator
->integer('id')
->allowEmptyString('id', null, 'create');
$validator
->scalar('first_name')
->maxLength('first_name', 255)
->requirePresence('first_name', 'create')
->notEmptyString('first_name', __('Câmpul este obligatoriu.'));
$validator
->scalar('last_name')
->maxLength('last_name', 255)
->requirePresence('last_name', 'create')
->notEmptyString('last_name', __('Câmpul este obligatoriu.'));
$validator
->scalar('county_id')
->requirePresence('county_id', 'create')
->notEmptyString('county_id', __('Câmpul este obligatoriu.'));
$validator
->scalar('city_id')
->requirePresence('city_id', 'create')
->notEmptyString('city_id', __('Câmpul este obligatoriu.'));
$validator->setProvider('tools', 'App\Model\Validation\ToolsValidation');
$validator
->requirePresence('phone', 'create')
->notEmptyString('phone', __('Câmpul este obligatoriu.'))
->add('phone', 'isValidROPhoneFormat', [
'rule' => 'isValidROPhoneFormat',
'provider' => 'tools',
'message' => 'Incorect'
]);
$validator
->scalar('str')
->requirePresence('str', 'create')
->notEmptyString('str', __('Câmpul este obligatoriu.'));
$validator
->scalar('nr')
->requirePresence('nr', 'create')
->notEmptyString('nr', __('Câmpul este obligatoriu.'));
$validator
->scalar('postal_code')
->maxLength('postal_code', 20)
->requirePresence('postal_code', 'create')
->notEmptyString('postal_code', __('Câmpul este obligatoriu.'));
$validator
->boolean('is_active')
->notEmptyString('is_active');
$validator
->boolean('is_default')
->notEmptyString('is_default');
return $validator;
}
/**
* Returns a rules checker object that will be used for validating
*/
public function buildRules(RulesChecker $rules): RulesChecker
{
$rules->add($rules->existsIn(['user_id'], 'Users'), ['errorField' => 'user_id']);
$rules->add($rules->existsIn(['city_id'], 'Cities'), ['errorField' => 'city_id']);
//$rules->add($rules->existsIn(['county_id'], 'Counties'), ['errorField' => 'county_id']);
return $rules;
}
/**
* beforeSave
*/
public function beforeSave(EventInterface $event, EntityInterface $entity, ArrayObject $options)
{
parent::beforeSave($event, $entity, $options);
//set address
$entity->address = $entity->str . ' ' . $entity->nr . ' ' . $entity->bl . ' ' . $entity->sc . ' ' . $entity->ap . ' ' . $entity->interfon;
}
}