first standalone plugin commit

This commit is contained in:
2025-11-18 00:43:34 -08:00
commit 5dc7aa87cd
86 changed files with 86844 additions and 0 deletions

View File

@@ -0,0 +1,93 @@
<?php
declare(strict_types=1);
namespace CakeAddresses;
use Cake\Console\CommandCollection;
use Cake\Core\BasePlugin;
use Cake\Core\ContainerInterface;
use Cake\Core\PluginApplicationInterface;
use Cake\Http\MiddlewareQueue;
use Cake\Routing\RouteBuilder;
/**
* Plugin for CakeAddresses
*/
class CakeAddressesPlugin extends BasePlugin
{
/**
* Load all the plugin configuration and bootstrap logic.
*
* The host application is provided as an argument. This allows you to load
* additional plugin dependencies, or attach events.
*
* @param \Cake\Core\PluginApplicationInterface $app The host application
* @return void
*/
public function bootstrap(PluginApplicationInterface $app): void
{
}
/**
* Add routes for the plugin.
*
* If your plugin has many routes and you would like to isolate them into a separate file,
* you can create `$plugin/config/routes.php` and delete this method.
*
* @param \Cake\Routing\RouteBuilder $routes The route builder to update.
* @return void
*/
public function routes(RouteBuilder $routes): void
{
$routes->plugin(
'CakeAddresses',
['path' => '/cake-addresses'],
function (RouteBuilder $builder) {
// Add custom routes here
$builder->fallbacks();
}
);
parent::routes($routes);
}
/**
* Add middleware for the plugin.
*
* @param \Cake\Http\MiddlewareQueue $middlewareQueue The middleware queue to update.
* @return \Cake\Http\MiddlewareQueue
*/
public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue
{
// Add your middlewares here
return $middlewareQueue;
}
/**
* Add commands for the plugin.
*
* @param \Cake\Console\CommandCollection $commands The command collection to update.
* @return \Cake\Console\CommandCollection
*/
public function console(CommandCollection $commands): CommandCollection
{
// Add your commands here
$commands = parent::console($commands);
return $commands;
}
/**
* Register application container services.
*
* @param \Cake\Core\ContainerInterface $container The Container to update.
* @return void
* @link https://book.cakephp.org/4/en/development/dependency-injection.html#dependency-injection
*/
public function services(ContainerInterface $container): void
{
// Add your services here
}
}

View File

@@ -0,0 +1,110 @@
<?php
declare(strict_types=1);
namespace CakeAddresses\Controller;
use Cake\Log\Log;
use CakeAddresses\Controller\AppController;
/**
* Addresses Controller
*
* @property \CakeAddresses\Model\Table\AddressesTable $Addresses
*/
class AddressesController extends AppController
{
/**
* Index method
*
* @return \Cake\Http\Response|null|void Renders view
*/
public function index()
{
$query = $this->Addresses->find()
->contain(['Cities', 'States', 'Countries']);
$addresses = $this->paginate($query);
$this->set(compact('addresses'));
}
/**
* View method
*
* @param string|null $id Address id.
* @return \Cake\Http\Response|null|void Renders view
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
*/
public function view($id = null)
{
$address = $this->Addresses->get($id, contain: ['Cities', 'States', 'Countries']);
$this->set(compact('address'));
}
/**
* Add method
*
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
*/
public function add()
{
$address = $this->Addresses->newEmptyEntity();
if ($this->request->is('post')) {
$data = $this->request->getData();
$address = $this->Addresses->patchEntity($address, $data);
if ($this->Addresses->save($address)) {
$this->Flash->success(__('The address has been saved.'));
return $this->redirect(['action' => 'index']);
}
Log::alert(print_r('$address->getErrors() from addresses add', true));
Log::alert(print_r($address->getErrors(), true));
$this->Flash->error(__('The address could not be saved. Please, try again.'));
}
$countries = $this->Addresses->Countries->find('list')->all();
$this->set(compact('address', 'countries'));
}
/**
* Edit method
*
* @param string|null $id Address id.
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
*/
public function edit($id = null)
{
$address = $this->Addresses->get($id, contain: []);
if ($this->request->is(['patch', 'post', 'put'])) {
$address = $this->Addresses->patchEntity($address, $this->request->getData());
if ($this->Addresses->save($address)) {
$this->Flash->success(__('The address has been saved.'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('The address could not be saved. Please, try again.'));
}
$countries = $this->Addresses->Countries->find('list')->all();
$states = $this->Addresses->States->find('list')->where(['country_id' => $address->country_id])->all();
$this->set(compact('address', 'countries', 'states'));
}
/**
* Delete method
*
* @param string|null $id Address id.
* @return \Cake\Http\Response|null Redirects to index.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
*/
public function delete($id = null)
{
$this->request->allowMethod(['post', 'delete']);
$address = $this->Addresses->get($id);
if ($this->Addresses->delete($address)) {
$this->Flash->success(__('The address has been deleted.'));
} else {
$this->Flash->error(__('The address could not be deleted. Please, try again.'));
}
return $this->redirect(['action' => 'index']);
}
}

View File

@@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace CakeAddresses\Controller;
use App\Controller\AppController as BaseController;
class AppController extends BaseController
{
}

View File

@@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
namespace CakeAddresses\Controller;
use CakeAddresses\Controller\AppController;
/**
* Cities Controller
*
* @property \CakeAddresses\Model\Table\CitiesTable $Cities
*/
class CitiesController extends AppController
{
/**
* @return \Cake\Http\Response|null|void Renders view
*/
public function select()
{
$query = $this->Cities
// ->find('search', $this->request->getQueryParams())
->find('list')
->orderBy(['name']);
$cities = $this->paginate($query);
$this->set(compact('cities'));
}
}

View File

@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
namespace CakeAddresses\Controller;
use CakeAddresses\Controller\AppController;
/**
* Countries Controller
*
* @property \CakeAddresses\Model\Table\CountriesTable $Countries
*/
class CountriesController extends AppController
{
/**
* Index method
*
* @return \Cake\Http\Response|null|void Renders view
*/
public function index()
{
$query = $this->Countries->find()
->contain(['Regions', 'Subregions']);
$countries = $this->paginate($query);
$this->set(compact('countries'));
}
/**
* View method
*
* @param string|null $id Country id.
* @return \Cake\Http\Response|null|void Renders view
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
*/
public function view($id = null)
{
$country = $this->Countries->get($id, contain: ['Regions', 'Subregions', 'States']);
$this->set(compact('country'));
}
}

View File

@@ -0,0 +1,40 @@
<?php
declare(strict_types=1);
namespace CakeAddresses\Controller;
use CakeAddresses\Controller\AppController;
/**
* Regions Controller
*
* @property \CakeAddresses\Model\Table\RegionsTable $Regions
*/
class RegionsController extends AppController
{
/**
* Index method
*
* @return \Cake\Http\Response|null|void Renders view
*/
public function index()
{
$query = $this->Regions->find();
$regions = $this->paginate($query);
$this->set(compact('regions'));
}
/**
* View method
*
* @param string|null $id Region id.
* @return \Cake\Http\Response|null|void Renders view
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
*/
public function view($id = null)
{
$region = $this->Regions->get($id, contain: ['Countries', 'Subregions']);
$this->set(compact('region'));
}
}

View File

@@ -0,0 +1,55 @@
<?php
declare(strict_types=1);
namespace CakeAddresses\Controller;
use CakeAddresses\Controller\AppController;
use Cake\Log\Log;
/**
* States Controller
*
* @property \CakeAddresses\Model\Table\StatesTable $States
*/
class StatesController extends AppController
{
/**
* Index method
*
* @return \Cake\Http\Response|null|void Renders view
*/
public function index()
{
$query = $this->States->find()
->contain(['Countries']);
$states = $this->paginate($query);
$this->set(compact('states'));
}
/**
* View method
*
* @param string|null $id State id.
* @return \Cake\Http\Response|null|void Renders view
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
*/
public function view($id = null)
{
$state = $this->States->get($id, contain: ['Countries', 'Addresses', 'Cities']);
$this->set(compact('state'));
}
/**
* @return \Cake\Http\Response|null|void Renders view
*/
public function select()
{
$states = $this->States
->find('list')
->where(['country_id' => $this->request->getQuery('country_id', -1)])
->orderBy(['States.name'])
->toArray();
$this->set(compact('states'));
}
}

View File

@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
namespace CakeAddresses\Controller;
use CakeAddresses\Controller\AppController;
/**
* Subregions Controller
*
* @property \CakeAddresses\Model\Table\SubregionsTable $Subregions
*/
class SubregionsController extends AppController
{
/**
* Index method
*
* @return \Cake\Http\Response|null|void Renders view
*/
public function index()
{
$query = $this->Subregions->find()
->contain(['Regions']);
$subregions = $this->paginate($query);
$this->set(compact('subregions'));
}
/**
* View method
*
* @param string|null $id Subregion id.
* @return \Cake\Http\Response|null|void Renders view
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
*/
public function view($id = null)
{
$subregion = $this->Subregions->get($id, contain: ['Regions', 'Countries']);
$this->set(compact('subregion'));
}
}

View File

@@ -0,0 +1,55 @@
<?php
declare(strict_types=1);
namespace CakeAddresses\Model\Entity;
use Cake\ORM\Entity;
/**
* Address Entity
*
* @property int $id
* @property string|null $address_name
* @property string|null $contact_name
* @property string $address_line1
* @property string|null $address_line2
* @property int|null $city_id
* @property int|null $state_id
* @property string $postal_code
* @property int|null $country_id
* @property string|null $phone_number
* @property string|null $email
* @property string|null $notes
*
* @property \CakeAddresses\Model\Entity\City $city
* @property \CakeAddresses\Model\Entity\State $state
* @property \CakeAddresses\Model\Entity\Country $country
*/
class Address extends Entity
{
/**
* Fields that can be mass assigned using newEntity() or patchEntity().
*
* Note that when '*' is set to true, this allows all unspecified fields to
* be mass assigned. For security purposes, it is advised to set '*' to false
* (or remove it), and explicitly make individual fields accessible as needed.
*
* @var array<string, bool>
*/
protected array $_accessible = [
'address_name' => true,
'contact_name' => true,
'address_line1' => true,
'address_line2' => true,
'city' => true,
'city_id' => true,
'state' => true,
'state_id' => true,
'postal_code' => true,
'country' => true,
'country_id' => true,
'phone_number' => true,
'email' => true,
'notes' => true,
];
}

55
src/Model/Entity/City.php Normal file
View File

@@ -0,0 +1,55 @@
<?php
declare(strict_types=1);
namespace CakeAddresses\Model\Entity;
use Cake\ORM\Entity;
/**
* City Entity
*
* @property int $id
* @property string $name
* @property int $state_id
* @property string $state_code
* @property int $country_id
* @property string $country_code
* @property string $latitude
* @property string $longitude
* @property \Cake\I18n\DateTime $created_at
* @property \Cake\I18n\DateTime $updated_at
* @property bool $flag
* @property string|null $wikiDataId
*
* @property \CakeAddresses\Model\Entity\State $state
* @property \CakeAddresses\Model\Entity\Country $country
* @property \CakeAddresses\Model\Entity\Address[] $addresses
*/
class City extends Entity
{
/**
* Fields that can be mass assigned using newEntity() or patchEntity().
*
* Note that when '*' is set to true, this allows all unspecified fields to
* be mass assigned. For security purposes, it is advised to set '*' to false
* (or remove it), and explicitly make individual fields accessible as needed.
*
* @var array<string, bool>
*/
protected array $_accessible = [
'name' => true,
'state_id' => true,
'state_code' => true,
'country_id' => true,
'country_code' => true,
'latitude' => true,
'longitude' => true,
'created_at' => true,
'updated_at' => true,
'flag' => true,
'wikiDataId' => true,
'state' => true,
'country' => true,
'addresses' => true,
];
}

View File

@@ -0,0 +1,85 @@
<?php
declare(strict_types=1);
namespace CakeAddresses\Model\Entity;
use Cake\ORM\Entity;
/**
* Country Entity
*
* @property int $id
* @property string $name
* @property string|null $iso3
* @property string|null $numeric_code
* @property string|null $iso2
* @property string|null $phonecode
* @property string|null $capital
* @property string|null $currency
* @property string|null $currency_name
* @property string|null $currency_symbol
* @property string|null $tld
* @property string|null $native
* @property int|null $region_id
* @property int|null $subregion_id
* @property string|null $nationality
* @property string|null $timezones
* @property string|null $translations
* @property string|null $latitude
* @property string|null $longitude
* @property string|null $emoji
* @property string|null $emojiU
* @property \Cake\I18n\DateTime|null $created_at
* @property \Cake\I18n\DateTime $updated_at
* @property bool $flag
* @property string|null $wikiDataId
*
* @property \CakeAddresses\Model\Entity\Region $region
* @property \CakeAddresses\Model\Entity\Subregion $subregion
* @property \CakeAddresses\Model\Entity\Address[] $addresses
* @property \CakeAddresses\Model\Entity\City[] $cities
* @property \CakeAddresses\Model\Entity\State[] $states
*/
class Country extends Entity
{
/**
* Fields that can be mass assigned using newEntity() or patchEntity().
*
* Note that when '*' is set to true, this allows all unspecified fields to
* be mass assigned. For security purposes, it is advised to set '*' to false
* (or remove it), and explicitly make individual fields accessible as needed.
*
* @var array<string, bool>
*/
protected array $_accessible = [
'name' => true,
'iso3' => true,
'numeric_code' => true,
'iso2' => true,
'phonecode' => true,
'capital' => true,
'currency' => true,
'currency_name' => true,
'currency_symbol' => true,
'tld' => true,
'native' => true,
'region' => true,
'region_id' => true,
'subregion' => true,
'subregion_id' => true,
'nationality' => true,
'timezones' => true,
'translations' => true,
'latitude' => true,
'longitude' => true,
'emoji' => true,
'emojiU' => true,
'created_at' => true,
'updated_at' => true,
'flag' => true,
'wikiDataId' => true,
'addresses' => true,
'cities' => true,
'states' => true,
];
}

View File

@@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
namespace CakeAddresses\Model\Entity;
use Cake\ORM\Entity;
/**
* Region Entity
*
* @property int $id
* @property string $name
* @property string|null $translations
* @property \Cake\I18n\DateTime|null $created_at
* @property \Cake\I18n\DateTime $updated_at
* @property bool $flag
* @property string|null $wikiDataId
*
* @property \CakeAddresses\Model\Entity\Country[] $countries
* @property \CakeAddresses\Model\Entity\Subregion[] $subregions
*/
class Region extends Entity
{
/**
* Fields that can be mass assigned using newEntity() or patchEntity().
*
* Note that when '*' is set to true, this allows all unspecified fields to
* be mass assigned. For security purposes, it is advised to set '*' to false
* (or remove it), and explicitly make individual fields accessible as needed.
*
* @var array<string, bool>
*/
protected array $_accessible = [
'name' => true,
'translations' => true,
'created_at' => true,
'updated_at' => true,
'flag' => true,
'wikiDataId' => true,
'countries' => true,
'subregions' => true,
];
}

View File

@@ -0,0 +1,57 @@
<?php
declare(strict_types=1);
namespace CakeAddresses\Model\Entity;
use Cake\ORM\Entity;
/**
* State Entity
*
* @property int $id
* @property string $name
* @property int $country_id
* @property string $country_code
* @property string|null $fips_code
* @property string|null $iso2
* @property string|null $type
* @property string|null $latitude
* @property string|null $longitude
* @property \Cake\I18n\DateTime|null $created_at
* @property \Cake\I18n\DateTime $updated_at
* @property bool $flag
* @property string|null $wikiDataId
*
* @property \CakeAddresses\Model\Entity\Country $country
* @property \CakeAddresses\Model\Entity\Address[] $addresses
* @property \CakeAddresses\Model\Entity\City[] $cities
*/
class State extends Entity
{
/**
* Fields that can be mass assigned using newEntity() or patchEntity().
*
* Note that when '*' is set to true, this allows all unspecified fields to
* be mass assigned. For security purposes, it is advised to set '*' to false
* (or remove it), and explicitly make individual fields accessible as needed.
*
* @var array<string, bool>
*/
protected array $_accessible = [
'name' => true,
'country_id' => true,
'country_code' => true,
'fips_code' => true,
'iso2' => true,
'type' => true,
'latitude' => true,
'longitude' => true,
'created_at' => true,
'updated_at' => true,
'flag' => true,
'wikiDataId' => true,
'country' => true,
'addresses' => true,
'cities' => true,
];
}

View File

@@ -0,0 +1,45 @@
<?php
declare(strict_types=1);
namespace CakeAddresses\Model\Entity;
use Cake\ORM\Entity;
/**
* Subregion Entity
*
* @property int $id
* @property string $name
* @property string|null $translations
* @property int $region_id
* @property \Cake\I18n\DateTime|null $created_at
* @property \Cake\I18n\DateTime $updated_at
* @property bool $flag
* @property string|null $wikiDataId
*
* @property \CakeAddresses\Model\Entity\Region $region
* @property \CakeAddresses\Model\Entity\Country[] $countries
*/
class Subregion extends Entity
{
/**
* Fields that can be mass assigned using newEntity() or patchEntity().
*
* Note that when '*' is set to true, this allows all unspecified fields to
* be mass assigned. For security purposes, it is advised to set '*' to false
* (or remove it), and explicitly make individual fields accessible as needed.
*
* @var array<string, bool>
*/
protected array $_accessible = [
'name' => true,
'translations' => true,
'region_id' => true,
'created_at' => true,
'updated_at' => true,
'flag' => true,
'wikiDataId' => true,
'region' => true,
'countries' => true,
];
}

View File

@@ -0,0 +1,185 @@
<?php
declare(strict_types=1);
namespace CakeAddresses\Model\Table;
use ArrayObject;
use Cake\Datasource\EntityInterface;
use Cake\Event\EventInterface;
use Cake\Log\Log;
use Cake\ORM\Query\SelectQuery;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
use CakeAddresses\Model\Entity\State;
/**
* Addresses Model
*
* @property \CakeAddresses\Model\Table\CitiesTable&\Cake\ORM\Association\BelongsTo $Cities
* @property \CakeAddresses\Model\Table\StatesTable&\Cake\ORM\Association\BelongsTo $States
* @property \CakeAddresses\Model\Table\CountriesTable&\Cake\ORM\Association\BelongsTo $Countries
*
* @method \CakeAddresses\Model\Entity\Address newEmptyEntity()
* @method \CakeAddresses\Model\Entity\Address newEntity(array $data, array $options = [])
* @method array<\CakeAddresses\Model\Entity\Address> newEntities(array $data, array $options = [])
* @method \CakeAddresses\Model\Entity\Address 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\Address findOrCreate($search, ?callable $callback = null, array $options = [])
* @method \CakeAddresses\Model\Entity\Address patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
* @method array<\CakeAddresses\Model\Entity\Address> patchEntities(iterable $entities, array $data, array $options = [])
* @method \CakeAddresses\Model\Entity\Address|false save(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method \CakeAddresses\Model\Entity\Address saveOrFail(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method iterable<\CakeAddresses\Model\Entity\Address>|\Cake\Datasource\ResultSetInterface<\CakeAddresses\Model\Entity\Address>|false saveMany(iterable $entities, array $options = [])
* @method iterable<\CakeAddresses\Model\Entity\Address>|\Cake\Datasource\ResultSetInterface<\CakeAddresses\Model\Entity\Address> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<\CakeAddresses\Model\Entity\Address>|\Cake\Datasource\ResultSetInterface<\CakeAddresses\Model\Entity\Address>|false deleteMany(iterable $entities, array $options = [])
* @method iterable<\CakeAddresses\Model\Entity\Address>|\Cake\Datasource\ResultSetInterface<\CakeAddresses\Model\Entity\Address> deleteManyOrFail(iterable $entities, array $options = [])
*/
class AddressesTable extends Table
{
/**
* Initialize method
*
* @param array<string, mixed> $config The configuration for the Table.
* @return void
*/
public function initialize(array $config): void
{
parent::initialize($config);
$this->setTable('addresses');
$this->setDisplayField('address_line1');
$this->setPrimaryKey('id');
$this->belongsTo('Cities', [
'foreignKey' => 'city_id',
'className' => 'CakeAddresses.Cities',
'propertyName' => 'city_entity',
]);
$this->belongsTo('States', [
'foreignKey' => 'state_id',
'className' => 'CakeAddresses.States',
'propertyName' => 'state_entity',
]);
$this->belongsTo('Countries', [
'foreignKey' => 'country_id',
'className' => 'CakeAddresses.Countries',
'propertyName' => 'country_entity',
]);
}
/**
* Default validation rules.
*
* @param \Cake\Validation\Validator $validator Validator instance.
* @return \Cake\Validation\Validator
*/
public function validationDefault(Validator $validator): Validator
{
$validator
->scalar('address_name')
->maxLength('address_name', 255)
->allowEmptyString('address_name');
$validator
->scalar('contact_name')
->maxLength('contact_name', 255)
->allowEmptyString('contact_name');
$validator
->scalar('address_line1')
->maxLength('address_line1', 255)
->requirePresence('address_line1', 'create')
->notEmptyString('address_line1');
$validator
->scalar('address_line2')
->maxLength('address_line2', 255)
->allowEmptyString('address_line2');
$validator
->scalar('city')
->maxLength('city', 255)
->requirePresence('city', 'create')
->notEmptyString('city');
$validator
->integer('city_id')
->allowEmptyString('city_id');
$validator
->scalar('state')
->maxLength('state', 255)
->requirePresence('state', 'create')
->notEmptyString('state');
$validator
->integer('state_id')
->allowEmptyString('state_id');
$validator
->scalar('postal_code')
->maxLength('postal_code', 25)
->requirePresence('postal_code', 'create')
->notEmptyString('postal_code');
$validator
->scalar('country')
->maxLength('country', 255)
->requirePresence('country', 'create')
->notEmptyString('country');
$validator
->integer('country_id')
->allowEmptyString('country_id');
$validator
->scalar('phone_number')
->maxLength('phone_number', 25)
->allowEmptyString('phone_number');
$validator
->email('email')
->allowEmptyString('email');
$validator
->scalar('notes')
->allowEmptyString('notes');
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->existsIn('city_id', 'Cities'), ['errorField' => 'city_id']);
$rules->add($rules->existsIn('state_id', 'States'), ['errorField' => 'state_id']);
$rules->add($rules->existsIn('country_id', 'Countries'), ['errorField' => 'country_id']);
return $rules;
}
/**
* @param EventInterface $event
* @param ArrayObject $data
* @param ArrayObject $options
*
* @return void
*/
public function beforeMarshal(EventInterface $event, ArrayObject $data, ArrayObject $options): void
{
if ($data['state_id'] && !isset($data['state'])) {
$state = $this->States->find()->where(['id' => $data['state_id']])->first();
$data['state'] = $state ? $state->name : null;
}
if ($data['country_id'] && !isset($data['country'])) {
$country = $this->Countries->find()->where(['id' => $data['country_id']])->first();
$data['country'] = $country ? $country->name : null;
}
}
}

View File

@@ -0,0 +1,142 @@
<?php
declare(strict_types=1);
namespace CakeAddresses\Model\Table;
use Cake\ORM\Query\SelectQuery;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
/**
* Cities Model
*
* @property \CakeAddresses\Model\Table\StatesTable&\Cake\ORM\Association\BelongsTo $States
* @property \CakeAddresses\Model\Table\CountriesTable&\Cake\ORM\Association\BelongsTo $Countries
* @property \CakeAddresses\Model\Table\AddressesTable&\Cake\ORM\Association\HasMany $Addresses
*
* @method \CakeAddresses\Model\Entity\City newEmptyEntity()
* @method \CakeAddresses\Model\Entity\City newEntity(array $data, array $options = [])
* @method array<\CakeAddresses\Model\Entity\City> newEntities(array $data, array $options = [])
* @method \CakeAddresses\Model\Entity\City 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\City findOrCreate($search, ?callable $callback = null, array $options = [])
* @method \CakeAddresses\Model\Entity\City patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
* @method array<\CakeAddresses\Model\Entity\City> patchEntities(iterable $entities, array $data, array $options = [])
* @method \CakeAddresses\Model\Entity\City|false save(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method \CakeAddresses\Model\Entity\City saveOrFail(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method iterable<\CakeAddresses\Model\Entity\City>|\Cake\Datasource\ResultSetInterface<\CakeAddresses\Model\Entity\City>|false saveMany(iterable $entities, array $options = [])
* @method iterable<\CakeAddresses\Model\Entity\City>|\Cake\Datasource\ResultSetInterface<\CakeAddresses\Model\Entity\City> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<\CakeAddresses\Model\Entity\City>|\Cake\Datasource\ResultSetInterface<\CakeAddresses\Model\Entity\City>|false deleteMany(iterable $entities, array $options = [])
* @method iterable<\CakeAddresses\Model\Entity\City>|\Cake\Datasource\ResultSetInterface<\CakeAddresses\Model\Entity\City> deleteManyOrFail(iterable $entities, array $options = [])
*/
class CitiesTable extends Table
{
/**
* Initialize method
*
* @param array<string, mixed> $config The configuration for the Table.
* @return void
*/
public function initialize(array $config): void
{
parent::initialize($config);
$this->setTable('cities');
$this->setDisplayField('name');
$this->setPrimaryKey('id');
$this->belongsTo('States', [
'foreignKey' => 'state_id',
'joinType' => 'INNER',
'className' => 'CakeAddresses.States',
]);
$this->belongsTo('Countries', [
'foreignKey' => 'country_id',
'joinType' => 'INNER',
'className' => 'CakeAddresses.Countries',
]);
$this->hasMany('Addresses', [
'foreignKey' => 'city_id',
'className' => 'CakeAddresses.Addresses',
]);
}
/**
* Default validation rules.
*
* @param \Cake\Validation\Validator $validator Validator instance.
* @return \Cake\Validation\Validator
*/
public function validationDefault(Validator $validator): Validator
{
$validator
->scalar('name')
->maxLength('name', 255)
->requirePresence('name', 'create')
->notEmptyString('name');
$validator
->nonNegativeInteger('state_id')
->notEmptyString('state_id');
$validator
->scalar('state_code')
->maxLength('state_code', 255)
->requirePresence('state_code', 'create')
->notEmptyString('state_code');
$validator
->nonNegativeInteger('country_id')
->notEmptyString('country_id');
$validator
->scalar('country_code')
->maxLength('country_code', 2)
->requirePresence('country_code', 'create')
->notEmptyString('country_code');
$validator
->decimal('latitude')
->requirePresence('latitude', 'create')
->notEmptyString('latitude');
$validator
->decimal('longitude')
->requirePresence('longitude', 'create')
->notEmptyString('longitude');
$validator
->dateTime('created_at')
->notEmptyDateTime('created_at');
$validator
->dateTime('updated_at')
->notEmptyDateTime('updated_at');
$validator
->boolean('flag')
->notEmptyString('flag');
$validator
->scalar('wikiDataId')
->maxLength('wikiDataId', 255)
->allowEmptyString('wikiDataId');
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->existsIn('state_id', 'States'), ['errorField' => 'state_id']);
$rules->add($rules->existsIn('country_id', 'Countries'), ['errorField' => 'country_id']);
return $rules;
}
}

View File

@@ -0,0 +1,221 @@
<?php
declare(strict_types=1);
namespace CakeAddresses\Model\Table;
use Cake\ORM\Query\SelectQuery;
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 = [])
*/
class CountriesTable extends Table
{
/**
* Initialize method
*
* @param array<string, mixed> $config The configuration for the Table.
* @return void
*/
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',
]);
}
/**
* Default validation rules.
*
* @param \Cake\Validation\Validator $validator Validator instance.
* @return \Cake\Validation\Validator
*/
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;
}
/**
* 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->existsIn('region_id', 'Regions'), ['errorField' => 'region_id']);
$rules->add($rules->existsIn('subregion_id', 'Subregions'), ['errorField' => 'subregion_id']);
return $rules;
}
}

View File

@@ -0,0 +1,94 @@
<?php
declare(strict_types=1);
namespace CakeAddresses\Model\Table;
use Cake\ORM\Query\SelectQuery;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
/**
* Regions Model
*
* @property \CakeAddresses\Model\Table\CountriesTable&\Cake\ORM\Association\HasMany $Countries
* @property \CakeAddresses\Model\Table\SubregionsTable&\Cake\ORM\Association\HasMany $Subregions
*
* @method \CakeAddresses\Model\Entity\Region newEmptyEntity()
* @method \CakeAddresses\Model\Entity\Region newEntity(array $data, array $options = [])
* @method array<\CakeAddresses\Model\Entity\Region> newEntities(array $data, array $options = [])
* @method \CakeAddresses\Model\Entity\Region 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\Region findOrCreate($search, ?callable $callback = null, array $options = [])
* @method \CakeAddresses\Model\Entity\Region patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
* @method array<\CakeAddresses\Model\Entity\Region> patchEntities(iterable $entities, array $data, array $options = [])
* @method \CakeAddresses\Model\Entity\Region|false save(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method \CakeAddresses\Model\Entity\Region saveOrFail(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method iterable<\CakeAddresses\Model\Entity\Region>|\Cake\Datasource\ResultSetInterface<\CakeAddresses\Model\Entity\Region>|false saveMany(iterable $entities, array $options = [])
* @method iterable<\CakeAddresses\Model\Entity\Region>|\Cake\Datasource\ResultSetInterface<\CakeAddresses\Model\Entity\Region> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<\CakeAddresses\Model\Entity\Region>|\Cake\Datasource\ResultSetInterface<\CakeAddresses\Model\Entity\Region>|false deleteMany(iterable $entities, array $options = [])
* @method iterable<\CakeAddresses\Model\Entity\Region>|\Cake\Datasource\ResultSetInterface<\CakeAddresses\Model\Entity\Region> deleteManyOrFail(iterable $entities, array $options = [])
*/
class RegionsTable extends Table
{
/**
* Initialize method
*
* @param array<string, mixed> $config The configuration for the Table.
* @return void
*/
public function initialize(array $config): void
{
parent::initialize($config);
$this->setTable('regions');
$this->setDisplayField('name');
$this->setPrimaryKey('id');
$this->hasMany('Countries', [
'foreignKey' => 'region_id',
'className' => 'CakeAddresses.Countries',
]);
$this->hasMany('Subregions', [
'foreignKey' => 'region_id',
'className' => 'CakeAddresses.Subregions',
]);
}
/**
* Default validation rules.
*
* @param \Cake\Validation\Validator $validator Validator instance.
* @return \Cake\Validation\Validator
*/
public function validationDefault(Validator $validator): Validator
{
$validator
->scalar('name')
->maxLength('name', 100)
->requirePresence('name', 'create')
->notEmptyString('name');
$validator
->scalar('translations')
->allowEmptyString('translations');
$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;
}
}

View File

@@ -0,0 +1,143 @@
<?php
declare(strict_types=1);
namespace CakeAddresses\Model\Table;
use Cake\ORM\Query\SelectQuery;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
/**
* States Model
*
* @property \CakeAddresses\Model\Table\CountriesTable&\Cake\ORM\Association\BelongsTo $Countries
* @property \CakeAddresses\Model\Table\AddressesTable&\Cake\ORM\Association\HasMany $Addresses
* @property \CakeAddresses\Model\Table\CitiesTable&\Cake\ORM\Association\HasMany $Cities
*
* @method \CakeAddresses\Model\Entity\State newEmptyEntity()
* @method \CakeAddresses\Model\Entity\State newEntity(array $data, array $options = [])
* @method array<\CakeAddresses\Model\Entity\State> newEntities(array $data, array $options = [])
* @method \CakeAddresses\Model\Entity\State 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\State findOrCreate($search, ?callable $callback = null, array $options = [])
* @method \CakeAddresses\Model\Entity\State patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
* @method array<\CakeAddresses\Model\Entity\State> patchEntities(iterable $entities, array $data, array $options = [])
* @method \CakeAddresses\Model\Entity\State|false save(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method \CakeAddresses\Model\Entity\State saveOrFail(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method iterable<\CakeAddresses\Model\Entity\State>|\Cake\Datasource\ResultSetInterface<\CakeAddresses\Model\Entity\State>|false saveMany(iterable $entities, array $options = [])
* @method iterable<\CakeAddresses\Model\Entity\State>|\Cake\Datasource\ResultSetInterface<\CakeAddresses\Model\Entity\State> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<\CakeAddresses\Model\Entity\State>|\Cake\Datasource\ResultSetInterface<\CakeAddresses\Model\Entity\State>|false deleteMany(iterable $entities, array $options = [])
* @method iterable<\CakeAddresses\Model\Entity\State>|\Cake\Datasource\ResultSetInterface<\CakeAddresses\Model\Entity\State> deleteManyOrFail(iterable $entities, array $options = [])
*/
class StatesTable extends Table
{
/**
* Initialize method
*
* @param array<string, mixed> $config The configuration for the Table.
* @return void
*/
public function initialize(array $config): void
{
parent::initialize($config);
$this->setTable('states');
$this->setDisplayField('name');
$this->setPrimaryKey('id');
$this->belongsTo('Countries', [
'foreignKey' => 'country_id',
'joinType' => 'INNER',
'className' => 'CakeAddresses.Countries',
]);
$this->hasMany('Addresses', [
'foreignKey' => 'state_id',
'className' => 'CakeAddresses.Addresses',
]);
$this->hasMany('Cities', [
'foreignKey' => 'state_id',
'className' => 'CakeAddresses.Cities',
]);
}
/**
* Default validation rules.
*
* @param \Cake\Validation\Validator $validator Validator instance.
* @return \Cake\Validation\Validator
*/
public function validationDefault(Validator $validator): Validator
{
$validator
->scalar('name')
->maxLength('name', 255)
->requirePresence('name', 'create')
->notEmptyString('name');
$validator
->nonNegativeInteger('country_id')
->notEmptyString('country_id');
$validator
->scalar('country_code')
->maxLength('country_code', 2)
->requirePresence('country_code', 'create')
->notEmptyString('country_code');
$validator
->scalar('fips_code')
->maxLength('fips_code', 255)
->allowEmptyString('fips_code');
$validator
->scalar('iso2')
->maxLength('iso2', 255)
->allowEmptyString('iso2');
$validator
->scalar('type')
->maxLength('type', 191)
->allowEmptyString('type');
$validator
->decimal('latitude')
->allowEmptyString('latitude');
$validator
->decimal('longitude')
->allowEmptyString('longitude');
$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;
}
/**
* 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->existsIn('country_id', 'Countries'), ['errorField' => 'country_id']);
return $rules;
}
}

View File

@@ -0,0 +1,113 @@
<?php
declare(strict_types=1);
namespace CakeAddresses\Model\Table;
use Cake\ORM\Query\SelectQuery;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
/**
* Subregions Model
*
* @property \CakeAddresses\Model\Table\RegionsTable&\Cake\ORM\Association\BelongsTo $Regions
* @property \CakeAddresses\Model\Table\CountriesTable&\Cake\ORM\Association\HasMany $Countries
*
* @method \CakeAddresses\Model\Entity\Subregion newEmptyEntity()
* @method \CakeAddresses\Model\Entity\Subregion newEntity(array $data, array $options = [])
* @method array<\CakeAddresses\Model\Entity\Subregion> newEntities(array $data, array $options = [])
* @method \CakeAddresses\Model\Entity\Subregion 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\Subregion findOrCreate($search, ?callable $callback = null, array $options = [])
* @method \CakeAddresses\Model\Entity\Subregion patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
* @method array<\CakeAddresses\Model\Entity\Subregion> patchEntities(iterable $entities, array $data, array $options = [])
* @method \CakeAddresses\Model\Entity\Subregion|false save(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method \CakeAddresses\Model\Entity\Subregion saveOrFail(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method iterable<\CakeAddresses\Model\Entity\Subregion>|\Cake\Datasource\ResultSetInterface<\CakeAddresses\Model\Entity\Subregion>|false saveMany(iterable $entities, array $options = [])
* @method iterable<\CakeAddresses\Model\Entity\Subregion>|\Cake\Datasource\ResultSetInterface<\CakeAddresses\Model\Entity\Subregion> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<\CakeAddresses\Model\Entity\Subregion>|\Cake\Datasource\ResultSetInterface<\CakeAddresses\Model\Entity\Subregion>|false deleteMany(iterable $entities, array $options = [])
* @method iterable<\CakeAddresses\Model\Entity\Subregion>|\Cake\Datasource\ResultSetInterface<\CakeAddresses\Model\Entity\Subregion> deleteManyOrFail(iterable $entities, array $options = [])
*/
class SubregionsTable extends Table
{
/**
* Initialize method
*
* @param array<string, mixed> $config The configuration for the Table.
* @return void
*/
public function initialize(array $config): void
{
parent::initialize($config);
$this->setTable('subregions');
$this->setDisplayField('name');
$this->setPrimaryKey('id');
$this->belongsTo('Regions', [
'foreignKey' => 'region_id',
'joinType' => 'INNER',
'className' => 'CakeAddresses.Regions',
]);
$this->hasMany('Countries', [
'foreignKey' => 'subregion_id',
'className' => 'CakeAddresses.Countries',
]);
}
/**
* Default validation rules.
*
* @param \Cake\Validation\Validator $validator Validator instance.
* @return \Cake\Validation\Validator
*/
public function validationDefault(Validator $validator): Validator
{
$validator
->scalar('name')
->maxLength('name', 100)
->requirePresence('name', 'create')
->notEmptyString('name');
$validator
->scalar('translations')
->allowEmptyString('translations');
$validator
->nonNegativeInteger('region_id')
->notEmptyString('region_id');
$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;
}
/**
* 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->existsIn('region_id', 'Regions'), ['errorField' => 'region_id']);
return $rules;
}
}