[TASK] Enable DataHandler frontend rendering tests
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Functional / Framework / Frontend / UserFunction.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Functional\Framework\Frontend;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2014 Oliver Hader <oliver.hader@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 /**
28 * Model of frontend response
29 */
30 class UserFunction implements \TYPO3\CMS\Core\SingletonInterface {
31
32 /**
33 * @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
34 */
35 public $cObj;
36
37 /**
38 * @param string $content
39 * @param array $configuration
40 * @return string
41 */
42 public function getManyToManyIds($content, array $configuration = NULL) {
43 $where = array();
44 $uidLocal = NULL;
45 $uidForeign = NULL;
46 $manyToManyTableName = NULL;
47
48 $uidLocal = (int)$this->getValue('uidLocal', $configuration);
49 $uidForeign = (int)$this->getValue('uidForeign', $configuration);
50 $manyToManyTableName = $this->getValue('manyToManyTableName', $configuration);
51
52 if (!($uidLocal xor $uidForeign) || empty($manyToManyTableName)) {
53 return $content;
54 }
55
56 if (!empty($uidLocal)) {
57 $selectField = 'uid_foreign';
58 $sortingField = 'sorting';
59 $where[] = 'uid_local=' . $uidLocal;
60 } else {
61 $selectField = 'uid_local';
62 $sortingField = 'sorting_foreign';
63 $where[] = 'uid_foreign=' . $uidForeign;
64 }
65
66 if (!empty($configuration['matchTableName'])) {
67 $where[] = 'tablenames=' . $this->getDatabaseConnection()->fullQuoteStr($configuration['matchTableName'], $manyToManyTableName);
68 }
69 if (!empty($configuration['matchFieldName'])) {
70 $where[] = 'fieldname=' . $this->getDatabaseConnection()->fullQuoteStr($configuration['matchFieldName'], $manyToManyTableName);
71 }
72
73 $references = $this->getDatabaseConnection()->exec_SELECTgetRows(
74 $selectField,
75 $manyToManyTableName,
76 implode(' AND ', $where),
77 '',
78 $sortingField,
79 '',
80 $selectField
81 );
82
83 if (empty($references)) {
84 return $content;
85 }
86
87 $content = implode(',', array_keys($references));
88 return $content;
89 }
90
91 /**
92 * @param string $property
93 * @param array $configuration
94 * @return string
95 */
96 protected function getValue($property, array $configuration = NULL) {
97 $value = '';
98
99 if (!empty($configuration[$property])) {
100 $value = $configuration[$property];
101 }
102 if (!empty($configuration[$property . '.'])) {
103 $value = $this->cObj->stdWrap($value, $configuration[$property . '.']);
104 }
105
106 return $value;
107 }
108
109 /**
110 * @return \TYPO3\CMS\Core\Database\DatabaseConnection
111 */
112 protected function getDatabaseConnection() {
113 return $GLOBALS['TYPO3_DB'];
114 }
115
116 }