Skip to content
Permalink
main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
Latest commit 4d93dcc Jun 18, 2023 History
2 contributors

Users who have contributed to this file

@Ioannis @arlen
149 lines (127 sloc) 3.97 KB
<?php
/**
* COmanage Match Rule Attributes Table
*
* Portions licensed to the University Corporation for Advanced Internet
* Development, Inc. ("UCAID") under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* UCAID licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @link http://www.internet2.edu/comanage COmanage Project
* @package match
* @since COmanage Match v1.0.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/
declare(strict_types = 1);
namespace App\Model\Table;
use Cake\ORM\Table;
use Cake\Validation\Validator;
use \App\Lib\Enum\SearchTypeEnum;
class RuleAttributesTable extends Table {
use \App\Lib\Traits\AutoViewVarsTrait;
use \App\Lib\Traits\MatchgridLinkTrait;
use \App\Lib\Traits\PrimaryLinkTrait;
use \App\Lib\Traits\QueryModificationTrait;
/**
* Perform Cake Model initialization.
*
* @since COmanage Match v1.0.0
* @param array $config Configuration options passed to constructor
*/
public function initialize(array $config): void {
$this->addBehavior('Timestamp');
// Define associations
$this->belongsTo('Attributes');
$this->belongsTo('CrosscheckAttributes', ['className' => 'Attributes'])
->setForeignKey('crosscheck_attribute_id')
->setProperty('crosscheck_attribute');
$this->belongsTo('Rules');
$this->setDisplayField('id');
$this->setPrimaryLink('rule_id');
$this->setRequiresMatchgrid(true);
$this->setIndexContains(['Attributes']);
$this->setAutoViewVars([
'attributes' => [
'type' => 'select',
'model' => 'Attributes',
'find' => 'filterMatchgrid',
'order' => ['name' => 'ASC']
],
'crosscheckAttributes' => [
'type' => 'select',
'model' => 'Attributes',
'find' => 'filterMatchgrid',
'order' => ['name' => 'ASC']
],
'searchTypes' => [
'type' => 'enum',
'class' => 'SearchTypeEnum'
]
]);
}
/**
* Set validation rules.
*
* @since COmanage Match v1.0.0
* @param Validator $validator Validator
* @return \Cake\Validation\Validator Validator
*/
public function validationDefault(Validator $validator): Validator {
$validator->add(
'rule_id',
'content',
[ 'rule' => 'isInteger' ]
);
$validator->notBlank('rule_id');
$validator->add(
'attribute_id',
'content',
[ 'rule' => 'isInteger' ]
);
$validator->notBlank('attribute_id');
$validator->add(
'crosscheck_attribute_id',
'content',
[ 'rule' => 'isInteger' ]
);
$validator->allowEmptyString('crosscheck_attribute_id');
$validator->add(
'search_type',
'content',
[ 'rule' => [ 'inList', [
SearchTypeEnum::Distance,
SearchTypeEnum::Exact,
SearchTypeEnum::Invalidate,
SearchTypeEnum::Mapping,
SearchTypeEnum::Skip,
SearchTypeEnum::Substring
] ] ]
);
$validator->notEmptyString('search_type');
$validator->add(
'required',
'toggle',
[ 'rule' => [ 'boolean' ] ]
);
$validator->allowEmptyString('required');
$validator->add(
'match_empty',
'toggle',
[ 'rule' => [ 'boolean' ] ]
);
$validator->allowEmptyString('match_empty');
return $validator;
}
}