Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/codeception-min-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ jobs:
with:
module-id: polls
use-rest-module: true
rest-module-branch: develop
6 changes: 2 additions & 4 deletions Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ public static function onSampleDataInstall($event)

$comment = new \humhub\modules\comment\models\Comment();
$comment->message = Yii::t('PollsModule.base', "Why don't we go to Bemelmans Bar?");
$comment->object_model = $poll->className();
$comment->object_id = $poll->getPrimaryKey();
$comment->content_id = $poll->content->id;
$comment->save();

// Switch Identity
Expand All @@ -155,8 +154,7 @@ public static function onSampleDataInstall($event)

$comment = new \humhub\modules\comment\models\Comment();
$comment->message = Yii::t('PollsModule.base', "Again? :weary:");
$comment->object_model = $poll->className();
$comment->object_id = $poll->getPrimaryKey();
$comment->content_id = $poll->content->id;
$comment->save();

// Switch Identity
Expand Down
14 changes: 0 additions & 14 deletions Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace humhub\modules\polls;

use humhub\components\console\Application as ConsoleApplication;
use humhub\modules\user\models\User;
use humhub\modules\polls\models\Poll;
use humhub\modules\space\models\Space;
Expand All @@ -26,19 +25,6 @@ class Module extends ContentContainerModule
*/
public $resourcesPath = 'resources';

/**
* @inheritdoc
*/
public function init()
{
parent::init();

if (Yii::$app instanceof ConsoleApplication) {
// Prevents the Yii HelpCommand from crawling all web controllers and possibly throwing errors at REST endpoints if the REST module is not available.
$this->controllerNamespace = 'polls/commands';
}
}

/**
* @inheritdoc
*/
Expand Down
38 changes: 12 additions & 26 deletions activities/NewVote.php
Original file line number Diff line number Diff line change
@@ -1,43 +1,29 @@
<?php

/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2015 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/

namespace humhub\modules\polls\activities;

use humhub\modules\activity\components\BaseActivity;
use humhub\modules\activity\components\BaseContentActivity;
use humhub\modules\activity\interfaces\ConfigurableActivityInterface;
use Yii;

class NewVote extends BaseActivity implements ConfigurableActivityInterface
class NewVote extends BaseContentActivity implements ConfigurableActivityInterface
{
/**
* @inheritdoc
*/
public $moduleId = 'polls';

/**
* @inheritdoc
*/
public $viewName = 'newVote';

/**
* @inheritdoc
*/
public function getTitle()
public static function getTitle(): string
{
return Yii::t('PollsModule.base', 'Polls');
}

/**
* @inheritdoc
*/
public function getDescription()
public static function getDescription(): string
{
return Yii::t('PollsModule.base', 'Whenever someone participates in a poll.');
}

protected function getMessage(array $params): string
{
// Backward compatibility of translation placeholders
$params['userName'] = $params['displayName'];
$params['question'] = $params['contentTitle'];

return Yii::t('PollsModule.base', '{userName} answered the {question}.', $params);
}
}
9 changes: 0 additions & 9 deletions activities/views/newVote.php

This file was deleted.

12 changes: 6 additions & 6 deletions controllers/PollController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use humhub\modules\polls\models\Poll;
use humhub\modules\polls\models\PollAnswer;
use humhub\modules\polls\widgets\WallCreateForm;
use humhub\modules\stream\actions\Stream;
use humhub\modules\stream\actions\StreamEntryResponse;
use humhub\modules\user\models\User;
use humhub\modules\user\widgets\UserListBox;
use humhub\helpers\Html;
Expand Down Expand Up @@ -67,7 +67,7 @@ public function actionReload($id)
throw new HttpException(403);
}

return $this->asJson(Stream::getContentResultEntry($model->content));
return $this->asJson(StreamEntryResponse::getAsArray($model->content));
}

public function actionEdit()
Expand Down Expand Up @@ -95,7 +95,7 @@ public function actionEdit()
if ($model->validate() && $model->save()) {
// Reload record to get populated updated_at field
$model = Poll::findOne(['id' => $id]);
return Stream::getContentResultEntry($model->content);
return StreamEntryResponse::getAsArray($model->content);
} else {
$result['errors'] = $model->getErrors();
}
Expand Down Expand Up @@ -131,7 +131,7 @@ public function setClosed($id, $closed)
// Refresh updated_at
$model->content->refresh();

return Stream::getContentResultEntry($model->content);
return StreamEntryResponse::getAsArray($model->content);
}

/**
Expand Down Expand Up @@ -159,7 +159,7 @@ public function actionAnswer()

$poll->vote($votes);

return Stream::getContentResultEntry($poll->content);
return StreamEntryResponse::getAsArray($poll->content);
}

/**
Expand All @@ -169,7 +169,7 @@ public function actionAnswerReset()
{
$poll = $this->getPollByParameter();
$poll->resetAnswer();
return $this->asJson(Stream::getContentResultEntry($poll->content));
return $this->asJson(StreamEntryResponse::getAsArray($poll->content));
}

/**
Expand Down
10 changes: 9 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
Changelog
=========

1.4.5 (Feburary 27, 2026)
1.5.1 (July 23, 2026)
---------------------
- Fix #175: Error creating installer sample content (comment no longer uses removed `object_model`/`object_id` properties)

1.5.0 (June 5, 2026)
--------------------
- Enh #174: Update for HumHub 1.19

1.4.5 (February 27, 2026)
-------------------------
- Fix #173: Alignment on large screens and Enterprise Theme

Expand Down
3 changes: 1 addition & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
[![Test Status](https://github.com/humhub/polls/actions/workflows/php-test-master.yml/badge.svg)](https://github.com/humhub/polls/actions/workflows/php-test-master.yml)

# Polls

Easily create polls with the intuitive Polls Module, simplifying decision-making on your network. Whether you're seeking opinions on urgent matters or aiming for consensus, harness the power of voting to streamline discussions and swiftly resolve disputes.
Expand All @@ -10,3 +8,4 @@ Easily create polls with the intuitive Polls Module, simplifying decision-making
- **Vote Types:** Choose between regular and anonymous voting.
- **Choices:** Allow your users to select single or multiple options.
- **Blind Voting:** Keep poll results hidden until it's closed to avoid choice bias.

17 changes: 13 additions & 4 deletions migrations/m150709_151858_namespace.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
<?php

use yii\db\Schema;
use humhub\modules\polls\models\Poll;
use humhub\components\Migration;

class m150709_151858_namespace extends Migration
{
public function up()
{
$this->renameClass('Poll', humhub\modules\polls\models\Poll::className());
$this->update('activity', ['class' => 'humhub\modules\content\activities\ContentCreated', 'module' => 'content'], ['class' => 'PollCreated']);
$this->update('activity', ['class' => 'humhub\modules\polls\activities\NewVote', 'module' => 'polls'], ['class' => 'PollAnswered']);
$this->renameClass('Poll', Poll::class);

$table = $this->db->getTableSchema('activity');
$columnsContentCreated = ['class' => 'humhub\modules\content\activities\ContentCreated'];
$columnsNewVote = ['class' => 'humhub\modules\polls\activities\NewVote'];
if (isset($table->columns['module'])) {
$columnsContentCreated['module'] = 'content';
$columnsNewVote['module'] = 'polls';
}

$this->update('activity', $columnsContentCreated, ['class' => 'PollCreated']);
$this->update('activity', $columnsNewVote, ['class' => 'PollAnswered']);
}

public function down()
Expand Down
10 changes: 4 additions & 6 deletions models/Poll.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

namespace humhub\modules\polls\models;

use humhub\modules\activity\services\ActivityManager;
use humhub\modules\content\widgets\richtext\RichText;
use humhub\modules\polls\activities\NewVote;
use humhub\modules\polls\permissions\CreatePoll;
use humhub\modules\search\interfaces\Searchable;
use humhub\modules\content\components\ContentActiveRecord;
use Yii;

Expand Down Expand Up @@ -32,7 +33,7 @@
* @since 0.5
* @author Luke
*/
class Poll extends ContentActiveRecord implements Searchable
class Poll extends ContentActiveRecord
{
public const MIN_REQUIRED_ANSWERS = 2;
public const SCENARIO_CREATE = 'create';
Expand Down Expand Up @@ -309,10 +310,7 @@ public function vote($votes = [])
}

if ($voted && !$this->anonymous) {
$activity = new \humhub\modules\polls\activities\NewVote();
$activity->source = $this;
$activity->originator = Yii::$app->user->getIdentity();
$activity->create();
ActivityManager::dispatch(NewVote::class, $this);
}

return $voted;
Expand Down
5 changes: 2 additions & 3 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
"name": "Polls",
"description": "Easily create polls, streamline decision-making, and harness the power of voting.",
"keywords": ["poll", "voting", "decision making"],
"version": "1.4.5",
"version": "1.5.1",
"humhub": {
"minVersion": "1.18.1",
"maxVersion": "1.18"
"minVersion": "1.19"
},
"homepage": "https://github.com/humhub/polls",
"authors": [
Expand Down
29 changes: 16 additions & 13 deletions widgets/views/closeButton.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
<?php

use humhub\modules\polls\models\Poll;
use humhub\widgets\bootstrap\Link;

/* @var Poll $poll */
?>
<li>
<?php if ($poll->closed) : ?>
<a class="dropdown-item" href="#" data-action-click="close" data-action-target="[data-poll='<?= $poll->id ?>']"
data-action-url="<?= $poll->content->container->createUrl('/polls/poll/open', ['id' => $poll->id]); ?>">
<i class="fa fa-check"></i>
<?= Yii::t('PollsModule.base', 'Reopen Poll') ?>
</a>
<?php else : ?>
<a class="dropdown-item" data-action-click="close" data-action-target="[data-poll='<?= $poll->id ?>']"
data-action-url="<?= $poll->content->container->createUrl('/polls/poll/close', ['id' => $poll->id]); ?>">
<i class="fa fa-times"></i>
<?= Yii::t('PollsModule.base', 'Close Poll') ?>
</a>
<?php endif; ?>
<?= $poll->closed
? Link::to(Yii::t('PollsModule.base', 'Reopen Poll'))
->action('close', $poll->content->container->createUrl('/polls/poll/open', ['id' => $poll->id]), '[data-poll=' . $poll->id . ']')
->icon('check')
->cssClass('dropdown-item')
: Link::to(Yii::t('PollsModule.base', 'Close Poll'))
->action('close', $poll->content->container->createUrl('/polls/poll/close', ['id' => $poll->id]), '[data-poll=' . $poll->id . ']')
->icon('times')
->cssClass('dropdown-item') ?>
</li>
17 changes: 11 additions & 6 deletions widgets/views/resetButton.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
<?php

use humhub\modules\polls\models\Poll;
use humhub\widgets\bootstrap\Link;

/* @var Poll $poll */
?>
<li>
<a class="dropdown-item" href="#" data-action-click="reset"
data-action-target="[data-poll='<?= $poll->id ?>']"
data-action-url="<?= $poll->content->container->createUrl('/polls/poll/answer-reset', ['pollId' => $poll->id]); ?>">
<i class="fa fa-undo"></i>
<?= Yii::t('PollsModule.base', 'Reset my vote') ?>
</a>
<?= Link::to(Yii::t('PollsModule.base', 'Reset my vote'))
->action('reset', $poll->content->container->createUrl('/polls/poll/answer-reset', ['pollId' => $poll->id]), '[data-poll=' . $poll->id . ']')
->icon('undo')
->cssClass('dropdown-item') ?>
</li>
Loading