Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SearchKit - Expose sql functions provided by extensions #27197

Merged
merged 1 commit into from Sep 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 22 additions & 14 deletions Civi/Api4/Utils/CoreUtil.php
Expand Up @@ -375,20 +375,28 @@ public static function formatOptionList($options, $format) {
*/
public static function getSqlFunctions(): array {
$fns = [];
foreach (glob(\Civi::paths()->getPath('[civicrm.root]/Civi/Api4/Query/SqlFunction*.php')) as $file) {
$matches = [];
if (preg_match('/(SqlFunction[A-Z_]+)\.php$/', $file, $matches)) {
$className = '\Civi\Api4\Query\\' . $matches[1];
if (is_subclass_of($className, '\Civi\Api4\Query\SqlFunction')) {
$fns[] = [
'name' => $className::getName(),
'title' => $className::getTitle(),
'description' => $className::getDescription(),
'params' => $className::getParams(),
'category' => $className::getCategory(),
'dataType' => $className::getDataType(),
'options' => CoreUtil::formatOptionList($className::getOptions(), ['id', 'name', 'label']),
];
$path = 'Civi/Api4/Query/SqlFunction*.php';
// Search CiviCRM core + all active extensions
$directories = [\Civi::paths()->getPath("[civicrm.root]/$path")];
foreach (\CRM_Extension_System::singleton()->getMapper()->getActiveModuleFiles() as $ext) {
$directories[] = \CRM_Utils_File::addTrailingSlash(dirname($ext['filePath'])) . $path;
}
foreach ($directories as $directory) {
foreach (glob($directory) as $file) {
$matches = [];
if (preg_match('/(SqlFunction[A-Z_]+)\.php$/', $file, $matches)) {
$className = '\Civi\Api4\Query\\' . $matches[1];
if (is_subclass_of($className, '\Civi\Api4\Query\SqlFunction')) {
$fns[] = [
'name' => $className::getName(),
'title' => $className::getTitle(),
'description' => $className::getDescription(),
'params' => $className::getParams(),
'category' => $className::getCategory(),
'dataType' => $className::getDataType(),
'options' => CoreUtil::formatOptionList($className::getOptions(), ['id', 'name', 'label']),
];
}
}
}
}
Expand Down