Skip to content

Commit 596d059

Browse files
committed
add highlighted rewards to project conf model and form
1 parent ced3219 commit 596d059

8 files changed

Lines changed: 105 additions & 6 deletions

File tree

Resources/templates/responsive/project/partials/highlighted_rewards.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
# Show three rewards in widgets in a responsive way (mobile first)
32
$project = $this->project;
43
?>
54

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/**
3+
* Migration Task class.
4+
*/
5+
class GoteoHighlightedRewards
6+
{
7+
public function preUp()
8+
{
9+
// add the pre-migration code here
10+
}
11+
12+
public function postUp()
13+
{
14+
// add the post-migration code here
15+
}
16+
17+
public function preDown()
18+
{
19+
// add the pre-migration code here
20+
}
21+
22+
public function postDown()
23+
{
24+
// add the post-migration code here
25+
}
26+
27+
/**
28+
* Return the SQL statements for the Up migration
29+
*
30+
* @return string The SQL string to execute for the Up migration.
31+
*/
32+
public function getUpSQL()
33+
{
34+
return "
35+
ALTER TABLE `project_conf` ADD COLUMN highlighted_rewards TINYINT(1) NOT NULL DEFAULT 0;
36+
";
37+
}
38+
39+
/**
40+
* Return the SQL statements for the Down migration
41+
*
42+
* @return string The SQL string to execute for the Down migration.
43+
*/
44+
public function getDownSQL()
45+
{
46+
return "
47+
ALTER TABLE `project_conf` DROP COLUMN highlighted_rewards;
48+
";
49+
}
50+
}

src/Goteo/Library/Forms/Model/ProjectCampaignForm.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,16 @@ public function createForm(): ProjectCampaignForm
9292
],
9393
'color' => 'cyan',
9494
'required' => false
95+
])
96+
->add('highlighted_rewards', BooleanType::class, [
97+
'label' => 'project-campaign-highlighted-rewards',
98+
'row_class' => 'extra',
99+
'data' => $project->isHighlightedRewardsActive(),
100+
'attr' => [
101+
'help' => Text::get('project-campaign-activate-highlighted-rewards')
102+
],
103+
'color' => 'cyan',
104+
'required' => false
95105
]);
96106
}
97107

@@ -143,6 +153,8 @@ public function save(FormInterface $form = null, $force_save = false) {
143153
$conf->deactivateImpactCalculator();
144154
}
145155
$errors = [];
156+
157+
$conf->setHighlightedRewards($data['highlighted_rewards']);
146158
if (!$conf->save($errors)) {
147159
throw new FormModelException(Text::get('form-sent-error', implode(', ',$errors)));
148160
}

src/Goteo/Model/Project.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3614,6 +3614,15 @@ public function isImpactCalcActive():bool
36143614
}
36153615
}
36163616

3617+
public function isHighlightedRewardsActive(): bool
3618+
{
3619+
try {
3620+
return ProjectConf::get($this->id)->isHighlightedRewards();
3621+
} catch(\Goteo\Core\Exception $e) {
3622+
return false;
3623+
}
3624+
}
3625+
36173626
/*
36183627
* Para saber si un proyecto tiene traducción en cierto idioma
36193628
* @return: boolean

src/Goteo/Model/Project/Conf.php

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class Conf extends Model
3838
$hide_exhausted_rewards;
3939

4040
private bool $impact_calculator = false;
41+
private bool $highlighted_rewards = false;
4142

4243
/**
4344
* Get the conf for a project
@@ -90,10 +91,24 @@ public function save(&$errors = array())
9091
if (!$this->validate($errors)) return false;
9192

9293
try {
93-
$sql = "REPLACE INTO project_conf (project, noinvest, watch, days_round1, days_round2, one_round, help_cost, help_license, mincost_estimation, publishing_estimation, hide_exhausted_rewards, impact_calculator) VALUES(:project, :noinvest, :watch, :round1, :round2, :one, :helpcost, :helplicense, :mincost_estimation, :publishing_estimation, :hide_exhausted_rewards, :impact_calculator)";
94-
$values = [':project' => $this->project, ':noinvest' => $this->noinvest, ':watch' => $this->watch,
95-
':round1' => $this->days_round1, ':round2' => $this->days_round2, ':one' => $this->one_round, ':helpcost' => $this->help_cost, ':helplicense' => $this->help_license, ':mincost_estimation' => $this->mincost_estimation, ':publishing_estimation' => $this->publishing_estimation, ':hide_exhausted_rewards' => $this->hide_exhausted_rewards, ':impact_calculator' => $this->impact_calculator];
96-
return self::query($sql, $values)?true:false;
94+
$sql = "REPLACE INTO project_conf (project, noinvest, watch, days_round1, days_round2, one_round, help_cost, help_license, mincost_estimation, publishing_estimation, hide_exhausted_rewards, impact_calculator, highlighted_rewards) VALUES(:project, :noinvest, :watch, :round1, :round2, :one, :helpcost, :helplicense, :mincost_estimation, :publishing_estimation, :hide_exhausted_rewards, :impact_calculator, :highlighted_rewards)";
95+
$values = [
96+
':project' => $this->project,
97+
':noinvest' => $this->noinvest,
98+
':watch' => $this->watch,
99+
':round1' => $this->days_round1,
100+
':round2' => $this->days_round2,
101+
':one' => $this->one_round,
102+
':helpcost' => $this->help_cost,
103+
':helplicense' => $this->help_license,
104+
':mincost_estimation' => $this->mincost_estimation,
105+
':publishing_estimation' => $this->publishing_estimation,
106+
':hide_exhausted_rewards' => $this->hide_exhausted_rewards,
107+
':impact_calculator' => $this->impact_calculator,
108+
':highlighted_rewards' => $this->highlighted_rewards
109+
];
110+
111+
return (bool)self::query($sql, $values);
97112
} catch (\PDOException $e) {
98113
$errors[] = "La configuración del proyecto no se ha guardado correctamente. Por favor, revise los datos." . $e->getMessage();
99114
return false;
@@ -370,4 +385,13 @@ public function deactivateImpactCalculator()
370385
$this->impact_calculator = false;
371386
}
372387

388+
public function isHighlightedRewards(): bool
389+
{
390+
return $this->highlighted_rewards;
391+
}
392+
393+
public function setHighlightedRewards(bool $highlighted_rewards): void
394+
{
395+
$this->highlighted_rewards = $highlighted_rewards;
396+
}
373397
}

translations/ca/project.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,5 @@ project-impact-calculator-card-impact-description: "Amb un pressupost de %s aspi
162162
project-create-continue-impact: "Desar i calcular impacte"
163163
project-campaign-impact-calculator: "Calculadora d'Impacte"
164164
project-campaign-activate-impact-calculator: "Al activar la calculadora d'impacte, l'impulsora del projecte podrà accedir al módul de les Dades d'Impacte del Projecte, així com també es veurà el seu impacte a la pàgina principal del projecte."
165+
project-campaign-highlighted-rewards: "Recompenses destacades"
166+
project-campaign-activate-highlighted-rewards: "Al activar les recompenses destacades, la visualització de les recompenses canvia. Es mostraran les recompenses destacades a la part superior de la pàgina del projecte."

translations/en/project.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,5 @@ project-impact-calculator-card-impact-description: "With a budget of %s we want
159159
project-create-continue-impact: "Save and calculate impact"
160160
project-campaign-impact-calculator: "Impact Calculator"
161161
project-campaign-activate-impact-calculator: "By activating the impact calculator, the project promoter will be able to access the project impact data module, as well as see their impact on the main project page."
162-
162+
project-campaign-highlighted-rewards: "Highlighted rewards"
163+
project-campaign-activate-highlighted-rewards: "When activating the highlighted rewards, the visualization of the rewards will change. The rewards will be shown at the top of the project page."

translations/es/project.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,5 @@ project-impact-calculator-card-impact-description: "Con un presupuesto de %s asp
181181
project-create-continue-impact: "Guardar y calcular impacto"
182182
project-campaign-impact-calculator: "Calculadora de Impacto"
183183
project-campaign-activate-impact-calculator: "Al activar la calculadora de impacto, la impulsora del proyecto podrá acceder al modulo de los Datos de Impacto del Proyecto, así como también se verá su impacto en la página principal del proyecto."
184+
project-campaign-highlighted-rewards: "Recompensas destacadas"
185+
project-campaign-activate-highlighted-rewards: "Al activar las recompensas destacadas, la visualización de las recompensas cambia. Se mostrarán las recompensas destacadas en la parte superior de la página del proyecto."

0 commit comments

Comments
 (0)