Skip to content
Snippets Groups Projects
Commit 6e0acb6b authored by jitendra's avatar jitendra
Browse files

Dru fixes

parent 43df3b1b
Branches
No related tags found
No related merge requests found
......@@ -50,23 +50,9 @@ class CRM_CivirulesActions_Zapier_Trigger extends CRM_Civirules_Action {
*/
public function userFriendlyConditionParams() {
$params = $this->getActionParameters();
$roles = self::getZapOptions();
$roles = CRM_Zapier_Utils::getZapOptions();
$zap = $roles[$params['zap_trigger']];
return E::ts('Trigger Zap for <em>%1</em>', array(1 => $zap));
}
/**
* Returns a list of possible case roles
*
* @return array
* @throws \CiviCRM_API3_Exception
*/
public static function getZapOptions() {
$caseRoles = [
'create_contact' => 'Create Contact',
'update_participant' => 'Update Participant',
];
return $caseRoles;
}
}
......@@ -9,20 +9,6 @@ use CRM_Zapier_ExtensionUtil as E;
*/
class CRM_Zapier_Form_TriggerZap extends CRM_CivirulesActions_Form_Form {
/**
* Method to get groups
*
* @return array
* @access protected
*/
protected function getZapOptions() {
$options = [
'create_contact' => 'Create Contact',
'update_participant' => 'Update Participant',
];
return $options;
}
/**
* Overridden parent method to build the form
*
......@@ -31,7 +17,7 @@ class CRM_Zapier_Form_TriggerZap extends CRM_CivirulesActions_Form_Form {
public function buildQuickForm() {
$this->add('hidden', 'rule_action_id');
$this->add('select', 'zap', ts('Select triggering Zap'), array('' => ts('-- please select --')) + $this->getZapOptions());
$this->add('select', 'zap', ts('Select triggering Zap'), array('' => ts('-- please select --')) + CRM_Zapier_Utils::getZapOptions());
$this->addButtons(array(
array('type' => 'next', 'name' => ts('Save'), 'isDefault' => TRUE,),
array('type' => 'cancel', 'name' => ts('Cancel'))));
......
......@@ -23,7 +23,7 @@ class CRM_Zapier_Form_ZapHooks extends CRM_Core_Form {
),
));
$zapHooks = unserialize(unserialize(Civi::settings()->get('zapierHooks')));
$zapHooks = unserialize(Civi::settings()->get('zapierHooks'));
$this->setDefaults($zapHooks);
// export form elements
......
......@@ -2,57 +2,41 @@
class CRM_Zapier_Page_Contact {
private function sampleContact() {
return [[
'id' => '1',
'first_name' => 'Dummy',
'last_name' => 'Dummy',
'email' => 'dummy@email.com',
]];
}
public function run() {
$inputJSON = file_get_contents('php://input');
$input = json_decode($inputJSON, TRUE); //convert JSON into array
// $inputJSON = file_get_contents('php://input');
// $input = json_decode($inputJSON, TRUE); //convert JSON into array
$id = CRM_Utils_Request::retrieveValue('id', 'Integer', NULL, FALSE);
if (empty($id)) {
$contact = [
0 => [
'id' => '1',
'first_name' => 'Dummy22',
'last_name' => 'Dummy22',
'email' => 'dummy22@email.com',
],
1 => [
'id' => '2',
'first_name' => 'Dummy2',
'last_name' => 'Dummy2',
'email' => 'dummy2@email.com',
],
];
}
else {
$contact = \Civi\Api4\Contact::get(FALSE)
->addWhere('id', '=', $id)
->execute()
->first();
if (empty($contact['id'])) {
$contact = [
0 => [
'id' => '1',
'first_name' => 'Dummy',
'last_name' => 'Dummy',
'email' => 'dummy@email.com',
],
1 => [
'id' => '2',
'first_name' => 'Dummy2',
'last_name' => 'Dummy2',
'email' => 'dummy2@email.com',
],
];
}
}
$contact = [
0 => [
'id' => '134',
'first_name' => 'Dummy4',
'last_name' => 'Dummy4',
'email' => 'dummy4@email.com',
]
];
// $id = CRM_Utils_Request::retrieveValue('id', 'Integer', NULL, FALSE);
// if (empty($id)) {
// $contact = $this->sampleContact();
// }
// else {
// $contact = \Civi\Api4\Contact::get(FALSE)
// ->addWhere('id', '=', $id)
// ->execute()
// ->first();
// if (empty($contact['id'])) {
// $contact = $this->sampleContact();
// }
// }
$contact = $this->sampleContact();
// $contact = [
// 0 => [
// 'id' => '134',
// 'first_name' => 'Dummy4',
// 'last_name' => 'Dummy4',
// 'email' => 'dummy4@email.com',
// ]
// ];
CRM_Utils_JSON::output($contact);
CRM_Utils_System::civiExit();
......
......@@ -8,6 +8,9 @@ class CRM_Zapier_Page_Participant {
0 => [
'id' => '134',
'contact_id' => 'John Doe',
'contact_first_name' => 'John',
'contact_last_name' => 'Doe',
'contact_email' => 'john.doe@example.com',
'event_id' => 'Fall Fundraiser Dinner',
'status_id' => 'Registered',
'role_id' => 'Volunteer',
......
......@@ -7,10 +7,17 @@ class CRM_Zapier_Triggers_UpdateParticipant {
'sequential' => 1,
'id' => $participantID,
])['values'][0] ?? [];
$contact = civicrm_api3('Contact', 'get', [
'sequential' => 1,
'id' => $participant['contact_id'],
])['values'][0] ?? [];
$data = [
'id' => $participantID,
'contact_id' => $participant['display_name'] ?? '',
'contact_first_name' => $contact['first_name'] ?? '',
'contact_last_name' => $contact['last_name'] ?? '',
'contact_email' => $contact['email'] ?? '',
'event_id' => $participant['event_title'] ?? '',
'status_id' => $participant['participant_status'] ?? '',
'role_id' => $participant['participant_role'] ?? '',
......
......@@ -2,6 +2,22 @@
class CRM_Zapier_Utils {
/**
* Returns a list of zap options
*
* @return array
* @throws \CiviCRM_API3_Exception
*/
public static function getZapOptions() {
return [
'create_contact' => 'Create Contact',
'update_participant' => 'Update Participant',
];
}
/**
* Save hook URLs in the database.
*/
public static function saveHookURL($trigger, $url) {
$zapHooks = self::getZapHooks();
if (!empty($zapHooks[$trigger]) && $zapHooks[$trigger] == $url) {
......@@ -12,6 +28,11 @@ class CRM_Zapier_Utils {
Civi::settings()->set('zapierHooks', serialize($zapHooks));
}
/**
* This is called when create contact hook is selected on zapier.
*
* The hook is registered in civicrm and is triggerred via civirules.
*/
public static function registerHooks() {
$inputJSON = file_get_contents('php://input');
$input = json_decode($inputJSON, TRUE);
......@@ -27,7 +48,7 @@ class CRM_Zapier_Utils {
'email' => 'dummy4@email.com',
];
}
elseif ($trigger == 'create_contact') {
elseif ($trigger == 'update_participant') {
$contact = [
'id' => '134',
'contact_id' => 'John Doe',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment