forked from spiegel/seminars
-
Notifications
You must be signed in to change notification settings - Fork 0
/
class.tx_seminars_flexForms.php
131 lines (118 loc) · 3.85 KB
/
class.tx_seminars_flexForms.php
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
<?php
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
/**
* This class is needed to dynamically create the list of selectable database
* columns for the pi1 flex forms.
*
* @package TYPO3
* @subpackage tx_seminars
*
* @author Niels Pardon <mail@niels-pardon.de>
*/
class tx_seminars_flexForms {
/**
* Returns the configuration for the flex forms field
* "showFeUserFieldsInRegistrationsList" with the selectable database
* columns.
*
* @param array[] $configuration the flex forms configuration
*
* @return array[] the modified flex forms configuration including the selectable database columns
*/
public function getShowFeUserFieldsInRegistrationsList(array $configuration) {
foreach ($this->getColumnsOfTable('fe_users') as $column) {
$configuration['items'][] = array(0 => $column, 1 => $column);
}
return $configuration;
}
/**
* Returns the configuration for the flex forms field
* "showRegistrationFieldsInRegistrationList" with the selectable database
* columns.
*
* @param array[] $configuration the flex forms configuration
*
* @return array[] the modified flex forms configuration including the selectable database columns
*/
public function getShowRegistrationFieldsInRegistrationList(array $configuration) {
foreach ($this->getColumnsOfTable('tx_seminars_attendances') as $column) {
$configuration['items'][] = array(0 => $column, 1 => $column);
}
return $configuration;
}
/**
* Returns the column names of the table given in the first parameter
* $tableName.
*
* @param string $tableName the table name to get the columns for, must not be empty
*
* @return string[] the column names of the given table name, may not be empty
*/
private function getColumnsOfTable($tableName) {
if ($tableName == '') {
throw new InvalidArgumentException('The first parameter $tableName must not be empty.', 1333291708);
}
$columns = $GLOBALS['TYPO3_DB']->admin_get_fields($tableName);
return array_keys($columns);
}
/**
* Returns the items of the given table for the flexforms.
*
* The table to retrieve the items for must have a title column.
*
* The given configuration array must apply to the following convention:
* - the sub-arrays "config", "row" and "items" must exist
* - "config" must have an element "itemTable" with a valid table name of a
* table which has a title column
* - "row" must have an item "pid" with the current page ID
*
* @param array[] $configuration the flexforms configuration
*
* @return array[] the modified flexforms configuration including the items available for selection
*/
public function getEntriesFromGeneralStoragePage(array $configuration) {
$whereClause = '1 = 1';
$table = $configuration['config']['itemTable'];
if (tx_oelib_configurationProxy::getInstance('seminars')
->getAsBoolean('useStoragePid')
) {
$rootlinePages = t3lib_befunc::BEgetRootLine(
$configuration['row']['pid']
);
foreach ($rootlinePages as $page) {
$storagePid = (int)$page['storage_pid'];
if ($storagePid > 0) {
$whereClause = '(' . $table . '.pid = ' . $storagePid . ')';
break;
}
}
}
$items = tx_oelib_db::selectMultiple(
'uid,title',
$table,
$whereClause . tx_oelib_db::enableFields($table),
'',
'title ASC'
);
$configuration['items'] = array();
foreach ($items as $item) {
$configuration['items'][] = array(
0 => $item['title'],
1 => $item['uid'],
2 => $GLOBALS['TCA'][$table]['ctrl']['iconfile']
);
}
return $configuration;
}
}