Gamification by FriendsOfFlarum

License Latest Stable Version OpenCollective

Extiverse

A Flarum extension. Add upvotes, downvotes, and ranks to your Flarum Community!

Upvote and downvote posts anonymously, and reward active users with ranks, and sort posts by hotness/popularity.

  • Q: How is hotness sorted ?
  • A: The total amount of hotness is got between the amount of votes on the discussion and the posts inside of it. Also, newer posts with the same amount of upvotes as another post will have more hotness, so time is also an influent factor.

Installation

Install manually with composer:

composer require fof/gamification

You can optionally convert your likes into upvotes, as well as calculate the hotness of all previously existing discussions.

Updating

composer update fof/gamification
php flarum migrate
php flarum cache:clear

Commands

Gamification doesn't need any CRON job, every calculated value will update itself automatically as needed.

However, if the calculated values become out of date as a result of a database migration, due to the extension being temporarily disabled or to import existing data when first using the extension, you can use the following commands to fix the values.

The following commands can be run in the Flarum folder:

php flarum fof:gamification:assign-groups

Updates all users in the database to match the current "Automatically assigned groups" rules.

Even if a user was manually assigned to a group, the group will still be removed if it doesn't match the rules.

php flarum fof:gamification:resync

Updates all discussions with their total first post votes.

php flarum fof:gamification:resyncUsers

Updates all users with a forced recalculation of points.

Links

An extension by FriendsOfFlarum.

    When enabling:
    Failed to load resource: the server responded with a status of 500 (Internal Server Error)

    I tested on clear installation as well.

      i've posted an issue on github to for the table name for the rank in the rank.php file, seems like was not modified like in the migration file.

        After uninstall this extension, like button moved right side of reply button.
        luceos mine line here.
        /var/www/dmn/public_html/vendor/fof/gamification/migrations/2019_07_09_000001_add_attributes_to_users.php(25): Illuminate\Database\Schema\Builder->table('users', Object(Closure))

          luceos
          Seems that it doesn't create SQL table (?)

          Next Illuminate\Database\QueryException: SQLSTATE[42S02]: Base table or view not found: 1146 Table so853_forums.ranks doesnt exist (SQL: select * from ranks) in /home/so853/domains/DOMAIN/public_html/forum/vendor/illuminate/database/Connection.php:664

            Veriael Whoops ! Seems like I somehow removed any migration that created the ranks table, sorry about that. Fixing right now. Same with mrnemesys, thank you for the report.

            tolgaaaltas After uninstall this extension, like button moved right side of reply button.

            That's not an issue, extension order matters on how items are positioned. However, about your log, is that an error you are having too ? If so, could you post the whole line ? There really isn't much to go on from there right now.

            0.1.2

            • Add migration for ranks table 🤦‍♂️
            • Fix issue when last vote time is null, you wouldn't be able to vote at all

            Updating

            composer update fof/gamification
              7 days later

              In a future update would it be possible to have the user rank number listed under the profile picture when they post?

              5 days later

              Things seem to work fine with this extension. But, it's not converting my likes into upvotes. The instructions say to wait a few minutes. I waited all day. My log is below.

              If it helps I'm using the latest version of Flarum, and PHP 7.3. Maybe it's a conflict with another extension. I know that when I tried this extension in the past, when it was still a reflar extension, something didn't work for me (I forget what) and so I removed it. I want to say it was an extension conflict back then; so maybe that's the problem again this time... But, I love the upvoting and other features so much that I really don't want to remove it again.

              See anything obvious?

              [2019-07-21 17:09:45] production.ERROR: Error: Class 'FoF\Gamification\vote' not found in /vendor/fof/gamification/src/Gamification.php:126
              Stack trace:
              #0 /vendor/fof/gamification/src/Api/Controllers/ConvertLikesController.php(65): FoF\Gamification\Gamification->convertLike('13', '4')
              #1 /vendor/flarum/core/src/Http/RouteHandlerFactory.php(40): FoF\Gamification\Api\Controllers\ConvertLikesController->handle(Object(Zend\Diactoros\ServerRequest))
              #2 /vendor/flarum/core/src/Http/Middleware/DispatchRoute.php(67): Flarum\Http\RouteHandlerFactory->Flarum\Http\{closure}(Object(Zend\Diactoros\ServerRequest), Array)
              #3 /vendor/zendframework/zend-stratigility/src/Next.php(60): Flarum\Http\Middleware\DispatchRoute->process(Object(Zend\Diactoros\ServerRequest), Object(Closure))
              #4 /vendor/reflar/stopforumspam/src/Middleware/RegisterMiddleware.php(75): Zend\Stratigility\Next->handle(Object(Zend\Diactoros\ServerRequest))
              #5 /vendor/zendframework/zend-stratigility/src/Next.php(60): Reflar\Stopforumspam\middleware\RegisterMiddleware->process(Object(Zend\Diactoros\ServerRequest), Object(Zend\Stratigility\Next))
              #6 /vendor/fof/secure-https/src/Middlewares/ContentSecurityPolicyMiddleware.php(21): Zend\Stratigility\Next->handle(Object(Zend\Diactoros\ServerRequest))
              #7 /vendor/zendframework/zend-stratigility/src/Next.php(60): FoF\SecureHttps\Middlewares\ContentSecurityPolicyMiddleware->process(Object(Zend\Diactoros\ServerRequest), Object(Zend\Stratigility\Next))
              #8 /vendor/flagrow/terms/src/Middlewares/RegisterMiddleware.php(59): Zend\Stratigility\Next->handle(Object(Zend\Diactoros\ServerRequest))
              #9 /vendor/zendframework/zend-stratigility/src/Next.php(60): Flagrow\Terms\Middlewares\RegisterMiddleware->process(Object(Zend\Diactoros\ServerRequest), Object(Zend\Stratigility\Next))
              #10 /vendor/flarum/core/src/Http/Middleware/SetLocale.php(51): Zend\Stratigility\Next->handle(Object(Zend\Diactoros\ServerRequest))
              #11 /vendor/zendframework/zend-stratigility/src/Next.php(60): Flarum\Http\Middleware\SetLocale->process(Object(Zend\Diactoros\ServerRequest), Object(Zend\Stratigility\Next))
              #12 /vendor/flarum/core/src/Http/Middleware/CheckCsrfToken.php(33): Zend\Stratigility\Next->handle(Object(Zend\Diactoros\ServerRequest))
              #13 /vendor/zendframework/zend-stratigility/src/Next.php(60): Flarum\Http\Middleware\CheckCsrfToken->process(Object(Zend\Diactoros\ServerRequest), Object(Zend\Stratigility\Next))
              #14 /vendor/flarum/core/src/Http/Middleware/AuthenticateWithHeader.php(56): Zend\Stratigility\Next->handle(Object(Zend\Diactoros\ServerRequest))
              #15 /vendor/zendframework/zend-stratigility/src/Next.php(60): Flarum\Http\Middleware\AuthenticateWithHeader->process(Object(Zend\Diactoros\ServerRequest), Object(Zend\Stratigility\Next))
              #16 /vendor/flarum/core/src/Http/Middleware/AuthenticateWithSession.php(34): Zend\Stratigility\Next->handle(Object(Zend\Diactoros\ServerRequest))
              #17 /vendor/zendframework/zend-stratigility/src/Next.php(60): Flarum\Http\Middleware\AuthenticateWithSession->process(Object(Zend\Diactoros\ServerRequest), Object(Zend\Stratigility\Next))
              #18 /vendor/flarum/core/src/Http/Middleware/RememberFromCookie.php(52): Zend\Stratigility\Next->handle(Object(Zend\Diactoros\ServerRequest))
              #19 /vendor/zendframework/zend-stratigility/src/Next.php(60): Flarum\Http\Middleware\RememberFromCookie->process(Object(Zend\Diactoros\ServerRequest), Object(Zend\Stratigility\Next))
              #20 /vendor/flarum/core/src/Http/Middleware/StartSession.php(62): Zend\Stratigility\Next->handle(Object(Zend\Diactoros\ServerRequest))
              #21 /vendor/zendframework/zend-stratigility/src/Next.php(60): Flarum\Http\Middleware\StartSession->process(Object(Zend\Diactoros\ServerRequest), Object(Zend\Stratigility\Next))
              #22 /vendor/flarum/core/src/Api/Middleware/FakeHttpMethods.php(31): Zend\Stratigility\Next->handle(Object(Zend\Diactoros\ServerRequest))
              #23 /vendor/zendframework/zend-stratigility/src/Next.php(60): Flarum\Api\Middleware\FakeHttpMethods->process(Object(Zend\Diactoros\ServerRequest), Object(Zend\Stratigility\Next))
              #24 /vendor/flarum/core/src/Http/Middleware/ParseJsonBody.php(29): Zend\Stratigility\Next->handle(Object(Zend\Diactoros\ServerRequest))
              #25 /vendor/zendframework/zend-stratigility/src/Next.php(60): Flarum\Http\Middleware\ParseJsonBody->process(Object(Zend\Diactoros\ServerRequest), Object(Zend\Stratigility\Next))
              #26 /vendor/flarum/core/src/Api/Middleware/HandleErrors.php(42): Zend\Stratigility\Next->handle(Object(Zend\Diactoros\ServerRequest))
              #27 /vendor/zendframework/zend-stratigility/src/Next.php(60): Flarum\Api\Middleware\HandleErrors->process(Object(Zend\Diactoros\ServerRequest), Object(Zend\Stratigility\Next))
              #28 /vendor/zendframework/zend-stratigility/src/MiddlewarePipe.php(83): Zend\Stratigility\Next->handle(Object(Zend\Diactoros\ServerRequest))
              #29 /vendor/middlewares/request-handler/src/RequestHandler.php(84): Zend\Stratigility\MiddlewarePipe->process(Object(Zend\Diactoros\ServerRequest), Object(Zend\Stratigility\Next))
              #30 /vendor/zendframework/zend-stratigility/src/Next.php(60): Middlewares\RequestHandler->process(Object(Zend\Diactoros\ServerRequest), Object(Zend\Stratigility\Next))
              #31 /vendor/middlewares/base-path-router/src/BasePathRouter.php(97): Zend\Stratigility\Next->handle(Object(Zend\Diactoros\ServerRequest))
              #32 /vendor/zendframework/zend-stratigility/src/Next.php(60): Middlewares\BasePathRouter->process(Object(Zend\Diactoros\ServerRequest), Object(Zend\Stratigility\Next))
              #33 /vendor/zendframework/zend-stratigility/src/Middleware/OriginalMessages.php(41): Zend\Stratigility\Next->handle(Object(Zend\Diactoros\ServerRequest))
              #34 /vendor/zendframework/zend-stratigility/src/Next.php(60): Zend\Stratigility\Middleware\OriginalMessages->process(Object(Zend\Diactoros\ServerRequest), Object(Zend\Stratigility\Next))
              #35 /vendor/middlewares/base-path/src/BasePath.php(53): Zend\Stratigility\Next->handle(Object(Zend\Diactoros\ServerRequest))
              #36 /vendor/zendframework/zend-stratigility/src/Next.php(60): Middlewares\BasePath->process(Object(Zend\Diactoros\ServerRequest), Object(Zend\Stratigility\Next))
              #37 /vendor/zendframework/zend-stratigility/src/MiddlewarePipe.php(83): Zend\Stratigility\Next->handle(Object(Zend\Diactoros\ServerRequest))
              #38 /vendor/zendframework/zend-stratigility/src/MiddlewarePipe.php(72): Zend\Stratigility\MiddlewarePipe->process(Object(Zend\Diactoros\ServerRequest), Object(Zend\Stratigility\EmptyPipelineHandler))
              #39 /vendor/zendframework/zend-httphandlerrunner/src/RequestHandlerRunner.php(95): Zend\Stratigility\MiddlewarePipe->handle(Object(Zend\Diactoros\ServerRequest))
              #40 /vendor/flarum/core/src/Http/Server.php(46): Zend\HttpHandlerRunner\RequestHandlerRunner->run()
              #41 /public_html/index.php(22): Flarum\Http\Server->listen()
              #42 {main}
              
              Next Exception: Class 'FoF\Gamification\vote' not found in /vendor/flarum/core/src/Api/ErrorHandler.php:41
              Stack trace:
              #0 /vendor/flarum/core/src/Api/Middleware/HandleErrors.php(44): Flarum\Api\ErrorHandler->handle(Object(Error))
              #1 /vendor/zendframework/zend-stratigility/src/Next.php(60): Flarum\Api\Middleware\HandleErrors->process(Object(Zend\Diactoros\ServerRequest), Object(Zend\Stratigility\Next))
              #2 /vendor/zendframework/zend-stratigility/src/MiddlewarePipe.php(83): Zend\Stratigility\Next->handle(Object(Zend\Diactoros\ServerRequest))
              #3 /vendor/middlewares/request-handler/src/RequestHandler.php(84): Zend\Stratigility\MiddlewarePipe->process(Object(Zend\Diactoros\ServerRequest), Object(Zend\Stratigility\Next))
              #4 /vendor/zendframework/zend-stratigility/src/Next.php(60): Middlewares\RequestHandler->process(Object(Zend\Diactoros\ServerRequest), Object(Zend\Stratigility\Next))
              #5 /vendor/middlewares/base-path-router/src/BasePathRouter.php(97): Zend\Stratigility\Next->handle(Object(Zend\Diactoros\ServerRequest))
              #6 /vendor/zendframework/zend-stratigility/src/Next.php(60): Middlewares\BasePathRouter->process(Object(Zend\Diactoros\ServerRequest), Object(Zend\Stratigility\Next))
              #7 /vendor/zendframework/zend-stratigility/src/Middleware/OriginalMessages.php(41): Zend\Stratigility\Next->handle(Object(Zend\Diactoros\ServerRequest))
              #8 /vendor/zendframework/zend-stratigility/src/Next.php(60): Zend\Stratigility\Middleware\OriginalMessages->process(Object(Zend\Diactoros\ServerRequest), Object(Zend\Stratigility\Next))
              #9 /vendor/middlewares/base-path/src/BasePath.php(53): Zend\Stratigility\Next->handle(Object(Zend\Diactoros\ServerRequest))
              #10 /vendor/zendframework/zend-stratigility/src/Next.php(60): Middlewares\BasePath->process(Object(Zend\Diactoros\ServerRequest), Object(Zend\Stratigility\Next))
              #11 /vendor/zendframework/zend-stratigility/src/MiddlewarePipe.php(83): Zend\Stratigility\Next->handle(Object(Zend\Diactoros\ServerRequest))
              #12 /vendor/zendframework/zend-stratigility/src/MiddlewarePipe.php(72): Zend\Stratigility\MiddlewarePipe->process(Object(Zend\Diactoros\ServerRequest), Object(Zend\Stratigility\EmptyPipelineHandler))
              #13 /vendor/zendframework/zend-httphandlerrunner/src/RequestHandlerRunner.php(95): Zend\Stratigility\MiddlewarePipe->handle(Object(Zend\Diactoros\ServerRequest))
              #14 /vendor/flarum/core/src/Http/Server.php(46): Zend\HttpHandlerRunner\RequestHandlerRunner->run()
              #15 /public_html/index.php(22): Flarum\Http\Server->listen()
              #16 {main}

                010101 Looks like it was a small capitalization error.

                How to get it setup now:

                1. Update to version 0.1.3
                2. Delete fof-gamification.convertedLikes in the settings table of your Flarum database in mysql
                3. Re-run the conversion in the admin panel.
                  15 days later

                  Hey there - Just want to make sure you are aware that this extension still causes this delete forever issue discussed here:

                  flarum/core1717

                    010101

                    0.1.4

                    Additions 🛠️

                    • Added ability to show original post votes on the discussion page (optional)
                    • Added ability to turn on the vote floodgate (now off by default)

                    Fixed Issues 🐛

                    • Fixed an issue that caused an error to popup on post deletion
                    • Fixed an issue that caused votes to not be removed from a user when a post was deleted
                    • Fixed an issue that caused user ranks to not be removed when a vote was deleted

                    Optimization 🧠

                    • Simplified post vote/user rank creation and deletion logic

                    Updating ⬆️

                    Run these commands in your Flarum root directory:

                    composer update fof/gamification
                    php flarum migrate
                      • [deleted]

                      Curious to know if there is any reason for the styling on the Ranking page not matching that of the main view. By this, I mean that in the main view, the navigation pane is on the left, and in the ranking view, it's across the top with a scroll bar. This makes it look out of place, and, a bit...well..."ugly" 🙂