Add Activity tab for goonj activity#512
Conversation
WalkthroughThe changes in this pull request focus on the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Outside diff range and nitpick comments (2)
wp-content/civi-extensions/goonjcustom/Civi/GoonjActivitiesService.php (2)
580-581: Remove redundant comment markers for clarityThe comments have double slashes (
// //), which is unnecessary and may reduce readability. Consider cleaning up the comment syntax.Apply this diff to fix the comments:
- // // Check for status change. - // // Access the id within the decoded data. + // Check for status change. + // Access the id within the decoded data.
593-605: Refactor handling of 'Other' activity for clarity and maintainabilityThe current logic for handling the 'Other' activity involves nested conditionals. Consider extracting this into a separate method or simplifying the logic to enhance readability and adhere to the Single Responsibility Principle.
Optionally, refactor the code as follows:
foreach ($activities as $activityName) { - // Check if the activity is 'Others'. - if ($activityName == 'Other') { - $otherActivity = $objectRef['Goonj_Activities.Other_Activity_Details'] ?? ''; - - if ($otherActivity) { - // Use the 'Other_activity' field as the title. - $activityName = $otherActivity; - } else { - continue; - } - } + $activityName = self::resolveActivityName($activityName, $objectRef); + if (!$activityName) { + continue; + } // Rest of the code... } + private static function resolveActivityName($activityName, $objectRef) + { + if ($activityName == 'Other') { + $otherActivity = $objectRef['Goonj_Activities.Other_Activity_Details'] ?? ''; + return $otherActivity ?: null; + } + return $activityName; + }
| public static function createActivityForGoonjActivityCollectionCamp(string $op, string $objectName, $objectId, &$objectRef) { | ||
| if ($objectName != 'Eck_Collection_Camp' || self::getEntitySubtypeName($objectId) !== self::ENTITY_SUBTYPE_NAME) { | ||
| return; | ||
| } | ||
|
|
||
| $newStatus = $objectRef['Collection_Camp_Core_Details.Status'] ?? ''; | ||
|
|
||
| if (!$newStatus || !$objectId) { | ||
| return; | ||
| } | ||
|
|
||
| $collectionCamp = EckEntity::get('Collection_Camp', FALSE) | ||
| ->addSelect('Collection_Camp_Core_Details.Status', 'Collection_Camp_Core_Details.Contact_Id', 'title') | ||
| ->addWhere('id', '=', $objectId) | ||
| ->execute()->single(); | ||
|
|
||
| $currentStatus = $collectionCamp['Collection_Camp_Core_Details.Status']; | ||
|
|
||
| if ($currentStatus === $newStatus || $newStatus !== 'authorized') { | ||
| return; | ||
| } | ||
|
|
||
| // // Check for status change. | ||
| // // Access the id within the decoded data. | ||
| $campId = $objectRef['id']; | ||
|
|
||
| if ($campId === NULL) { | ||
| return; | ||
| } | ||
|
|
||
| $activities = $objectRef['Goonj_Activities.How_do_you_want_to_engage_with_Goonj_']; | ||
| $startDate = $objectRef['Goonj_Activities.Start_Date']; | ||
| $endDate = $objectRef['Goonj_Activities.End_Date']; | ||
| $initiator = $objectRef['Collection_Camp_Core_Details.Contact_Id']; | ||
|
|
||
| foreach ($activities as $activityName) { | ||
| // Check if the activity is 'Others'. | ||
| if ($activityName == 'Other') { | ||
| $otherActivity = $objectRef['Goonj_Activities.Other_Activity_Details'] ?? ''; | ||
|
|
||
| if ($otherActivity) { | ||
| // Use the 'Other_activity' field as the title. | ||
| $activityName = $otherActivity; | ||
| } | ||
| else { | ||
| continue; | ||
| } | ||
| } | ||
|
|
||
| $optionValue = OptionValue::get(TRUE) | ||
| ->addSelect('value') | ||
| ->addWhere('option_group_id:name', '=', 'eck_sub_types') | ||
| ->addWhere('grouping', '=', 'Collection_Camp_Activity') | ||
| ->addWhere('name', '=', 'Goonj_Activities') | ||
| ->execute()->single(); | ||
|
|
||
| $results = EckEntity::create('Collection_Camp_Activity', TRUE) | ||
| ->addValue('title', $activityName) | ||
| ->addValue('subtype', $optionValue['value']) | ||
| ->addValue('Collection_Camp_Activity.Collection_Camp_Id', $campId) | ||
| ->addValue('Collection_Camp_Activity.Start_Date', $startDate) | ||
| ->addValue('Collection_Camp_Activity.End_Date', $endDate) | ||
| ->addValue('Collection_Camp_Activity.Organizing_Person', $initiator) | ||
| ->execute(); | ||
| } | ||
| } |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Refactor 'createActivityForGoonjActivityCollectionCamp' method to improve readability
The method is lengthy with multiple nested conditionals and responsibilities. Breaking it into smaller, dedicated methods can enhance readability and maintainability, aligning with best practices like the Single Responsibility Principle.
Consider refactoring the method into smaller helper functions:
- One function to validate inputs and state.
- One function to handle 'Other' activities.
- One function to create the activities.
| if ($objectRef['subtype']) { | ||
| !self::isCurrentSubtype($objectRef); | ||
| } |
There was a problem hiding this comment.
Fix incorrect usage of the negation operator in conditional statement
The expression !self::isCurrentSubtype($objectRef); doesn't have any effect since it's not part of a conditional check. It seems you intended to check if self::isCurrentSubtype($objectRef) returns false and return early.
Apply this diff to correct the conditional logic:
if ($objectRef['subtype']) {
- !self::isCurrentSubtype($objectRef);
+ if (!self::isCurrentSubtype($objectRef)) {
+ return;
+ }
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if ($objectRef['subtype']) { | |
| !self::isCurrentSubtype($objectRef); | |
| } | |
| if ($objectRef['subtype']) { | |
| if (!self::isCurrentSubtype($objectRef)) { | |
| return; | |
| } | |
| } |
| $activities = $objectRef['Goonj_Activities.How_do_you_want_to_engage_with_Goonj_']; | ||
| $startDate = $objectRef['Goonj_Activities.Start_Date']; | ||
| $endDate = $objectRef['Goonj_Activities.End_Date']; | ||
| $initiator = $objectRef['Collection_Camp_Core_Details.Contact_Id']; |
There was a problem hiding this comment.
Ensure variables are set before usage to prevent undefined index errors
Before using $activities, $startDate, $endDate, and $initiator, check if these keys exist in $objectRef to avoid potential undefined index notices or errors if the expected data is missing.
Apply this diff to add necessary checks:
+ if (
+ !isset($objectRef['Goonj_Activities.How_do_you_want_to_engage_with_Goonj_']) ||
+ !isset($objectRef['Goonj_Activities.Start_Date']) ||
+ !isset($objectRef['Goonj_Activities.End_Date']) ||
+ !isset($objectRef['Collection_Camp_Core_Details.Contact_Id'])
+ ) {
+ return;
+ }
$activities = $objectRef['Goonj_Activities.How_do_you_want_to_engage_with_Goonj_'];
$startDate = $objectRef['Goonj_Activities.Start_Date'];
$endDate = $objectRef['Goonj_Activities.End_Date'];
$initiator = $objectRef['Collection_Camp_Core_Details.Contact_Id'];📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| $activities = $objectRef['Goonj_Activities.How_do_you_want_to_engage_with_Goonj_']; | |
| $startDate = $objectRef['Goonj_Activities.Start_Date']; | |
| $endDate = $objectRef['Goonj_Activities.End_Date']; | |
| $initiator = $objectRef['Collection_Camp_Core_Details.Contact_Id']; | |
| if ( | |
| !isset($objectRef['Goonj_Activities.How_do_you_want_to_engage_with_Goonj_']) || | |
| !isset($objectRef['Goonj_Activities.Start_Date']) || | |
| !isset($objectRef['Goonj_Activities.End_Date']) || | |
| !isset($objectRef['Collection_Camp_Core_Details.Contact_Id']) | |
| ) { | |
| return; | |
| } | |
| $activities = $objectRef['Goonj_Activities.How_do_you_want_to_engage_with_Goonj_']; | |
| $startDate = $objectRef['Goonj_Activities.Start_Date']; | |
| $endDate = $objectRef['Goonj_Activities.End_Date']; | |
| $initiator = $objectRef['Collection_Camp_Core_Details.Contact_Id']; |
Add Activity tab for goonj activity
Summary by CodeRabbit
New Features
Bug Fixes
Documentation