Debian Codegraph @

lib/types/asteriskExt.inc

raw
1 <?php
2
3 /*
4
5 This code is part of LDAP Account Manager (http://www.sourceforge.net/projects/lam)
6 Copyright (C) 2009 - 2012 Pozdnyak Pavel
7 2010 - 2026 Roland Gruber
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
23 */
24
25 /**
26 * The account type for Asterisk extensions.
27 *
28 * @package types
29 * @author Pozdnyak Pavel
30 * @author Roland Gruber
31 */
32
33 use LAM\TYPES\ConfiguredType;
34
35 /**
36 * The account type for Asterisk extensions.
37 *
38 * @package types
39 */
40 class asteriskExt extends baseType {
41
42 /**
43 * Constructs a new domain type object.
44 *
45 * @param ConfiguredType $type configuration
46 */
47 public function __construct($type) {
48 parent::__construct($type);
49 $this->LABEL_CREATE_ANOTHER_ACCOUNT = _('Create another extension');
50 $this->LABEL_BACK_TO_ACCOUNT_LIST = _('Back to extensions list');
51 }
52
53 /**
54 * {@inheritDoc}
55 */
56 public function getAlias(): string {
57 return _("Asterisk extensions");
58 }
59
60 /**
61 * {@inheritDoc}
62 */
63 public function getDescription(): string {
64 return _("Asterisk extensions entries");
65 }
66
67 /**
68 * {@inheritDoc}
69 */
70 public function getListClassName(): string {
71 return lamAsteriskExtList::class;
72 }
73
74 /**
75 * {@inheritDoc}
76 */
77 public function getDefaultListAttributes(): string {
78 return "#AstExtension;#AstContext;#member";
79 }
80
81 /**
82 * {@inheritDoc}
83 */
84 public function getTitleBarTitle(accountContainer $container): ?string {
85 $attributes = null;
86 if ($container->getAccountModule('asteriskExtension') != null) {
87 $attributes = $container->getAccountModule('asteriskExtension')->getAttributes();
88 }
89 // check if a common name is set
90 if (isset($attributes['AstExtension'][0])) {
91 return htmlspecialchars($attributes['AstExtension'][0]);
92 }
93 // new account
94 if ($container->isNewAccount) {
95 return _("New extension");
96 }
97 // fall back to default
98 return parent::getTitleBarTitle($container);
99 }
100
101 }
102
103 /**
104 * Generates the list view.
105 *
106 * @package lists
107 * @author Pozdnyak Pavel
108 *
109 */
110 class lamAsteriskExtList extends lamList {
111
112 /**
113 * Constructor
114 *
115 * @param ConfiguredType $type account type
116 */
117 public function __construct(ConfiguredType $type) {
118 parent::__construct($type);
119 $this->labels = [
120 'nav' => _("Extension count: %s"),
121 'error_noneFound' => _("No Asterisk extensions found."),
122 'newEntry' => _("New extension"),
123 'deleteEntry' => _("Delete selected extensions")
124 ];
125 }
126
127 /**
128 * {@inheritDoc}
129 */
130 protected function listGetParams(): void {
131 parent::listGetParams();
132 $this->attrArray = ["astextension", "astcontext", "member"];
133 $this->descArray = [_("Extension name"), _("Account context"), _("Owner")];
134 }
135
136 /**
137 * {@inheritDoc}
138 */
139 protected function listRefreshData(): void {
140 // configure search filter
141 $module_filter = get_ldap_filter($this->type->getId()); // basic filter is provided by modules
142 $filter = "(&" . $module_filter . $this->buildLDAPAttributeFilter() . ")";
143 $attrs = $this->attrArray;
144 $attrs[] = "astpriority";
145 $entries = searchLDAP($this->suffix, $filter, $attrs);
146 $lastError = getLastLDAPError();
147 if ($lastError != null) {
148 call_user_func_array(StatusMessage(...), $lastError);
149 }
150
151 $this->ldapEntries = $this->normalizeLdapOutput($entries);
152 $this->entries = [];
153 foreach ($this->ldapEntries as $index) {
154 $this->entries[] = $index;
155 }
156 // generate list of possible suffixes
157 $this->possibleSuffixes = $this->type->getSuffixList();
158 }
159
160 /**
161 * Groups the extensions.
162 *
163 * @param array<string, string[]|string>[] $entries extension entries
164 * @return array<string, string[]|string>[] filtered extensions
165 */
166 private function normalizeLdapOutput($entries): array {
167 $filteredEntries = [];
168 foreach ($entries as $entry) {
169 if ($entry["astpriority"][0] == '1') {
170 $filteredEntries[] = $entry;
171 }
172 }
173 return $filteredEntries;
174 }
175
176 }