Files
cake-addresses/src/Model/Table/CountriesTable.php

219 lines
6.6 KiB
PHP
Raw Normal View History

2025-11-18 00:43:34 -08:00
<?php
declare(strict_types=1);
namespace CakeAddresses\Model\Table;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
/**
* Countries Model
*
* @property \CakeAddresses\Model\Table\RegionsTable&\Cake\ORM\Association\BelongsTo $Regions
* @property \CakeAddresses\Model\Table\SubregionsTable&\Cake\ORM\Association\BelongsTo $Subregions
* @property \CakeAddresses\Model\Table\AddressesTable&\Cake\ORM\Association\HasMany $Addresses
* @property \CakeAddresses\Model\Table\CitiesTable&\Cake\ORM\Association\HasMany $Cities
* @property \CakeAddresses\Model\Table\StatesTable&\Cake\ORM\Association\HasMany $States
*
* @method \CakeAddresses\Model\Entity\Country newEmptyEntity()
* @method \CakeAddresses\Model\Entity\Country newEntity(array $data, array $options = [])
* @method array<\CakeAddresses\Model\Entity\Country> newEntities(array $data, array $options = [])
* @method \CakeAddresses\Model\Entity\Country get(mixed $primaryKey, array|string $finder = 'all', \Psr\SimpleCache\CacheInterface|string|null $cache = null, \Closure|string|null $cacheKey = null, mixed ...$args)
* @method \CakeAddresses\Model\Entity\Country findOrCreate($search, ?callable $callback = null, array $options = [])
* @method \CakeAddresses\Model\Entity\Country patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
* @method array<\CakeAddresses\Model\Entity\Country> patchEntities(iterable $entities, array $data, array $options = [])
* @method \CakeAddresses\Model\Entity\Country|false save(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method \CakeAddresses\Model\Entity\Country saveOrFail(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method iterable<\CakeAddresses\Model\Entity\Country>|\Cake\Datasource\ResultSetInterface<\CakeAddresses\Model\Entity\Country>|false saveMany(iterable $entities, array $options = [])
* @method iterable<\CakeAddresses\Model\Entity\Country>|\Cake\Datasource\ResultSetInterface<\CakeAddresses\Model\Entity\Country> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<\CakeAddresses\Model\Entity\Country>|\Cake\Datasource\ResultSetInterface<\CakeAddresses\Model\Entity\Country>|false deleteMany(iterable $entities, array $options = [])
* @method iterable<\CakeAddresses\Model\Entity\Country>|\Cake\Datasource\ResultSetInterface<\CakeAddresses\Model\Entity\Country> deleteManyOrFail(iterable $entities, array $options = [])
*/
2026-01-23 18:36:15 -08:00
class CountriesTable extends Table {
/**
2025-11-18 00:43:34 -08:00
* Initialize method
*
* @param array<string, mixed> $config The configuration for the Table.
* @return void
*/
2026-01-23 18:36:15 -08:00
public function initialize(array $config): void {
parent::initialize($config);
$this->setTable('countries');
$this->setDisplayField('name');
$this->setPrimaryKey('id');
$this->belongsTo('Regions', [
'foreignKey' => 'region_id',
'className' => 'CakeAddresses.Regions',
'propertyName' => 'region_entity',
]);
$this->belongsTo('Subregions', [
'foreignKey' => 'subregion_id',
'className' => 'CakeAddresses.Subregions',
'propertyName' => 'subregion_entity',
]);
$this->hasMany('Addresses', [
'foreignKey' => 'country_id',
'className' => 'CakeAddresses.Addresses',
]);
$this->hasMany('Cities', [
'foreignKey' => 'country_id',
'className' => 'CakeAddresses.Cities',
]);
$this->hasMany('States', [
'foreignKey' => 'country_id',
'className' => 'CakeAddresses.States',
]);
}
/**
2025-11-18 00:43:34 -08:00
* Default validation rules.
*
* @param \Cake\Validation\Validator $validator Validator instance.
* @return \Cake\Validation\Validator
*/
2026-01-23 18:36:15 -08:00
public function validationDefault(Validator $validator): Validator {
$validator
->scalar('name')
->maxLength('name', 100)
->requirePresence('name', 'create')
->notEmptyString('name');
$validator
->scalar('iso3')
->maxLength('iso3', 3)
->allowEmptyString('iso3');
$validator
->scalar('numeric_code')
->maxLength('numeric_code', 3)
->allowEmptyString('numeric_code');
$validator
->scalar('iso2')
->maxLength('iso2', 2)
->allowEmptyString('iso2');
$validator
->scalar('phonecode')
->maxLength('phonecode', 255)
->allowEmptyString('phonecode');
$validator
->scalar('capital')
->maxLength('capital', 255)
->allowEmptyString('capital');
$validator
->scalar('currency')
->maxLength('currency', 255)
->allowEmptyString('currency');
$validator
->scalar('currency_name')
->maxLength('currency_name', 255)
->allowEmptyString('currency_name');
$validator
->scalar('currency_symbol')
->maxLength('currency_symbol', 255)
->allowEmptyString('currency_symbol');
$validator
->scalar('tld')
->maxLength('tld', 255)
->allowEmptyString('tld');
$validator
->scalar('native')
->maxLength('native', 255)
->allowEmptyString('native');
$validator
->scalar('region')
->maxLength('region', 255)
->allowEmptyString('region');
$validator
->nonNegativeInteger('region_id')
->allowEmptyString('region_id');
$validator
->scalar('subregion')
->maxLength('subregion', 255)
->allowEmptyString('subregion');
$validator
->nonNegativeInteger('subregion_id')
->allowEmptyString('subregion_id');
$validator
->scalar('nationality')
->maxLength('nationality', 255)
->allowEmptyString('nationality');
$validator
->scalar('timezones')
->allowEmptyString('timezones');
$validator
->scalar('translations')
->allowEmptyString('translations');
$validator
->decimal('latitude')
->allowEmptyString('latitude');
$validator
->decimal('longitude')
->allowEmptyString('longitude');
$validator
->scalar('emoji')
->maxLength('emoji', 191)
->allowEmptyString('emoji');
$validator
->scalar('emojiU')
->maxLength('emojiU', 191)
->allowEmptyString('emojiU');
$validator
->dateTime('created_at')
->allowEmptyDateTime('created_at');
$validator
->dateTime('updated_at')
->notEmptyDateTime('updated_at');
$validator
->boolean('flag')
->notEmptyString('flag');
$validator
->scalar('wikiDataId')
->maxLength('wikiDataId', 255)
->allowEmptyString('wikiDataId');
return $validator;
}
/**
2025-11-18 00:43:34 -08:00
* 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
*/
2026-01-23 18:36:15 -08:00
public function buildRules(RulesChecker $rules): RulesChecker {
$rules->add($rules->existsIn('region_id', 'Regions'), ['errorField' => 'region_id']);
$rules->add($rules->existsIn('subregion_id', 'Subregions'), ['errorField' => 'subregion_id']);
return $rules;
}
2025-11-18 00:43:34 -08:00
}