Feature #55793 » groupings.patch

Rename "groupBy" to "groupings" - Mathias Brodala, 2014-09-02 08:54

View differences:

Classes/TYPO3/Flow/Persistence/Doctrine/Query.php
58 58
	protected $orderings;
59 59

  
60 60
	/**
61
	 * @var array
62
	 */
63
	protected $groupings;
64

  
65
	/**
61 66
	 * @var integer
62 67
	 */
63 68
	protected $limit;
......
93 98
	protected $cacheResult = FALSE;
94 99

  
95 100
	/**
96
	 * @var array
97
	 */
98
	protected $groupBy;
99

  
100
	/**
101 101
	 * @param string $entityClassName
102 102
	 */
103 103
	public function __construct($entityClassName) {
......
225 225
			if ($offset !== NULL) {
226 226
				$dqlQuery->setFirstResult(NULL);
227 227
			}
228
			if ($this->getGroupBy() !== NULL) {
228
			if ($this->getGroupings() !== NULL) {
229 229
				$numberOfResults = count($dqlQuery->getResult());
230 230
			} else {
231 231
				$numberOfResults = (int)$dqlQuery->getSingleScalarResult();
......
283 283
	}
284 284

  
285 285
	/**
286
	 * Sets the property names to group the result by. Use NULL or empty array to unset groupBy
287
	 *
288
	 * @param array $groupings
289
	 * @return \TYPO3\Flow\Persistence\QueryInterface
290
	 * @api
291
	 */
292
	public function setGroupings(array $groupings = NULL) {
293
		if (empty($groupings)) {
294
			$this->groupings = NULL;
295
		} else {
296
			$this->groupings = $groupings;
297
		}
298
		$this->queryBuilder->resetDQLPart('groupBy');
299
		if (is_array($this->groupings)) {
300
			foreach ($this->groupings as $propertyName) {
301
				$this->queryBuilder->addGroupBy($this->getPropertyNameWithAlias($propertyName));
302
			}
303
		}
304
		return $this;
305
	}
306

  
307
	/**
308
	 * Returns the property names to group the result by.
309
	 *
310
	 * @return array
311
	 * @api
312
	 */
313
	public function getGroupings() {
314
		return $this->groupings;
315
	}
316

  
317
	/**
286 318
	 * Sets the maximum size of the result set to limit. Returns $this to allow
287 319
	 * for chaining (fluid interface)
288 320
	 *
......
333 365
	}
334 366

  
335 367
	/**
336
	 * Sets the property names to group the result by. Use NULL or empty array to unset groupBy
337
	 *
338
	 * @param array $groupBy
339
	 * @return \TYPO3\Flow\Persistence\QueryInterface
340
	 * @api
341
	 */
342
	public function setGroupBy(array $groupBy = NULL) {
343
		if (empty($groupBy)) {
344
			$this->groupBy = NULL;
345
		} else {
346
			$this->groupBy = $groupBy;
347
		}
348
		$this->queryBuilder->resetDQLPart('groupBy');
349
		if (is_array($this->groupBy)) {
350
			foreach ($this->groupBy as $propertyName) {
351
				$this->queryBuilder->addGroupBy($this->getPropertyNameWithAlias($propertyName));
352
			}
353
		}
354
		return $this;
355
	}
356

  
357
	/**
358
	 * Returns the property names to group the result by.
359
	 *
360
	 * @return array
361
	 * @api
362
	 */
363
	public function getGroupBy() {
364
		return $this->groupBy;
365
	}
366

  
367
	/**
368 368
	 * The constraint used to limit the result set. Returns $this to allow
369 369
	 * for chaining (fluid interface)
370 370
	 *
......
653 653
				$this->queryBuilder->addOrderBy($aliases[0] . '.' . $propertyName, $order);
654 654
			}
655 655
		}
656
		if (is_array($this->groupBy)) {
656
		if (is_array($this->groupings)) {
657 657
			$aliases = $this->queryBuilder->getRootAliases();
658
			foreach ($this->groupBy as $propertyName) {
658
			foreach ($this->groupings as $propertyName) {
659 659
				$this->queryBuilder->addGroupBy($aliases[0] . '.' . $propertyName);
660 660
			}
661 661
		}
Tests/Functional/Persistence/Doctrine/QueryTest.php
186 186
	/**
187 187
	 * @test
188 188
	 */
189
	public function countRespectsGroupByConstraint() {
189
	public function countRespectsGroupingsConstraint() {
190 190
		$testEntityRepository = new \TYPO3\Flow\Tests\Functional\Persistence\Fixtures\TestEntityRepository();
191 191
		$testEntityRepository->removeAll();
192 192

  
......
206 206

  
207 207
		$query = new Query('TYPO3\Flow\Tests\Functional\Persistence\Fixtures\TestEntity');
208 208

  
209
		$this->assertEquals(2, $query->setGroupBy(array('name'))->execute()->count());
209
		$this->assertEquals(2, $query->setGroupings(array('name'))->execute()->count());
210 210
	}
211 211

  
212 212
	/**
213 213
	 * @test
214 214
	 */
215
	public function nullResetsGroupByConstraint() {
215
	public function nullResetsGroupingsConstraint() {
216 216
		$testEntityRepository = new \TYPO3\Flow\Tests\Functional\Persistence\Fixtures\TestEntityRepository();
217 217
		$testEntityRepository->removeAll();
218 218

  
......
232 232

  
233 233
		$query = new Query('TYPO3\Flow\Tests\Functional\Persistence\Fixtures\TestEntity');
234 234

  
235
		$this->assertEquals(3, $query->setGroupBy(array('name'))->setGroupBy(NULL)->execute()->count());
235
		$this->assertEquals(3, $query->setGroupings(array('name'))->setGroupings(NULL)->execute()->count());
236 236
	}
237 237

  
238 238
	/**
239 239
	 * @test
240 240
	 */
241
	public function emptyArrayResetsGroupByConstraint() {
241
	public function emptyArrayResetsGroupingsConstraint() {
242 242
		$testEntityRepository = new \TYPO3\Flow\Tests\Functional\Persistence\Fixtures\TestEntityRepository();
243 243
		$testEntityRepository->removeAll();
244 244

  
......
258 258

  
259 259
		$query = new Query('TYPO3\Flow\Tests\Functional\Persistence\Fixtures\TestEntity');
260 260

  
261
		$this->assertEquals(3, $query->setGroupBy(array('name'))->setGroupBy(array())->execute()->count());
261
		$this->assertEquals(3, $query->setGroupings(array('name'))->setGroupings(array())->execute()->count());
262 262
	}
263 263

  
264 264

  
......
301 301
		$this->assertEquals($expected->getOrderings(), $actual->getOrderings());
302 302
		$this->assertEquals($expected->getOffset(), $actual->getOffset());
303 303
		$this->assertEquals($expected->getLimit(), $actual->getLimit());
304
		$this->assertEquals($expected->getGroupBy(), $actual->getGroupBy());
304
		$this->assertEquals($expected->getGroupings(), $actual->getGroupings());
305 305
	}
306 306

  
307 307
}
(1-1/3)