namespace Civi\Api4\Generic;
-use Civi\Api4\Utils\SelectUtil;
-
/**
* Base class for all `Get` api actions.
*
* @package Civi\Api4\Generic
- *
- * @method $this setSelect(array $selects) Set array of fields to be selected (wildcard * allowed)
- * @method array getSelect()
*/
abstract class AbstractGetAction extends AbstractQueryAction {
- /**
- * Fields to return for each $ENTITY. Defaults to all fields `[*]`.
- *
- * Use the * wildcard by itself to select all available fields, or use it to match similarly-named fields.
- * E.g. `is_*` will match fields named is_primary, is_active, etc.
- *
- * Set to `["row_count"]` to return only the number of $ENTITIES found.
- *
- * @var array
- */
- protected $select = [];
+ use Traits\SelectParamTrait;
/**
* Only return the number of found items.
}
}
- /**
- * Adds all fields matched by the * wildcard
- *
- * @throws \API_Exception
- */
- protected function expandSelectClauseWildcards() {
- $wildFields = array_filter($this->select, function($item) {
- return strpos($item, '*') !== FALSE && strpos($item, '.') === FALSE && strpos($item, '(') === FALSE && strpos($item, ' ') === FALSE;
- });
- foreach ($wildFields as $item) {
- $pos = array_search($item, array_values($this->select));
- $matches = SelectUtil::getMatchingFields($item, array_column($this->entityFields(), 'name'));
- array_splice($this->select, $pos, 1, $matches);
- }
- $this->select = array_unique($this->select);
- }
-
/**
* Helper to parse the WHERE param for getRecords to perform simple pre-filtering.
*
return FALSE;
}
- /**
- * Add one or more fields to be selected (wildcard * allowed)
- * @param string ...$fieldNames
- * @return $this
- */
- public function addSelect(string ...$fieldNames) {
- $this->select = array_merge($this->select, $fieldNames);
- return $this;
- }
-
}