Debian Codegraph @

lib/types/netgroup.inc

raw
1 <?php
2 /*
3
4 This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
5 Copyright (C) 2009 - 2025 Roland Gruber
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
21 */
22
23 /**
24 * The account type for NIS netgroups.
25 *
26 * @package types
27 * @author Roland Gruber
28 */
29
30 use LAM\TYPES\ConfiguredType;
31
32 /**
33 * The account type for NIS netgroups.
34 *
35 * @package types
36 */
37 class netgroup extends baseType {
38
39 /**
40 * Constructs a new group type object.
41 *
42 * @param ConfiguredType $type configuration
43 */
44 public function __construct($type) {
45 parent::__construct($type);
46 $this->LABEL_CREATE_ANOTHER_ACCOUNT = _('Create another group');
47 $this->LABEL_BACK_TO_ACCOUNT_LIST = _('Back to group list');
48 }
49
50 /**
51 * {@inheritDoc}
52 */
53 public function getAlias(): string {
54 return _("NIS netgroups");
55 }
56
57 /**
58 * {@inheritDoc}
59 */
60 public function getDescription(): string {
61 return _("NIS netgroup entries");
62 }
63
64 /**
65 * {@inheritDoc}
66 */
67 public function getIcon(): string {
68 return 'group.svg';
69 }
70
71 /**
72 * {@inheritDoc}
73 */
74 public function getListClassName(): string {
75 return lamNetgroupList::class;
76 }
77
78 /**
79 * {@inheritDoc}
80 */
81 public function getDefaultListAttributes(): string {
82 return "#cn;#description;#memberNisNetgroup";
83 }
84
85 /**
86 * {@inheritDoc}
87 */
88 public function getTitleBarTitle(accountContainer $container): ?string {
89 // get attributes
90 $attributes = null;
91 if ($container->getAccountModule('nisnetgroup') != null) {
92 $attributes = $container->getAccountModule('nisnetgroup')->getAttributes();
93 }
94 // check if a common name is set
95 if (isset($attributes['cn'][0])) {
96 return htmlspecialchars($attributes['cn'][0]);
97 }
98 // new entry
99 if ($container->isNewAccount) {
100 return _("New group");
101 }
102 // fall back to default
103 return parent::getTitleBarTitle($container);
104 }
105
106 /**
107 * {@inheritDoc}
108 */
109 public function getTitleBarSubtitle(accountContainer $container): string {
110 // get attributes
111 $attributes = null;
112 if ($container->getAccountModule('nisnetgroup') != null) {
113 $attributes = $container->getAccountModule('nisnetgroup')->getAttributes();
114 }
115 if ($attributes == null) {
116 return '';
117 }
118 $subtitle = '';
119 // check if a description can be shown
120 if (isset($attributes['description'][0])) {
121 $subtitle .= htmlspecialchars($attributes['description'][0]);
122 }
123 return $subtitle;
124 }
125
126 }
127
128
129 /**
130 * Generates the list view.
131 *
132 * @package lists
133 * @author Roland Gruber
134 *
135 */
136 class lamNetgroupList extends lamList {
137
138 /**
139 * Constructor
140 *
141 * @param ConfiguredType $type account type
142 */
143 public function __construct(ConfiguredType $type) {
144 parent::__construct($type);
145 $this->labels = [
146 'nav' => _("Group count: %s"),
147 'error_noneFound' => _("No groups found!"),
148 'newEntry' => _("New group"),
149 'deleteEntry' => _("Delete selected groups")
150 ];
151 }
152
153 }