Skip to content

Commit

Permalink
add Reputation
Browse files Browse the repository at this point in the history
  • Loading branch information
skywalker512 committed Jul 9, 2018
1 parent f1dc0cd commit 44f5d78
Show file tree
Hide file tree
Showing 11 changed files with 567 additions and 0 deletions.
12 changes: 12 additions & 0 deletions addons/languages/Chinese/definitions.Reputation.php
@@ -0,0 +1,12 @@
<?php

$definitions["Top 10 members"] = "最高10名";
$definitions["Members nearby your rank"] = "与你排名相当的用户";
$definitions["Show Reputation Points to members."] = "显示积分给用户(即使没用勾选,插件也在计算积分)";
$definitions["RP to member for starting a conversation."] = "用户发新话题所获得的积分";
$definitions["RP to be given to member for posting a reply on a conversation."] = "用户发表回复所获得的积分";
$definitions["RP to be given to conversation start member for getting a post."] = "用户的话题获得回复时得到的积分";
$definitions["RP to be given to member for getting a view on a conversation."] = "用户的话题获得查看时得到的积分";
$definitions["RP to be given to member for getting a like on a post."] = "用户的话题获得喜欢时得到的积分";
$definitions["Update Reputation Points of all members based on the new values. Use with caution."] = "使用新的积分规则更新用户的积分,请谨慎使用";
$definitions["<strong> You must have Likes and Views Plugins installed and enabled to use this option!</strong>"] = "<strong> 你必须安装并开启 喜欢 和 查看 插件</strong>";
37 changes: 37 additions & 0 deletions addons/plugins/Reputation/.gitignore
@@ -0,0 +1,37 @@
.buildpath
.project
.settings
.htaccess

# Compiled source
*.com
*.class
*.dll
*.exe
*.o
*.so

# Packages
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip

# Logs and databases
*.log
*.sql
*.sqlite

# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
*~
38 changes: 38 additions & 0 deletions addons/plugins/Reputation/README.md
@@ -0,0 +1,38 @@
# Reputation Plugin

Works with esoTalk v1.0.0g4 (http://esotalk.org/)

Gamifies the forum by assigning reputation points to members based on customisable formula.

###Plugin dependancy (optional):

<b>Likes:</b> https://github.com/esotalk/Likes

<b>Views:</b> https://github.com/esotalk/Views

## Installation

Place Reputation folder under addons/plugins

Navigate to the the admin/plugins page and activate the Reputation plugin.

You need to ```Enable RP``` to make it visible.

## Customisable settings

Formula for reputation points can be tweaked for following parameters:

![settings](http://s6.postimg.org/c8dceejpd/settings.png)

## Views

![settings](http://s6.postimg.org/dbxgqd4ch/header.png)

---

![settings](http://s6.postimg.org/45f632z41/post_RP.png)

---

![settings](http://s6.postimg.org/bzfroh6wx/wall_Of_Fame.png)

39 changes: 39 additions & 0 deletions addons/plugins/Reputation/ReputationController.class.php
@@ -0,0 +1,39 @@
<?php
// Made by Yathish
// This file is part of esoTalk. Please see the included license file for usage information.

if (!defined("IN_ESOTALK")) exit;

/**
* The reputation controller handles the wall of reputation, to fetch top reputation members, their ranks and nearby reputation members.
*
* @package esoTalk
*/
class ReputationController extends ETController {

public function action_index($orderBy = false, $start = 0)
{
if (!$this->allowed("esoTalk.members.visibleToGuests")) return;
//If admin has disabled reputatoin points, break
if(!C("plugin.Reputation.showReputationPublic")) return;
$model = ET::getInstance("reputationModel");
$members = $model->getReputationMembers();

//Get rank of current member and get nearby members if rank is greater than 10
$rank = $model->getRankOfCurrentMember(ET::$session->userId, $members);
//Three parameters for getNearbyReputationMembers is number of members to be shown, offset, members array
if($rank>10) $nearbyMembers = $model->getNearbyReputationMembers(10, $rank-5, $members);

//Get top 10 reputation members
$topMembers = $model->getTopReputationMembers(10, $members);

//Pass data to view
$this->data("topMembers",$topMembers);
$this->data("nearbyMembers",$nearbyMembers);
$this->data("rank",$rank);

$this->render("reputation");
}

}

62 changes: 62 additions & 0 deletions addons/plugins/Reputation/ReputationModel.class.php
@@ -0,0 +1,62 @@
<?php
// Made by Yathish
// This file is part of esoTalk. Please see the included license file for usage information.

if (!defined("IN_ESOTALK")) exit;

/**
* The reputation model provides functions for retrieving and managing member data, reputation points and rank.
*
* @package esoTalk
*/
class ReputationModel extends ETModel {

public function __construct()
{
parent::__construct("reputation");
}

public function getReputationMembers()
{
$result = ET::SQL()
->select("username")
->select("memberId")
->select("reputationPoints")
->from("member")
->orderBy("reputationPoints DESC")
->exec()
->allRows();

//Assign ranks to all members based on reputation points
$rank = 1;
foreach ($result as $k => $v) {
$results[$k]["rank"] = $rank;
$results[$k]["avatar"] = avatar($v, "thumb");
$results[$k]["username"] = $result[$k]["username"];
$results[$k]["memberId"] = $result[$k]["memberId"];
$results[$k]["reputationPoints"] = $result[$k]["reputationPoints"];
$rank++;
}
return $results;

}

public function getRankOfCurrentMember($memberId, $results)
{

foreach ($results as $v) {
if($v["memberId"] == $memberId) return $v["rank"];
}
}

public function getNearbyReputationMembers($limit, $offset, $results)
{
return array_slice($results, $offset, $limit);
}

public function getTopReputationMembers($limit, $results)
{
return array_slice($results, 0, $limit);
}

}
Binary file added addons/plugins/Reputation/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.

0 comments on commit 44f5d78

Please sign in to comment.