Skip to content

Commit

Permalink
Merge pull request #74 from humhub/enh/71-wall-stream-layout-migration
Browse files Browse the repository at this point in the history
Wall Stream Layout Migration #71
  • Loading branch information
luke- committed Oct 30, 2020
2 parents 4468404 + 624ff6e commit ade1773
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 55 deletions.
7 changes: 7 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
=========

1.0.0 (November 30, 2020)
---------------------
- Enh #71: Wall Stream Layout Migration (HumHub 1.7+)
- Enh: Rename the attribute "Question" to "Description"
- Enh: Add an attribute "Question" as simple short text


0.9.20 - October 16, 2020
-------------------------
- Enh #15: Implement user profile polls
Expand Down
28 changes: 28 additions & 0 deletions migrations/m201020_125649_question_description.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use yii\db\Migration;
use yii\db\Schema;

/**
* Class m201020_125649_question_description
*/
class m201020_125649_question_description extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->renameColumn('poll', 'question', 'description');
$this->addColumn('poll', 'question', Schema::TYPE_STRING . ' AFTER id');
}

/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropColumn('poll', 'question');
$this->renameColumn('poll', 'description','question');
}
}
18 changes: 11 additions & 7 deletions models/Poll.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*
* @property integer $id
* @property string $question
* @property string $description
* @property integer $allow_multiple
* @property string $created_at
* @property integer $created_by
Expand Down Expand Up @@ -51,8 +52,8 @@ public function scenarios()
{
return [
self::SCENARIO_CLOSE => [],
self::SCENARIO_CREATE => ['question', 'anonymous', 'is_random', 'show_result_after_close', 'newAnswers', 'allow_multiple'],
self::SCENARIO_EDIT => ['question', 'anonymous', 'is_random', 'show_result_after_close','newAnswers', 'editAnswers', 'allow_multiple']
self::SCENARIO_CREATE => ['question', 'description', 'anonymous', 'is_random', 'show_result_after_close', 'newAnswers', 'allow_multiple'],
self::SCENARIO_EDIT => ['question', 'description', 'anonymous', 'is_random', 'show_result_after_close','newAnswers', 'editAnswers', 'allow_multiple']
];
}

Expand All @@ -62,8 +63,9 @@ public function scenarios()
public function rules()
{
return array(
[['question'], 'required'],
[['question'], 'string'],
[['question'], 'string', 'max' => 255],
[['description'], 'required'],
[['description'], 'string'],
[['anonymous', 'is_random'], 'boolean'],
[['newAnswers'], 'required', 'on' => self::SCENARIO_CREATE],
[['newAnswers'], 'minTwoNewAnswers', 'on' => self::SCENARIO_CREATE],
Expand Down Expand Up @@ -98,6 +100,7 @@ public function attributeLabels()
'newAnswers' => Yii::t('PollsModule.models_Poll', 'Answers'),
'editAnswers' => Yii::t('PollsModule.models_Poll', 'Answers'),
'question' => Yii::t('PollsModule.models_Poll', 'Question'),
'description' => Yii::t('PollsModule.models_Poll', 'Description'),
'allow_multiple' => Yii::t('PollsModule.models_Poll', 'Multiple answers per user'),
'is_random' => Yii::t('PollsModule.widgets_views_pollForm', 'Display answers in random order?'),
'anonymous' => Yii::t('PollsModule.widgets_views_pollForm', 'Anonymous Votes?'),
Expand Down Expand Up @@ -153,7 +156,7 @@ public function afterSave($insert, $changedAttributes)
{
parent::afterSave($insert, $changedAttributes);

RichText::postProcess($this->question, $this);
RichText::postProcess($this->description, $this);

if($this->scenario === static::SCENARIO_EDIT || $this->scenario === static::SCENARIO_CREATE) {
if (!$insert) {
Expand Down Expand Up @@ -320,7 +323,7 @@ public function resetAnswer($userId = "")
*/
public function getContentName()
{
return Yii::t('PollsModule.models_Poll', "Question");
return Yii::t('PollsModule.models_Poll', 'Question');
}

/**
Expand All @@ -337,14 +340,15 @@ public function getContentDescription()
public function getSearchAttributes()
{

$itemAnswers = "";
$itemAnswers = '';

foreach ($this->answers as $answer) {
$itemAnswers .= $answer->answer;
}

return array(
'question' => $this->question,
'description' => $this->description,
'itemAnswers' => $itemAnswers
);
}
Expand Down
6 changes: 3 additions & 3 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"name": "Polls",
"description": "Easy to use poll system",
"keywords": ["poll", "voting", "decision making"],
"version": "0.9.20",
"version": "1.0.0",
"humhub": {
"minVersion": "1.6"
"minVersion": "1.7"
},
"homepage": "https://github.com/humhub/humhub-modules-polls",
"authors": [
Expand All @@ -25,4 +25,4 @@
"assets/screen3.PNG",
"assets/screen4.PNG"
]
}
}
43 changes: 23 additions & 20 deletions views/poll/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,25 @@
$disabled = ($poll->closed) ? 'disabled="disabled"' : '';
?>

<div data-poll="<?= $poll->id ?>" data-content-component="polls.Poll" data-content-key="<?= $poll->content->id ?>" class="content_edit" id="poll_edit_<?= $poll->id; ?>">
<div class="alert alert-danger" role="alert" style="display:none">
<div data-poll="<?= $poll->id ?>" data-content-component="polls.Poll" data-content-key="<?= $poll->content->id ?>"
class="content_edit" id="poll_edit_<?= $poll->id; ?>">
<div class="alert alert-danger" role="alert" style="display:none">
<span class="errorMessage"></span>
</div>

<?php $form = ActiveForm::begin(); ?>

<?= $form->field($poll, 'question')->widget(RichTextField::class, ['disabled' => $poll->closed, 'placeholder' => Yii::t('PollsModule.widgets_views_pollForm', 'Edit your poll question...')]) ?>
<?= $form->field($poll, 'question')->textInput($poll->closed ? ['disabled' => 'disabled'] : []) ?>

<?= $form->field($poll, 'description')->widget(RichTextField::class, ['disabled' => $poll->closed, 'placeholder' => Yii::t('PollsModule.widgets_views_pollForm', 'Edit your poll question...')]) ?>

<div class="contentForm_options">
<?= Html::activeLabel($poll, 'answersText', ['class' => 'control-label']); ?>
<?php foreach ($poll->answers as $answer) :?>
<?= Html::activeLabel($poll, 'answersText', ['label' => Yii::t('PollsModule.base', 'Answers'), 'class' => 'control-label']); ?>
<?php foreach ($poll->answers as $answer) : ?>
<div class="form-group">
<div class="input-group">
<input type="text" name="answers[<?= $answer->id ?>]" <?= $disabled ?>
title="<?= count($answer->votes) . ' ' . Yii::t('PollsModule.widgets_views_entry', 'votes') ?>"
title="<?= count($answer->votes) . ' ' . Yii::t('PollsModule.widgets_views_entry', 'votes') ?>"
value="<?= Html::encode($answer->answer) ?>"
class="form-control tt poll_answer_old_input"
placeholder="<?= Yii::t('PollsModule.widgets_views_pollForm', "Edit answer (empty answers will be removed)...") ?>"/>
Expand All @@ -38,28 +41,28 @@ class="form-control tt poll_answer_old_input"

<?php if (!$poll->closed) : ?>
<?= AddAnswerInput::widget(['name' => 'newAnswers[]', 'showTitle' => true]); ?>
<?php endif; ?>
<?php endif; ?>


<?= $form->field($poll, 'is_random')->checkbox(['id' => 'edit_poll_is_random_' . $poll->id]) ?>


<?= $form->field($poll, 'is_random')->checkbox(['id' => 'edit_poll_is_random_'.$poll->id]) ?>

<?php if (!$poll->anonymous) : ?>
<?= $form->field($poll, 'anonymous')->checkbox(['id' => 'edit_poll_anonymous'.$poll->id]) ?>
<?= $form->field($poll, 'anonymous')->checkbox(['id' => 'edit_poll_anonymous' . $poll->id]) ?>
<?php endif; ?>

<?= $form->field($poll, 'show_result_after_close')->checkbox(['id' => 'edit_poll_show_result_after_close'.$poll->id]) ?>
<?= $form->field($poll, 'show_result_after_close')->checkbox(['id' => 'edit_poll_show_result_after_close' . $poll->id]) ?>

</div>
<a href="#" class="btn btn-primary"
data-action-click="editSubmit" data-action-submit

<a href="#" class="btn btn-primary"
data-action-click="editSubmit" data-action-submit
data-action-url="<?= $poll->content->container->createUrl('/polls/poll/edit', ['id' => $poll->id]) ?>"
data-ui-loader>
<?= Yii::t('PollsModule.base', "Save") ?>
</a>
<a href="#" class="btn btn-danger"
data-action-click="editCancel"

<a href="#" class="btn btn-danger"
data-action-click="editCancel"
data-action-url="<?= $poll->content->container->createUrl('/polls/poll/reload', ['id' => $poll->id]) ?>"
data-ui-loader>
<?= Yii::t('PollsModule.base', "Cancel") ?>
Expand Down
29 changes: 21 additions & 8 deletions widgets/WallEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,45 @@

namespace humhub\modules\polls\widgets;

use humhub\modules\content\widgets\stream\WallStreamModuleEntryWidget;
use Yii;

/**
* PollWallEntryWidget is used to display a poll inside the stream.
*
* This Widget will used by the Poll Model in Method getWallOut().
*
* @package humhub.modules.polls.widgets
* @since 0.5
* @author Luke
*/
class WallEntry extends \humhub\modules\content\widgets\WallEntry
class WallEntry extends WallStreamModuleEntryWidget
{

/**
* @inheritDoc
*/
public $editRoute = "/polls/poll/edit";

public function run()

/**
* @inheritDoc
*/
public function renderContent()
{
//We don't want an edit menu when the poll is closed
if(version_compare(Yii::$app->version, '1.0.0-beta.4', 'lt') || $this->contentObject->closed) {
if ($this->model->closed) {
$this->editRoute = '';
}

return $this->render('entry', ['poll' => $this->contentObject,
'user' => $this->contentObject->content->createdBy,
'contentContainer' => $this->contentObject->content->container]);
return $this->render('entry', ['poll' => $this->model,
'user' => $this->model->content->createdBy,
'contentContainer' => $this->model->content->container]);
}

/**
* @return string a non encoded plain text title (no html allowed) used in the header of the widget
*/
protected function getTitle()
{
return trim($this->model->question) === '' ? $this->model->getContentName() : $this->model->question;
}
}
2 changes: 1 addition & 1 deletion widgets/views/entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<?= Html::beginForm($contentContainer->createUrl('/polls/poll/answer', ['pollId' => $poll->id])) ?>

<div data-ui-markdown>
<?= RichText::output($poll->question) ?>
<?= RichText::output($poll->description) ?>
</div>

<br><br>
Expand Down
44 changes: 28 additions & 16 deletions widgets/views/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,43 @@
use humhub\modules\polls\widgets\AddAnswerInput;
use yii\bootstrap\Html;

/** @var $model \yii\base\Model **/
/** @var $model \yii\base\Model * */

PollsAsset::register($this);

?>

<?= RichTextField::widget([
'name' => 'Poll[question]',
'placeholder' => Yii::t('PollsModule.widgets_views_pollForm', "Ask something...")
]); ?>
<?= Html::activeTextInput($model, 'question', [
'placeholder' => Yii::t('PollsModule.widgets_views_pollForm', 'Question'),
'class' => 'form-control',
]) ?>

<div class="contentForm_options" data-content-component="polls.Poll">
<?= RichTextField::widget([
'name' => 'Poll[description]',
'placeholder' => Yii::t('PollsModule.widgets_views_pollForm', 'Description'),
'options' => ['style' => 'margin:20px 0 15px'],
]); ?>

<?= Html::activeLabel($model, 'answersText', ['label' => Yii::t('PollsModule.base', 'Answers'), 'class' => 'control-label']); ?>
<?= AddAnswerInput::widget(['name' => 'newAnswers[]', 'showTitle' => false]); ?>

<div class="checkbox regular-checkbox-container">
<?= Html::activeCheckbox($model, 'allow_multiple'); ?>
</div>
<div class="checkbox regular-checkbox-container">
<?= Html::activeCheckbox($model, 'is_random'); ?>
</div>
<div class="checkbox regular-checkbox-container">
<?= Html::activeCheckbox($model, 'anonymous'); ?>
</div>
<div class="checkbox regular-checkbox-container">
<?= Html::activeCheckbox($model, 'show_result_after_close'); ?>
<div class="row">
<div class="col-sm-6">
<div class="checkbox regular-checkbox-container">
<?= Html::activeCheckbox($model, 'allow_multiple'); ?>
</div>
<div class="checkbox regular-checkbox-container">
<?= Html::activeCheckbox($model, 'is_random'); ?>
</div>
</div>
<div class="col-sm-6">
<div class="checkbox regular-checkbox-container">
<?= Html::activeCheckbox($model, 'anonymous'); ?>
</div>
<div class="checkbox regular-checkbox-container">
<?= Html::activeCheckbox($model, 'show_result_after_close'); ?>
</div>
</div>
</div>
</div>

0 comments on commit ade1773

Please sign in to comment.