Skip to content

Commit c8bde4e

Browse files
authored
Fixes on impact data after first uses (#531)
* fixes on impact data form on admin * change impact item project from impact item unit to impact data unit * fixes on copies from admin.yml * add impact calculator field to project configuration form only for admin users * fix errors in admin.yml related to impact data form * fixes on use of impact data unit instead of impact item
1 parent 9736345 commit c8bde4e

15 files changed

Lines changed: 105 additions & 30 deletions

File tree

src/Goteo/Library/Forms/Admin/AdminImpactDataForm.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,15 @@ public function createForm(): AdminImpactDataForm
3939
new Constraints\NotBlank(),
4040
),
4141
))
42+
->add('description', TextareaType::Class, array(
43+
'label' => 'regular-description',
44+
'required' => false
45+
))
4246
->add('data', TextType::class, array(
4347
'label' => 'regular-data',
44-
'constraints' => array(
45-
new Constraints\NotBlank(),
46-
),
48+
'required' => false
4749
)) ->add('data_unit', TextType::class, array(
4850
'label' => 'regular-data-unit',
49-
'constraints' => array(
50-
new Constraints\NotBlank(),
51-
),
52-
))
53-
->add('description', TextareaType::Class, array(
54-
'label' => 'regular-description',
5551
'constraints' => array(
5652
new Constraints\NotBlank(),
5753
)
@@ -72,6 +68,9 @@ public function createForm(): AdminImpactDataForm
7268
])
7369
->add('result_msg', TextType::class, [
7470
'label' => 'regular-result-msg',
71+
'attr' => [
72+
'pre-help' => Text::get('admin-impact-data-result_msg-help')
73+
]
7574
])
7675
->add('operation_type', ChoiceType::class, [
7776
'label' => 'regular-operation-type',
@@ -131,7 +130,7 @@ private function getImpactDataTypes(): array
131130
$types = ImpactData::getTypes();
132131
$list = [];
133132
foreach($types as $type) {
134-
$list[Text::get('impact-data-type-' . $type)] = $type;
133+
$list[Text::get('admin-impact-data-type-' . $type)] = $type;
135134
}
136135
return $list;
137136
}
@@ -141,7 +140,7 @@ private function getImpactSources(): array
141140
$sources = ImpactData::getSources();
142141
$list = [];
143142
foreach($sources as $source) {
144-
$list[Text::get('impact-data-source-'. $source)] = $source;
143+
$list[Text::get('admin-impact-data-source-'. $source)] = $source;
145144
}
146145
return $list;
147146
}
@@ -151,7 +150,7 @@ private function getImpactOperations(): array
151150
$operations = ImpactData::getOperations();
152151
$list = [];
153152
foreach($operations as $operation) {
154-
$list[Text::get('impact-data-operation-'. $operation)] = $operation;
153+
$list[Text::get('admin-impact-data-operation-'. $operation)] = $operation;
155154
}
156155
return $list;
157156
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ private function getImpactItems(): array
2424

2525
$list = [];
2626
foreach($impactItems as $impactItem) {
27-
$unit = $impactItem->getUnit();
27+
$unit = $impactData->data_unit;
2828
$description = $impactItem->getDescription();
2929
$name = $impactItem->getName() . " ($unit) " . ($description ? " - $description" : "");
3030
$list[$name] = $impactItem->getId();
@@ -41,9 +41,10 @@ public function createForm(): ImpactItemProjectForm
4141
{
4242
$model = $this->getModel();
4343
$impactItem = $model->getImpactItem();
44+
$impactData = $this->getOption('impactData');
4445

45-
$unit = $impactItem ? $impactItem->getUnit() : "";
46-
$label = $unit ? Text::get('regular-value') . "($unit)" : "";
46+
$unit = $impactData->data_unit;
47+
$label = Text::get('regular-value') . " ($unit)";
4748
$description = $impactItem ? $impactItem->getDescription() : "";
4849

4950
$builder = $this->getBuilder();
@@ -55,7 +56,7 @@ public function createForm(): ImpactItemProjectForm
5556
'disabled' => $this->getReadonly(),
5657
])
5758
->add("value", NumberType::class, [
58-
"label" => $unit ,
59+
"label" => $label ,
5960
"data" => $model->getValue(),
6061
"attr" => [
6162
'pre-help' => $description

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

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111

1212
namespace Goteo\Library\Forms\Model;
1313

14+
use Goteo\Application\Session;
1415
use Goteo\Library\Forms\FormProcessorInterface;
1516
use Goteo\Library\Forms\AbstractFormProcessor;
1617
use Goteo\Library\Forms\FormModelException;
18+
use Goteo\Model\Project\Conf;
1719
use Goteo\Util\Form\Type\BooleanType;
1820
use Goteo\Util\Form\Type\ChoiceType;
19-
use Goteo\Util\Form\Type\EmailType;
2021
use Goteo\Util\Form\Type\TextareaType;
2122
use Goteo\Util\Form\Type\TextType;
2223
use Symfony\Component\Form\FormInterface;
@@ -35,11 +36,13 @@ public function getPhoneConstraints(): array
3536
}
3637
}
3738

38-
public function createForm() {
39+
public function createForm(): ProjectCampaignForm
40+
{
3941
$project = $this->getModel();
4042
$account = $this->getOption('account');
4143

42-
$this->getBuilder()
44+
$builder = $this->getBuilder();
45+
$builder
4346
->add('one_round', ChoiceType::class, [
4447
'disabled' => $this->getReadonly(),
4548
'label' => 'costs-field-select-rounds',
@@ -76,6 +79,22 @@ public function createForm() {
7679
]
7780
])
7881
;
82+
83+
$admin = Session::isAdmin();
84+
if ($admin) {
85+
$builder
86+
->add('impact_calculator', BooleanType::class, [
87+
'label' => 'project-campaign-impact-calculator',
88+
'row_class' => 'extra',
89+
'data' => $project->isImpactCalcActive(),
90+
'attr' => [
91+
'help' => Text::get('project-campaign-activate-impact-calculator')
92+
],
93+
'color' => 'cyan',
94+
'required' => false
95+
]);
96+
}
97+
7998
return $this;
8099
}
81100

@@ -109,11 +128,26 @@ public function save(FormInterface $form = null, $force_save = false) {
109128
if (!$account->save($errors)) {
110129
throw new FormModelException(Text::get('form-sent-error', implode(', ',$errors)));
111130
}
131+
112132
$user = $this->getOption('user');
113133
if(!User::setPersonal($user, ['phone' => $data['phone']], true, $errors)) {
114134
throw new FormModelException(Text::get('form-sent-error', implode(', ',$errors)));
115135
}
116136

137+
$admin = Session::isAdmin();
138+
if ($admin && isset($data['impact_calculator'])) {
139+
$conf = Conf::get($project->id);
140+
if ($data['impact_calculator']) {
141+
$conf->activateImpactCalculator();
142+
} else {
143+
$conf->deactivateImpactCalculator();
144+
}
145+
$errors = [];
146+
if (!$conf->save($errors)) {
147+
throw new FormModelException(Text::get('form-sent-error', implode(', ',$errors)));
148+
}
149+
}
150+
117151
if(!$form->isValid()) throw new FormModelException(Text::get('form-has-errors'));
118152

119153
return $this;

src/Goteo/Model/ImpactData.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ImpactData extends Model {
2727
const TYPE_REAL = "real";
2828

2929
const OPERATION_AMOUNT_ESTIMATION_DIVIDE_DATA = 'amount_estimation_divide_data';
30-
const OPERATION_DATA_DIVIDE_AMOUNT_ESTIMATION = 'amount_estimation_divide_data';
30+
const OPERATION_DATA_DIVIDE_AMOUNT_ESTIMATION = 'data_divide_amount_estimation';
3131

3232
public
3333
$id,
@@ -196,14 +196,8 @@ public function validate(&$errors = array()): bool
196196
if (!$this->title)
197197
$errors['title'] = Text::get('mandatory-title');
198198

199-
if (!$this->data)
200-
$errors['data'] = Text::get('mandatory-data');
201-
202199
if (!$this->data_unit)
203-
$errors['data'] = Text::get('mandatory-data-unit');
204-
205-
if (!$this->description)
206-
$errors['description'] = Text::get('mandatory-description');
200+
$errors['data_unit'] = Text::get('mandatory-data-unit');
207201

208202
return empty($errors);
209203
}

src/Goteo/Util/ModelNormalizer/Transformer/ImpactDataProjectTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class ImpactDataProjectTransformer extends AbstractTransformer
66
{
7-
protected $keys = ['impact_data', 'estimation', 'dataValue'];
7+
protected $keys = ['impact_data', 'estimation', 'source', 'dataValue'];
88

99
public function getImpactDataId(): string
1010
{

src/Goteo/Util/ModelNormalizer/Transformer/ImpactProjectItemTransformer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ public function getImpactItemName(): string
2424
public function getImpactValue()
2525
{
2626
$impactItem = $this->model->getImpactItem();
27-
$unit = $impactItem->getUnit();
27+
$impactData = $this->model->getRelatedImpactData();
28+
$unit = $impactData->data_unit;
2829
return $this->model->getValue() . " ($unit)";
2930
}
3031

translations/ca/admin.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,3 +304,12 @@ admin-title-impactValue: "Quantitat"
304304
admin-title-impactItemName: "Element d'impacte"
305305
admin-title-costId: "Id"
306306
admin-title-costName: "Nom"
307+
admin-title-source: "Font"
308+
admin-impact-data-operation-amount_estimation_divide_data: "La quantitat estimada de l'usuari divideix el camp Dada"
309+
admin-impact-data-operation-data_divide_amount_estimation: "El camp Dada divideix la quantitat estimada"
310+
admin-impact-data-source-item: "Element d'Impacte"
311+
admin-impact-data-source-project: "Projecte"
312+
admin-impact-data-source-channel: "Canal"
313+
admin-impact-data-result_msg-help: "Aquest camp permet afegir un missatge al càlcul del impacte d'aquesta Data d'Impacte. Per utilitzar-lo haurem de fer servir les variables <b>%amount</b> i <b>%result</b>, on <b>%amount</b> fa referència a la quantitat estimada per l'usuari i <b>%result</b> al resultat d'impacte calculat."
314+
admin-impact-data-type-estimation: "Estimació"
315+
admin-impact-data-type-real: "Real"

translations/ca/general.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,3 +256,8 @@ regular-impact: "Impacte"
256256
regular-list: "Llista"
257257
regular-costs: "Costos"
258258
regular-value: "Valor"
259+
regular-type: "Tipus"
260+
regular-source: "Font"
261+
regular-result-msg: "Missatge de resultat"
262+
regular-operation-type: "Operació de càlcul"
263+

translations/ca/project.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,5 @@ project-impact-calculator-footprint-3-description: "Emplena aquí les dades esti
160160
project-impact-calculator-activate-indicator: "Activar compromís"
161161
project-impact-calculator-card-impact-description: "Amb un pressupost de %s aspirem a tenir un impacte de %s"
162162
project-create-continue-impact: "Desar i calcular impacte"
163+
project-campaign-impact-calculator: "Calculadora d'Impacte"
164+
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."

translations/en/admin.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,4 +542,12 @@ admin-title-impactValue: "Quantity"
542542
admin-title-impactItemName: "Impact Item"
543543
admin-title-costId: "Id"
544544
admin-title-costName: "Name"
545-
545+
admin-title-source: "Source"
546+
admin-impact-data-operation-amount_estimation_divide_data: "The estimated amount of the user divides the Data field"
547+
admin-impact-data-operation-data_divide_amount_estimation: "The Data field divides the estimated amount"
548+
admin-impact-data-source-item: "Impact Item"
549+
admin-impact-data-source-project: "Project"
550+
admin-impact-data-source-channel: "Channel"
551+
admin-impact-data-result_msg-help: "This field allows you to add a message to the impact calculation of this Impact Data. To use it we will have to use the variables <b>%amount</b> and <b>%result</b>, where <b>%amount</b> refers to the amount estimated by the user and <b>%result</b> to the calculated impact result."
552+
admin-impact-data-type-estimation: "Estimation"
553+
admin-impact-data-type-real: "Real"

0 commit comments

Comments
 (0)