Skip to content

Commit

Permalink
Fix EnrollmentFlow broken start view. Fix petitions view.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis committed Dec 15, 2024
1 parent 373d5a4 commit a4b7b48
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 74 deletions.
10 changes: 9 additions & 1 deletion app/src/View/Helper/FieldHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@
class FieldHelper extends Helper {
public $helpers = ['Form', 'Html'];

/**
* List of predefined editable form actions
*/
public const EDITABLE_ACTIONS = [
'add', 'edit', // CRUD actions
'start' // ENROLLMENT FLOW actions
];

// Is this read-only or read-write?
protected bool $editable = true;

Expand Down Expand Up @@ -74,7 +82,7 @@ public function initialize(array $config): void
$this->reqFields = $this->getView()->get('vv_required_fields');
$this->modelName = $this->getView()->getName();
$this->action = $this->getView()->get('vv_action');
$this->editable = \in_array($this->action, ['add', 'edit']);
$this->editable = \in_array($this->action, self::EDITABLE_ACTIONS, true);
$this->pluginName = $this->getView()->getPlugin();
$this->entity = $this->getView()->get('vv_obj');
$this->fieldTypes = $this->getView()->get('vv_field_types');
Expand Down
3 changes: 3 additions & 0 deletions app/templates/EnrollmentFlows/fields.inc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
* @since COmanage Registry v5.0.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/

declare(strict_types = 1);

?>
<script type="text/javascript">
// JS specific to these fields
Expand Down
51 changes: 51 additions & 0 deletions app/templates/EnrollmentFlows/start.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/**
* COmanage Registry Enrollment Flow Start Fields
*
* 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);

// $this->name = Models
$modelsName = $this->name;
// $tablename = models
$tableName = \Cake\Utility\Inflector::tableize(\Cake\Utility\Inflector::singularize($this->name));
// Table Reference
$modelTable = $this->Tab->getModelTableReference($modelsName);


// For now, we just request the enrollee email. We're only called if
// collect_enrollee_email is true, so we don't need to check it, though
// if we ever add more fields to the start form we should.
print $this->element('form/listItem', [
'arguments' => [
'fieldName' => 'enrollee_email',
'fieldOptions' => [
'required' => true
],
'fieldType' => 'string'
]
]);

// Any hidden fields??
26 changes: 6 additions & 20 deletions app/templates/EnrollmentFlows/start.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,13 @@

declare(strict_types = 1);

// For now, we just request the enrollee email. We're only called if
// collect_enrollee_email is true, so we don't need to check it, though
// if we ever add more fields to the start form we should.
// Enrollment Flow Start has its own file of fields
$this->set('vv_fields_inc', 'start.inc');

// Create the Form
print $this->Form->create();

print $this->Field->startControlSet(
modelName: $this->name,
action: $vv_action,
editable: true,
reqFields: []
);

print $this->Field->control(
fieldName: 'enrollee_email',
controlType: 'string',
options: ['required' => true]
);

print $this->Field->submit(__d('operation', 'save'));

// Form body
print $this->element('form/unorderedList');
// Close the Form
print $this->Form->end();

print $this->Field->endControlSet();
106 changes: 53 additions & 53 deletions app/templates/Petitions/fields.inc
Original file line number Diff line number Diff line change
Expand Up @@ -25,63 +25,63 @@
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/

declare(strict_types = 1);

use \Cake\Utility\Hash;

// Petitions are read-only, though they can link to other actions
if($vv_action == 'view') {
// Start with the petition metadata
print $this->Field->control('status');

print $this->Field->statusControl(
fieldName: 'enrollee_person_id',
status: !empty($vv_obj->enrollee_person->primary_name)
? $vv_obj->enrollee_person->primary_name->full_name
: __d('field', 'Petitions.enrollee.new'),
link: (!empty($vv_obj->enrollee_person->id)
? ['url' => [
'controller' => 'people',
'action' => 'edit',
$vv_obj->enrollee_person_id
]]
: [])
);

print $this->Field->statusControl(
fieldName: 'petitioner_person_id',
status: !empty($vv_obj->petitioner_person->primary_name)
? $vv_obj->petitioner_person->primary_name->full_name
: "",
link: (!empty($vv_obj->petitioner_person->id)
? ['url' => [
'controller' => 'people',
'action' => 'edit',
$vv_obj->enrollee_person_id
]]
: [])
);

// XXX petitioner_identifier if set?
print "<ol>\n";

// XXX merge this with resume?
foreach($vv_obj->enrollment_flow->enrollment_flow_steps as $step) {
$stepId = $step->id;

print "<li>" . $step->description;
print $this->element('form/listItem', [
'arguments' => [
'fieldName' => 'status',
]
]);

$result = \Cake\Utility\Hash::extract($vv_obj->petition_step_results, "{n}[enrollment_flow_step_id=$stepId]");
// Enrollee
$enrolleeStatus = $vv_obj->enrollee_person->primary_name->full_name ?? __d('field', 'Petitions.enrollee.new');
$enrolleeLink = [
'url' => [
'controller' => 'people',
'action' => 'edit',
$vv_obj->enrollee_person_id
]
];
print $this->element('form/listItem', [
'arguments' => [
'fieldName' => 'enrollee_person_id',
'status' => $enrolleeStatus,
'link' => !empty($vv_obj->enrollee_person->id) ? $enrolleeLink : [],
]
]);

if(!empty($result)) {
print ", Result: " . $result[0]->comment
. $this->Html->link(' (View)', [
'controller' => 'petitions',
'action' => 'result',
$vv_obj->id,
'?' => ['enrollment_flow_step_id' => $step->id]
]);
}
// Petitioner
$petitionerStatus = $vv_obj?->petitioner_person?->primary_name?->full_name ?? '';
$petitionerLink = [
'url' => [
'controller' => 'people',
'action' => 'edit',
$vv_obj->petitioner_person->id
]
];
print $this->element('form/listItem', [
'arguments' => [
'fieldName' => 'petitioner_person_id',
'status' => $petitionerStatus,
'link' => !empty($vv_obj->petitioner_person->id) ? $petitionerLink : []
]
]);

print "</li>\n";
}
?>

print "</ol>\n";
}
<ol>
<?php foreach($vv_obj->enrollment_flow->enrollment_flow_steps as $step): ?>
<li><?= $step->description ?>
<?php $result = Hash::extract($vv_obj->petition_step_results, "{n}[enrollment_flow_step_id=$step->id]"); ?>
<?php if (!empty($result)): ?>
<pre> ,Result: <?= $result[0]->comment ?></pre>
<a class="ml-1" href="petitions/result/<?= $vv_obj->id ?>?enrollment_flow_step_id=<?=$step->id?>">(View)</a>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ol>

0 comments on commit a4b7b48

Please sign in to comment.