Permalink
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?
match/app/src/Model/Table/MatchgridHistoryRecordsTable.php
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

…story Records (CO-1682)
183 lines (158 sloc)
5.33 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* COmanage Match Matchgrid History Records 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 https://www.internet2.edu/comanage COmanage Project | |
* @package match | |
* @since COmanage Match v1.1.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; | |
class MatchgridHistoryRecordsTable extends Table { | |
use \App\Lib\Traits\AutoViewVarsTrait; | |
use \App\Lib\Traits\MatchgridLinkTrait; | |
use \App\Lib\Traits\PrimaryLinkTrait; | |
use \App\Lib\Traits\SearchFilterTrait; | |
/** | |
* Perform Cake Model initialization. | |
* | |
* @since COmanage Match v1.1.0 | |
* @param array $config Configuration options passed to constructor | |
*/ | |
public function initialize(array $config): void { | |
$this->addBehavior('Timestamp'); | |
// Define associations | |
$this->belongsTo('Matchgrids'); | |
// We don't use "comment" here because it might be lengthy | |
$this->setDisplayField('id'); | |
$this->setPrimaryLink('matchgrid_id'); | |
$this->setRequiresMatchgrid(true); | |
$this->setAutoViewVars([ | |
'sor' => [ | |
'type' => 'list', | |
'model' => 'SystemsOfRecord', | |
'find' => 'filterPrimaryLink', | |
// Because matchgrids use the actual SOR label and not systems_of_record_id | |
// we need a custom select field | |
'fields' => ['keyField' => 'label', 'valueField' => 'label'], | |
'order' => ['label' => 'ASC'] | |
] | |
]); | |
// Always permit search on SOR, SORID, and Reference ID | |
$this->setSearchFilter('sor', true, null, false); | |
$this->setSearchFilter('sorid', true, null, false); | |
} | |
/** | |
* Record a Matchgrid History Record. | |
* | |
* @since COmanage Match v1.1.0 | |
* @param int $matchgridId Matchgrid ID | |
* @param string $sorLabel System of Record Label | |
* @param string $sorid System of Record Identifier | |
* @param string $action Transaction code | |
* @param string $comment Human readable comment | |
* @param string $remoteIp Remote IP | |
* @param string $actorIdentifier Actor Identifier | |
*/ | |
public function record(int $matchgridId, | |
string $sorLabel, | |
string $sorid, | |
string $action, | |
string $comment, | |
string $remoteIp=null, | |
string $actorIdentifier=null) { | |
$obj = $this->newEntity([ | |
"matchgrid_id" => $matchgridId, | |
"sor" => $sorLabel, | |
"sorid" => $sorid, | |
"action" => $action, | |
"comment" => $comment, | |
"remote_ip" => $remoteIp, | |
"actor_identifier" => $actorIdentifier | |
]); | |
$this->saveOrFail($obj); | |
} | |
/** | |
* Set validation rules. | |
* | |
* @since COmanage Match v1.1.0 | |
* @param Validator $validator Validator | |
* @return \Cake\Validation\Validator Validator | |
*/ | |
public function validationDefault(Validator $validator): Validator { | |
$validator->add( | |
'matchgrid_id', | |
'content', | |
[ 'rule' => 'isInteger' ] | |
); | |
$validator->notBlank('matchgrid_id'); | |
$validator->add( | |
'sor', | |
'length', | |
[ 'rule' => [ 'maxLength', 80 ], | |
'message' => __('match.er.val.length', [80]) ] | |
); | |
$validator->notEmptyString('sor'); | |
$validator->add( | |
'sorid', | |
'length', | |
[ 'rule' => [ 'maxLength', 64 ], | |
'message' => __('match.er.val.length', [64]) ] | |
); | |
$validator->notEmptyString('sorid'); | |
$validator->add( | |
'action', | |
'length', | |
[ 'rule' => [ 'maxLength', 4 ], | |
'message' => __('match.er.val.length', [4]) ] | |
); | |
$validator->notEmptyString('action'); | |
$validator->add( | |
'comment', | |
'length', | |
[ 'rule' => [ 'maxLength', 256 ], | |
'message' => __('match.er.val.length', [256]) ] | |
); | |
$validator->notEmptyString('comment'); | |
$validator->add( | |
'remote_ip', | |
'ip', | |
[ 'rule' => [ 'ip' ]] | |
); | |
$validator->add( | |
'remote_ip', | |
'length', | |
[ 'rule' => [ 'maxLength', 80 ], | |
'message' => __('match.er.val.length', [80]) ] | |
); | |
$validator->allowEmptyString('remote_ip'); | |
$validator->add( | |
'actor_identifier', | |
'length', | |
[ 'rule' => [ 'maxLength', 256 ], | |
'message' => __('match.er.val.length', [256]) ] | |
); | |
$validator->allowEmptyString('actor_identifier'); | |
return $validator; | |
} | |
} |