Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature archive rewards #573

Open
wants to merge 6 commits into
base: live
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
<?= $this->form_row($form["unlimited_$id"]) ?>
</div>
</div>
<div class="unlimited form-group">
<label for="archived_<?= $id ?>"><?= $this->text('project-reward-archived') ?></label>
<div class="input-wrap">
<?= $this->form_row($form["archived_$id"]) ?>
</div>
</div>
</div>
<?= $this->form_row($form["reward_$id"]) ?>
<?= $this->form_row($form["description_$id"]) ?>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
$reward = $this->reward_item;
$selected = $selected;
$selected = $this->selected;
$available = $reward->available();
?>
<form class="form-horizontal" role="form" method="GET" action="/invest/<?= $this->project->id ?>/payment">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<form class="form-horizontal" role="form" method="GET" action="/invest/<?= $this->project->id ?>/payment">

davidbeig marked this conversation as resolved.
Show resolved Hide resolved
<form class="form-horizontal" role="form" method="GET" action="/invest/<?= $this->project->id ?>/payment">
<div class="row padding-sm no-padding col-sm-10 col-sm-offset-1 reward-box-resign">
<label class="label-reward <?= $this->reward ? '' : 'reward-choosen' ?>" for="reward-empty">
<div class="col-sm-11 no-padding">
Expand All @@ -13,7 +12,7 @@
<strong class="reward-amount"><?= $this->get_currency('html') ?></strong>
</div>
<div class="no-padding container-input-amount col-md-4 col-sm-3 col-xs-10">
<input type="number" min="0" class="form-control input-amount" name="amount" value="<?= $this->amount ? $this->amount : '0' ?>" id="amount" required>
<input type="number" min="0" class="form-control input-amount" name="amount" value="<?= $this->amount ?: '0' ?>" id="amount" required>
</div>
<div class="col-md-5 col-sm-4 col-md-offset-1 reward-button">
<button type="submit" class="btn btn-block btn-success col-xs-3 margin-2"><?= $this->text('invest-button') ?></button>
Expand All @@ -22,4 +21,4 @@
</div>
</label>
</div>
</form>
</form>
13 changes: 2 additions & 11 deletions Resources/templates/responsive/invest/select_reward.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,14 @@

<?= $this->insert('invest/partials/reward_box_resign') ?>

<?php foreach($this->rewards as $reward_item): ?>

<?php //check if show the exhausted rewards ?>
<?php if($reward_item->available()||!$this->project::hideExhaustedRewards($this->project->id)||!$this->project->inCampaign()): ?>

<?php foreach($this->rewards as $reward_item):
if(!$reward_item->archived && ($reward_item->available()||!$this->project::hideExhaustedRewards($this->project->id)||!$this->project->inCampaign())): ?>
<?= $this->insert('invest/partials/reward_box', ['reward_item' => $reward_item]) ?>

<?php endif; ?>

<?php endforeach ?>

</form>
</div>
</div>

</div>

</div>


Expand Down
1 change: 0 additions & 1 deletion Resources/templates/responsive/project/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@
</div>
<?php endif; ?>

<!-- show rewards of type patreon if active -->
<?php if ($project->isPermanent()):?>
<div class="row">
<?= $this->insert('project/partials/highlighted_rewards') ?>
Expand Down
6 changes: 4 additions & 2 deletions Resources/templates/responsive/project/partials/side.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php $project=$this->project; ?>

<div class="hidden-xs">
<aside class="hidden-xs">
<h2 class="green-title">
<?= $this->text('project-rewards-side-title') ?>
</h2>
Expand All @@ -10,6 +10,7 @@
$available = $individual->available();
$units = ($individual->units - $individual->taken); // units left
$matchedReward = $individual->isMatched();
if (!$individual->archived):
?>
<li id="reward-<?= $individual->id ?>" class="side-widget <?= $matchedReward ? "matched-reward" : ''?>">
<article>
Expand Down Expand Up @@ -52,6 +53,7 @@
</div>
</article>
</li>
<?php endif; ?>
<?php endforeach ?>
</ul>

Expand Down Expand Up @@ -87,4 +89,4 @@
</li>
<?php endforeach ?>
</ul>
</div>
</aside>
51 changes: 51 additions & 0 deletions db/migrations/20231106164820_goteo_add_archived_reward.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/**
* Migration Task class.
*/
class GoteoAddArchivedReward
{
public function preUp()
{
// add the pre-migration code here
}

public function postUp()
{
// add the post-migration code here
}

public function preDown()
{
// add the pre-migration code here
}

public function postDown()
{
// add the post-migration code here
}

/**
* Return the SQL statements for the Up migration
*
* @return string The SQL string to execute for the Up migration.
*/
public function getUpSQL()
{
return "
ALTER TABLE `reward` ADD COLUMN `archived` TINYINT(1) NOT NULL DEFAULT 0;
";
}

/**
* Return the SQL statements for the Down migration
*
* @return string The SQL string to execute for the Down migration.
*/
public function getDownSQL()
{
return "
ALTER TABLE `reward` DROP COLUMN `archived`;
";
}

}
29 changes: 17 additions & 12 deletions src/Goteo/Controller/InvestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use Goteo\Util\Monolog\Processor\WebProcessor;
use Omnipay\Common\Message\ResponseInterface;
use RuntimeException;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

Expand Down Expand Up @@ -76,7 +77,6 @@ private function validate(
) {
$project = Project::get($project_id, Lang::current());
// Add analytics to config
// TODO: do the same with facebook pixel (not done yet because f.pixel is only used in the project page)
if($project->analytics_id) {
Config::set('analytics.google', array_merge(Config::get('analytics.google'), [$project->analytics_id]));
}
Expand Down Expand Up @@ -215,7 +215,7 @@ private function validate(
/**
* step1: Choose rewards
*/
public function selectRewardAction($project_id, Request $request): Response
public function selectRewardAction(Request $request, $project_id): Response
{
// TODO: add events
$amount = $request->query->get('amount');
Expand All @@ -236,7 +236,8 @@ public function selectRewardAction($project_id, Request $request): Response
public function loginAction($project_id, Request $request)
{
$amount = $request->query->get('amount');
$reward = $this->validate($project_id, $request->query->get('reward'), $amount, null, false);
$rewardId = $request->query->getDigits('reward');
$reward = $this->validate($project_id, $rewardId, $amount, null, false);

if($reward instanceOf Response) return $reward;
if(!$request->query->has('return')) {
Expand All @@ -258,7 +259,8 @@ public function loginAction($project_id, Request $request)
public function signupAction($project_id, Request $request)
{
$amount = $request->query->get('amount');
$reward = $this->validate($project_id, $request->query->get('reward'), $amount, null, false);
$rewardId = $request->query->getDigits('reward');
$reward = $this->validate($project_id, $rewardId, $amount, null, false);

if($reward instanceOf Response) return $reward;
if(!$request->query->has('return')) {
Expand All @@ -283,7 +285,8 @@ public function selectPaymentMethodAction($project_id, Request $request)
$amount = $request->query->get('amount');
$donate_amount = $request->query->get('donate_amount');
$email = $request->query->has('email');
$reward = $this->validate($project_id, $request->query->get('reward'), $amount, null, 'auto');
$rewardId = $request->query->getDigits('reward');
$reward = $this->validate($project_id, $rewardId, $amount, null, 'auto');

if(!($this->skip_login && $email) && !Session::isLogged()) {
return $this->redirect('/invest/' . $this->project->id . '/signup?' . $this->query);
Expand Down Expand Up @@ -322,7 +325,8 @@ public function paymentFormAction($project_id, Request $request) {
$tip=$request->query->get('tip');
$donate_amount = $tip ? $request->query->get('donate_amount') : 0;
$amount = $amount_original = $request->query->get('amount');
$reward = $this->validate($project_id, $request->query->get('reward'), $amount, null, 'auto');
$rewardId = $request->query->getDigits('reward');
$reward = $this->validate($project_id, $rewardId, $amount, null, 'auto');

if($reward instanceOf Response) return $reward;

Expand Down Expand Up @@ -639,13 +643,14 @@ public function shareAction($project_id, $invest_id, Request $request) {
}

// Send a public support message
public function supportMsgAction(Request $request) {
if ($request->isMethod('post')) {
public function supportMsgAction(Request $request): JsonResponse
{
$result=false;

if ($request->isMethod(Request::METHOD_POST)) {
$msg = $request->request->get('msg');
$invest = $request->request->get('invest');
if(empty($msg))
$result=false;
else
$invest = $request->request->getDigits('invest');
if(!empty($msg))
$result=Invest::newSupportMessage($invest, $msg);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Goteo/Core/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function rawResponse(
return $response;
}

public function jsonResponse($vars = [])
public function jsonResponse($vars = []): JsonResponse
{
$resp = new JsonResponse($vars);
if(App::debug()) $resp->setEncodingOptions(JSON_PRETTY_PRINT);
Expand Down
24 changes: 19 additions & 5 deletions src/Goteo/Library/Forms/Model/ProjectRewardsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Goteo\Library\Forms\Model;

use Goteo\Application\Session;
use Goteo\Util\Form\Type\BooleanType;
use Goteo\Util\Form\Type\MarkdownType;
use Goteo\Util\Form\Type\NumberType;
Expand Down Expand Up @@ -89,7 +90,7 @@ public function addReward(Reward $reward) {
$this->rewards[$reward->id] = $reward;
$project = $this->getModel();
$suffix = "_{$reward->id}";

$admin = Session::isAdmin();
// readonly only if has no invests associated
$units_readonly = $readonly = $this->getReadonly() && !$reward->isDraft() && $reward->getTaken();
$remove_readonly = $this->getReadonly()&&$reward->getTaken();
Expand All @@ -98,7 +99,8 @@ public function addReward(Reward $reward) {
$units_readonly = false;
}

$this->getBuilder()
$builder = $this->getBuilder();
$builder
->add("amount$suffix", NumberType::class, [
'label' => 'rewards-field-individual_reward-amount',
'data' => $reward->amount,
Expand All @@ -123,7 +125,20 @@ public function addReward(Reward $reward) {
'disabled' => $units_readonly,
'required' => false,
'color' => 'cyan'
])
]);

if ($admin) {
$builder
->add("archived$suffix", BooleanType::class, [
'label' => false,
'data' => (bool) $reward->archived,
'required' => false,
'disabled' => $readonly,
'color' => 'cyan'
]);
}

$builder
->add("reward$suffix", TextType::class, [
'label' => 'regular-title',
'data' => $reward->reward,
Expand All @@ -143,7 +158,6 @@ public function addReward(Reward $reward) {
'rows' => 4,
'data-toolbar' => 'close,bold,italic,link,unordered-list,ordered-list,preview,fullscreen,guide'
]

]);
if(!$remove_readonly) {
$this->getBuilder()
Expand Down Expand Up @@ -181,7 +195,7 @@ public function save(FormInterface $form = null, $force_save = false) {

foreach($data as $key => $val) {
list($field, $id) = explode('_', $key);
if(!in_array($field, ['amount', 'icon', 'units', 'reward', 'description'])) continue;
if(!in_array($field, ['amount', 'icon', 'units', 'reward', 'description', 'archived'])) continue;
if($field == 'units' && $data['unlimited_' . $id]) {
$val = 0;
}
Expand Down
Loading
Loading