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

first commit

parents
Branches
No related tags found
No related merge requests found
<?php
use CRM_Zapier_ExtensionUtil as E;
/**
* Form controller class
*
* @see https://docs.civicrm.org/dev/en/latest/framework/quickform/
*/
class CRM_Zapier_Form_ZapHooks extends CRM_Core_Form {
public function buildQuickForm() {
// add form elements
$this->add('text', 'create_contact', ts('Create Contact'), ['size' => 60]);
$this->add('text', 'update_participant', ts('Update Participant'), ['size' => 60]);
$this->addButtons(array(
array(
'type' => 'submit',
'name' => E::ts('Submit'),
'isDefault' => TRUE,
),
));
$zapHooks = unserialize(unserialize(Civi::settings()->get('zapierHooks')));
$this->setDefaults($zapHooks);
// export form elements
$this->assign('elementNames', $this->getRenderableElementNames());
parent::buildQuickForm();
}
public function postProcess() {
$values = $this->exportValues();
$zapHooks = serialize([
'create_contact' => $values['create_contact'] ?? '',
'update_participant' => $values['update_participant'] ?? '',
]);
Civi::settings()->set('zapierHooks', serialize($zapHooks));
CRM_Core_Session::setStatus(E::ts('Zapier hooks are saved.'));
parent::postProcess();
}
/**
* Get the fields/elements defined in this form.
*
* @return array (string)
*/
public function getRenderableElementNames() {
// The _elements list includes some items which should not be
// auto-rendered in the loop -- such as "qfKey" and "buttons". These
// items don't have labels. We'll identify renderable by filtering on
// the 'label'.
$elementNames = array();
foreach ($this->_elements as $element) {
/** @var HTML_QuickForm_Element $element */
$label = $element->getLabel();
if (!empty($label)) {
$elementNames[] = $element->getName();
}
}
return $elementNames;
}
}
<?php
class CRM_Zapier_Page_Auth {
public function run() {
$apiKey = CRM_Utils_Request::retrieveValue('apiKey', 'String', NULL, TRUE);
CRM_Utils_Request::retrieveValue('key', 'String', NULL, TRUE);
$contactsWithApiKey = \Civi\Api4\Contact::get(FALSE)
->addWhere('api_key', '=', $apiKey)
->execute()
->count();
if ($contactsWithApiKey < 1) {
throw new CRM_Core_Exception(ts('API Key not found.'));
}
$keyValid = CRM_Utils_System::authenticateKey(FALSE);
if (empty($keyValid)) {
throw new CRM_Core_Exception(ts('Invalid Site key.'));
}
CRM_Utils_JSON::output(['success']);
CRM_Utils_System::civiExit();
}
}
<?php
class CRM_Zapier_Page_Contact {
public function run() {
$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',
]
];
CRM_Utils_JSON::output($contact);
CRM_Utils_System::civiExit();
}
// public static function createContact($id) {
// }
}
<?php
class CRM_Zapier_Page_Participant {
public function run() {
$contact = [
0 => [
'id' => '134',
'contact_id' => 'John Doe',
'event_id' => 'Fall Fundraiser Dinner',
'status_id' => 'Registered',
'role_id' => 'Volunteer',
'source' => 'created from zapier',
'fee_amount' => '100',
]
];
CRM_Utils_JSON::output($contact);
CRM_Utils_System::civiExit();
}
}
\ No newline at end of file
<?php
class CRM_Zapier_Utils {
public static function saveHookURL($trigger, $url) {
$zapHooks = self::getZapHooks();
if (!empty($zapHooks[$trigger]) && $zapHooks[$trigger] == $url) {
return;
}
$zapHooks[$trigger] = $url;
Civi::settings()->set('zapierHooks', serialize($zapHooks));
}
public static function registerHooks() {
$inputJSON = file_get_contents('php://input');
$input = json_decode($inputJSON, TRUE);
$trigger = $input['triggers'][0] ?? '';
if (!empty($input['webhookUrl']) && !empty($trigger)) {
self::saveHookURL($trigger, $input['webhookUrl']);
$contact = [];
if ($trigger == 'create_contact') {
$contact = [
'id' => '134',
'first_name' => 'Dummy4',
'last_name' => 'Dummy4',
'email' => 'dummy4@email.com',
];
}
elseif ($trigger == 'create_contact') {
$contact = [
'id' => '134',
'contact_id' => 'John Doe',
'event_id' => 'Fall Fundraiser Dinner',
'status_id' => 'Registered',
'role_id' => 'Volunteer',
'source' => 'created from zapier',
'fee_amount' => '100',
];
}
CRM_Zapier_Utils::triggerZap('POST', $input['webhookUrl'], $contact);
}
}
public static function getZapHooks() {
return self::unserialize_recursive(Civi::settings()->get('zapierHooks'));
}
public static function getZapHook($name) {
$zapHooks = self::getZapHooks();
return $zapHooks[$name] ?? NULL;
}
public static function unserialize_recursive($val) {
//$pattern = "/.*\{(.*)\}/";
if(self::is_serialized($val)){
$val = trim($val);
$ret = unserialize($val);
if (is_array($ret)) {
foreach($ret as &$r) $r = self::unserialize_recursive($r);
}
return $ret;
} elseif (is_array($val)) {
foreach($val as &$r) $r = self::unserialize_recursive($r);
return $val;
} else { return $val; }
}
public static function is_serialized($val) {
if (!is_string($val)) return false;
if (trim($val) == "") return false;
$val = trim($val);
if (preg_match('/^(i|s|a|o|d):.*{/si', $val) > 0) return true;
return false;
}
/**
*
* @param $method
* @param $url
* @param $data
*/
public static function triggerZap($method, $url, $data = array()) {
$curl = curl_init();
switch ($method) {
case "POST":
curl_setopt($curl, CURLOPT_POST, 1);
if ($data)
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
break;
case "PUT":
curl_setopt($curl, CURLOPT_PUT, 1);
break;
default:
if ($data)
$url = sprintf("%s?%s", $url, http_build_query($data));
}
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);
return json_decode($result);
}
}
\ No newline at end of file
This diff is collapsed.
# nz.co.fuzion.zapier
![Screenshot](/images/screenshot.png)
(*FIXME: In one or two paragraphs, describe what the extension does and why one would download it. *)
The extension is licensed under [AGPL-3.0](LICENSE.txt).
## Requirements
* PHP v7.0+
* CiviCRM (*FIXME: Version number*)
## Installation (Web UI)
This extension has not yet been published for installation via the web UI.
## Installation (CLI, Zip)
Sysadmins and developers may download the `.zip` file for this extension and
install it with the command-line tool [cv](https://github.com/civicrm/cv).
```bash
cd <extension-dir>
cv dl nz.co.fuzion.zapier@https://github.com/FIXME/nz.co.fuzion.zapier/archive/master.zip
```
## Installation (CLI, Git)
Sysadmins and developers may clone the [Git](https://en.wikipedia.org/wiki/Git) repo for this extension and
install it with the command-line tool [cv](https://github.com/civicrm/cv).
```bash
git clone https://github.com/FIXME/nz.co.fuzion.zapier.git
cv en zapier
```
## Usage
(* FIXME: Where would a new user navigate to get started? What changes would they see? *)
## Known Issues
(* FIXME *)
images/screenshot.png

11.5 KiB

info.xml 0 → 100644
<?xml version="1.0"?>
<extension key="nz.co.fuzion.zapier" type="module">
<file>zapier</file>
<name>CiviZap</name>
<description>Triggers zap for civicrm events</description>
<license>AGPL-3.0</license>
<maintainer>
<author>jitendrapurohit</author>
<email>jitendra@fuzion.co.nz</email>
</maintainer>
<urls>
<url desc="Main Extension Page">http://FIXME</url>
<url desc="Documentation">http://FIXME</url>
<url desc="Support">http://FIXME</url>
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
</urls>
<releaseDate>2021-06-15</releaseDate>
<version>1.0</version>
<develStage>alpha</develStage>
<compatibility>
<ver>5.0</ver>
</compatibility>
<comments>This is a new, undeveloped module</comments>
<classloader>
<psr4 prefix="Civi\" path="Civi"/>
</classloader>
<civix>
<namespace>CRM/Zapier</namespace>
</civix>
</extension>
{* HEADER *}
<div class="crm-submit-buttons">
{include file="CRM/common/formButtons.tpl" location="top"}
</div>
{* FIELD EXAMPLE: OPTION 1 (AUTOMATIC LAYOUT) *}
{foreach from=$elementNames item=elementName}
<div class="crm-section">
<div class="label">{$form.$elementName.label}</div>
<div class="content">{$form.$elementName.html}</div>
<div class="clear"></div>
</div>
{/foreach}
{* FIELD EXAMPLE: OPTION 2 (MANUAL LAYOUT)
<div>
<span>{$form.favorite_color.label}</span>
<span>{$form.favorite_color.html}</span>
</div>
{* FOOTER *}
<div class="crm-submit-buttons">
{include file="CRM/common/formButtons.tpl" location="bottom"}
</div>
<?xml version="1.0"?>
<menu>
<item>
<path>civicrm/zapierauth</path>
<page_callback>CRM_Zapier_Page_Auth</page_callback>
<title>Auth</title>
<access_callback>1</access_callback>
<is_public>true</is_public>
</item>
<item>
<path>civicrm/zapier/contacts</path>
<page_callback>CRM_Zapier_Page_Contact</page_callback>
<access_callback>1</access_callback>
<is_public>true</is_public>
</item>
<item>
<path>civicrm/zapier/participants</path>
<page_callback>CRM_Zapier_Page_Participant</page_callback>
<access_callback>1</access_callback>
<is_public>true</is_public>
</item>
<item>
<path>civicrm/zaphooks</path>
<page_callback>CRM_Zapier_Form_ZapHooks</page_callback>
<title>ZapHooks</title>
<access_arguments>access CiviCRM</access_arguments>
</item>
<item>
<path>civicrm/zaphooks/new</path>
<page_callback>CRM_Zapier_Utils::registerHooks</page_callback>
<access_callback>1</access_callback>
<is_public>true</is_public>
<weight>0</weight>
</item>
</menu>
<?php
// AUTO-GENERATED FILE -- Civix may overwrite any changes made to this file
/**
* The ExtensionUtil class provides small stubs for accessing resources of this
* extension.
*/
class CRM_Zapier_ExtensionUtil {
const SHORT_NAME = "zapier";
const LONG_NAME = "nz.co.fuzion.zapier";
const CLASS_PREFIX = "CRM_Zapier";
/**
* Translate a string using the extension's domain.
*
* If the extension doesn't have a specific translation
* for the string, fallback to the default translations.
*
* @param string $text
* Canonical message text (generally en_US).
* @param array $params
* @return string
* Translated text.
* @see ts
*/
public static function ts($text, $params = []) {
if (!array_key_exists('domain', $params)) {
$params['domain'] = [self::LONG_NAME, NULL];
}
return ts($text, $params);
}
/**
* Get the URL of a resource file (in this extension).
*
* @param string|NULL $file
* Ex: NULL.
* Ex: 'css/foo.css'.
* @return string
* Ex: 'http://example.org/sites/default/ext/org.example.foo'.
* Ex: 'http://example.org/sites/default/ext/org.example.foo/css/foo.css'.
*/
public static function url($file = NULL) {
if ($file === NULL) {
return rtrim(CRM_Core_Resources::singleton()->getUrl(self::LONG_NAME), '/');
}
return CRM_Core_Resources::singleton()->getUrl(self::LONG_NAME, $file);
}
/**
* Get the path of a resource file (in this extension).
*
* @param string|NULL $file
* Ex: NULL.
* Ex: 'css/foo.css'.
* @return string
* Ex: '/var/www/example.org/sites/default/ext/org.example.foo'.
* Ex: '/var/www/example.org/sites/default/ext/org.example.foo/css/foo.css'.
*/
public static function path($file = NULL) {
// return CRM_Core_Resources::singleton()->getPath(self::LONG_NAME, $file);
return __DIR__ . ($file === NULL ? '' : (DIRECTORY_SEPARATOR . $file));
}
/**
* Get the name of a class within this extension.
*
* @param string $suffix
* Ex: 'Page_HelloWorld' or 'Page\\HelloWorld'.
* @return string
* Ex: 'CRM_Foo_Page_HelloWorld'.
*/
public static function findClass($suffix) {
return self::CLASS_PREFIX . '_' . str_replace('\\', '_', $suffix);
}
}
use CRM_Zapier_ExtensionUtil as E;
/**
* (Delegated) Implements hook_civicrm_config().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_config
*/
function _zapier_civix_civicrm_config(&$config = NULL) {
static $configured = FALSE;
if ($configured) {
return;
}
$configured = TRUE;
$template =& CRM_Core_Smarty::singleton();
$extRoot = dirname(__FILE__) . DIRECTORY_SEPARATOR;
$extDir = $extRoot . 'templates';
if (is_array($template->template_dir)) {
array_unshift($template->template_dir, $extDir);
}
else {
$template->template_dir = [$extDir, $template->template_dir];
}
$include_path = $extRoot . PATH_SEPARATOR . get_include_path();
set_include_path($include_path);
}
/**
* (Delegated) Implements hook_civicrm_xmlMenu().
*
* @param $files array(string)
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_xmlMenu
*/
function _zapier_civix_civicrm_xmlMenu(&$files) {
foreach (_zapier_civix_glob(__DIR__ . '/xml/Menu/*.xml') as $file) {
$files[] = $file;
}
}
/**
* Implements hook_civicrm_install().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_install
*/
function _zapier_civix_civicrm_install() {
_zapier_civix_civicrm_config();
if ($upgrader = _zapier_civix_upgrader()) {
$upgrader->onInstall();
}
}
/**
* Implements hook_civicrm_postInstall().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_postInstall
*/
function _zapier_civix_civicrm_postInstall() {
_zapier_civix_civicrm_config();
if ($upgrader = _zapier_civix_upgrader()) {
if (is_callable([$upgrader, 'onPostInstall'])) {
$upgrader->onPostInstall();
}
}
}
/**
* Implements hook_civicrm_uninstall().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_uninstall
*/
function _zapier_civix_civicrm_uninstall() {
_zapier_civix_civicrm_config();
if ($upgrader = _zapier_civix_upgrader()) {
$upgrader->onUninstall();
}
}
/**
* (Delegated) Implements hook_civicrm_enable().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_enable
*/
function _zapier_civix_civicrm_enable() {
_zapier_civix_civicrm_config();
if ($upgrader = _zapier_civix_upgrader()) {
if (is_callable([$upgrader, 'onEnable'])) {
$upgrader->onEnable();
}
}
}
/**
* (Delegated) Implements hook_civicrm_disable().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_disable
* @return mixed
*/
function _zapier_civix_civicrm_disable() {
_zapier_civix_civicrm_config();
if ($upgrader = _zapier_civix_upgrader()) {
if (is_callable([$upgrader, 'onDisable'])) {
$upgrader->onDisable();
}
}
}
/**
* (Delegated) Implements hook_civicrm_upgrade().
*
* @param $op string, the type of operation being performed; 'check' or 'enqueue'
* @param $queue CRM_Queue_Queue, (for 'enqueue') the modifiable list of pending up upgrade tasks
*
* @return mixed based on op. for 'check', returns array(boolean) (TRUE if upgrades are pending)
* for 'enqueue', returns void
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_upgrade
*/
function _zapier_civix_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) {
if ($upgrader = _zapier_civix_upgrader()) {
return $upgrader->onUpgrade($op, $queue);
}
}
/**
* @return CRM_Zapier_Upgrader
*/
function _zapier_civix_upgrader() {
if (!file_exists(__DIR__ . '/CRM/Zapier/Upgrader.php')) {
return NULL;
}
else {
return CRM_Zapier_Upgrader_Base::instance();
}
}
/**
* Search directory tree for files which match a glob pattern.
*
* Note: Dot-directories (like "..", ".git", or ".svn") will be ignored.
* Note: In Civi 4.3+, delegate to CRM_Utils_File::findFiles()
*
* @param string $dir base dir
* @param string $pattern , glob pattern, eg "*.txt"
*
* @return array(string)
*/
function _zapier_civix_find_files($dir, $pattern) {
if (is_callable(['CRM_Utils_File', 'findFiles'])) {
return CRM_Utils_File::findFiles($dir, $pattern);
}
$todos = [$dir];
$result = [];
while (!empty($todos)) {
$subdir = array_shift($todos);
foreach (_zapier_civix_glob("$subdir/$pattern") as $match) {
if (!is_dir($match)) {
$result[] = $match;
}
}
if ($dh = opendir($subdir)) {
while (FALSE !== ($entry = readdir($dh))) {
$path = $subdir . DIRECTORY_SEPARATOR . $entry;
if ($entry{0} == '.') {
}
elseif (is_dir($path)) {
$todos[] = $path;
}
}
closedir($dh);
}
}
return $result;
}
/**
* (Delegated) Implements hook_civicrm_managed().
*
* Find any *.mgd.php files, merge their content, and return.
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_managed
*/
function _zapier_civix_civicrm_managed(&$entities) {
$mgdFiles = _zapier_civix_find_files(__DIR__, '*.mgd.php');
sort($mgdFiles);
foreach ($mgdFiles as $file) {
$es = include $file;
foreach ($es as $e) {
if (empty($e['module'])) {
$e['module'] = E::LONG_NAME;
}
if (empty($e['params']['version'])) {
$e['params']['version'] = '3';
}
$entities[] = $e;
}
}
}
/**
* (Delegated) Implements hook_civicrm_caseTypes().
*
* Find any and return any files matching "xml/case/*.xml"
*
* Note: This hook only runs in CiviCRM 4.4+.
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_caseTypes
*/
function _zapier_civix_civicrm_caseTypes(&$caseTypes) {
if (!is_dir(__DIR__ . '/xml/case')) {
return;
}
foreach (_zapier_civix_glob(__DIR__ . '/xml/case/*.xml') as $file) {
$name = preg_replace('/\.xml$/', '', basename($file));
if ($name != CRM_Case_XMLProcessor::mungeCaseType($name)) {
$errorMessage = sprintf("Case-type file name is malformed (%s vs %s)", $name, CRM_Case_XMLProcessor::mungeCaseType($name));
throw new CRM_Core_Exception($errorMessage);
}
$caseTypes[$name] = [
'module' => E::LONG_NAME,
'name' => $name,
'file' => $file,
];
}
}
/**
* (Delegated) Implements hook_civicrm_angularModules().
*
* Find any and return any files matching "ang/*.ang.php"
*
* Note: This hook only runs in CiviCRM 4.5+.
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_angularModules
*/
function _zapier_civix_civicrm_angularModules(&$angularModules) {
if (!is_dir(__DIR__ . '/ang')) {
return;
}
$files = _zapier_civix_glob(__DIR__ . '/ang/*.ang.php');
foreach ($files as $file) {
$name = preg_replace(':\.ang\.php$:', '', basename($file));
$module = include $file;
if (empty($module['ext'])) {
$module['ext'] = E::LONG_NAME;
}
$angularModules[$name] = $module;
}
}
/**
* (Delegated) Implements hook_civicrm_themes().
*
* Find any and return any files matching "*.theme.php"
*/
function _zapier_civix_civicrm_themes(&$themes) {
$files = _zapier_civix_glob(__DIR__ . '/*.theme.php');
foreach ($files as $file) {
$themeMeta = include $file;
if (empty($themeMeta['name'])) {
$themeMeta['name'] = preg_replace(':\.theme\.php$:', '', basename($file));
}
if (empty($themeMeta['ext'])) {
$themeMeta['ext'] = E::LONG_NAME;
}
$themes[$themeMeta['name']] = $themeMeta;
}
}
/**
* Glob wrapper which is guaranteed to return an array.
*
* The documentation for glob() says, "On some systems it is impossible to
* distinguish between empty match and an error." Anecdotally, the return
* result for an empty match is sometimes array() and sometimes FALSE.
* This wrapper provides consistency.
*
* @link http://php.net/glob
* @param string $pattern
*
* @return array, possibly empty
*/
function _zapier_civix_glob($pattern) {
$result = glob($pattern);
return is_array($result) ? $result : [];
}
/**
* Inserts a navigation menu item at a given place in the hierarchy.
*
* @param array $menu - menu hierarchy
* @param string $path - path to parent of this item, e.g. 'my_extension/submenu'
* 'Mailing', or 'Administer/System Settings'
* @param array $item - the item to insert (parent/child attributes will be
* filled for you)
*
* @return bool
*/
function _zapier_civix_insert_navigation_menu(&$menu, $path, $item) {
// If we are done going down the path, insert menu
if (empty($path)) {
$menu[] = [
'attributes' => array_merge([
'label' => CRM_Utils_Array::value('name', $item),
'active' => 1,
], $item),
];
return TRUE;
}
else {
// Find an recurse into the next level down
$found = FALSE;
$path = explode('/', $path);
$first = array_shift($path);
foreach ($menu as $key => &$entry) {
if ($entry['attributes']['name'] == $first) {
if (!isset($entry['child'])) {
$entry['child'] = [];
}
$found = _zapier_civix_insert_navigation_menu($entry['child'], implode('/', $path), $item);
}
}
return $found;
}
}
/**
* (Delegated) Implements hook_civicrm_navigationMenu().
*/
function _zapier_civix_navigationMenu(&$nodes) {
if (!is_callable(['CRM_Core_BAO_Navigation', 'fixNavigationMenu'])) {
_zapier_civix_fixNavigationMenu($nodes);
}
}
/**
* Given a navigation menu, generate navIDs for any items which are
* missing them.
*/
function _zapier_civix_fixNavigationMenu(&$nodes) {
$maxNavID = 1;
array_walk_recursive($nodes, function($item, $key) use (&$maxNavID) {
if ($key === 'navID') {
$maxNavID = max($maxNavID, $item);
}
});
_zapier_civix_fixNavigationMenuItems($nodes, $maxNavID, NULL);
}
function _zapier_civix_fixNavigationMenuItems(&$nodes, &$maxNavID, $parentID) {
$origKeys = array_keys($nodes);
foreach ($origKeys as $origKey) {
if (!isset($nodes[$origKey]['attributes']['parentID']) && $parentID !== NULL) {
$nodes[$origKey]['attributes']['parentID'] = $parentID;
}
// If no navID, then assign navID and fix key.
if (!isset($nodes[$origKey]['attributes']['navID'])) {
$newKey = ++$maxNavID;
$nodes[$origKey]['attributes']['navID'] = $newKey;
$nodes[$newKey] = $nodes[$origKey];
unset($nodes[$origKey]);
$origKey = $newKey;
}
if (isset($nodes[$origKey]['child']) && is_array($nodes[$origKey]['child'])) {
_zapier_civix_fixNavigationMenuItems($nodes[$origKey]['child'], $maxNavID, $nodes[$origKey]['attributes']['navID']);
}
}
}
/**
* (Delegated) Implements hook_civicrm_alterSettingsFolders().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_alterSettingsFolders
*/
function _zapier_civix_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) {
$settingsDir = __DIR__ . DIRECTORY_SEPARATOR . 'settings';
if (!in_array($settingsDir, $metaDataFolders) && is_dir($settingsDir)) {
$metaDataFolders[] = $settingsDir;
}
}
/**
* (Delegated) Implements hook_civicrm_entityTypes().
*
* Find any *.entityType.php files, merge their content, and return.
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_entityTypes
*/
function _zapier_civix_civicrm_entityTypes(&$entityTypes) {
$entityTypes = array_merge($entityTypes, array (
));
}
<?php
require_once 'zapier.civix.php';
use CRM_Zapier_ExtensionUtil as E;
/**
* Implements hook_civicrm_config().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_config/
*/
function zapier_civicrm_config(&$config) {
_zapier_civix_civicrm_config($config);
}
/**
* Implements hook_civicrm_xmlMenu().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_xmlMenu
*/
function zapier_civicrm_xmlMenu(&$files) {
_zapier_civix_civicrm_xmlMenu($files);
}
/**
* Implements hook_civicrm_install().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_install
*/
function zapier_civicrm_install() {
_zapier_civix_civicrm_install();
}
/**
* Implements hook_civicrm_postInstall().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_postInstall
*/
function zapier_civicrm_postInstall() {
_zapier_civix_civicrm_postInstall();
}
/**
* Implements hook_civicrm_uninstall().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_uninstall
*/
function zapier_civicrm_uninstall() {
_zapier_civix_civicrm_uninstall();
}
/**
* Implements hook_civicrm_enable().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_enable
*/
function zapier_civicrm_enable() {
_zapier_civix_civicrm_enable();
}
/**
* Implements hook_civicrm_disable().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_disable
*/
function zapier_civicrm_disable() {
_zapier_civix_civicrm_disable();
}
function zapier_civicrm_post($op, $objectName, $objectId, &$objectRef) {
if (($op == 'create' || $op == 'edit') && $objectName == 'Individual') {
$email = civicrm_api3('Email', 'get', [
'sequential' => 1,
'contact_id' => $objectId,
'is_primary' => 1,
])['values'][0]['email'] ?? '';
$data = [
'id' => $objectId,
'first_name' => $objectRef->first_name,
'last_name' => $objectRef->last_name,
'email' => $email,
];
$hookURL = CRM_Zapier_Utils::getZapHook('create_contact');
CRM_Zapier_Utils::triggerZap('POST', $hookURL, $data);
}
if (($op == 'create' || $op == 'edit') && $objectName == 'Participant') {
$participant = civicrm_api3('Participant', 'get', [
'sequential' => 1,
'id' => $objectId,
])['values'][0] ?? [];
$data = [
'id' => $objectId,
'contact_id' => $participant['display_name'] ?? '',
'event_id' => $participant['event_title'] ?? '',
'status_id' => $participant['participant_status'] ?? '',
'role_id' => $participant['participant_role'] ?? '',
'source' => $participant['participant_source'] ?? '',
'fee_amount' => $participant['participant_fee_amount'] ?? '',
];
$hookURL = CRM_Zapier_Utils::getZapHook('update_participant');
CRM_Zapier_Utils::triggerZap('POST', $hookURL, $data);
}
}
/**
* Implements hook_civicrm_upgrade().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_upgrade
*/
function zapier_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) {
return _zapier_civix_civicrm_upgrade($op, $queue);
}
/**
* Implements hook_civicrm_managed().
*
* Generate a list of entities to create/deactivate/delete when this module
* is installed, disabled, uninstalled.
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_managed
*/
function zapier_civicrm_managed(&$entities) {
_zapier_civix_civicrm_managed($entities);
}
/**
* Implements hook_civicrm_caseTypes().
*
* Generate a list of case-types.
*
* Note: This hook only runs in CiviCRM 4.4+.
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_caseTypes
*/
function zapier_civicrm_caseTypes(&$caseTypes) {
_zapier_civix_civicrm_caseTypes($caseTypes);
}
/**
* Implements hook_civicrm_angularModules().
*
* Generate a list of Angular modules.
*
* Note: This hook only runs in CiviCRM 4.5+. It may
* use features only available in v4.6+.
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_angularModules
*/
function zapier_civicrm_angularModules(&$angularModules) {
_zapier_civix_civicrm_angularModules($angularModules);
}
/**
* Implements hook_civicrm_alterSettingsFolders().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_alterSettingsFolders
*/
function zapier_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) {
_zapier_civix_civicrm_alterSettingsFolders($metaDataFolders);
}
/**
* Implements hook_civicrm_entityTypes().
*
* Declare entity types provided by this module.
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_entityTypes
*/
function zapier_civicrm_entityTypes(&$entityTypes) {
_zapier_civix_civicrm_entityTypes($entityTypes);
}
/**
* Implements hook_civicrm_thems().
*/
function zapier_civicrm_themes(&$themes) {
_zapier_civix_civicrm_themes($themes);
}
// --- Functions below this ship commented out. Uncomment as required. ---
/**
* Implements hook_civicrm_preProcess().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_preProcess
*
function zapier_civicrm_preProcess($formName, &$form) {
} // */
/**
* Implements hook_civicrm_navigationMenu().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_navigationMenu
*
function zapier_civicrm_navigationMenu(&$menu) {
_zapier_civix_insert_navigation_menu($menu, 'Mailings', array(
'label' => E::ts('New subliminal message'),
'name' => 'mailing_subliminal_message',
'url' => 'civicrm/mailing/subliminal',
'permission' => 'access CiviMail',
'operator' => 'OR',
'separator' => 0,
));
_zapier_civix_navigationMenu($menu);
} // */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment