3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
6 * Galette application instance
10 * Copyright © 2020-2022 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-2022 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-2022 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 gith 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 (GALETTE_NIGHTLY
!== false) {
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"),
193 'title' => _T("Saved searches"),
204 ||
($login->isGroupManager() && $preferences->pref_bool_groupsmanagers_create_member
)
206 $menus['members']['items'][] = [
207 'label' => _T("Add a member"),
208 'title' => _T("Add new member in database"),
210 'name' => 'addMember'
215 if ($login->isAdmin() ||
$login->isStaff()) {
216 $menus['contributions'] = [
217 'title' => _T('Contributions'),
221 'label' => _T("List of contributions"),
222 'title' => _T("View and filter contributions"),
224 'name' => 'contributions',
225 'args' => ['type' => 'contributions'],
226 'aliases' => ['editContribution']
230 'label' => _T("List of transactions"),
231 'title' => _T("View and filter transactions"),
233 'name' => 'contributions',
234 'args' => ['type' => 'transactions'],
235 'aliases' => ['editTransaction']
239 'label' => _T("Add a membership fee"),
240 'title' => _T("Add new membership fee in database"),
242 'name' => 'addContribution',
243 'args' => ['type' => \Galette\Entity\Contribution
::TYPE_FEE
]
247 'label' => _T("Add a donation"),
248 'title' => _T("Add new donation in database"),
250 'name' => 'addContribution',
251 'args' => ['type' => \Galette\Entity\Contribution
::TYPE_DONATION
]
255 'label' => _T("Add a transaction"),
256 'title' => _T("Add new transaction in database"),
258 'name' => 'addTransaction'
262 'label' => _T("Reminders"),
263 'title' => _T("Send reminders to late members"),
265 'name' => 'reminders'
272 if ($login->isAdmin() ||
$login->isStaff() ||
$login->isGroupManager()) {
273 $menus['management'] = [
274 'title' => _T("Management"),
275 'icon' => 'dharmachakra',
278 'label' => _T("Manage groups"),
279 'title' => _T("View and manage groups"),
287 if ($login->isAdmin() ||
$login->isStaff()) {
288 $menus['management']['items'] = array_merge($menus['management']['items'], [
290 'label' => _T("Logs"),
291 'title' => _T("View application's logs"),
297 'label' => _T("Manage mailings"),
298 'title' => _T("Manage mailings that has been sent"),
304 'label' => _T("Exports"),
305 'title' => _T("Export some data in various formats"),
311 'label' => _T("Imports"),
312 'title' => _T("Import members from CSV files"),
315 'aliases' => ['importModel']
319 'label' => _T("Charts"),
320 'title' => _T("Various charts"),
328 if ($login->isAdmin()) {
329 $menus['configuration'] = [
330 'title' => _T("Configuration"),
334 'label' => _T("Settings"),
335 'title' => _T("Set applications preferences (address, website, member's cards configuration, ...)"),
337 'name' => 'preferences'
341 'label' => _T("Plugins"),
342 'title' => _T("Information about available plugins"),
348 'label' => _T("Core lists"),
349 'title' => _T("Customize lists fields and order"),
351 'name' => 'configureListFields',
352 'args' => ['table' => 'adherents']
356 'label' => _T("Core fields"),
357 'title' => _T("Customize fields order, set which are required, and for who they're visibles"),
359 'name' => 'configureCoreFields'
363 'label' => _T("Dynamic fields"),
364 'title' => _T("Manage additional fields for various forms"),
366 'name' => 'configureDynamicFields',
367 'aliases' => ['editDynamicField'],
371 'label' => _T("Translate labels"),
372 'title' => _T("Translate additionnals fields labels"),
374 'name' => 'dynamicTranslations'
378 'label' => _T("Manage statuses"),
379 'title' => _T("Manage statuses"),
381 'name' => 'entitleds',
382 'args' => ['class' => 'status'],
383 'aliases' => ['editEntitled'],
384 'sub_select' => false
388 'label' => _T("Contributions types"),
389 'title' => _T("Manage contributions types"),
391 'name' => 'entitleds',
392 'args' => ['class' => 'contributions-types']
396 'label' => _T("Emails content"),
397 'title' => _T("Manage emails texts and subjects"),
403 'label' => _T("Titles"),
404 'title' => _T("Manage titles"),
407 'aliases' => ['editTitle']
411 'label' => _T("PDF models"),
412 'title' => _T("Manage PDF models"),
414 'name' => 'pdfModels'
418 'label' => _T("Payment types"),
419 'title' => _T("Manage payment types"),
421 'name' => 'paymentTypes',
422 'aliases' => ['editPaymentType']
426 'label' => _T("Empty adhesion form"),
427 'title' => _T("Download empty adhesion form"),
429 'name' => 'emptyAdhesionForm'
435 if ($login->isSuperAdmin()) {
436 $menus['configuration']['items'][] = [
437 'label' => _T("Admin tools"),
438 'title' => _T("Various administrative tools"),
440 'name' => 'adminTools'
448 foreach (array_keys($plugins->getModules()) as $module_id) {
449 //get plugins menus entries
450 $plugin_class = $plugins->getClassName($module_id, true);
451 if (class_exists($plugin_class)) {
452 $plugin = new $plugin_class();
453 $menus = array_merge_recursive(
461 $menus +
= static::getPublicMenus();
464 //cleanup empty entries (no items)
465 foreach ($menus as $key => $menu) {
466 if (!count($menu['items'])) {
479 public static function getPublicMenus(): array
482 * @var Preferences $preferences
484 * @var Plugins $plugins
486 global $preferences, $login, $plugins;
489 if ($preferences->showPublicPages($login)) {
491 'title' => _T("Public pages"),
492 'icon' => 'eye outline',
495 'label' => _T("Members list"),
496 'title' => _T("Members list"),
498 'name' => 'publicList',
499 'args' => ['type' => 'list']
501 'icon' => 'address book'
504 'label' => _T("Trombinoscope"),
505 'title' => _T("Trombinoscope"),
507 'name' => 'publicList',
508 'args' => ['type' => 'trombi']
510 'icon' => 'user friends'
515 foreach (array_keys($plugins->getModules()) as $module_id) {
516 //get plugins public menus entries
517 $plugin_class = $plugins->getClassName($module_id, true);
518 if (class_exists($plugin_class)) {
519 $plugin = new $plugin_class();
520 $menus['public']['items'] = array_merge(
521 $menus['public']['items'],
522 $plugin->getPublicMenuItems()
536 public static function getDashboards(): array
540 * @var Plugins $plugins
542 global $login, $plugins;
546 if ($login->isAdmin() ||
$login->isStaff() ||
$login->isGroupManager()) {
547 $dashboards = array_merge(
551 'label' => _T("Members"),
552 'title' => _T("View, search into and filter member's list"),
559 'label' => _T("Groups"),
560 'title' => _T("View and manage groups"),
564 'icon' => 'busts_in_silhouette'
570 if ($login->isAdmin() ||
$login->isStaff()) {
571 $dashboards = array_merge(
575 'label' => _T("Mailings"),
576 'title' => _T("Manage mailings that has been sent"),
583 'label' => _T("Contributions"),
584 'title' => _T("View and filter contributions"),
586 'name' => 'contributions',
587 'args' => ['type' => 'contributions']
592 'label' => _T("Transactions"),
593 'title' => _T("View and filter transactions"),
595 'name' => 'contributions',
596 'args' => ['type' => 'transactions']
601 'label' => _T("Reminders"),
602 'title' => _T("Send reminders to late members"),
604 'name' => 'reminders'
612 if ($login->isAdmin()) {
613 $dashboards = array_merge(
617 'label' => _T("Settings"),
618 'title' => _T("Set applications preferences (address, website, member's cards configuration, ...)"),
620 'name' => 'preferences'
622 'icon' => 'control_knobs'
625 'label' => _T("Plugins"),
626 'title' => _T("Information about available plugins"),
636 if (!$login->isAdmin() && !$login->isStaff() && !$login->isGroupManager()) {
638 $dashboards = array_merge(
642 'label' => _T("My information"),
643 'title' => _T("View my member card"),
647 'icon' => 'bust_in_silhouette'
650 'label' => _T("My contributions"),
651 'title' => _T("View and filter all my contributions"),
653 'name' => 'contributions',
654 'args' => ['type' => 'contributions']
659 'label' => _T("My transactions"),
660 'title' => _T("View and filter all my transactions"),
662 'name' => 'contributions',
663 'args' => ['type' => 'transactions']
672 foreach (array_keys($plugins->getModules()) as $module_id) {
673 //get plugins menus entries
674 $plugin_class = $plugins->getClassName($module_id, true);
675 if (class_exists($plugin_class)) {
676 /** @var GalettePlugin $plugin */
677 $plugin = new $plugin_class();
678 $dashboards = array_merge_recursive(
680 $plugin->getDashboards()
689 * Get members list actions
691 * @param Adherent $member Current member
695 public static function getListActions(Adherent
$member): array
699 * @var Plugins $plugins
701 global $login, $plugins;
705 if ($member->canEdit($login)) {
707 'label' => str_replace(
710 _T("%membername: edit information")
712 'title' => str_replace(
715 _T("%membername: edit information")
718 'name' => 'editMember',
719 'args' => ['id' => $member->id
]
721 'icon' => 'user edit'
725 if ($login->isAdmin() ||
$login->isStaff()) {
726 $actions = array_merge($actions, [
728 'label' => str_replace(
731 _T("%membername: contributions")
733 'title' => str_replace(
736 _T("%membername: contributions")
739 'name' => 'contributions',
741 "type" => "contributions",
742 "option" => "member",
743 'value' => $member->id
746 'icon' => 'receipt yellow'
749 'label' => str_replace(
752 _T("%membername: remove from database")
754 'title' => str_replace(
757 _T("%membername: remove from database")
760 'name' => 'removeMember',
765 'icon' => 'user times red',
766 'extra_class' => 'delete'
771 if ($login->isSuperAdmin()) {
773 'label' => str_replace(
776 _T("Log in in as %membername")
778 'title' => str_replace(
781 _T("Log in in as %membername")
784 'name' => 'impersonate',
789 'icon' => 'user secret grey'
793 foreach (array_keys($plugins->getModules()) as $module_id) {
794 //get plugins menus entries
795 $plugin_class = $plugins->getClassName($module_id, true);
796 if (class_exists($plugin_class)) {
797 /** @var GalettePlugin $plugin */
798 $plugin = new $plugin_class();
799 $actions = array_merge_recursive(
801 $plugin->getListActions($member)
809 * Get member show actions
811 * @param Adherent $member Current member
815 public static function getDetailedActions(Adherent
$member): array
819 * @var Plugins $plugins
821 global $login, $plugins;
825 //TODO: add core detailled actions
827 foreach (array_keys($plugins->getModules()) as $module_id) {
828 //get plugins menus entries
829 $plugin_class = $plugins->getClassName($module_id, true);
830 if (class_exists($plugin_class)) {
831 /** @var GalettePlugin $plugin */
832 $plugin = new $plugin_class();
833 $actions = array_merge_recursive(
835 $plugin->getDetailedActions($member)
843 * Get members list batch actions
847 public static function getBatchActions(): array
851 * @var Plugins $plugins
852 * @var Preferences $preferences
854 global $login, $plugins, $preferences;
862 $actions = array_merge(
866 'name' => 'masschange',
867 'label' => _T('Mass change'),
868 'icon' => 'user edit blue'
871 'name' => 'masscontributions',
872 'label' => _T('Mass add contributions'),
873 'icon' => 'receipt bite yellow'
877 'label' => _T('Delete'),
878 'icon' => 'user times red'
887 ||
$login->isGroupManager()
888 && $preferences->pref_bool_groupsmanagers_mailings
)
889 && $preferences->pref_mail_method
!= \Galette\Core\GaletteMail
::METHOD_DISABLED
892 'name' => 'sendmail',
893 'label' => _T('Mail'),
894 'icon' => 'mail bulk'
899 $login->isGroupManager()
900 && $preferences->pref_bool_groupsmanagers_exports
904 $actions = array_merge(
908 'name' => 'attendance_sheet',
909 'label' => _T('Attendance sheet'),
910 'icon' => 'file alternate'
913 'name' => 'labels__directdownload',
914 'label' => _T('Generate labels'),
915 'icon' => 'address card'
918 'name' => 'cards__directdownload',
919 'label' => _T('Generate Member Cards'),
923 'name' => 'csv__directdownload',
924 'label' => _T('Export as CSV'),
931 foreach (array_keys($plugins->getModules()) as $module_id) {
932 //get plugins menus entries
933 $plugin_class = $plugins->getClassName($module_id, true);
934 if (class_exists($plugin_class)) {
935 /** @var GalettePlugin $plugin */
936 $plugin = new $plugin_class();
937 $actions = array_merge_recursive(
939 $plugin->getBatchActions()