Skip to content

Commit

Permalink
fix: getProgressByMilestoneId needs to consider campaign ID
Browse files Browse the repository at this point in the history
  • Loading branch information
ammopt committed Nov 11, 2024
1 parent 19ce72a commit 69f3ad2
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion code/web/services/Community/CampaignTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function launch() {

foreach ($milestones as $milestone) {
$milestoneComplete = $milestoneCompletionStatus[$milestone->id] ?? false;
$userProgress = MilestoneUsersProgress::getProgressByMilestoneId($milestone->id, $user->id);
$userProgress = MilestoneUsersProgress::getProgressByMilestoneId($milestone->id, $campaignId, $user->id);
$totalGoals = CampaignMilestone::getMilestoneGoalCountByCampaign($campaignId, $milestone->id);
$milestoneRewardGiven = MilestoneUsersProgress::getRewardGivenForMilestone($milestone->id, $user->id);

Expand Down
2 changes: 1 addition & 1 deletion code/web/services/Community/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function launch() {
$milestoneCompletionStatus = $userCampaign->checkMilestoneCompletionStatus();
foreach ($milestones as $milestone) {
$milestoneComplete = $milestoneCompletionStatus[$milestone->id] ?? false;
$userProgress = CampaignMilestoneUsersProgress::getProgressByMilestoneId($milestone->id, $user->id);
$userProgress = CampaignMilestoneUsersProgress::getProgressByMilestoneId($milestone->id, $campaignId, $user->id);
$totalGoals = CampaignMilestone::getMilestoneGoalCountByCampaign($campaign->id, $milestone->id);
$milestoneRewardGiven = CampaignMilestoneUsersProgress::getRewardGivenForMilestone($milestone->id, $user->id);
$userCampaigns[$campaign->id][$user->id]['milestones'][$milestone->id] = [
Expand Down
4 changes: 2 additions & 2 deletions code/web/sys/Community/Campaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public static function getMilestoneRewards(int $campaignId, int $userId): array
$userCampaign->campaignId = $campaignId;

if ($userCampaign->find(true)) {
$milestoneProgress = CampaignMilestoneUsersProgress::getProgressByMilestoneId($milestone->id, $userId);
$milestoneProgress = CampaignMilestoneUsersProgress::getProgressByMilestoneId($milestone->id, $campaignId, $userId);
$rewardGiven = (int)$milestoneProgress->rewardGiven;
}

Expand Down Expand Up @@ -455,7 +455,7 @@ public function getPastCampaigns(int $userId): array {
// Update milestone details based on user progress
foreach ($pastCampaignList[$campaign->id]->milestones as $milestone) {
$milestoneProgress = CampaignMilestone::getMilestoneProgress($campaign->id, $userId, $milestone->id);
$milestone->userProgress = CampaignMilestoneUsersProgress::getProgressByMilestoneId($milestone->id, $userId);
$milestone->userProgress = CampaignMilestoneUsersProgress::getProgressByMilestoneId($milestone->id, $campaign->id, $userId);
$milestone->isComplete = $milestoneCompletionStatus[$milestone->id] ?? false;
$milestone->rewardGiven = CampaignMilestoneUsersProgress::getRewardGivenForMilestone($milestone->id, $userId);
$milestone->progress = $milestoneProgress['progress'];
Expand Down
2 changes: 1 addition & 1 deletion code/web/sys/Community/CampaignMilestone.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public static function getMilestoneProgress($campaignId, $userId, $milestoneId)
$goal = $campaignMilestone->getMilestoneGoalCountByCampaign($campaignId, $milestoneId);

//Number of completed goals for this milestone
$userCompletedGoalCount = $campaignMilestoneUsersProgress->getProgressByMilestoneId($milestoneId, $userId);
$userCompletedGoalCount = $campaignMilestoneUsersProgress->getProgressByMilestoneId($milestoneId, $campaignId, $userId);

if ($goal > 0) {
$progress = ($userCompletedGoalCount / $goal ) * 100;
Expand Down
4 changes: 3 additions & 1 deletion code/web/sys/Community/CampaignMilestoneUsersProgress.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ class CampaignMilestoneUsersProgress extends DataObject
public $__table = 'ce_campaign_milestone_users_progress';
public $id;
public $userId;
public $ce_campaign_id;
public $ce_milestone_id;
public $progress;
public $rewardGiven;

public static function getProgressByMilestoneId($milestoneId, $userId) {
public static function getProgressByMilestoneId($milestoneId, $campaignId, $userId) {
$milestoneProgress = new Self();

$milestoneProgress->whereAdd('ce_milestone_id = ' . intval($milestoneId));
$milestoneProgress->whereAdd('ce_campaign_id = ' . intval($campaignId));
$milestoneProgress->whereAdd('userId = ' . intval($userId));
$milestoneProgress->find(true);

Expand Down
4 changes: 2 additions & 2 deletions code/web/sys/Community/UserCampaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function checkCompletionStatus() {
$isComplete = true;

foreach ($milestones as $milestone) {
$userProgress = CampaignMilestoneUsersProgress::getProgressByMilestoneId($milestone->id, $this->userId);
$userProgress = CampaignMilestoneUsersProgress::getProgressByMilestoneId($milestone->id, $this->campaignId, $this->userId);
$goal = CampaignMilestone::getMilestoneGoalCountByCampaign($this->campaignId, $milestone->id);

if ($userProgress < $goal) {
Expand All @@ -85,7 +85,7 @@ public function checkMilestoneCompletionStatus() {

foreach ($milestones as $milestone) {
//User's progress for this milestone
$userProgress = CampaignMilestoneUsersProgress::getProgressByMilestoneId($milestone->id, $this->userId);
$userProgress = CampaignMilestoneUsersProgress::getProgressByMilestoneId($milestone->id, $this->campaignId, $this->userId);

//Goal for this milestone
$goal = CampaignMilestone::getMilestoneGoalCountByCampaign($this->campaignId, $milestone->id);
Expand Down

0 comments on commit 69f3ad2

Please sign in to comment.