/** * add points to user based on the action. */ function assignPoint($action, $userId = null) { //get the rule points //must use the JFactory::getUser to get the aid $juser =& JFactory::getUser($userId); if ($juser->id != 0) { $aid = $juser->aid; // if the aid is null, means this is not the current logged-in user. // so we need to manually get this aid for this user. if (is_null($aid)) { $aid = 0; //defautl to 0 // Get an ACL object $acl =& JFactory::getACL(); $grp = $acl->getAroGroup($juser->id); $group = 'USERS'; if ($acl->is_group_child_of($grp->name, $group)) { $aid = 1; // Fudge Authors, Editors, Publishers and Super Administrators into the special access group if ($acl->is_group_child_of($grp->name, 'Registered') || $acl->is_group_child_of($grp->name, 'Public Backend')) { $aid = 2; } } } $points = CUserPoints::_getActionPoint($action, $aid); $user = CFactory::getUser($userId); $points += $user->getKarmaPoint(); $user->_points = $points; $user->save(); } }
/** * add points to user based on the action. * @param $action * @param null $userId */ public static function assignPoint($action, $userId = null) { //get the rule points //must use the JFactory::getUser to get the aid $juser = JFactory::getUser($userId); //since 4.0, check if this action is published, else return false (boolean) $userPointModel = CFactory::getModel('Userpoints'); $point = $userPointModel->getPointData($action); if (!isset($point->published) || !$point->published) { return false; } if ($juser->id != 0) { if (!method_exists($juser, 'getAuthorisedViewLevels')) { $aid = $juser->aid; // if the aid is null, means this is not the current logged-in user. // so we need to manually get this aid for this user. if (is_null($aid)) { $aid = 0; //defautl to 0 // Get an ACL object $acl = JFactory::getACL(); $grp = $acl->getAroGroup($juser->id); $group = 'USERS'; if ($acl->is_group_child_of($grp->name, $group)) { $aid = 1; // Fudge Authors, Editors, Publishers and Super Administrators into the special access group if ($acl->is_group_child_of($grp->name, 'Registered') || $acl->is_group_child_of($grp->name, 'Public Backend')) { $aid = 2; } } } } else { //joomla 1.6 $aid = $juser->getAuthorisedViewLevels(); } $points = CUserPoints::_getActionPoint($action, $aid); $user = CFactory::getUser($userId); $points += $user->getKarmaPoint(); $user->_points = $points; $profile = JTable::getInstance('Profile', 'CTable'); $profile->load($user->id); $user->_thumb = $profile->thumb; $user->_avatar = $profile->avatar; $user->save(); //Event trigger $appsLib = CAppPlugins::getInstance(); $appsLib->loadApplications(); $params = array('action' => $action, 'points' => $points, 'userId' => $user->id); $appsLib->triggerEvent('onAfterAssignPoint', $params); return true; } }