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