/** * Pre-processor for $table->store($data) * * @param Points $userPoints * @param array $options * * @return void */ public function onAfterPointsIncrease($userPoints, $options = array()) { // Get the context. $alias = isset($options["context"]) ? $options["context"] : ""; // Check for allowed context. if (!in_array($alias, $this->allowedContext)) { return; } $keys = array("user_id" => $userPoints->getUserId(), "group_id" => $userPoints->getGroupId()); // Get user level $level = new Points\Level(\JFactory::getDbo()); $level->load($keys); $level->setUserPoints($userPoints); if (!$level->getId()) { // Create a level record $level->startLeveling($keys); } else { // Level UP if ($level->levelUp($options) and ($this->storeActivity or $this->sendNotification)) { $params = \JComponentHelper::getParams("com_gamification"); $user = \JFactory::getUser($userPoints->getUserId()); $optionsActivitiesNotifications = array("social_platform" => "", "user_id" => $user->get("id"), "context_id" => $user->get("id"), "app" => "gamification.level"); $activityService = $params->get("integration_activities"); if ($this->storeActivity and $activityService) { $optionsActivitiesNotifications["social_platform"] = $activityService; $message = \JText::sprintf("LIB_GAMIFICATION_LEVELING_LEVEL_UP", $user->get("name"), $level->getLevel()); Helper::storeActivity($message, $optionsActivitiesNotifications); } $notificationService = $params->get("integration_notifications"); if ($this->sendNotification and $notificationService) { $optionsActivitiesNotifications["social_platform"] = $notificationService; $message = \JText::sprintf("LIB_GAMIFICATION_LEVELING_NOTIFICATION", $level->getLevel()); Helper::sendNotification($message, $optionsActivitiesNotifications); } } } }
/** * Pre-processor for $table->store($data) * * @param string $context * @param int $value * @param Points $points * @param array $options * * @throws \InvalidArgumentException * @throws \RuntimeException * @throws \UnexpectedValueException * * @return void */ public function onAfterPointsIncrease($context, $value, Points $points, array $options = array()) { // Check for allowed context. if (!in_array($context, $this->allowedContext, true)) { return; } $rewardSeeker = new RewardPointsSeeker(\JFactory::getDbo()); $rewardSeeker->setUserPoints($points); $newReward = $rewardSeeker->find(); if ($newReward !== null) { $rewardManager = new RewardManager(\JFactory::getDbo()); $rewardManager->setReward($newReward); $userReward = $rewardManager->give($context, $points->getUserId(), $options); if ($userReward !== null and ($this->storeActivity or $this->sendNotification)) { $params = \JComponentHelper::getParams('com_gamification'); $user = \JFactory::getUser($points->getUserId()); $communityOptions = new Registry(array('platform' => '', 'user_id' => $user->get('id'), 'context_id' => $user->get('id'), 'app' => 'gamification.reward')); $activityService = $params->get('integration_activities'); if ($this->storeActivity and $activityService) { $communityOptions['platform'] = $activityService; $message = \JText::sprintf('LIB_GAMIFICATION_REWARDING_RECEIVED_REWARD', $user->get('name'), $userReward->getReward()->getTitle()); Helper::storeActivity($message, $communityOptions); } $notificationService = $params->get('integration_notifications'); if ($this->sendNotification and $notificationService) { $communityOptions['platform'] = $notificationService; $message = \JText::sprintf('LIB_GAMIFICATION_REWARDING_NOTIFICATION', $userReward->getReward()->getTitle()); Helper::sendNotification($message, $communityOptions); } } } }
/** * Pre-processor for $table->store($data) * * @param string $context * @param int $value * @param Points $points * @param array $options * * @throws \InvalidArgumentException * @throws \RuntimeException * @throws \UnexpectedValueException * * @return void */ public function onAfterPointsIncrease($context, $value, Points $points, array $options = array()) { // Check for allowed context. if (!in_array($context, $this->allowedContext, true)) { return; } $levelSeeker = new LevelPointsSeeker(\JFactory::getDbo()); $levelSeeker->setUserPoints($points); $newLevel = $levelSeeker->find(); if ($newLevel !== null) { $levelManager = new LevelManager(\JFactory::getDbo()); $levelManager->setLevel($newLevel); $userLevel = $levelManager->levelUp($context, $points->getUserId(), $options); if ($userLevel !== null and ($this->storeActivity or $this->sendNotification)) { $params = \JComponentHelper::getParams('com_gamification'); $user = \JFactory::getUser($points->getUserId()); $communityOptions = new Registry(array('platform' => '', 'user_id' => $user->get('id'), 'context_id' => $user->get('id'), 'app' => 'gamification.level')); $activityService = $params->get('integration_activities'); if ($this->storeActivity and $activityService) { $communityOptions['platform'] = $activityService; $message = \JText::sprintf('LIB_GAMIFICATION_LEVELING_LEVEL_UP', $user->get('name'), $newLevel->getValue()); Helper::storeActivity($message, $communityOptions); } $notificationService = $params->get('integration_notifications'); if ($this->sendNotification and $notificationService) { $communityOptions['platform'] = $notificationService; $message = \JText::sprintf('LIB_GAMIFICATION_LEVELING_NOTIFICATION', $newLevel->getValue()); Helper::sendNotification($message, $communityOptions); } } } }
/** * Pre-processor for $table->store($data) * * @param string $context * @param int $value * @param Points $points * @param array $options * * @throws \InvalidArgumentException * @throws \RuntimeException * @throws \UnexpectedValueException * * @return void */ public function onAfterPointsIncrease($context, $value, Points $points, array $options = array()) { // Check for allowed context. if (!in_array($context, $this->allowedContext, true)) { return; } $achievementSeeker = new AchievementPointsSeeker(\JFactory::getDbo()); $achievementSeeker->setUserPoints($points); $newAchievement = $achievementSeeker->find(); if ($newAchievement !== null) { $achievementManager = new AchievementManager(\JFactory::getDbo()); $achievementManager->setAchievement($newAchievement); $userAchievement = $achievementManager->accomplish($context, $points->getUserId(), $options); if ($userAchievement !== null and ($this->storeActivity or $this->sendNotification)) { $params = \JComponentHelper::getParams('com_gamification'); $user = \JFactory::getUser($points->getUserId()); $communityOptions = new Registry(array('platform' => '', 'user_id' => $user->get('id'), 'context_id' => $user->get('id'), 'app' => 'gamification.achievement')); $activityService = $params->get('integration_activities'); if ($this->storeActivity and $activityService) { $communityOptions['platform'] = $activityService; $message = \JText::sprintf('LIB_GAMIFICATION_ACCOMPLISHING_COMPLETE_ACHIEVEMENT', $user->get('name'), $userAchievement->getAchievement()->getTitle()); Helper::storeActivity($message, $communityOptions); } $notificationService = $params->get('integration_notifications'); if ($this->sendNotification and $notificationService) { $communityOptions['platform'] = $notificationService; $message = \JText::sprintf('LIB_GAMIFICATION_ACCOMPLISHING_NOTIFICATION', $userAchievement->getAchievement()->getTitle()); Helper::sendNotification($message, $communityOptions); } } } }
/** * Pre-processor for $table->store($data) * * @param Points $userPoints * @param array $options * * @return void */ public function onAfterPointsIncrease($userPoints, $options = array()) { // Get the context. $alias = isset($options["context"]) ? $options["context"] : ""; // Check for allowed context. if (!in_array($alias, $this->allowedContext)) { return; } // Load all badges. $keys = array("user_id" => $userPoints->getUserId(), "group_id" => $userPoints->getGroupId()); $badge = new Points\Badge(\JFactory::getDbo()); $badge->setUserPoints($userPoints); if ($badge->giveBadge($options) and ($this->storeActivity or $this->sendNotification)) { // Give a badge. $params = \JComponentHelper::getParams("com_gamification"); $user = \JFactory::getUser($userPoints->getUserId()); $optionsActivitiesNotifications = array("social_platform" => "", "user_id" => $user->get("id"), "context_id" => $user->get("id"), "app" => "gamification.badge"); $activityService = $params->get("integration_activities"); if ($this->storeActivity and $activityService) { $optionsActivitiesNotifications["social_platform"] = $activityService; $message = \JText::sprintf("LIB_GAMIFICATION_BADGING_RECEIVE_NEW_BADGE", $user->get("name"), $badge->getTitle()); Helper::storeActivity($message, $optionsActivitiesNotifications); } $notificationService = $params->get("integration_notifications"); if ($this->sendNotification and $notificationService) { $optionsActivitiesNotifications["social_platform"] = $notificationService; $message = \JText::sprintf("LIB_GAMIFICATION_BADGING_NOTIFICATION", $badge->getTitle()); Helper::sendNotification($message, $optionsActivitiesNotifications); } } }
/** * Pre-processor for $table->store($data) * * @param Points $userPoints * @param array $options * * @return void */ public function onAfterPointsIncrease($userPoints, $options = array()) { // Get the context. $alias = isset($options["context"]) ? $options["context"] : ""; // Check for allowed context. if (!in_array($alias, $this->allowedContext)) { return; } $keys = array("user_id" => $userPoints->getUserId(), "group_id" => $userPoints->getGroupId()); // Get user rank. $rank = new Points\Rank(\JFactory::getDbo()); $rank->load($keys); $rank->setUserPoints($userPoints); if (!$rank->getId()) { // Create a rank record $rank->startRanking($keys); } else { // Give new rank. if ($rank->giveRank($options) and ($this->storeActivity or $this->sendNotification)) { $params = \JComponentHelper::getParams("com_gamification"); $user = \JFactory::getUser($userPoints->getUserId()); $optionsActivitiesNotifications = array("social_platform" => "", "user_id" => $user->get("id"), "context_id" => $user->get("id"), "app" => "gamification.rank"); $activityService = $params->get("integration_activities"); if ($this->storeActivity and $activityService) { $optionsActivitiesNotifications["social_platform"] = $activityService; $message = \JText::sprintf("LIB_GAMIFICATION_RANKING_REACH_NEW_RANK", $user->get("name"), $rank->getTitle()); Helper::storeActivity($message, $optionsActivitiesNotifications); } $notificationService = $params->get("integration_notifications"); if ($this->sendNotification and $notificationService) { $optionsActivitiesNotifications["social_platform"] = $notificationService; $message = \JText::sprintf("LIB_GAMIFICATION_RANKING_NOTIFICATION", $rank->getTitle()); Helper::sendNotification($message, $optionsActivitiesNotifications); } } } }