From bf630e47c0877b0e130f0dcb913f75aded724e53 Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Mon, 10 Feb 2025 23:24:27 +0200 Subject: [PATCH] Move petition Enrollment Flow steps preview to cells --- .../src/View/Cell/AttributeCollectorsCell.php | 89 +++++++++++++++++++ .../Cell/BasicAttributeCollectorsCell.php | 81 +++++++++++++++++ .../src/View/Cell/EmailVerifiersCell.php | 85 ++++++++++++++++++ .../View/Cell/IdentifierCollectorsCell.php | 80 +++++++++++++++++ .../src/View/Cell/InvitationAcceptersCell.php | 80 +++++++++++++++++ .../AttributeCollectors/display.php} | 16 +--- .../BasicAttributeCollectors/display.php} | 14 ++- .../templates/cell/EmailVerifiers/display.php | 53 +++++++++++ .../cell/IdentifierCollectors/display.php | 39 ++++++++ .../cell/InvitationAccepters/display.php | 50 +++++++++++ .../element/petition/emailVerifiersStep.php | 32 ------- .../petition/identifierCollectorsStep.php | 8 -- .../petition/invitationAcceptersStep.php | 23 ----- .../View/Cell/AttributeCollectorsCellTest.php | 70 +++++++++++++++ .../Cell/BasicAttributeCollectorsCellTest.php | 70 +++++++++++++++ .../View/Cell/EmailVerifiersCellTest.php | 70 +++++++++++++++ .../Cell/IdentifierCollectorsCellTest.php | 70 +++++++++++++++ .../View/Cell/InvitationAcceptersCellTest.php | 70 +++++++++++++++ app/src/Model/Table/PersonRolesTable.php | 4 +- app/templates/Petitions/fields.inc | 7 +- 20 files changed, 916 insertions(+), 95 deletions(-) create mode 100644 app/plugins/CoreEnroller/src/View/Cell/AttributeCollectorsCell.php create mode 100644 app/plugins/CoreEnroller/src/View/Cell/BasicAttributeCollectorsCell.php create mode 100644 app/plugins/CoreEnroller/src/View/Cell/EmailVerifiersCell.php create mode 100644 app/plugins/CoreEnroller/src/View/Cell/IdentifierCollectorsCell.php create mode 100644 app/plugins/CoreEnroller/src/View/Cell/InvitationAcceptersCell.php rename app/plugins/CoreEnroller/templates/{element/petition/attributeCollectorsStep.php => cell/AttributeCollectors/display.php} (85%) rename app/plugins/CoreEnroller/templates/{element/petition/basicAttributeCollectorsStep.php => cell/BasicAttributeCollectors/display.php} (86%) create mode 100644 app/plugins/CoreEnroller/templates/cell/EmailVerifiers/display.php create mode 100644 app/plugins/CoreEnroller/templates/cell/IdentifierCollectors/display.php create mode 100644 app/plugins/CoreEnroller/templates/cell/InvitationAccepters/display.php delete mode 100644 app/plugins/CoreEnroller/templates/element/petition/emailVerifiersStep.php delete mode 100644 app/plugins/CoreEnroller/templates/element/petition/identifierCollectorsStep.php delete mode 100644 app/plugins/CoreEnroller/templates/element/petition/invitationAcceptersStep.php create mode 100644 app/plugins/CoreEnroller/tests/TestCase/View/Cell/AttributeCollectorsCellTest.php create mode 100644 app/plugins/CoreEnroller/tests/TestCase/View/Cell/BasicAttributeCollectorsCellTest.php create mode 100644 app/plugins/CoreEnroller/tests/TestCase/View/Cell/EmailVerifiersCellTest.php create mode 100644 app/plugins/CoreEnroller/tests/TestCase/View/Cell/IdentifierCollectorsCellTest.php create mode 100644 app/plugins/CoreEnroller/tests/TestCase/View/Cell/InvitationAcceptersCellTest.php diff --git a/app/plugins/CoreEnroller/src/View/Cell/AttributeCollectorsCell.php b/app/plugins/CoreEnroller/src/View/Cell/AttributeCollectorsCell.php new file mode 100644 index 000000000..bef6e3072 --- /dev/null +++ b/app/plugins/CoreEnroller/src/View/Cell/AttributeCollectorsCell.php @@ -0,0 +1,89 @@ + + */ + protected $_validCellOptions = [ + 'vv_obj', + 'vv_step', + 'viewVars', + ]; + + /** + * Initialization logic run at the end of object construction. + * + * @return void + */ + public function initialize(): void + { + } + + /** + * Default display method. + * + * @param int $petitionId + * @return void + * @since COmanage Registry v5.1.0 + */ + public function display(int $petitionId): void + { + $vv_enrollment_atttributes_ids = Hash::extract($this->vv_obj->petition_attributes, '{n}.enrollment_attribute_id'); + $vv_enrollment_atttributes_ids = array_unique($vv_enrollment_atttributes_ids); + + $vv_enrollment_attributes = $this->fetchTable('EnrollmentAttributes') + ->find() + ->where(fn(QueryExpression $exp, Query $q) => $exp->in('id', $vv_enrollment_atttributes_ids)) + ->order(['ordr' => 'ASC']) + ->toArray(); + + $this->set('vv_enrollment_attributes', $vv_enrollment_attributes); + $this->set('vv_step', $this->vv_step); + $this->set('vv_obj', $this->vv_obj); + } +} diff --git a/app/plugins/CoreEnroller/src/View/Cell/BasicAttributeCollectorsCell.php b/app/plugins/CoreEnroller/src/View/Cell/BasicAttributeCollectorsCell.php new file mode 100644 index 000000000..16e12361b --- /dev/null +++ b/app/plugins/CoreEnroller/src/View/Cell/BasicAttributeCollectorsCell.php @@ -0,0 +1,81 @@ + + */ + protected $_validCellOptions = [ + 'vv_obj', + 'vv_step', + 'viewVars', + ]; + + /** + * Initialization logic run at the end of object construction. + * + * @return void + */ + public function initialize(): void + { + } + + /** + * Default display method. + * + * @param int $petitionId + * @return string + * @since COmanage Registry v5.1.0 + */ + public function display(int $petitionId): void + { + $vv_petition_basic_attribute_set = $this->fetchTable('PetitionBasicAttributeSets') + ->find() + ->where(['PetitionBasicAttributeSets.petition_id' => $this->vv_obj->id]) + ->firstOrFail(); + + $this->set('vv_petition_basic_attribute_set', $vv_petition_basic_attribute_set); + $this->set('vv_obj', $this->vv_obj); + } +} diff --git a/app/plugins/CoreEnroller/src/View/Cell/EmailVerifiersCell.php b/app/plugins/CoreEnroller/src/View/Cell/EmailVerifiersCell.php new file mode 100644 index 000000000..e855b6e2a --- /dev/null +++ b/app/plugins/CoreEnroller/src/View/Cell/EmailVerifiersCell.php @@ -0,0 +1,85 @@ + + */ + protected $_validCellOptions = [ + 'vv_obj', + 'vv_step', + 'viewVars', + ]; + + /** + * Initialization logic run at the end of object construction. + * + * @return void + */ + public function initialize(): void + { + } + + /** + * Default display method. + * + * @param int $petitionId + * @return void + * @since COmanage Registry v5.1.0 + */ + public function display(int $petitionId): void + { + // Because Petition Verifications are not tracked on a per-step basis, we just pull all + // associated with the Petition + + $vv_pv = $this->fetchTable('CoreEnroller.PetitionVerifications') + ->find() + ->where(['PetitionVerifications.petition_id' => $this->vv_obj->id]) + ->contain(['Verifications']) + ->all(); + + $this->set('vv_pv', $vv_pv); + $this->set('viewVars', $this->viewVars); + } +} diff --git a/app/plugins/CoreEnroller/src/View/Cell/IdentifierCollectorsCell.php b/app/plugins/CoreEnroller/src/View/Cell/IdentifierCollectorsCell.php new file mode 100644 index 000000000..af18eb85b --- /dev/null +++ b/app/plugins/CoreEnroller/src/View/Cell/IdentifierCollectorsCell.php @@ -0,0 +1,80 @@ + + */ + protected $_validCellOptions = [ + 'vv_obj', + 'vv_step', + 'viewVars', + ]; + + /** + * Initialization logic run at the end of object construction. + * + * @return void + */ + public function initialize(): void + { + } + + /** + * Default display method. + * + * @param int $petitionId + * @return void + * @since COmanage Registry v5.1.0 + */ + public function display(int $petitionId): void + { + $vv_pi = $this->fetchTable('CoreEnroller.PetitionIdentifiers') + ->find() + ->where(['petition_id' => $this->vv_obj->id]) + ->first(); + + $this->set('vv_pi', $vv_pi); + } +} diff --git a/app/plugins/CoreEnroller/src/View/Cell/InvitationAcceptersCell.php b/app/plugins/CoreEnroller/src/View/Cell/InvitationAcceptersCell.php new file mode 100644 index 000000000..320b8dc87 --- /dev/null +++ b/app/plugins/CoreEnroller/src/View/Cell/InvitationAcceptersCell.php @@ -0,0 +1,80 @@ + + */ + protected $_validCellOptions = [ + 'vv_obj', + 'vv_step', + 'viewVars', + ]; + + /** + * Initialization logic run at the end of object construction. + * + * @return void + */ + public function initialize(): void + { + } + + /** + * Default display method. + * + * @param int $petitionId + * @return void + * @since COmanage Registry v5.1.0 + */ + public function display(int $petitionId): void + { + $vv_pa = $this->fetchTable('CoreEnroller.PetitionAcceptances') + ->find() + ->where(['petition_id' => $this->vv_obj->id]) + ->first(); + + $this->set('vv_pa', $vv_pa); + } +} diff --git a/app/plugins/CoreEnroller/templates/element/petition/attributeCollectorsStep.php b/app/plugins/CoreEnroller/templates/cell/AttributeCollectors/display.php similarity index 85% rename from app/plugins/CoreEnroller/templates/element/petition/attributeCollectorsStep.php rename to app/plugins/CoreEnroller/templates/cell/AttributeCollectors/display.php index 0293a519f..e2d44c602 100644 --- a/app/plugins/CoreEnroller/templates/element/petition/attributeCollectorsStep.php +++ b/app/plugins/CoreEnroller/templates/cell/AttributeCollectors/display.php @@ -1,6 +1,6 @@ petition_attributes, '{n}.enrollment_attribute_id'); -$vv_enrollment_atttributes_ids = array_unique($vv_enrollment_atttributes_ids); - -$enrollmentAttributesTable = $this->Petition->getTable('EnrollmentAttributes'); -$vv_enrollment_attributes = $enrollmentAttributesTable->find() - ->where(fn(QueryExpression $exp, Query $q) => $exp->in('id', $vv_enrollment_atttributes_ids)) - ->order(['ordr' => 'ASC']) - ->toArray(); - ?>