@@ -1387,62 +1387,9 @@ public function loadRelations(
1387
1387
?int $ relationType = null
1388
1388
): array {
1389
1389
$ query = $ this ->queryBuilder ->createRelationFindQueryBuilder ();
1390
- $ expr = $ query ->expr ();
1391
- $ query
1392
- ->innerJoin (
1393
- 'l ' ,
1394
- 'ezcontentobject ' ,
1395
- 'ezcontentobject_to ' ,
1396
- $ expr ->andX (
1397
- 'l.to_contentobject_id = ezcontentobject_to.id ' ,
1398
- 'ezcontentobject_to.status = :status '
1399
- )
1400
- )
1401
- ->where (
1402
- 'l.from_contentobject_id = :content_id '
1403
- )
1404
- ->setParameter (
1405
- 'status ' ,
1406
- ContentInfo::STATUS_PUBLISHED ,
1407
- ParameterType::INTEGER
1408
- )
1409
- ->setParameter ('content_id ' , $ contentId , ParameterType::INTEGER );
1410
-
1411
- // source version number
1412
- if (null !== $ contentVersionNo ) {
1413
- $ query
1414
- ->andWhere ('l.from_contentobject_version = :version_no ' )
1415
- ->setParameter ('version_no ' , $ contentVersionNo , ParameterType::INTEGER );
1416
- } else {
1417
- // from published version only
1418
- $ query
1419
- ->innerJoin (
1420
- 'ezcontentobject_to ' ,
1421
- 'ezcontentobject ' ,
1422
- 'c ' ,
1423
- $ expr ->andX (
1424
- 'c.id = l.from_contentobject_id ' ,
1425
- 'c.current_version = l.from_contentobject_version '
1426
- )
1427
- );
1428
- }
1429
-
1430
- // relation type
1431
- if (null !== $ relationType ) {
1432
- $ query
1433
- ->andWhere (
1434
- $ expr ->gt (
1435
- $ this ->databasePlatform ->getBitAndComparisonExpression (
1436
- 'l.relation_type ' ,
1437
- ':relation_type '
1438
- ),
1439
- 0
1440
- )
1441
- )
1442
- ->setParameter ('relation_type ' , $ relationType , ParameterType::INTEGER );
1443
- }
1390
+ $ query = $ this ->prepareRelationQuery ($ query , $ contentId , $ contentVersionNo , $ relationType );
1444
1391
1445
- return $ query ->execute ()->fetchAll (FetchMode:: ASSOCIATIVE );
1392
+ return $ query ->execute ()->fetchAllAssociative ( );
1446
1393
}
1447
1394
1448
1395
public function countRelations (
@@ -1451,89 +1398,50 @@ public function countRelations(
1451
1398
?int $ relationType = null
1452
1399
): int {
1453
1400
$ query = $ this ->connection ->createQueryBuilder ();
1454
- $ expr = $ query ->expr ();
1455
- $ query
1456
- ->select ($ this ->databasePlatform ->getCountExpression ('l.id ' ))
1457
- ->from (self ::CONTENT_RELATION_TABLE , 'l ' )
1458
- ->innerJoin (
1459
- 'l ' ,
1460
- 'ezcontentobject ' ,
1461
- 'ezcontentobject_to ' ,
1462
- $ expr ->and (
1463
- 'l.to_contentobject_id = ezcontentobject_to.id ' ,
1464
- 'ezcontentobject_to.status = :status '
1465
- )
1466
- )
1467
- ->andWhere (
1468
- 'l.from_contentobject_id = :content_id '
1469
- )
1470
- ->setParameter (
1471
- 'status ' ,
1472
- ContentInfo::STATUS_PUBLISHED ,
1473
- ParameterType::INTEGER
1474
- )
1475
- ->setParameter ('content_id ' , $ contentId , ParameterType::INTEGER );
1476
-
1477
- // source version number
1478
- if (null !== $ contentVersionNo ) {
1479
- $ query
1480
- ->andWhere ('l.from_contentobject_version = :version_no ' )
1481
- ->setParameter ('version_no ' , $ contentVersionNo , ParameterType::INTEGER );
1482
- } else {
1483
- // from published version only
1484
- $ query
1485
- ->innerJoin (
1486
- 'ezcontentobject_to ' ,
1487
- 'ezcontentobject ' ,
1488
- 'c ' ,
1489
- $ expr ->and (
1490
- 'c.id = l.from_contentobject_id ' ,
1491
- 'c.current_version = l.from_contentobject_version '
1492
- )
1493
- );
1494
- }
1401
+ $ query ->select ($ this ->databasePlatform ->getCountExpression ('l.id ' ))
1402
+ ->from (self ::CONTENT_RELATION_TABLE , 'l ' );
1495
1403
1496
- // relation type
1497
- if (null !== $ relationType ) {
1498
- $ query
1499
- ->andWhere (
1500
- $ expr ->gt (
1501
- $ this ->databasePlatform ->getBitAndComparisonExpression (
1502
- 'l.relation_type ' ,
1503
- ':relation_type '
1504
- ),
1505
- 0
1506
- )
1507
- )
1508
- ->setParameter ('relation_type ' , $ relationType , ParameterType::INTEGER );
1509
- }
1404
+ $ query = $ this ->prepareRelationQuery ($ query , $ contentId , $ contentVersionNo , $ relationType );
1510
1405
1511
1406
return (int )$ query ->execute ()->fetchOne ();
1512
1407
}
1513
1408
1514
- /**
1515
- * {@inheritdoc}
1516
- */
1517
1409
public function listRelations (
1518
1410
int $ contentId ,
1411
+ int $ limit ,
1519
1412
int $ offset = 0 ,
1520
- ?int $ limit = null ,
1521
1413
?int $ contentVersionNo = null ,
1522
1414
?int $ relationType = null
1523
1415
): array {
1524
1416
$ query = $ this ->queryBuilder ->createRelationFindQueryBuilder ();
1417
+ $ query = $ this ->prepareRelationQuery ($ query , $ contentId , $ contentVersionNo , $ relationType );
1418
+
1419
+ $ query ->setFirstResult ($ offset )
1420
+ ->setMaxResults ($ limit );
1421
+
1422
+ $ query ->orderBy ('l.id ' , 'DESC ' );
1423
+
1424
+ return $ query ->execute ()->fetchAllAssociative ();
1425
+ }
1426
+
1427
+ private function prepareRelationQuery (
1428
+ DoctrineQueryBuilder $ query ,
1429
+ int $ contentId ,
1430
+ ?int $ contentVersionNo = null ,
1431
+ ?int $ relationType = null
1432
+ ): DoctrineQueryBuilder {
1525
1433
$ expr = $ query ->expr ();
1526
1434
$ query
1527
1435
->innerJoin (
1528
1436
'l ' ,
1529
- ' ezcontentobject ' ,
1437
+ self :: CONTENT_ITEM_TABLE ,
1530
1438
'ezcontentobject_to ' ,
1531
1439
$ expr ->and (
1532
- $ expr -> eq ( 'l.to_contentobject_id ' , ' ezcontentobject_to.id ') ,
1533
- $ expr -> eq ( 'ezcontentobject_to.status ' , ' :status '),
1440
+ 'l.to_contentobject_id = ezcontentobject_to.id ' ,
1441
+ 'ezcontentobject_to.status = :status '
1534
1442
)
1535
1443
)
1536
- ->andWhere (
1444
+ ->where (
1537
1445
'l.from_contentobject_id = :content_id '
1538
1446
)
1539
1447
->setParameter (
@@ -1544,7 +1452,7 @@ public function listRelations(
1544
1452
->setParameter ('content_id ' , $ contentId , ParameterType::INTEGER );
1545
1453
1546
1454
// source version number
1547
- if (null !== $ contentVersionNo ) {
1455
+ if ($ contentVersionNo !== null ) {
1548
1456
$ query
1549
1457
->andWhere ('l.from_contentobject_version = :version_no ' )
1550
1458
->setParameter ('version_no ' , $ contentVersionNo , ParameterType::INTEGER );
@@ -1553,11 +1461,11 @@ public function listRelations(
1553
1461
$ query
1554
1462
->innerJoin (
1555
1463
'ezcontentobject_to ' ,
1556
- ' ezcontentobject ' ,
1464
+ self :: CONTENT_ITEM_TABLE ,
1557
1465
'c ' ,
1558
1466
$ expr ->and (
1559
- $ expr -> eq ( 'c.id ' , ' l.from_contentobject_id ') ,
1560
- $ expr -> eq ( 'c.current_version ' , ' l.from_contentobject_version '),
1467
+ 'c.id = l.from_contentobject_id ' ,
1468
+ 'c.current_version = l.from_contentobject_version '
1561
1469
)
1562
1470
);
1563
1471
}
@@ -1577,14 +1485,7 @@ public function listRelations(
1577
1485
->setParameter ('relation_type ' , $ relationType , ParameterType::INTEGER );
1578
1486
}
1579
1487
1580
- $ query ->setFirstResult ($ offset );
1581
- if ($ limit !== null ) {
1582
- $ query ->setMaxResults ($ limit );
1583
- }
1584
-
1585
- $ query ->orderBy ('l.id ' , 'DESC ' );
1586
-
1587
- return $ query ->execute ()->fetchAllAssociative ();
1488
+ return $ query ;
1588
1489
}
1589
1490
1590
1491
public function countReverseRelations (int $ toContentId , ?int $ relationType = null ): int
0 commit comments