4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
7 | This work is published under the GNU AGPLv3 license with some |
8 | permitted exceptions and without any warranty. For full license |
9 | and copyright information, see https://civicrm.org/licensing |
10 +--------------------------------------------------------------------+
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
22 namespace Civi\Api4\Service\Schema\Joinable
;
24 use Civi\Api4\CustomField
;
26 class CustomGroupJoinable
extends Joinable
{
31 protected $joinSide = self
::JOIN_SIDE_LEFT
;
36 * Name of the custom field column.
43 * @param bool $isMultiRecord
44 * @param string $entity
45 * @param string $columns
47 public function __construct($targetTable, $alias, $isMultiRecord, $entity, $columns) {
48 $this->entity
= $entity;
49 $this->columns
= $columns;
50 parent
::__construct($targetTable, 'entity_id', $alias);
51 $this->joinType
= $isMultiRecord ?
52 self
::JOIN_TYPE_ONE_TO_MANY
: self
::JOIN_TYPE_ONE_TO_ONE
;
58 public function getEntityFields() {
59 if (!$this->entityFields
) {
60 $fields = CustomField
::get()
61 ->setCheckPermissions(FALSE)
62 ->setSelect(['custom_group.name', 'custom_group_id', 'name', 'label', 'data_type', 'html_type', 'is_required', 'is_searchable', 'is_search_range', 'weight', 'is_active', 'is_view', 'option_group_id', 'default_value', 'date_format', 'time_format', 'start_date_years', 'end_date_years'])
63 ->addWhere('custom_group.table_name', '=', $this->getTargetTable())
65 foreach ($fields as $field) {
66 $this->entityFields
[] = \Civi\Api4\Service\Spec\SpecFormatter
::arrayToField($field, $this->getEntity());
69 return $this->entityFields
;
75 public function getField($fieldName) {
76 foreach ($this->getEntityFields() as $field) {
77 $name = $field->getName();
78 if ($name === $fieldName ||
strrpos($name, '.' . $fieldName) === strlen($name) - strlen($fieldName) - 1) {
88 public function getSqlColumn($fieldName) {
89 if (strpos($fieldName, '.') !== FALSE) {
90 $fieldName = substr($fieldName, 1 +
strrpos($fieldName, '.'));
92 return $this->columns
[$fieldName];