start a case for event initiator
This commit is contained in:
parent
cc4f4e85bc
commit
fceac70336
2 changed files with 35 additions and 8 deletions
|
@ -6,11 +6,11 @@ namespace CRM\TwingleCampaign\BAO;
|
||||||
use Civi;
|
use Civi;
|
||||||
use CRM_TwingleCampaign_ExtensionUtil as E;
|
use CRM_TwingleCampaign_ExtensionUtil as E;
|
||||||
use CRM\TwingleCampaign\Utils\ExtensionCache as Cache;
|
use CRM\TwingleCampaign\Utils\ExtensionCache as Cache;
|
||||||
use CRM\TwingleCampaign\BAO\Campaign;
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use CiviCRM_API3_Exception;
|
use CiviCRM_API3_Exception;
|
||||||
|
|
||||||
include_once E::path() . '/CRM/TwingleCampaign/BAO/Campaign.php';
|
include_once E::path() . '/CRM/TwingleCampaign/BAO/Campaign.php';
|
||||||
|
include_once E::path() . '/CRM/TwingleCampaign/BAO/Configuration.php';
|
||||||
include_once E::path() . '/CRM/TwingleCampaign/Utils/ExtensionCache.php';
|
include_once E::path() . '/CRM/TwingleCampaign/Utils/ExtensionCache.php';
|
||||||
|
|
||||||
class TwingleEvent extends Campaign {
|
class TwingleEvent extends Campaign {
|
||||||
|
@ -46,6 +46,7 @@ class TwingleEvent extends Campaign {
|
||||||
*
|
*
|
||||||
* @param array $values
|
* @param array $values
|
||||||
* @param TwingleApiCall $twingleApi
|
* @param TwingleApiCall $twingleApi
|
||||||
|
* @param int $user
|
||||||
* @param bool $is_test
|
* @param bool $is_test
|
||||||
* If TRUE, don't do any changes
|
* If TRUE, don't do any changes
|
||||||
*
|
*
|
||||||
|
@ -53,11 +54,12 @@ class TwingleEvent extends Campaign {
|
||||||
* Returns a response array that contains title, id, event_id, project_id
|
* Returns a response array that contains title, id, event_id, project_id
|
||||||
* and status or NULL if $values is not an array
|
* and status or NULL if $values is not an array
|
||||||
*
|
*
|
||||||
* @throws CiviCRM_API3_Exception
|
* @throws \CiviCRM_API3_Exception
|
||||||
*/
|
*/
|
||||||
public static function sync(
|
public static function sync(
|
||||||
array $values,
|
array $values,
|
||||||
TwingleApiCall &$twingleApi,
|
TwingleApiCall &$twingleApi,
|
||||||
|
int $user,
|
||||||
bool $is_test = FALSE
|
bool $is_test = FALSE
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
@ -93,7 +95,7 @@ class TwingleEvent extends Campaign {
|
||||||
|
|
||||||
// ... if not, get embed data and create event
|
// ... if not, get embed data and create event
|
||||||
try {
|
try {
|
||||||
$result = $event->create($is_test);
|
$result = $event->create($user, $is_test);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$errorMessage = $e->getMessage();
|
$errorMessage = $e->getMessage();
|
||||||
|
|
||||||
|
@ -154,16 +156,16 @@ class TwingleEvent extends Campaign {
|
||||||
/**
|
/**
|
||||||
* Create the Event as a campaign in CiviCRM if it does not exist
|
* Create the Event as a campaign in CiviCRM if it does not exist
|
||||||
*
|
*
|
||||||
|
* @param int $user
|
||||||
* @param bool $is_test
|
* @param bool $is_test
|
||||||
* If true: don't do any changes
|
* If true: don't do any changes
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
* Returns a response array that contains title, id, project_id and status
|
* Returns a response array that contains title, id, project_id and status
|
||||||
*
|
*
|
||||||
* @throws CiviCRM_API3_Exception
|
* @throws \CiviCRM_API3_Exception
|
||||||
* @throws Exception
|
|
||||||
*/
|
*/
|
||||||
public function create(bool $is_test = FALSE) {
|
public function create(int $user, bool $is_test = FALSE) {
|
||||||
|
|
||||||
// Create campaign only if it does not already exist
|
// Create campaign only if it does not already exist
|
||||||
if (!$is_test) {
|
if (!$is_test) {
|
||||||
|
@ -178,6 +180,7 @@ class TwingleEvent extends Campaign {
|
||||||
$values_prepared_for_import,
|
$values_prepared_for_import,
|
||||||
self::IN
|
self::IN
|
||||||
);
|
);
|
||||||
|
$formattedValues = $values_prepared_for_import;
|
||||||
$this->translateCustomFields(
|
$this->translateCustomFields(
|
||||||
$values_prepared_for_import,
|
$values_prepared_for_import,
|
||||||
self::IN
|
self::IN
|
||||||
|
@ -200,6 +203,21 @@ class TwingleEvent extends Campaign {
|
||||||
$response = $this->getResponse("$this->className creation failed");
|
$response = $this->getResponse("$this->className creation failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Start a case for event initiator
|
||||||
|
if (
|
||||||
|
$result['is_error'] == 0 &&
|
||||||
|
Configuration::get('twinglecampaign_start_case')
|
||||||
|
) {
|
||||||
|
$result = civicrm_api3('Case', 'create', [
|
||||||
|
'contact_id' => $formattedValues['contact_id'],
|
||||||
|
'creator_id' => $user,
|
||||||
|
'case_type_id' => Configuration::get('twinglecampaign_start_case'),
|
||||||
|
'subject' => $formattedValues['title'],
|
||||||
|
'start_date' => $formattedValues['created_at'],
|
||||||
|
'status_id' => "Open",
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// If this is a test, do not create campaign
|
// If this is a test, do not create campaign
|
||||||
else {
|
else {
|
||||||
|
@ -247,7 +265,7 @@ class TwingleEvent extends Campaign {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($values['user_name']) {
|
if ($values['user_name']) {
|
||||||
$values['user_name'] = $this->matchContact(
|
$values['contact_id'] = $this->matchContact(
|
||||||
$values['user_name'],
|
$values['user_name'],
|
||||||
$values['user_email']
|
$values['user_email']
|
||||||
);
|
);
|
||||||
|
|
|
@ -58,6 +58,15 @@ function _civicrm_api3_twingle_sync_Post_spec(array &$spec) {
|
||||||
function civicrm_api3_twingle_sync_Post(array $params) {
|
function civicrm_api3_twingle_sync_Post(array $params) {
|
||||||
$result_values = [];
|
$result_values = [];
|
||||||
|
|
||||||
|
// Who is calling?
|
||||||
|
$api_key = $_REQUEST['api_key'];
|
||||||
|
$user = CRM_Core_DAO::getFieldValue(
|
||||||
|
'CRM_Contact_DAO_Contact',
|
||||||
|
$api_key,
|
||||||
|
'id',
|
||||||
|
'api_key'
|
||||||
|
);
|
||||||
|
|
||||||
// Is this call a test?
|
// Is this call a test?
|
||||||
$is_test = (boolean) $params['is_test'];
|
$is_test = (boolean) $params['is_test'];
|
||||||
|
|
||||||
|
@ -93,7 +102,7 @@ function civicrm_api3_twingle_sync_Post(array $params) {
|
||||||
foreach ($events as $event) {
|
foreach ($events as $event) {
|
||||||
if ($event) {
|
if ($event) {
|
||||||
$result_values['sync']['events'][$j++] =
|
$result_values['sync']['events'][$j++] =
|
||||||
TwingleEvent::sync($event, $twingleApi, $is_test);
|
TwingleEvent::sync($event, $twingleApi, $user, $is_test);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue