Skip to content
Permalink
dead5ff318
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
 
 
Cannot retrieve contributors at this time
141 lines (123 sloc) 5.09 KB
<?php
/**
* COmanage Registry People Controller
*
* 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 registry
* @since COmanage Registry v5.0.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/
declare(strict_types = 1);
namespace App\Controller;
// XXX not doing anything with Log yet
use Cake\Log\Log;
use Cake\ORM\TableRegistry;
class PeopleController extends StandardController {
public $paginate = [
'order' => [
// XXX this will sort by family name, but it this universally correct?
// so we need a configuration, or can we do something automagic?
// (ie: what is CJK sort order?)
// C=pinyin, so basically latin; J=KSTNHMYRW/AIUEO; K=hangugl
// so basically a mess... let's just use family name for now and wait for
// (and we haven't even gotten to other languages like Hindi)
// someone to file an RFE
'PrimaryName.family' => 'asc',
'PrimaryName.given' => 'asc'
],
'sortableFields' => [
'PrimaryName.given',
'PrimaryName.family'
]
];
/**
* Callback run prior to the request render.
*
* @since COmanage Registry v5.0.0
* @param EventInterface $event Cake Event
*/
public function beforeRender(\Cake\Event\EventInterface $event) {
if(!$this->request->is('restful') && $this->request->getParam('action') == 'add') {
// Get the set of permitted and required name fields to pass to the view.
// We need to pull a few settings for default enrollment.
// XXX maybe $CoSettings should be available via AppController, like $this->getCOID()?
$CoSettings = TableRegistry::getTableLocator()->get('CoSettings');
$settings = $CoSettings->find()->where(['co_id' => $this->getCOID()])->firstOrFail();
$this->set('vv_permitted_name_fields', $settings->name_permitted_fields_array());
$this->set('vv_required_name_fields', $settings->name_required_fields_array());
$this->set('vv_default_name_type', $settings->default_name_type_id);
}
return parent::beforeRender($event);
}
/**
* Person overview / canvas
*
* @since COmanage Registry v5.0.0
*/
public function canvas(string $id) {
/* XXX Simply including parent::edit() is nearly all that's required - but we need
to delve a little deeper to get data from underlying relationships. We might send a contains()
override to parent::edit() which would allow this to be more DRY
// Keep the following as an example for now.
parent::edit($id, false);
// We've just set the vv_supertitle in the parent controller.
// Pass it to the title for use in the breadcrumbs.
$this->set('vv_title', $this->viewBuilder()->getVar('vv_supertitle'));
*/
/* The following is nearly identical to parent::edit/view */
$modelsName = $this->name;
$table = $this->$modelsName;
$tableName = $table->getTable();
$query = $table->findById($id);
// This contain() directive is the primary deviation from standard edit()/view().
// We need to drill down to deeper related models for display.
$query = $query->contain([
'PrimaryName',
'Names' => ['Types'],
'Addresses' => ['Types'],
'AdHocAttributes',
'EmailAddresses' => ['Types'],
'GroupMembers',
'GroupOwners',
'Identifiers' => ['Types'],
'PersonRoles' => ['Cous','Types'],
'Pronouns',
'TelephoneNumbers' => ['Types'],
'Urls' => ['Types']
]);
try {
// Pull the current record
$obj = $query->firstOrFail();
} catch(\Exception $e) {
// findById throws Cake\Datasource\Exception\RecordNotFoundException
$this->Flash->error($e->getMessage());
// XXX This redirects to an Exception page because $id is not found.
// XXX A 404 with error would be better.
return $this->generateRedirect((int)$id);
}
$this->set('vv_obj', $obj);
$this->getPrimaryLink();
$this->populateAutoViewVars($obj);
$this->set('vv_title', $table->generateDisplayField($obj));
$this->set('vv_supertitle', $table->generateDisplayField($obj));
// Pass the display field also into subtitle for dealing with External IDs
$this->set('vv_subtitle', $table->generateDisplayField($obj));
}
}