From 11a55bbd430cfb2594b17ae4b6a9c4721145c272 Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Wed, 12 Jun 2013 20:06:49 +0200 Subject: [PATCH] Add labels to databoxes --- lib/Alchemy/Phrasea/Application.php | 1 + lib/Alchemy/Phrasea/Command/RecordAdd.php | 2 +- .../Phrasea/Controller/Admin/Databox.php | 42 +++++- .../Phrasea/Controller/Admin/Databoxes.php | 2 +- lib/Alchemy/Phrasea/Controller/Prod/TOU.php | 2 +- .../Controller/Thesaurus/Thesaurus.php | 4 +- .../Phrasea/Controller/Thesaurus/Xmlhttp.php | 4 +- lib/Alchemy/Phrasea/Out/Module/PDF.php | 2 +- .../SphinxSearch/ConfigurationPanel.php | 4 +- lib/classes/API/V1/adapter.php | 11 +- lib/classes/appbox.php | 23 +-- lib/classes/databox.php | 138 +++++++++++++++--- lib/classes/databox/cgu.php | 2 +- lib/classes/deprecated/inscript.api.php | 4 +- lib/classes/module/console/fieldsList.php | 2 +- .../console/sphinxGenerateSuggestion.php | 2 +- lib/classes/module/console/systemExport.php | 2 +- lib/classes/module/report.php | 2 +- lib/classes/module/report/dashboard.php | 6 +- lib/classes/phrasea.php | 47 ++++-- lib/classes/task/period/RecordMover.php | 2 +- lib/classes/task/period/archive.php | 2 +- lib/classes/task/period/ftp.php | 6 +- lib/conf.d/bases_structure.xml | 45 ++++-- templates/web/account/access.html.twig | 14 +- templates/web/admin/connected-users.html.twig | 2 +- templates/web/admin/databox/databox.html.twig | 29 +++- templates/web/admin/editusers.html.twig | 2 +- templates/web/admin/editusers_masks.html.twig | 2 +- .../web/admin/editusers_quotas.html.twig | 2 +- .../web/admin/editusers_timelimit.html.twig | 2 +- .../web/admin/publications/fiche.html.twig | 2 +- .../web/admin/publications/list.html.twig | 4 +- templates/web/admin/tree.html.twig | 2 +- templates/web/client/index.html.twig | 6 +- templates/web/prod/Story/Create.html.twig | 2 +- .../prod/actions/Download/prepare.html.twig | 2 +- .../web/prod/actions/Property/index.html.twig | 2 +- .../web/prod/actions/Property/type.html.twig | 2 +- .../web/prod/actions/edit_default.html.twig | 2 +- templates/web/prod/index.html.twig | 6 +- .../web/prod/upload/upload-flash.html.twig | 2 +- templates/web/prod/upload/upload.html.twig | 2 +- .../report/ajax_dashboard_content.html.twig | 2 +- .../web/report/ajax_report_content.html.twig | 2 +- templates/web/report/chart.html.twig | 4 +- .../Tests/Phrasea/Application/ApiAbstract.php | 6 + .../Phrasea/Controller/Admin/DataboxTest.php | 36 ++++- tests/classes/databoxTest.php | 41 ++++++ 49 files changed, 406 insertions(+), 129 deletions(-) diff --git a/lib/Alchemy/Phrasea/Application.php b/lib/Alchemy/Phrasea/Application.php index f05df5d72a..7d0f228dca 100644 --- a/lib/Alchemy/Phrasea/Application.php +++ b/lib/Alchemy/Phrasea/Application.php @@ -532,6 +532,7 @@ class Application extends SilexApplication $twig->addFilter('min', new \Twig_Filter_Function('min')); $twig->addFilter('bas_labels', new \Twig_Filter_Function('phrasea::bas_labels')); $twig->addFilter('sbas_names', new \Twig_Filter_Function('phrasea::sbas_names')); + $twig->addFilter('sbas_labels', new \Twig_Filter_Function('phrasea::sbas_labels')); $twig->addFilter('sbas_from_bas', new \Twig_Filter_Function('phrasea::sbasFromBas')); $twig->addFilter('key_exists', new \Twig_Filter_Function('array_key_exists')); $twig->addFilter('round', new \Twig_Filter_Function('round')); diff --git a/lib/Alchemy/Phrasea/Command/RecordAdd.php b/lib/Alchemy/Phrasea/Command/RecordAdd.php index 6731cd9cce..054c8bb76d 100644 --- a/lib/Alchemy/Phrasea/Command/RecordAdd.php +++ b/lib/Alchemy/Phrasea/Command/RecordAdd.php @@ -116,7 +116,7 @@ class RecordAdd extends Command if ($elementCreated instanceof \record_adapter) { $output->writeln( sprintf( - "Record id %d on collection `%s` (databox `%s`) has been created", $elementCreated->get_record_id(), $elementCreated->get_collection()->get_label($this->container['locale.I18n']), $elementCreated->get_databox()->get_viewname() + "Record id %d on collection `%s` (databox `%s`) has been created", $elementCreated->get_record_id(), $elementCreated->get_collection()->get_label($this->container['locale.I18n']), $elementCreated->get_databox()->get_label($this->container['locale.I18n']) ) ); $this->container['phraseanet.SE']->addRecord($elementCreated); diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Databox.php b/lib/Alchemy/Phrasea/Controller/Admin/Databox.php index 9c37ab1d9b..79f1ec5947 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/Databox.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/Databox.php @@ -183,6 +183,12 @@ class Databox implements ControllerProviderInterface $app['firewall']->requireRightOnSbas($request->attributes->get('databox_id'), 'bas_modify_struct'); })->bind('admin_database_display_cgus'); + $controllers->post('/{databox_id}/labels/', $this->call('setLabels')) + ->assert('databox_id', '\d+') + ->before(function(Request $request) use ($app) { + $app['firewall']->requireRightOnSbas($request->attributes->get('databox_id'), 'bas_manage'); + })->bind('admin_databox_labels'); + /** * Update database CGU * @@ -484,6 +490,40 @@ class Databox implements ControllerProviderInterface return $app->redirect('/admin/databox/' . $databox->get_sbas_id() . '/?success=' . (int) $success . ($databox->get_record_amount() > 0 ? '&error=databox-not-empty' : '')); } + public function setLabels(Application $app, Request $request, $databox_id) + { + if (null === $labels = $request->request->get('labels')) { + $app->abort(400, _('Missing labels parameter')); + } + if (false === is_array($labels)) { + $app->abort(400, _('Invalid labels parameter')); + } + + $databox = $app['phraseanet.appbox']->get_databox($databox_id); + $success = true; + + try { + foreach ($app['locales.I18n.available'] as $code => $language) { + if (!isset($labels[$code])) { + continue; + } + $value = $labels[$code] ?: null; + $databox->set_label($code, $value); + } + } catch (\Exception $e) { + $success = false; + } + + if ('json' === $app['request']->getRequestFormat()) { + return $app->json(array( + 'success' => $success, + 'msg' => $success ? _('Successful update') : _('An error occured') + )); + } + + return $app->redirect('/admin/databox/' . $databox->get_sbas_id() . '/?success=' . (int) $success . '&reload-tree=1'); + } + /** * Reindex databox content * @@ -716,7 +756,7 @@ class Databox implements ControllerProviderInterface $success = false; try { - $app['phraseanet.appbox']->set_databox_viewname($app['phraseanet.appbox']->get_databox($databox_id), $viewName); + $app['phraseanet.appbox']->get_databox($databox_id)->set_viewname($viewName); $success = true; } catch (\Exception $e) { diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Databoxes.php b/lib/Alchemy/Phrasea/Controller/Admin/Databoxes.php index 4372031916..15263faeaa 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/Databoxes.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/Databoxes.php @@ -141,7 +141,7 @@ class Databoxes implements ControllerProviderInterface 'version' => $databox->get_version(), 'image' => '/skins/icons/foldph20close_0.gif', 'server_info' => $databox->get_connection()->server_info(), - 'name' => \phrasea::sbas_names($sbasId, $app) + 'name' => \phrasea::sbas_labels($sbasId, $app) ); } catch (\Exception $e) { diff --git a/lib/Alchemy/Phrasea/Controller/Prod/TOU.php b/lib/Alchemy/Phrasea/Controller/Prod/TOU.php index 71bba843ef..4bcf807169 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/TOU.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/TOU.php @@ -120,7 +120,7 @@ class TOU implements ControllerProviderInterface continue; } - $data[$databox->get_viewname()] = $cgus[$app['locale']]['value']; + $data[$databox->get_label($app['locale.I18n'])] = $cgus[$app['locale']]['value']; } return new Response($app['twig']->render('/prod/TOU.html.twig', array( diff --git a/lib/Alchemy/Phrasea/Controller/Thesaurus/Thesaurus.php b/lib/Alchemy/Phrasea/Controller/Thesaurus/Thesaurus.php index 9024dcc9c1..8eca242656 100644 --- a/lib/Alchemy/Phrasea/Controller/Thesaurus/Thesaurus.php +++ b/lib/Alchemy/Phrasea/Controller/Thesaurus/Thesaurus.php @@ -789,7 +789,7 @@ class Thesaurus implements ControllerProviderInterface } catch (\Exception $e) { continue; } - $bases[$row['sbas_id']] = \phrasea::sbas_names($row['sbas_id'], $app); + $bases[$row['sbas_id']] = \phrasea::sbas_labels($row['sbas_id'], $app); } foreach (PhraseaApplication::getAvailableLanguages() as $lng_code => $lng) { @@ -1065,7 +1065,7 @@ class Thesaurus implements ControllerProviderInterface $updated = false; $validThesaurus = true; $ctlist = array(); - $name = \phrasea::sbas_names($request->get('bid'), $app); + $name = \phrasea::sbas_labels($request->get('bid'), $app); try { $databox = $app['phraseanet.appbox']->get_databox((int) $request->get('bid')); diff --git a/lib/Alchemy/Phrasea/Controller/Thesaurus/Xmlhttp.php b/lib/Alchemy/Phrasea/Controller/Thesaurus/Xmlhttp.php index 6aea9c2593..d887f07dcb 100644 --- a/lib/Alchemy/Phrasea/Controller/Thesaurus/Xmlhttp.php +++ b/lib/Alchemy/Phrasea/Controller/Thesaurus/Xmlhttp.php @@ -832,7 +832,7 @@ class Xmlhttp implements ControllerProviderInterface try { $connbas = \connection::getPDOConnection($app, $sbid); - $dbname = \phrasea::sbas_names($sbid, $app); + $dbname = \phrasea::sbas_labels($sbid, $app); $t_nrec = array(); $lthid = strlen($thid); @@ -1632,7 +1632,7 @@ class Xmlhttp implements ControllerProviderInterface $html = "" . '
  • ' . sprintf(_('task::ftp:Record %1$s - %2$s de la base (%3$s - %4$s) - %5$s') , $row["record_id"], $row["filename"] - , phrasea::sbas_names(phrasea::sbasFromBas($this->dependencyContainer, $row["base_id"]), $this->dependencyContainer) + , phrasea::sbas_labels(phrasea::sbasFromBas($this->dependencyContainer, $row["base_id"]), $this->dependencyContainer) , phrasea::bas_labels($row['base_id'], $this->dependencyContainer), $row['subdef']) . ' : ' . _('Transfert OK') . '
  • '; } else { $transferts[] = '
  • ' . sprintf(_('task::ftp:Record %1$s - %2$s de la base (%3$s - %4$s) - %5$s') , $row["record_id"], $row["filename"] - , phrasea::sbas_names(phrasea::sbasFromBas($this->dependencyContainer, $row["base_id"]), $this->dependencyContainer), phrasea::bas_labels($row['base_id'], $this->dependencyContainer) + , phrasea::sbas_labels(phrasea::sbasFromBas($this->dependencyContainer, $row["base_id"]), $this->dependencyContainer), phrasea::bas_labels($row['base_id'], $this->dependencyContainer) , $row['subdef']) . ' : ' . _('Transfert Annule') . '
  • '; $transfert_status = _('task::ftp:Certains documents n\'ont pas pu etre tranferes'); } diff --git a/lib/conf.d/bases_structure.xml b/lib/conf.d/bases_structure.xml index 9dd91ce171..21a85dcc54 100644 --- a/lib/conf.d/bases_structure.xml +++ b/lib/conf.d/bases_structure.xml @@ -2522,19 +2522,8 @@ - - thesaurus_id - int(11) unsigned - - - - - 0 - - viewname - char(128) @@ -2543,7 +2532,6 @@ - indexable tinyint(1) unsigned @@ -2551,7 +2539,38 @@ 1 - + + + label_en + char(50) + YES + + + + + + label_fr + char(50) + YES + + + + + + label_de + char(50) + YES + + + + + + label_nl + char(50) + YES + + + diff --git a/templates/web/account/access.html.twig b/templates/web/account/access.html.twig index 17a0e591ef..588f2497c3 100644 --- a/templates/web/account/access.html.twig +++ b/templates/web/account/access.html.twig @@ -17,7 +17,7 @@ {% for sbasId, baseInsc in inscriptions %} {% if baseInsc["CollsRegistered"] or baseInsc["CollsRefuse"] or baseInsc["CollsWait"] or baseInsc["CollsIntime"] or baseInsc["CollsOuttime"] or baseInsc["CollsNonactif"] or baseInsc["CollsCGU"] or baseInsc["Colls"] %} -

    {{ sbasId | sbas_names(app) }}

    +

    {{ sbasId | sbas_labels(app) }}

    {% endif %} @@ -27,7 +27,7 @@ {% set base_id = sbasId |base_from_coll(collId, app) %} - {% trans "login::register: acces authorise sur la collection " %}{{ sbasId |sbas_names(app) }} + {% trans "login::register: acces authorise sur la collection " %}{{ sbasId |sbas_labels(app) }} {% if isTrue | trim != "" %} {% trans "login::register::CGU: lire les CGU" %} {% endif %} @@ -46,7 +46,7 @@ {% set base_id = sbasId |base_from_coll(collId, app) %} - {% trans "login::register: acces refuse sur la collection " %}{{ sbasId |sbas_names(app) }} + {% trans "login::register: acces refuse sur la collection " %}{{ sbasId |sbas_labels(app) }} {% if isTrue | trim != "" %} {% trans "login::register::CGU: lire les CGU" %} {% endif %} @@ -64,7 +64,7 @@ {% set base_id = sbasId |base_from_coll(collId, app) %} - {% trans "login::register: en attente d\'acces sur" %} {{ sbasId |sbas_names(app) }} + {% trans "login::register: en attente d\'acces sur" %} {{ sbasId |sbas_labels(app) }} {% if isTrue | trim != "" %} {% trans "login::register::CGU: lire les CGU" %} {% endif %} @@ -79,7 +79,7 @@ {% set base_id = sbasId |base_from_coll(collId, app) %} - {% trans "login::register: acces temporaire sur" %} {{ sbasId |sbas_names(app) }} + {% trans "login::register: acces temporaire sur" %} {{ sbasId |sbas_labels(app) }} {% if isTrue |trim != "" %} {% trans "login::register::CGU: lire les CGU" %} {% endif %} @@ -94,7 +94,7 @@ {% set base_id = sbasId |base_from_coll(collId, app) %} - {% trans "login::register: acces temporaire termine sur " %}{{ sbasId |sbas_names(app) }} + {% trans "login::register: acces temporaire termine sur " %}{{ sbasId |sbas_labels(app) }} {% if isTrue |trim != "" %} {% trans "login::register::CGU: lire les CGU" %} {% endif %} @@ -109,7 +109,7 @@ {% set base_id = sbasId |base_from_coll(collId, app) %} - {% trans "login::register: acces supendu sur" %} {{ sbasId |sbas_names(app) }} + {% trans "login::register: acces supendu sur" %} {{ sbasId |sbas_labels(app) }} {% if isTrue |trim != "" %} {% trans "login::register::CGU: lire les CGU" %} {% endif %} diff --git a/templates/web/admin/connected-users.html.twig b/templates/web/admin/connected-users.html.twig index 91ed56452d..86d48fd84c 100644 --- a/templates/web/admin/connected-users.html.twig +++ b/templates/web/admin/connected-users.html.twig @@ -26,7 +26,7 @@ {% for databox in user.ACL().get_granted_sbas() %} - {{ databox.get_viewname() }} + {{ databox.get_label(app['locale.I18n']) }} {% endfor %} diff --git a/templates/web/admin/databox/databox.html.twig b/templates/web/admin/databox/databox.html.twig index ef4f52418e..c1dc2a2f97 100644 --- a/templates/web/admin/databox/databox.html.twig +++ b/templates/web/admin/databox/databox.html.twig @@ -29,7 +29,7 @@
  • - {% trans 'admin::base: Alias' %} : {{ databox.get_viewname() }} + {% trans 'admin::base: Alias' %} : {{ databox.get_label(app['locale.I18n']) }} {% if app['authentication'].getUser().ACL().has_right_on_sbas(databox.get_sbas_id(), "bas_manage") %} +
    +
    +
    +
    + {% for code, language in app['locales.I18n.available'] %} +
    +
    {{ language }}
    +
    + {% endfor %} +
    +
    + {% for code, language in app['locales.I18n.available'] %} +
    + +
    + {% endfor %} +
    + +
    +
    +
    +
    +
    +
    diff --git a/templates/web/admin/editusers.html.twig b/templates/web/admin/editusers.html.twig index 8c1e31e68b..b2b0e85af5 100644 --- a/templates/web/admin/editusers.html.twig +++ b/templates/web/admin/editusers.html.twig @@ -203,7 +203,7 @@ - {{rights['sbas_id']|sbas_names(app)}} + {{rights['sbas_id']|sbas_labels(app)}}
    diff --git a/templates/web/admin/editusers_masks.html.twig b/templates/web/admin/editusers_masks.html.twig index b0635db66c..10ef3949ba 100644 --- a/templates/web/admin/editusers_masks.html.twig +++ b/templates/web/admin/editusers_masks.html.twig @@ -1,6 +1,6 @@

    Masks

    -Base {{ collection.get_databox().get_viewname() }} +Base {{ collection.get_databox().get_label(app['locale.I18n']) }}
    Collection {{base_id|bas_labels(app)}} diff --git a/templates/web/admin/editusers_quotas.html.twig b/templates/web/admin/editusers_quotas.html.twig index 7196462c75..330997f154 100644 --- a/templates/web/admin/editusers_quotas.html.twig +++ b/templates/web/admin/editusers_quotas.html.twig @@ -38,7 +38,7 @@

    {% trans 'Quotas' %}

    -{% set base = collection.get_databox().get_viewname() %} +{% set base = collection.get_databox().get_label(app['locale.I18n']) %} {% trans %}Base {{base}}{% endtrans %}
    diff --git a/templates/web/admin/editusers_timelimit.html.twig b/templates/web/admin/editusers_timelimit.html.twig index 594e698197..16845fe61d 100644 --- a/templates/web/admin/editusers_timelimit.html.twig +++ b/templates/web/admin/editusers_timelimit.html.twig @@ -1,6 +1,6 @@

    {% trans 'Limite temporelle' %}

    -{% set base = collection.get_databox().get_viewname() %} +{% set base = collection.get_databox().get_label(app['locale.I18n']) %} {% trans %}Base {{base}}{% endtrans %}
    diff --git a/templates/web/admin/publications/fiche.html.twig b/templates/web/admin/publications/fiche.html.twig index d8d0c759ae..fcdf700b7b 100644 --- a/templates/web/admin/publications/fiche.html.twig +++ b/templates/web/admin/publications/fiche.html.twig @@ -98,7 +98,7 @@ {% for databox in app['authentication'].getUser().ACL().get_granted_sbas('bas_chupub') %} - + {% for collection in databox.get_collections() %} {% endfor %} @@ -71,7 +71,7 @@ {% if feed.get_collection() != null %} - {{ feed.get_collection().get_databox().get_viewname() }} / + {{ feed.get_collection().get_databox().get_label(app['locale.I18n']) }} / {{ feed.get_collection().get_name() }} {% endif %} diff --git a/templates/web/admin/tree.html.twig b/templates/web/admin/tree.html.twig index bcdd735232..5d8f96e259 100644 --- a/templates/web/admin/tree.html.twig +++ b/templates/web/admin/tree.html.twig @@ -98,7 +98,7 @@
      diff --git a/templates/web/client/index.html.twig b/templates/web/client/index.html.twig index 0bbec14c21..1bf4c43a35 100644 --- a/templates/web/client/index.html.twig +++ b/templates/web/client/index.html.twig @@ -118,8 +118,8 @@ {% set databox = databoxWrapper['databoxes'] %} {% set collections = databoxWrapper['collections'] %} {% if collections|length > 0 %} - - + + {% for collId, collection in collections %} {% endfor %} @@ -192,7 +192,7 @@
      - +
      {% set status_bit_filters = '' %} diff --git a/templates/web/prod/Story/Create.html.twig b/templates/web/prod/Story/Create.html.twig index face56a509..7400600ff4 100644 --- a/templates/web/prod/Story/Create.html.twig +++ b/templates/web/prod/Story/Create.html.twig @@ -3,7 +3,7 @@ diff --git a/templates/web/prod/actions/Download/prepare.html.twig b/templates/web/prod/actions/Download/prepare.html.twig index 3fab3e85ca..62d4c9cd4a 100644 --- a/templates/web/prod/actions/Download/prepare.html.twig +++ b/templates/web/prod/actions/Download/prepare.html.twig @@ -46,7 +46,7 @@ {% for file in list["files"] %} {% set size = 0 %} - {{ app|sbas_from_bas(file['base_id'])|sbas_names(app) }} {{ file['base_id']|bas_labels(app) }} + {{ app|sbas_from_bas(file['base_id'])|sbas_labels(app) }} {{ file['base_id']|bas_labels(app) }} {{ file['original_name'] }} {% if file['subdefs'] is iterable and file['subdefs']|length > 0 %} diff --git a/templates/web/prod/actions/Property/index.html.twig b/templates/web/prod/actions/Property/index.html.twig index e613c5ece7..66c73925e3 100644 --- a/templates/web/prod/actions/Property/index.html.twig +++ b/templates/web/prod/actions/Property/index.html.twig @@ -43,7 +43,7 @@ - {{ databox.get_viewname()|title }} + {{ databox.get_label(app['locale.I18n'])|title }} diff --git a/templates/web/prod/actions/Property/type.html.twig b/templates/web/prod/actions/Property/type.html.twig index c158e74d93..c03ee4d65b 100644 --- a/templates/web/prod/actions/Property/type.html.twig +++ b/templates/web/prod/actions/Property/type.html.twig @@ -20,7 +20,7 @@
      {% for sbasId,databoxTypes in recordsType %} -

      {{ sbasId|sbas_names(app) }}

      +

      {{ sbasId|sbas_labels(app) }}

      {% for currentType, recordsByType in databoxTypes %}
        {% for record in recordsByType %} diff --git a/templates/web/prod/actions/edit_default.html.twig b/templates/web/prod/actions/edit_default.html.twig index d99991c236..b91a13a353 100644 --- a/templates/web/prod/actions/edit_default.html.twig +++ b/templates/web/prod/actions/edit_default.html.twig @@ -245,7 +245,7 @@
        diff --git a/templates/web/prod/index.html.twig b/templates/web/prod/index.html.twig index 604ecd18ee..bb662c3055 100644 --- a/templates/web/prod/index.html.twig +++ b/templates/web/prod/index.html.twig @@ -6,7 +6,7 @@