ff355303c8f9d49394b6a7ffc2dd037f59e2990c
[TYPO3CMS/Extensions/static_info_tables.git] / Classes / Hook / Backend / Form / class.tx_staticinfotables_renderElement.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2013 Stanislas Rolland <typo3(arobas)sjbr.ca>
6 * All rights reserved
7 *
8 * This script is part of the Typo3 project. The Typo3 project is
9 * 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 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24 /**
25 * Custom rendering of some backend forms elements
26 *
27 */
28 class tx_staticinfotables_renderElement {
29
30 /*
31 * Add ISO codes to the label of entities
32 */
33 public function addIsoCodeToLabel ($PA, $fObj) {
34 $PA['title'] = $PA['row'][$GLOBALS['TCA'][$PA['table']]['ctrl']['label']];
35 if (TYPO3_MODE == 'BE') {
36 switch ($PA['table']) {
37 case 'static_territories':
38 case 'cc_static_territories':
39 $isoCode = $PA['row']['tr_iso_nr'];
40 if (!$isoCode) {
41 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
42 'uid,tr_iso_nr',
43 $PA['table'],
44 'uid = ' . intval($PA['row']['uid']) . t3lib_befunc::deleteClause($PA['table'])
45 );
46 $isoCode = $rows[0]['tr_iso_nr'];
47 }
48 if ($isoCode) {
49 $PA['title'] = tx_staticinfotables_div::getTitleFromIsoCode($PA['table'], $isoCode) . ' (' . $isoCode . ')';
50 }
51 break;
52 case 'static_countries':
53 case 'cc_static_countries':
54 $isoCode = $PA['row']['cn_iso_2'];
55 if (!$isoCode) {
56 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
57 'uid,cn_iso_2',
58 $PA['table'],
59 'uid = ' . intval($PA['row']['uid']) . t3lib_befunc::deleteClause($PA['table'])
60 );
61 $isoCode = $rows[0]['cn_iso_2'];
62 }
63 if ($isoCode) {
64 $PA['title'] = tx_staticinfotables_div::getTitleFromIsoCode($PA['table'], $isoCode) . ' (' . $isoCode . ')';
65 }
66 break;
67 case 'static_currencies':
68 case 'cc_static_currencies':
69 $isoCode = $PA['row']['cu_iso_3'];
70 if (!$isoCode) {
71 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
72 'uid,cu_iso_3',
73 $PA['table'],
74 'uid = ' . intval($PA['row']['uid']) . t3lib_befunc::deleteClause($PA['table'])
75 );
76 $isoCode = $rows[0]['cu_iso_3'];
77 }
78 if ($isoCode) {
79 $PA['title'] = tx_staticinfotables_div::getTitleFromIsoCode($PA['table'], $isoCode) . ' (' . $isoCode . ')';
80 }
81 break;
82 default:
83 break;
84 }
85 }
86 }
87
88 /*
89 * Sort the territories selector using the current locale
90 */
91 public function sortTerritoriesSelector ($PA, $fObj) {
92 switch ($PA['table']) {
93 case 'static_territories':
94 case 'cc_static_territories':
95 // Avoid circular relation
96 $row = $PA['row'];
97 foreach ($PA['items'] as $index => $item) {
98 if ($item[1] == $row['uid']) {
99 unset($PA['items'][$index]);
100 }
101 }
102 case 'static_countries':
103 case 'cc_static_countries':
104 asort($PA['items']);
105 break;
106 }
107 }
108
109 /*
110 * Sort the currencies selector using the current locale
111 */
112 public function sortCurrenciesSelector ($PA, $fObj) {
113 switch ($PA['table']) {
114 case 'static_currencies':
115 case 'cc_static_currencies':
116 asort($PA['items']);
117 break;
118 }
119 }
120 }
121 ?>