From a6e93fa5074cbc78d56ce7f8f03df0e680fc2c80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Ig=C3=B3n?= Date: Tue, 27 Jul 2021 15:38:36 +0200 Subject: [PATCH 01/20] update symfony to ^2.8 --- composer.json | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/composer.json b/composer.json index be7100652f..77d6f1d868 100644 --- a/composer.json +++ b/composer.json @@ -13,25 +13,25 @@ "iignatov/lightopenid": "~1.0", "paypal/adaptivepayments-sdk-php": "*", "paypal/merchant-sdk-php": "*", - "symfony/class-loader": "2.8.30", - "symfony/http-foundation": "2.8.30", - "symfony/routing": "2.8.30", - "symfony/http-kernel": "2.8.30", - "symfony/security": "2.8.30", - "symfony/config": "2.8.30", - "symfony/stopwatch": "2.8.30", - "symfony/dependency-injection": "2.8.30", - "symfony/debug": "2.8.30", - "symfony/console": "2.8.30", - "symfony/translation": "2.8.30", - "symfony/finder": "2.8.30", - "symfony/dom-crawler": "2.8.30", - "symfony/css-selector": "2.8.30", - "symfony/process": "2.8.30", - "symfony/form": "2.8.30", - "symfony/templating": "2.8.30", - "symfony/framework-bundle": "2.8.30", - "symfony/validator": "2.8.30", + "symfony/class-loader": "^2.8", + "symfony/http-foundation": "^2.8", + "symfony/routing": "^2.8", + "symfony/http-kernel": "^2.8", + "symfony/security": "^2.8", + "symfony/config": "^2.8", + "symfony/stopwatch": "^2.8", + "symfony/dependency-injection": "^2.8", + "symfony/debug": "^2.8", + "symfony/console": "^2.8", + "symfony/translation": "^2.8", + "symfony/finder": "^2.8", + "symfony/dom-crawler": "^2.8", + "symfony/css-selector": "^2.8", + "symfony/process": "^2.8", + "symfony/form": "^2.8", + "symfony/templating": "^2.8", + "symfony/framework-bundle": "^2.8", + "symfony/validator": "^2.8", "symfony/yaml": "^3.3", "monolog/monolog": "^1.17", "gregwar/captcha": "^1.1", From b3abc09e3fb2774c9f7ba099ce37d24de592d2e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Ig=C3=B3n?= Date: Tue, 27 Jul 2021 15:40:32 +0200 Subject: [PATCH 02/20] remove url from dropfiles in forms --- src/Goteo/Library/Forms/Admin/AdminChannelResourceEditForm.php | 1 - src/Goteo/Library/Forms/Admin/AdminFootprintEditForm.php | 1 - src/Goteo/Library/Forms/Admin/AdminPostEditForm.php | 2 -- src/Goteo/Library/Forms/Admin/AdminProgramForm.php | 1 - src/Goteo/Library/Forms/Admin/AdminSdgEditForm.php | 1 - src/Goteo/Library/Forms/Admin/AdminSectionForm.php | 3 +-- .../Library/Forms/Admin/AdminSocialCommitmentEditForm.php | 1 - src/Goteo/Library/Forms/Admin/AdminSphereEditForm.php | 1 - src/Goteo/Library/Forms/Admin/AdminStoryEditForm.php | 3 --- src/Goteo/Library/Forms/Admin/AdminWorkshopEditForm.php | 1 - src/Goteo/Library/Forms/Model/QuestionnaireCreateForm.php | 2 +- src/Goteo/Library/Forms/Model/QuestionnaireForm.php | 2 +- src/Goteo/Library/Forms/Model/UserProfileForm.php | 1 - 13 files changed, 3 insertions(+), 17 deletions(-) diff --git a/src/Goteo/Library/Forms/Admin/AdminChannelResourceEditForm.php b/src/Goteo/Library/Forms/Admin/AdminChannelResourceEditForm.php index b29ac921bd..35824f6a97 100644 --- a/src/Goteo/Library/Forms/Admin/AdminChannelResourceEditForm.php +++ b/src/Goteo/Library/Forms/Admin/AdminChannelResourceEditForm.php @@ -65,7 +65,6 @@ public function createForm() { 'data' => [$resource->image ? $resource->getImage() : null], 'label' => 'admin-title-image', 'accepted_files' => 'image/jpeg,image/gif,image/png,image/svg+xml', - 'url' => '/api/channel-resources/images', 'constraints' => array( new Constraints\Count(array('max' => 1)) ) diff --git a/src/Goteo/Library/Forms/Admin/AdminFootprintEditForm.php b/src/Goteo/Library/Forms/Admin/AdminFootprintEditForm.php index 1f91d8d3bb..3d5baad9ef 100644 --- a/src/Goteo/Library/Forms/Admin/AdminFootprintEditForm.php +++ b/src/Goteo/Library/Forms/Admin/AdminFootprintEditForm.php @@ -57,7 +57,6 @@ public function createForm() { 'data' => [$model->icon ? $model->getIcon() : null], 'label' => 'admin-title-icon', 'accepted_files' => 'image/jpeg,image/gif,image/png,image/svg+xml', - 'url' => '/api/categories/images', 'constraints' => array( new Constraints\Count(array('max' => 1)) ), diff --git a/src/Goteo/Library/Forms/Admin/AdminPostEditForm.php b/src/Goteo/Library/Forms/Admin/AdminPostEditForm.php index 0f8d170f80..c20b3b65a5 100644 --- a/src/Goteo/Library/Forms/Admin/AdminPostEditForm.php +++ b/src/Goteo/Library/Forms/Admin/AdminPostEditForm.php @@ -49,7 +49,6 @@ public function createForm() { 'limit' => 1, 'label' => 'admin-title-header-image', 'accepted_files' => 'image/jpeg,image/gif,image/png', - 'url' => '/api/blog/images', 'constraints' => array( new Constraints\Count(array('max' => 1)) ) @@ -140,7 +139,6 @@ public function createForm() { 'label' => 'regular-images', 'markdown_link' => 'text', 'accepted_files' => 'image/jpeg,image/gif,image/png', - 'url' => '/api/blog/images', 'constraints' => array( new Constraints\Count(array('max' => 20)) ) diff --git a/src/Goteo/Library/Forms/Admin/AdminProgramForm.php b/src/Goteo/Library/Forms/Admin/AdminProgramForm.php index 29f547ac34..16c5c84384 100644 --- a/src/Goteo/Library/Forms/Admin/AdminProgramForm.php +++ b/src/Goteo/Library/Forms/Admin/AdminProgramForm.php @@ -56,7 +56,6 @@ public function createForm() { 'data' => [$model->header ? $model->getHeader() : null], 'label' => 'admin-title-icon', 'accepted_files' => 'image/jpeg,image/gif,image/png,image/svg+xml', - 'url' => '/api/channels/images', 'constraints' => array( new Constraints\Count(array('max' => 1)) ), diff --git a/src/Goteo/Library/Forms/Admin/AdminSdgEditForm.php b/src/Goteo/Library/Forms/Admin/AdminSdgEditForm.php index f5bc1c39d2..54e1052509 100644 --- a/src/Goteo/Library/Forms/Admin/AdminSdgEditForm.php +++ b/src/Goteo/Library/Forms/Admin/AdminSdgEditForm.php @@ -55,7 +55,6 @@ public function createForm() { 'data' => [$model->icon ? $model->getIcon() : null], 'label' => 'admin-title-icon', 'accepted_files' => 'image/jpeg,image/gif,image/png,image/svg+xml', - 'url' => '/api/categories/images', 'constraints' => array( new Constraints\Count(array('max' => 1)) ), diff --git a/src/Goteo/Library/Forms/Admin/AdminSectionForm.php b/src/Goteo/Library/Forms/Admin/AdminSectionForm.php index 9e31c0bf27..5a0b7ea270 100644 --- a/src/Goteo/Library/Forms/Admin/AdminSectionForm.php +++ b/src/Goteo/Library/Forms/Admin/AdminSectionForm.php @@ -58,10 +58,9 @@ public function createForm() { ->add('main_image', 'dropfiles', array( 'required' => false, 'limit' => 1, - 'data' => [$model->main_image ? $model->getMainImage() : null], + 'data' => [$model->main_image ? $model->getImage() : null], 'label' => 'regular-image', 'accepted_files' => 'image/jpeg,image/png,image/svg+xml', - 'url' => '/api/channels/images', 'constraints' => array( new Constraints\Count(array('max' => 1)) ), diff --git a/src/Goteo/Library/Forms/Admin/AdminSocialCommitmentEditForm.php b/src/Goteo/Library/Forms/Admin/AdminSocialCommitmentEditForm.php index 5b58993f9b..214fae03d7 100644 --- a/src/Goteo/Library/Forms/Admin/AdminSocialCommitmentEditForm.php +++ b/src/Goteo/Library/Forms/Admin/AdminSocialCommitmentEditForm.php @@ -60,7 +60,6 @@ public function createForm() { 'data' => [$model->icon ? $model->getIcon() : null], 'label' => 'admin-title-icon', 'accepted_files' => 'image/jpeg,image/gif,image/png,image/svg+xml', - 'url' => '/api/categories/images', 'constraints' => array( new Constraints\Count(array('max' => 1)) ), diff --git a/src/Goteo/Library/Forms/Admin/AdminSphereEditForm.php b/src/Goteo/Library/Forms/Admin/AdminSphereEditForm.php index 2e6813ad4e..876b97b7e7 100644 --- a/src/Goteo/Library/Forms/Admin/AdminSphereEditForm.php +++ b/src/Goteo/Library/Forms/Admin/AdminSphereEditForm.php @@ -50,7 +50,6 @@ public function createForm() { 'data' => [$model->icon ? $model->getIcon() : null], 'label' => 'admin-title-icon', 'accepted_files' => 'image/jpeg,image/gif,image/png,image/svg+xml', - 'url' => '/api/categories/images', 'constraints' => array( new Constraints\Count(array('max' => 1)) ), diff --git a/src/Goteo/Library/Forms/Admin/AdminStoryEditForm.php b/src/Goteo/Library/Forms/Admin/AdminStoryEditForm.php index 276cb431bd..90b16e0014 100644 --- a/src/Goteo/Library/Forms/Admin/AdminStoryEditForm.php +++ b/src/Goteo/Library/Forms/Admin/AdminStoryEditForm.php @@ -36,7 +36,6 @@ public function createForm() { ->add('image', 'dropfiles', [ 'label' => 'story-field-image', 'disabled' => $this->getReadonly(), - 'url' => '/api/stories/images', 'required' => true, 'data' => $story->getImage(), 'limit' => 1, @@ -48,7 +47,6 @@ public function createForm() { 'label' => 'story-field-pool-image', 'disabled' => $this->getReadonly(), 'data' => $story->getPoolImage(), - 'url' => '/api/stories/images', 'required' => false, 'limit' => 1, 'constraints' => [ @@ -60,7 +58,6 @@ public function createForm() { 'label' => 'story-field-background-image', 'disabled' => $this->getReadonly(), 'data' => $story->getBackgroundImage(), - 'url' => '/api/stories/images', 'required' => false, 'limit' => 1, 'constraints' => [ diff --git a/src/Goteo/Library/Forms/Admin/AdminWorkshopEditForm.php b/src/Goteo/Library/Forms/Admin/AdminWorkshopEditForm.php index cce789b12b..f38af7b4f8 100644 --- a/src/Goteo/Library/Forms/Admin/AdminWorkshopEditForm.php +++ b/src/Goteo/Library/Forms/Admin/AdminWorkshopEditForm.php @@ -101,7 +101,6 @@ public function createForm() { 'data' => [$workshop->header_image ? $workshop->getHeaderImage() : null], 'label' => 'admin-title-header-image', 'accepted_files' => 'image/jpeg,image/gif,image/png,image/svg+xml', - 'url' => '/api/workshops/images', 'constraints' => array( new Constraints\Count(array('max' => 1)) ) diff --git a/src/Goteo/Library/Forms/Model/QuestionnaireCreateForm.php b/src/Goteo/Library/Forms/Model/QuestionnaireCreateForm.php index 13014c14ff..8d775d9d0a 100644 --- a/src/Goteo/Library/Forms/Model/QuestionnaireCreateForm.php +++ b/src/Goteo/Library/Forms/Model/QuestionnaireCreateForm.php @@ -50,7 +50,7 @@ public function addQuestion($question) if ($config->attr) { $config->attr = (array) $config->attr; } if ($config->type == "dropfiles") { - $config->url = '/api/questionnaire/documents'; + // $config->url = '/api/questionnaire/documents'; $config->constraints = $this->getConstraints('docs'); } $builder = $this->getBuilder(); diff --git a/src/Goteo/Library/Forms/Model/QuestionnaireForm.php b/src/Goteo/Library/Forms/Model/QuestionnaireForm.php index ef4a1becc3..20ffd04ff4 100644 --- a/src/Goteo/Library/Forms/Model/QuestionnaireForm.php +++ b/src/Goteo/Library/Forms/Model/QuestionnaireForm.php @@ -53,7 +53,7 @@ public function createForm() $question->vars->attr = (array) $question->vars->attr; if ($type == "dropfiles") { - $question->vars->url = '/api/questionnaire/documents'; + // $question->vars->url = '/api/questionnaire/documents'; $question->vars->accepted_files = 'image/jpeg,image/gif,image/png,application/pdf'; $question->vars->constraints = [ new Constraints\Count(['max' => 1]), diff --git a/src/Goteo/Library/Forms/Model/UserProfileForm.php b/src/Goteo/Library/Forms/Model/UserProfileForm.php index 74b55eb54b..879b9978fc 100644 --- a/src/Goteo/Library/Forms/Model/UserProfileForm.php +++ b/src/Goteo/Library/Forms/Model/UserProfileForm.php @@ -107,7 +107,6 @@ public function createForm() { 'label' => 'profile-fields-image-title', 'constraints' => $this->getConstraints('avatar'), 'disabled' => $this->getReadonly(), - 'url' => '/api/users/' . $user->id . '/avatar', 'required' => false ]) ; From 9366bb4caaa68fffbeb62ee199bec970da42b2d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Ig=C3=B3n?= Date: Tue, 27 Jul 2021 15:41:00 +0200 Subject: [PATCH 03/20] make uploadimagetransformer save image so that it updates the file name --- src/Goteo/Util/Form/DataTransformer/UploadImageTransformer.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Goteo/Util/Form/DataTransformer/UploadImageTransformer.php b/src/Goteo/Util/Form/DataTransformer/UploadImageTransformer.php index cdc9a5970c..9bf29dd5c0 100644 --- a/src/Goteo/Util/Form/DataTransformer/UploadImageTransformer.php +++ b/src/Goteo/Util/Form/DataTransformer/UploadImageTransformer.php @@ -20,6 +20,7 @@ public function reverseTransform($image) { // Convert File to Image if(!$img instanceOf Image) { $image[$i] = new Image($img); + $image[$i]->save(); } } } From 782178a441d4cfb4e4b1a177aa4077fd392bf7bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Ig=C3=B3n?= Date: Tue, 27 Jul 2021 15:41:13 +0200 Subject: [PATCH 04/20] some fixes --- src/Goteo/Model/Questionnaire/Answer.php | 10 +++++++--- .../Transformer/ChannelProgramTransformer.php | 4 ++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Goteo/Model/Questionnaire/Answer.php b/src/Goteo/Model/Questionnaire/Answer.php index 69c7496fad..1705ca8392 100644 --- a/src/Goteo/Model/Questionnaire/Answer.php +++ b/src/Goteo/Model/Questionnaire/Answer.php @@ -70,12 +70,11 @@ public function save(&$errors = array()) */ static public function getList($filters = [], $offset = 0, $limit = 10, $count = false, $lang = null) { $values = []; - $filter = []; $sqlInner = ""; + $sqlWhere = []; if ($filters['questionnaire']) { - $sqlInner .= "LEFT JOIN question - ON question.questionnaire = :questionnaire AND question_answer.question = question.id + $sqlWhere[] = "question.questionnaire = :questionnaire AND question_answer.question = question.id "; $values[":questionnaire"] = $filters['questionnaire']; } @@ -85,6 +84,9 @@ static public function getList($filters = [], $offset = 0, $limit = 10, $count = $values[":project"] = $filters["project"]; } + if (!empty($sqlWhere)) + $where = "WHERE " . implode(' AND ', $sqlWhere); + if ($count) { $sql = "SELECT count(id) FROM question_answer @@ -93,10 +95,12 @@ static public function getList($filters = [], $offset = 0, $limit = 10, $count = return (int) self::query($sql, $values)->fetchColumn(); } + $sql = "SELECT question_answer.* FROM question_answer INNER JOIN question ON question_answer.question = question.id $sqlInner + $where ORDER BY question.order"; // die(\sqldbg($sql, $values)); diff --git a/src/Goteo/Util/ModelNormalizer/Transformer/ChannelProgramTransformer.php b/src/Goteo/Util/ModelNormalizer/Transformer/ChannelProgramTransformer.php index 279e89a523..0669129cb9 100644 --- a/src/Goteo/Util/ModelNormalizer/Transformer/ChannelProgramTransformer.php +++ b/src/Goteo/Util/ModelNormalizer/Transformer/ChannelProgramTransformer.php @@ -23,6 +23,10 @@ public function getDescription(){ return $this->model->description; } + public function getImage() { + return $this->model->getHeader()->getLink(64,64); + } + public function getActions() { if(!$u = $this->getUser()) return []; $ret = ['edit' => '/admin/channelprogram/'. $this->model->node_id . '/edit/' . $this->model->id]; From b7b3c0825bb8bf249af779dca96d83b1260abfba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Ig=C3=B3n?= Date: Mon, 2 Aug 2021 09:35:25 +0200 Subject: [PATCH 05/20] fix user profile form to save avatar --- src/Goteo/Library/Forms/Model/UserProfileForm.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Goteo/Library/Forms/Model/UserProfileForm.php b/src/Goteo/Library/Forms/Model/UserProfileForm.php index 879b9978fc..6dc7cdd9af 100644 --- a/src/Goteo/Library/Forms/Model/UserProfileForm.php +++ b/src/Goteo/Library/Forms/Model/UserProfileForm.php @@ -256,14 +256,15 @@ public function save(FormInterface $form = null, $force_save = false) { $user = $this->getModel(); // var_dump($data);die; // Process main image - if(is_array($data['avatar'])) { + if(is_array($data['avatar']) && !empty($data['avatar'])) { $data['avatar'] = reset($data['avatar']); - } - $user->user_avatar = $data['avatar']; - if($user->user_avatar && $err = $user->user_avatar->getUploadError()) { - throw new FormModelException(Text::get('form-sent-error', $err)); + $user->user_avatar = $data['avatar']; + if($user->user_avatar && $err = $user->user_avatar->getUploadError()) { + throw new FormModelException(Text::get('form-sent-error', $err)); + } } + // $data['user_avatar'] = $data['avatar']; unset($data['avatar']); // do not rebuild data using this From fc992c983b3c3862479ffc6e58547377b7179b17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Ig=C3=B3n?= Date: Fri, 20 Aug 2021 20:53:11 +0200 Subject: [PATCH 06/20] rework of dropfiles type and js --- .../forms/bootstrap/dropfiles_widget.html.php | 8 +++- public/assets/js/forms.js | 9 +++- src/Goteo/Util/Form/Type/DropfilesType.php | 43 +++++++++++++++++-- 3 files changed, 54 insertions(+), 6 deletions(-) diff --git a/Resources/templates/forms/bootstrap/dropfiles_widget.html.php b/Resources/templates/forms/bootstrap/dropfiles_widget.html.php index 4da46d7d85..9d3ef45e44 100644 --- a/Resources/templates/forms/bootstrap/dropfiles_widget.html.php +++ b/Resources/templates/forms/bootstrap/dropfiles_widget.html.php @@ -2,12 +2,13 @@ $uploads_name = $form['uploads']->vars['full_name']; $current_name = $form['current']->vars['full_name']; +$removed_name = $form['removed']->vars['full_name']; // $current_files = $value; $current_files = is_array($value) ? $value : [$value]; // var_dump($current_files);die; ?> -
+
    $text_send_to_markdown, 'text_delete_image' => $text_delete_image, 'text_download' => $text_download, - 'hidden_input' => '' + 'hidden_input' => '' ]); } } ?>
+ + +
diff --git a/public/assets/js/forms.js b/public/assets/js/forms.js index 02f998c210..55b805822c 100644 --- a/public/assets/js/forms.js +++ b/public/assets/js/forms.js @@ -900,7 +900,7 @@ $(function(){ // console.log('extension',ext,$img.attr('class')); if(response) { - $li.append(''); + $li.append(''); if($dz.data('markdown-link')) { $li.find('.add-to-markdown').data('target', $dz.data('markdown-link')); $li.find('.add-to-markdown').removeClass('hidden'); @@ -965,6 +965,7 @@ $(function(){ var $list = $(this).closest('.image-list-sortable'); var $form = $(this).closest('form'); var $error = $zone.next(); + var image = $li[0].getAttribute('data-name'); $li.remove(); $error.addClass('hidden'); var limit = parseInt($drop.data('limit')); @@ -972,6 +973,12 @@ $(function(){ if(total < limit) { $zone.find('.dragndrop').show(); } + if ($(this).parent().siblings('input').attr('name').includes("current")) { + $removed_input = $("input[name='" + $drop.data('removed') + "[]']"); + $cloned_input = $removed_input.get(0).cloneNode(); + $cloned_input.setAttribute('value', image); + $removed_input.after($cloned_input); + } }); // Add to markdown diff --git a/src/Goteo/Util/Form/Type/DropfilesType.php b/src/Goteo/Util/Form/Type/DropfilesType.php index 501d922f83..c32ceb74a9 100644 --- a/src/Goteo/Util/Form/Type/DropfilesType.php +++ b/src/Goteo/Util/Form/Type/DropfilesType.php @@ -19,9 +19,11 @@ use Symfony\Component\Form\Extension\Core\Type\FileType; use Symfony\Component\Form\Extension\Core\Type\CollectionType; use Symfony\Component\Form\Extension\Core\Type\HiddenType; +use Goteo\Util\Form\Type\TextType; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Form\CallbackTransformer; use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\HttpFoundation\File\File; /** * @@ -54,21 +56,56 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->get('uploads') ->addModelTransformer(new $options['upload_transformer']); + $builder->add('removed', CollectionType::class, [ + 'entry_type' => TextType::class, + 'allow_add' => true + ]); + + $builder->get('removed') + ->addModelTransformer( new CallbackTransformer( + function($image) { + return $image; + }, + function($image) { + $images = []; + + foreach($image as $img) { + if (!$img) + continue; + if ($img = Image::get($img)) + $images[] = $img; + } + + return $images; + } + )); + // General processing $builder->addViewTransformer(new CallbackTransformer( function($image) { + if ($image instanceOf File) + $image = new Image($image); + if (is_array($image)) { + foreach($image as $i => $img) { + if ($image instanceOf File) + $image = new Image($image); + } + } + return is_array($image) ? $image : [$image]; }, function ($image) { - // var_dump($image);die; // Sum current + uploads + $img = []; $img = isset($image['current']) && is_array($image['current']) ? $image['current'] : []; if($image['uploads']) { if(is_array($image['uploads'])) { - $img = array_merge($img, $image['uploads']); + $img = array_merge($img, ['uploads' => $image['uploads']]); } } - // var_dump($img);die; + if ($image['removed']) { + $img = array_merge($img, ['removed' => $image['removed']] ); + } return $img; // return null; })); From bc077e097aec189fd5ab0f92200c6f504704c9db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Ig=C3=B3n?= Date: Fri, 20 Aug 2021 20:53:38 +0200 Subject: [PATCH 07/20] rework of all forms with dropfiles --- .../Admin/AdminChannelResourceEditForm.php | 15 ++++-- .../Forms/Admin/AdminFootprintEditForm.php | 25 +++++++--- .../Library/Forms/Admin/AdminPostEditForm.php | 5 +- .../Library/Forms/Admin/AdminProgramForm.php | 25 ++++++---- .../Library/Forms/Admin/AdminSdgEditForm.php | 21 ++++---- .../Library/Forms/Admin/AdminSectionForm.php | 21 ++++---- .../Admin/AdminSocialCommitmentEditForm.php | 21 ++++---- .../Forms/Admin/AdminSphereEditForm.php | 20 ++++---- .../Forms/Admin/AdminStoryEditForm.php | 44 ++++++++++------ .../Forms/Admin/AdminWorkshopEditForm.php | 16 ++++-- .../Library/Forms/Model/ProjectPostForm.php | 50 ++++++++++++------- .../Library/Forms/Model/ProjectStoryForm.php | 46 +++++++++++++---- .../Library/Forms/Model/UserProfileForm.php | 18 +++++-- src/Goteo/Model/Node/NodeProgram.php | 9 ---- src/Goteo/Model/Node/NodeResource.php | 6 --- src/Goteo/Model/Stories.php | 6 +-- src/Goteo/Model/User.php | 4 ++ src/Goteo/Model/Workshop.php | 7 --- 18 files changed, 211 insertions(+), 148 deletions(-) diff --git a/src/Goteo/Library/Forms/Admin/AdminChannelResourceEditForm.php b/src/Goteo/Library/Forms/Admin/AdminChannelResourceEditForm.php index 35824f6a97..5e88cb69dd 100644 --- a/src/Goteo/Library/Forms/Admin/AdminChannelResourceEditForm.php +++ b/src/Goteo/Library/Forms/Admin/AdminChannelResourceEditForm.php @@ -64,10 +64,7 @@ public function createForm() { 'limit' => 1, 'data' => [$resource->image ? $resource->getImage() : null], 'label' => 'admin-title-image', - 'accepted_files' => 'image/jpeg,image/gif,image/png,image/svg+xml', - 'constraints' => array( - new Constraints\Count(array('max' => 1)) - ) + 'accepted_files' => 'image/jpeg,image/gif,image/png,image/svg+xml' )) ->add('node_id', 'choice', array( 'label' => 'admin-title-channel', @@ -97,8 +94,16 @@ public function save(FormInterface $form = null, $force_save = false) { if(!$form->isValid() && !$force_save) throw new FormModelException(Text::get('form-has-errors')); $data = $form->getData(); - $model = $this->getModel(); + + if ($data['image']['removed']) + if ($model->image->id == current($data['image']['removed'])->id) + $model->image = null; + + if ($data['image']['uploads']) + $model->image = $data['image']['uploads']; + + unset($data['image']); $model->rebuildData($data, array_keys($form->all())); $errors = []; diff --git a/src/Goteo/Library/Forms/Admin/AdminFootprintEditForm.php b/src/Goteo/Library/Forms/Admin/AdminFootprintEditForm.php index 3d5baad9ef..36b28f63aa 100644 --- a/src/Goteo/Library/Forms/Admin/AdminFootprintEditForm.php +++ b/src/Goteo/Library/Forms/Admin/AdminFootprintEditForm.php @@ -57,9 +57,6 @@ public function createForm() { 'data' => [$model->icon ? $model->getIcon() : null], 'label' => 'admin-title-icon', 'accepted_files' => 'image/jpeg,image/gif,image/png,image/svg+xml', - 'constraints' => array( - new Constraints\Count(array('max' => 1)) - ), 'attr' => [ 'help' => Text::get('admin-categories-if-empty-then-asset', '') ] @@ -109,14 +106,26 @@ public function save(FormInterface $form = null, $force_save = false) { $data = $form->getData(); // Dropfiles type always return an array, just get the first element if required - if($data['icon'] && is_array($data['icon'])) { - $data['icon'] = $data['icon'][0]; - } else { - $data['icon'] = null; - } + // if($data['icon'] && is_array($data['icon'])) { + // $data['icon'] = $data['icon'][0]; + // } else { + // $data['icon'] = null; + // } + // print_r($data);die; $model = $this->getModel(); + if ($data['icon'] && is_array($data['icon'])) { + if ($data['icon']['removed'] && $model->icon == current($data['icon']['removed'])->id) + $model->icon = null; + + if ($data['icon']['uploads'] && is_array($data['icon']['uploads'])) + $model->icon = $data['icon']['uploads'][0]; + } + + unset($data['icon']); + $model->rebuildData($data, array_keys($form->all())); + $errors = []; if (!$model->save($errors)) { diff --git a/src/Goteo/Library/Forms/Admin/AdminPostEditForm.php b/src/Goteo/Library/Forms/Admin/AdminPostEditForm.php index c20b3b65a5..7755b3b71f 100644 --- a/src/Goteo/Library/Forms/Admin/AdminPostEditForm.php +++ b/src/Goteo/Library/Forms/Admin/AdminPostEditForm.php @@ -48,10 +48,7 @@ public function createForm() { 'required' => false, 'limit' => 1, 'label' => 'admin-title-header-image', - 'accepted_files' => 'image/jpeg,image/gif,image/png', - 'constraints' => array( - new Constraints\Count(array('max' => 1)) - ) + 'accepted_files' => 'image/jpeg,image/gif,image/png' )) ->add('author', 'typeahead', [ 'label' => 'regular-author', diff --git a/src/Goteo/Library/Forms/Admin/AdminProgramForm.php b/src/Goteo/Library/Forms/Admin/AdminProgramForm.php index 16c5c84384..6ccd64066b 100644 --- a/src/Goteo/Library/Forms/Admin/AdminProgramForm.php +++ b/src/Goteo/Library/Forms/Admin/AdminProgramForm.php @@ -54,11 +54,8 @@ public function createForm() { 'required' => false, 'limit' => 1, 'data' => [$model->header ? $model->getHeader() : null], - 'label' => 'admin-title-icon', - 'accepted_files' => 'image/jpeg,image/gif,image/png,image/svg+xml', - 'constraints' => array( - new Constraints\Count(array('max' => 1)) - ), + 'label' => 'admin-title-header-image', + 'accepted_files' => 'image/jpeg,image/gif,image/png,image/svg+xml' )) ->add('icon', 'text', [ 'disabled' => $this->getReadonly(), @@ -94,15 +91,21 @@ public function save(FormInterface $form = null, $force_save = false) { $data = $form->getData(); $model = $this->getModel(); - $model->rebuildData($data, array_keys($form->all())); - - // Dropfiles type always return an array, just get the first element if required + if($data['header'] && is_array($data['header'])) { - $data['header'] = $data['header'][0]->name; - } else { - $data['header'] = null; + if ($data['header']['removed']) { + if ($model->header == $data['header']['removed'][0]->id) + $model->header = null; + } + + if ($data['header']['uploads']) { + $model->header = $data['header']['uploads'][0]; + } } + unset($data['header']); + + $model->rebuildData($data, array_keys($form->all())); $errors = []; if (!$model->save($errors)) { throw new FormModelException(Text::get('form-sent-error', implode(', ',$errors))); diff --git a/src/Goteo/Library/Forms/Admin/AdminSdgEditForm.php b/src/Goteo/Library/Forms/Admin/AdminSdgEditForm.php index 54e1052509..6dccc5dab4 100644 --- a/src/Goteo/Library/Forms/Admin/AdminSdgEditForm.php +++ b/src/Goteo/Library/Forms/Admin/AdminSdgEditForm.php @@ -37,7 +37,6 @@ public function createForm() { $sdgs[' '.$s->name] = $s->id; } - // print_r($defaults);die; $builder ->add('name', 'text', [ 'disabled' => $this->getReadonly(), @@ -55,9 +54,6 @@ public function createForm() { 'data' => [$model->icon ? $model->getIcon() : null], 'label' => 'admin-title-icon', 'accepted_files' => 'image/jpeg,image/gif,image/png,image/svg+xml', - 'constraints' => array( - new Constraints\Count(array('max' => 1)) - ), 'attr' => [ 'help' => Text::get('admin-categories-if-empty-then-asset', '') ] @@ -84,14 +80,17 @@ public function save(FormInterface $form = null, $force_save = false) { if(!$form->isValid() && !$force_save) throw new FormModelException(Text::get('form-has-errors')); $data = $form->getData(); - // Dropfiles type always return an array, just get the first element if required - if($data['icon'] && is_array($data['icon'])) { - $data['icon'] = $data['icon'][0]; - } else { - $data['icon'] = null; - } - // print_r($data);die; $model = $this->getModel(); + + if ($data['icon'] && is_array($data['icon'])) { + if ($data['icon']['removed'] && $model->icon->id == current($data['icon']['removed'])->id) + $model->icon = null; + + if ($data['icon']['uploads'] && is_array($data['icon']['uploads'])) + $model->icon = $data['icon']['uploads'][0]; + } + + unset($data['icon']); $model->rebuildData($data, array_keys($form->all())); $errors = []; diff --git a/src/Goteo/Library/Forms/Admin/AdminSectionForm.php b/src/Goteo/Library/Forms/Admin/AdminSectionForm.php index 5a0b7ea270..0e859189d5 100644 --- a/src/Goteo/Library/Forms/Admin/AdminSectionForm.php +++ b/src/Goteo/Library/Forms/Admin/AdminSectionForm.php @@ -60,10 +60,7 @@ public function createForm() { 'limit' => 1, 'data' => [$model->main_image ? $model->getImage() : null], 'label' => 'regular-image', - 'accepted_files' => 'image/jpeg,image/png,image/svg+xml', - 'constraints' => array( - new Constraints\Count(array('max' => 1)) - ), + 'accepted_files' => 'image/jpeg,image/png,image/svg+xml' )) ; @@ -78,15 +75,17 @@ public function save(FormInterface $form = null, $force_save = false) { } $data = $form->getData(); - // Dropfiles type always return an array, just get the first element if required - if($data['main_image'] && is_array($data['main_image'])) { - $data['main_image'] = $data['main_image'][0]; - } else { - $data['main_image'] = null; + $model = $this->getModel(); + + if ($data['main_image'] && is_array($data['main_image'])) { + if ($data['main_image']['removed'] && $model->main_image == current($data['main_image']['removed'])->id) + $model->main_image = null; + + if ($data['main_image']['uploads'] && is_array($data['main_image']['uploads'])) + $model->main_image = $data['main_image']['uploads'][0]; } - $model = $this->getModel(); - + unset($data['main_image']); $model->rebuildData($data, array_keys($form->all())); $errors = []; if (!$model->save($errors)) { diff --git a/src/Goteo/Library/Forms/Admin/AdminSocialCommitmentEditForm.php b/src/Goteo/Library/Forms/Admin/AdminSocialCommitmentEditForm.php index 214fae03d7..6508facd70 100644 --- a/src/Goteo/Library/Forms/Admin/AdminSocialCommitmentEditForm.php +++ b/src/Goteo/Library/Forms/Admin/AdminSocialCommitmentEditForm.php @@ -60,9 +60,6 @@ public function createForm() { 'data' => [$model->icon ? $model->getIcon() : null], 'label' => 'admin-title-icon', 'accepted_files' => 'image/jpeg,image/gif,image/png,image/svg+xml', - 'constraints' => array( - new Constraints\Count(array('max' => 1)) - ), 'attr' => [ 'help' => Text::get('admin-categories-if-empty-then-asset', '') ] @@ -100,14 +97,18 @@ public function save(FormInterface $form = null, $force_save = false) { if(!$form->isValid() && !$force_save) throw new FormModelException(Text::get('form-has-errors')); $data = $form->getData(); - // Dropfiles type always return an array, just get the first element if required - if($data['icon'] && is_array($data['icon'])) { - $data['icon'] = $data['icon'][0]; - } else { - $data['icon'] = null; - } - // print_r($data);die; $model = $this->getModel(); + + if ($data['icon'] && is_array($data['icon'])) { + if ($data['icon']['removed'] && $model->icon == current($data['icon']['removed'])->id) + $model->icon = null; + + if ($data['icon']['uploads'] && is_array($data['icon']['uploads'])) + $model->icon = $data['icon']['uploads'][0]; + } + + unset($data['icon']); + $model->rebuildData($data, array_keys($form->all())); $errors = []; diff --git a/src/Goteo/Library/Forms/Admin/AdminSphereEditForm.php b/src/Goteo/Library/Forms/Admin/AdminSphereEditForm.php index 876b97b7e7..a71853a9e4 100644 --- a/src/Goteo/Library/Forms/Admin/AdminSphereEditForm.php +++ b/src/Goteo/Library/Forms/Admin/AdminSphereEditForm.php @@ -50,9 +50,6 @@ public function createForm() { 'data' => [$model->icon ? $model->getIcon() : null], 'label' => 'admin-title-icon', 'accepted_files' => 'image/jpeg,image/gif,image/png,image/svg+xml', - 'constraints' => array( - new Constraints\Count(array('max' => 1)) - ), 'attr' => [ 'help' => Text::get('admin-categories-if-empty-then-asset', '') ] @@ -84,14 +81,17 @@ public function save(FormInterface $form = null, $force_save = false) { if(!$form->isValid() && !$force_save) throw new FormModelException(Text::get('form-has-errors')); $data = $form->getData(); - // Dropfiles type always return an array, just get the first element if required - if($data['icon'] && is_array($data['icon'])) { - $data['icon'] = $data['icon'][0]; - } else { - $data['icon'] = null; - } - // print_r($data);die; $model = $this->getModel(); + + if ($data['icon'] && is_array($data['icon'])) { + if ($data['icon']['removed'] && $model->icon == current($data['icon']['removed'])->id) + $model->icon = null; + + if ($data['icon']['uploads'] && is_array($data['icon']['uploads'])) + $model->icon = $data['icon']['uploads'][0]; + } + + unset($data['icon']); $model->rebuildData($data, array_keys($form->all())); $errors = []; diff --git a/src/Goteo/Library/Forms/Admin/AdminStoryEditForm.php b/src/Goteo/Library/Forms/Admin/AdminStoryEditForm.php index 90b16e0014..c85615b7fd 100644 --- a/src/Goteo/Library/Forms/Admin/AdminStoryEditForm.php +++ b/src/Goteo/Library/Forms/Admin/AdminStoryEditForm.php @@ -38,32 +38,21 @@ public function createForm() { 'disabled' => $this->getReadonly(), 'required' => true, 'data' => $story->getImage(), - 'limit' => 1, - 'constraints' => [ - new Constraints\Count(['max' => 1]), - ] + 'limit' => 1 ]) ->add('pool_image', 'dropfiles', [ 'label' => 'story-field-pool-image', 'disabled' => $this->getReadonly(), 'data' => $story->getPoolImage(), 'required' => false, - 'limit' => 1, - 'constraints' => [ - new Constraints\Count(['max' => 1]), - ] - + 'limit' => 1 ]) ->add('background_image', 'dropfiles', [ 'label' => 'story-field-background-image', 'disabled' => $this->getReadonly(), 'data' => $story->getBackgroundImage(), 'required' => false, - 'limit' => 1, - 'constraints' => [ - new Constraints\Count(['max' => 1]), - ] - + 'limit' => 1 ]) ->add('background_image_credits', 'text', array( 'label' => 'story-field-background-image-credits', @@ -157,6 +146,31 @@ public function save(FormInterface $form = null, $force_save = false) { $data = $form->getData(); $model = $this->getModel(); + + if ($data['image'] && is_array($data['image'])) { + if ($data['image']['uploads'] && is_array($data['image']['uploads'])) + $model->image = $data['image']['uploads'][0]; + } + + if ($data['background_image'] && is_array($data['background_image'])) { + if ($data['background_image']['removed'] && $model->background_image == current($data['background_image']['removed'])->id) + $model->background_image = null; + + if ($data['background_image']['uploads'] && is_array($data['background_image']['uploads'])) + $model->background_image = $data['background_image']['uploads'][0]; + } + + if ($data['pool_image'] && is_array($data['pool_image'])) { + if ($data['pool_image']['removed'] && $model->pool_image == current($data['pool_image']['removed'])->id) + $model->pool_image = null; + + if ($data['pool_image']['uploads'] && is_array($data['pool_image']['uploads'])) + $model->pool_image = $data['pool_image']['uploads'][0]; + } + + unset($data['image']); + unset($data['background_image']); + unset($data['pool_image']); $model->rebuildData($data, array_keys($form->all())); $errors = []; @@ -164,7 +178,7 @@ public function save(FormInterface $form = null, $force_save = false) { throw new FormModelException(Text::get('form-sent-error', implode(', ',$errors))); } - if ($model->background_image && $data['background_image_credits']) { + if ($model->background_image && $data['background_image_credits_credits']) { $model->background_image->setCredits($data['background_image_credits']); } diff --git a/src/Goteo/Library/Forms/Admin/AdminWorkshopEditForm.php b/src/Goteo/Library/Forms/Admin/AdminWorkshopEditForm.php index f38af7b4f8..04b20348c0 100644 --- a/src/Goteo/Library/Forms/Admin/AdminWorkshopEditForm.php +++ b/src/Goteo/Library/Forms/Admin/AdminWorkshopEditForm.php @@ -100,10 +100,7 @@ public function createForm() { 'limit' => 1, 'data' => [$workshop->header_image ? $workshop->getHeaderImage() : null], 'label' => 'admin-title-header-image', - 'accepted_files' => 'image/jpeg,image/gif,image/png,image/svg+xml', - 'constraints' => array( - new Constraints\Count(array('max' => 1)) - ) + 'accepted_files' => 'image/jpeg,image/gif,image/png,image/svg+xml' )) ->add('venue', 'text', [ 'label' => 'admin-title-venue', @@ -173,12 +170,21 @@ public function save(FormInterface $form = null, $force_save = false) { if(!$form->isValid() && !$force_save) throw new FormModelException(Text::get('form-has-errors')); $data = $form->getData(); - // Instance of workshop location $workshop_location=$data['workshop_location']; $data['workshop_location'] = $data['workshop_location']->location ? $data['workshop_location']->location : $data['workshop_location']->name; $model = $this->getModel(); + + if ($data['header_image'] && is_array($data['header_image'])) { + if (current($data['header_image']['removed'])->id == $model->header_image) + $model->header_image = null; + + if ($data['header_image']['uploads']) + $model->header_image = $data['header_image']['uploads'][0]; + } + + unset($data['header_image']); $model->rebuildData($data, array_keys($form->all())); $errors = []; diff --git a/src/Goteo/Library/Forms/Model/ProjectPostForm.php b/src/Goteo/Library/Forms/Model/ProjectPostForm.php index e6d38df190..66849e21e1 100644 --- a/src/Goteo/Library/Forms/Model/ProjectPostForm.php +++ b/src/Goteo/Library/Forms/Model/ProjectPostForm.php @@ -99,30 +99,44 @@ public function save(FormInterface $form = null, $force_save = false) { $data = $form->getData(); if(array_key_exists('tags', $data)) $data['tags'] = explode(',', $data['tags']); $post = $this->getModel(); - $post->rebuildData($data, array_keys($form->all())); - $post->image = $data['image']; - if(is_array($data['header_image'])) $post->header_image = $data['header_image'][0]; - - + $gallery = Image::getModelGallery('post', $post->id); - - $current = array_map(function($e) { - return is_object($e) ? $e->id : $e['id']; - }, $post->image); - - // print_r($gallery); - if(is_array($gallery)) { - foreach($gallery as $img) { - if(!in_array($img->id, $current)) { - // Delete from model if exists - Image::deleteModelImage('post', $post->id); - // delete from gallery if exists - $img->delFromModelGallery('post', $post->id); + $post->image = $gallery; + + if ($data['image'] && is_array($data['image'])) { + if ($data['image']['removed']) { + $removed_ids = array_column($data['image']['removed'], null, 'id'); + + if(is_array($post->image)) { + foreach($post->image as $index => $img) { + if(in_array($img->id, $removed_ids)) { + // delete from gallery if exists + $img->delFromModelGallery('post', $post->id); + unset($post->image[$index]); + } + } } } + + if ($data['image']['uploads']) { + $post->image = array_merge($post->image, $data['image']['uploads']); + } + } + + if ($data['header_image'] && is_array($data['header_image'])) { + + if (current($data['header_image']['removed'])->id == $post->header_image) + $post->header_image = null; + + if ($data['header_image']['uploads']) + $post->header_image = $data['header_image']['uploads'][0]; } // print_r($post);die; + unset($data['image']); + unset($data['header_image']); + $post->rebuildData($data, array_keys($form->all())); + // Remove html tags if has no permission if(!Session::getUser()->hasPerm('full-html-edit')) { $post->text = Text::tags_filter($post->text); diff --git a/src/Goteo/Library/Forms/Model/ProjectStoryForm.php b/src/Goteo/Library/Forms/Model/ProjectStoryForm.php index 4252aab390..5f0363e0c4 100644 --- a/src/Goteo/Library/Forms/Model/ProjectStoryForm.php +++ b/src/Goteo/Library/Forms/Model/ProjectStoryForm.php @@ -39,7 +39,6 @@ public function getConstraints($field) { public function createForm() { $builder = $this->getBuilder(); - $project = $this->getOption('project'); $builder @@ -61,25 +60,52 @@ public function createForm() { 'disabled' => $this->getReadonly(), 'url' => '/api/projects/' . $project->id . '/images', 'required' => true, - 'limit' => 1, - 'constraints' => [ - new Constraints\Count(['max' => 1, 'min' => 1]), - ] + 'limit' => 1 ]) ->add('pool_image', 'dropfiles', [ 'label' => 'story-field-pool-image', 'disabled' => $this->getReadonly(), 'url' => '/api/projects/' . $project->id . '/images', 'required' => false, - 'limit' => 1, - 'constraints' => [ - new Constraints\Count(['max' => 1]), - ] - + 'limit' => 1 ]); return $this; } + public function save(FormInterface $form = null, $force_save = false) { + + if(!$form) $form = $this->getBuilder()->getForm(); + if(!$form->isValid() && !$force_save) { + throw new FormModelException(Text::get('form-has-errors')); + } + + $data = $form->getData(); + $model = $this->getModel(); + + if ($data['image'] && is_array($data['image'])) { + if ($data['image']['removed'] && $model->image == current($data['image']['removed'])->id) + $model->image = null; + + if ($data['image']['uploads'] && is_array($data['image']['uploads'])) + $model->image = $data['image']['uploads'][0]; + } + if ($data['pool_image'] && is_array($data['pool_image'])) { + if ($data['pool_image']['removed'] && $model->pool_image == current($data['pool_image']['removed'])->id) + $model->pool_image = null; + + if ($data['pool_image']['uploads'] && is_array($data['pool_image']['uploads'])) + $model->pool_image = $data['pool_image']['uploads'][0]; + } + + unset($data['image']); + unset($data['pool_image']); + $model->rebuildData($data, array_keys($form->all())); + $errors = []; + if (!$model->save($errors)) { + throw new FormModelException(Text::get('form-sent-error', implode(', ',$errors))); + } + return $this; + } } diff --git a/src/Goteo/Library/Forms/Model/UserProfileForm.php b/src/Goteo/Library/Forms/Model/UserProfileForm.php index 6dc7cdd9af..ad65e33344 100644 --- a/src/Goteo/Library/Forms/Model/UserProfileForm.php +++ b/src/Goteo/Library/Forms/Model/UserProfileForm.php @@ -71,6 +71,7 @@ public function createForm() { $builder = $this->getBuilder(); $options = $builder->getOptions(); $defaults = $options['data']; + // print_r($defaults);die; $builder ->add('name', 'text', [ @@ -257,15 +258,22 @@ public function save(FormInterface $form = null, $force_save = false) { // var_dump($data);die; // Process main image if(is_array($data['avatar']) && !empty($data['avatar'])) { - $data['avatar'] = reset($data['avatar']); - $user->user_avatar = $data['avatar']; + if (!empty($data['avatar']['removed'])) { + if ($user->avatar->id == current($data['avatar']['removed'])->id) { + $user->user_avatar = []; + } + } + + if (!empty($data['avatar']['uploads'])) { + $uploaded_avatar = $data['avatar']['uploads'][0]; + $user->user_avatar = $uploaded_avatar; - if($user->user_avatar && $err = $user->user_avatar->getUploadError()) { - throw new FormModelException(Text::get('form-sent-error', $err)); + if($user->user_avatar && $err = $user->user_avatar->getUploadError()) { + throw new FormModelException(Text::get('form-sent-error', $err)); + } } } - // $data['user_avatar'] = $data['avatar']; unset($data['avatar']); // do not rebuild data using this // Process interests diff --git a/src/Goteo/Model/Node/NodeProgram.php b/src/Goteo/Model/Node/NodeProgram.php index 72cc8328ac..ec6b2c854f 100644 --- a/src/Goteo/Model/Node/NodeProgram.php +++ b/src/Goteo/Model/Node/NodeProgram.php @@ -133,15 +133,6 @@ public function save(&$errors = array()) { if (!$this->validate($errors)) return false; - // Dropfiles type always return an array, just get the first element if required - if($this->header && is_array($this->header)) { - $this->header = $this->header[0]; - } else { - $this->header = null; - } - - // TODO: handle uploaded files here? - // If instanceOf Image, means already uploaded (via API probably), just get the name if($this->header instanceOf Image) $this->header = $this->header->getName(); diff --git a/src/Goteo/Model/Node/NodeResource.php b/src/Goteo/Model/Node/NodeResource.php index 60508f8186..84cc65875e 100644 --- a/src/Goteo/Model/Node/NodeResource.php +++ b/src/Goteo/Model/Node/NodeResource.php @@ -127,15 +127,10 @@ public function save(&$errors = array()) { if (!$this->validate($errors)) return false; - // Dropfiles type always return an array, just get the first element if required if($this->image && is_array($this->image)) { $this->image = $this->image[0]; - } else { - $this->image = null; } - // TODO: handle uploaded files here? - // If instanceOf Image, means already uploaded (via API probably), just get the name if($this->image instanceOf Image) $this->image = $this->image->getName(); @@ -155,7 +150,6 @@ public function save(&$errors = array()) { ); try { - //automatic $this->id assignation $this->dbInsertUpdate($fields); return true; diff --git a/src/Goteo/Model/Stories.php b/src/Goteo/Model/Stories.php index a114810670..3274e72e79 100644 --- a/src/Goteo/Model/Stories.php +++ b/src/Goteo/Model/Stories.php @@ -376,7 +376,7 @@ public function getUser() { } public function getImage() { - if(!$this->imageInstance instanceOf Image) { + if(!$this->imageInstance instanceOf Image && $this->image) { $this->imageInstance = new Image($this->image); } return $this->imageInstance; @@ -393,14 +393,14 @@ public function getSphere() { } public function getPoolImage() { - if(!$this->PoolImageInstance instanceOf Image) { + if(!$this->PoolImageInstance instanceOf Image && $this->pool_image) { $this->PoolImageInstance = new Image($this->pool_image); } return $this->PoolImageInstance; } public function getBackgroundImage() { - if(!$this->BackgroundImageInstance instanceOf Image) { + if(!$this->BackgroundImageInstance instanceOf Image && $this->backgorund_image) { $this->BackgroundImageInstance = new Image($this->background_image); } return $this->BackgroundImageInstance; diff --git a/src/Goteo/Model/User.php b/src/Goteo/Model/User.php index 1fd564b1a1..a2c096ea4f 100644 --- a/src/Goteo/Model/User.php +++ b/src/Goteo/Model/User.php @@ -209,7 +209,11 @@ public function save(&$errors = array(), $skip_validations = array()) { } else { unset($data[':avatar']); } + } else if ($this->user_avatar instanceOf Image) { + $data[':avatar'] = $this->user_avatar->id; + $this->avatar = $this->user_avatar; } + if (empty($this->user_avatar)) { $data[':avatar'] = ''; $this->avatar->remove(); diff --git a/src/Goteo/Model/Workshop.php b/src/Goteo/Model/Workshop.php index 7b9556f07b..7a6a419fe7 100644 --- a/src/Goteo/Model/Workshop.php +++ b/src/Goteo/Model/Workshop.php @@ -410,13 +410,6 @@ public function save(&$errors = array()) { if (!$this->validate($errors)) return false; - // Dropfiles type always return an array, just get the first element if required - if($this->header_image && is_array($this->header_image)) { - $this->header_image = $this->header_image[0]; - } else { - $this->header_image = null; - } - // TODO: handle uploaded files here? // If instanceOf Image, means already uploaded (via API probably), just get the name if($this->header_image instanceOf Image) From 5e7e45b5d18b8bf77d90559d3b56a02fe5c49829 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Ig=C3=B3n?= Date: Fri, 20 Aug 2021 20:53:53 +0200 Subject: [PATCH 08/20] small fixes in model transformers --- .../Transformer/ChannelProgramTransformer.php | 5 ++++- .../Transformer/ChannelResourceTransformer.php | 9 ++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Goteo/Util/ModelNormalizer/Transformer/ChannelProgramTransformer.php b/src/Goteo/Util/ModelNormalizer/Transformer/ChannelProgramTransformer.php index 0669129cb9..b702b260a4 100644 --- a/src/Goteo/Util/ModelNormalizer/Transformer/ChannelProgramTransformer.php +++ b/src/Goteo/Util/ModelNormalizer/Transformer/ChannelProgramTransformer.php @@ -24,7 +24,10 @@ public function getDescription(){ } public function getImage() { - return $this->model->getHeader()->getLink(64,64); + if ($this->model->header) + return $this->model->getHeader()->getLink(64,64); + + return null; } public function getActions() { diff --git a/src/Goteo/Util/ModelNormalizer/Transformer/ChannelResourceTransformer.php b/src/Goteo/Util/ModelNormalizer/Transformer/ChannelResourceTransformer.php index d9011bad99..230e967f4e 100644 --- a/src/Goteo/Util/ModelNormalizer/Transformer/ChannelResourceTransformer.php +++ b/src/Goteo/Util/ModelNormalizer/Transformer/ChannelResourceTransformer.php @@ -19,10 +19,17 @@ class ChannelResourceTransformer extends AbstractTransformer { protected $keys = ['id', 'image', 'title']; + public function getInfo() { return ''.$this->getTitle().''; } - + + public function getImage() { + if ($this->model->image) + return $this->model->getImage()->getLink(64,64,true); + + return $this->model->image; + } public function getActions() { if(!$u = $this->getUser()) return []; From b539e6ab30b683035a0b7efae683cbf39aa5ef74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Ig=C3=B3n?= Date: Tue, 14 Sep 2021 16:49:53 +0200 Subject: [PATCH 09/20] remove unnecessary comments from Forms --- src/Goteo/Library/Forms/Admin/AdminFootprintEditForm.php | 9 +-------- .../Library/Forms/Model/QuestionnaireCreateForm.php | 1 - src/Goteo/Library/Forms/Model/QuestionnaireForm.php | 5 ----- 3 files changed, 1 insertion(+), 14 deletions(-) diff --git a/src/Goteo/Library/Forms/Admin/AdminFootprintEditForm.php b/src/Goteo/Library/Forms/Admin/AdminFootprintEditForm.php index 36b28f63aa..442e1e7062 100644 --- a/src/Goteo/Library/Forms/Admin/AdminFootprintEditForm.php +++ b/src/Goteo/Library/Forms/Admin/AdminFootprintEditForm.php @@ -105,14 +105,7 @@ public function save(FormInterface $form = null, $force_save = false) { if(!$form->isValid() && !$force_save) throw new FormModelException(Text::get('form-has-errors')); $data = $form->getData(); - // Dropfiles type always return an array, just get the first element if required - // if($data['icon'] && is_array($data['icon'])) { - // $data['icon'] = $data['icon'][0]; - // } else { - // $data['icon'] = null; - // } - - // print_r($data);die; + $model = $this->getModel(); if ($data['icon'] && is_array($data['icon'])) { if ($data['icon']['removed'] && $model->icon == current($data['icon']['removed'])->id) diff --git a/src/Goteo/Library/Forms/Model/QuestionnaireCreateForm.php b/src/Goteo/Library/Forms/Model/QuestionnaireCreateForm.php index 8d775d9d0a..fda9d5f19a 100644 --- a/src/Goteo/Library/Forms/Model/QuestionnaireCreateForm.php +++ b/src/Goteo/Library/Forms/Model/QuestionnaireCreateForm.php @@ -50,7 +50,6 @@ public function addQuestion($question) if ($config->attr) { $config->attr = (array) $config->attr; } if ($config->type == "dropfiles") { - // $config->url = '/api/questionnaire/documents'; $config->constraints = $this->getConstraints('docs'); } $builder = $this->getBuilder(); diff --git a/src/Goteo/Library/Forms/Model/QuestionnaireForm.php b/src/Goteo/Library/Forms/Model/QuestionnaireForm.php index 20ffd04ff4..ed3d4600cd 100644 --- a/src/Goteo/Library/Forms/Model/QuestionnaireForm.php +++ b/src/Goteo/Library/Forms/Model/QuestionnaireForm.php @@ -28,9 +28,6 @@ class QuestionnaireForm extends AbstractFormProcessor implements FormProcessorIn public function getConstraints($field) { $constraints = []; - if($this->getFullValidation()) { - // $constraints[] = new Constraints\NotBlank(); - } return $constraints; } @@ -53,7 +50,6 @@ public function createForm() $question->vars->attr = (array) $question->vars->attr; if ($type == "dropfiles") { - // $question->vars->url = '/api/questionnaire/documents'; $question->vars->accepted_files = 'image/jpeg,image/gif,image/png,application/pdf'; $question->vars->constraints = [ new Constraints\Count(['max' => 1]), @@ -86,7 +82,6 @@ public function save(FormInterface $form = null, $force_save = false) $questionnaire = $this->getModel(); $questions = Question::getByQuestionnaire($questionnaire->id); $questions = array_column($questions, NULL, 'id'); - // $data = $form->getData();] $index = 0; if ($answers = Answer::getList(['project' => $this->model->project_id, 'questionnaire' => $questionnaire->id])) From aa5622a488fb1873681d3cbedefc1ce223de07b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Alberto=20Mart=C3=ADnez=20Gadea?= Date: Tue, 14 Sep 2021 17:27:44 +0200 Subject: [PATCH 10/20] Fix AdminStoryEdit form so it can properly add, save and remove the 3 types of images it has --- .../Forms/Admin/AdminStoryEditForm.php | 40 +++++++++---------- src/Goteo/Model/Stories.php | 2 +- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/src/Goteo/Library/Forms/Admin/AdminStoryEditForm.php b/src/Goteo/Library/Forms/Admin/AdminStoryEditForm.php index c85615b7fd..07ccef3f6d 100644 --- a/src/Goteo/Library/Forms/Admin/AdminStoryEditForm.php +++ b/src/Goteo/Library/Forms/Admin/AdminStoryEditForm.php @@ -28,7 +28,7 @@ class AdminStoryEditForm extends ProjectStoryForm { public function createForm() { $builder = $this->getBuilder(); - $options = $builder->getOptions(); + /** @var Stories $story */ $story = $this->getModel(); $data = $options['data']; parent::createForm(); @@ -147,26 +147,9 @@ public function save(FormInterface $form = null, $force_save = false) { $data = $form->getData(); $model = $this->getModel(); - if ($data['image'] && is_array($data['image'])) { - if ($data['image']['uploads'] && is_array($data['image']['uploads'])) - $model->image = $data['image']['uploads'][0]; - } - - if ($data['background_image'] && is_array($data['background_image'])) { - if ($data['background_image']['removed'] && $model->background_image == current($data['background_image']['removed'])->id) - $model->background_image = null; - - if ($data['background_image']['uploads'] && is_array($data['background_image']['uploads'])) - $model->background_image = $data['background_image']['uploads'][0]; - } - - if ($data['pool_image'] && is_array($data['pool_image'])) { - if ($data['pool_image']['removed'] && $model->pool_image == current($data['pool_image']['removed'])->id) - $model->pool_image = null; - - if ($data['pool_image']['uploads'] && is_array($data['pool_image']['uploads'])) - $model->pool_image = $data['pool_image']['uploads'][0]; - } + $model->image = $this->getProcessedImage($data['image'], $model->image); + $model->background_image = $this->getProcessedImage($data['background_image'], $model->background_image); + $model->pool_image = $this->getProcessedImage($data['pool_image'], $model->pool_image); unset($data['image']); unset($data['background_image']); @@ -181,10 +164,23 @@ public function save(FormInterface $form = null, $force_save = false) { if ($model->background_image && $data['background_image_credits_credits']) { $model->background_image->setCredits($data['background_image_credits']); } - + if(!$form->isValid()) throw new FormModelException(Text::get('form-has-errors')); return $this; } + private function getProcessedImage($imageData, $modelImage) + { + if ($imageData && is_array($imageData)) { + if ($imageData['removed'] && $modelImage == current($imageData['removed'])->id) { + return null; + } + if ($imageData['uploads'] && is_array($imageData['uploads'])) { + return $imageData['uploads'][0]; + } + } + + return $modelImage; + } } diff --git a/src/Goteo/Model/Stories.php b/src/Goteo/Model/Stories.php index 3274e72e79..d7fabe3267 100644 --- a/src/Goteo/Model/Stories.php +++ b/src/Goteo/Model/Stories.php @@ -400,7 +400,7 @@ public function getPoolImage() { } public function getBackgroundImage() { - if(!$this->BackgroundImageInstance instanceOf Image && $this->backgorund_image) { + if(!$this->BackgroundImageInstance instanceOf Image && $this->background_image) { $this->BackgroundImageInstance = new Image($this->background_image); } return $this->BackgroundImageInstance; From 6aa714b1e65d758e200ecd648ee04d2076026c38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Alberto=20Mart=C3=ADnez=20Gadea?= Date: Tue, 14 Sep 2021 18:22:13 +0200 Subject: [PATCH 11/20] Refactor to have a unique place where to handle additions, changes or removals of pictures on a form --- .../Library/Forms/AbstractFormProcessor.php | 12 +++++++++++ .../Library/Forms/Admin/AdminSectionForm.php | 8 +------- .../Forms/Admin/AdminStoryEditForm.php | 20 +++---------------- 3 files changed, 16 insertions(+), 24 deletions(-) diff --git a/src/Goteo/Library/Forms/AbstractFormProcessor.php b/src/Goteo/Library/Forms/AbstractFormProcessor.php index bb4ffd4951..4bc14eb422 100644 --- a/src/Goteo/Library/Forms/AbstractFormProcessor.php +++ b/src/Goteo/Library/Forms/AbstractFormProcessor.php @@ -132,4 +132,16 @@ public function save(FormInterface $form = null, $force_save = false) { return $this; } + + protected function getProcessedImage($imageData, &$modelImage, bool $isImageRequired = true) + { + if ($imageData && is_array($imageData)) { + if ($imageData['removed'] && $modelImage == current($imageData['removed'])->id && !$isImageRequired) { + $modelImage = null; + } + if ($imageData['uploads'] && is_array($imageData['uploads'])) { + $modelImage = $imageData['uploads'][0]; + } + } + } } diff --git a/src/Goteo/Library/Forms/Admin/AdminSectionForm.php b/src/Goteo/Library/Forms/Admin/AdminSectionForm.php index 0e859189d5..543609fa42 100644 --- a/src/Goteo/Library/Forms/Admin/AdminSectionForm.php +++ b/src/Goteo/Library/Forms/Admin/AdminSectionForm.php @@ -77,13 +77,7 @@ public function save(FormInterface $form = null, $force_save = false) { $data = $form->getData(); $model = $this->getModel(); - if ($data['main_image'] && is_array($data['main_image'])) { - if ($data['main_image']['removed'] && $model->main_image == current($data['main_image']['removed'])->id) - $model->main_image = null; - - if ($data['main_image']['uploads'] && is_array($data['main_image']['uploads'])) - $model->main_image = $data['main_image']['uploads'][0]; - } + $this->getProcessedImage($data['main_image'], $model->main_image, false); unset($data['main_image']); $model->rebuildData($data, array_keys($form->all())); diff --git a/src/Goteo/Library/Forms/Admin/AdminStoryEditForm.php b/src/Goteo/Library/Forms/Admin/AdminStoryEditForm.php index 07ccef3f6d..df5b3260c7 100644 --- a/src/Goteo/Library/Forms/Admin/AdminStoryEditForm.php +++ b/src/Goteo/Library/Forms/Admin/AdminStoryEditForm.php @@ -147,9 +147,9 @@ public function save(FormInterface $form = null, $force_save = false) { $data = $form->getData(); $model = $this->getModel(); - $model->image = $this->getProcessedImage($data['image'], $model->image); - $model->background_image = $this->getProcessedImage($data['background_image'], $model->background_image); - $model->pool_image = $this->getProcessedImage($data['pool_image'], $model->pool_image); + $this->getProcessedImage($data['image'], $model->image); + $this->getProcessedImage($data['background_image'], $model->background_image, false); + $this->getProcessedImage($data['pool_image'], $model->pool_image, false); unset($data['image']); unset($data['background_image']); @@ -169,18 +169,4 @@ public function save(FormInterface $form = null, $force_save = false) { return $this; } - - private function getProcessedImage($imageData, $modelImage) - { - if ($imageData && is_array($imageData)) { - if ($imageData['removed'] && $modelImage == current($imageData['removed'])->id) { - return null; - } - if ($imageData['uploads'] && is_array($imageData['uploads'])) { - return $imageData['uploads'][0]; - } - } - - return $modelImage; - } } From 0bcf87081abd363ac66ba0ee332a964d1131714c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Alberto=20Mart=C3=ADnez=20Gadea?= Date: Tue, 14 Sep 2021 18:31:32 +0200 Subject: [PATCH 12/20] Fix ProjectPostForm so it adds, edits and removes pictures correctly --- .../Library/Forms/Model/ProjectPostForm.php | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/Goteo/Library/Forms/Model/ProjectPostForm.php b/src/Goteo/Library/Forms/Model/ProjectPostForm.php index 66849e21e1..5bfc8acde1 100644 --- a/src/Goteo/Library/Forms/Model/ProjectPostForm.php +++ b/src/Goteo/Library/Forms/Model/ProjectPostForm.php @@ -50,7 +50,6 @@ public function createForm() { 'label' => 'regular-images', 'markdown_link' => 'text', 'accepted_files' => 'image/jpeg,image/gif,image/png', - 'url' => '/api/projects/' . $this->getOption('project')->id . '/images', 'constraints' => array( new Constraints\Count(array('max' => 10)), new Constraints\All(array( @@ -99,14 +98,14 @@ public function save(FormInterface $form = null, $force_save = false) { $data = $form->getData(); if(array_key_exists('tags', $data)) $data['tags'] = explode(',', $data['tags']); $post = $this->getModel(); - + $gallery = Image::getModelGallery('post', $post->id); $post->image = $gallery; - + if ($data['image'] && is_array($data['image'])) { if ($data['image']['removed']) { $removed_ids = array_column($data['image']['removed'], null, 'id'); - + if(is_array($post->image)) { foreach($post->image as $index => $img) { if(in_array($img->id, $removed_ids)) { @@ -123,15 +122,7 @@ public function save(FormInterface $form = null, $force_save = false) { } } - if ($data['header_image'] && is_array($data['header_image'])) { - - if (current($data['header_image']['removed'])->id == $post->header_image) - $post->header_image = null; - - if ($data['header_image']['uploads']) - $post->header_image = $data['header_image']['uploads'][0]; - } - // print_r($post);die; + $this->getProcessedImage($data['header_image'], $post->header_image, false); unset($data['image']); unset($data['header_image']); From b0a5b874aa6b91a93d631559be82277064eaba2e Mon Sep 17 00:00:00 2001 From: David Date: Thu, 16 Sep 2021 11:54:16 +0200 Subject: [PATCH 13/20] Feature: Project can share a url to a signature platform (#234) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add sign_url field to Project and to Project Forms * Make new project fields not required * Add signture button in project skin * Fix signature css * Fix css and target blank link Co-authored-by: Javier Carrillo Co-authored-by: David Igón --- .../project/partials/main_extra.php | 10 ++++ .../project/partials/responsive_meter.php | 17 ++++-- Resources/translations/ca/overview.yml | 3 + Resources/translations/en/overview.yml | 3 + Resources/translations/es/overview.yml | 5 +- .../20210915125443_goteo_project_sign_url.php | 57 +++++++++++++++++++ public/assets/sass/components/_buttons.scss | 11 ++-- public/assets/sass/project.scss | 3 + .../Forms/Model/ProjectOverviewForm.php | 16 ++++++ .../Model/ProjectTranslateOverviewForm.php | 13 +++++ src/Goteo/Model/Project.php | 11 +++- 11 files changed, 136 insertions(+), 13 deletions(-) create mode 100644 db/migrations/20210915125443_goteo_project_sign_url.php diff --git a/Resources/templates/responsive/project/partials/main_extra.php b/Resources/templates/responsive/project/partials/main_extra.php index 85c2c00da0..8e3f31a542 100644 --- a/Resources/templates/responsive/project/partials/main_extra.php +++ b/Resources/templates/responsive/project/partials/main_extra.php @@ -254,6 +254,16 @@ + sign_url): ?> + + + + + node !== $this->get_config('current_node')&&($project->nodeData->active)) : ?> -
@@ -215,16 +214,24 @@ -
+ - - - + + + +sign_url): ?> + + + diff --git a/Resources/translations/ca/overview.yml b/Resources/translations/ca/overview.yml index 756c43665a..acd0418311 100644 --- a/Resources/translations/ca/overview.yml +++ b/Resources/translations/ca/overview.yml @@ -81,3 +81,6 @@ overview-field-sustainability-model: 'Model de sostenibilitat' overview-field-sustainability-model-url: 'URL del teu business canvas' tooltip-project-sustainability-model: 'Explica el model de sostenibilitat del teu projecte' tooltip-project-sustainability-model-url: 'Afegeix una url amb teu business canvas' +overview-field-sign-url: "Url per signar" +overview-field-sign-url-action: "Text per fer una crida a signar" +overview-field-sign-url-help: "Aquest camp et permet afegir un salt cap a la teva pàgina de recollida de signatures" \ No newline at end of file diff --git a/Resources/translations/en/overview.yml b/Resources/translations/en/overview.yml index 05dc9365a4..a14ce09939 100644 --- a/Resources/translations/en/overview.yml +++ b/Resources/translations/en/overview.yml @@ -78,3 +78,6 @@ overview-field-sustainability-model: 'Sustainability plan' overview-field-sustainability-model-url: 'URL of your business canvas' tooltip-project-sustainability-model: 'Present a basic business plan to show how you will ensure project''s sustainability. The business plan should cover the key elements of the business canvas template and be no longer than two pages.' tooltip-project-sustainability-model-url: 'Add the URL of your business canvas' +overview-field-sign-url: "Singature Url" +overview-field-sign-url-action: "Text to call for signature" +overview-field-sign-url-help: "This field allows you to add a redirection to your project signature page" \ No newline at end of file diff --git a/Resources/translations/es/overview.yml b/Resources/translations/es/overview.yml index a0eef28245..8c050bac6c 100644 --- a/Resources/translations/es/overview.yml +++ b/Resources/translations/es/overview.yml @@ -83,4 +83,7 @@ overview-field-sustainability-model-url: 'URL de tu business canva' tooltip-project-sustainability-model: 'Explica el modelo de sostenibilidad de tu proyecto' tooltip-project-sustainability-model-url: 'Agrega una url con tu business canvas' tooltip-project-sdg: 'Elige los objetivos con los que cumple tu proyecto, intentando seleccionar un máximo de tres.' -tooltip-project-sdg-suggestion: 'A continuación te sugerimos algunos ODS que podrían encajar según el compromiso social seleccionado para tu proyecto, te recomendamos que consultes aquí su contenido especifico.

' \ No newline at end of file +tooltip-project-sdg-suggestion: 'A continuación te sugerimos algunos ODS que podrían encajar según el compromiso social seleccionado para tu proyecto, te recomendamos que consultes aquí su contenido especifico.

' +overview-field-sign-url: "Url de firma" +overview-field-sign-url-action: "Texto para llamar a firmar" +overview-field-sign-url-help: "Este campo permite añadir un salto en la campaña para tu página de firmas del proyecto" \ No newline at end of file diff --git a/db/migrations/20210915125443_goteo_project_sign_url.php b/db/migrations/20210915125443_goteo_project_sign_url.php new file mode 100644 index 0000000000..73d724aa7b --- /dev/null +++ b/db/migrations/20210915125443_goteo_project_sign_url.php @@ -0,0 +1,57 @@ + false, 'attr' => ['help' => Text::get('tooltip-project-social-description'), 'rows' => 8] ]) + + ->add('sign_url', UrlType::Class, [ + 'label' => 'overview-field-sign-url', + 'required' => false, + 'attr' => [ + 'pre-help' => Text::get('overview-field-sign-url-help') + ] + ]) + + ->add('sign_url_action', TextType::class, [ + 'label' => 'overview-field-sign-url-action', + 'required' => false + ]) ; return $this; diff --git a/src/Goteo/Library/Forms/Model/ProjectTranslateOverviewForm.php b/src/Goteo/Library/Forms/Model/ProjectTranslateOverviewForm.php index 28706fe946..158793e57b 100644 --- a/src/Goteo/Library/Forms/Model/ProjectTranslateOverviewForm.php +++ b/src/Goteo/Library/Forms/Model/ProjectTranslateOverviewForm.php @@ -19,6 +19,9 @@ use Goteo\Library\Text; use Goteo\Library\Forms\FormModelException; +use Goteo\Util\Form\Type\TextType; +use Goteo\Util\Form\Type\UrlType; + class ProjectTranslateOverviewForm extends AbstractFormProcessor implements FormProcessorInterface { public function createForm() { @@ -97,6 +100,16 @@ public function createForm() { 'required' => false, 'attr' => ['help' => $project->social_commitment_description, 'rows' => 8] ]) + ->add('sign_url', UrlType::Class, [ + 'label' => 'overview-field-sign-url', + 'attr' => [ + 'pre-help' => Text::get('overview-field-sign-url-help') + ] + ]) + + ->add('sign_url_action', TextType::class, [ + 'label' => 'overview-field-sign-url-action' + ]) ; return $this; } diff --git a/src/Goteo/Model/Project.php b/src/Goteo/Model/Project.php index a99292d754..746fad5a9e 100644 --- a/src/Goteo/Model/Project.php +++ b/src/Goteo/Model/Project.php @@ -181,8 +181,11 @@ class Project extends \Goteo\Core\Model { $one_round = 0, $help_cost = 0, $help_license= 0, - $callInstance = null // si está en una convocatoria + $callInstance = null, // si está en una convocatoria + // Data about political participation outside Goteo + $sign_url = '', + $sign_url_action = '' ; @@ -1711,7 +1714,9 @@ public function save (&$errors = array()) { 'analytics_id', 'facebook_pixel', 'social_commitment', - 'social_commitment_description' + 'social_commitment_description', + 'sign_url', + 'sign_url_action' ); try { @@ -1890,7 +1895,7 @@ public function save (&$errors = array()) { } public static function getLangFields() { - return ['name', 'subtitle', 'description', 'motivation', 'video', 'about', 'goal', 'related', 'reward', 'keywords', 'media', 'social_commitment_description']; + return ['name', 'subtitle', 'description', 'motivation', 'video', 'about', 'goal', 'related', 'reward', 'keywords', 'media', 'social_commitment_description', 'sign_url', 'sign_url_action']; } /* From 76c6889b12c6b4c858fd6cf48e09836d6cd224a5 Mon Sep 17 00:00:00 2001 From: David Date: Fri, 17 Sep 2021 15:30:53 +0200 Subject: [PATCH 14/20] make new project sign fields not required in translate overview form (#236) --- .../Library/Forms/Model/ProjectTranslateOverviewForm.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Goteo/Library/Forms/Model/ProjectTranslateOverviewForm.php b/src/Goteo/Library/Forms/Model/ProjectTranslateOverviewForm.php index 158793e57b..dde7dbc82a 100644 --- a/src/Goteo/Library/Forms/Model/ProjectTranslateOverviewForm.php +++ b/src/Goteo/Library/Forms/Model/ProjectTranslateOverviewForm.php @@ -102,13 +102,15 @@ public function createForm() { ]) ->add('sign_url', UrlType::Class, [ 'label' => 'overview-field-sign-url', + 'required' => false, 'attr' => [ 'pre-help' => Text::get('overview-field-sign-url-help') ] ]) ->add('sign_url_action', TextType::class, [ - 'label' => 'overview-field-sign-url-action' + 'label' => 'overview-field-sign-url-action', + 'required' => false ]) ; return $this; From 3a837005391a693a135a0368986672af27502ea4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Ig=C3=B3n?= Date: Mon, 20 Sep 2021 11:13:54 +0200 Subject: [PATCH 15/20] update composer.lock to symfony 2.8.52 --- composer.lock | 429 ++++++++++++++++++++++++++------------------------ 1 file changed, 220 insertions(+), 209 deletions(-) diff --git a/composer.lock b/composer.lock index ba11c35b98..de48ce2b74 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "b4888ccf787f3c619e158dc98dc24149", + "content-hash": "75d52f64daa1648e89d68f92632336ef", "packages": [ { "name": "amphp/amp", @@ -6478,16 +6478,16 @@ }, { "name": "symfony/class-loader", - "version": "v2.8.30", + "version": "v2.8.52", "source": { "type": "git", "url": "https://github.com/symfony/class-loader.git", - "reference": "5d7aa644f5c5c7828f97d2d2f4957d2a7ad3ab17" + "reference": "8194721a1e2768cfb95079581889c41eec7a5959" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/class-loader/zipball/5d7aa644f5c5c7828f97d2d2f4957d2a7ad3ab17", - "reference": "5d7aa644f5c5c7828f97d2d2f4957d2a7ad3ab17", + "url": "https://api.github.com/repos/symfony/class-loader/zipball/8194721a1e2768cfb95079581889c41eec7a5959", + "reference": "8194721a1e2768cfb95079581889c41eec7a5959", "shasum": "" }, "require": { @@ -6528,27 +6528,28 @@ "description": "Symfony ClassLoader Component", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/class-loader/tree/2.8" + "source": "https://github.com/symfony/class-loader/tree/v2.8.52" }, - "time": "2017-11-05T15:25:56+00:00" + "time": "2018-11-11T11:18:13+00:00" }, { "name": "symfony/config", - "version": "v2.8.30", + "version": "v2.8.52", "source": { "type": "git", "url": "https://github.com/symfony/config.git", - "reference": "f4f3f1d7090c464434bbbc3e8aa2b41149c59196" + "reference": "7dd5f5040dc04c118d057fb5886563963eb70011" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/config/zipball/f4f3f1d7090c464434bbbc3e8aa2b41149c59196", - "reference": "f4f3f1d7090c464434bbbc3e8aa2b41149c59196", + "url": "https://api.github.com/repos/symfony/config/zipball/7dd5f5040dc04c118d057fb5886563963eb70011", + "reference": "7dd5f5040dc04c118d057fb5886563963eb70011", "shasum": "" }, "require": { "php": ">=5.3.9", - "symfony/filesystem": "~2.3|~3.0.0" + "symfony/filesystem": "~2.3|~3.0.0", + "symfony/polyfill-ctype": "~1.8" }, "require-dev": { "symfony/yaml": "~2.7|~3.0.0" @@ -6587,22 +6588,22 @@ "description": "Symfony Config Component", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/config/tree/2.8" + "source": "https://github.com/symfony/config/tree/v2.8.50" }, - "time": "2017-11-07T11:56:23+00:00" + "time": "2018-11-26T09:38:12+00:00" }, { "name": "symfony/console", - "version": "v2.8.30", + "version": "v2.8.52", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "3eeaec6a5d9a253925139cd19eda07d882635d87" + "reference": "cbcf4b5e233af15cd2bbd50dee1ccc9b7927dc12" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/3eeaec6a5d9a253925139cd19eda07d882635d87", - "reference": "3eeaec6a5d9a253925139cd19eda07d882635d87", + "url": "https://api.github.com/repos/symfony/console/zipball/cbcf4b5e233af15cd2bbd50dee1ccc9b7927dc12", + "reference": "cbcf4b5e233af15cd2bbd50dee1ccc9b7927dc12", "shasum": "" }, "require": { @@ -6616,7 +6617,7 @@ "symfony/process": "~2.1|~3.0.0" }, "suggest": { - "psr/log": "For using the console logger", + "psr/log-implementation": "For using the console logger", "symfony/event-dispatcher": "", "symfony/process": "" }, @@ -6651,22 +6652,22 @@ "description": "Symfony Console Component", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/console/tree/2.8" + "source": "https://github.com/symfony/console/tree/v2.8.52" }, - "time": "2017-11-12T16:36:54+00:00" + "time": "2018-11-20T15:55:20+00:00" }, { "name": "symfony/css-selector", - "version": "v2.8.30", + "version": "v2.8.52", "source": { "type": "git", "url": "https://github.com/symfony/css-selector.git", - "reference": "b7b041487197fb6d803b7edbcaae7f00a793b1c4" + "reference": "7b1692e418d7ccac24c373528453bc90e42797de" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/css-selector/zipball/b7b041487197fb6d803b7edbcaae7f00a793b1c4", - "reference": "b7b041487197fb6d803b7edbcaae7f00a793b1c4", + "url": "https://api.github.com/repos/symfony/css-selector/zipball/7b1692e418d7ccac24c373528453bc90e42797de", + "reference": "7b1692e418d7ccac24c373528453bc90e42797de", "shasum": "" }, "require": { @@ -6691,14 +6692,14 @@ "MIT" ], "authors": [ - { - "name": "Jean-François Simon", - "email": "jeanfrancois.simon@sensiolabs.com" - }, { "name": "Fabien Potencier", "email": "fabien@symfony.com" }, + { + "name": "Jean-François Simon", + "email": "jeanfrancois.simon@sensiolabs.com" + }, { "name": "Symfony Community", "homepage": "https://symfony.com/contributors" @@ -6707,22 +6708,22 @@ "description": "Symfony CssSelector Component", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/css-selector/tree/2.8" + "source": "https://github.com/symfony/css-selector/tree/v2.8.52" }, - "time": "2017-11-05T15:25:56+00:00" + "time": "2018-11-11T11:18:13+00:00" }, { "name": "symfony/debug", - "version": "v2.8.30", + "version": "v2.8.52", "source": { "type": "git", "url": "https://github.com/symfony/debug.git", - "reference": "a0a29e9867debabdace779a20a9385c623a23bbd" + "reference": "74251c8d50dd3be7c4ce0c7b862497cdc641a5d0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/debug/zipball/a0a29e9867debabdace779a20a9385c623a23bbd", - "reference": "a0a29e9867debabdace779a20a9385c623a23bbd", + "url": "https://api.github.com/repos/symfony/debug/zipball/74251c8d50dd3be7c4ce0c7b862497cdc641a5d0", + "reference": "74251c8d50dd3be7c4ce0c7b862497cdc641a5d0", "shasum": "" }, "require": { @@ -6767,22 +6768,22 @@ "description": "Symfony Debug Component", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/debug/tree/2.8" + "source": "https://github.com/symfony/debug/tree/v2.8.50" }, - "time": "2017-10-24T13:48:52+00:00" + "time": "2018-11-11T11:18:13+00:00" }, { "name": "symfony/dependency-injection", - "version": "v2.8.30", + "version": "v2.8.52", "source": { "type": "git", "url": "https://github.com/symfony/dependency-injection.git", - "reference": "bc845111480786a9a68b39578ecdf27d9a6a44ec" + "reference": "c306198fee8f872a8f5f031e6e4f6f83086992d8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/dependency-injection/zipball/bc845111480786a9a68b39578ecdf27d9a6a44ec", - "reference": "bc845111480786a9a68b39578ecdf27d9a6a44ec", + "url": "https://api.github.com/repos/symfony/dependency-injection/zipball/c306198fee8f872a8f5f031e6e4f6f83086992d8", + "reference": "c306198fee8f872a8f5f031e6e4f6f83086992d8", "shasum": "" }, "require": { @@ -6835,24 +6836,25 @@ "support": { "source": "https://github.com/symfony/dependency-injection/tree/2.8" }, - "time": "2017-11-07T14:08:47+00:00" + "time": "2019-04-16T11:33:46+00:00" }, { "name": "symfony/dom-crawler", - "version": "v2.8.30", + "version": "v2.8.52", "source": { "type": "git", "url": "https://github.com/symfony/dom-crawler.git", - "reference": "eeb78092b5cc95b9e37017887da0e39f1530b8a8" + "reference": "2cdc7d3909eea6f982a6298d2e9ab7db01b6403c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/dom-crawler/zipball/eeb78092b5cc95b9e37017887da0e39f1530b8a8", - "reference": "eeb78092b5cc95b9e37017887da0e39f1530b8a8", + "url": "https://api.github.com/repos/symfony/dom-crawler/zipball/2cdc7d3909eea6f982a6298d2e9ab7db01b6403c", + "reference": "2cdc7d3909eea6f982a6298d2e9ab7db01b6403c", "shasum": "" }, "require": { "php": ">=5.3.9", + "symfony/polyfill-ctype": "~1.8", "symfony/polyfill-mbstring": "~1.0" }, "require-dev": { @@ -6892,9 +6894,9 @@ "description": "Symfony DomCrawler Component", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/dom-crawler/tree/2.8" + "source": "https://github.com/symfony/dom-crawler/tree/v2.8.50" }, - "time": "2017-11-05T15:25:56+00:00" + "time": "2018-11-24T22:30:19+00:00" }, { "name": "symfony/event-dispatcher", @@ -7013,16 +7015,16 @@ }, { "name": "symfony/finder", - "version": "v2.8.30", + "version": "v2.8.52", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "efeceae6a05a9b2fcb3391333f1d4a828ff44ab8" + "reference": "1444eac52273e345d9b95129bf914639305a9ba4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/efeceae6a05a9b2fcb3391333f1d4a828ff44ab8", - "reference": "efeceae6a05a9b2fcb3391333f1d4a828ff44ab8", + "url": "https://api.github.com/repos/symfony/finder/zipball/1444eac52273e345d9b95129bf914639305a9ba4", + "reference": "1444eac52273e345d9b95129bf914639305a9ba4", "shasum": "" }, "require": { @@ -7059,22 +7061,22 @@ "description": "Symfony Finder Component", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/finder/tree/2.8" + "source": "https://github.com/symfony/finder/tree/v2.8.50" }, - "time": "2017-11-05T15:25:56+00:00" + "time": "2018-11-11T11:18:13+00:00" }, { "name": "symfony/form", - "version": "v2.8.30", + "version": "v2.8.52", "source": { "type": "git", "url": "https://github.com/symfony/form.git", - "reference": "6b6e1e382faf45541fe17808daeea7f94221bba5" + "reference": "74382a47aa97496d181fbb598822fdfb9e1744e4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/form/zipball/6b6e1e382faf45541fe17808daeea7f94221bba5", - "reference": "6b6e1e382faf45541fe17808daeea7f94221bba5", + "url": "https://api.github.com/repos/symfony/form/zipball/74382a47aa97496d181fbb598822fdfb9e1744e4", + "reference": "74382a47aa97496d181fbb598822fdfb9e1744e4", "shasum": "" }, "require": { @@ -7082,6 +7084,7 @@ "symfony/event-dispatcher": "~2.1|~3.0.0", "symfony/intl": "~2.7.25|^2.8.18|~3.2.5", "symfony/options-resolver": "~2.6", + "symfony/polyfill-ctype": "~1.8", "symfony/polyfill-mbstring": "~1.0", "symfony/property-access": "~2.3|~3.0.0" }, @@ -7096,7 +7099,7 @@ "symfony/dependency-injection": "~2.7|~3.0.0", "symfony/http-foundation": "~2.2|~3.0.0", "symfony/http-kernel": "~2.4|~3.0.0", - "symfony/security-csrf": "~2.4|~3.0.0", + "symfony/security-csrf": "^2.8.31|^3.3.13", "symfony/translation": "^2.0.5|~3.0.0", "symfony/validator": "^2.8.18|~3.2.5" }, @@ -7137,22 +7140,22 @@ "description": "Symfony Form Component", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/form/tree/2.8" + "source": "https://github.com/symfony/form/tree/v2.8.52" }, - "time": "2017-11-13T18:11:59+00:00" + "time": "2018-12-06T11:12:46+00:00" }, { "name": "symfony/framework-bundle", - "version": "v2.8.30", + "version": "v2.8.52", "source": { "type": "git", "url": "https://github.com/symfony/framework-bundle.git", - "reference": "eac07ff5854977f701146fd03cf7f1470cc56109" + "reference": "07b6056e3a84861fa8a54c33f70b189cf18a1aad" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/framework-bundle/zipball/eac07ff5854977f701146fd03cf7f1470cc56109", - "reference": "eac07ff5854977f701146fd03cf7f1470cc56109", + "url": "https://api.github.com/repos/symfony/framework-bundle/zipball/07b6056e3a84861fa8a54c33f70b189cf18a1aad", + "reference": "07b6056e3a84861fa8a54c33f70b189cf18a1aad", "shasum": "" }, "require": { @@ -7163,7 +7166,7 @@ "symfony/asset": "~2.7|~3.0.0", "symfony/class-loader": "~2.1|~3.0.0", "symfony/config": "~2.8", - "symfony/dependency-injection": "~2.8", + "symfony/dependency-injection": "~2.8.41", "symfony/event-dispatcher": "~2.8|~3.0.0", "symfony/filesystem": "~2.3|~3.0.0", "symfony/finder": "^2.0.5|~3.0.0", @@ -7171,10 +7174,10 @@ "symfony/http-kernel": "^2.8.22", "symfony/polyfill-mbstring": "~1.0", "symfony/routing": "^2.8.17", - "symfony/security-core": "~2.6.13|~2.7.9|~2.8|~3.0.0", - "symfony/security-csrf": "~2.6|~3.0.0", + "symfony/security-core": "^2.8.41|^3.3.17", + "symfony/security-csrf": "^2.8.31|^3.3.13", "symfony/stopwatch": "~2.3|~3.0.0", - "symfony/templating": "~2.1|~3.0.0", + "symfony/templating": "~2.7|~3.0.0", "symfony/translation": "~2.8" }, "conflict": { @@ -7192,7 +7195,6 @@ "symfony/polyfill-intl-icu": "~1.0", "symfony/process": "^2.0.5|~3.0.0", "symfony/property-info": "~2.8|~3.0.0", - "symfony/security": "~2.6|~3.0.0", "symfony/validator": "~2.5|~3.0.0", "symfony/yaml": "^2.0.5|~3.0.0", "twig/twig": "~1.34|~2.4" @@ -7239,20 +7241,20 @@ "support": { "source": "https://github.com/symfony/framework-bundle/tree/2.8" }, - "time": "2017-11-10T18:59:36+00:00" + "time": "2019-04-16T10:01:35+00:00" }, { "name": "symfony/http-foundation", - "version": "v2.8.30", + "version": "v2.8.52", "source": { "type": "git", "url": "https://github.com/symfony/http-foundation.git", - "reference": "984fa8301472a2857b1b2397f7ad1126fb83b229" + "reference": "3929d9fe8148d17819ad0178c748b8d339420709" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-foundation/zipball/984fa8301472a2857b1b2397f7ad1126fb83b229", - "reference": "984fa8301472a2857b1b2397f7ad1126fb83b229", + "url": "https://api.github.com/repos/symfony/http-foundation/zipball/3929d9fe8148d17819ad0178c748b8d339420709", + "reference": "3929d9fe8148d17819ad0178c748b8d339420709", "shasum": "" }, "require": { @@ -7297,20 +7299,20 @@ "support": { "source": "https://github.com/symfony/http-foundation/tree/2.8" }, - "time": "2017-11-13T18:11:59+00:00" + "time": "2019-11-12T12:34:41+00:00" }, { "name": "symfony/http-kernel", - "version": "v2.8.30", + "version": "v2.8.52", "source": { "type": "git", "url": "https://github.com/symfony/http-kernel.git", - "reference": "0009e0092081d495d7349f1790f286d85d216f90" + "reference": "c3be27b8627cd5ee8dfa8d1b923982f618ec521c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-kernel/zipball/0009e0092081d495d7349f1790f286d85d216f90", - "reference": "0009e0092081d495d7349f1790f286d85d216f90", + "url": "https://api.github.com/repos/symfony/http-kernel/zipball/c3be27b8627cd5ee8dfa8d1b923982f618ec521c", + "reference": "c3be27b8627cd5ee8dfa8d1b923982f618ec521c", "shasum": "" }, "require": { @@ -7318,7 +7320,9 @@ "psr/log": "~1.0", "symfony/debug": "^2.6.2", "symfony/event-dispatcher": "^2.6.7|~3.0.0", - "symfony/http-foundation": "~2.7.36|~2.8.29|~3.1.6" + "symfony/http-foundation": "~2.7.36|~2.8.29|~3.1.6", + "symfony/polyfill-ctype": "~1.8", + "symfony/polyfill-php56": "~1.8" }, "conflict": { "symfony/config": "<2.7", @@ -7381,9 +7385,9 @@ "description": "Symfony HttpKernel Component", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/http-kernel/tree/2.8" + "source": "https://github.com/symfony/http-kernel/tree/v2.8.52" }, - "time": "2017-11-13T19:30:25+00:00" + "time": "2019-11-13T08:36:16+00:00" }, { "name": "symfony/intl", @@ -7597,6 +7601,85 @@ ], "time": "2021-02-19T12:13:01+00:00" }, + { + "name": "symfony/polyfill-ctype", + "version": "v1.23.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-ctype.git", + "reference": "46cd95797e9df938fdd2b03693b5fca5e64b01ce" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/46cd95797e9df938fdd2b03693b5fca5e64b01ce", + "reference": "46cd95797e9df938fdd2b03693b5fca5e64b01ce", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "suggest": { + "ext-ctype": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.23-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Ctype\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Gert de Pagter", + "email": "BackEndTea@gmail.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for ctype functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "ctype", + "polyfill", + "portable" + ], + "support": { + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.23.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-02-19T12:13:01+00:00" + }, { "name": "symfony/polyfill-intl-icu", "version": "v1.23.0", @@ -8111,16 +8194,16 @@ }, { "name": "symfony/process", - "version": "v2.8.30", + "version": "v2.8.52", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "d25449e031f600807949aab7cadbf267712f4eee" + "reference": "c3591a09c78639822b0b290d44edb69bf9f05dc8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/d25449e031f600807949aab7cadbf267712f4eee", - "reference": "d25449e031f600807949aab7cadbf267712f4eee", + "url": "https://api.github.com/repos/symfony/process/zipball/c3591a09c78639822b0b290d44edb69bf9f05dc8", + "reference": "c3591a09c78639822b0b290d44edb69bf9f05dc8", "shasum": "" }, "require": { @@ -8157,9 +8240,9 @@ "description": "Symfony Process Component", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/process/tree/2.8" + "source": "https://github.com/symfony/process/tree/v2.8.50" }, - "time": "2017-11-05T15:25:56+00:00" + "time": "2018-11-11T11:18:13+00:00" }, { "name": "symfony/property-access", @@ -8226,16 +8309,16 @@ }, { "name": "symfony/routing", - "version": "v2.8.30", + "version": "v2.8.52", "source": { "type": "git", "url": "https://github.com/symfony/routing.git", - "reference": "67bcd31a2f2fb1bf25cd8f4d4e0e2e2c91cccd5f" + "reference": "8b0df6869d1997baafff6a1541826eac5a03d067" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/routing/zipball/67bcd31a2f2fb1bf25cd8f4d4e0e2e2c91cccd5f", - "reference": "67bcd31a2f2fb1bf25cd8f4d4e0e2e2c91cccd5f", + "url": "https://api.github.com/repos/symfony/routing/zipball/8b0df6869d1997baafff6a1541826eac5a03d067", + "reference": "8b0df6869d1997baafff6a1541826eac5a03d067", "shasum": "" }, "require": { @@ -8246,7 +8329,6 @@ }, "require-dev": { "doctrine/annotations": "~1.0", - "doctrine/common": "~2.2", "psr/log": "~1.0", "symfony/config": "~2.7|~3.0.0", "symfony/expression-language": "~2.4|~3.0.0", @@ -8298,28 +8380,28 @@ "url" ], "support": { - "source": "https://github.com/symfony/routing/tree/2.8" + "source": "https://github.com/symfony/routing/tree/v2.8.50" }, - "time": "2017-11-07T14:08:47+00:00" + "time": "2018-11-20T15:55:20+00:00" }, { "name": "symfony/security", - "version": "v2.8.30", + "version": "v2.8.52", "source": { "type": "git", "url": "https://github.com/symfony/security.git", - "reference": "87807daa2b5192dd3573ade1353fa0b497582f2d" + "reference": "b9e9130cf348d4e85e37ba1d0d27263e33b97534" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/security/zipball/87807daa2b5192dd3573ade1353fa0b497582f2d", - "reference": "87807daa2b5192dd3573ade1353fa0b497582f2d", + "url": "https://api.github.com/repos/symfony/security/zipball/b9e9130cf348d4e85e37ba1d0d27263e33b97534", + "reference": "b9e9130cf348d4e85e37ba1d0d27263e33b97534", "shasum": "" }, "require": { "php": ">=5.3.9", "symfony/event-dispatcher": "~2.2|~3.0.0", - "symfony/http-foundation": "~2.1|~3.0.0", + "symfony/http-foundation": "^2.7.38|~3.3.13", "symfony/http-kernel": "~2.4|~3.0.0", "symfony/polyfill-php55": "~1.0", "symfony/polyfill-php56": "~1.0", @@ -8328,6 +8410,9 @@ "symfony/property-access": "~2.3|~3.0.0", "symfony/security-acl": "~2.7|~3.0.0" }, + "conflict": { + "symfony/http-foundation": "~2.8,<2.8.31" + }, "replace": { "symfony/security-core": "self.version", "symfony/security-csrf": "self.version", @@ -8361,7 +8446,10 @@ "Symfony\\Component\\Security\\": "" }, "exclude-from-classmap": [ - "/Tests/" + "/Core/Tests/", + "/Csrf/Tests/", + "/Guard/Tests/", + "/Http/Tests/" ] }, "notification-url": "https://packagist.org/downloads/", @@ -8383,7 +8471,7 @@ "support": { "source": "https://github.com/symfony/security/tree/2.8" }, - "time": "2017-11-07T14:08:47+00:00" + "time": "2019-04-16T10:01:12+00:00" }, { "name": "symfony/security-acl", @@ -8452,16 +8540,16 @@ }, { "name": "symfony/stopwatch", - "version": "v2.8.30", + "version": "v2.8.52", "source": { "type": "git", "url": "https://github.com/symfony/stopwatch.git", - "reference": "533bb9d7c2da1c6d2da163ecf0f22043ea98f59b" + "reference": "752586c80af8a85aeb74d1ae8202411c68836663" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/stopwatch/zipball/533bb9d7c2da1c6d2da163ecf0f22043ea98f59b", - "reference": "533bb9d7c2da1c6d2da163ecf0f22043ea98f59b", + "url": "https://api.github.com/repos/symfony/stopwatch/zipball/752586c80af8a85aeb74d1ae8202411c68836663", + "reference": "752586c80af8a85aeb74d1ae8202411c68836663", "shasum": "" }, "require": { @@ -8498,32 +8586,33 @@ "description": "Symfony Stopwatch Component", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/stopwatch/tree/2.8" + "source": "https://github.com/symfony/stopwatch/tree/v2.8.52" }, - "time": "2017-11-10T18:59:36+00:00" + "time": "2018-11-11T11:18:13+00:00" }, { "name": "symfony/templating", - "version": "v2.8.30", + "version": "v2.8.52", "source": { "type": "git", "url": "https://github.com/symfony/templating.git", - "reference": "ce8bd0f47706199383f082cf29b7a841a0dac682" + "reference": "7e64705b32855ebce87eff8cc5fbe6bf240c8e44" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/templating/zipball/ce8bd0f47706199383f082cf29b7a841a0dac682", - "reference": "ce8bd0f47706199383f082cf29b7a841a0dac682", + "url": "https://api.github.com/repos/symfony/templating/zipball/7e64705b32855ebce87eff8cc5fbe6bf240c8e44", + "reference": "7e64705b32855ebce87eff8cc5fbe6bf240c8e44", "shasum": "" }, "require": { - "php": ">=5.3.9" + "php": ">=5.3.9", + "symfony/polyfill-ctype": "~1.8" }, "require-dev": { "psr/log": "~1.0" }, "suggest": { - "psr/log": "For using debug logging in loaders" + "psr/log-implementation": "For using debug logging in loaders" }, "type": "library", "extra": { @@ -8556,22 +8645,22 @@ "description": "Symfony Templating Component", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/templating/tree/2.8" + "source": "https://github.com/symfony/templating/tree/v2.8.50" }, - "time": "2017-11-07T14:08:47+00:00" + "time": "2018-11-20T15:55:20+00:00" }, { "name": "symfony/translation", - "version": "v2.8.30", + "version": "v2.8.52", "source": { "type": "git", "url": "https://github.com/symfony/translation.git", - "reference": "0c63d56516c4c4c323228ca6348eadb7c91b1daf" + "reference": "fc58c2a19e56c29f5ba2736ec40d0119a0de2089" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/translation/zipball/0c63d56516c4c4c323228ca6348eadb7c91b1daf", - "reference": "0c63d56516c4c4c323228ca6348eadb7c91b1daf", + "url": "https://api.github.com/repos/symfony/translation/zipball/fc58c2a19e56c29f5ba2736ec40d0119a0de2089", + "reference": "fc58c2a19e56c29f5ba2736ec40d0119a0de2089", "shasum": "" }, "require": { @@ -8588,7 +8677,7 @@ "symfony/yaml": "~2.2|~3.0.0" }, "suggest": { - "psr/log": "To use logging capability in translator", + "psr/log-implementation": "To use logging capability in translator", "symfony/config": "", "symfony/yaml": "" }, @@ -8623,26 +8712,27 @@ "description": "Symfony Translation Component", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/translation/tree/2.8" + "source": "https://github.com/symfony/translation/tree/v2.8.50" }, - "time": "2017-11-07T14:08:47+00:00" + "time": "2018-11-24T21:16:41+00:00" }, { "name": "symfony/validator", - "version": "v2.8.30", + "version": "v2.8.52", "source": { "type": "git", "url": "https://github.com/symfony/validator.git", - "reference": "2c5ae6fa983b65c58cb7c4481cd54871a3bfd10a" + "reference": "d5d2090bba3139d8ddb79959fbf516e87238fe3a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/validator/zipball/2c5ae6fa983b65c58cb7c4481cd54871a3bfd10a", - "reference": "2c5ae6fa983b65c58cb7c4481cd54871a3bfd10a", + "url": "https://api.github.com/repos/symfony/validator/zipball/d5d2090bba3139d8ddb79959fbf516e87238fe3a", + "reference": "d5d2090bba3139d8ddb79959fbf516e87238fe3a", "shasum": "" }, "require": { "php": ">=5.3.9", + "symfony/polyfill-ctype": "~1.8", "symfony/polyfill-mbstring": "~1.0", "symfony/translation": "~2.4|~3.0.0" }, @@ -8699,9 +8789,9 @@ "description": "Symfony Validator Component", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/validator/tree/2.8" + "source": "https://github.com/symfony/validator/tree/v2.8.50" }, - "time": "2017-11-10T18:59:36+00:00" + "time": "2018-11-14T14:06:48+00:00" }, { "name": "symfony/yaml", @@ -10705,85 +10795,6 @@ }, "time": "2016-10-03T07:35:21+00:00" }, - { - "name": "symfony/polyfill-ctype", - "version": "v1.23.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "46cd95797e9df938fdd2b03693b5fca5e64b01ce" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/46cd95797e9df938fdd2b03693b5fca5e64b01ce", - "reference": "46cd95797e9df938fdd2b03693b5fca5e64b01ce", - "shasum": "" - }, - "require": { - "php": ">=7.1" - }, - "suggest": { - "ext-ctype": "For best performance" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "1.23-dev" - }, - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Ctype\\": "" - }, - "files": [ - "bootstrap.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Gert de Pagter", - "email": "BackEndTea@gmail.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill for ctype functions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "ctype", - "polyfill", - "portable" - ], - "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.23.0" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2021-02-19T12:13:01+00:00" - }, { "name": "theseer/tokenizer", "version": "1.1.3", From 15dbc568fcc4e1c3af3932b960957603c1d98b1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Alberto=20Mart=C3=ADnez=20Gadea?= Date: Mon, 20 Sep 2021 12:49:00 +0200 Subject: [PATCH 16/20] Fix AdminSdgEdit form in order to allow removing the Sdf icon --- src/Goteo/Library/Forms/AbstractFormProcessor.php | 2 +- src/Goteo/Library/Forms/Admin/AdminSdgEditForm.php | 9 +-------- src/Goteo/Library/Forms/Admin/AdminSectionForm.php | 2 +- src/Goteo/Library/Forms/Admin/AdminStoryEditForm.php | 6 +++--- src/Goteo/Library/Forms/Model/ProjectPostForm.php | 2 +- 5 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/Goteo/Library/Forms/AbstractFormProcessor.php b/src/Goteo/Library/Forms/AbstractFormProcessor.php index 4bc14eb422..b335d80dc6 100644 --- a/src/Goteo/Library/Forms/AbstractFormProcessor.php +++ b/src/Goteo/Library/Forms/AbstractFormProcessor.php @@ -133,7 +133,7 @@ public function save(FormInterface $form = null, $force_save = false) { return $this; } - protected function getProcessedImage($imageData, &$modelImage, bool $isImageRequired = true) + protected function processImageChange($imageData, &$modelImage, bool $isImageRequired = true) { if ($imageData && is_array($imageData)) { if ($imageData['removed'] && $modelImage == current($imageData['removed'])->id && !$isImageRequired) { diff --git a/src/Goteo/Library/Forms/Admin/AdminSdgEditForm.php b/src/Goteo/Library/Forms/Admin/AdminSdgEditForm.php index 6dccc5dab4..b8ed32f96e 100644 --- a/src/Goteo/Library/Forms/Admin/AdminSdgEditForm.php +++ b/src/Goteo/Library/Forms/Admin/AdminSdgEditForm.php @@ -74,7 +74,6 @@ public function createForm() { return $this; } - public function save(FormInterface $form = null, $force_save = false) { if(!$form) $form = $this->getBuilder()->getForm(); if(!$form->isValid() && !$force_save) throw new FormModelException(Text::get('form-has-errors')); @@ -82,13 +81,7 @@ public function save(FormInterface $form = null, $force_save = false) { $data = $form->getData(); $model = $this->getModel(); - if ($data['icon'] && is_array($data['icon'])) { - if ($data['icon']['removed'] && $model->icon->id == current($data['icon']['removed'])->id) - $model->icon = null; - - if ($data['icon']['uploads'] && is_array($data['icon']['uploads'])) - $model->icon = $data['icon']['uploads'][0]; - } + $this->processImageChange($data['icon'], $model->icon, false); unset($data['icon']); $model->rebuildData($data, array_keys($form->all())); diff --git a/src/Goteo/Library/Forms/Admin/AdminSectionForm.php b/src/Goteo/Library/Forms/Admin/AdminSectionForm.php index 543609fa42..eeb19a6bb7 100644 --- a/src/Goteo/Library/Forms/Admin/AdminSectionForm.php +++ b/src/Goteo/Library/Forms/Admin/AdminSectionForm.php @@ -77,7 +77,7 @@ public function save(FormInterface $form = null, $force_save = false) { $data = $form->getData(); $model = $this->getModel(); - $this->getProcessedImage($data['main_image'], $model->main_image, false); + $this->processImageChange($data['main_image'], $model->main_image, false); unset($data['main_image']); $model->rebuildData($data, array_keys($form->all())); diff --git a/src/Goteo/Library/Forms/Admin/AdminStoryEditForm.php b/src/Goteo/Library/Forms/Admin/AdminStoryEditForm.php index df5b3260c7..48eb22a016 100644 --- a/src/Goteo/Library/Forms/Admin/AdminStoryEditForm.php +++ b/src/Goteo/Library/Forms/Admin/AdminStoryEditForm.php @@ -147,9 +147,9 @@ public function save(FormInterface $form = null, $force_save = false) { $data = $form->getData(); $model = $this->getModel(); - $this->getProcessedImage($data['image'], $model->image); - $this->getProcessedImage($data['background_image'], $model->background_image, false); - $this->getProcessedImage($data['pool_image'], $model->pool_image, false); + $this->processImageChange($data['image'], $model->image); + $this->processImageChange($data['background_image'], $model->background_image, false); + $this->processImageChange($data['pool_image'], $model->pool_image, false); unset($data['image']); unset($data['background_image']); diff --git a/src/Goteo/Library/Forms/Model/ProjectPostForm.php b/src/Goteo/Library/Forms/Model/ProjectPostForm.php index 5bfc8acde1..65407acf85 100644 --- a/src/Goteo/Library/Forms/Model/ProjectPostForm.php +++ b/src/Goteo/Library/Forms/Model/ProjectPostForm.php @@ -122,7 +122,7 @@ public function save(FormInterface $form = null, $force_save = false) { } } - $this->getProcessedImage($data['header_image'], $post->header_image, false); + $this->processImageChange($data['header_image'], $post->header_image, false); unset($data['image']); unset($data['header_image']); From cafc6d6066098bb578c635ec92fc49663ce759ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Alberto=20Mart=C3=ADnez=20Gadea?= Date: Mon, 20 Sep 2021 13:20:17 +0200 Subject: [PATCH 17/20] Fix ProjectStory form, since it wasn't possible to upload, update or remove images to the ProjectStory --- .../Library/Forms/Model/ProjectStoryForm.php | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/src/Goteo/Library/Forms/Model/ProjectStoryForm.php b/src/Goteo/Library/Forms/Model/ProjectStoryForm.php index 5f0363e0c4..b7671dea8d 100644 --- a/src/Goteo/Library/Forms/Model/ProjectStoryForm.php +++ b/src/Goteo/Library/Forms/Model/ProjectStoryForm.php @@ -58,14 +58,12 @@ public function createForm() { ->add('image', 'dropfiles', [ 'label' => 'story-field-image', 'disabled' => $this->getReadonly(), - 'url' => '/api/projects/' . $project->id . '/images', 'required' => true, 'limit' => 1 ]) ->add('pool_image', 'dropfiles', [ 'label' => 'story-field-pool-image', 'disabled' => $this->getReadonly(), - 'url' => '/api/projects/' . $project->id . '/images', 'required' => false, 'limit' => 1 ]); @@ -82,22 +80,9 @@ public function save(FormInterface $form = null, $force_save = false) { $data = $form->getData(); $model = $this->getModel(); - - if ($data['image'] && is_array($data['image'])) { - if ($data['image']['removed'] && $model->image == current($data['image']['removed'])->id) - $model->image = null; - if ($data['image']['uploads'] && is_array($data['image']['uploads'])) - $model->image = $data['image']['uploads'][0]; - } - - if ($data['pool_image'] && is_array($data['pool_image'])) { - if ($data['pool_image']['removed'] && $model->pool_image == current($data['pool_image']['removed'])->id) - $model->pool_image = null; - - if ($data['pool_image']['uploads'] && is_array($data['pool_image']['uploads'])) - $model->pool_image = $data['pool_image']['uploads'][0]; - } + $this->processImageChange($data['image'], $model->image, true); + $this->processImageChange($data['pool_image'], $model->pool_image, false); unset($data['image']); unset($data['pool_image']); From c95abbbeff993c5b046d5031888054d64b585f1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Alberto=20Mart=C3=ADnez=20Gadea?= Date: Mon, 20 Sep 2021 17:04:12 +0200 Subject: [PATCH 18/20] Fix Questionnaire form so it saves the uploaded image ID as the answer for Dropfiles --- src/Goteo/Library/Forms/Model/QuestionnaireForm.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Goteo/Library/Forms/Model/QuestionnaireForm.php b/src/Goteo/Library/Forms/Model/QuestionnaireForm.php index ed3d4600cd..194dbadbf9 100644 --- a/src/Goteo/Library/Forms/Model/QuestionnaireForm.php +++ b/src/Goteo/Library/Forms/Model/QuestionnaireForm.php @@ -78,7 +78,7 @@ public function save(FormInterface $form = null, $force_save = false) } if(!$form->isValid() && !$force_save) { throw new FormModelException(Text::get('form-has-errors')); } - + $questionnaire = $this->getModel(); $questions = Question::getByQuestionnaire($questionnaire->id); $questions = array_column($questions, NULL, 'id'); @@ -101,13 +101,12 @@ public function save(FormInterface $form = null, $force_save = false) $type = $question->vars->type; if ($type != "choice") $answer->answer = $value; - - if ($type == "dropfiles") { + + if ($type == "dropfiles") { if($value[0] && $err = $value[0]->getUploadError()) { throw new FormModelException(Text::get('form-sent-error', $err)); } - $error = []; - $answer->answer = $value[0]->id; + $answer->answer = $value['uploads'][0]->id; } $answer->save(); From 7464eaee91a2887683db5a9dfa266138c5eb5f0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Ig=C3=B3n?= Date: Wed, 22 Sep 2021 16:22:14 +0200 Subject: [PATCH 19/20] fixes on questionnaire form to handle upload of documents instead of images --- .../Admin/ChannelCriteriaAdminController.php | 1 + .../Library/Forms/Model/QuestionnaireForm.php | 3 +- src/Goteo/Util/Form/Type/DropfilesType.php | 44 ++++++++++++++++--- 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/src/Goteo/Controller/Admin/ChannelCriteriaAdminController.php b/src/Goteo/Controller/Admin/ChannelCriteriaAdminController.php index 5019a6ec72..c47fcb2889 100644 --- a/src/Goteo/Controller/Admin/ChannelCriteriaAdminController.php +++ b/src/Goteo/Controller/Admin/ChannelCriteriaAdminController.php @@ -18,6 +18,7 @@ use Goteo\Application\Config; use Goteo\Application\Message; +use Goteo\Application\Exception\ModelNotFoundException; use Goteo\Library\Text; use Goteo\Model\Node; diff --git a/src/Goteo/Library/Forms/Model/QuestionnaireForm.php b/src/Goteo/Library/Forms/Model/QuestionnaireForm.php index 194dbadbf9..baa14d36fb 100644 --- a/src/Goteo/Library/Forms/Model/QuestionnaireForm.php +++ b/src/Goteo/Library/Forms/Model/QuestionnaireForm.php @@ -54,6 +54,7 @@ public function createForm() $question->vars->constraints = [ new Constraints\Count(['max' => 1]), ]; + $question->vars->type = 'document'; } if ($type == "choice") $question->vars->choices = array_column($question->getChoices(), 'option', 'id'); @@ -106,7 +107,7 @@ public function save(FormInterface $form = null, $force_save = false) if($value[0] && $err = $value[0]->getUploadError()) { throw new FormModelException(Text::get('form-sent-error', $err)); } - $answer->answer = $value['uploads'][0]->id; + $answer->answer = $value['uploads'][0]->name; } $answer->save(); diff --git a/src/Goteo/Util/Form/Type/DropfilesType.php b/src/Goteo/Util/Form/Type/DropfilesType.php index c32ceb74a9..ba15519b2a 100644 --- a/src/Goteo/Util/Form/Type/DropfilesType.php +++ b/src/Goteo/Util/Form/Type/DropfilesType.php @@ -11,6 +11,7 @@ namespace Goteo\Util\Form\Type; +use Goteo\Model\Contract\BaseDocument; use Goteo\Model\Image; use Goteo\Library\Text; @@ -53,8 +54,31 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'multiple' => true ]); - $builder->get('uploads') - ->addModelTransformer(new $options['upload_transformer']); + if ($options['type'] == 'document') { + $builder->get('uploads') + ->addModelTransformer(new CallbackTransformer( + function($image) { + return null; + }, + function($image) { + if(is_array($image)) { + foreach($image as $i => $img) { + if(!$img) continue; + + // Convert File to Image + if(!$img instanceOf BaseDocument) { + $image[$i] = new BaseDocument($img); + $image[$i]->save(); + } + } + } + return $image; + } + )); + } else { + $builder->get('uploads') + ->addModelTransformer(new $options['upload_transformer']); + } $builder->add('removed', CollectionType::class, [ 'entry_type' => TextType::class, @@ -73,7 +97,9 @@ function($image) { if (!$img) continue; if ($img = Image::get($img)) - $images[] = $img; + $images[] = $img; + else if ($img = BaseDocument::get($img)) + $images[] = $img; } return $images; @@ -82,13 +108,19 @@ function($image) { // General processing $builder->addViewTransformer(new CallbackTransformer( - function($image) { + function($image) use ($options) { if ($image instanceOf File) - $image = new Image($image); + if ($options['type'] == 'document') + $image = new BaseDocument($image); + else + $image = new Image($image); if (is_array($image)) { foreach($image as $i => $img) { if ($image instanceOf File) - $image = new Image($image); + if ($options['type'] == 'document') + $image = new BaseDocument($image); + else + $image = new Image($image); } } From 968a175efb6d19a9cec21532f07a971fa579a631 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Alberto=20Mart=C3=ADnez=20Gadea?= Date: Thu, 23 Sep 2021 13:21:38 +0200 Subject: [PATCH 20/20] Refactor on DropfilesType to include constant and to separate the different view elements added as a DropfilesType --- .../Library/Forms/Model/QuestionnaireForm.php | 3 +- src/Goteo/Util/Form/Type/DropfilesType.php | 58 ++++++++++++++----- 2 files changed, 47 insertions(+), 14 deletions(-) diff --git a/src/Goteo/Library/Forms/Model/QuestionnaireForm.php b/src/Goteo/Library/Forms/Model/QuestionnaireForm.php index baa14d36fb..dfdd93002d 100644 --- a/src/Goteo/Library/Forms/Model/QuestionnaireForm.php +++ b/src/Goteo/Library/Forms/Model/QuestionnaireForm.php @@ -12,6 +12,7 @@ namespace Goteo\Library\Forms\Model; use Goteo\Library\Forms\FormProcessorInterface; +use Goteo\Util\Form\Type\DropfilesType; use Symfony\Component\Form\FormInterface; use Goteo\Library\Forms\AbstractFormProcessor; use Goteo\Library\Text; @@ -54,7 +55,7 @@ public function createForm() $question->vars->constraints = [ new Constraints\Count(['max' => 1]), ]; - $question->vars->type = 'document'; + $question->vars->type = DropfilesType::TYPE_DOCUMENT; } if ($type == "choice") $question->vars->choices = array_column($question->getChoices(), 'option', 'id'); diff --git a/src/Goteo/Util/Form/Type/DropfilesType.php b/src/Goteo/Util/Form/Type/DropfilesType.php index ba15519b2a..63b72dd9e4 100644 --- a/src/Goteo/Util/Form/Type/DropfilesType.php +++ b/src/Goteo/Util/Form/Type/DropfilesType.php @@ -34,12 +34,25 @@ class DropfilesType extends FileType { + const TYPE_DOCUMENT = 'document'; + /** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { - // Current files + $this->addCurrentViewAndModelTransformer($options, $builder); + $this->addUploadsViewFileType($builder); + $this->addUploadsFieldModelTransformer($options, $builder); + $this->addRemovedViewCollectionType($builder); + $this->addRemovedFieldModelTransformer($builder); + $this->addViewTransformer($options, $builder); + } + + private function addCurrentViewAndModelTransformer( + array $options, + FormBuilderInterface $builder + ) { $builder->add('current', FileType::class, [ 'multiple' => true, 'data' => is_array($options['data']) ? $options['data'] : [$options['data']], @@ -48,14 +61,30 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->get('current') ->addModelTransformer(new $options['model_transformer']); + } - // New added files + private function addUploadsViewFileType(FormBuilderInterface $builder) + { $builder->add('uploads', FileType::class, [ 'multiple' => true ]); + } - if ($options['type'] == 'document') { + private function addUploadsFieldModelTransformer( + array $options, + FormBuilderInterface $builder + ) { + if ($options['type'] == DropfilesType::TYPE_DOCUMENT) { + $this->addUploadsTransformerAsDocument($builder); + } else { $builder->get('uploads') + ->addModelTransformer(new $options['upload_transformer']); + } + } + + private function addUploadsTransformerAsDocument(FormBuilderInterface $builder) + { + $builder->get('uploads') ->addModelTransformer(new CallbackTransformer( function($image) { return null; @@ -65,7 +94,6 @@ function($image) { foreach($image as $i => $img) { if(!$img) continue; - // Convert File to Image if(!$img instanceOf BaseDocument) { $image[$i] = new BaseDocument($img); $image[$i]->save(); @@ -75,16 +103,18 @@ function($image) { return $image; } )); - } else { - $builder->get('uploads') - ->addModelTransformer(new $options['upload_transformer']); - } + } + private function addRemovedViewCollectionType(FormBuilderInterface $builder) + { $builder->add('removed', CollectionType::class, [ 'entry_type' => TextType::class, 'allow_add' => true ]); + } + private function addRemovedFieldModelTransformer(FormBuilderInterface $builder) + { $builder->get('removed') ->addModelTransformer( new CallbackTransformer( function($image) { @@ -105,8 +135,12 @@ function($image) { return $images; } )); + } - // General processing + private function addViewTransformer( + array $options, + FormBuilderInterface $builder + ) { $builder->addViewTransformer(new CallbackTransformer( function($image) use ($options) { if ($image instanceOf File) @@ -127,8 +161,6 @@ function($image) use ($options) { return is_array($image) ? $image : [$image]; }, function ($image) { - // Sum current + uploads - $img = []; $img = isset($image['current']) && is_array($image['current']) ? $image['current'] : []; if($image['uploads']) { if(is_array($image['uploads'])) { @@ -139,8 +171,8 @@ function ($image) { $img = array_merge($img, ['removed' => $image['removed']] ); } return $img; - // return null; - })); + }) + ); } /**