getBaoName(); if (!$baoName) { // In some cases (eg. site spin-up) the code may attempt to call the api before the entity name is registered. throw new \API_Exception("BAO for {$this->getEntityName()} is not available. This could be a load-order issue"); } if (!$baoName::tableHasBeenAdded()) { \Civi::log()->warning("Could not read from {$this->getEntityName()} before table has been added. Upgrade required.", ['civi.tag' => 'upgrade_needed']); return; } $this->setDefaultWhereClause(); $this->expandSelectClauseWildcards(); $this->getObjects($result); } /** * @param \Civi\Api4\Generic\Result $result */ protected function getObjects(Result $result) { $getCount = in_array('row_count', $this->getSelect()); $onlyCount = $this->getSelect() === ['row_count']; if (!$onlyCount) { $query = new Api4SelectQuery($this); $rows = $query->run(); \CRM_Utils_API_HTMLInputCoder::singleton()->decodeRows($rows); $result->exchangeArray($rows); // No need to fetch count if we got a result set below the limit if (!$this->getLimit() || count($rows) < $this->getLimit()) { $result->rowCount = count($rows) + $this->getOffset(); $getCount = FALSE; } } if ($getCount) { $query = new Api4SelectQuery($this); $result->rowCount = $query->getCount(); } } /** * @param string $fieldName * @param string $op * @param mixed $value * @param bool $isExpression * @return $this * @throws \API_Exception */ public function addWhere(string $fieldName, string $op, $value = NULL, bool $isExpression = FALSE) { if (!in_array($op, CoreUtil::getOperators())) { throw new \API_Exception('Unsupported operator'); } $this->where[] = [$fieldName, $op, $value, $isExpression]; return $this; } /** * @return array */ public function getGroupBy(): array { return $this->groupBy; } /** * @param array $groupBy * @return $this */ public function setGroupBy(array $groupBy) { $this->groupBy = $groupBy; return $this; } /** * @param string $field * @return $this */ public function addGroupBy(string $field) { $this->groupBy[] = $field; return $this; } /** * @param string $expr * @param string $op * @param mixed $value * @return $this * @throws \API_Exception */ public function addHaving(string $expr, string $op, $value = NULL) { if (!in_array($op, CoreUtil::getOperators())) { throw new \API_Exception('Unsupported operator'); } $this->having[] = [$expr, $op, $value]; return $this; } /** * @param string $entity * @param string|bool $type * @param string $bridge * @param array ...$conditions * @return DAOGetAction */ public function addJoin(string $entity, $type = 'LEFT', $bridge = NULL, ...$conditions): DAOGetAction { if ($bridge) { array_unshift($conditions, $bridge); } array_unshift($conditions, $entity, $type); $this->join[] = $conditions; return $this; } /** * @param array $join * @return DAOGetAction */ public function setJoin(array $join): DAOGetAction { $this->join = $join; return $this; } /** * @return array */ public function getJoin(): array { return $this->join; } }