From f054dabbdfab4a7e5c4cd6f4b8af7f495739b809 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 20 Jan 2023 13:36:23 +0100 Subject: [PATCH] NEW expend/collapse list of social networks --- htdocs/contact/card.php | 56 +--------- htdocs/contact/class/contact.class.php | 3 + .../core/class/commonsocialnetworks.class.php | 102 ++++++++++++++++++ htdocs/langs/en_US/companies.lang | 4 +- htdocs/societe/card.php | 52 +-------- htdocs/societe/class/societe.class.php | 2 + 6 files changed, 116 insertions(+), 103 deletions(-) create mode 100644 htdocs/core/class/commonsocialnetworks.class.php diff --git a/htdocs/contact/card.php b/htdocs/contact/card.php index 66cdc1ed1aa..4fde1b75552 100644 --- a/htdocs/contact/card.php +++ b/htdocs/contact/card.php @@ -856,9 +856,9 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { print ''; } - + // Social network if (isModEnabled('socialnetworks')) { - showSocialNetwork(); + $object->showSocialNetwork($socialnetworks, ($conf->browser->layout == 'phone' ? 2 : 4)); } // Visibility @@ -1128,8 +1128,9 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { print ''; } + // Social network if (isModEnabled('socialnetworks')) { - showSocialNetwork(); + $object->showSocialNetwork($socialnetworks, ($conf->browser->layout == 'phone' ? 2 : 4)); } // Visibility @@ -1584,55 +1585,6 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { } } -/** - * Show social network part if the module is enabled with hiding functionality - * - * @return void - */ -function showSocialNetwork() -{ - global $socialnetworks, $object, $form, $object, $langs; - echo ''; - - print ' '; - foreach ($socialnetworks as $key => $value) { - if ($value['active']) { - print ''; - print ''; - print ''; - if (!empty($value['icon'])) { - print ''; - } - print ''; - print ''; - print ''; - } elseif (!empty($object->socialnetworks[$key])) { - print ''; - } - } - - print ''; -} - llxFooter(); diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php index e55f123a540..c9d62c410b3 100644 --- a/htdocs/contact/class/contact.class.php +++ b/htdocs/contact/class/contact.class.php @@ -32,6 +32,7 @@ * \brief File of contacts class */ require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/commonsocialnetworks.class.php'; /** @@ -39,6 +40,8 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; */ class Contact extends CommonObject { + use CommonSocialNetworks; + /** * @var string ID to identify managed object */ diff --git a/htdocs/core/class/commonsocialnetworks.class.php b/htdocs/core/class/commonsocialnetworks.class.php new file mode 100644 index 00000000000..eeb6583ca65 --- /dev/null +++ b/htdocs/core/class/commonsocialnetworks.class.php @@ -0,0 +1,102 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/core/class/commonincoterm.class.php + * \ingroup core + * \brief File of the superclass of object classes that support incoterm (customer and supplier) + */ + + +/** + * Superclass for social networks + */ +trait CommonSocialNetworks +{ + /** + * Show social network part if the module is enabled with hiding functionality + * + * @param array $socialnetworks Array of social networks + * @param int $colspan Colspan + * @return void + */ + public function showSocialNetwork($socialnetworks, $colspan = 4) + { + global $object, $form, $langs; + + $nbofnetworks = count($socialnetworks); + $nbactive = 0; + foreach ($socialnetworks as $key => $value) { + if (!empty($object->socialnetworks[$key])) { + $nbactive++; + } + } + + if ($nbofnetworks > 1) { + print '
'; + print ''; + print '
'.$nbactive.''; + print ''; + print ''; + } + foreach ($socialnetworks as $key => $value) { + if ($value['active'] || $nbofnetworks == 1) { + print ''; + print ''; + print ''; + if (!empty($value['icon'])) { + print ''; + } + print ''; + print ''; + print ''; + } elseif (!empty($object->socialnetworks[$key])) { + print ''; + } + } + print '
'; + + if ($nbofnetworks > 1) { + print ''; + } + } +} diff --git a/htdocs/langs/en_US/companies.lang b/htdocs/langs/en_US/companies.lang index 38b6892dbae..911ba31bc25 100644 --- a/htdocs/langs/en_US/companies.lang +++ b/htdocs/langs/en_US/companies.lang @@ -500,4 +500,6 @@ CurrentOutstandingBillLate=Current outstanding bill late BecarefullChangeThirdpartyBeforeAddProductToInvoice=Be carefull, depending on your product price settings, you should change thirdparty before adding product to POS. EmailAlreadyExistsPleaseRewriteYourCompanyName=email already exists please rewrite your company name TwoRecordsOfCompanyName=more than one record exists for this company, please contact us to complete your partnership request -CompanySection=Company section \ No newline at end of file +CompanySection=Company section +ShowSocialNetworks=Show social networks +HideSocialNetworks=Hide social networks diff --git a/htdocs/societe/card.php b/htdocs/societe/card.php index 6ef8d929361..02d0b042aab 100644 --- a/htdocs/societe/card.php +++ b/htdocs/societe/card.php @@ -1663,7 +1663,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { // Social networks if (isModEnabled('socialnetworks')) { - showSocialNetwork(); + $object->showSocialNetwork($socialnetworks, ($conf->browser->layout == 'phone' ? 2 : 4)); } // Prof ids @@ -2381,7 +2381,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { // Social network if (isModEnabled('socialnetworks')) { - showSocialNetwork(); + $object->showSocialNetwork($socialnetworks, ($conf->browser->layout == 'phone' ? 2 : 4)); } // Prof ids @@ -3299,54 +3299,6 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { } } -/** - * Show social network part if the module is enabled with hiding functionality - * - * @return void - */ -function showSocialNetwork() -{ - global $socialnetworks, $object, $form, $object, $langs; - echo ''; - - print ' '; - foreach ($socialnetworks as $key => $value) { - if ($value['active']) { - print ''; - print ''; - print ''; - if (!empty($value['icon'])) { - print ''; - } - print ''; - print ''; - print ''; - } elseif (!empty($object->socialnetworks[$key])) { - print ''; - } - } - - print ''; -} // End of page llxFooter(); diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 29f400fc778..2e633126f64 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -40,6 +40,7 @@ */ require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/commonincoterm.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/commonsocialnetworks.class.php'; require_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php'; @@ -49,6 +50,7 @@ require_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php'; class Societe extends CommonObject { use CommonIncoterm; + use CommonSocialNetworks; /** * @var string ID to identify managed object