Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
nodeloc committed Jan 31, 2024
1 parent 4bff0d1 commit 23d9ac6
Show file tree
Hide file tree
Showing 65 changed files with 688 additions and 720 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/backend.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: FoF Polls PHP
name: Lottery PHP

on: [workflow_dispatch, push, pull_request]

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/frontend.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: FoF Polls JS
name: Lottery JS

on: [workflow_dispatch, push, pull_request]

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019-2022 FriendsOfFlarum
Copyright (c) 2019-2022 Nodeloc
Copyright (c) 2018 ReFlar
Copyright (c) Shahiem Seymor

Expand Down
36 changes: 16 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,53 +1,49 @@
# Polls by FriendsOfFlarum
# Lottery by Nodeloc

![License](https://img.shields.io/badge/license-MIT-blue.svg) [![Latest Stable Version](https://img.shields.io/packagist/v/fof/polls.svg)](https://packagist.org/packages/fof/polls) [![OpenCollective](https://img.shields.io/badge/opencollective-fof-blue.svg)](https://opencollective.com/fof/donate) [![Patreon](https://img.shields.io/badge/patreon-datitisev-f96854.svg?logo=patreon)](https://patreon.com/datitisev)
![License](https://img.shields.io/badge/license-MIT-blue.svg) [![Latest Stable Version](https://img.shields.io/packagist/v/nodeloc/lottery.svg)](https://packagist.org/packages/nodeloc/lottery) [![OpenCollective](https://img.shields.io/badge/opencollective-fof-blue.svg)](https://opencollective.com/fof/donate) [![Patreon](https://img.shields.io/badge/patreon-datitisev-f96854.svg?logo=patreon)](https://patreon.com/datitisev)

A [Flarum](http://flarum.org) extension. A Flarum extension that adds polls to your discussions.
A [Flarum](http://flarum.org) extension. A Flarum extension that adds lottery to your discussions.

### Installation

```sh
composer require fof/polls:"*"
composer require nodeloc/lottery:"*"
```

#### Migrating from ReFlar Polls
#### Migrating from ReFlar Lottery

Make sure you've updated to the latest `reflar/polls` version and run `php flarum migrate` BEFORE installing `fof/polls`.
You will not be able to install this extension if you have a version of ReFlar Polls older than v1.3.4 as well.
Make sure you've updated to the latest `reflar/lottery` version and run `php flarum migrate` BEFORE installing `nodeloc/lottery`.
You will not be able to install this extension if you have a version of ReFlar Lottery older than v1.3.4 as well.

```sh
$ composer require reflar/polls
$ composer require nodeloc/lottery
$ php flarum migrate
$ composer require fof/polls
```

### Updating

```sh
composer update fof/polls
composer update nodeloc/lottery
```

### Metadata update

To improve performance, Polls calculates and stores the number of votes when it changes.
To improve performance, Lottery calculates and stores the number of votes when it changes.

As long as the extension is active, Polls will automatically keep those numbers up to date and you don't need to do anything.
As long as the extension is active, Lottery will automatically keep those numbers up to date and you don't need to do anything.

If you are updating from a version prior to 0.3.3, if you disabled the extension for a while or if you made manual changes to the database you should run the following command to refresh the numbers:

```sh
php flarum fof:polls:refresh
php flarum nodeloc:lottery:refresh
```

You can only run the command when the extension is enabled in the admin panel.

### Links

[<img src="https://opencollective.com/fof/donate/button@2x.png?color=blue" height="25" />](https://opencollective.com/fof/donate)
[<img src="https://c5.patreon.com/external/logo/become_a_patron_button.png" height="25" />](https://patreon.com/datitisev)
- [Packagist](https://packagist.org/packages/nodeloc/lottery)
- [GitHub](https://github.com/packages/Nodeloc/lottery)
- [Discuss](https://www.nodeloc.com)

- [Packagist](https://packagist.org/packages/fof/polls)
- [GitHub](https://github.com/packages/FriendsOfFlarum/polls)
- [Discuss](https://discuss.flarum.org/d/20586)

An extension by [FriendsOfFlarum](https://github.com/FriendsOfFlarum).
An extension by [Nodeloc](https://github.com/Nodeloc).
53 changes: 15 additions & 38 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
{
"name": "fof/polls",
"description": " A Flarum extension that adds polls to your discussions",
"name": "nodeloc/lottery",
"description": " A Flarum extension that adds lottery to your discussions",
"keywords": [
"flarum"
],
"type": "flarum-extension",
"license": "MIT",
"support": {
"issues": "https://github.com/FriendsOfFlarum/polls/issues",
"source": "https://github.com/FriendsOfFlarum/polls",
"forum": "https://discuss.flarum.org/d/20586"
"issues": "https://github.com/nodeloc/lottery/issues",
"source": "https://github.com/nodeloc/lottery",
"forum": "#"
},
"homepage": "https://friendsofflarum.org",
"homepage": "https://www.nodeloc.com",
"funding": [
{
"type": "website",
"url": "https://opencollective.com/fof/donate"
"url": "https://www.nodeloc.com"
}
],
"require": {
"flarum/core": "^1.3.0"
},
"conflict": {
"reflar/polls": "*"
"reflar/lottery": "*"
},
"authors": [
{
"name": "David Sevilla Martin",
"email": "david.s@redevs.org",
"name": "James",
"email": "james@nodeloc.com",
"role": "Developer"
}
],
"autoload": {
"psr-4": {
"FoF\\Polls\\": "src/",
"FoF\\Polls\\Migrations\\": "migrations/"
"Nodeloc\\Lottery\\": "src/",
"Nodeloc\\Lottery\\Migrations\\": "migrations/"
}
},
"extra": {
"flarum-extension": {
"title": "FoF Polls",
"title": "Lottery",
"category": "discussion",
"icon": {
"name": "fas fa-signal",
"name": "fas fa-gift",
"backgroundColor": "#e74c3c",
"color": "#fff"
}
},
"flagrow": {
"discuss": "https://discuss.flarum.org/d/20586"
"discuss": "https://www.nodeloc.com"
},
"flarum-cli": {
"modules": {
Expand All @@ -60,28 +60,5 @@
"require-dev": {
"flarum/phpstan": "*",
"flarum/testing": "^1.0.0"
},
"scripts": {
"analyse:phpstan": "phpstan analyse",
"clear-cache:phpstan": "phpstan clear-result-cache",
"test": [
"@test:unit",
"@test:integration"
],
"test:unit": "phpunit -c tests/phpunit.unit.xml",
"test:integration": "phpunit -c tests/phpunit.integration.xml",
"test:setup": "@php tests/integration/setup.php"
},
"scripts-descriptions": {
"analyse:phpstan": "Run static analysis",
"test": "Runs all tests.",
"test:unit": "Runs all unit tests.",
"test:integration": "Runs all integration tests.",
"test:setup": "Sets up a database for use with integration tests. Execute this only once."
},
"autoload-dev": {
"psr-4": {
"FoF\\Polls\\Tests\\": "tests/"
}
}
}
66 changes: 33 additions & 33 deletions extend.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php

/*
* This file is part of fof/polls.
* This file is part of nodeloc/lottery.
*
* Copyright (c) FriendsOfFlarum.
* Copyright (c) Nodeloc.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace FoF\Polls;
namespace Nodeloc\Lottery;

use Flarum\Api\Controller;
use Flarum\Api\Serializer\DiscussionSerializer;
Expand All @@ -20,8 +20,8 @@
use Flarum\Post\Event\Saving as PostSaving;
use Flarum\Post\Post;
use Flarum\Settings\Event\Saved as SettingsSaved;
use FoF\Polls\Api\Controllers;
use FoF\Polls\Api\Serializers\PollSerializer;
use Nodeloc\Lottery\Api\Controllers;
use Nodeloc\Lottery\Api\Serializers\LotterySerializer;

return [
(new Extend\Frontend('forum'))
Expand All @@ -35,71 +35,71 @@
new Extend\Locales(__DIR__.'/resources/locale'),

(new Extend\Routes('api'))
->post('/fof/polls', 'fof.polls.create', Controllers\CreatePollController::class)
->get('/fof/polls/{id}', 'fof.polls.show', Controllers\ShowPollController::class)
->patch('/fof/polls/{id}', 'fof.polls.edit', Controllers\EditPollController::class)
->delete('/fof/polls/{id}', 'fof.polls.delete', Controllers\DeletePollController::class)
->patch('/fof/polls/{id}/votes', 'fof.polls.votes', Controllers\MultipleVotesPollController::class),
->post('/nodeloc/lottery', 'nodeloc.lottery.create', Controllers\CreateLotteryController::class)
->get('/nodeloc/lottery/{id}', 'nodeloc.lottery.show', Controllers\ShowLotteryController::class)
->patch('/nodeloc/lottery/{id}', 'nodeloc.lottery.edit', Controllers\EditLotteryController::class)
->delete('/nodeloc/lottery/{id}', 'nodeloc.lottery.delete', Controllers\DeleteLotteryController::class)
->patch('/nodeloc/lottery/{id}/votes', 'nodeloc.lottery.votes', Controllers\MultipleVotesLotteryController::class),

(new Extend\Model(Post::class))
->hasMany('polls', Poll::class, 'post_id', 'id'),
->hasMany('lottery', Lottery::class, 'post_id', 'id'),

(new Extend\Model(Discussion::class))
->hasMany('polls', Poll::class, 'post_id', 'first_post_id'),
->hasMany('lottery', Lottery::class, 'post_id', 'first_post_id'),

(new Extend\Event())
->listen(PostSaving::class, Listeners\SavePollsToDatabase::class)
->listen(PostSaving::class, Listeners\SaveLotteryToDatabase::class)
->listen(SettingsSaved::class, Listeners\ClearFormatterCache::class),

(new Extend\ApiSerializer(DiscussionSerializer::class))
->attributes(Api\AddDiscussionAttributes::class),

(new Extend\ApiSerializer(PostSerializer::class))
->hasMany('polls', PollSerializer::class)
->hasMany('lottery', LotterySerializer::class)
->attributes(Api\AddPostAttributes::class),

(new Extend\ApiSerializer(ForumSerializer::class))
->attributes(Api\AddForumAttributes::class),

(new Extend\ApiController(Controller\ListDiscussionsController::class))
->addOptionalInclude(['firstPost.polls']),
->addOptionalInclude(['firstPost.lottery']),

(new Extend\ApiController(Controller\ShowDiscussionController::class))
->addInclude(['posts.polls', 'posts.polls.options', 'posts.polls.myVotes', 'posts.polls.myVotes.option'])
->addOptionalInclude(['posts.polls.votes', 'posts.polls.votes.user', 'posts.polls.votes.option']),
->addInclude(['posts.lottery', 'posts.lottery.options', 'posts.lottery.myVotes', 'posts.lottery.myVotes.option'])
->addOptionalInclude(['posts.lottery.votes', 'posts.lottery.votes.user', 'posts.lottery.votes.option']),

(new Extend\ApiController(Controller\CreateDiscussionController::class))
->addInclude(['firstPost.polls', 'firstPost.polls.options', 'firstPost.polls.myVotes', 'firstPost.polls.myVotes.option'])
->addOptionalInclude(['firstPost.polls.votes', 'firstPost.polls.votes.user', 'firstPost.polls.votes.option']),
->addInclude(['firstPost.lottery', 'firstPost.lottery.options', 'firstPost.lottery.myVotes', 'firstPost.lottery.myVotes.option'])
->addOptionalInclude(['firstPost.lottery.votes', 'firstPost.lottery.votes.user', 'firstPost.lottery.votes.option']),

(new Extend\ApiController(Controller\CreatePostController::class))
->addInclude(['polls', 'polls.options', 'polls.myVotes', 'polls.myVotes.option'])
->addOptionalInclude(['polls.votes', 'polls.votes.user', 'polls.votes.option']),
->addInclude(['lottery', 'lottery.options', 'lottery.myVotes', 'lottery.myVotes.option'])
->addOptionalInclude(['lottery.votes', 'lottery.votes.user', 'lottery.votes.option']),

(new Extend\ApiController(Controller\ListPostsController::class))
->addInclude(['polls', 'polls.options', 'polls.myVotes', 'polls.myVotes.option'])
->addOptionalInclude(['polls.votes', 'polls.votes.user', 'polls.votes.option']),
->addInclude(['lottery', 'lottery.options', 'lottery.myVotes', 'lottery.myVotes.option'])
->addOptionalInclude(['lottery.votes', 'lottery.votes.user', 'lottery.votes.option']),

(new Extend\ApiController(Controller\ShowPostController::class))
->addInclude(['polls', 'polls.options', 'polls.myVotes', 'polls.myVotes.option'])
->addOptionalInclude(['polls.votes', 'polls.votes.user', 'polls.votes.option']),
->addInclude(['lottery', 'lottery.options', 'lottery.myVotes', 'lottery.myVotes.option'])
->addOptionalInclude(['lottery.votes', 'lottery.votes.user', 'lottery.votes.option']),

(new Extend\Console())
->command(Console\RefreshVoteCountCommand::class),

(new Extend\Policy())
->modelPolicy(Poll::class, Access\PollPolicy::class)
->modelPolicy(Lottery::class, Access\LotteryPolicy::class)
->modelPolicy(Post::class, Access\PostPolicy::class),

(new Extend\Settings())
->default('fof-polls.maxOptions', 10)
->default('fof-polls.optionsColorBlend', true)
->serializeToForum('allowPollOptionImage', 'fof-polls.allowOptionImage', 'boolval')
->serializeToForum('pollMaxOptions', 'fof-polls.maxOptions', 'intval')
->registerLessConfigVar('fof-polls-options-color-blend', 'fof-polls.optionsColorBlend', function ($value) {
->default('nodeloc-lottery.maxOptions', 10)
->default('nodeloc-lottery.optionsColorBlend', true)
->serializeToForum('allowLotteryOptionImage', 'nodeloc-lottery.allowOptionImage', 'boolval')
->serializeToForum('lotteryMaxOptions', 'nodeloc-lottery.maxOptions', 'intval')
->registerLessConfigVar('nodeloc-lottery-options-color-blend', 'nodeloc-lottery.optionsColorBlend', function ($value) {
return $value ? 'true' : 'false';
}),

(new Extend\ModelVisibility(Poll::class))
->scope(Access\ScopePollVisibility::class),
(new Extend\ModelVisibility(Lottery::class))
->scope(Access\ScopeLotteryVisibility::class),
];
2 changes: 1 addition & 1 deletion js/dist/admin.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 23d9ac6

Please sign in to comment.