+/**
+ * @param $params
+ */
+function _civicrm_api3_generic_getrefcount_spec(&$params) {
+ $params['id']['api.required'] = 1;
+}
+
+/**
+ * API to determine if a record is in-use
+ *
+ * @param array $apiRequest api request as an array
+ *
+ * @throws API_Exception
+ * @return array API result (int 0 or 1)
+ */
+function civicrm_api3_generic_getrefcount($apiRequest) {
+ $entityToClassMap = CRM_Core_DAO_AllCoreTables::daoToClass();
+ if (!isset($entityToClassMap[$apiRequest['entity']])) {
+ throw new API_Exception("The entity '{$apiRequest['entity']}' is unknown or unsupported by 'getrefcount'. Consider implementing this API.", 'getrefcount_unsupported');
+ }
+ $daoClass = $entityToClassMap[$apiRequest['entity']];
+
+ /* @var $dao CRM_Core_DAO */
+ $dao = new $daoClass();
+ $dao->id = $apiRequest['params']['id'];
+ if ($dao->find(TRUE)) {
+ return civicrm_api3_create_success($dao->getReferenceCounts());
+ }
+ else {
+ return civicrm_api3_create_success(array());
+ }
+}
+