From 1acbbb7c7864d80a850cd303d0d8391317cc6767 Mon Sep 17 00:00:00 2001 From: Marc Michalsky forumZFD Date: Tue, 27 Oct 2020 10:39:37 +0100 Subject: [PATCH] import classes --- CRM/TwingleCampaign/BAO/TwingleProject.php | 17 +++++++------ .../BAO/TwingleProjectOptions.php | 9 +++++++ api/v3/TwingleSync/BAO/TwingleApiCall.php | 25 +++++++++++-------- 3 files changed, 33 insertions(+), 18 deletions(-) create mode 100644 CRM/TwingleCampaign/BAO/TwingleProjectOptions.php diff --git a/CRM/TwingleCampaign/BAO/TwingleProject.php b/CRM/TwingleCampaign/BAO/TwingleProject.php index 6c0126f..a93fc1e 100644 --- a/CRM/TwingleCampaign/BAO/TwingleProject.php +++ b/CRM/TwingleCampaign/BAO/TwingleProject.php @@ -8,10 +8,12 @@ use CRM_TwingleCampaign_ExtensionUtil as E; use CRM_Utils_Array; use DateTime; use CRM\TwingleCampaign\BAO\CustomField as CustomField; +use CRM\TwingleCampaign\BAO\TwingleProjectOptions as TwingleProjectOptions; use Exception; use CiviCRM_API3_Exception; include_once E::path() . '/CRM/TwingleCampaign/BAO/CustomField.php'; +include_once E::path() . '/CRM/TwingleCampaign/BAO/TwingleProjectOptions.php'; class TwingleProject { @@ -56,7 +58,7 @@ class TwingleProject { * Origin of the arrays. It can be one of two constants: * TwingleProject::TWINGLE|CIVICRM * - * @throws \Exception + * @throws Exception */ public function __construct(array $project, array $options, string $origin) { @@ -99,7 +101,7 @@ class TwingleProject { * This function will be fully executed only once, when the TwingleProject * class gets instantiated for the first time. * - * @throws \Exception + * @throws Exception */ private static function init() { @@ -152,6 +154,7 @@ class TwingleProject { * Returns a response array that contains title, id, project_id and status * * @throws CiviCRM_API3_Exception + * @throws Exception */ public function create(bool $is_test = FALSE) { @@ -202,7 +205,7 @@ class TwingleProject { * Origin of the array. It can be one of two constants: * TwingleProject::TWINGLE|CIVICRM * - * @throws \Exception + * @throws Exception */ public function update(array $values, array $options, string $origin = NULL) { @@ -234,7 +237,7 @@ class TwingleProject { * @return array * Array with all values to send to the Twingle API * - * @throws \Exception + * @throws Exception */ public function export() { @@ -263,7 +266,7 @@ class TwingleProject { * @return array * Array with all options to send to the Twingle API * - * @throws \Exception + * @throws Exception * */ public function exportOptions() { @@ -416,7 +419,7 @@ class TwingleProject { * TwingleProject::OUT -> translate array keys from CiviCRM format into * Twingle format * - * @throws \Exception + * @throws Exception */ private static function translateKeys(array &$values, string $direction) { @@ -453,7 +456,7 @@ class TwingleProject { * TwingleProject::IN -> translate array values from Twingle to CiviCRM
* TwingleProject::OUT -> translate array values from CiviCRM to Twingle * - * @throws \Exception + * @throws Exception */ private function formatValues(array &$values, string $direction) { diff --git a/CRM/TwingleCampaign/BAO/TwingleProjectOptions.php b/CRM/TwingleCampaign/BAO/TwingleProjectOptions.php new file mode 100644 index 0000000..8ce7c8a --- /dev/null +++ b/CRM/TwingleCampaign/BAO/TwingleProjectOptions.php @@ -0,0 +1,9 @@ +apiKey = $apiKey; @@ -40,7 +43,7 @@ class TwingleApiCall { curl_close($curl); if (empty($response)) { - throw new \API_Exception( + throw new API_Exception( "Twingle API call failed. Please check your api key."); } @@ -141,7 +144,7 @@ class TwingleApiCall { } catch (\Exception $e) { // Log Exception - \Civi::log()->error( + Civi::log()->error( "Failed to instantiate TwingleProject: $e->getMessage()" ); @@ -169,10 +172,10 @@ class TwingleApiCall { $project_options, TwingleProject::TWINGLE ); - } catch (\Exception $e) { + } catch (Exception $e) { // Log Exception - \Civi::log()->error( + Civi::log()->error( "Failed to instantiate TwingleProject: $e->getMessage()" ); @@ -191,10 +194,10 @@ class TwingleApiCall { // ... if not, create it try { $result = $project->create($is_test); - } catch (\Exception $e) { + } catch (Exception $e) { // Log Exception - \Civi::log()->error( + Civi::log()->error( "Could not create campaign from TwingleProject: $e->getMessage()" ); @@ -278,9 +281,9 @@ class TwingleApiCall { try { $values = $project->export(); - } catch (\Exception $e) { + } catch (Exception $e) { // Log Exception - \Civi::log()->error( + Civi::log()->error( "Could not export TwingleProject values: $e->getMessage()" ); // Return result array with error description @@ -303,9 +306,9 @@ class TwingleApiCall { $project->update($result, TwingleProject::TWINGLE); $project->create(); return $project->getResponse('TwingleProject pushed to Twingle'); - } catch (\Exception $e) { + } catch (Exception $e) { // Log Exception - \Civi::log()->error( + Civi::log()->error( "Could not update TwingleProject campaign: $e->getMessage()" ); // Return result array with error description