Skip to content
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/institute goonj activities #591

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

nishant22029
Copy link
Collaborator

@nishant22029 nishant22029 commented Dec 10, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a new service for managing Goonj activities, including event subscriptions and QR code generation.
    • Added mappings for the Institute_Goonj_Activities entity to enhance data processing.
    • Expanded event code list with a new entry for 'Institution Goonj Activities'.
  • Bug Fixes

    • Activated previously commented-out mappings for various entities to ensure proper functionality.

@nishant22029 nishant22029 self-assigned this Dec 10, 2024
Copy link

coderabbitai bot commented Dec 10, 2024

Walkthrough

The pull request introduces modifications to the CollectionBaseService class, updates the IntitutionGoonjActivitiesService class, and adds a new entry to the eventCode.php configuration file. The getStateGroupNameMapper method in CollectionBaseService now includes active mappings for several entities. The newly created IntitutionGoonjActivitiesService class provides functionalities for managing Goonj institution activities, including event subscription methods. Additionally, a new event code for "Institution Goonj Activities" is added to the configuration.

Changes

File Path Change Summary
wp-content/civi-extensions/goonjcustom/Civi/CollectionBaseService.php Updated getStateGroupNameMapper to include active mappings for Institute_Goonj_Activities and others.
wp-content/civi-extensions/goonjcustom/Civi/IntitutionGoonjActivitiesService.php Added IntitutionGoonjActivitiesService class with various methods for managing Goonj activities and events.
wp-content/civi-extensions/goonjcustom/config/eventCode.php Added new entry: 'Institution Goonj Activities' => 'GA' to the event codes array.

Possibly related PRs

Suggested labels

status : ready for review

Suggested reviewers

  • tarunnjoshi

🌟 In the code, new mappings arise,
For Goonj activities, the service now flies.
With events and hooks, it dances with glee,
Managing collections, oh so effortlessly!
A new code entry, bright as a star,
In the world of Civi, it’ll go far! 🌟


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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Experiment)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@nishant22029 nishant22029 marked this pull request as draft December 10, 2024 06:29
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 9

🧹 Outside diff range and nitpick comments (6)
wp-content/civi-extensions/goonjcustom/Civi/IntitutionGoonjActivitiesService.php (4)

869-911: Code Duplication in Address Handling

The methods setGoonjActivitiesAddress and setActivitiesVolunteersAddress contain similar logic for setting addresses.

Consider consolidating the shared logic into a private helper method to avoid duplication and enhance maintainability.


625-628: Consider Using 'mt_rand()' Instead of 'rand()'

The method getCoordinator uses rand() for random selection, which may have lower randomness quality.

Replace rand() with mt_rand() for better randomness performance:

- ? $existingCoordinators->itemAt(rand(0, $coordinatorCount - 1))
+ ? $existingCoordinators->itemAt(mt_rand(0, $coordinatorCount - 1))

110-120: Enhance Error Handling in 'addContactToGroup'

Currently, exceptions are caught, and errors are only logged without notifying the caller.

Consider rethrowing the exception or returning a failure status to ensure that calling methods are aware of the issue.

catch (Exception $e) {
  \Civi::log()->error("Error adding contact_id: $contactId to group_id: $groupId. Exception: " . $e->getMessage());
  throw $e;
}

24-1037: Lack of Method Documentation

Several methods lack docblocks or have empty docblocks, which reduces code understandability.

Add meaningful docblocks to each method, describing its purpose, parameters, and return values.

Example:

/**
 * Assigns the chapter group to an individual based on state and organization.
 *
 * @param string $op
 * @param string $objectName
 * @param int $objectId
 * @param array &$objectRef
 */
public static function assignChapterGroupToIndividual(string $op, string $objectName, $objectId, &$objectRef) {
  // Method implementation...
}
wp-content/civi-extensions/goonjcustom/config/eventCode.php (1)

Line range hint 1-35: Improve code organization and documentation

  1. The @file docblock is empty. Consider adding meaningful documentation about the purpose of these event codes and their usage.
  2. The array entries are not alphabetically sorted, which makes it harder to maintain and locate specific entries.
  3. There are multiple pairs of similar entries sharing the same codes:
    • 'Collection Camp' and 'Institution Collection Camp' both use 'CC'
    • 'Dropping Center' and 'Institution Dropping Center' both use 'DC'

Consider:

  1. Adding proper documentation
  2. Organizing entries alphabetically
  3. Using distinct codes for institutional vs non-institutional events

Example improvement:

 <?php
 
 /**
- * @file
+ * @file
+ * Event codes configuration for the Goonj system.
+ *
+ * This file defines the mapping between event names and their corresponding
+ * short codes used throughout the system. Each event type has a unique
+ * identifier used for tracking and reporting purposes.
  */
 
 return [
+  'Activity' => 'AY',
   'Book Fair' => 'BK',
+  'Capacity Building Session- NJPC' => 'CBS',
   'Chaupal' => 'Chaupal',
   // ... (rest of the entries in alphabetical order)
 ];
wp-content/civi-extensions/goonjcustom/Civi/CollectionBaseService.php (1)

523-526: Consider improving naming consistency

There's a slight inconsistency in the naming pattern:

  • Institute_Goonj_Activities vs Institution_Collection_Camp
  • One uses "Institute" while others use "Institution"

This could lead to confusion. Consider standardizing the naming convention across all entities.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 341415d and 3ca5dc5.

📒 Files selected for processing (3)
  • wp-content/civi-extensions/goonjcustom/Civi/CollectionBaseService.php (1 hunks)
  • wp-content/civi-extensions/goonjcustom/Civi/IntitutionGoonjActivitiesService.php (1 hunks)
  • wp-content/civi-extensions/goonjcustom/config/eventCode.php (1 hunks)
🔇 Additional comments (3)
wp-content/civi-extensions/goonjcustom/config/eventCode.php (1)

Line range hint 1-35: Verify the impact of duplicate event codes

Let's check how these event codes are used in the codebase to understand the potential impact of duplicate codes.

✅ Verification successful

Let me search for more specific usage patterns of event codes to better understand their impact.


Let me check the CollectionSource trait to understand how these event codes are used.


Duplicate event codes are intentionally used for grouping similar events

After analyzing the codebase, I can confirm that the duplicate event codes ('DC' for both 'Institution Dropping Center' and 'Dropping Center', and 'GA' for both 'Goonj Activities' and 'Institution Goonj Activities') are intentionally used to group similar types of events. The CollectionSource trait shows that these codes are used to generate standardized titles in the format year/state_code/event_code/source_id, where similar events should share the same event code.

The implementation in generateCollectionSourceCode() method demonstrates that these codes are used for categorization purposes, and the uniqueness of each record is maintained by the source_id in the final title format.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usages of event codes to understand potential conflicts
echo "Searching for GA event code usage..."
rg -A 5 "'GA'" --type php

echo "Searching for event code comparisons..."
ast-grep --pattern 'if ($_ === "GA")' 

Length of output: 11235


Script:

#!/bin/bash
# Search for any usage of event codes in PHP files
echo "Searching for event code usage patterns..."
rg -A 5 "=> 'DC'" --type php

# Search for files that might be using these event codes
echo "Searching for files that might process event codes..."
fd -e php | xargs rg -l "eventCode"

# Search for any comparison or switch statements using event codes
echo "Searching for event code processing logic..."
ast-grep --pattern 'switch ($_) { $$$case$$$: }'

Length of output: 11062


Script:

#!/bin/bash
# Check the implementation in CollectionSource.php
echo "Checking CollectionSource.php implementation..."
cat "wp-content/civi-extensions/goonjcustom/Civi/Traits/CollectionSource.php"

# Look for any other files that might be using these event codes
echo "Searching for files referencing specific event codes..."
rg -l "'DC'|'GA'" --type php

Length of output: 8836

wp-content/civi-extensions/goonjcustom/Civi/CollectionBaseService.php (2)

523-526: Verify state group mappings for new institution entities

The addition of new institution-related mappings looks good, but let's verify that the corresponding custom groups exist in the system.

Let's verify the existence of these custom groups:

✅ Verification successful

✓ State group mappings are correctly implemented and used

The verification shows that all the custom group mappings in getStateGroupNameMapper are actively used in the codebase:

  • Institution_Collection_Camp_Intent is used in InstitutionCollectionCampService.php for managing collection camp data
  • Institution_Dropping_Center_Intent is used in InstitutionDroppingCenterService.php for dropping center operations
  • Both services properly reference these custom groups in their API queries and field operations

The mappings are consistent with the actual implementation and usage patterns in the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the custom groups referenced in the mappings exist

# Search for custom group definitions in PHP files
rg -l "Institution_Collection_Camp_Intent|Goonj_Activities|Institution_Dropping_Center_Intent|Institute_Goonj_Activities" --type php

# Search for any XML installer files that might define these custom groups
fd -e xml | xargs grep -l "Institution_Collection_Camp_Intent\|Goonj_Activities\|Institution_Dropping_Center_Intent\|Institute_Goonj_Activities"

Length of output: 1901


Script:

#!/bin/bash
# Let's check the actual implementation and usage of these custom groups

# First, let's look at the service implementations
rg -A 5 "Institution_Collection_Camp_Intent|Institution_Dropping_Center_Intent" wp-content/civi-extensions/goonjcustom/Civi/InstitutionCollectionCampService.php wp-content/civi-extensions/goonjcustom/Civi/InstitutionDroppingCenterService.php

# Check for custom group definitions in XML installer files
fd "xml$" --full-path wp-content/civi-extensions/goonjcustom | xargs cat

# Check for any database schema or installation related files
fd "(sql|install|upgrade)" --full-path wp-content/civi-extensions/goonjcustom

# Look for any CiviCRM API calls or definitions related to these custom groups
rg "custom_group.*(_name|_id).*=.*('|\").*Intent" wp-content/civi-extensions/goonjcustom

Length of output: 16101


523-526: Verify ACL impact for new mappings

The aclCollectionCamp method uses these mappings indirectly through getStateFieldDbDetails. Ensure that ACL restrictions work correctly for the new institution entities.

Let's check for any ACL-related code that might need updates:

✅ Verification successful

Let me gather more information about the ACL implementation to verify its impact.


Let me try one more search to understand the complete ACL implementation.


ACL implementation verified for new institution entities

The ACL implementation in aclCollectionCamp method correctly handles the new institution mappings through:

  1. Dynamic state field resolution via getStateFieldDbDetails()
  2. Proper mapping of institution entities in getStateGroupNameMapper()
  3. Unified ACL query generation for all collection camp subtypes

The changes maintain consistent ACL restrictions across all institution types by using the same state-based access control mechanism.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for ACL-related code that might need updates for new entities

# Search for ACL-related code referencing these entities
rg "aclCollectionCamp|ACL.*Institution|Institution.*ACL" --type php

# Search for any permission checks related to these entities
ast-grep --pattern 'checkPermission($$$Institution$$$)'

Length of output: 9690


Script:

#!/bin/bash
# Let's examine the aclCollectionCamp method implementation and its usage

# First, get the implementation of aclCollectionCamp
ast-grep --pattern 'function aclCollectionCamp($$$) {
  $$$
}'

# Check for getStateFieldDbDetails usage
rg "getStateFieldDbDetails" -A 5 --type php

# Look for any other ACL-related hooks or implementations
rg "hook_civicrm_selectWhereClause" --type php

Length of output: 11598


Script:

#!/bin/bash
# Get the complete implementation of CollectionBaseService.php to understand ACL flow
cat wp-content/civi-extensions/goonjcustom/Civi/CollectionBaseService.php

# Also check for any state-related configurations
rg "getStateGroupNameMapper" -A 5 --type php

Length of output: 18582

Comment on lines +444 to +521
private static function sendDispatchEmail($contactName, $collectionCampId, $campAttendedById, $collectionCampGoonjOffice, $campCode, $campAddress, $pocEmail, $pocContactNumber, $nameOfInstitution, $addressOfInstitution) {
$homeUrl = \CRM_Utils_System::baseCMSURL();

$campVehicleDispatchFormUrl = $homeUrl . 'institution-camp-vehicle-dispatch-form/#?Camp_Vehicle_Dispatch.Collection_Camp=' . $collectionCampId
. '&Camp_Vehicle_Dispatch.Filled_by=' . $campAttendedById
. '&Camp_Vehicle_Dispatch.To_which_PU_Center_material_is_being_sent=' . $collectionCampGoonjOffice
. '&Eck_Collection_Camp1=' . $collectionCampId
. '&Camp_Institution_Data.Name_of_the_institution=' . $nameOfInstitution
. '&Camp_Institution_Data.Address=' . $addressOfInstitution
. '&Camp_Institution_Data.Email=' . $pocEmail
. '&Camp_Institution_Data.Contact_Number=' . $pocContactNumber;

$html = "
<p>Dear $contactName,</p>
<p>Thank you for attending the camp <strong>$campCode</strong> at <strong>$campAddress</strong>. There is a form that requires your attention during the camp:</p>
<ol>
<li><a href=\"$campVehicleDispatchFormUrl\">Dispatch Form</a><br>
Please complete this form from the camp location once the vehicle is being loaded and ready for dispatch to Goonj's processing center.</li>
</ol>
<p>We appreciate your cooperation.</p>
<p>Warm Regards,<br>Urban Relations Team</p>";

return $html;
}

/**
*
*/
private static function sendOutcomeEmail($contactName, $collectionCampId, $coordinatingPOCId, $campCode, $campAddress) {
$homeUrl = \CRM_Utils_System::baseCMSURL();

$campOutcomeFormUrl = $homeUrl . '/institution-camp-outcome-form/#?Eck_Collection_Camp1=' . $collectionCampId . '&Camp_Outcome.Filled_By=' . $campAttendedById;

$html = "
<p>Dear $contactName,</p>
<p>Thank you for attending the camp <strong>$campCode</strong> at <strong>$campAddress</strong>. There is one form that requires your attention after the camp:</p>
<ol>
<li><a href=\"$campOutcomeFormUrl\">Camp Outcome Form</a><br>
This feedback form should be filled out after the camp/drive ends, once you have an overview of the event's outcomes.</li>
</ol>
<p>We appreciate your cooperation.</p>
<p>Warm Regards,<br>Urban Relations Team</p>";

return $html;
}

/**
* Generates the logistics email HTML content.
*/
private static function getLogisticsEmailHtml($contactName, $collectionCampId, $campAttendedById, $collectionCampGoonjOffice, $campCode, $campAddress, $pocEmail, $pocContactNumber, $nameOfInstitution, $addressOfInstitution) {
$homeUrl = \CRM_Utils_System::baseCMSURL();

$campVehicleDispatchFormUrl = $homeUrl
. 'institution-camp-vehicle-dispatch-form/#?Camp_Vehicle_Dispatch.Collection_Camp=' . $collectionCampId
. '&Camp_Vehicle_Dispatch.Filled_by=' . $campAttendedById
. '&Camp_Vehicle_Dispatch.To_which_PU_Center_material_is_being_sent=' . $collectionCampGoonjOffice
. '&Eck_Collection_Camp1=' . $collectionCampId
. '&Camp_Institution_Data.Name_of_the_institution=' . $nameOfInstitution
. '&Camp_Institution_Data.Address=' . $addressOfInstitution
. '&Camp_Institution_Data.Email=' . $pocEmail
. '&Camp_Institution_Data.Contact_Number=' . $pocContactNumber;

$campOutcomeFormUrl = $homeUrl . '/institution-camp-outcome-form/#?Eck_Collection_Camp1=' . $collectionCampId . '&Camp_Outcome.Filled_By=' . $campAttendedById;

$html = "
<p>Dear $contactName,</p>
<p>Thank you for attending the camp <strong>$campCode</strong> at <strong>$campAddress</strong>. There are two forms that require your attention during and after the camp:</p>
<ol>
<li><a href=\"$campVehicleDispatchFormUrl\">Dispatch Form</a><br>
Please complete this form from the camp location once the vehicle is being loaded and ready for dispatch to Goonj's processing center.</li>
<li><a href=\"$campOutcomeFormUrl\">Camp Outcome Form</a><br>
This feedback form should be filled out after the camp/drive ends, once you have an overview of the event's outcomes.</li>
</ol>
<p>We appreciate your cooperation.</p>
<p>Warm Regards,<br>Urban Relations Team</p>";

return $html;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Duplicate Code in Email Sending Methods

The methods sendDispatchEmail, sendOutcomeEmail, and getLogisticsEmailHtml contain similar code for generating email HTML content. This duplication violates the DRY (Don't Repeat Yourself) principle.

Consider refactoring these methods by extracting common code into a reusable method or using a templating system for generating emails. This will enhance maintainability and reduce the risk of inconsistencies.

Comment on lines +300 to +439
->addWhere('id', '=', $campAttendedById)
->execute()->single();

$recipientEmail = $recipient['email.email'];
$recipientName = $recipient['display_name'];

if (!$recipientEmail) {
\Civi::log()->info("Recipient email missing: $campId");
}
$from = HelperService::getDefaultFromEmail();
$mailParams = [
'subject' => 'Collection Camp Notification: ' . $campCode . ' at ' . $campAddress,
'from' => $from,
'toEmail' => $recipientEmail,
'replyTo' => $from,
'html' => self::getLogisticsEmailHtml($recipientName, $campId, $campAttendedById, $campOffice, $campCode, $campAddress, $pocEmail, $pocContactNumber, $nameOfInstitution, $addressOfInstitution),
];

// Send logistics email.
$emailSendResult = \CRM_Utils_Mail::send($mailParams);

if ($emailSendResult) {
\Civi::log()->info("Logistics email sent for collection camp: $campId");
EckEntity::update('Collection_Camp', FALSE)
->addValue('Institution_Collection_Camp_Logistics.Email_Sent', 1)
->addWhere('id', '=', $campId)
->execute();
}
}
else {
$recipient = Contact::get(FALSE)
->addSelect('email.email', 'display_name')
->addJoin('Email AS email', 'LEFT')
->addWhere('id', '=', $institutionPOCId)
->execute()->single();

$recipientEmail = $recipient['email.email'];
$recipientName = $recipient['display_name'];

if (!$recipientEmail) {
\Civi::log()->info("Recipient email missing for institution POC: $campId");
return;
}

$from = HelperService::getDefaultFromEmail();
$mailParams = [
'subject' => 'Dispatch Notification for Self Managed Camp: ' . $campCode,
'from' => $from,
'toEmail' => $recipientEmail,
'replyTo' => $from,
'html' => self::sendDispatchEmail($recipientName, $campId, $coordinatingPOCId, $campOffice, $campCode, $campAddress, $pocEmail, $pocContactNumber, $nameOfInstitution, $addressOfInstitution),
];

$dispatchEmailSendResult = \CRM_Utils_Mail::send($mailParams);

if ($dispatchEmailSendResult) {
\Civi::log()->info("dispatch email sent for collection camp: $campId");
EckEntity::update('Collection_Camp', FALSE)
->addValue('Institution_Collection_Camp_Logistics.Email_Sent', 1)
->addWhere('id', '=', $campId)
->execute();
}

$recipient = Contact::get(FALSE)
->addSelect('email.email', 'display_name')
->addJoin('Email AS email', 'LEFT')
->addWhere('id', '=', $coordinatingPOCId)
->execute()->single();

$recipientEmail = $recipient['email.email'];
$recipientName = $recipient['display_name'];

if (!$recipientEmail) {
\Civi::log()->info("Recipient email missing for coordinating POC': $campId");
return;
}

$mailParams = [
'subject' => 'Outcome Notification for Self Managed Camp: ' . $campCode,
'from' => $from,
'toEmail' => $recipientEmail,
'replyTo' => $from,
'html' => self::sendOutcomeEmail($recipientName, $campId, $coordinatingPOCId, $campCode, $campAddress,),
];

$outcomeEmailSendResult = \CRM_Utils_Mail::send($mailParams);
if ($outcomeEmailSendResult) {
\Civi::log()->info("dispatch email sent for collection camp: $campId");
EckEntity::update('Collection_Camp', FALSE)
->addValue('Institution_Collection_Camp_Logistics.Email_Sent', 1)
->addWhere('id', '=', $campId)
->execute();
}
}
}
}
catch (\Exception $e) {
\Civi::log()->error("Error in sendLogisticsEmail for $campId: " . $e->getMessage());
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Method 'sendLogisticsEmail' Is Too Long and Complex

The sendLogisticsEmail method is lengthy with deeply nested conditionals, making it difficult to read and maintain.

Refactor the method by:

  • Extracting logical blocks into separate methods (e.g., email preparation, contact retrieval).
  • Reducing nesting by returning early where possible.
  • Using guard clauses to simplify conditional logic.

This will enhance clarity and adhere to the Single Responsibility Principle.


🛠️ Refactor suggestion

Single Responsibility Principle Violation in 'sendLogisticsEmail'

This method handles multiple tasks including data retrieval, email content generation, and sending emails.

Split the method into smaller, focused methods:

  • One for retrieving data.
  • One for preparing email content.
  • One for sending emails.

This adheres to the Single Responsibility Principle and improves code clarity.

/**
*
*/
class IntitutionGoonjActivitiesService extends AutoSubscriber {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Typographical Error in Class Name

The class name IntitutionGoonjActivitiesService appears to be misspelled. Correcting it to InstitutionGoonjActivitiesService will improve code readability and prevent potential issues.

Apply this diff to fix the class name:

-class IntitutionGoonjActivitiesService extends AutoSubscriber {
+class InstitutionGoonjActivitiesService extends AutoSubscriber {
📝 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.

Suggested change
class IntitutionGoonjActivitiesService extends AutoSubscriber {
class InstitutionGoonjActivitiesService extends AutoSubscriber {

'is_primary' => 1,
];
self::$addressAdded = TRUE;
\Civi::log()->info('instituteGoonjActivitiesA12312312ddress', ['instit21212uteGoonjActivitiesAddress' => self::$instituteGoonjActivitiesAddress, 'institutePocAddress' => self::$institutePocAddress]);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Garbled Text in Log Message

The log message contains typographical errors and seems to include unintended characters.

Apply this diff to correct the log message:

- \Civi::log()->info('instituteGoonjActivitiesA12312312ddress', ['instit21212uteGoonjActivitiesAddress' => self::$instituteGoonjActivitiesAddress, 'institutePocAddress' => self::$institutePocAddress]);
+ \Civi::log()->info('instituteGoonjActivitiesAddress', ['instituteGoonjActivitiesAddress' => self::$instituteGoonjActivitiesAddress, 'institutePocAddress' => self::$institutePocAddress]);
📝 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.

Suggested change
\Civi::log()->info('instituteGoonjActivitiesA12312312ddress', ['instit21212uteGoonjActivitiesAddress' => self::$instituteGoonjActivitiesAddress, 'institutePocAddress' => self::$institutePocAddress]);
\Civi::log()->info('instituteGoonjActivitiesAddress', ['instituteGoonjActivitiesAddress' => self::$instituteGoonjActivitiesAddress, 'institutePocAddress' => self::$institutePocAddress]);

$relationshipTypeName = 'Other Entities Coordinator of';
}
\Civi::log()->info('relationshipTypeName', ['relationshipTypeName' => $relationshipTypeName, '------', 'stateOfficeId' => $stateOfficeId]);

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Remove Debug Logging Statements from Production Code

The logging statement includes detailed internal data, which may not be suitable for production environments.

Apply this diff to remove or adjust the logging statement:

- \Civi::log()->info('registrationCategorySelection', ['registrationCategorySelection' => $registrationCategorySelection, 'relationshipTypeMap' => $relationshipTypeMap]);

If logging is necessary, ensure it's appropriately leveled and sanitized.

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +41 to +54
'&hook_civicrm_pre' => [
['assignChapterGroupToIndividual'],
['generateInstitutionCollectionCampQr'],
],
'civi.afform.submit' => [
['setGoonjActivitiesAddress', 10],
['setActivitiesVolunteersAddress', 20],
],
'&hook_civicrm_custom' => [
['setOfficeDetails'],
],
'&hook_civicrm_pre' => [
['createActivityForGoonjActivityCollectionCamp'],
],
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Duplicate Event Subscription for 'hook_civicrm_pre'

The getSubscribedEvents method subscribes to &hook_civicrm_pre twice, which may lead to confusion or unintended behavior.

Combine the event handlers under a single subscription:

return [
  '&hook_civicrm_pre' => [
    ['assignChapterGroupToIndividual'],
    ['generateInstitutionCollectionCampQr'],
    ['createActivityForGoonjActivityCollectionCamp'],
  ],
  // Other event subscriptions...
];

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +946 to +947
\Civi::log()->info('joined', ['event2' => $joins, 'contacinstituteGoonjActivitiesAddresst' => $instituteGoonjActivitiesAddress]);
// Add if not present.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Misspelled Variable Names in Logging

Variable names in the logging statements are misspelled, which can lead to confusion during debugging.

Apply this diff to correct the variable names:

- \Civi::log()->info('joined', ['event2' => $joins, 'contacinstituteGoonjActivitiesAddresst' => $instituteGoonjActivitiesAddress]);
+ \Civi::log()->info('joined', ['event2' => $joins, 'instituteGoonjActivitiesAddress' => self::$instituteGoonjActivitiesAddress]);

Committable suggestion skipped: line range outside the PR's diff.

@@ -15,6 +15,7 @@
'Disaster Exhibition' => 'DE',
'Dropping Center' => 'DC',
'Goonj Activities' => 'GA',
'Institution Goonj Activities' => 'GA',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Potential ambiguity with duplicate event code 'GA'

The newly added 'Institution Goonj Activities' uses the same code 'GA' as the existing 'Goonj Activities' entry. This could cause confusion or issues in event identification and reporting. Consider using a distinct code for institutional activities, such as 'IGA'.

Apply this diff to use a unique code:

-  'Institution Goonj Activities' => 'GA',
+  'Institution Goonj Activities' => 'IGA',
📝 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.

Suggested change
'Institution Goonj Activities' => 'GA',
'Institution Goonj Activities' => 'IGA',

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant