implement getsingle APIs for TwingleEvent, TwingleProject & TwingleForm
This commit is contained in:
parent
682ba5e7e2
commit
5df73c7c26
6 changed files with 441 additions and 0 deletions
106
api/v3/TwingleEvent/Getsingle.php
Normal file
106
api/v3/TwingleEvent/Getsingle.php
Normal file
|
@ -0,0 +1,106 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use CRM_TwingleCampaign_ExtensionUtil as E;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TwingleEvent.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_event_Getsingle_spec(array &$spec) {
|
||||||
|
$spec['id'] = [
|
||||||
|
'name' => 'id',
|
||||||
|
'title' => E::ts('Campaign ID'),
|
||||||
|
'type' => CRM_Utils_Type::T_INT,
|
||||||
|
'api.required' => 0,
|
||||||
|
'description' => E::ts('Unique Campaign ID'),
|
||||||
|
];
|
||||||
|
$spec['name'] = [
|
||||||
|
'name' => 'name',
|
||||||
|
'title' => E::ts('Campaign Name'),
|
||||||
|
'type' => CRM_Utils_Type::T_STRING,
|
||||||
|
'api.required' => 0,
|
||||||
|
'description' => E::ts('Name of the Campaign'),
|
||||||
|
];
|
||||||
|
$spec['title'] = [
|
||||||
|
'name' => 'title',
|
||||||
|
'title' => E::ts('Campaign Title'),
|
||||||
|
'type' => CRM_Utils_Type::T_STRING,
|
||||||
|
'api.required' => 0,
|
||||||
|
'description' => E::ts('Title of the Campaign'),
|
||||||
|
];
|
||||||
|
$spec['start_date'] = [
|
||||||
|
'name' => 'start_date',
|
||||||
|
'title' => E::ts('Campaign Start Date'),
|
||||||
|
'type' => CRM_Utils_Type::T_STRING,
|
||||||
|
'api.required' => 0,
|
||||||
|
'description' => E::ts('Date and Time that Campaign starts.'),
|
||||||
|
];
|
||||||
|
$spec['project_id'] = [
|
||||||
|
'name' => 'project_id',
|
||||||
|
'title' => E::ts('Twingle Project ID'),
|
||||||
|
'type' => CRM_Utils_Type::T_INT,
|
||||||
|
'api.required' => 0,
|
||||||
|
'description' => E::ts('Parent Project ID for this Event'),
|
||||||
|
];
|
||||||
|
$spec['event_id'] = [
|
||||||
|
'name' => 'event_id',
|
||||||
|
'title' => E::ts('Twingle Event ID'),
|
||||||
|
'type' => CRM_Utils_Type::T_INT,
|
||||||
|
'api.required' => 0,
|
||||||
|
'description' => E::ts('Twingle ID for this Event'),
|
||||||
|
];
|
||||||
|
$spec['last_modified_id'] = [
|
||||||
|
'name' => 'last_modified_id',
|
||||||
|
'title' => E::ts('Campaign Modified By'),
|
||||||
|
'type' => CRM_Utils_Type::T_INT,
|
||||||
|
'api.required' => 0,
|
||||||
|
'description' => E::ts('FK ti civicrm_contact, who recently edited this campaign'),
|
||||||
|
'FKClassName' => 'CRM_Contact_DAO_Contact',
|
||||||
|
];
|
||||||
|
$spec['last_modified_date'] = [
|
||||||
|
'name' => 'last_modified_date',
|
||||||
|
'title' => E::ts('Campaign Modified Date'),
|
||||||
|
'type' => CRM_Utils_Type::T_STRING,
|
||||||
|
'api.required' => 0,
|
||||||
|
'description' => E::ts('FK ti civicrm_contact, who recently edited this campaign'),
|
||||||
|
];
|
||||||
|
$spec['is_active'] = [
|
||||||
|
'name' => 'is_active',
|
||||||
|
'title' => E::ts('Campaign is active'),
|
||||||
|
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||||
|
'api.required' => 0,
|
||||||
|
'description' => E::ts('Is this Campaign enabled or disabled/cancelled?'),
|
||||||
|
];
|
||||||
|
$spec['confirmed_at'] = [
|
||||||
|
'name' => 'confirmed_at',
|
||||||
|
'title' => E::ts('Confirmed at'),
|
||||||
|
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||||
|
'api.required' => 0,
|
||||||
|
'description' => E::ts('When the Event was confirmed by its initiator'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TwingleEvent.Getsingle API
|
||||||
|
*
|
||||||
|
* @param array $params
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
* API result descriptor
|
||||||
|
*
|
||||||
|
* @throws CiviCRM_API3_Exception
|
||||||
|
* @see civicrm_api3_create_success
|
||||||
|
*/
|
||||||
|
function civicrm_api3_twingle_event_Getsingle(array $params): array {
|
||||||
|
$returnValues = civicrm_api3('TwingleEvent', 'get', $params);
|
||||||
|
$count = $returnValues['count'];
|
||||||
|
|
||||||
|
if ($count != 1) {
|
||||||
|
return civicrm_api3_create_error("Expected one TwingleEvent but found $count");
|
||||||
|
}
|
||||||
|
return civicrm_api3_create_success($returnValues, $params, 'TwingleEvent', 'Getsingle');
|
||||||
|
}
|
63
api/v3/TwingleForm/Getsingle.php
Normal file
63
api/v3/TwingleForm/Getsingle.php
Normal 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');
|
||||||
|
}
|
113
api/v3/TwingleProject/Getsingle.php
Normal file
113
api/v3/TwingleProject/Getsingle.php
Normal file
|
@ -0,0 +1,113 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use CRM_TwingleCampaign_ExtensionUtil as E;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TwingleProject.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_project_Getsingle_spec(array &$spec) {
|
||||||
|
$spec['id'] = [
|
||||||
|
'name' => 'id',
|
||||||
|
'title' => E::ts('Campaign ID'),
|
||||||
|
'type' => CRM_Utils_Type::T_INT,
|
||||||
|
'api.required' => 0,
|
||||||
|
'description' => E::ts('Unique Campaign ID'),
|
||||||
|
];
|
||||||
|
$spec['name'] = [
|
||||||
|
'name' => 'name',
|
||||||
|
'title' => E::ts('Campaign Name'),
|
||||||
|
'type' => CRM_Utils_Type::T_STRING,
|
||||||
|
'api.required' => 0,
|
||||||
|
'description' => E::ts('Name of the Campaign'),
|
||||||
|
];
|
||||||
|
$spec['title'] = [
|
||||||
|
'name' => 'title',
|
||||||
|
'title' => E::ts('Campaign Title'),
|
||||||
|
'type' => CRM_Utils_Type::T_STRING,
|
||||||
|
'api.required' => 0,
|
||||||
|
'description' => E::ts('Title of the Campaign'),
|
||||||
|
];
|
||||||
|
$spec['start_date'] = [
|
||||||
|
'name' => 'start_date',
|
||||||
|
'title' => E::ts('Campaign Start Date'),
|
||||||
|
'type' => CRM_Utils_Type::T_STRING,
|
||||||
|
'api.required' => 0,
|
||||||
|
'description' => E::ts('Date and Time that Campaign starts.'),
|
||||||
|
];
|
||||||
|
$spec['project_id'] = [
|
||||||
|
'name' => 'project_id',
|
||||||
|
'title' => E::ts('Twingle Project ID'),
|
||||||
|
'type' => CRM_Utils_Type::T_INT,
|
||||||
|
'api.required' => 0,
|
||||||
|
'description' => E::ts('Twingle ID for this project'),
|
||||||
|
];
|
||||||
|
$spec['last_modified_id'] = [
|
||||||
|
'name' => 'last_modified_id',
|
||||||
|
'title' => E::ts('Campaign Modified By'),
|
||||||
|
'type' => CRM_Utils_Type::T_INT,
|
||||||
|
'api.required' => 0,
|
||||||
|
'description' => E::ts('FK ti civicrm_contact, who recently edited this campaign'),
|
||||||
|
'FKClassName' => 'CRM_Contact_DAO_Contact',
|
||||||
|
];
|
||||||
|
$spec['last_modified_date'] = [
|
||||||
|
'name' => 'last_modified_date',
|
||||||
|
'title' => E::ts('Campaign Modified Date'),
|
||||||
|
'type' => CRM_Utils_Type::T_STRING,
|
||||||
|
'api.required' => 0,
|
||||||
|
'description' => E::ts('FK ti civicrm_contact, who recently edited this campaign'),
|
||||||
|
];
|
||||||
|
$spec['type'] = [
|
||||||
|
'name' => 'type',
|
||||||
|
'title' => E::ts('Twingle Project Type'),
|
||||||
|
'type' => CRM_Utils_Type::T_STRING,
|
||||||
|
'api.required' => 0,
|
||||||
|
'description' => E::ts('The type of the Twingle Project'),
|
||||||
|
];
|
||||||
|
$spec['allow_more'] = [
|
||||||
|
'name' => 'allow_more',
|
||||||
|
'title' => E::ts('Allow more'),
|
||||||
|
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||||
|
'api.required' => 0,
|
||||||
|
'description' => E::ts('Allow to donate more than is defined in the target'),
|
||||||
|
];
|
||||||
|
$spec['organisation_id'] = [
|
||||||
|
'name' => 'organisation_id',
|
||||||
|
'title' => E::ts('Twingle Organisation ID'),
|
||||||
|
'type' => CRM_Utils_Type::T_INT,
|
||||||
|
'api.required' => 0,
|
||||||
|
'description' => E::ts('Your Twingle Organisation ID'),
|
||||||
|
];
|
||||||
|
$spec['is_active'] = [
|
||||||
|
'name' => 'is_active',
|
||||||
|
'title' => E::ts('Campaign is active'),
|
||||||
|
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||||
|
'api.required' => 0,
|
||||||
|
'description' => E::ts('Is this Campaign enabled or disabled/cancelled?'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TwingleProject.Getsingle API
|
||||||
|
*
|
||||||
|
* @param array $params
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
* API result descriptor
|
||||||
|
*
|
||||||
|
* @throws CiviCRM_API3_Exception
|
||||||
|
* @see civicrm_api3_create_success
|
||||||
|
*/
|
||||||
|
function civicrm_api3_twingle_project_Getsingle(array $params): array {
|
||||||
|
$returnValues = civicrm_api3('TwingleProject', 'get', $params);
|
||||||
|
$count = $returnValues['count'];
|
||||||
|
|
||||||
|
if ($count != 1) {
|
||||||
|
return civicrm_api3_create_error("Expected one TwingleProject but found $count");
|
||||||
|
}
|
||||||
|
return civicrm_api3_create_success($returnValues, $params, 'TwingleProject', 'Getsingle');
|
||||||
|
}
|
53
tests/phpunit/api/v3/TwingleEvent/GetsingleTest.php
Normal file
53
tests/phpunit/api/v3/TwingleEvent/GetsingleTest.php
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Civi\Test\HeadlessInterface;
|
||||||
|
use Civi\Test\HookInterface;
|
||||||
|
use Civi\Test\TransactionalInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TwingleEvent.Getsingle API Test Case
|
||||||
|
* This is a generic test class implemented with PHPUnit.
|
||||||
|
* @group headless
|
||||||
|
*/
|
||||||
|
class api_v3_TwingleEvent_GetsingleTest extends \PHPUnit\Framework\TestCase implements HeadlessInterface, HookInterface, TransactionalInterface {
|
||||||
|
use \Civi\Test\Api3TestTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set up for headless tests.
|
||||||
|
*
|
||||||
|
* Civi\Test has many helpers, like install(), uninstall(), sql(), and sqlFile().
|
||||||
|
*
|
||||||
|
* See: https://docs.civicrm.org/dev/en/latest/testing/phpunit/#civitest
|
||||||
|
*/
|
||||||
|
public function setUpHeadless() {
|
||||||
|
return \Civi\Test::headless()
|
||||||
|
->installMe(__DIR__)
|
||||||
|
->apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The setup() method is executed before the test is executed (optional).
|
||||||
|
*/
|
||||||
|
public function setUp() {
|
||||||
|
parent::setUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The tearDown() method is executed after the test was executed (optional)
|
||||||
|
* This can be used for cleanup.
|
||||||
|
*/
|
||||||
|
public function tearDown() {
|
||||||
|
parent::tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple example test case.
|
||||||
|
*
|
||||||
|
* Note how the function name begins with the word "test".
|
||||||
|
*/
|
||||||
|
public function testApiExample() {
|
||||||
|
$result = civicrm_api3('TwingleEvent', 'Getsingle', array('magicword' => 'sesame'));
|
||||||
|
$this->assertEquals('Twelve', $result['values'][12]['name']);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
53
tests/phpunit/api/v3/TwingleForm/GetsingleTest.php
Normal file
53
tests/phpunit/api/v3/TwingleForm/GetsingleTest.php
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Civi\Test\HeadlessInterface;
|
||||||
|
use Civi\Test\HookInterface;
|
||||||
|
use Civi\Test\TransactionalInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TwingleForm.Getsingle API Test Case
|
||||||
|
* This is a generic test class implemented with PHPUnit.
|
||||||
|
* @group headless
|
||||||
|
*/
|
||||||
|
class api_v3_TwingleForm_GetsingleTest extends \PHPUnit\Framework\TestCase implements HeadlessInterface, HookInterface, TransactionalInterface {
|
||||||
|
use \Civi\Test\Api3TestTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set up for headless tests.
|
||||||
|
*
|
||||||
|
* Civi\Test has many helpers, like install(), uninstall(), sql(), and sqlFile().
|
||||||
|
*
|
||||||
|
* See: https://docs.civicrm.org/dev/en/latest/testing/phpunit/#civitest
|
||||||
|
*/
|
||||||
|
public function setUpHeadless() {
|
||||||
|
return \Civi\Test::headless()
|
||||||
|
->installMe(__DIR__)
|
||||||
|
->apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The setup() method is executed before the test is executed (optional).
|
||||||
|
*/
|
||||||
|
public function setUp() {
|
||||||
|
parent::setUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The tearDown() method is executed after the test was executed (optional)
|
||||||
|
* This can be used for cleanup.
|
||||||
|
*/
|
||||||
|
public function tearDown() {
|
||||||
|
parent::tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple example test case.
|
||||||
|
*
|
||||||
|
* Note how the function name begins with the word "test".
|
||||||
|
*/
|
||||||
|
public function testApiExample() {
|
||||||
|
$result = civicrm_api3('TwingleForm', 'Getsingle', array('magicword' => 'sesame'));
|
||||||
|
$this->assertEquals('Twelve', $result['values'][12]['name']);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
53
tests/phpunit/api/v3/TwingleProject/GetsingleTest.php
Normal file
53
tests/phpunit/api/v3/TwingleProject/GetsingleTest.php
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Civi\Test\HeadlessInterface;
|
||||||
|
use Civi\Test\HookInterface;
|
||||||
|
use Civi\Test\TransactionalInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TwingleProject.Getsingle API Test Case
|
||||||
|
* This is a generic test class implemented with PHPUnit.
|
||||||
|
* @group headless
|
||||||
|
*/
|
||||||
|
class api_v3_TwingleProject_GetsingleTest extends \PHPUnit\Framework\TestCase implements HeadlessInterface, HookInterface, TransactionalInterface {
|
||||||
|
use \Civi\Test\Api3TestTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set up for headless tests.
|
||||||
|
*
|
||||||
|
* Civi\Test has many helpers, like install(), uninstall(), sql(), and sqlFile().
|
||||||
|
*
|
||||||
|
* See: https://docs.civicrm.org/dev/en/latest/testing/phpunit/#civitest
|
||||||
|
*/
|
||||||
|
public function setUpHeadless() {
|
||||||
|
return \Civi\Test::headless()
|
||||||
|
->installMe(__DIR__)
|
||||||
|
->apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The setup() method is executed before the test is executed (optional).
|
||||||
|
*/
|
||||||
|
public function setUp() {
|
||||||
|
parent::setUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The tearDown() method is executed after the test was executed (optional)
|
||||||
|
* This can be used for cleanup.
|
||||||
|
*/
|
||||||
|
public function tearDown() {
|
||||||
|
parent::tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple example test case.
|
||||||
|
*
|
||||||
|
* Note how the function name begins with the word "test".
|
||||||
|
*/
|
||||||
|
public function testApiExample() {
|
||||||
|
$result = civicrm_api3('TwingleProject', 'Getsingle', array('magicword' => 'sesame'));
|
||||||
|
$this->assertEquals('Twelve', $result['values'][12]['name']);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue