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 +--------------------------------------------------------------------+
13 use Civi\Api4\Service\Schema\Joinable\Joinable
;
18 * @copyright CiviCRM LLC https://civicrm.org/licensing
20 class CRM_Api4_Page_Api4Explorer
extends CRM_Core_Page
{
22 public function run() {
23 $apiDoc = new ReflectionFunction('civicrm_api4');
24 $groupOptions = civicrm_api4('Group', 'getFields', ['loadOptions' => TRUE, 'select' => ['options', 'name'], 'where' => [['name', 'IN', ['visibility', 'group_type']]]]);
25 // Don't show n-to-many joins in Explorer
26 $entityLinks = (array) civicrm_api4('Entity', 'getLinks', [], ['entity' => 'links']);
27 foreach ($entityLinks as $entity => $links) {
28 $entityLinks[$entity] = array_filter($links, function($link) {
29 return $link['joinType'] != Joinable
::JOIN_TYPE_ONE_TO_MANY
;
33 'operators' => \CRM_Core_DAO
::acceptedSQLOperators(),
34 'basePath' => Civi
::resources()->getUrl('civicrm'),
35 'schema' => (array) \Civi\Api4\Entity
::get()->setChain(['fields' => ['$name', 'getFields']])->execute(),
36 'links' => $entityLinks,
37 'docs' => \Civi\Api4\Utils\ReflectionUtils
::parseDocBlock($apiDoc->getDocComment()),
38 'functions' => self
::getSqlFunctions(),
39 'groupOptions' => array_column((array) $groupOptions, 'options', 'name'),
42 ->addVars('api4', $vars)
43 ->addPermissions(['access debug output', 'edit groups', 'administer reserved groups'])
44 ->addScriptFile('civicrm', 'js/load-bootstrap.js')
45 ->addScriptFile('civicrm', 'bower_components/js-yaml/dist/js-yaml.min.js')
46 ->addScriptFile('civicrm', 'bower_components/marked/marked.min.js')
47 ->addScriptFile('civicrm', 'bower_components/google-code-prettify/bin/prettify.min.js')
48 ->addStyleFile('civicrm', 'bower_components/google-code-prettify/bin/prettify.min.css');
50 $loader = new Civi\Angular\
AngularLoader();
51 $loader->setModules(['api4Explorer']);
52 $loader->setPageName('civicrm/api4');
54 'defaultRoute' => '/explorer',
61 * Gets info about all available sql functions
64 public static function getSqlFunctions() {
66 foreach (glob(Civi
::paths()->getPath('[civicrm.root]/Civi/Api4/Query/SqlFunction*.php')) as $file) {
68 if (preg_match('/(SqlFunction[A-Z_]+)\.php$/', $file, $matches)) {
69 $className = '\Civi\Api4\Query\\' . $matches[1];
70 if (is_subclass_of($className, '\Civi\Api4\Query\SqlFunction')) {
72 'name' => $className::getName(),
73 'params' => $className::getParams(),