a5df96706a3c2551833e69cf5b7b6a9f391ef8c2
[TYPO3CMS/Extensions/powermailCond.git] / Classes / Utility / FieldlistingBackend.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2012 Alex Kellner <alexander.kellner@in2code.de>, in2code.de
6 *
7 * All rights reserved
8 *
9 * This script is part of the TYPO3 project. The TYPO3 project is
10 * free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * The GNU General Public License can be found at
16 * http://www.gnu.org/copyleft/gpl.html.
17 *
18 * This script is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * This copyright notice MUST APPEAR in all copies of the script!
24 ***************************************************************/
25
26
27 /**
28 * List powermail fields in Backend for powermail_cond rules
29 *
30 * @package powermail_cond
31 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
32 */
33 class Tx_PowermailCond_Utility_FieldlistingBackend {
34
35 /**
36 * show all fields in the backend
37 *
38 * @param array $params: Params
39 * @param object $pObj: Parent Object
40 * @return void
41 */
42 public function fieldname(&$params, $pObj) {
43 $where = '1';
44 if (isset($params['config']['itemsProcFuncValue'])) { // additional where clause
45 $where = 'formtype IN (' . $params['config']['itemsProcFuncValue'] . ')';
46 }
47 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
48 $select = 'uid, title',
49 $from = 'tx_powermail_fields',
50 $where .= ' AND pid = ' . intval($params['row']['pid']) . ' AND hidden = 0 AND deleted = 0',
51 $groupBy = '',
52 $orderBy = 'sorting',
53 $limit = ''
54 );
55 if ($res) {
56 $params['items'][] = array('powermail Fields', '--div--');
57 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
58 $params['items'][] = array($pObj->sL($row['title']) . ' (' . $row['uid'] . ')', $row['uid']);
59 }
60 }
61
62 if (isset($params['config']['itemsProcFunc_addFieldsets'])) { // add fieldsets to selection
63 $params['items'] = array_merge((array) $params['items'], $this->getFieldsets($params['row']['pid'])); // add some fieldsets
64 }
65 }
66
67 /**
68 * give me all fieldsets in an array
69 *
70 * @param integer $pid: Page ID
71 * @return array $arr: all fieldsets with its name and the fieldset uid
72 */
73 public function getFieldsets($pid) {
74 $arr = array();
75 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
76 $select = 'uid, title',
77 $from = 'tx_powermail_fieldsets',
78 $where .= 'pid = ' . intval($pid) . ' AND hidden = 0 AND deleted = 0',
79 $groupBy = '',
80 $orderBy = 'sorting',
81 $limit = ''
82 );
83 if ($res) {
84 $arr[] = array('powermail Fieldsets', '--div--');
85 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
86 $arr[] = array($row['title'] . ' (' . $row['uid'] . ')', 'fieldset:' . $row['uid']);
87 }
88 }
89 return $arr;
90 }
91
92 /**
93 * List values of a powermail selectorbox
94 *
95 * @param array $params: Params
96 * @param object $pObj: Parent Object
97 * @return void
98 */
99 public function valuesFromPowermailSelectbox(&$params, $pObj) {
100 // Get targetField UID
101 $gParams = t3lib_div::_GET('edit');
102 $gParams2 = $gParams['tx_powermailcond_conditions'];
103 foreach ((array) $gParams2 as $uid => $actions) {
104 $thisConditionsUid = $uid;
105 }
106 $targetField = $pObj->cachedTSconfig['tx_powermailcond_conditions:' . $thisConditionsUid]['_THIS_ROW']['targetField'];
107
108 // Read values from powermail
109 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
110 $select = 'flexform',
111 $from = 'tx_powermail_fields',
112 $where = 'uid = ' . intval($targetField),
113 $groupBy = '',
114 $orderBy = '',
115 $limit = '1'
116 );
117 if ($res) {
118 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
119 }
120
121 // Change xml to a readable format
122 $arr = (array) t3lib_div::xml2array($row['flexform']);
123 $optionlist = $arr['data']['sDEF']['lDEF']['options']['vDEF'];
124 $options = t3lib_div::trimExplode("\n", $optionlist, 1);
125
126 // write params
127 foreach ((array) $options as $option) {
128 $params['items'][] = array(htmlspecialchars($option), htmlspecialchars($option));
129 }
130 }
131 }