From 60892c39a82233fd897b6996f69608d69155fb74 Mon Sep 17 00:00:00 2001
From: gloas <gloas@afi-sa.fr>
Date: Tue, 17 Apr 2018 15:44:34 +0200
Subject: [PATCH] dev #73975 add mailto link to features

---
 FEATURES/73975                                | 10 ++++
 VERSIONS_WIP/73975                            |  1 +
 .../admin/views/scripts/feature/index.phtml   | 13 ++++-
 library/Class/AdminVar.php                    |  3 +-
 library/Class/Feature/Description.php         | 54 +++++++++++++++++++
 library/Class/Users.php                       | 17 ++++++
 .../controllers/FeatureControllerTest.php     |  7 +++
 7 files changed, 103 insertions(+), 2 deletions(-)
 create mode 100644 FEATURES/73975
 create mode 100644 VERSIONS_WIP/73975

diff --git a/FEATURES/73975 b/FEATURES/73975
new file mode 100644
index 00000000000..5bd58314e21
--- /dev/null
+++ b/FEATURES/73975
@@ -0,0 +1,10 @@
+        '73975' =>
+            ['Label' => $this->_('Mail de formations ou d\'activation des fonctionnalités'),
+             'Desc' => $this->_('Depuis la liste des fonctionnalités, vous pouvez faire une demande d\'accompagnement pour la mise en place ou l\'utilisation d\'une fonctionnalité de Bokeh'),
+             'Image' => '',
+             'Video' => '',
+             'Category' => $this->_('Administration'),
+             'Right' => function($feature_description, $user) {return true;},
+             'Wiki' => 'http://wiki.bokeh-library-portal.org/index.php?title=Nouvelles_fonctionnalit%C3%A9s',
+             'Test' => '/admin/feature/index',
+             'Date' => '2018-04-17'],
\ No newline at end of file
diff --git a/VERSIONS_WIP/73975 b/VERSIONS_WIP/73975
new file mode 100644
index 00000000000..f890311d8b0
--- /dev/null
+++ b/VERSIONS_WIP/73975
@@ -0,0 +1 @@
+ - ticket #73975 : Liste des fonctionnalités : ajout d'un lien permettant de demander un devis de formation ou d'activation par fonctionnalités.
diff --git a/application/modules/admin/views/scripts/feature/index.phtml b/application/modules/admin/views/scripts/feature/index.phtml
index 53260183f02..29ce5b1fcc6 100644
--- a/application/modules/admin/views/scripts/feature/index.phtml
+++ b/application/modules/admin/views/scripts/feature/index.phtml
@@ -22,6 +22,17 @@ $description = (new Class_TableDescription('features'))
                 return $feature->getCategory();
               })
 
+  ->addRowAction(function($feature)
+                 {
+                   return ($email = $feature->getEmail(Class_Users::getIdentity()))
+                     ? $this->tagAnchor($email,
+                                        $this->tagImg(Class_Admin_Skin::current()
+                                                  ->getIconUrl('icons',
+                                                               'newsletters')),
+                                        ['title' => $this->_('Demander une formation ou une mise en place pour: "%s"', $feature->getLabel())])
+                     : '';
+                 })
+
   ->addRowAction(function($feature)
                  {
                    $hide = $this->tagAnchor(['module' => 'admin',
@@ -102,4 +113,4 @@ $script_loader = Class_ScriptLoader::getInstance()
   ->addSearchInputToContent($this->_('Chercher'))
   ->addJQueryReady('$(\'#features_list\').accordion({heightStyle: \'content\'});');
 
-    (new Class_Admin_Skin)->renderJQueryCssOn($script_loader);
+(new Class_Admin_Skin)->renderJQueryCssOn($script_loader);
diff --git a/library/Class/AdminVar.php b/library/Class/AdminVar.php
index a396d465f2a..757101c5a19 100644
--- a/library/Class/AdminVar.php
+++ b/library/Class/AdminVar.php
@@ -366,7 +366,8 @@ class Class_AdminVarLoader extends Storm_Model_Loader {
             'STATUS_REPORT_PUSH_URL' => Class_AdminVar_Meta::newRawText($this->_('URL destinataire du rapport d\'état du système (0 pour désactiver)'), ['value' => 'http://pola.afi-sa.net/smile.php'])->bePrivate(),
             'STATUS_REPORT_TAGS' => Class_AdminVar_Meta::newMultiInput($this->_('Liste des tags à ajouter au rapport d\'état du système'))->bePrivate(),
             'FEATURES_TRACKING_ENABLE' => Class_AdminVar_Meta::newOnOff('Affiche les dernières modifications apportés au logiciel Bokeh', ['value' => 1])->bePrivate(),
-            'INSPECTOR_GADGET_MARC_XML' => Class_AdminVar_Meta::newOnOff('Affiche le MARC XML de la notice dans Inspector Gadget')->bePrivate()
+            'INSPECTOR_GADGET_MARC_XML' => Class_AdminVar_Meta::newOnOff('Affiche le MARC XML de la notice dans Inspector Gadget')->bePrivate(),
+            'BUSINESS_EMAIL' => Class_AdminVar_Meta::newDefault($this->_('Email utiliser pour les demandes de formations ou d\'activation des fonctionnalités du logiciel'), ['value' => 'cial-bib@afi-sa.fr'])->bePrivate()
 ];
   }
 
diff --git a/library/Class/Feature/Description.php b/library/Class/Feature/Description.php
index ed608369f39..6e25b215fcd 100644
--- a/library/Class/Feature/Description.php
+++ b/library/Class/Feature/Description.php
@@ -21,6 +21,9 @@
 
 
 class Class_Feature_Description extends Class_Entity {
+  use Trait_Translator;
+
+
   public function isNewFor($user) {
     return !in_array($this, (new Class_Feature)->findCheckedBy($user));
   }
@@ -35,4 +38,55 @@ class Class_Feature_Description extends Class_Entity {
 
     return call_user_func_array($this->getRight(), [$this, $user]);
   }
+
+
+  public function getEmail($user) {
+    if(!$user)
+      return;
+
+    if(!$reciepe = Class_AdminVar::get('BUSINESS_EMAIL'))
+      return;
+
+    $line_break = '%0D%0A';
+
+    $cc = array_filter([$user->getMail(),
+                        $user->getLibraryMail()]);
+
+    $subject = $this->_('Demande d\'accompagnement pour la mise en place ou l\'utilisation de la fonction Bokeh : %s',
+                        $this->getLabel());
+
+    $body = [$this->_('Bonjour,'),
+             $line_break,
+             $line_break,
+             $this->_('Je souhaite un accompagnement pour la mise en place ou l\'utilisation d\'une fonctionnalité Bokeh:'),
+             $line_break,
+             $line_break,
+             $this->getLabel(),
+             $line_break,
+             $line_break,
+             $this->_('Informations de mon Bokeh: '),
+             $line_break,
+             $this->_('Url : ') . Class_Url::rootUrl() . Class_Url::baseUrl(),
+             $line_break,
+             $this->_('Version : %s', BOKEH_RELEASE_NUMBER),
+             $line_break,
+             $this->_('Base de données : ') . Zend_Db_Table::getDefaultAdapter()->getConfig()['dbname'],
+             $line_break,
+             $line_break,
+             $this->_('Cordialement,'),
+             $line_break,
+             $user->getNomComplet()];
+
+    $email_params = array_filter(['cc' => implode(',', $cc),
+                                  'subject' => $subject,
+                                  'body' => implode($body)]);
+
+    $params = [];
+    foreach($email_params as $key => $value)
+      $params [] = $key . '=' . $value;
+
+    return sprintf('mailto:%s?%s',
+                   $reciepe,
+                   implode('&', $params));
+  }
 }
\ No newline at end of file
diff --git a/library/Class/Users.php b/library/Class/Users.php
index 9e74dc1b8c9..558f8a3817d 100644
--- a/library/Class/Users.php
+++ b/library/Class/Users.php
@@ -1887,4 +1887,21 @@ class Class_Users extends Storm_Model_Abstract {
   public function verifyPassword($value) {
     return (new Class_User_Password($this))->verify($value);
   }
+
+
+  public function getLibraryMail() {
+    $profile = Class_Profil::getCurrentProfil();
+
+    $int_library_mail = ($int_library = $this->getIntBib())
+      ? $int_library->getMail()
+      : '';
+
+    $library_mail = ($library = $this->getBib())
+      ? $library->getMail()
+      : $profile->getMailSiteOrPortail();
+
+    return $int_library_mail
+      ? $int_library_mail
+      : $library_mail;
+  }
 }
diff --git a/tests/application/modules/admin/controllers/FeatureControllerTest.php b/tests/application/modules/admin/controllers/FeatureControllerTest.php
index 913442b47be..b3689fcb4c0 100644
--- a/tests/application/modules/admin/controllers/FeatureControllerTest.php
+++ b/tests/application/modules/admin/controllers/FeatureControllerTest.php
@@ -25,6 +25,7 @@ class FeatureControllerIndexDispatchTest extends Admin_AbstractControllerTestCas
 
   public function setUp() {
     parent::setUp();
+    Class_AdminVar::set('BUSINESS_EMAIL', 'business@afi.fr');
     $this->dispatch('/admin/feature/index', true);
   }
 
@@ -69,6 +70,12 @@ class FeatureControllerIndexDispatchTest extends Admin_AbstractControllerTestCas
   public function fileManagerVideoShouldBePresent() {
     $this->assertXPath('//td//a[contains(@href, "youtube")]');
   }
+
+
+  /** @test */
+  public function emailLinkShouldBePresent() {
+    $this->assertXPath('//table[@id="features"]//td//a[contains(@href, "mailto:business@afi.fr")]', $this->_response->getBody());
+  }
 }
 
 
-- 
GitLab