Completed
Push — master ( 71b299...4ab862 )
by Fabien
55:03
created
Classes/Facet/StandardFacet.php 1 patch
Indentation   +153 added lines, -153 removed lines patch added patch discarded remove patch
@@ -24,158 +24,158 @@
 block discarded – undo
24 24
 class StandardFacet implements FacetInterface
25 25
 {
26 26
 
27
-    /**
28
-     * @var string
29
-     */
30
-    protected $name;
31
-
32
-    /**
33
-     * @var string
34
-     */
35
-    protected $label;
36
-
37
-    /**
38
-     * @var array
39
-     */
40
-    protected $suggestions = array();
41
-
42
-    /**
43
-     * @var string
44
-     */
45
-    protected $dataType;
46
-
47
-    /**
48
-     * @var bool
49
-     */
50
-    protected $canModifyMatcher = false;
51
-
52
-    /**
53
-     * @var bool
54
-     */
55
-    protected $forceKeyValueObject = false;
56
-
57
-    /**
58
-     * Constructor of a Generic Facet in Vidi.
59
-     *
60
-     * @param string $name
61
-     * @param string $label
62
-     * @param array $suggestions
63
-     * @param bool $forceKeyValueObject
64
-     */
65
-    public function __construct($name, $label = '', array $suggestions = array(), $forceKeyValueObject = false)
66
-    {
67
-        $this->name = $name;
68
-        if (empty($label)) {
69
-            $label = $this->name;
70
-        }
71
-        $this->label = $label;
72
-        $this->suggestions = $suggestions;
73
-        $this->forceKeyValueObject = $forceKeyValueObject;
74
-    }
75
-
76
-    /**
77
-     * @return string
78
-     */
79
-    public function getName()
80
-    {
81
-        return $this->name;
82
-    }
83
-
84
-    /**
85
-     * @return string
86
-     */
87
-    public function getLabel()
88
-    {
89
-        if ($this->label === $this->name) {
90
-            $label = Tca::table($this->dataType)->field($this->getName())->getLabel();
91
-        } else {
92
-            $label = LocalizationUtility::translate($this->label, '');
93
-            if (empty($label)) {
94
-                $label = $this->label;
95
-            }
96
-        }
97
-
98
-        return $label;
99
-    }
100
-
101
-    /**
102
-     * @return array
103
-     */
104
-    public function getSuggestions()
105
-    {
106
-
107
-        $values = array();
108
-        foreach ($this->suggestions as $key => $label) {
109
-            $localizedLabel = $this->getLanguageService()->sL($label);
110
-            if (!empty($localizedLabel)) {
111
-                $label = $localizedLabel;
112
-            }
113
-
114
-            if ($this->forceKeyValueObject) {
115
-                $values[] = [$key => $label];
116
-            } else {
117
-
118
-                // Hack to have object correctly json encoded.
119
-                $values[$key] = $label;
120
-            }
121
-        }
122
-
123
-        return $values;
124
-    }
125
-
126
-    /**
127
-     * @return \TYPO3\CMS\Lang\LanguageService
128
-     */
129
-    protected function getLanguageService()
130
-    {
131
-        return $GLOBALS['LANG'];
132
-    }
133
-
134
-    /**
135
-     * @return bool
136
-     */
137
-    public function hasSuggestions()
138
-    {
139
-        return !empty($this->suggestions);
140
-    }
141
-
142
-    /**
143
-     * @param string $dataType
144
-     * @return $this
145
-     */
146
-    public function setDataType($dataType)
147
-    {
148
-        $this->dataType = $dataType;
149
-        return $this;
150
-    }
151
-
152
-    /**
153
-     * @return bool
154
-     */
155
-    public function canModifyMatcher()
156
-    {
157
-        return $this->canModifyMatcher;
158
-    }
159
-
160
-    /**
161
-     * @param Matcher $matcher
162
-     * @param $value
163
-     * @return Matcher
164
-     */
165
-    public function modifyMatcher(Matcher $matcher, $value)
166
-    {
167
-        return $matcher;
168
-    }
169
-
170
-    /**
171
-     * Magic method implementation for retrieving state.
172
-     *
173
-     * @param array $states
174
-     * @return StandardFacet
175
-     */
176
-    static public function __set_state($states)
177
-    {
178
-        return new StandardFacet($states['name'], $states['label'], $states['suggestions']);
179
-    }
27
+	/**
28
+	 * @var string
29
+	 */
30
+	protected $name;
31
+
32
+	/**
33
+	 * @var string
34
+	 */
35
+	protected $label;
36
+
37
+	/**
38
+	 * @var array
39
+	 */
40
+	protected $suggestions = array();
41
+
42
+	/**
43
+	 * @var string
44
+	 */
45
+	protected $dataType;
46
+
47
+	/**
48
+	 * @var bool
49
+	 */
50
+	protected $canModifyMatcher = false;
51
+
52
+	/**
53
+	 * @var bool
54
+	 */
55
+	protected $forceKeyValueObject = false;
56
+
57
+	/**
58
+	 * Constructor of a Generic Facet in Vidi.
59
+	 *
60
+	 * @param string $name
61
+	 * @param string $label
62
+	 * @param array $suggestions
63
+	 * @param bool $forceKeyValueObject
64
+	 */
65
+	public function __construct($name, $label = '', array $suggestions = array(), $forceKeyValueObject = false)
66
+	{
67
+		$this->name = $name;
68
+		if (empty($label)) {
69
+			$label = $this->name;
70
+		}
71
+		$this->label = $label;
72
+		$this->suggestions = $suggestions;
73
+		$this->forceKeyValueObject = $forceKeyValueObject;
74
+	}
75
+
76
+	/**
77
+	 * @return string
78
+	 */
79
+	public function getName()
80
+	{
81
+		return $this->name;
82
+	}
83
+
84
+	/**
85
+	 * @return string
86
+	 */
87
+	public function getLabel()
88
+	{
89
+		if ($this->label === $this->name) {
90
+			$label = Tca::table($this->dataType)->field($this->getName())->getLabel();
91
+		} else {
92
+			$label = LocalizationUtility::translate($this->label, '');
93
+			if (empty($label)) {
94
+				$label = $this->label;
95
+			}
96
+		}
97
+
98
+		return $label;
99
+	}
100
+
101
+	/**
102
+	 * @return array
103
+	 */
104
+	public function getSuggestions()
105
+	{
106
+
107
+		$values = array();
108
+		foreach ($this->suggestions as $key => $label) {
109
+			$localizedLabel = $this->getLanguageService()->sL($label);
110
+			if (!empty($localizedLabel)) {
111
+				$label = $localizedLabel;
112
+			}
113
+
114
+			if ($this->forceKeyValueObject) {
115
+				$values[] = [$key => $label];
116
+			} else {
117
+
118
+				// Hack to have object correctly json encoded.
119
+				$values[$key] = $label;
120
+			}
121
+		}
122
+
123
+		return $values;
124
+	}
125
+
126
+	/**
127
+	 * @return \TYPO3\CMS\Lang\LanguageService
128
+	 */
129
+	protected function getLanguageService()
130
+	{
131
+		return $GLOBALS['LANG'];
132
+	}
133
+
134
+	/**
135
+	 * @return bool
136
+	 */
137
+	public function hasSuggestions()
138
+	{
139
+		return !empty($this->suggestions);
140
+	}
141
+
142
+	/**
143
+	 * @param string $dataType
144
+	 * @return $this
145
+	 */
146
+	public function setDataType($dataType)
147
+	{
148
+		$this->dataType = $dataType;
149
+		return $this;
150
+	}
151
+
152
+	/**
153
+	 * @return bool
154
+	 */
155
+	public function canModifyMatcher()
156
+	{
157
+		return $this->canModifyMatcher;
158
+	}
159
+
160
+	/**
161
+	 * @param Matcher $matcher
162
+	 * @param $value
163
+	 * @return Matcher
164
+	 */
165
+	public function modifyMatcher(Matcher $matcher, $value)
166
+	{
167
+		return $matcher;
168
+	}
169
+
170
+	/**
171
+	 * Magic method implementation for retrieving state.
172
+	 *
173
+	 * @param array $states
174
+	 * @return StandardFacet
175
+	 */
176
+	static public function __set_state($states)
177
+	{
178
+		return new StandardFacet($states['name'], $states['label'], $states['suggestions']);
179
+	}
180 180
 
181 181
 }
Please login to merge, or discard this patch.
Classes/Facet/FacetSuggestionService.php 1 patch
Indentation   +108 added lines, -108 removed lines patch added patch discarded remove patch
@@ -25,113 +25,113 @@
 block discarded – undo
25 25
 class FacetSuggestionService
26 26
 {
27 27
 
28
-    /**
29
-     * Retrieve possible suggestions for a field name
30
-     *
31
-     * @param string $fieldNameAndPath
32
-     * @return array
33
-     * @throws \Exception
34
-     */
35
-    public function getSuggestions($fieldNameAndPath)
36
-    {
37
-
38
-        $values = array();
39
-
40
-        $dataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath);
41
-        $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath);
42
-
43
-        if (Tca::grid()->facet($fieldNameAndPath)->hasSuggestions()) {
44
-            $values = Tca::grid()->facet($fieldNameAndPath)->getSuggestions();
45
-        } else if (Tca::table($dataType)->hasField($fieldName)) {
46
-
47
-            if (Tca::table($dataType)->field($fieldName)->hasRelation()) {
48
-
49
-                // Fetch the adequate repository
50
-                $foreignTable = Tca::table($dataType)->field($fieldName)->getForeignTable();
51
-                $contentRepository = ContentRepositoryFactory::getInstance($foreignTable);
52
-                $table = Tca::table($foreignTable);
53
-
54
-                // Initialize the matcher object.
55
-                $matcher = MatcherObjectFactory::getInstance()->getMatcher(array(), $foreignTable);
56
-
57
-                $numberOfValues = $contentRepository->countBy($matcher);
58
-                if ($numberOfValues <= $this->getLimit()) {
59
-
60
-                    $contents = $contentRepository->findBy($matcher);
61
-
62
-                    foreach ($contents as $content) {
63
-                        $values[] = array($content->getUid() => $content[$table->getLabelField()]);
64
-                    }
65
-                }
66
-            } elseif (!Tca::table($dataType)->field($fieldName)->isTextArea()) { // We don't want suggestion if field is text area.
67
-
68
-                // Fetch the adequate repository
69
-                /** @var \Fab\Vidi\Domain\Repository\ContentRepository $contentRepository */
70
-                $contentRepository = ContentRepositoryFactory::getInstance($dataType);
71
-
72
-                // Initialize some objects related to the query
73
-                $matcher = MatcherObjectFactory::getInstance()->getMatcher(array(), $dataType);
74
-
75
-                // Count the number of objects.
76
-                $numberOfValues = $contentRepository->countDistinctValues($fieldName, $matcher);
77
-
78
-                // Only returns suggestion if there are not too many for the browser.
79
-                if ($numberOfValues <= $this->getLimit()) {
80
-
81
-                    // Query the repository.
82
-                    $contents = $contentRepository->findDistinctValues($fieldName, $matcher);
83
-
84
-                    foreach ($contents as $content) {
85
-
86
-                        $value = $content[$fieldName];
87
-                        $label = $content[$fieldName];
88
-                        if (Tca::table($dataType)->field($fieldName)->isSelect()) {
89
-                            $label = Tca::table($dataType)->field($fieldName)->getLabelForItem($value);
90
-                        }
91
-
92
-                        $values[] = $label;
93
-                    }
94
-                }
95
-            }
96
-        }
97
-        return $values;
98
-    }
99
-
100
-    /**
101
-     * Return from settings the suggestion limit.
102
-     *
103
-     * @return int
104
-     */
105
-    protected function getLimit()
106
-    {
107
-        $settings = $this->getSettings();
108
-        $suggestionLimit = (int)$settings['suggestionLimit'];
109
-        if ($suggestionLimit <= 0) {
110
-            $suggestionLimit = 1000;
111
-        }
112
-        return $suggestionLimit;
113
-    }
114
-
115
-    /**
116
-     * @return \Fab\Vidi\Resolver\FieldPathResolver
117
-     */
118
-    protected function getFieldPathResolver()
119
-    {
120
-        return GeneralUtility::makeInstance('Fab\Vidi\Resolver\FieldPathResolver');
121
-    }
122
-
123
-    /**
124
-     * Returns the module settings.
125
-     *
126
-     * @return array
127
-     */
128
-    protected function getSettings()
129
-    {
130
-        /** @var \TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager $backendConfigurationManager */
131
-        $objectManager = GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');
132
-        $backendConfigurationManager = $objectManager->get('TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager');
133
-        $configuration = $backendConfigurationManager->getTypoScriptSetup();
134
-        return $configuration['module.']['tx_vidi.']['settings.'];
135
-    }
28
+	/**
29
+	 * Retrieve possible suggestions for a field name
30
+	 *
31
+	 * @param string $fieldNameAndPath
32
+	 * @return array
33
+	 * @throws \Exception
34
+	 */
35
+	public function getSuggestions($fieldNameAndPath)
36
+	{
37
+
38
+		$values = array();
39
+
40
+		$dataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath);
41
+		$fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath);
42
+
43
+		if (Tca::grid()->facet($fieldNameAndPath)->hasSuggestions()) {
44
+			$values = Tca::grid()->facet($fieldNameAndPath)->getSuggestions();
45
+		} else if (Tca::table($dataType)->hasField($fieldName)) {
46
+
47
+			if (Tca::table($dataType)->field($fieldName)->hasRelation()) {
48
+
49
+				// Fetch the adequate repository
50
+				$foreignTable = Tca::table($dataType)->field($fieldName)->getForeignTable();
51
+				$contentRepository = ContentRepositoryFactory::getInstance($foreignTable);
52
+				$table = Tca::table($foreignTable);
53
+
54
+				// Initialize the matcher object.
55
+				$matcher = MatcherObjectFactory::getInstance()->getMatcher(array(), $foreignTable);
56
+
57
+				$numberOfValues = $contentRepository->countBy($matcher);
58
+				if ($numberOfValues <= $this->getLimit()) {
59
+
60
+					$contents = $contentRepository->findBy($matcher);
61
+
62
+					foreach ($contents as $content) {
63
+						$values[] = array($content->getUid() => $content[$table->getLabelField()]);
64
+					}
65
+				}
66
+			} elseif (!Tca::table($dataType)->field($fieldName)->isTextArea()) { // We don't want suggestion if field is text area.
67
+
68
+				// Fetch the adequate repository
69
+				/** @var \Fab\Vidi\Domain\Repository\ContentRepository $contentRepository */
70
+				$contentRepository = ContentRepositoryFactory::getInstance($dataType);
71
+
72
+				// Initialize some objects related to the query
73
+				$matcher = MatcherObjectFactory::getInstance()->getMatcher(array(), $dataType);
74
+
75
+				// Count the number of objects.
76
+				$numberOfValues = $contentRepository->countDistinctValues($fieldName, $matcher);
77
+
78
+				// Only returns suggestion if there are not too many for the browser.
79
+				if ($numberOfValues <= $this->getLimit()) {
80
+
81
+					// Query the repository.
82
+					$contents = $contentRepository->findDistinctValues($fieldName, $matcher);
83
+
84
+					foreach ($contents as $content) {
85
+
86
+						$value = $content[$fieldName];
87
+						$label = $content[$fieldName];
88
+						if (Tca::table($dataType)->field($fieldName)->isSelect()) {
89
+							$label = Tca::table($dataType)->field($fieldName)->getLabelForItem($value);
90
+						}
91
+
92
+						$values[] = $label;
93
+					}
94
+				}
95
+			}
96
+		}
97
+		return $values;
98
+	}
99
+
100
+	/**
101
+	 * Return from settings the suggestion limit.
102
+	 *
103
+	 * @return int
104
+	 */
105
+	protected function getLimit()
106
+	{
107
+		$settings = $this->getSettings();
108
+		$suggestionLimit = (int)$settings['suggestionLimit'];
109
+		if ($suggestionLimit <= 0) {
110
+			$suggestionLimit = 1000;
111
+		}
112
+		return $suggestionLimit;
113
+	}
114
+
115
+	/**
116
+	 * @return \Fab\Vidi\Resolver\FieldPathResolver
117
+	 */
118
+	protected function getFieldPathResolver()
119
+	{
120
+		return GeneralUtility::makeInstance('Fab\Vidi\Resolver\FieldPathResolver');
121
+	}
122
+
123
+	/**
124
+	 * Returns the module settings.
125
+	 *
126
+	 * @return array
127
+	 */
128
+	protected function getSettings()
129
+	{
130
+		/** @var \TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager $backendConfigurationManager */
131
+		$objectManager = GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');
132
+		$backendConfigurationManager = $objectManager->get('TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager');
133
+		$configuration = $backendConfigurationManager->getTypoScriptSetup();
134
+		return $configuration['module.']['tx_vidi.']['settings.'];
135
+	}
136 136
 
137 137
 }
Please login to merge, or discard this patch.