Skip to content
Snippets Groups Projects
Unverified Commit ad071041 authored by Eileen McNaughton's avatar Eileen McNaughton Committed by GitHub
Browse files

Merge pull request #19010 from colemanw/bridges

Use trait instead of class for Entity Bridges; add OptionList trait
parents f72d958c 465bc32a
Branches
Tags
No related merge requests found
Showing
with 62 additions and 15 deletions
......@@ -29,6 +29,7 @@ namespace Civi\Api4;
* @see \Civi\Api4\Activity
* @package Civi\Api4
*/
class ActivityContact extends Generic\BridgeEntity {
class ActivityContact extends Generic\DAOEntity {
use Generic\Traits\EntityBridge;
}
......@@ -24,5 +24,6 @@ namespace Civi\Api4;
* @package Civi\Api4
*/
class Country extends Generic\DAOEntity {
use Generic\Traits\OptionList;
}
......@@ -26,6 +26,7 @@ namespace Civi\Api4;
* @see \Civi\Api4\Dashboard
* @package Civi\Api4
*/
class DashboardContact extends Generic\BridgeEntity {
class DashboardContact extends Generic\DAOEntity {
use Generic\Traits\EntityBridge;
}
......@@ -58,8 +58,15 @@ class Entity extends Generic\AbstractEntity {
],
[
'name' => 'type',
'data_type' => 'Array',
'description' => 'Base class for this entity',
'options' => ['DAOEntity' => 'DAOEntity', 'BasicEntity' => 'BasicEntity', 'BridgeEntity' => 'BridgeEntity', 'AbstractEntity' => 'AbstractEntity'],
'options' => [
'AbstractEntity' => 'AbstractEntity',
'DAOEntity' => 'DAOEntity',
'BasicEntity' => 'BasicEntity',
'EntityBridge' => 'EntityBridge',
'OptionList' => 'OptionList',
],
],
[
'name' => 'description',
......
......@@ -25,6 +25,7 @@ namespace Civi\Api4;
*
* @package Civi\Api4
*/
class EntityTag extends Generic\BridgeEntity {
class EntityTag extends Generic\DAOEntity {
use Generic\Traits\EntityBridge;
}
......@@ -133,9 +133,12 @@ abstract class AbstractEntity {
'name' => static::getEntityName(),
'title' => static::getEntityTitle(),
'title_plural' => static::getEntityTitle(TRUE),
'type' => self::stripNamespace(get_parent_class(static::class)),
'type' => [self::stripNamespace(get_parent_class(static::class))],
'paths' => static::getEntityPaths(),
];
foreach (ReflectionUtils::getTraits(static::class) as $trait) {
$info['type'][] = self::stripNamespace($trait);
}
$reflection = new \ReflectionClass(static::class);
$info += ReflectionUtils::getCodeDocs($reflection, NULL, ['entity' => $info['name']]);
unset($info['package'], $info['method']);
......
......@@ -59,13 +59,13 @@ class DAOGetAction extends AbstractGetAction {
*
* - `Entity`: the name of the api entity to join onto.
* - `Required`: `TRUE` for an `INNER JOIN`, `FALSE` for a `LEFT JOIN`.
* - `Bridge` (optional): Name of a BridgeEntity to incorporate into the join.
* - `Bridge` (optional): Name of a Bridge to incorporate into the join.
* - `[field, op, value]...`: zero or more conditions for the ON clause, using the same nested format as WHERE and HAVING
* but with the difference that "value" is interpreted as an expression (e.g. can be the name of a field).
* Enclose literal values with quotes.
*
* @var array
* @see \Civi\Api4\Generic\BridgeEntity
* @see \Civi\Api4\Generic\Traits\EntityBridge
*/
protected $join = [];
......
......@@ -9,13 +9,13 @@
+--------------------------------------------------------------------+
*/
namespace Civi\Api4\Generic;
namespace Civi\Api4\Generic\Traits;
/**
* A bridge is a small table that provides an intermediary link between two other tables.
*
* The API can automatically incorporate a bridgeEntity into a join expression.
* The API can automatically incorporate a Bridge into a join expression.
*/
class BridgeEntity extends DAOEntity {
trait EntityBridge {
}
<?php
/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
namespace Civi\Api4\Generic\Traits;
/**
* An optionList is a small entity whose primary purpose is to supply a semi-static list of options to fields in other entities.
*
* The options appear in the field metadata for other entities that reference this one via pseudoconstant.
*/
trait OptionList {
}
......@@ -28,7 +28,8 @@ namespace Civi\Api4;
*
* @package Civi\Api4
*/
class GroupContact extends Generic\BridgeEntity {
class GroupContact extends Generic\DAOEntity {
use Generic\Traits\EntityBridge;
/**
* @param bool $checkPermissions
......
......@@ -18,5 +18,6 @@ namespace Civi\Api4;
* @package Civi\Api4
*/
class LocationType extends Generic\DAOEntity {
use Generic\Traits\OptionList;
}
......@@ -18,5 +18,6 @@ namespace Civi\Api4;
* @package Civi\Api4
*/
class MembershipType extends Generic\DAOEntity {
use Generic\Traits\OptionList;
}
......@@ -26,5 +26,6 @@ namespace Civi\Api4;
* @package Civi\Api4
*/
class OptionValue extends Generic\DAOEntity {
use Generic\Traits\OptionList;
}
......@@ -25,5 +25,6 @@ namespace Civi\Api4;
* @package Civi\Api4
*/
class PaymentProcessorType extends Generic\DAOEntity {
use Generic\Traits\OptionList;
}
......@@ -594,7 +594,7 @@ class Api4SelectQuery {
}
/**
* Join onto a BridgeEntity table
* Join onto a Bridge table
*
* @param array $joinTree
* @param string $joinEntity
......@@ -604,13 +604,15 @@ class Api4SelectQuery {
*/
protected function getBridgeJoin(&$joinTree, $joinEntity, $alias) {
$bridgeEntity = array_shift($joinTree);
if (!is_a('\Civi\Api4\\' . $bridgeEntity, '\Civi\Api4\Generic\BridgeEntity', TRUE)) {
/* @var \Civi\Api4\Generic\DAOEntity $bridgeEntityClass */
$bridgeEntityClass = '\Civi\Api4\\' . $bridgeEntity;
if (!in_array('EntityBridge', $bridgeEntityClass::getInfo()['type'], TRUE)) {
throw new \API_Exception("Illegal bridge entity specified: " . $bridgeEntity);
}
$bridgeAlias = $alias . '_via_' . strtolower($bridgeEntity);
$bridgeTable = CoreUtil::getTableName($bridgeEntity);
$joinTable = CoreUtil::getTableName($joinEntity);
$bridgeEntityGet = \Civi\API\Request::create($bridgeEntity, 'get', ['version' => 4, 'checkPermissions' => $this->getCheckPermissions()]);
$bridgeEntityGet = $bridgeEntityClass::get($this->getCheckPermissions());
$fkToJoinField = $fkToBaseField = NULL;
// Find the bridge field that links to the joinEntity (either an explicit FK or an entity_id/entity_table combo)
foreach ($bridgeEntityGet->entityFields() as $name => $field) {
......
......@@ -27,6 +27,7 @@ namespace Civi\Api4;
* @package Civi\Api4
*/
class RelationshipCache extends Generic\AbstractEntity {
use Generic\Traits\EntityBridge;
/**
* @param bool $checkPermissions
......
......@@ -27,5 +27,6 @@ namespace Civi\Api4;
* @package Civi\Api4
*/
class RelationshipType extends Generic\DAOEntity {
use Generic\Traits\OptionList;
}
......@@ -24,5 +24,6 @@ namespace Civi\Api4;
* @package Civi\Api4
*/
class StateProvince extends Generic\DAOEntity {
use Generic\Traits\OptionList;
}
......@@ -26,5 +26,6 @@ namespace Civi\Api4;
* @package Civi\Api4
*/
class UFJoin extends Generic\DAOEntity {
use Generic\Traits\EntityBridge;
}
......@@ -24,6 +24,7 @@ namespace Civi\Api4;
*
* @package Civi\Api4
*/
class UFMatch extends Generic\BridgeEntity {
class UFMatch extends Generic\DAOEntity {
use Generic\Traits\EntityBridge;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment