Esempio n. 1
0
 /**
  * {%inheritDoc}
  */
 public static function process(User $user, $params = [])
 {
     if (!isset($params['code']) || empty($params['code'])) {
         return false;
     }
     if ($activity = Activity::findActivityType('LikeWorkOfArt')->first()) {
         $code = $params['code'];
         if ($data = self::isAssessionNumber($code)) {
             // Skip activity process if user has already like this work of art
             $likeCount = ActivityMetadata::hasMetadataValue($user, $activity, 'object_id', $data['object_id'])->count();
             if ($likeCount == 0) {
                 // User haven't like this artwork yet
                 if ($ret = parent::process($user, ['activity' => $activity])) {
                     // TODO: Find a better way to pass this data
                     $activity->objectData = $data;
                     // Save user metada activity
                     ActivityMetadata::addUserActivity($user, $activity, $data, ['object_title']);
                     FriendsLog::artwork(['user' => $user, 'artwork_id' => $params['code']]);
                 }
                 return $ret;
             } else {
                 Session::put('activityError', Lang::get('dma.friends::lang.activities.alreadyLikeWorkArtError', ['code' => $params['code']]));
             }
         } else {
             // Verify if user try to enter an Object number
             // Regex expression to match object number format
             $re = "/((([a-zA-Z0-9_\\-]+\\.){1,})([a-zA-Z0-9_\\-]+))/";
             $isObjectNumber = preg_match_all($re, str_replace(' ', '', $code)) > 0;
             if ($isObjectNumber) {
                 Session::put('activityError', Lang::get('dma.friends::lang.activities.likeWorkArtCodeError', ['code' => $params['code']]));
             }
         }
     }
     return false;
 }
Esempio n. 2
0
 /**
  * Add points to a users account
  *
  * @param integer $points
  * The amount of points to add to a user
  */
 public function addPoints($points)
 {
     if (!is_numeric($points)) {
         throw new SystemException('Points must be an integer');
     }
     $this->user->points += $points;
     $this->user->points_this_week += $points;
     $this->user->points_today += $points;
     if ($this->user->forceSave()) {
         // Process any activities awarded on points achievement
         Points::process($this->user);
         Event::fire('dma.friends.user.pointsEarned', [$this->user, $points]);
         $params = ['user' => $this->user, 'points_earned' => $points];
         FriendsLog::points($params);
     }
 }
 public function onAuthLogin($event)
 {
     $user = Auth::getUser();
     $location = LocationManager::getLocation();
     if ($location) {
         $data = ['user' => $user, 'object' => $location];
         FriendsLog::checkin($data);
     }
 }
Esempio n. 4
0
 public function testUnlocked()
 {
     $user = FactoryMuffin::create('RainLab\\User\\Models\\User');
     $step = FactoryMuffin::create('DMA\\Friends\\Models\\Step');
     $params = ['object' => $step, 'user' => $user];
     FriendsLog::unlocked($params);
 }
Esempio n. 5
0
 /**
  * Complete the step and proceed to complete a badge if it can be completed
  *
  * @param Step $step
  * A step model
  * @param User $user
  * A user model
  */
 private static function completeBadge(Step $step, User $user)
 {
     $badge = $step->badge;
     // Check badge global limit
     if ($badge->maximum_earnings_global > 0 && count($badge->users) > $badge->maximum_earnings_global) {
         return false;
     }
     // Complete step
     try {
         $user->steps()->save($step);
         Event::fire('dma.friends.step.completed', [$step, $user]);
     } catch (Exception $e) {
         throw new Exception(Lang::get('dma.friends::lang.exceptions.stepFailed'));
     }
     // See if the user has completed all steps for a badge
     foreach ($badge->steps as $step) {
         if (!$user->steps->contains($step->id)) {
             //user did not complete a step in badge so we cannot complete the badge
             return;
         }
     }
     try {
         // If loop completes with out returning false the user has completed all steps
         $user->badges()->save($badge);
         $userExtend = new UserExtend($user);
         $userExtend->addPoints($badge->points);
         Event::fire('dma.friends.badge.completed', [$badge, $user]);
         // log an entry to the activity log
         FriendsLog::unlocked(['user' => $user, 'object' => $badge]);
         if ($badge->congratulations_text) {
             $notificationText = $badge->congratulations_text;
         } else {
             $notificationText = Lang::get('dma.friends::lang.badges.completed', ['title' => $badge->title]);
         }
         //Flash::info($notificationText);
         Postman::send('simple', function (NotificationMessage $notification) use($user, $badge, $notificationText) {
             // Set user
             $notification->to($user, $user->name);
             // Send code and activity just in case we want to use in the template
             $notification->addData(['badge' => $badge]);
             $notification->message($notificationText);
         }, ['flash', 'kiosk']);
     } catch (Exception $e) {
         throw new Exception(Lang::get('dma.friends::lang.exceptions.badgeFailed'));
     }
 }