add comments
This commit is contained in:
parent
3f3a8eb04d
commit
f54f3bf262
3 changed files with 32 additions and 7 deletions
|
@ -19,7 +19,7 @@ function _civicrm_api3_twingle_sync_Get_spec(&$spec) {
|
|||
'title' => E::ts('Twingle API key'),
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'api.required' => 0,
|
||||
'description' => E::ts('The key you need to access the Twingle API'),
|
||||
'description' => E::ts('The key to access the Twingle API'),
|
||||
];
|
||||
$spec['test'] = [
|
||||
'name' => 'test',
|
||||
|
@ -45,13 +45,15 @@ function _civicrm_api3_twingle_sync_Get_spec(&$spec) {
|
|||
function civicrm_api3_twingle_sync_Get($params) {
|
||||
$result_values = [];
|
||||
|
||||
// If function call provides an API key, use it instead of the API key set
|
||||
// on the extension settings page
|
||||
$apiKey = empty($params['twingle_api_key'])
|
||||
? CRM_Core_BAO_Setting::getItem('', 'twingle_api_key')
|
||||
: $params['twingle_api_key'];
|
||||
|
||||
// TODO: Do the magic!
|
||||
// Get all projects from Twingle and store them in $projects
|
||||
|
||||
$twingleApi = new TwingleApiCall($apiKey);
|
||||
// Create projects as campaigns if they do not exist and store results in
|
||||
$result_values['projects'] = $twingleApi->getProject();
|
||||
foreach ($result_values['projects'] as $project) {
|
||||
if (is_array($project)) {
|
||||
|
|
|
@ -99,10 +99,13 @@ class TwingleApiCall {
|
|||
return $result;
|
||||
}
|
||||
|
||||
public function createProject($values) {
|
||||
try {
|
||||
if (is_array($values)) {
|
||||
$project = new TwingleProject($values);
|
||||
/**
|
||||
* @param $values
|
||||
*
|
||||
* @return array|null
|
||||
* @throws \CiviCRM_API3_Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
return $project->create();
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
|
|
|
@ -53,6 +53,10 @@ class TwingleProject {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get all related custom fields as CustomField objects in an static array.
|
||||
* This function will be fully executed only once, when the TwingleProject
|
||||
* class gets instantiated for the first time.
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
private static function init() {
|
||||
|
@ -77,6 +81,12 @@ class TwingleProject {
|
|||
self::$bInitialized = TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the project as a campaign in CiviCRM if it does not exist
|
||||
*
|
||||
* @return array
|
||||
* @throws \CiviCRM_API3_Exception
|
||||
*/
|
||||
public function create() {
|
||||
$values = $this->values;
|
||||
try {
|
||||
|
@ -86,6 +96,11 @@ class TwingleProject {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats values to import them as campaigns
|
||||
*
|
||||
* @param $values
|
||||
*/
|
||||
private function formatForImport(&$values) {
|
||||
|
||||
// Change timestamp into DateTime string
|
||||
|
@ -100,6 +115,11 @@ class TwingleProject {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats values to send them to Twingle API
|
||||
*
|
||||
* @param $values
|
||||
*/
|
||||
private function formatForExport(&$values) {
|
||||
|
||||
// Change DateTime string into timestamp
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue