Beispiel #1
0
 private function givePoints($user_id, $points, $data = null, $mode = null)
 {
     if ($points === 0) {
         return true;
     }
     $points_mode = @$this->plugin_params->mode;
     if ($mode !== null) {
         $points_mode = $mode;
     }
     if ($points_mode == 'aup') {
         if ($this->getAUP(true)) {
             $aupid = AlphaUserPointsHelper::getAnyUserReferreID($user_id);
             AlphaUserPointsHelper::newpoints('plgaup_orderValidation', $aupid, '', $data, $points);
             return true;
         }
         return false;
     }
     if ($points_mode == 'hks') {
         if (hikaserial::initShop()) {
             $app = JFactory::getApplication();
             $ret = true;
             $userClass = hikaserial::get('shop.class.user');
             $oldUser = $userClass->get($user_id, 'cms');
             if (!isset($oldUser->user_points) && !in_array('user_points', array_keys(get_object_vars($oldUser)))) {
                 return false;
             }
             if (empty($oldUser->user_points)) {
                 $oldUser->user_points = 0;
             }
             $user = new stdClass();
             $user->user_id = $oldUser->user_id;
             $user->user_points = (int) $oldUser->user_points + $points;
             if ($user->user_points < 0) {
                 $app->enqueueMessage(JText::_('CANT_HAVE_NEGATIVE_POINTS'), 'error');
                 $points = -$oldUser->user_points;
                 $user->user_points = 0;
                 $ret = false;
             } else {
                 $app->enqueueMessage(JText::sprintf('HIKAPOINTS_EARN_X_POINTS', $points), 'success');
             }
             $userClass->save($user);
             return $ret;
         }
         return false;
     }
     if ($points_mode == 'hkp') {
         if (hikaserial::initPoints()) {
             return hikapoints::trigger($user_id, 'hikaserial_points_consumer', $points);
         }
         return false;
     }
     if (substr($points_mode, 0, 4) == 'hkp.') {
         if (hikaserial::initPoints()) {
             $category_id = (int) substr($points_mode, 4);
             $pointsClass = hikapoints::get('class.points');
             return $pointsClass->add($user_id, $category_id, $points);
         }
         return false;
     }
     return false;
 }