Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | // $Id$ | |
3 | ||
4 | require_once 'api/v3/utils.php'; | |
5 | ||
6 | /** | |
7 | * returns the list of all the entities that you can manipulate via the api. The entity of this API call is the entity, that isn't a real civicrm entity as in something stored in the DB, but an abstract meta object. My head is going to explode. In a meta way. | |
8 | */ | |
9 | function civicrm_api3_entity_get($params) { | |
10 | ||
11 | civicrm_api3_verify_mandatory($params); | |
12 | $entities = array(); | |
13 | $include_dirs = array_unique(explode(PATH_SEPARATOR, get_include_path())); | |
14 | #$include_dirs = array(dirname(__FILE__). '/../../'); | |
15 | foreach ($include_dirs as $include_dir) { | |
16 | $api_dir = implode(DIRECTORY_SEPARATOR, array($include_dir, 'api', 'v3')); | |
17 | if (! is_dir($api_dir)) { | |
18 | continue; | |
19 | } | |
20 | $iterator = new DirectoryIterator($api_dir); | |
21 | foreach ($iterator as $fileinfo) { | |
22 | $file = $fileinfo->getFilename(); | |
23 | ||
24 | // Check for entities with a master file ("api/v3/MyEntity.php") | |
25 | $parts = explode(".", $file); | |
26 | if (end($parts) == "php" && $file != "utils.php" && !preg_match('/Tests?.php$/', $file) ) { | |
27 | // without the ".php" | |
28 | $entities[] = substr($file, 0, -4); | |
29 | } | |
30 | ||
31 | // Check for entities with standalone action files ("api/v3/MyEntity/MyAction.php") | |
32 | $action_dir = $api_dir . DIRECTORY_SEPARATOR . $file; | |
33 | if (preg_match('/^[A-Z][A-Za-z0-9]*$/', $file) && is_dir($action_dir)) { | |
34 | if (count(glob("$action_dir/[A-Z]*.php")) > 0) { | |
35 | $entities[] = $file; | |
36 | } | |
37 | } | |
38 | } | |
39 | } | |
40 | $entities = array_diff($entities, array('Generic')); | |
41 | $entities = array_unique($entities); | |
42 | sort($entities); | |
43 | return civicrm_api3_create_success($entities); | |
44 | } | |
45 | ||
46 | /** | |
47 | * Placeholder function. This should never be called, as it doesn't have any meaning | |
48 | */ | |
49 | function civicrm_api3_entity_create($params) { | |
50 | return civicrm_api3_create_error("API (Entity,Create) does not exist Creating a new entity means modifying the source code of civiCRM."); | |
51 | } | |
52 | ||
53 | /** | |
54 | * Placeholder function. This should never be called, as it doesn't have any meaning | |
55 | */ | |
56 | function civicrm_api3_entity_delete($params) { | |
57 | return civicrm_api3_create_error("API (Entity,Delete) does not exist Deleting an entity means modifying the source code of civiCRM."); | |
58 | } | |
59 | ||
60 | /** | |
61 | * Placeholder function. This should never be called, as it doesn't have any meaning | |
62 | */ | |
63 | function civicrm_api3_entity_getfields($params) { | |
64 | // we return an empty array so it makes it easier to write generic getdefaults / required tests | |
65 | // without putting an exception in for entity | |
66 | return civicrm_api3_create_success(array()); | |
67 | } | |
68 |