-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/assign to chapter group #617
Open
belwalshubham
wants to merge
4
commits into
develop
Choose a base branch
from
feat/assign-to-chapter-group
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e1d05b2
assign conatct to chapter group
belwalshubham ef03d00
Merge branch 'develop' of https://github.com/ColoredCow/goonj into fe…
belwalshubham 937ce81
code cleanups
belwalshubham 5d0c1b1
link institution collection camp to contact
belwalshubham File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ | |
use Civi\Api4\CustomField; | ||
use Civi\Api4\Organization; | ||
use Civi\Api4\Relationship; | ||
use Civi\Api4\Group; | ||
use Civi\Api4\GroupContact; | ||
use Civi\Core\Service\AutoSubscriber; | ||
use Civi\Traits\CollectionSource; | ||
|
||
|
@@ -26,7 +28,7 @@ public static function getSubscribedEvents() { | |
'&hook_civicrm_post' => [ | ||
['organizationCreated'], | ||
['setOfficeDetails'], | ||
['assignChapterGroupToIndividual'], | ||
// ['assignChapterGroupToIndividual'], | ||
], | ||
]; | ||
} | ||
|
@@ -87,28 +89,53 @@ private static function getChapterGroupForState($stateId) { | |
/** | ||
* | ||
*/ | ||
public static function assignChapterGroupToIndividual(string $op, string $objectName, int $objectId, &$objectRef) { | ||
return; | ||
if ($objectName !== 'Eck_Collection_Camp' || empty($objectRef['title']) || $objectRef['title'] !== 'Institution Collection Camp') { | ||
return FALSE; | ||
} | ||
$stateId = $objectRef['Institution_Collection_Camp_Intent.State']; | ||
$contactId = $objectRef['Institution_Collection_Camp_Intent.Institution_POC']; | ||
$organizationId = $objectRef['Institution_Collection_Camp_Intent.Organization_Name']; | ||
|
||
if (!$stateId || !$contactId) { | ||
\Civi::log()->info("Missing Contact ID and State ID"); | ||
return FALSE; | ||
} | ||
$groupId = self::getChapterGroupForState($stateId); | ||
// public static function assignChapterGroupToIndividual(string $op, string $objectName, $objectId, &$objectRef) { | ||
// // Define the assignments array | ||
// $assignments = [ | ||
// 'Institution Collection Camp' => [ | ||
// 'stateField' => 'Institution_Collection_Camp_Intent.State', | ||
// 'contactField' => 'Institution_Collection_Camp_Intent.Institution_POC', | ||
// 'organizationField' => 'Institution_Collection_Camp_Intent.Organization_Name' | ||
// ], | ||
// 'Institution Dropping Center' => [ | ||
// 'stateField' => 'Institution_Dropping_Center_Intent.State', | ||
// 'contactField' => 'Institution_Dropping_Center_Intent.Institution_POC', | ||
// 'organizationField' => 'Institution_Dropping_Center_Intent.Organization_Name' | ||
// ] | ||
// ]; | ||
|
||
|
||
|
||
// // Validate objectName and objectRef | ||
// if ($objectName !== 'Eck_Collection_Camp' || empty($objectRef['title']) || !isset($assignments[$objectRef['title']])) { | ||
// return FALSE; | ||
// } | ||
|
||
// $assignment = $assignments[$objectRef['title']]; | ||
|
||
// // Access fields using array syntax | ||
// $stateId = $objectRef[$assignment['stateField']] ?? NULL; | ||
// $contactId = $objectRef[$assignment['contactField']] ?? NULL; | ||
// $organizationId = $objectRef[$assignment['organizationField']] ?? NULL; | ||
|
||
// if (!$stateId || !$contactId) { | ||
// \Civi::log()->info("Missing Contact ID or State ID for " . $objectRef['title']); | ||
// return FALSE; | ||
// } | ||
|
||
// // Get the group and add contacts | ||
// $groupId = self::getChapterGroupForState($stateId); | ||
|
||
// if ($groupId) { | ||
// self::addContactToGroup($contactId, $groupId); | ||
// if ($organizationId) { | ||
// self::addContactToGroup($organizationId, $groupId); | ||
// } | ||
// } | ||
|
||
// return TRUE; | ||
// } | ||
Comment on lines
+92
to
+137
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Refactor commented implementation for better maintainability The commented-out implementation has several areas for improvement:
Here's a suggested refactor: private const INSTITUTION_ASSIGNMENTS = [
self::INSTITUTION_COLLECTION_CAMP => [
'stateField' => 'Institution_Collection_Camp_Intent.State',
'contactField' => 'Institution_Collection_Camp_Intent.Institution_POC',
'organizationField' => 'Institution_Collection_Camp_Intent.Organization_Name'
],
self::INSTITUTION_DROPPING_CENTER => [
'stateField' => 'Institution_Dropping_Center_Intent.State',
'contactField' => 'Institution_Dropping_Center_Intent.Institution_POC',
'organizationField' => 'Institution_Dropping_Center_Intent.Organization_Name'
]
];
public static function assignChapterGroupToIndividual(string $op, string $objectName, $objectId, &$objectRef) {
if (!self::isValidAssignment($objectName, $objectRef)) {
return FALSE;
}
$assignment = self::INSTITUTION_ASSIGNMENTS[$objectRef['title']];
$ids = self::extractAssignmentIds($objectRef, $assignment);
if (!self::areIdsValid($ids)) {
return FALSE;
}
return self::processGroupAssignment($ids);
}
private static function isValidAssignment(string $objectName, array $objectRef): bool {
return $objectName === 'Eck_Collection_Camp'
&& !empty($objectRef['title'])
&& isset(self::INSTITUTION_ASSIGNMENTS[$objectRef['title']]);
}
private static function extractAssignmentIds(array $objectRef, array $assignment): array {
return [
'stateId' => $objectRef[$assignment['stateField']] ?? NULL,
'contactId' => $objectRef[$assignment['contactField']] ?? NULL,
'organizationId' => $objectRef[$assignment['organizationField']] ?? NULL,
];
}
private static function areIdsValid(array $ids): bool {
if (!$ids['stateId'] || !$ids['contactId']) {
\Civi::log()->info("Missing Contact ID or State ID");
return FALSE;
}
return TRUE;
}
private static function processGroupAssignment(array $ids): bool {
$groupId = self::getChapterGroupForState($ids['stateId']);
if (!$groupId) {
return FALSE;
}
self::addContactToGroup($ids['contactId'], $groupId);
if ($ids['organizationId']) {
self::addContactToGroup($ids['organizationId'], $groupId);
}
return TRUE;
} |
||
|
||
if ($groupId) { | ||
self::addContactToGroup($contactId, $groupId); | ||
if ($organizationId) { | ||
self::addContactToGroup($organizationId, $groupId); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid commenting out event subscriptions without proper cleanup
The commented-out event subscription could lead to:
Either remove the line completely or document why it's temporarily disabled.