3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
6 * Galette application instance
10 * Copyright © 2020-2023 The Galette Team
12 * This file is part of Galette (http://galette.tuxfamily.org).
14 * Galette is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
19 * Galette is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
30 * @author Johan Cwiklinski <johan@x-tnd.be>
31 * @copyright 2020-2023 The Galette Team
32 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
33 * @link https://galette.eu
34 * @since Available since 0.9.4-dev - 2020-05-18
37 namespace Galette\Core
;
39 use Galette\Entity\Adherent
;
42 * Galette application instance
47 * @author Johan Cwiklinski <johan@x-tnd.be>
48 * @copyright 2020-2023 The Galette Team
49 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
50 * @link https://galette.eu
51 * @since Available since 0.9.4-dev - 2020-05-18
55 public const MODE_PROD
= 'PROD';
56 public const MODE_DEV
= 'DEV';
57 public const MODE_MAINT
= 'MAINT';
58 public const MODE_DEMO
= 'DEMO';
61 * Retrieve Galette version from git, if present.
63 * @param boolean $time Include time and timezone. Defaults to false.
67 public static function gitVersion($time = false)
69 $galette_version = GALETTE_VERSION
;
71 //used for both git and nightly installs
72 $version = str_replace('-dev', '-git', GALETTE_VERSION
);
73 if (strstr($version, '-git') === false) {
77 if (is_dir(GALETTE_ROOT
. '../.git')) {
78 $commitHash = trim(exec('git log --pretty="%h" -n1 HEAD'));
80 $commitDate = new \
DateTime(trim(exec('git log -n1 --pretty=%ci HEAD')));
82 $galette_version = sprintf(
86 $commitDate->format(($time ?
'Y-m-d H:i:s T' : 'Y-m-d'))
88 } elseif (static::isNightly()) {
89 $galette_version = $version . '-' . GALETTE_NIGHTLY
;
91 return $galette_version;
99 public static function getAllMenus(): array
101 return static::getMenus(true);
107 * @param bool $public Include public menus. Defaults to false
111 public static function getMenus(bool $public = false): array
115 * @var Preferences $preferences
116 * @var Plugins $plugins
118 global $login, $preferences, $plugins;
122 if ($login->isLogged()) {
123 if (!$login->isSuperAdmin()) {
125 $menus['myaccount'] = [
126 'title' => _T("My Account"),
130 'label' => _T('My contributions'),
131 'title' => _T('View and filter all my contributions'),
133 'name' => 'myContributions',
134 'args' => ['type' => 'contributions']
138 'label' => _T('My transactions'),
139 'title' => _T('View and filter all my transactions'),
141 'name' => 'myContributions',
142 'args' => ['type' => 'transactions']
146 'label' => _T('My information'),
147 'title' => _T('View my member card'),
156 if ($preferences->pref_bool_create_member
) {
157 $menus['myaccount']['items'][] = [
158 'label' => _T('Add a child member'),
159 'title' => _T('Add new child member in database'),
161 'name' => 'addMemberChild',
168 $menus['members'] = [
169 'title' => _T("Members"),
174 if ($login->isAdmin() ||
$login->isStaff() ||
$login->isGroupManager()) {
175 $menus['members']['items'] = [
177 'label' => _T("List of members"),
178 'title' => _T("View, search into and filter member's list"),
181 'aliases' => ['editMember', 'member']
185 'label' => _T("Advanced search"),
186 'title' => _T("Perform advanced search into members list"),
188 'name' => 'advanced-search'
192 'label' => _T("Saved searches"),
203 ||
($login->isGroupManager() && $preferences->pref_bool_groupsmanagers_create_member
)
205 $menus['members']['items'][] = [
206 'label' => _T("Add a member"),
207 'title' => _T("Add new member in database"),
209 'name' => 'addMember'
214 if ($login->isAdmin() ||
$login->isStaff()) {
215 $menus['contributions'] = [
216 'title' => _T('Contributions'),
220 'label' => _T("List of contributions"),
221 'title' => _T("View and filter contributions"),
223 'name' => 'contributions',
224 'args' => ['type' => 'contributions'],
225 'aliases' => ['editContribution']
229 'label' => _T("List of transactions"),
230 'title' => _T("View and filter transactions"),
232 'name' => 'contributions',
233 'args' => ['type' => 'transactions'],
234 'aliases' => ['editTransaction']
238 'label' => _T("Add a membership fee"),
239 'title' => _T("Add new membership fee in database"),
241 'name' => 'addContribution',
242 'args' => ['type' => \Galette\Entity\Contribution
::TYPE_FEE
]
246 'label' => _T("Add a donation"),
247 'title' => _T("Add new donation in database"),
249 'name' => 'addContribution',
250 'args' => ['type' => \Galette\Entity\Contribution
::TYPE_DONATION
]
254 'label' => _T("Add a transaction"),
255 'title' => _T("Add new transaction in database"),
257 'name' => 'addTransaction'
261 'label' => _T("Reminders"),
262 'title' => _T("Send reminders to late members"),
264 'name' => 'reminders'
271 if ($login->isAdmin() ||
$login->isStaff() ||
$login->isGroupManager()) {
272 $menus['management'] = [
273 'title' => _T("Management"),
274 'icon' => 'dharmachakra',
277 'label' => _T("Manage groups"),
278 'title' => _T("View and manage groups"),
286 if ($login->isAdmin() ||
$login->isStaff()) {
287 $menus['management']['items'] = array_merge($menus['management']['items'], [
289 'label' => _T("Logs"),
290 'title' => _T("View application's logs"),
296 'label' => _T("Manage mailings"),
297 'title' => _T("Manage mailings that has been sent"),
303 'label' => _T("Exports"),
304 'title' => _T("Export some data in various formats"),
310 'label' => _T("Imports"),
311 'title' => _T("Import members from CSV files"),
314 'aliases' => ['importModel']
318 'label' => _T("Charts"),
319 'title' => _T("Various charts"),
327 if ($login->isAdmin()) {
328 $menus['configuration'] = [
329 'title' => _T("Configuration"),
333 'label' => _T("Settings"),
334 'title' => _T("Set applications preferences (address, website, member's cards configuration, ...)"),
336 'name' => 'preferences'
340 'label' => _T("Plugins"),
341 'title' => _T("Information about available plugins"),
347 'label' => _T("Core lists"),
348 'title' => _T("Customize lists fields and order"),
350 'name' => 'configureListFields',
351 'args' => ['table' => 'adherents']
355 'label' => _T("Core fields"),
356 'title' => _T("Customize fields order, set which are required, and for who they're visibles"),
358 'name' => 'configureCoreFields'
362 'label' => _T("Dynamic fields"),
363 'title' => _T("Manage additional fields for various forms"),
365 'name' => 'configureDynamicFields',
366 'aliases' => ['editDynamicField'],
370 'label' => _T("Translate labels"),
371 'title' => _T("Translate additionnals fields labels"),
373 'name' => 'dynamicTranslations'
377 'label' => _T("Manage statuses"),
379 'name' => 'entitleds',
380 'args' => ['class' => 'status'],
381 'aliases' => ['editEntitled'],
382 'sub_select' => false
386 'label' => _T("Contributions types"),
387 'title' => _T("Manage contributions types"),
389 'name' => 'entitleds',
390 'args' => ['class' => 'contributions-types']
394 'label' => _T("Emails content"),
395 'title' => _T("Manage emails texts and subjects"),
401 'label' => _T("Titles"),
402 'title' => _T("Manage titles"),
405 'aliases' => ['editTitle']
409 'label' => _T("PDF models"),
410 'title' => _T("Manage PDF models"),
412 'name' => 'pdfModels'
416 'label' => _T("Payment types"),
417 'title' => _T("Manage payment types"),
419 'name' => 'paymentTypes',
420 'aliases' => ['editPaymentType']
424 'label' => _T("Empty adhesion form"),
425 'title' => _T("Download empty adhesion form"),
427 'name' => 'emptyAdhesionForm'
433 if ($login->isSuperAdmin()) {
434 $menus['configuration']['items'][] = [
435 'label' => _T("Admin tools"),
436 'title' => _T("Various administrative tools"),
438 'name' => 'adminTools'
446 foreach (array_keys($plugins->getModules()) as $module_id) {
447 //get plugins menus entries
448 $plugin_class = $plugins->getClassName($module_id, true);
449 if (class_exists($plugin_class)) {
450 $plugin = new $plugin_class();
451 $menus = array_merge_recursive(
459 $menus +
= static::getPublicMenus();
462 //cleanup empty entries (no items)
463 foreach ($menus as $key => $menu) {
464 if (!count($menu['items'])) {
477 public static function getPublicMenus(): array
480 * @var Preferences $preferences
482 * @var Plugins $plugins
484 global $preferences, $login, $plugins;
487 if ($preferences->showPublicPages($login)) {
489 'title' => _T("Public pages"),
490 'icon' => 'eye outline',
493 'label' => _T("Members list"),
495 'name' => 'publicList',
496 'args' => ['type' => 'list']
498 'icon' => 'address book'
501 'label' => _T("Trombinoscope"),
503 'name' => 'publicList',
504 'args' => ['type' => 'trombi']
506 'icon' => 'user friends'
511 foreach (array_keys($plugins->getModules()) as $module_id) {
512 //get plugins public menus entries
513 $plugin_class = $plugins->getClassName($module_id, true);
514 if (class_exists($plugin_class)) {
515 $plugin = new $plugin_class();
516 $menus['public']['items'] = array_merge(
517 $menus['public']['items'],
518 $plugin->getPublicMenuItems()
532 public static function getDashboards(): array
536 * @var Plugins $plugins
538 global $login, $plugins;
542 if ($login->isAdmin() ||
$login->isStaff() ||
$login->isGroupManager()) {
543 $dashboards = array_merge(
547 'label' => _T("Members"),
548 'title' => _T("View, search into and filter member's list"),
555 'label' => _T("Groups"),
556 'title' => _T("View and manage groups"),
560 'icon' => 'busts_in_silhouette'
566 if ($login->isAdmin() ||
$login->isStaff()) {
567 $dashboards = array_merge(
571 'label' => _T("Mailings"),
572 'title' => _T("Manage mailings that has been sent"),
579 'label' => _T("Contributions"),
580 'title' => _T("View and filter contributions"),
582 'name' => 'contributions',
583 'args' => ['type' => 'contributions']
588 'label' => _T("Transactions"),
589 'title' => _T("View and filter transactions"),
591 'name' => 'contributions',
592 'args' => ['type' => 'transactions']
597 'label' => _T("Reminders"),
598 'title' => _T("Send reminders to late members"),
600 'name' => 'reminders'
608 if ($login->isAdmin()) {
609 $dashboards = array_merge(
613 'label' => _T("Settings"),
614 'title' => _T("Set applications preferences (address, website, member's cards configuration, ...)"),
616 'name' => 'preferences'
618 'icon' => 'control_knobs'
621 'label' => _T("Plugins"),
622 'title' => _T("Information about available plugins"),
632 if ($login->isLogged() && !$login->isSuperAdmin()) {
634 $dashboards = array_merge(
638 'label' => _T("My information"),
639 'title' => _T("View my member card"),
643 'icon' => 'bust_in_silhouette'
646 'label' => _T("My contributions"),
647 'title' => _T("View and filter all my contributions"),
649 'name' => 'myContributions',
650 'args' => ['type' => 'contributions']
655 'label' => _T("My transactions"),
656 'title' => _T("View and filter all my transactions"),
658 'name' => 'myContributions',
659 'args' => ['type' => 'transactions']
668 foreach (array_keys($plugins->getModules()) as $module_id) {
669 //get plugins menus entries
670 $plugin_class = $plugins->getClassName($module_id, true);
671 if (class_exists($plugin_class)) {
672 /** @var GalettePlugin $plugin */
673 $plugin = new $plugin_class();
674 $dashboards = array_merge_recursive(
676 $plugin->getDashboards()
685 * Get members list actions
687 * @param Adherent $member Current member
691 public static function getListActions(Adherent
$member): array
695 * @var Plugins $plugins
697 global $login, $plugins;
701 if ($member->canEdit($login)) {
703 'label' => str_replace(
706 _T("%membername: edit information")
708 'title' => str_replace(
711 _T("%membername: edit information")
714 'name' => 'editMember',
715 'args' => ['id' => $member->id
]
717 'icon' => 'user edit'
721 if ($login->isAdmin() ||
$login->isStaff()) {
722 $actions = array_merge($actions, [
724 'label' => str_replace(
727 _T("%membername: contributions")
729 'title' => str_replace(
732 _T("%membername: contributions")
735 'name' => 'contributions',
737 "type" => "contributions",
738 "option" => "member",
739 'value' => $member->id
742 'icon' => 'receipt green'
745 'label' => str_replace(
748 _T("%membername: remove from database")
750 'title' => str_replace(
753 _T("%membername: remove from database")
756 'name' => 'removeMember',
761 'icon' => 'user times red',
762 'extra_class' => 'delete'
767 if ($login->isSuperAdmin()) {
769 'label' => str_replace(
772 _T("Log in in as %membername")
774 'title' => str_replace(
777 _T("Log in in as %membername")
780 'name' => 'impersonate',
785 'icon' => 'user secret grey'
789 foreach (array_keys($plugins->getModules()) as $module_id) {
790 //get plugins menus entries
791 $plugin_class = $plugins->getClassName($module_id, true);
792 if (class_exists($plugin_class)) {
793 /** @var GalettePlugin $plugin */
794 $plugin = new $plugin_class();
795 $actions = array_merge_recursive(
797 $plugin->getListActions($member)
805 * Get member show actions
807 * @param Adherent $member Current member
811 public static function getDetailedActions(Adherent
$member): array
815 * @var Plugins $plugins
817 global $login, $plugins;
821 //TODO: add core detailled actions
823 foreach (array_keys($plugins->getModules()) as $module_id) {
824 //get plugins menus entries
825 $plugin_class = $plugins->getClassName($module_id, true);
826 if (class_exists($plugin_class)) {
827 /** @var GalettePlugin $plugin */
828 $plugin = new $plugin_class();
829 $actions = array_merge_recursive(
831 $plugin->getDetailedActions($member)
839 * Get members list batch actions
843 public static function getBatchActions(): array
847 * @var Plugins $plugins
848 * @var Preferences $preferences
850 global $login, $plugins, $preferences;
858 $actions = array_merge(
862 'name' => 'masschange',
863 'label' => _T('Mass change'),
864 'icon' => 'user edit blue'
867 'name' => 'masscontributions',
868 'label' => _T('Mass add contributions'),
869 'icon' => 'receipt bite green'
873 'label' => _T('Delete'),
874 'icon' => 'user times red'
883 ||
$login->isGroupManager()
884 && $preferences->pref_bool_groupsmanagers_mailings
)
885 && $preferences->pref_mail_method
!= \Galette\Core\GaletteMail
::METHOD_DISABLED
888 'name' => 'sendmail',
889 'label' => _T('Mail'),
890 'icon' => 'mail bulk'
895 $login->isGroupManager()
896 && $preferences->pref_bool_groupsmanagers_exports
900 $actions = array_merge(
904 'name' => 'attendance_sheet',
905 'label' => _T('Attendance sheet'),
906 'icon' => 'file alternate'
909 'name' => 'labels__directdownload',
910 'label' => _T('Generate labels'),
911 'icon' => 'address card'
914 'name' => 'cards__directdownload',
915 'label' => _T('Generate Member Cards'),
919 'name' => 'csv__directdownload',
920 'label' => _T('Export as CSV'),
927 foreach (array_keys($plugins->getModules()) as $module_id) {
928 //get plugins menus entries
929 $plugin_class = $plugins->getClassName($module_id, true);
930 if (class_exists($plugin_class)) {
931 /** @var GalettePlugin $plugin */
932 $plugin = new $plugin_class();
933 $actions = array_merge_recursive(
935 $plugin->getBatchActions()
943 * Is demonstration mode enabled
947 public static function isDemo(): bool
949 return GALETTE_MODE
=== static::MODE_DEMO
;
953 * Is debug mode enabled
957 public static function isDebugEnabled(): bool
959 return GALETTE_MODE
=== static::MODE_DEV
;
963 * Is SQL debug mode enabled
967 public static function isSqlDebugEnabled(): bool
969 return defined('GALETTE_SQL_DEBUG') ||
static::isDebugEnabled();
977 public static function isNightly(): bool
979 return GALETTE_NIGHTLY
!== false;