implement getsingle APIs for TwingleEvent, TwingleProject & TwingleForm

This commit is contained in:
Marc Michalsky forumZFD 2020-12-17 10:32:34 +01:00
parent 682ba5e7e2
commit 5df73c7c26
Signed by untrusted user who does not match committer: marc.koch
GPG key ID: 12406554CFB028B9
6 changed files with 441 additions and 0 deletions

View file

@ -0,0 +1,63 @@
<?php
use CRM_TwingleCampaign_ExtensionUtil as E;
/**
* TwingleForm.Getsingle API specification (optional)
* This is used for documentation and validation.
*
* @param array $spec description of fields supported by this API call
*
* @see https://docs.civicrm.org/dev/en/latest/framework/api-architecture/
*/
function _civicrm_api3_twingle_form_Getsingle_spec(array &$spec) {
$spec['id'] = [
'name' => 'id',
'title' => E::ts('TwingleProject ID'),
'type' => CRM_Utils_Type::T_INT,
'api.required' => 0,
'description' => E::ts('ID of the TwingleProject campaign'),
];
$spec['name'] = [
'name' => 'name',
'title' => E::ts('TwingleProject name'),
'type' => CRM_Utils_Type::T_STRING,
'api.required' => 0,
'description' => E::ts('Name of the TwingleProject campaign'),
];
$spec['title'] = [
'name' => 'title',
'title' => E::ts('TwingleProject title'),
'type' => CRM_Utils_Type::T_STRING,
'api.required' => 0,
'description' => E::ts('Title of the TwingleProject campaign'),
];
$spec['twingle_project_type'] = [
'name' => 'twingle_project_type',
'title' => E::ts('TwingleProject type'),
'type' => CRM_Utils_Type::T_STRING,
'api.required' => 0,
'description' => E::ts('Project type can be default, event or membership'),
];
}
/**
* TwingleForm.Getsingle API
*
* @param array $params
*
* @return array
* API result descriptor
*
* @throws \API_Exception
* @throws \CiviCRM_API3_Exception
* @see civicrm_api3_create_success
*/
function civicrm_api3_twingle_form_Getsingle(array $params): array {
$returnValues = civicrm_api3('TwingleForm', 'get', $params);
$count = $returnValues['count'];
if ($count != 1){
return civicrm_api3_create_error("Expected one TwingleForm but found $count");
}
return civicrm_api3_create_success($returnValues, $params, 'TwingleForm', 'Getsingle');
}