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
1 contributor

Users who have contributed to this file

148 lines (126 sloc) 4.11 KB
<?php
/**
* COmanage Match Systems of Record 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\ResolutionModeEnum;
use \App\Lib\Enum\TrustModeEnum;
class SystemsOfRecordTable extends Table {
use \App\Lib\Traits\AutoViewVarsTrait;
use \App\Lib\Traits\MatchgridLinkTrait;
use \App\Lib\Traits\PrimaryLinkTrait;
/**
* 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->hasMany('ApiUsers');
$this->belongsTo('Matchgrids');
$this->setDisplayField('label');
$this->setPrimaryLink('matchgrid_id');
$this->setRequiresMatchgrid(true);
$this->setAutoViewVars([
'resolutionModes' => [
'type' => 'enum',
'class' => 'ResolutionModeEnum'
],
'trustModes' => [
'type' => 'enum',
'class' => 'TrustModeEnum'
]
]);
}
/**
* Determine the trust mode setting for the requested SOR within the matchgrid.
*
* @since COmanage Match v1.2.0
* @param int $matchgridId Matchgrid ID
* @param string $sorLabel System of Record Label
*/
public function getTrustMode(int $matchgridId, string $sorLabel) {
$systemOfRecord = $this->find()
->where([
'matchgrid_id' => $matchgridId,
'label' => $sorLabel
])
->firstOrFail();
return $systemOfRecord->trust_mode;
}
/**
* 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(
'label',
'length',
[ 'rule' => [ 'maxLength', 80 ],
'message' => __('match.er.val.length', [80]) ]
);
$validator->notEmptyString('label');
$validator->add(
'matchgrid_id',
'content',
[ 'rule' => 'isInteger' ]
);
$validator->notBlank('matchgrid_id');
$validator->add(
'trust_mode',
'content',
[ 'rule' => [ 'inList', TrustModeEnum::getConstValues() ] ]
);
$validator->notEmptyString('trust_mode');
$validator->add(
'resolution_mode',
'content',
[ 'rule' => [ 'inList', ResolutionModeEnum::getConstValues() ] ]
);
$validator->notEmptyString('resolution_mode');
$validator->add(
'notification_email',
'length',
[ 'rule' => [ 'maxLength', 80 ],
'message' => __('match.er.val.length', [80]) ]
);
$validator->add(
'notification_email',
'content',
[ 'rule' => 'email',
'message' => __('match.er.val.email') ]
);
$validator->allowEmptyString('notification_email');
return $validator;
}
}