import classes
This commit is contained in:
parent
b331aa88d9
commit
1acbbb7c78
3 changed files with 33 additions and 18 deletions
|
@ -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 <br>
|
||||
* TwingleProject::OUT -> translate array values from CiviCRM to Twingle
|
||||
*
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
private function formatValues(array &$values, string $direction) {
|
||||
|
||||
|
|
9
CRM/TwingleCampaign/BAO/TwingleProjectOptions.php
Normal file
9
CRM/TwingleCampaign/BAO/TwingleProjectOptions.php
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace CRM\TwingleCampaign\BAO;
|
||||
|
||||
|
||||
class TwingleProjectOptions {
|
||||
|
||||
}
|
|
@ -2,9 +2,12 @@
|
|||
|
||||
namespace CRM\TwingleCampaign\BAO;
|
||||
|
||||
use API_Exception;
|
||||
use Civi;
|
||||
use CRM_Core_BAO_Setting;
|
||||
use CRM_TwingleCampaign_ExtensionUtil as E;
|
||||
use CRM\TwingleCampaign\BAO\TwingleProject as TwingleProject;
|
||||
use Exception;
|
||||
|
||||
include_once E::path() . '/CRM/TwingleCampaign/BAO/TwingleProject.php';
|
||||
|
||||
|
@ -23,7 +26,7 @@ class TwingleApiCall {
|
|||
*
|
||||
* @param $apiKey
|
||||
*
|
||||
* @throws \API_Exception
|
||||
* @throws API_Exception
|
||||
*/
|
||||
public function __construct($apiKey) {
|
||||
$this->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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue