From ac25ae514c1158de13592a8ff8fdd7adc2a82e42 Mon Sep 17 00:00:00 2001 From: David Date: Mon, 27 Sep 2021 13:12:29 +0200 Subject: [PATCH] Fix dropfiles type after symfony BC in 2.8.31 (#199) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add deployer script * update symfony to ^2.8 * remove url from dropfiles in forms * make uploadimagetransformer save image so that it updates the file name * some fixes * fix user profile form to save avatar * rework of dropfiles type and js * rework of all forms with dropfiles * small fixes in model transformers * refactor subdomain processing and add test to it (#205) * fix/var subs (#215) * refactor subdomain processing and add test to it (#204) * refactor subdomain processing and add test to it * add other envs to deployment * make config process deep ENV substitution * fix/var subs (#216) * refactor subdomain processing and add test to it (#204) * refactor subdomain processing and add test to it * add other envs to deployment * make config process deep ENV substitution * fix namespace * update oauth library for linkedin * fix/linkedin (#227) * Update live base code with latest fixes (#218) * add project name to project translate overview * fix route of poster in project dashboard * Upgraded Symfony packages to v2.8.30 (last working version) * Fix call to render method since it was renamed (cherry picked from commit 5d93afab554e8211c59ed1f1ab21a2eb4ac75ad2) * add composer.lock * restore a early die if misconfiguration * Updated Dockerfile to use an Ubuntu image that's not deprecated (#181) * Updated Dockerfile to use an Ubuntu image that's not deprecated * Removed Docker image based on date in favour of one that won't change * fix/composer lock (#185) * Fix call to render method since it was renamed (cherry picked from commit 5d93afab554e8211c59ed1f1ab21a2eb4ac75ad2) * remove lock to force deploy Co-authored-by: Carlos Alberto Martínez Gadea * Twitter card meta description fix * change projects to be shown in map when a matcher is selected to use node configuration if available * improve filters in discover and fix ajax query (cherry picked from commit 0432ebb325b99d68c42e300493fca974a6142c0f) * fix use of query parameters when they are not being used * fix project filters in discover and use of inner joins in project get list function * Add matcher completed status * Fix icons size * Fix user leave exceptions * remove comment on sql project name selects * fix missing ) on fallback lang in Project published * fix on config test yaml with env parameters * add entries in docker settings to be used in yaml test * change in config test to use real yaml instead of inserting env variables * fix removing log in public index since its done via plugin Co-authored-by: Carlos Alberto Martínez Gadea Co-authored-by: Ivan Vergés Co-authored-by: Javier Co-authored-by: Javier Carrillo * specify region before connecting to s3 (#219) * fix on deprecated parse_str without variable (#221) * make loggin resilient to Gelf updates failures (#225) * make loggin resilient to Gelf updates failures * ignore redundant exception thrown * update oauth library for linkedin Co-authored-by: David Co-authored-by: Carlos Alberto Martínez Gadea Co-authored-by: Javier Co-authored-by: Javier Carrillo * update up to a working commit * fix linkedin call * remove unnecessary comments from Forms * Fix AdminStoryEdit form so it can properly add, save and remove the 3 types of images it has * Refactor to have a unique place where to handle additions, changes or removals of pictures on a form * Fix ProjectPostForm so it adds, edits and removes pictures correctly * add sign_url field to Project and to Project Forms * make new project fields not required * Add signture button in project skin * [STAGING deploy] Feature: Project can share a url to a signature platform (#235) * fix on deprecated implode call (#229) * update oauth library for linkedin (#226) * add deployer script * refactor subdomain processing and add test to it (#205) * fix/var subs (#215) * refactor subdomain processing and add test to it (#204) * refactor subdomain processing and add test to it * add other envs to deployment * make config process deep ENV substitution * fix/var subs (#216) * refactor subdomain processing and add test to it (#204) * refactor subdomain processing and add test to it * add other envs to deployment * make config process deep ENV substitution * fix namespace * update oauth library for linkedin * update up to a working commit * fix linkedin call * remove orphan location stats (#230) * fix on deprecated implode call in Check (#233) * add sign_url field to Project and to Project Forms * make new project fields not required * Add signture button in project skin Co-authored-by: Ivan Vergés Co-authored-by: Javier Carrillo * Fix signature css * Fix css and target blank link * update composer.lock to symfony 2.8.52 * Fix AdminSdgEdit form in order to allow removing the Sdf icon * Fix ProjectStory form, since it wasn't possible to upload, update or remove images to the ProjectStory * Fix Questionnaire form so it saves the uploaded image ID as the answer for Dropfiles * fixes on questionnaire form to handle upload of documents instead of images * Refactor on DropfilesType to include constant and to separate the different view elements added as a DropfilesType Co-authored-by: Ivan Vergés Co-authored-by: Carlos Alberto Martínez Gadea Co-authored-by: Javier Co-authored-by: Javier Carrillo --- .../forms/bootstrap/dropfiles_widget.html.php | 8 +- composer.json | 38 +- composer.lock | 429 +++++++++--------- public/assets/js/forms.js | 9 +- .../Admin/ChannelCriteriaAdminController.php | 1 + .../Library/Forms/AbstractFormProcessor.php | 12 + .../Admin/AdminChannelResourceEditForm.php | 16 +- .../Forms/Admin/AdminFootprintEditForm.php | 23 +- .../Library/Forms/Admin/AdminPostEditForm.php | 7 +- .../Library/Forms/Admin/AdminProgramForm.php | 26 +- .../Library/Forms/Admin/AdminSdgEditForm.php | 17 +- .../Library/Forms/Admin/AdminSectionForm.php | 20 +- .../Admin/AdminSocialCommitmentEditForm.php | 22 +- .../Forms/Admin/AdminSphereEditForm.php | 21 +- .../Forms/Admin/AdminStoryEditForm.php | 35 +- .../Forms/Admin/AdminWorkshopEditForm.php | 17 +- .../Library/Forms/Model/ProjectPostForm.php | 43 +- .../Library/Forms/Model/ProjectStoryForm.php | 35 +- .../Model/ProjectTranslateOverviewForm.php | 3 +- .../Forms/Model/QuestionnaireCreateForm.php | 1 - .../Library/Forms/Model/QuestionnaireForm.php | 16 +- .../Library/Forms/Model/UserProfileForm.php | 24 +- src/Goteo/Model/Node/NodeProgram.php | 9 - src/Goteo/Model/Node/NodeResource.php | 6 - src/Goteo/Model/Questionnaire/Answer.php | 10 +- src/Goteo/Model/Stories.php | 6 +- src/Goteo/Model/User.php | 4 + src/Goteo/Model/Workshop.php | 7 - .../UploadImageTransformer.php | 1 + src/Goteo/Util/Form/Type/DropfilesType.php | 123 ++++- .../Transformer/ChannelProgramTransformer.php | 7 + .../ChannelResourceTransformer.php | 9 +- 32 files changed, 572 insertions(+), 433 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/composer.json b/composer.json index f5c2dbc454..1d344e8c4d 100644 --- a/composer.json +++ b/composer.json @@ -19,25 +19,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", diff --git a/composer.lock b/composer.lock index dd8e2aedb4..bf46612301 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": "00cca74d32e54cdeee20196e8cabbb36", + "content-hash": "75d52f64daa1648e89d68f92632336ef", "packages": [ { "name": "amphp/amp", @@ -6558,16 +6558,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": { @@ -6608,27 +6608,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" @@ -6667,22 +6668,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": { @@ -6696,7 +6697,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": "" }, @@ -6731,22 +6732,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": { @@ -6771,14 +6772,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" @@ -6787,22 +6788,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": { @@ -6847,22 +6848,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": { @@ -6915,24 +6916,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": { @@ -6972,9 +6974,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", @@ -7093,16 +7095,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": { @@ -7139,22 +7141,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": { @@ -7162,6 +7164,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" }, @@ -7176,7 +7179,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" }, @@ -7217,22 +7220,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": { @@ -7243,7 +7246,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", @@ -7251,10 +7254,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": { @@ -7272,7 +7275,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" @@ -7319,20 +7321,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": { @@ -7377,20 +7379,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": { @@ -7398,7 +7400,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", @@ -7461,9 +7465,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", @@ -7677,6 +7681,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", @@ -8191,16 +8274,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": { @@ -8237,9 +8320,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", @@ -8306,16 +8389,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": { @@ -8326,7 +8409,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", @@ -8378,28 +8460,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", @@ -8408,6 +8490,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", @@ -8441,7 +8526,10 @@ "Symfony\\Component\\Security\\": "" }, "exclude-from-classmap": [ - "/Tests/" + "/Core/Tests/", + "/Csrf/Tests/", + "/Guard/Tests/", + "/Http/Tests/" ] }, "notification-url": "https://packagist.org/downloads/", @@ -8463,7 +8551,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", @@ -8532,16 +8620,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": { @@ -8578,32 +8666,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": { @@ -8636,22 +8725,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": { @@ -8668,7 +8757,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": "" }, @@ -8703,26 +8792,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" }, @@ -8779,9 +8869,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", @@ -10853,85 +10943,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.2.0", 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/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/AbstractFormProcessor.php b/src/Goteo/Library/Forms/AbstractFormProcessor.php index bb4ffd4951..b335d80dc6 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 processImageChange($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/AdminChannelResourceEditForm.php b/src/Goteo/Library/Forms/Admin/AdminChannelResourceEditForm.php index b29ac921bd..5e88cb69dd 100644 --- a/src/Goteo/Library/Forms/Admin/AdminChannelResourceEditForm.php +++ b/src/Goteo/Library/Forms/Admin/AdminChannelResourceEditForm.php @@ -64,11 +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', - 'url' => '/api/channel-resources/images', - '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', @@ -98,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 1f91d8d3bb..442e1e7062 100644 --- a/src/Goteo/Library/Forms/Admin/AdminFootprintEditForm.php +++ b/src/Goteo/Library/Forms/Admin/AdminFootprintEditForm.php @@ -57,10 +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)) - ), 'attr' => [ 'help' => Text::get('admin-categories-if-empty-then-asset', '') ] @@ -109,15 +105,20 @@ 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 = []; if (!$model->save($errors)) { diff --git a/src/Goteo/Library/Forms/Admin/AdminPostEditForm.php b/src/Goteo/Library/Forms/Admin/AdminPostEditForm.php index 0f8d170f80..7755b3b71f 100644 --- a/src/Goteo/Library/Forms/Admin/AdminPostEditForm.php +++ b/src/Goteo/Library/Forms/Admin/AdminPostEditForm.php @@ -48,11 +48,7 @@ public function createForm() { 'required' => false, '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)) - ) + 'accepted_files' => 'image/jpeg,image/gif,image/png' )) ->add('author', 'typeahead', [ 'label' => 'regular-author', @@ -140,7 +136,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..6ccd64066b 100644 --- a/src/Goteo/Library/Forms/Admin/AdminProgramForm.php +++ b/src/Goteo/Library/Forms/Admin/AdminProgramForm.php @@ -54,12 +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', - 'url' => '/api/channels/images', - '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(), @@ -95,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 f5bc1c39d2..b8ed32f96e 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,10 +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', - 'url' => '/api/categories/images', - 'constraints' => array( - new Constraints\Count(array('max' => 1)) - ), 'attr' => [ 'help' => Text::get('admin-categories-if-empty-then-asset', '') ] @@ -79,20 +74,16 @@ 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')); $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(); + + $this->processImageChange($data['icon'], $model->icon, false); + + 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 9e31c0bf27..eeb19a6bb7 100644 --- a/src/Goteo/Library/Forms/Admin/AdminSectionForm.php +++ b/src/Goteo/Library/Forms/Admin/AdminSectionForm.php @@ -58,13 +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)) - ), + 'accepted_files' => 'image/jpeg,image/png,image/svg+xml' )) ; @@ -79,15 +75,11 @@ 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(); - + + $this->processImageChange($data['main_image'], $model->main_image, false); + + 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 5b58993f9b..6508facd70 100644 --- a/src/Goteo/Library/Forms/Admin/AdminSocialCommitmentEditForm.php +++ b/src/Goteo/Library/Forms/Admin/AdminSocialCommitmentEditForm.php @@ -60,10 +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)) - ), 'attr' => [ 'help' => Text::get('admin-categories-if-empty-then-asset', '') ] @@ -101,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 2e6813ad4e..a71853a9e4 100644 --- a/src/Goteo/Library/Forms/Admin/AdminSphereEditForm.php +++ b/src/Goteo/Library/Forms/Admin/AdminSphereEditForm.php @@ -50,10 +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)) - ), 'attr' => [ 'help' => Text::get('admin-categories-if-empty-then-asset', '') ] @@ -85,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 276cb431bd..48eb22a016 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(); @@ -36,37 +36,23 @@ public function createForm() { ->add('image', 'dropfiles', [ 'label' => 'story-field-image', 'disabled' => $this->getReadonly(), - 'url' => '/api/stories/images', '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(), - 'url' => '/api/stories/images', '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(), - 'url' => '/api/stories/images', 'required' => false, - 'limit' => 1, - 'constraints' => [ - new Constraints\Count(['max' => 1]), - ] - + 'limit' => 1 ]) ->add('background_image_credits', 'text', array( 'label' => 'story-field-background-image-credits', @@ -160,6 +146,14 @@ public function save(FormInterface $form = null, $force_save = false) { $data = $form->getData(); $model = $this->getModel(); + + $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']); + unset($data['pool_image']); $model->rebuildData($data, array_keys($form->all())); $errors = []; @@ -167,13 +161,12 @@ 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']); } - + if(!$form->isValid()) throw new FormModelException(Text::get('form-has-errors')); return $this; } - } diff --git a/src/Goteo/Library/Forms/Admin/AdminWorkshopEditForm.php b/src/Goteo/Library/Forms/Admin/AdminWorkshopEditForm.php index cce789b12b..04b20348c0 100644 --- a/src/Goteo/Library/Forms/Admin/AdminWorkshopEditForm.php +++ b/src/Goteo/Library/Forms/Admin/AdminWorkshopEditForm.php @@ -100,11 +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', - 'url' => '/api/workshops/images', - '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', @@ -174,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..65407acf85 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,29 +98,35 @@ 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']); + } } - // print_r($post);die; + + $this->processImageChange($data['header_image'], $post->header_image, false); + + 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')) { diff --git a/src/Goteo/Library/Forms/Model/ProjectStoryForm.php b/src/Goteo/Library/Forms/Model/ProjectStoryForm.php index 4252aab390..b7671dea8d 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 @@ -59,27 +58,39 @@ public function createForm() { ->add('image', 'dropfiles', [ 'label' => 'story-field-image', '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(); + $this->processImageChange($data['image'], $model->image, true); + $this->processImageChange($data['pool_image'], $model->pool_image, false); + + 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/ProjectTranslateOverviewForm.php b/src/Goteo/Library/Forms/Model/ProjectTranslateOverviewForm.php index dde7dbc82a..3c6c43bcfa 100644 --- a/src/Goteo/Library/Forms/Model/ProjectTranslateOverviewForm.php +++ b/src/Goteo/Library/Forms/Model/ProjectTranslateOverviewForm.php @@ -53,7 +53,8 @@ public function createForm() { 'label' => 'overview-field-media', 'disabled' => $this->getReadonly(), 'required' => false, - 'attr' => ['help' => $project->media] + + 'attr' => ['help' => $project->media] ]) ->add('motivation', 'markdown', [ 'label' => 'overview-field-motivation', diff --git a/src/Goteo/Library/Forms/Model/QuestionnaireCreateForm.php b/src/Goteo/Library/Forms/Model/QuestionnaireCreateForm.php index 13014c14ff..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 ef4a1becc3..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; @@ -28,9 +29,6 @@ class QuestionnaireForm extends AbstractFormProcessor implements FormProcessorIn public function getConstraints($field) { $constraints = []; - if($this->getFullValidation()) { - // $constraints[] = new Constraints\NotBlank(); - } return $constraints; } @@ -53,11 +51,11 @@ 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]), ]; + $question->vars->type = DropfilesType::TYPE_DOCUMENT; } if ($type == "choice") $question->vars->choices = array_column($question->getChoices(), 'option', 'id'); @@ -82,11 +80,10 @@ 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'); - // $data = $form->getData();] $index = 0; if ($answers = Answer::getList(['project' => $this->model->project_id, 'questionnaire' => $questionnaire->id])) @@ -106,13 +103,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]->name; } $answer->save(); diff --git a/src/Goteo/Library/Forms/Model/UserProfileForm.php b/src/Goteo/Library/Forms/Model/UserProfileForm.php index 74b55eb54b..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', [ @@ -107,7 +108,6 @@ public function createForm() { 'label' => 'profile-fields-image-title', 'constraints' => $this->getConstraints('avatar'), 'disabled' => $this->getReadonly(), - 'url' => '/api/users/' . $user->id . '/avatar', 'required' => false ]) ; @@ -257,15 +257,23 @@ public function save(FormInterface $form = null, $force_save = false) { $user = $this->getModel(); // var_dump($data);die; // Process main image - if(is_array($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)); + if(is_array($data['avatar']) && !empty($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)); + } + } } - // $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/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/Model/Stories.php b/src/Goteo/Model/Stories.php index a114810670..d7fabe3267 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->background_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 1fa8c32b40..da8ec29a1c 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) 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(); } } } diff --git a/src/Goteo/Util/Form/Type/DropfilesType.php b/src/Goteo/Util/Form/Type/DropfilesType.php index 501d922f83..63b72dd9e4 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; @@ -19,9 +20,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; /** * @@ -31,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']], @@ -45,33 +61,118 @@ 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 ]); + } + 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 $options['upload_transformer']); + ->addModelTransformer(new CallbackTransformer( + function($image) { + return null; + }, + function($image) { + if(is_array($image)) { + foreach($image as $i => $img) { + if(!$img) continue; - // General processing + if(!$img instanceOf BaseDocument) { + $image[$i] = new BaseDocument($img); + $image[$i]->save(); + } + } + } + return $image; + } + )); + } + + 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) { + return $image; + }, + function($image) { + $images = []; + + foreach($image as $img) { + if (!$img) + continue; + if ($img = Image::get($img)) + $images[] = $img; + else if ($img = BaseDocument::get($img)) + $images[] = $img; + } + + return $images; + } + )); + } + + private function addViewTransformer( + array $options, + FormBuilderInterface $builder + ) { $builder->addViewTransformer(new CallbackTransformer( - function($image) { + function($image) use ($options) { + if ($image instanceOf File) + 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) + if ($options['type'] == 'document') + $image = new BaseDocument($image); + else + $image = new Image($image); + } + } + return is_array($image) ? $image : [$image]; }, function ($image) { - // var_dump($image);die; - // Sum current + uploads $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; - })); + }) + ); } /** diff --git a/src/Goteo/Util/ModelNormalizer/Transformer/ChannelProgramTransformer.php b/src/Goteo/Util/ModelNormalizer/Transformer/ChannelProgramTransformer.php index 279e89a523..b702b260a4 100644 --- a/src/Goteo/Util/ModelNormalizer/Transformer/ChannelProgramTransformer.php +++ b/src/Goteo/Util/ModelNormalizer/Transformer/ChannelProgramTransformer.php @@ -23,6 +23,13 @@ public function getDescription(){ return $this->model->description; } + public function getImage() { + if ($this->model->header) + return $this->model->getHeader()->getLink(64,64); + + return null; + } + public function getActions() { if(!$u = $this->getUser()) return []; $ret = ['edit' => '/admin/channelprogram/'. $this->model->node_id . '/edit/' . $this->model->id]; 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 [];