1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
<?php
/**
* MvvContactRange.php
*
* 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 2 of
* the License, or (at your option) any later version.
*
* @author Timo Hartge <hartge@data-quest.de>
* @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
* @category Stud.IP
* @since 4.5
*
* @property string $id
* @property string $contact_range_id
* @property string $contact_id
* @property string $range_id
* @property string $range_type
* @property string $type
* @property string $category
* @property int|null $position
* @property string $author_id
* @property string $editor_id
* @property int $mkdate
* @property int $chdate
*
* @property MvvContact $contact
*
* @property int $count_relations
* @property string $name
* @property string $contact_status
*/
class MvvContactRange extends ModuleManagementModel
{
/**
* @param array $config
*/
protected static function configure($config = array())
{
$config['db_table'] = 'mvv_contacts_ranges';
$config['belongs_to']['contact'] = array(
'class_name' => MvvContact::class,
'foreign_key' => 'contact_id',
'assoc_func' => 'findCached',
);
$config['additional_fields']['count_relations']['get'] = 'countRelations';
$config['additional_fields']['name']['get'] = 'getDisplayName';
$config['additional_fields']['contact_status']['get'] = 'getContactStatus';
parent::configure($config);
}
/**
* Returns the name of the object to display in a specific context..
*
* @return string The name for
*/
public function getDisplayName($options = null)
{
return $this->contact->name;
}
/**
* Returns the status of the contact.
*
* @return string contact status
*/
public function getContactStatus()
{
return $this->contact->contact_status;
}
/**
* Returns the number of assignments to other MVV objects.
*
* @return int Number of assignments.
*/
public function countRelations()
{
return self::countBySql("contact_id = ?", [$this->contact_id]);
}
/**
* Returns all relations of this contact grouped by object types.
*
* @return Array Relations ordered by object types
*/
public function getRelations($filter = null)
{
if (is_array($filter)) {
$ids = MvvContact::getIdsFiltered($filter, true);
$ids['contact_id'] = $this->contact_id;
$contacts = self::findBySQL('`contact_id` = :contact_id AND '
. '`category` IN (:categories) AND `range_id` IN (:ranges)', $ids);
} else {
$contacts = self::findBySQL('contact_id = ?', [$this->contact_id]);
}
$zuordnungen = [];
if (!empty($contacts)) {
foreach ($contacts as $contact) {
$zuordnungen[$contact['range_type']][$contact['range_id']][] = $contact;
}
}
return $zuordnungen;
}
/**
* Returns the number of contacts comply with the given filter parameters.
*
* @param array $filter Array of filter parameters
* @see ModuleManagementModel::getFilterSql()
* @return int The number of contacts.
*/
public static function getCount($filter = null)
{
$sql = "SELECT COUNT(DISTINCT contact_id) AS 'anz' FROM mvv_contacts
INNER JOIN auth_user_md5 ON (contact_id = user_id)
LEFT JOIN Institute ON (contact_id = Institut_id)
LEFT JOIN mvv_extern_contacts ON (contact_id = extern_contact_id)";
if ($filter) {
foreach ($filter as $column => $val) {
if ($column === null || $val === null) {
continue;
}
if (is_array($val)) {
$sql .= ' AND '. $column . ' IN('
. join(',', array_map(
function ($val) {
return DBManager::get()->quote($val);
},
$val
))
. ') ';
} else {
$sql .= ' AND '.$column.' = ? ';
$params[] = $val;
}
}
}
$ret = DBManager::get()->fetchOne($sql, $params);
return $ret['anz'];
}
/**
* Returns the rangetype of the contact.
*
* @return string Returns the name of the range.
*/
public function getRangeType()
{
return $this->range_type;
}
/**
* Returns the highest current sorting position.
*
* @param sting $range_id Id of the mvv object.
* @return int Number of the highest current sorting position.
*/
public static function getMaxSortingPos($range_id)
{
$ret = DBManager::get()->fetchOne("SELECT MAX(`position`) FROM `mvv_contacts_ranges` WHERE `range_id` = ?", [$range_id]);
return $ret['MAX(`position`)'];
}
/**
* Returns the range_type of given range.
*
* @param sting $range_id Id of the mvv object.
* @return string range_type
*/
public static function getRangeTypeByRangeId($range_id)
{
$one_contact = self::findOneBySQL('range_id =?', [$range_id]);
return $one_contact ? $one_contact->range_type : null;
}
/**
* Returns the 'PERSONEN_GRUPPEN' from mvv config of given range type.
*
* @param sting $range_type type of the mvv object.
* @return array PERSONEN_GRUPPEN
*/
public static function getCategoriesByRangetype($range_type)
{
switch ($range_type) {
case 'Modul':
return $GLOBALS['MVV_MODUL']['PERSONEN_GRUPPEN']['values'];
case 'Studiengang':
return $GLOBALS['MVV_STUDIENGANG']['PERSONEN_GRUPPEN']['values'];
case 'StudiengangTeil':
return $GLOBALS['MVV_STGTEIL']['PERSONEN_GRUPPEN']['values'];
default:
return array_merge(
$GLOBALS['MVV_STUDIENGANG']['PERSONEN_GRUPPEN']['values'],
$GLOBALS['MVV_MODUL']['PERSONEN_GRUPPEN']['values'],
$GLOBALS['MVV_STGTEIL']['PERSONEN_GRUPPEN']['values']
);
}
}
/**
* Returns the displayname of selected category.
*
* @return string displayname
*/
public function getCategoryDisplayname()
{
$cats = self::getCategoriesByRangetype($this->range_type);
return $cats[$this->category]['name'];
}
}
|