First commit
This commit is contained in:
commit
c6e2478c40
13918 changed files with 2303184 additions and 0 deletions
7
sites/all/modules/civicrm/drupal/TESTING.md
Normal file
7
sites/all/modules/civicrm/drupal/TESTING.md
Normal file
|
@ -0,0 +1,7 @@
|
|||
This repository contains the CiviCRM-Drupal integration module. It does NOT
|
||||
contain tests for core functionality. (For tests of core functionality, see
|
||||
https://github.com/civicrm/civicrm-core .)
|
||||
|
||||
At time of writing, these tests execute within the context of the default
|
||||
Drupal database. Consequently, you must be quite careful to write tests
|
||||
which don't leave a mess in the database.
|
127
sites/all/modules/civicrm/drupal/civicrm.config.php.drupal
Normal file
127
sites/all/modules/civicrm/drupal/civicrm.config.php.drupal
Normal file
|
@ -0,0 +1,127 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* This function has been copied from DRUPAL_ROOT/includes/bootstrap.inc
|
||||
*/
|
||||
|
||||
/**
|
||||
* Locate the appropriate configuration file.
|
||||
*
|
||||
* Try finding a matching configuration directory by stripping the
|
||||
* website's hostname from left to right and pathname from right to
|
||||
* left. The first configuration file found will be used, the
|
||||
* remaining will ignored. If no configuration file is found,
|
||||
* return a default value '$confdir/default'.
|
||||
*
|
||||
* Example for a fictitious site installed at
|
||||
* http://www.drupal.org/mysite/test/ the 'settings.php' is
|
||||
* searched in the following directories:
|
||||
*
|
||||
* 1. $confdir/www.drupal.org.mysite.test
|
||||
* 2. $confdir/drupal.org.mysite.test
|
||||
* 3. $confdir/org.mysite.test
|
||||
*
|
||||
* 4. $confdir/www.drupal.org.mysite
|
||||
* 5. $confdir/drupal.org.mysite
|
||||
* 6. $confdir/org.mysite
|
||||
*
|
||||
* 7. $confdir/www.drupal.org
|
||||
* 8. $confdir/drupal.org
|
||||
* 9. $confdir/org
|
||||
*
|
||||
* 10. $confdir/default
|
||||
*
|
||||
*/
|
||||
function civicrm_conf_init() {
|
||||
global $skipConfigError;
|
||||
|
||||
static $conf = '';
|
||||
|
||||
if ($conf) {
|
||||
return $conf;
|
||||
}
|
||||
|
||||
/**
|
||||
* We are within the civicrm module, the drupal root is 2 links
|
||||
* above us, so use that
|
||||
*/
|
||||
$currentDir = dirname(__FILE__) . DIRECTORY_SEPARATOR;
|
||||
if (file_exists($currentDir . 'settings_location.php')) {
|
||||
include $currentDir . 'settings_location.php';
|
||||
}
|
||||
|
||||
if (defined('CIVICRM_CONFDIR') && !isset($confdir)) {
|
||||
$confdir = CIVICRM_CONFDIR;
|
||||
}
|
||||
else {
|
||||
// make it relative to civicrm.config.php, else php makes it relative
|
||||
// to the script that invokes it
|
||||
$moduleDir = 'sites' . DIRECTORY_SEPARATOR . 'all' . DIRECTORY_SEPARATOR . 'modules';
|
||||
$contribDir = $moduleDir . DIRECTORY_SEPARATOR . 'contrib';
|
||||
// check to see if this is under sites/all/modules/contrib or subdir civicrm-core
|
||||
if (strpos($currentDir, $contribDir) !== FALSE || strpos($currentDir, 'civicrm-core') !== FALSE) {
|
||||
$confdir = $currentDir . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..';
|
||||
}
|
||||
// check to see if this is under sites/all/modules
|
||||
elseif (strpos($currentDir, $moduleDir) !== FALSE) {
|
||||
$confdir = $currentDir . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..';
|
||||
}
|
||||
else {
|
||||
$confdir = $currentDir . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR;
|
||||
}
|
||||
}
|
||||
|
||||
if (file_exists($confdir . DIRECTORY_SEPARATOR . 'civicrm.settings.php')) {
|
||||
return $confdir;
|
||||
}
|
||||
|
||||
if (!file_exists($confdir) && !$skipConfigError) {
|
||||
echo "Could not find valid configuration dir, best guess: $confdir<br/><br/>\n";
|
||||
exit();
|
||||
}
|
||||
|
||||
// since drupal 7, alias could be defined in sites/sites.php
|
||||
if (file_exists($confdir . "/sites.php")) {
|
||||
include $confdir . "/sites.php";
|
||||
}
|
||||
else {
|
||||
$sites = array();
|
||||
}
|
||||
|
||||
$phpSelf = array_key_exists('PHP_SELF', $_SERVER) ? $_SERVER['PHP_SELF'] : '';
|
||||
$httpHost = array_key_exists('HTTP_HOST', $_SERVER) ? $_SERVER['HTTP_HOST'] : '';
|
||||
|
||||
$uri = explode('/', $phpSelf);
|
||||
$server = explode('.', implode('.', array_reverse(explode(':', rtrim($httpHost, '.')))));
|
||||
for ($i = count($uri) - 1; $i > 0; $i--) {
|
||||
for ($j = count($server); $j > 0; $j--) {
|
||||
$dir = implode('.', array_slice($server, -$j)) . implode('.', array_slice($uri, 0, $i));
|
||||
if (file_exists("$confdir/$dir/civicrm.settings.php")) {
|
||||
$conf = "$confdir/$dir";
|
||||
return $conf;
|
||||
}
|
||||
// check for alias
|
||||
if (isset($sites[$dir]) && file_exists("$confdir/{$sites[$dir]}/civicrm.settings.php")) {
|
||||
$conf = "$confdir/{$sites[$dir]}";
|
||||
return $conf;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: problem spot for Drupal 5.1 config dir layout
|
||||
$conf = "$confdir/default";
|
||||
return $conf;
|
||||
}
|
||||
|
||||
$settingsFile = civicrm_conf_init() . '/civicrm.settings.php';
|
||||
define('CIVICRM_SETTINGS_PATH', $settingsFile);
|
||||
$error = include_once $settingsFile;
|
||||
if ($error == FALSE) {
|
||||
echo "Could not load the settings file at: {$settingsFile}\n";
|
||||
exit();
|
||||
}
|
||||
|
||||
// Load class loader
|
||||
global $civicrm_root;
|
||||
require_once $civicrm_root . '/CRM/Core/ClassLoader.php';
|
||||
CRM_Core_ClassLoader::singleton()->register();
|
102
sites/all/modules/civicrm/drupal/civicrm.info
Normal file
102
sites/all/modules/civicrm/drupal/civicrm.info
Normal file
|
@ -0,0 +1,102 @@
|
|||
name = CiviCRM
|
||||
description = Constituent relationship management system. Allows sites to manage contacts, relationships and groups, and track contact activities, contributions, memberships and events. See the <a href="https://civicrm.org/">CiviCRM website</a> for more information.
|
||||
version = 7.x-4.7.29
|
||||
package = CiviCRM
|
||||
core = 7.x
|
||||
project = civicrm
|
||||
php = 5.3
|
||||
|
||||
files[] = civicrm.module
|
||||
files[] = civicrm.install
|
||||
files[] = civicrm_user.inc
|
||||
|
||||
; views handlers
|
||||
files[] = modules/views/civicrm.views.inc
|
||||
files[] = modules/views/civicrm.views_default.inc
|
||||
|
||||
; field handlers
|
||||
files[] = modules/views/civicrm/civicrm_handler_field.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_field_pseudo_constant.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_field_address.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_field_component.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_field_contact_link.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_field_county.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_field_country.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_field_custom.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_field_datetime.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_field_drupalid.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_field_email.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_field_encounter_medium.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_field_event.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_field_event_link.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_field_file.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_field_link.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_field_link_activity.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_field_link_contact.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_field_link_contribution.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_field_link_delete.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_field_link_edit.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_field_link_event.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_field_link_participant.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_field_link_pcp.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_field_link_relationship.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_field_location.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_field_mail.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_field_markup.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_field_money.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_field_option.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_field_pcp_raised_amount.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_field_phone.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_field_im.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_field_website.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_field_relationship_type.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_field_state.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_field_custom_file.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_field_contact_image.inc
|
||||
|
||||
; filter handlers
|
||||
files[] = modules/views/civicrm/civicrm_handler_filter_pseudo_constant.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_filter_custom_option.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_filter_datetime.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_filter_encounter_medium.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_filter_group_status.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_filter_custom_option.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_filter_custom_single_option.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_filter_relationship_type.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_filter_country_multi.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_filter_state_multi.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_filter_domain.inc
|
||||
|
||||
; activity handlers
|
||||
files[] = modules/views/civicrm/civicrm_handler_field_activity.inc
|
||||
|
||||
; sort handlers
|
||||
files[] = modules/views/civicrm/civicrm_handler_sort_date.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_sort_pcp_raised_amount.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_sort_address_pseudoconstant.inc
|
||||
|
||||
; argument handlers
|
||||
files[] = modules/views/civicrm/civicrm_plugin_argument_default.inc
|
||||
files[] = modules/views/civicrm/views_handler_argument_civicrm_day.inc
|
||||
files[] = modules/views/civicrm/views_handler_argument_civicrm_fulldate.inc
|
||||
files[] = modules/views/civicrm/views_handler_argument_civicrm_month.inc
|
||||
files[] = modules/views/civicrm/views_handler_argument_civicrm_week.inc
|
||||
files[] = modules/views/civicrm/views_handler_argument_civicrm_year.inc
|
||||
files[] = modules/views/civicrm/views_handler_argument_civicrm_year_month.inc
|
||||
|
||||
; relationship handlers
|
||||
files[] = modules/views/civicrm/civicrm_handler_relationship.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_relationship_relationship.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_relationship_contact2users.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_relationship_memberships_contributions.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_relationship_location.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_relationship_mail.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_relationship_phone.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_relationship_im.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_relationship_website.inc
|
||||
files[] = modules/views/civicrm/civicrm_handler_relationship_address.inc
|
||||
|
||||
; views plugins
|
||||
files[] = modules/views/plugins/calendar_plugin_row_civicrm.inc
|
||||
files[] = modules/views/plugins/calendar_plugin_row_civicrm_event.inc
|
||||
files[] = modules/views/plugins/civicrm_plugin_argument_default_civicrm_id.inc
|
97
sites/all/modules/civicrm/drupal/civicrm.install
Normal file
97
sites/all/modules/civicrm/drupal/civicrm.install
Normal file
|
@ -0,0 +1,97 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
function civicrm_install() {}
|
||||
|
||||
/**
|
||||
* Implementation of hook_uninstall( )
|
||||
*/
|
||||
function civicrm_uninstall() {
|
||||
require_once 'civicrm.module';
|
||||
|
||||
if (!civicrm_initialize()) {
|
||||
return;
|
||||
}
|
||||
|
||||
require_once 'CRM/Core/Config.php';
|
||||
$config = CRM_Core_Config::singleton();
|
||||
|
||||
require_once 'CRM/Core/DAO.php';
|
||||
CRM_Core_DAO::dropAllTables();
|
||||
}
|
||||
|
||||
function civicrm_requirements($phase) {
|
||||
global $base_url;
|
||||
$civicrm_path = drupal_get_path('module', 'civicrm');
|
||||
|
||||
//remove the last occurrence of 'drupal' from path
|
||||
$pos = strrpos($civicrm_path, 'drupal');
|
||||
|
||||
if ($pos !== false) {
|
||||
$civicrm_path = substr_replace($civicrm_path, '', $pos, strlen($civicrm_path));
|
||||
}
|
||||
|
||||
$url = $base_url . '/' . $civicrm_path . 'install/index.php';
|
||||
|
||||
$settings = glob('sites/*/civicrm.settings.php');
|
||||
$problems = array();
|
||||
if (empty($settings) && $phase == 'install') {
|
||||
$problems[] = array(
|
||||
'title' => t('CiviCRM settings does not exist'),
|
||||
'value' =>
|
||||
t('CiviCRM settings file does not exist. It should be created by CiviCRM <a href="!link">install</a>',
|
||||
array('!link' => $url)),
|
||||
'severity' => REQUIREMENT_ERROR,
|
||||
);
|
||||
}
|
||||
|
||||
return $problems;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update CiviCRM module weight
|
||||
*/
|
||||
function civicrm_update_7400(&$sandbox) {
|
||||
db_query("UPDATE {system} SET weight = 100 WHERE name = 'civicrm'");
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger cache clear to pick up TZ handling change from CRM-6877.
|
||||
*/
|
||||
function civicrm_update_7401($sandbox) {
|
||||
// This is an empty hook_update_N() so that caches will be
|
||||
// cleared when update_finished() is called.
|
||||
return t('TZ changes in CiviCRM Views picked up.');
|
||||
}
|
||||
|
1302
sites/all/modules/civicrm/drupal/civicrm.module
Normal file
1302
sites/all/modules/civicrm/drupal/civicrm.module
Normal file
File diff suppressed because it is too large
Load diff
286
sites/all/modules/civicrm/drupal/civicrm_user.inc
Normal file
286
sites/all/modules/civicrm/drupal/civicrm_user.inc
Normal file
|
@ -0,0 +1,286 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Project: CiviCRM: Constituent Relationship Management for NP's
|
||||
* File: civicrm_user.inc
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* Drupal module include file.
|
||||
*/
|
||||
|
||||
/**
|
||||
* User hooks for civicrm module
|
||||
*
|
||||
* Note that we ignore the edit field and do not follow the drupal protocol
|
||||
* of extracting values from the edit field. We extract the fields directly
|
||||
* from $_POST. This is because the underlying form package that we use
|
||||
* (HTML_QuickForm) does the form value extraction and validation.
|
||||
*
|
||||
* @abstractparam array $edit The array of form values submitted by the user.
|
||||
*
|
||||
* @param object $user The user object on which the operation is being performed.
|
||||
* @param object $category The active category of user information being edited.
|
||||
*
|
||||
* @return mixed depends on the operation being performed
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_user_login().
|
||||
*/
|
||||
function civicrm_user_login(&$edit, $user) {
|
||||
if (!civicrm_initialize()) {
|
||||
return;
|
||||
}
|
||||
return CRM_Core_BAO_UFMatch::synchronize($user, FALSE, 'Drupal',
|
||||
civicrm_get_ctype('Individual')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_user_insert().
|
||||
*/
|
||||
function civicrm_user_insert(&$edit, &$user, $category = NULL) {
|
||||
if (!civicrm_initialize()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$config = CRM_Core_Config::singleton();
|
||||
if ($config->inCiviCRM) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Did civicrm generate this page, or is it via a user hook?
|
||||
if (civicrm_on_user_page()) {
|
||||
civicrm_register_data($edit, $user, $category, FALSE);
|
||||
}
|
||||
else {
|
||||
CRM_Core_BAO_UFMatch::synchronize($user, FALSE, 'Drupal',
|
||||
civicrm_get_ctype('Individual')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_user_update().
|
||||
*/
|
||||
function civicrm_user_update(&$edit, &$user, $category) {
|
||||
if (!civicrm_initialize()) {
|
||||
return;
|
||||
}
|
||||
// This always comes in via user hook.
|
||||
// in D7 we don't know if the email has changed, so we go ahead and update
|
||||
if (isset($edit['mail']) && !empty($edit['mail'])) {
|
||||
$contactID = CRM_Core_BAO_UFMatch::getContactId($user->uid);
|
||||
// cant find the contactID, so lets skip
|
||||
if (!$contactID) {
|
||||
return;
|
||||
}
|
||||
$contactEmail = CRM_Contact_BAO_Contact::getPrimaryEmail($contactID);
|
||||
$userEmail = trim($edit['mail']);
|
||||
if ($contactEmail != $userEmail) {
|
||||
CRM_Core_BAO_UFMatch::updateContactEmail($contactID, $userEmail);
|
||||
}
|
||||
|
||||
// reset navigation on user role change
|
||||
$editRoles = array_keys(CRM_Utils_Array::value('roles', $edit, array()));
|
||||
$orginRoles = array_keys($user->original->roles);
|
||||
$editRoleDiff = array_diff($editRoles, $orginRoles);
|
||||
$orginRoleDiff = array_diff($orginRoles, $editRoles);
|
||||
if (!empty($editRoleDiff) || !empty($orginRoleDiff)) {
|
||||
CRM_Core_BAO_Navigation::resetNavigation($contactID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_user_delete().
|
||||
*/
|
||||
function civicrm_user_delete($account) {
|
||||
if (!civicrm_initialize()) {
|
||||
return;
|
||||
}
|
||||
CRM_Core_BAO_UFMatch::deleteUser($account->uid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_user_categories().
|
||||
*/
|
||||
function civicrm_user_categories() {
|
||||
if (!civicrm_initialize()) {
|
||||
return;
|
||||
}
|
||||
$urlParts = explode('/', CRM_Utils_Array::value('q', $_GET, array()));
|
||||
|
||||
$allUFGroups = CRM_Core_BAO_UFGroup::getModuleUFGroup('User Account', 0, TRUE, CRM_Core_Permission::VIEW, array(
|
||||
'id',
|
||||
'name',
|
||||
'title',
|
||||
'is_active',
|
||||
));
|
||||
$ufGroups = array();
|
||||
|
||||
$weight = 100;
|
||||
foreach ($allUFGroups as $key => $value) {
|
||||
if ($value['is_active']) {
|
||||
$name = $value['name'];
|
||||
foreach (array_reverse($urlParts) as $urlPart) {
|
||||
if ($urlPart == $name) {
|
||||
continue;
|
||||
}
|
||||
elseif ($urlPart == $value['title']) {
|
||||
$name = $value['title'];
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$ufGroups[] = array(
|
||||
'id' => $key,
|
||||
'name' => $name,
|
||||
'title' => $value['title'],
|
||||
'weight' => $weight,
|
||||
'access callback' => '_civicrm_categories_access',
|
||||
'access arguments' => array("$key"),
|
||||
);
|
||||
$weight += 10;
|
||||
}
|
||||
}
|
||||
|
||||
return $ufGroups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_user_view().
|
||||
*
|
||||
* @todo I suspect that some of the stuff done in the old form_alter handler
|
||||
* should live here instead under D7
|
||||
*/
|
||||
function civicrm_user_view($user, $view_mode) {
|
||||
if (!civicrm_initialize()) {
|
||||
return;
|
||||
}
|
||||
$userID = CRM_Core_BAO_UFMatch::getContactId($user->uid);
|
||||
if ($userID) {
|
||||
// Make sure user has permission to view the record.
|
||||
$contactURL = NULL;
|
||||
$civiPerm = CRM_Contact_BAO_Contact_Permission::allow($userID);
|
||||
|
||||
if (CRM_Core_Permission::check('access CiviCRM') && $civiPerm) {
|
||||
$contactURL
|
||||
= '<span class="user-page-link" id="user-page-contact" ><span class="user-page-bullet">»</span> '
|
||||
. l(ts("View contact record"),
|
||||
'civicrm/contact/view',
|
||||
array('query' => array('reset' => 1, 'cid' => $userID))
|
||||
) .
|
||||
'</span>';
|
||||
}
|
||||
|
||||
if (CRM_Core_Permission::check('access Contact Dashboard')) {
|
||||
if (!empty($contactURL)) {
|
||||
$contactURL .= '<br/>';
|
||||
}
|
||||
$contactURL .=
|
||||
'<span class="user-page-link" id="user-page-dashboard" ><span class="user-page-bullet">»</span> '
|
||||
. l(ts("View Contact Dashboard"),
|
||||
'civicrm/user',
|
||||
array('query' => array('reset' => 1, 'id' => $userID))
|
||||
) .
|
||||
'</span>';
|
||||
}
|
||||
|
||||
$ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $userID, 'contact_type');
|
||||
|
||||
$ufGroups = CRM_Core_BAO_UFGroup::getModuleUFGroup('User Account', 0, TRUE, CRM_Core_Permission::VIEW, array(
|
||||
'id',
|
||||
'name',
|
||||
'title',
|
||||
'is_active',
|
||||
));
|
||||
$weight = 100;
|
||||
foreach ($ufGroups as $id => $ufGroup) {
|
||||
|
||||
$fieldType = CRM_Core_BAO_UFField::getProfileType($id);
|
||||
if (CRM_Contact_BAO_ContactType::isaSubType($fieldType)) {
|
||||
$fieldType = CRM_Contact_BAO_ContactType::getBasicType($fieldType);
|
||||
}
|
||||
if (($fieldType != 'Contact') && ($fieldType != $ctype)) {
|
||||
continue;
|
||||
}
|
||||
$page = new CRM_Profile_Page_Dynamic($userID, $id, NULL, TRUE);
|
||||
$pageContent = $page->run();
|
||||
|
||||
// CRM-3537: profile edit link
|
||||
$editURL = '';
|
||||
if (user_edit_access($user)) {
|
||||
$editURL = '<span class="user-page-link" id="user-page-profile-' . substr($ufGroup['title'], 0, 3) . '" ><span class="user-page-bullet">»</span> '
|
||||
. l(ts("Edit %1", array(1 => $ufGroup['title'])), "user/{$user->uid}/edit/" . $ufGroup['name']) . '</span>';
|
||||
}
|
||||
|
||||
if ($pageContent) {
|
||||
$user->content[$ufGroup['name']] = array(
|
||||
'#title' => $ufGroup['title'],
|
||||
'#type' => 'user_profile_category',
|
||||
'#weight' => $weight,
|
||||
);
|
||||
$user->content[$ufGroup['name']][$ufGroup['name']] = array(
|
||||
'#type' => 'user_profile_item',
|
||||
'#title' => NULL,
|
||||
'#value' => $pageContent . $editURL,
|
||||
'#markup' => $pageContent . $editURL,
|
||||
);
|
||||
|
||||
$weight += 10;
|
||||
}
|
||||
}
|
||||
|
||||
if ($contactURL) {
|
||||
$user->content['urls'] = array(
|
||||
'#markup' => $contactURL,
|
||||
'#weight' => $weight,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_user_logout().
|
||||
*/
|
||||
function civicrm_user_logout($account) {
|
||||
if (!civicrm_initialize()) {
|
||||
return;
|
||||
}
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$session->reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Validation functions so CiviCRM can get at these items.
|
||||
* @param $form
|
||||
* @param $form_state
|
||||
*/
|
||||
function civicrm_validate_user_forms($form, &$form_state) {
|
||||
if (!civicrm_initialize()) {
|
||||
return;
|
||||
}
|
||||
// we ignore this
|
||||
$edit = array();
|
||||
// this as well
|
||||
$category = FALSE;
|
||||
global $user;
|
||||
civicrm_validate_data($edit, $user, $category);
|
||||
}
|
1603
sites/all/modules/civicrm/drupal/drush/civicrm.drush.inc
Normal file
1603
sites/all/modules/civicrm/drupal/drush/civicrm.drush.inc
Normal file
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Integration with the Feeds module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_feeds_processor_targets_alter().
|
||||
*
|
||||
* @see FeedsNodeProcessor::getMappingTargets()
|
||||
*/
|
||||
function civicrm_contact_ref_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_name) {
|
||||
foreach (field_info_instances($entity_type, $bundle_name) as $name => $instance) {
|
||||
$info = field_info_field($name);
|
||||
if (in_array($info['type'], array('civicrm_contact_ref_contact'))) {
|
||||
$targets[$name] = array(
|
||||
'name' => $instance['label'],
|
||||
'callback' => 'civicrm_contact_ref_feeds_set_target',
|
||||
'description' => t('The @label field of the node.', array('@label' => $instance['label'])),
|
||||
'optional_unique' => TRUE,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback function for mapping CiviCRM Contact Ref field.
|
||||
*
|
||||
* This function is invoked via hook_feeds_processor_targets_alter().
|
||||
* Here is where the actual mapping happens.
|
||||
*
|
||||
* @param $target
|
||||
* the name of the field the user has decided to map to.
|
||||
* @param $value
|
||||
* the value of the feed item element the user has picked as a source.
|
||||
*/
|
||||
function civicrm_contact_ref_feeds_set_target($source, $entity, $target, $value) {
|
||||
$value = is_array($value) ? $value : array($value);
|
||||
|
||||
$info = field_info_field($target);
|
||||
|
||||
// Iterate over all values.
|
||||
|
||||
$field = isset($entity->$target) ? $entity->$target : array();
|
||||
// Allow for multiple mappings to the same target.
|
||||
$delta = 0;
|
||||
foreach ($value as $v) {
|
||||
if ($info['cardinality'] == $delta) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (is_object($v) && ($v instanceof FeedsElement)) {
|
||||
$v = $v->getValue();
|
||||
}
|
||||
|
||||
if (is_numeric($v)) {
|
||||
$field['und'][$delta]['contact_id'] = $v;
|
||||
$delta++;
|
||||
}
|
||||
}
|
||||
|
||||
$entity->{$target} = $field;
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
name = CiviCRM Contact Reference Field
|
||||
description = Makes a CiviCRM Contact Reference Field.
|
||||
version = 7.x-4.7.29
|
||||
core = 7.x
|
||||
package = CiviCRM
|
||||
project = civicrm
|
||||
|
||||
dependencies[] = civicrm
|
||||
dependencies[] = text
|
||||
dependencies[] = list
|
||||
|
||||
files[] = civicrm_contact_ref.install
|
||||
files[] = civicrm_contact_ref.module
|
||||
files[] = civicrm_contact_ref.feeds.inc
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Implements hook_enable().
|
||||
*/
|
||||
function civicrm_contact_ref_enable() {
|
||||
db_query("UPDATE {system} SET weight = 110 WHERE name = 'civicrm_contact_ref'");
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_schema().
|
||||
*/
|
||||
function civicrm_contact_ref_field_schema($field) {
|
||||
return array(
|
||||
'columns' => array(
|
||||
'contact_id' => array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => FALSE,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
|
@ -0,0 +1,482 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Implemetation of hook_menu, retrieve conatacts from civicrm for
|
||||
* autocomplete widget.
|
||||
*/
|
||||
function civicrm_contact_ref_menu() {
|
||||
$items = array();
|
||||
$items['civicrm_contact_ref/autocomplete'] = array(
|
||||
'title' => 'Contacts',
|
||||
'page callback' => 'civicrm_contact_ref_autocomplete_value',
|
||||
'type' => MENU_CALLBACK,
|
||||
'access arguments' => array('access content'),
|
||||
);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implemets hook_field_info
|
||||
*/
|
||||
function civicrm_contact_ref_field_info() {
|
||||
return array(
|
||||
'civicrm_contact_ref_contact' =>
|
||||
array(
|
||||
'label' => t('CiviCRM Contact'),
|
||||
'description' => t('Reference a CiviCRM contact.'),
|
||||
'default_widget' => 'options_select',
|
||||
'default_formatter' => 'civicrm_contact_ref_link',
|
||||
'property_type' => 'integer', // note that this property is used by entity.module
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implemets hook_field_widget_info().
|
||||
*/
|
||||
function civicrm_contact_ref_field_widget_info() {
|
||||
return array(
|
||||
'civicrm_contact_ref_autocomplete' =>
|
||||
array(
|
||||
'label' => t('Autocomplete text field'),
|
||||
'field types' => array('civicrm_contact_ref_contact'),
|
||||
'settings' => array(
|
||||
'size' => 60,
|
||||
'autocomplete_path' => 'civicrm_contact_ref/autocomplete',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* ImplemetS hook_field_widget_info_alter().
|
||||
*/
|
||||
function civicrm_contact_ref_field_widget_info_alter(&$info) {
|
||||
$info['options_select']['field types'][] = 'civicrm_contact_ref_contact';
|
||||
$info['options_buttons']['field types'][] = 'civicrm_contact_ref_contact';
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_options_list().
|
||||
*/
|
||||
function civicrm_contact_ref_options_list($field) {
|
||||
$function = !empty($field['settings']['options_list_callback']) ? $field['settings']['options_list_callback'] : 'civicrm_contact_ref_allowed_values';
|
||||
return $function($field);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_is_empty().
|
||||
*/
|
||||
function civicrm_contact_ref_field_is_empty($item, $field) {
|
||||
return empty($item['contact_id']) ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_formatter_info().
|
||||
*/
|
||||
function civicrm_contact_ref_field_formatter_info() {
|
||||
return array(
|
||||
'civicrm_contact_ref_link' => array(
|
||||
'label' => t('Title (link)'),
|
||||
'field types' => array('civicrm_contact_ref_contact'),
|
||||
),
|
||||
'civicrm_contact_ref_plain' => array(
|
||||
'label' => t('Title (plain)'),
|
||||
'field types' => array('civicrm_contact_ref_contact'),
|
||||
),
|
||||
'civicrm_contact_ref_raw' => array(
|
||||
'label' => t('CID (raw)'),
|
||||
'field types' => array('civicrm_contact_ref_contact'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_formatter_view().
|
||||
*/
|
||||
function civicrm_contact_ref_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
|
||||
$element = array();
|
||||
|
||||
// Terms whose tid is 'autocreate' do not exist
|
||||
// yet and $item['taxonomy_term'] is not set. Theme such terms as
|
||||
// just their name.
|
||||
|
||||
switch ($display['type']) {
|
||||
case 'civicrm_contact_ref_link':
|
||||
foreach ($items as $delta => $item) {
|
||||
if (isset($item['contact_id']) && is_numeric($item['contact_id'])) {
|
||||
$title = _civicrm_contact_ref_titles($item['contact_id']);
|
||||
$element[$delta] = array(
|
||||
'#markup' => l($title,
|
||||
'civicrm/contact/view',
|
||||
array(
|
||||
'query' =>
|
||||
array(
|
||||
'reset' => 1,
|
||||
'cid' => "{$item['contact_id']}",
|
||||
),
|
||||
)
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'civicrm_contact_ref_plain':
|
||||
foreach ($items as $delta => $item) {
|
||||
$element[$delta] = array(
|
||||
'#markup' => _civicrm_contact_ref_titles($item['contact_id']),
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'civicrm_contact_ref_raw':
|
||||
foreach ($items as $delta => $item) {
|
||||
$element[$delta] = array(
|
||||
'#markup' => $item['contact_id'],
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the set of valid civicrm contacts
|
||||
*
|
||||
* @param $field
|
||||
* The field definition.
|
||||
*
|
||||
* @return array
|
||||
* The array of valid contacts.
|
||||
*/
|
||||
function civicrm_contact_ref_allowed_values($field) {
|
||||
$references = _civicrm_contact_ref_potential_references($field);
|
||||
|
||||
$options = array();
|
||||
foreach ($references as $key => $value) {
|
||||
// Views theming runs check_plain (htmlentities) on the values.
|
||||
// We reverse that with html_entity_decode.
|
||||
$options[$key] = html_entity_decode(strip_tags($value['rendered']));
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_widget_form().
|
||||
*/
|
||||
function civicrm_contact_ref_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
|
||||
$defaultValues = array();
|
||||
foreach ($items as $item) {
|
||||
$sort_name = _civicrm_contact_ref_titles($item['contact_id'], 'sort_name');
|
||||
$defaultValues[] = "$sort_name [cid:{$item['contact_id']}]";
|
||||
}
|
||||
|
||||
$element += array(
|
||||
'#type' => 'textfield',
|
||||
'#autocomplete_path' => $instance['widget']['settings']['autocomplete_path'] . '/' . $field['field_name'],
|
||||
'#size' => $instance['widget']['settings']['size'],
|
||||
'#maxlength' => 1024,
|
||||
'#default_value' => empty($defaultValues[$delta]) ? '' : $defaultValues[$delta],
|
||||
'#element_validate' => array('civicrm_contact_ref_autocomplete_validate'),
|
||||
);
|
||||
|
||||
return array('contact_id' => $element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_widget_error().
|
||||
*/
|
||||
function civicrm_contact_ref_field_widget_error($element, $error, $form, &$form_state) {
|
||||
form_error($element, $error['message']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_settings_form().
|
||||
*/
|
||||
function civicrm_contact_ref_field_settings_form($field, $instance, $has_data) {
|
||||
|
||||
if (!civicrm_initialize()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$settings = $field['settings'];
|
||||
|
||||
require_once 'CRM/Contact/BAO/ContactType.php';
|
||||
$contactTypes = CRM_Contact_BAO_ContactType::basicTypePairs();
|
||||
$form = array();
|
||||
$form['allowed_values'] = array(
|
||||
'#tree' => TRUE,
|
||||
);
|
||||
foreach ($contactTypes as $name => $label) {
|
||||
$subTypes = CRM_Contact_BAO_ContactType::subTypePairs($name);
|
||||
$form['allowed_values'][$name] = array(
|
||||
'#type' => 'checkboxes',
|
||||
'#title' => ts('CiviCRM Contact Type %1', array(1 => $label)),
|
||||
'#options' => CRM_Utils_Array::crmArrayMerge(array($name => $label), $subTypes),
|
||||
'#default_value' => isset($settings['allowed_values']) ? $settings['allowed_values'][$name] : array(),
|
||||
'#weight' => 1,
|
||||
);
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Form element validate handler for civicrm contact autocomplete element.
|
||||
*/
|
||||
function civicrm_contact_ref_autocomplete_validate($element, &$form_state) {
|
||||
|
||||
$field = field_info_field($element['#field_name']);
|
||||
$field_key = $element['#columns'][0];
|
||||
$delta = $element['#delta'];
|
||||
$value = $element['#value'];
|
||||
|
||||
$cid = NULL;
|
||||
if (!empty($value)) {
|
||||
preg_match('/^(?:\s*|(.*) )?\[\s*cid\s*:\s*(\d+)\s*\]$/', $value, $matches);
|
||||
if (!empty($matches)) {
|
||||
// Explicit [cid:n].
|
||||
$cid = $matches[2];
|
||||
}
|
||||
else {
|
||||
// No explicit cid.
|
||||
$cids = _civicrm_contact_ref_potential_references($field, $value, TRUE);
|
||||
if (empty($cids)) {
|
||||
form_error($element, t('%name: found no valid post with that title.', array('%name' => $element['#title'])));
|
||||
}
|
||||
else {
|
||||
// TODO:
|
||||
// the best thing would be to present the user with an additional form,
|
||||
// allowing the user to choose between valid candidates with the same title
|
||||
// ATM, we pick the first matching candidate...
|
||||
$cid = array_shift(array_keys($cids));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
form_set_value($element, $cid, $form_state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to provide values for autocomplete civicrm contact
|
||||
* element, depend upon entered string.
|
||||
*/
|
||||
function civicrm_contact_ref_autocomplete_value($field_name, $string = '') {
|
||||
if (!civicrm_initialize()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$field = field_info_field($field_name);;
|
||||
$matches = array();
|
||||
|
||||
$references = _civicrm_contact_ref_potential_references($field, $string);
|
||||
foreach ($references as $id => $row) {
|
||||
// Add a class wrapper for a few required CSS overrides.
|
||||
$matches["{$row['title']} [cid:{$id}]"] = '<div class="reference-autocomplete">' . $row['rendered'] . '</div>';
|
||||
}
|
||||
drupal_json_output($matches);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch an array of all candidate referenced nodes.
|
||||
*
|
||||
* This info is used in various places (aloowed values, autocomplete results,
|
||||
* input validation...). Some of them only need the nids, others nid + titles,
|
||||
* others yet nid + titles + rendered row (for display in widgets).
|
||||
* The array we return contains all the potentially needed information, and lets
|
||||
* consumers use the parts they actually need.
|
||||
*
|
||||
* @param $field
|
||||
* The field description.
|
||||
* @param $string
|
||||
* Optional string to filter titles on (used by autocomplete)
|
||||
* @param $exact_string
|
||||
* Optional: should the title filter be an exact match.
|
||||
*
|
||||
* @return array
|
||||
* An array of valid nodes in the form:
|
||||
* array(
|
||||
* nid => array(
|
||||
* 'title' => The node title,
|
||||
* 'rendered' => The text to display in widgets (can be HTML)
|
||||
* ),
|
||||
* ...
|
||||
* )
|
||||
*/
|
||||
function _civicrm_contact_ref_potential_references($field, $string = '', $exact_string = FALSE) {
|
||||
static $results = array();
|
||||
|
||||
$references = _civicrm_contact_ref_potential_references_standard($field, $string, $exact_string);
|
||||
|
||||
// Store the results.
|
||||
$results[$field['field_name']][$string][$exact_string] = $references;
|
||||
|
||||
return $results[$field['field_name']][$string][$exact_string];
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for _civicrm_contact_ref_potential_references():
|
||||
* referenceable nodes defined by content types.
|
||||
*/
|
||||
function _civicrm_contact_ref_potential_references_standard($field, $string = '', $exact_string = FALSE, $limit = '10') {
|
||||
$args = $whereClause = $contactTypes = $contactSubTypes = array();
|
||||
|
||||
if (!civicrm_initialize()) {
|
||||
return;
|
||||
}
|
||||
|
||||
require_once 'CRM/Contact/BAO/ContactType.php';
|
||||
$basicTypes = CRM_Contact_BAO_ContactType::basicTypePairs();
|
||||
|
||||
foreach ($basicTypes as $name => $label) {
|
||||
if (isset($field['settings']['allowed_values']) && is_array($field['settings']['allowed_values'][$name])) {
|
||||
$contactNames = array_filter($field['settings']['allowed_values'][$name]);
|
||||
if (!empty($contactNames)) {
|
||||
if (in_array($name, $contactNames)) {
|
||||
$contactTypes[] = $name;
|
||||
}
|
||||
else {
|
||||
$contactSubTypes = array_merge($contactSubTypes, array_keys($contactNames));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($contactTypes)) {
|
||||
$contactTypes = implode("','", $contactTypes);
|
||||
$whereClause[] = "contact_type IN ( '{$contactTypes}' )";
|
||||
}
|
||||
|
||||
if (!empty($contactSubTypes)) {
|
||||
foreach ($contactSubTypes as $subType) {
|
||||
$whereClause[] = "contact_sub_type LIKE '%" . CRM_Core_DAO::VALUE_SEPARATOR . $subType . CRM_Core_DAO::VALUE_SEPARATOR . "%'";
|
||||
}
|
||||
}
|
||||
|
||||
$whereClause = empty($whereClause) ? '' : '(' . implode(' OR ', $whereClause) . ') AND';
|
||||
$related_clause = "";
|
||||
|
||||
if (isset($string)) {
|
||||
if ($exact_string) {
|
||||
$string_clause = " AND sort_name = %1";
|
||||
$args[] = $string;
|
||||
}
|
||||
else {
|
||||
$string_clause = " AND sort_name LIKE %1";
|
||||
$args[] = "%%" . $string . "%";
|
||||
}
|
||||
}
|
||||
|
||||
$q = "
|
||||
SELECT sort_name, id
|
||||
FROM civicrm_contact
|
||||
WHERE $whereClause
|
||||
sort_name IS NOT NULL
|
||||
AND sort_name NOT LIKE ''
|
||||
AND sort_name NOT LIKE '<Last>%%'
|
||||
AND sort_name NOT LIKE '%@%%'
|
||||
AND sort_name NOT LIKE '--%%'
|
||||
AND sort_name NOT LIKE '- -%%'
|
||||
AND sort_name NOT LIKE ',%%'
|
||||
AND sort_name NOT LIKE '..%%'
|
||||
AND is_deleted = 0
|
||||
" . $string_clause . " LIMIT $limit";
|
||||
$params = array(1 => array($args[0], "String"));
|
||||
$dao = CRM_Core_DAO::executeQuery($q, $params);
|
||||
|
||||
$references = array();
|
||||
while ($dao->fetch()) {
|
||||
$references[$dao->id] = array(
|
||||
'title' => $dao->sort_name,
|
||||
'rendered' => $dao->sort_name,
|
||||
);
|
||||
}
|
||||
|
||||
return $references;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for formatters.
|
||||
*
|
||||
* Store node titles collected in the current request.
|
||||
*
|
||||
* @param int $cid
|
||||
* @param string $field
|
||||
* @return string|null
|
||||
*/
|
||||
function _civicrm_contact_ref_titles($cid, $field = 'display_name') {
|
||||
if (!civicrm_initialize() || !$cid) {
|
||||
return NULL;
|
||||
}
|
||||
static $titles = array();
|
||||
|
||||
if (!isset($titles["{$cid}_{$field}"])) {
|
||||
$q = "
|
||||
SELECT {$field}
|
||||
FROM civicrm_contact
|
||||
WHERE id = %1";
|
||||
$params = array(1 => array($cid, "Integer"));
|
||||
$dao = CRM_Core_DAO::executeQuery($q, $params);
|
||||
|
||||
$titles["{$cid}_{$field}"] = $dao->fetch() ? $dao->$field : '';
|
||||
}
|
||||
return $titles["{$cid}_{$field}"];
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_views_data().
|
||||
*
|
||||
* To allow for views relationships
|
||||
*/
|
||||
function civicrm_contact_ref_field_views_data($field) {
|
||||
$data = field_views_field_default_views_data($field);
|
||||
$storage = $field['storage']['details']['sql'];
|
||||
|
||||
foreach ($storage as $age => $table_data) {
|
||||
$table = key($table_data);
|
||||
$columns = current($table_data);
|
||||
$id_column = $columns['contact_id'];
|
||||
if (isset($data[$table])) {
|
||||
// Relationship.
|
||||
$data[$table][$id_column]['relationship'] = array(
|
||||
'handler' => 'views_handler_relationship',
|
||||
'base' => 'civicrm_contact',
|
||||
'base field' => 'id',
|
||||
'field' => $id_column,
|
||||
'label' => $field['field_name'],
|
||||
'field_name' => $field['field_name'],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_civicrm_merge().
|
||||
*
|
||||
* Update field data to reflect new cids when contacts are merged.
|
||||
*/
|
||||
function civicrm_contact_ref_civicrm_merge($type, $data, $new_id = NULL, $old_id = NULL, $tables = NULL) {
|
||||
$updated = FALSE;
|
||||
if (!empty($new_id) && !empty($old_id) && $type == 'sqls' && $tables === FALSE) {
|
||||
// Update contact reference field data
|
||||
$db = db_query("SELECT field_name FROM {field_config} WHERE module = 'civicrm_contact_ref'");
|
||||
foreach ($db as $table) {
|
||||
$result = db_update("field_data_{$table->field_name}")
|
||||
->fields(array("{$table->field_name}_contact_id" => $new_id))
|
||||
->condition("{$table->field_name}_contact_id", $old_id)
|
||||
->execute();
|
||||
if ($result) {
|
||||
$updated = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($updated) {
|
||||
cache_clear_all('*', 'cache_field', TRUE);
|
||||
cache_clear_all('*', 'cache_page', TRUE);
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,427 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* @copyright DharmaTech (c) 2009
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
require_once 'Engage/Report/Form/List.php';
|
||||
|
||||
/**
|
||||
* Generate a phone call list report
|
||||
*/
|
||||
class Engage_Report_Form_CallList extends Engage_Report_Form_List {
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->_columns = array(
|
||||
'civicrm_phone' => array(
|
||||
'dao' => 'CRM_Core_DAO_Phone',
|
||||
'fields' => array(
|
||||
'phone' => array(
|
||||
'default' => TRUE,
|
||||
'required' => TRUE,
|
||||
),
|
||||
),
|
||||
'grouping' => 'location-fields',
|
||||
'order_bys' => array(
|
||||
'phone' => array(
|
||||
'title' => ts('Phone'),
|
||||
'required' => TRUE,
|
||||
),
|
||||
),
|
||||
),
|
||||
'civicrm_address' =>
|
||||
array(
|
||||
'dao' => 'CRM_Core_DAO_Address',
|
||||
'fields' => array(
|
||||
'street_address' => array(
|
||||
'default' => TRUE,
|
||||
),
|
||||
'city' => array(
|
||||
'default' => TRUE,
|
||||
),
|
||||
'postal_code' => array(
|
||||
'title' => 'Zip',
|
||||
'default' => TRUE,
|
||||
),
|
||||
'state_province_id' => array(
|
||||
'title' => ts('State/Province'),
|
||||
'default' => TRUE,
|
||||
),
|
||||
'country_id' => array(
|
||||
'title' => ts('Country'),
|
||||
),
|
||||
),
|
||||
'filters' => array(
|
||||
'street_address' => NULL,
|
||||
'city' => NULL,
|
||||
'postal_code' => array('title' => 'Zip'),
|
||||
),
|
||||
'grouping' => 'location-fields',
|
||||
),
|
||||
'civicrm_email' => array(
|
||||
'dao' => 'CRM_Core_DAO_Email',
|
||||
'fields' => array('email' => NULL),
|
||||
'grouping' => 'location-fields',
|
||||
),
|
||||
'civicrm_contact' => array(
|
||||
'dao' => 'CRM_Contact_DAO_Contact',
|
||||
'fields' => array(
|
||||
'id' => array(
|
||||
'title' => ts('Contact ID'),
|
||||
'required' => TRUE,
|
||||
),
|
||||
'display_name' => array(
|
||||
'title' => ts('Contact Name'),
|
||||
'required' => TRUE,
|
||||
'no_repeat' => TRUE,
|
||||
),
|
||||
'gender_id' => array(
|
||||
'title' => ts('Sex'),
|
||||
'required' => TRUE,
|
||||
),
|
||||
'birth_date' => array(
|
||||
'title' => ts('Age'),
|
||||
'required' => TRUE,
|
||||
'type' => CRM_Report_FORM::OP_INT,
|
||||
),
|
||||
),
|
||||
'filters' => array(
|
||||
'sort_name' => array(
|
||||
'title' => ts('Contact Name'),
|
||||
'operator' => 'like',
|
||||
),
|
||||
),
|
||||
'grouping' => 'contact-fields',
|
||||
),
|
||||
$this->_demoTable => array(
|
||||
'dao' => 'CRM_Contact_DAO_Contact',
|
||||
'fields' => array(
|
||||
$this->_demoLangCol => array(
|
||||
'type' => CRM_Report_FORM::OP_STRING,
|
||||
'required' => TRUE,
|
||||
'title' => ts('Language'),
|
||||
),
|
||||
),
|
||||
'filters' => array(
|
||||
$this->_demoLangCol => array(
|
||||
'title' => ts('Language'),
|
||||
'operatorType' => CRM_Report_FORM::OP_SELECT,
|
||||
'type' => CRM_Report_FORM::OP_STRING,
|
||||
'methodName' => 'selector',
|
||||
'options' => $this->_languages,
|
||||
),
|
||||
),
|
||||
'grouping' => 'contact-fields',
|
||||
),
|
||||
$this->_coreInfoTable => array(
|
||||
'dao' => 'CRM_Contact_DAO_Contact',
|
||||
'fields' => array(
|
||||
$this->_coreTypeCol => array(
|
||||
'type' => CRM_Report_FORM::OP_STRING,
|
||||
'required' => TRUE,
|
||||
'title' => ts('Constituent Type'),
|
||||
),
|
||||
$this->_coreOtherCol => array(
|
||||
'no_display' => TRUE,
|
||||
'type' => CRM_Report_Form::OP_STRING,
|
||||
'required' => TRUE,
|
||||
),
|
||||
),
|
||||
'grouping' => 'contact-fields',
|
||||
),
|
||||
'civicrm_group' => array(
|
||||
'dao' => 'CRM_Contact_DAO_GroupContact',
|
||||
'alias' => 'cgroup',
|
||||
'filters' => array(
|
||||
'gid' => array(
|
||||
'name' => 'group_id',
|
||||
'title' => ts('Group'),
|
||||
'operatorType' => CRM_Report_Form::OP_MULTISELECT,
|
||||
'group' => TRUE,
|
||||
'options' => CRM_Core_PseudoConstant::group(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
$reportDate = CRM_Utils_Date::customFormat(date('Y-m-d H:i'));
|
||||
$this->assign('reportTitle', "{$this->_orgName} - Call List <br /> {$reportDate}");
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate WHERE clauses for SQL SELECT
|
||||
*/
|
||||
public function where() {
|
||||
// Don't list anybody who doesn't have a phone
|
||||
// or has do_not_phone = 1
|
||||
$clauses = array(
|
||||
"{$this->_aliases['civicrm_contact']}.do_not_phone != 1",
|
||||
"NOT ISNULL({$this->_aliases['civicrm_phone']}.phone)",
|
||||
);
|
||||
|
||||
foreach ($this->_columns as $tableName => $table) {
|
||||
//echo "where: table name $tableName<br>";
|
||||
|
||||
// Treatment of normal filters
|
||||
if (array_key_exists('filters', $table)) {
|
||||
foreach ($table['filters'] as $fieldName => $field) {
|
||||
//echo " field name $fieldName<br>";
|
||||
$clause = NULL;
|
||||
|
||||
if (CRM_Utils_Array::value('type', $field) & CRM_Utils_Type::T_DATE) {
|
||||
$relative = CRM_Utils_Array::value("{$fieldName}_relative", $this->_params);
|
||||
$from = CRM_Utils_Array::value("{$fieldName}_from", $this->_params);
|
||||
$to = CRM_Utils_Array::value("{$fieldName}_to", $this->_params);
|
||||
|
||||
$clause = $this->dateClause($field['name'], $relative, $from, $to);
|
||||
}
|
||||
elseif ($fieldName == $this->_demoLangCol) {
|
||||
if (!empty($this->_params[$this->_demoLangCol . '_value'])) {
|
||||
$clause = "{$field['dbAlias']}='" . $this->_params[$this->_demoLangCol . '_value'] . "'";
|
||||
}
|
||||
}
|
||||
else {
|
||||
$op = CRM_Utils_Array::value("{$fieldName}_op", $this->_params);
|
||||
if ($op == 'mand') {
|
||||
$clause = TRUE;
|
||||
}
|
||||
elseif ($op) {
|
||||
$clause = $this->whereClause($field,
|
||||
$op,
|
||||
CRM_Utils_Array::value("{$fieldName}_value", $this->_params),
|
||||
CRM_Utils_Array::value("{$fieldName}_min", $this->_params),
|
||||
CRM_Utils_Array::value("{$fieldName}_max", $this->_params)
|
||||
);
|
||||
}
|
||||
}
|
||||
//echo " clause=";
|
||||
//var_dump($clause);
|
||||
if (!empty($clause)) {
|
||||
if (!empty($field['group'])) {
|
||||
$clauses[] = $this->engageWhereGroupClause($clause);
|
||||
}
|
||||
else {
|
||||
$clauses[] = $clause;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($clauses)) {
|
||||
$this->_where = "WHERE ( 1 ) ";
|
||||
}
|
||||
else {
|
||||
$this->_where = "WHERE " . implode(' AND ', $clauses);
|
||||
}
|
||||
//echo $this->_where . "<br>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Process submitted form
|
||||
*/
|
||||
public function postProcess() {
|
||||
parent::postProcess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert contact type info from fields separated by \x01 to a
|
||||
* string of fields separated by commas
|
||||
*/
|
||||
public function type2str($type) {
|
||||
$typeArray = explode("\x01", $type);
|
||||
foreach ($typeArray as $key => $value) {
|
||||
if (empty($value)) {
|
||||
unset($typeArray[$key]);
|
||||
}
|
||||
}
|
||||
return implode(', ', $typeArray);
|
||||
}
|
||||
|
||||
public function alterDisplay(&$rows) {
|
||||
// custom code to alter rows
|
||||
$genderList = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id');
|
||||
$entryFound = FALSE;
|
||||
foreach ($rows as $rowNum => $row) {
|
||||
// handle state province
|
||||
if (array_key_exists('civicrm_address_state_province_id', $row)) {
|
||||
if ($value = $row['civicrm_address_state_province_id']) {
|
||||
$rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant::stateProvince($value);
|
||||
}
|
||||
$entryFound = TRUE;
|
||||
}
|
||||
|
||||
// handle country
|
||||
if (array_key_exists('civicrm_address_country_id', $row)) {
|
||||
if ($value = $row['civicrm_address_country_id']) {
|
||||
$rows[$rowNum]['civicrm_address_country_id'] = CRM_Core_PseudoConstant::country($value);
|
||||
}
|
||||
$entryFound = TRUE;
|
||||
}
|
||||
|
||||
// Handle contactType
|
||||
if (!empty($row[$this->_coreInfoTable . '_' . $this->_coreTypeCol])) {
|
||||
$rows[$rowNum][$this->_coreInfoTable . '_' . $this->_coreTypeCol] = $this->type2str($rows[$rowNum][$this->_coreInfoTable . '_' . $this->_coreTypeCol]);
|
||||
$entryFound = TRUE;
|
||||
}
|
||||
|
||||
// date of birth to age
|
||||
if (!empty($row['civicrm_contact_birth_date'])) {
|
||||
$rows[$rowNum]['civicrm_contact_birth_date'] = $this->dob2age($row['civicrm_contact_birth_date']);
|
||||
$entryFound = TRUE;
|
||||
}
|
||||
|
||||
// gender label
|
||||
if (!empty($row['civicrm_contact_gender_id'])) {
|
||||
$rows[$rowNum]['civicrm_contact_gender_id'] = $genderList[$row['civicrm_contact_gender_id']];
|
||||
$entryFound = TRUE;
|
||||
}
|
||||
|
||||
if (($this->_outputMode != 'html') && !empty($row[$this->_coreInfoTable . '_' . $this->_coreOtherCol])) {
|
||||
$rows[$rowNum]['civicrm_contact_display_name'] .= "<br />" . $row[$this->_coreInfoTable . '_' . $this->_coreOtherCol];
|
||||
$entryFound = TRUE;
|
||||
}
|
||||
|
||||
// skip looking further in rows, if first row itself doesn't
|
||||
// have the column we need
|
||||
if (!$entryFound) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$columnOrder = array(
|
||||
'civicrm_phone_phone',
|
||||
'civicrm_contact_display_name',
|
||||
'civicrm_address_street_address',
|
||||
'civicrm_contact_birth_date',
|
||||
'civicrm_contact_gender_id',
|
||||
$this->_demoTable . '_' . $this->_demoLangCol,
|
||||
$this->_coreInfoTable . '_' . $this->_coreTypeCol,
|
||||
'civicrm_contact_id',
|
||||
);
|
||||
if ($this->_outputMode == 'print' || $this->_outputMode == 'pdf') {
|
||||
$this->_columnHeaders = array(
|
||||
'civicrm_phone_phone' => array(
|
||||
'title' => 'PHONE',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'class' => 'width=68',
|
||||
),
|
||||
'civicrm_contact_display_name' => array(
|
||||
'title' => 'NAME',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'class' => 'width=83',
|
||||
),
|
||||
'civicrm_address_street_address' => array(
|
||||
'title' => 'ADDRESS',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'class' => 'width=117',
|
||||
),
|
||||
'civicrm_contact_birth_date' => array(
|
||||
'title' => 'AGE',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'class' => 'width=25',
|
||||
),
|
||||
'civicrm_contact_gender_id' => array(
|
||||
'title' => 'SEX',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'class' => 'width=18',
|
||||
),
|
||||
$this->_demoTable . '_' . $this->_demoLangCol =>
|
||||
array(
|
||||
'title' => 'Lang',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'class' => 'width=27',
|
||||
),
|
||||
$this->_coreInfoTable . '_' . $this->_coreTypeCol =>
|
||||
array(
|
||||
'title' => 'Contact Type',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'class' => 'width=48',
|
||||
),
|
||||
'notes' => array(
|
||||
'title' => 'NOTES',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'class' => 'width=48',
|
||||
),
|
||||
'response_codes' => array(
|
||||
'title' => 'RESPONSE CODES',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'class' => 'width=91',
|
||||
),
|
||||
'status' => array(
|
||||
'title' => 'STATUS',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'class' => 'width=70',
|
||||
),
|
||||
'civicrm_contact_id' => array(
|
||||
'title' => 'ID',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'class' => 'width=100',
|
||||
),
|
||||
);
|
||||
$newRows = array();
|
||||
foreach ($columnOrder as $col) {
|
||||
foreach ($rows as $rowNum => $row) {
|
||||
$newRows[$rowNum][$col] = $row[$col];
|
||||
$newRows[$rowNum]['notes'] = ' ';
|
||||
$newRows[$rowNum]['status'] = 'NH MV D WN';
|
||||
$newRows[$rowNum]['response_codes'] = '
|
||||
Q1 Y N U D<br />
|
||||
Q2 Y N U D<br />
|
||||
Q3 Y N U D<br />
|
||||
Q4 Y N U D';
|
||||
}
|
||||
}
|
||||
$rows = $newRows;
|
||||
$this->assign('pageTotal', ceil((count($newRows) / 7)));
|
||||
}
|
||||
else {
|
||||
// make sure column order is same as in print mode
|
||||
$tempHeaders = $this->_columnHeaders;
|
||||
$this->_columnHeaders = array();
|
||||
foreach ($columnOrder as $col) {
|
||||
if (array_key_exists($col, $tempHeaders)) {
|
||||
$this->_columnHeaders[$col] = $tempHeaders[$col];
|
||||
unset($tempHeaders[$col]);
|
||||
}
|
||||
}
|
||||
$this->_columnHeaders = $this->_columnHeaders + $tempHeaders;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,583 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* @copyright DharmaTech (c) 2009
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
require_once 'CRM/Report/Form.php';
|
||||
require_once 'CRM/Core/DAO.php';
|
||||
|
||||
/**
|
||||
* Generate a walk list
|
||||
*/
|
||||
class Engage_Report_Form_List extends CRM_Report_Form {
|
||||
/*
|
||||
* Note: In order to detect column names of a particular custom group, we need to know
|
||||
* custom field ID or LABEL. Since labels are less likely to change on initial setup of the module,
|
||||
* we 'll use label constants for now.
|
||||
*
|
||||
* Please note these values 'll need to be adjusted if custom field labels are modified.
|
||||
*
|
||||
*/
|
||||
const CF_CONSTITUENT_TYPE_NAME = 'constituent_type', CF_OTHER_NAME_NAME = 'other_name', CG_VOTER_INFO_TABLE = 'civicrm_value_voter_info', CF_PARTY_REG_NAME = 'party_registration', CF_VOTER_HISTORY_NAME = 'voter_history', CG_DEMOGROPHICS_TABLE = 'civicrm_value_demographics';
|
||||
|
||||
/**
|
||||
* Address information needed in output
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_addressField = FALSE;
|
||||
|
||||
/**
|
||||
* Email address needed in output
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_emailField = FALSE;
|
||||
|
||||
/**
|
||||
* Demographic information needed in output
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_demoField = FALSE;
|
||||
|
||||
protected $_coreField = FALSE;
|
||||
|
||||
/**
|
||||
* Phone number needed in output
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_phoneField = FALSE;
|
||||
|
||||
/**
|
||||
* Group membership information needed in output
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_groupField = FALSE;
|
||||
|
||||
/**
|
||||
* Voter Info information needed in output
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_voterInfoField = FALSE;
|
||||
|
||||
protected $_contributionField = FALSE;
|
||||
|
||||
/**
|
||||
* Constituent individual table name has changed
|
||||
* between versions of civicrm. Populate this field
|
||||
* dynamically to ensure backward compatability
|
||||
*/
|
||||
protected $_constituentIndividualTable = FALSE;
|
||||
|
||||
/**
|
||||
* Langauage field might be primary or secondary
|
||||
* depending on version...
|
||||
*/
|
||||
protected $_langaugeName = FALSE;
|
||||
|
||||
protected $_summary = NULL;
|
||||
|
||||
/**
|
||||
* Available contact type options
|
||||
* @var string[]
|
||||
*/
|
||||
protected $_contactType = NULL;
|
||||
|
||||
/**
|
||||
* Available gender options
|
||||
* @var string[]
|
||||
*/
|
||||
protected $_gender = NULL;
|
||||
|
||||
/**
|
||||
* Available group options
|
||||
* @var string[]
|
||||
*/
|
||||
protected $_groups = NULL;
|
||||
|
||||
protected $_groupDescr = NULL;
|
||||
|
||||
/**
|
||||
* Available primary language options
|
||||
* @var string
|
||||
*/
|
||||
protected $_languages = NULL;
|
||||
|
||||
protected $_orgName = NULL;
|
||||
|
||||
/**
|
||||
* Table with Voter Info group information
|
||||
* @var string
|
||||
*/
|
||||
protected $_voterInfoTable;
|
||||
|
||||
protected $_demoTable;
|
||||
|
||||
protected $_demoLangCol;
|
||||
|
||||
protected $_coreInfoTable;
|
||||
|
||||
protected $_coreTypeCol;
|
||||
|
||||
protected $_coreOtherCol;
|
||||
|
||||
/**
|
||||
* Column in $_voterInfoTable with party registration information
|
||||
* @var string
|
||||
*/
|
||||
protected $_partyCol;
|
||||
|
||||
/**
|
||||
* Available party registration options
|
||||
* @var string[]
|
||||
*/
|
||||
protected $_partyRegs = array();
|
||||
|
||||
/**
|
||||
* Column in $_voterInfoTable with voter history information
|
||||
* @var string
|
||||
*/
|
||||
protected $_vhCol; function __construct() {
|
||||
// Find the invidual constituent table (varies between versions)
|
||||
$query = "SELECT table_name FROM civicrm_custom_group g" . " JOIN civicrm_custom_field f ON g.id = f.custom_group_id" . " WHERE column_name='" . self::CF_CONSTITUENT_TYPE_NAME . "' AND" . " ( g.table_name = 'civicrm_value_core_info' OR g.table_name " . " = 'civicrm_value_constituent_info' )";
|
||||
$dao = CRM_Core_DAO::executeQuery($query);
|
||||
$dao->fetch();
|
||||
$this->_constituentIndividualTable = $dao->table_name;
|
||||
|
||||
// Find the language field name (varies between versions - either
|
||||
// primary_langauge or secondary_language)
|
||||
$query = "SELECT column_name FROM civicrm_custom_field" . " WHERE column_name = 'primary_language' OR" . " column_name = 'secondary_language'";
|
||||
$dao = CRM_Core_DAO::executeQuery($query);
|
||||
$dao->fetch();
|
||||
$this->_languageName = $dao->column_name;
|
||||
|
||||
// Find the Voter Info custom data group
|
||||
$query = "SELECT id, table_name FROM civicrm_custom_group" . " WHERE table_name='" . self::CG_VOTER_INFO_TABLE . "'";
|
||||
$dao = CRM_Core_DAO::executeQuery($query);
|
||||
$dao->fetch();
|
||||
$voterInfoID = $dao->id;
|
||||
$this->_voterInfoTable = $dao->table_name;
|
||||
|
||||
// From Voter Info custom data group get Party Registration info
|
||||
$query = "SELECT column_name, option_group_id" . " FROM civicrm_custom_field" . " WHERE custom_group_id={$voterInfoID}" . " AND column_name='" . self::CF_PARTY_REG_NAME . "'";
|
||||
$dao = CRM_Core_DAO::executeQuery($query);
|
||||
$dao->fetch();
|
||||
$this->_partyCol = $dao->column_name;
|
||||
$partyOptGrp = $dao->option_group_id;
|
||||
$query = "SELECT label, value" . " FROM civicrm_option_value" . " WHERE option_group_id={$partyOptGrp}";
|
||||
$dao = CRM_Core_DAO::executeQuery($query);
|
||||
while ($dao->fetch()) {
|
||||
$this->_partyRegs[$dao->value] = $dao->label;
|
||||
}
|
||||
|
||||
// From Voter Info custom data group get Voter History info
|
||||
$query = "SELECT column_name, option_group_id" . " FROM civicrm_custom_field" . " WHERE custom_group_id={$voterInfoID}" . " AND column_name='" . self::CF_VOTER_HISTORY_NAME . "'";
|
||||
$dao = CRM_Core_DAO::executeQuery($query);
|
||||
$dao->fetch();
|
||||
$this->_vhCol = $dao->column_name;
|
||||
|
||||
// Get contactType option values
|
||||
// There are two custom groups named 'Contact Type'
|
||||
// so there isn't a very good way to do this.
|
||||
$this->_contactType = array('' => '');
|
||||
$query = "
|
||||
SELECT ov.label, ov.value FROM civicrm_option_value ov
|
||||
WHERE ov.option_group_id = (
|
||||
SELECT cf.option_group_id FROM civicrm_custom_field cf
|
||||
WHERE cf.custom_group_id = (
|
||||
SELECT cg.id FROM civicrm_custom_group cg WHERE cg.table_name='" . $this->_constituentIndividualTable . "' ) AND cf.column_name='" . self::CF_CONSTITUENT_TYPE_NAME . "'
|
||||
)";
|
||||
$dao = CRM_Core_DAO::executeQuery($query);
|
||||
while ($dao->fetch()) {
|
||||
$this->_contactType[$dao->value] = $dao->label;
|
||||
}
|
||||
|
||||
// ** demographics ** //
|
||||
$query = "SELECT id, table_name FROM civicrm_custom_group WHERE table_name='" . self::CG_DEMOGROPHICS_TABLE . "'";
|
||||
$dao = CRM_Core_DAO::executeQuery($query);
|
||||
$dao->fetch();
|
||||
$demoTableID = $dao->id;
|
||||
$this->_demoTable = $dao->table_name;
|
||||
|
||||
$query = "
|
||||
SELECT column_name
|
||||
FROM civicrm_custom_field
|
||||
WHERE custom_group_id={$demoTableID} AND column_name = '" . $this->_languageName . "' LIMIT 1";
|
||||
$dao = CRM_Core_DAO::executeQuery($query);
|
||||
$dao->fetch();
|
||||
$this->_demoLangCol = $dao->column_name;
|
||||
|
||||
// ** Core Info ** //
|
||||
$query = "SELECT id, table_name FROM civicrm_custom_group WHERE table_name='" . $this->_constituentIndividualTable . "'";
|
||||
$dao = CRM_Core_DAO::executeQuery($query);
|
||||
$dao->fetch();
|
||||
$coreInfoTableID = $dao->id;
|
||||
$this->_coreInfoTable = $dao->table_name;
|
||||
|
||||
$query = "
|
||||
SELECT column_name
|
||||
FROM civicrm_custom_field
|
||||
WHERE custom_group_id={$coreInfoTableID} AND column_name='" . self::CF_OTHER_NAME_NAME . "' LIMIT 1";
|
||||
$dao = CRM_Core_DAO::executeQuery($query);
|
||||
$dao->fetch();
|
||||
$this->_coreOtherCol = $dao->column_name;
|
||||
|
||||
$query = "
|
||||
SELECT column_name
|
||||
FROM civicrm_custom_field
|
||||
WHERE custom_group_id={$coreInfoTableID} AND column_name='" . self::CF_CONSTITUENT_TYPE_NAME . "' LIMIT 1";
|
||||
$dao = CRM_Core_DAO::executeQuery($query);
|
||||
$dao->fetch();
|
||||
$this->_coreTypeCol = $dao->column_name;
|
||||
|
||||
// Get language option values, English on top
|
||||
$this->_languages = array('' => '');
|
||||
$query = "
|
||||
SELECT ov.label, ov.value FROM civicrm_option_value ov
|
||||
WHERE ov.option_group_id = (
|
||||
SELECT cf.option_group_id FROM civicrm_custom_field cf
|
||||
WHERE cf.custom_group_id = {$demoTableID} AND column_name = '{$this->_demoLangCol}'
|
||||
)
|
||||
ORDER BY ov.label
|
||||
";
|
||||
$dao = CRM_Core_DAO::executeQuery($query);
|
||||
while ($dao->fetch()) {
|
||||
$this->_languages[$dao->value] = $dao->label;
|
||||
}
|
||||
|
||||
// Get organization name
|
||||
$query = "SELECT name FROM civicrm_domain";
|
||||
$dao = CRM_Core_DAO::executeQuery($query);
|
||||
$dao->fetch();
|
||||
$this->_orgName = $dao->name;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function setDefaultValues($freeze = TRUE) {
|
||||
$defaults = parent::setDefaultValues($freeze);
|
||||
$defaults['report_header'] = '
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<style>
|
||||
body { font-size: 10px;
|
||||
}
|
||||
h1 { text-align: center;
|
||||
font-size: 14px;
|
||||
margin-bottom: 8px;
|
||||
padding-bottom: 0;
|
||||
}
|
||||
h2 { text-align: center;
|
||||
font-size: 14px;
|
||||
margin-top: 0;
|
||||
padding-top: 0;
|
||||
padding-bottom: 20px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.body { border-collapse: collapse;
|
||||
border-spacing: 0px;
|
||||
width: 770px;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
.head { width: 770px;
|
||||
}
|
||||
thead th { padding: 0;
|
||||
margin: 0;
|
||||
text-align: left;
|
||||
font-size: 10px;
|
||||
whitespace: normal;
|
||||
}
|
||||
.head td { padding-left: 5px;
|
||||
margin: 0 0 20px 0;
|
||||
border: 0;
|
||||
font-size: 14px;
|
||||
whitespace: normal;
|
||||
}
|
||||
.body td { padding-left: 5px;
|
||||
margin: 0;
|
||||
border: 1px solid black;
|
||||
font-size: 10px;
|
||||
whitespace: normal;
|
||||
}
|
||||
p { padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
.page { page-break-before: always;
|
||||
}
|
||||
@page { size: landscape;
|
||||
}
|
||||
</style>
|
||||
<meta http-equiv="Content-Type" content="text/xhtml; charset=utf-8"/>
|
||||
</head>
|
||||
<body>
|
||||
';
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
}
|
||||
|
||||
public function getOperationPair($type = "string", $fieldName = NULL) {
|
||||
if ($fieldName == 'gid' && $type == CRM_Report_Form::OP_MULTISELECT) {
|
||||
return array(
|
||||
'in' => ts('Is one of'),
|
||||
'mand' => ts('Is equal to'),
|
||||
);
|
||||
}
|
||||
else {
|
||||
return parent::getOperationPair($type);
|
||||
}
|
||||
}
|
||||
|
||||
public function engageWhereGroupClause($clause) {
|
||||
$smartGroupQuery = "";
|
||||
require_once 'CRM/Contact/DAO/Group.php';
|
||||
require_once 'CRM/Contact/BAO/SavedSearch.php';
|
||||
|
||||
$group = new CRM_Contact_DAO_Group();
|
||||
$group->is_active = 1;
|
||||
$group->find();
|
||||
while ($group->fetch()) {
|
||||
if (in_array($group->id, $this->_params['gid_value']) && $group->saved_search_id) {
|
||||
$smartGroups[] = $group->id;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($smartGroups)) {
|
||||
$smartGroups = implode(',', $smartGroups);
|
||||
$smartGroupQuery = " UNION DISTINCT
|
||||
SELECT DISTINCT smartgroup_contact.contact_id
|
||||
FROM civicrm_group_contact_cache smartgroup_contact
|
||||
WHERE smartgroup_contact.group_id IN ({$smartGroups}) ";
|
||||
}
|
||||
|
||||
if ($this->_params['gid_op'] == 'in') {
|
||||
return " {$this->_aliases['civicrm_contact']}.id IN (
|
||||
SELECT DISTINCT {$this->_aliases['civicrm_group']}.contact_id
|
||||
FROM civicrm_group_contact {$this->_aliases['civicrm_group']}
|
||||
WHERE {$clause} AND {$this->_aliases['civicrm_group']}.status = 'Added'
|
||||
{$smartGroupQuery} ) ";
|
||||
}
|
||||
elseif ($this->_params['gid_op'] == 'mand') {
|
||||
$query = " {$this->_aliases['civicrm_contact']}.id IN (
|
||||
SELECT DISTINCT {$this->_aliases['civicrm_group']}1.contact_id
|
||||
FROM civicrm_group_contact {$this->_aliases['civicrm_group']}1
|
||||
";
|
||||
|
||||
for ($i = 2; $i <= count($this->_params['gid_value']); $i++) {
|
||||
$j = $i - 1;
|
||||
$status[] = "{$this->_aliases['civicrm_group']}{$i}.group_id != {$this->_aliases['civicrm_group']}{$j}.group_id";
|
||||
$query .= " INNER JOIN civicrm_group_contact {$this->_aliases['civicrm_group']}{$i}
|
||||
ON {$this->_aliases['civicrm_group']}{$i}.contact_id = {$this->_aliases['civicrm_group']}{$j}.contact_id AND " . implode(" AND ", $status) . "
|
||||
";
|
||||
}
|
||||
$query .= " WHERE ";
|
||||
|
||||
for ($i = 1; $i <= count($this->_params['gid_value']); $i++) {
|
||||
$query .= ($i > 1) ? " AND " : "";
|
||||
$query .= " {$this->_aliases['civicrm_group']}{$i}.group_id IN ( '" . implode("' , '", $this->_params['gid_value']) . "') AND {$this->_aliases['civicrm_group']}{$i}.status = 'Added'
|
||||
";
|
||||
}
|
||||
$query .= " {$smartGroupQuery} ) ";
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
|
||||
public function select() {
|
||||
$select = array();
|
||||
//var_dump($this->_params);
|
||||
$this->_columnHeaders = array();
|
||||
foreach ($this->_columns as $tableName => $table) {
|
||||
if (array_key_exists('fields', $table)) {
|
||||
foreach ($table['fields'] as $fieldName => $field) {
|
||||
|
||||
//var_dump($this->_params['fields'][$fieldName]);
|
||||
if (!empty($field['required']) || !empty($this->_params['fields'][$fieldName])) {
|
||||
if ($tableName == 'civicrm_address') {
|
||||
$this->_addressField = TRUE;
|
||||
}
|
||||
elseif ($tableName == 'civicrm_email') {
|
||||
$this->_emailField = TRUE;
|
||||
}
|
||||
elseif ($tableName == 'civicrm_phone') {
|
||||
$this->_phoneField = TRUE;
|
||||
}
|
||||
elseif ($tableName == 'civicrm_group_contact') {
|
||||
$this->_groupField = TRUE;
|
||||
}
|
||||
elseif ($tableName == $this->_demoTable) {
|
||||
$this->_demoField = TRUE;
|
||||
}
|
||||
elseif ($tableName == $this->_coreInfoTable) {
|
||||
$this->_coreField = TRUE;
|
||||
}
|
||||
elseif ($tableName == $this->_voterInfoTable) {
|
||||
$this->_voterInfoField = TRUE;
|
||||
}
|
||||
elseif ($tableName == "civicrm_contribution_cont") {
|
||||
$this->_contributionField = TRUE;
|
||||
}
|
||||
|
||||
$select[] = "{$table['alias']}.{$fieldName} as {$tableName}_{$fieldName}";
|
||||
$this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array::value('title', $field);
|
||||
$this->_columnHeaders["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array::value('type', $field);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->_select = "SELECT " . implode(",\n", $select) . " ";
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate FROM clause for SQL SELECT
|
||||
*/
|
||||
protected function from() {
|
||||
|
||||
$this->_from = " FROM civicrm_contact AS {$this->_aliases['civicrm_contact']} ";
|
||||
if ($this->_contributionField) {
|
||||
//store in a temp table max receive date & relevant contribution _value - described as 'group by trick' here http://dev.mysql.com/doc/refman/5.1/en/example-maximum-column-group-row.html
|
||||
//there doesn't appear to be any efficient way to do this without using the temp table
|
||||
//as we want to use the latest receive date & the latest value (not the max value)
|
||||
//and we want to join this against contact_id
|
||||
$query = "create temporary table civicrm_maxconts SELECT * FROM ( SELECT `receive_date` ,`total_amount`, contact_id FROM `civicrm_contribution` ORDER BY receive_date DESC) as maxies group by contact_id;";
|
||||
$dao = CRM_Core_DAO::executeQuery($query);
|
||||
//apparently it is faster to create & then index http://mysqldump.azundris.com/archives/80-CREATE-TEMPORARY-TABLE.html
|
||||
$query = "alter table civicrm_maxconts add index (contact_id);";
|
||||
$dao = CRM_Core_DAO::executeQuery($query);
|
||||
$this->_from .= "LEFT JOIN civicrm_maxconts cont_civireport ON contact_civireport.id = cont_civireport.contact_id ";
|
||||
}
|
||||
if ($this->_addressField) {
|
||||
$this->_from .= "LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']} ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id AND {$this->_aliases['civicrm_address']}.is_primary = 1\n";
|
||||
}
|
||||
|
||||
if ($this->_emailField) {
|
||||
$this->_from .= "LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']} ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id AND {$this->_aliases['civicrm_email']}.is_primary = 1\n";
|
||||
}
|
||||
|
||||
if ($this->_phoneField) {
|
||||
$this->_from .= "LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']} ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND {$this->_aliases['civicrm_phone']}.is_primary = 1\n";
|
||||
}
|
||||
|
||||
if ($this->_demoField) {
|
||||
$this->_from .= " LEFT JOIN " . $this->_demoTable . " AS " . $this->_aliases[$this->_demoTable] . " ON {$this->_aliases['civicrm_contact']}.id =" . $this->_aliases[$this->_demoTable] . ".entity_id\n";
|
||||
}
|
||||
|
||||
if ($this->_coreField) {
|
||||
$this->_from .= " LEFT JOIN " . $this->_coreInfoTable . " AS " . $this->_aliases[$this->_coreInfoTable] . " ON {$this->_aliases['civicrm_contact']}.id =" . $this->_aliases[$this->_coreInfoTable] . ".entity_id\n";
|
||||
}
|
||||
|
||||
if ($this->_voterInfoField) {
|
||||
$this->_from .= " LEFT JOIN {$this->_voterInfoTable}" . " AS {$this->_aliases[$this->_voterInfoTable]}" . " ON {$this->_aliases['civicrm_contact']}.id =" . "{$this->_aliases[$this->_voterInfoTable]}.entity_id\n";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Interpret the 'order_by' keys in selected fields
|
||||
*/
|
||||
public function orderBy() {
|
||||
$this->_orderBy = "";
|
||||
foreach ($this->_columns as $tableName => $table) {
|
||||
if (array_key_exists('order_bys', $table)) {
|
||||
foreach ($table['order_bys'] as $fieldName => $field) {
|
||||
$this->_orderBy[] = $field['dbAlias'];
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->_orderBy = "ORDER BY " . implode(', ', $this->_orderBy) . " ";
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a string of fields separated by \x01 to a
|
||||
* string of fields separated by commas
|
||||
*/
|
||||
public function hexOne2str($hexOne) {
|
||||
$hexOneArray = explode("\x01", $hexOne);
|
||||
foreach ($hexOneArray as $key => $value) {
|
||||
if (empty($value)) {
|
||||
unset($hexOneArray[$key]);
|
||||
}
|
||||
}
|
||||
return implode(', ', $hexOneArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert MySQL YYYY-MM-DD HH:MM:SS date of birth timestamp to
|
||||
* current age
|
||||
*/
|
||||
public function dob2age($myTimestamp) {
|
||||
// Separate parts of DOB timestamp
|
||||
$matches = array();
|
||||
preg_match('/(\d\d\d\d)-(\d\d)-(\d\d)/',
|
||||
$myTimestamp, $matches
|
||||
);
|
||||
//var_dump($matches);
|
||||
$dobYear = (int) $matches[1];
|
||||
$dobMonth = (int) $matches[2];
|
||||
$dobDay = (int) $matches[3];
|
||||
//echo "DOB year=$dobYear month=$dobMonth day=$dobDay<br>";
|
||||
|
||||
$nowYear = (int) strftime('%Y');
|
||||
$nowMonth = (int) strftime('%m');
|
||||
$nowDay = (int) strftime('%d');
|
||||
//echo "Now year=$nowYear month=$nowMonth day=$nowDay<br>";
|
||||
// Calculate age
|
||||
if ($dobMonth < $nowMonth) {
|
||||
|
||||
// Born in a month before this month
|
||||
$age = $nowYear - $dobYear;
|
||||
}
|
||||
elseif ($dobMonth == $nowMonth) {
|
||||
// Born in this month
|
||||
if ($dobDay <= $nowDay) {
|
||||
// Born before or on this day
|
||||
$age = $nowYear - $dobYear;
|
||||
}
|
||||
else {
|
||||
// Born after today in this month
|
||||
$age = $nowYear - $dobYear - 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Born in a month after this month
|
||||
$age = $nowYear - $dobYear - 1;
|
||||
}
|
||||
//echo "age=$age years<br>";
|
||||
return $age;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,643 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* @copyright DharmaTech (c) 2009
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
require_once 'Engage/Report/Form/List.php';
|
||||
|
||||
/**
|
||||
* Generate a walk list
|
||||
*/
|
||||
class Engage_Report_Form_WalkList extends Engage_Report_Form_List {
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct();
|
||||
|
||||
// Walk list columns
|
||||
$this->_columns = array(
|
||||
$this->_demoTable => array(
|
||||
'dao' => 'CRM_Contact_DAO_Contact',
|
||||
'fields' => array(
|
||||
$this->_demoLangCol => array(
|
||||
'type' => CRM_Report_Form::OP_STRING,
|
||||
'required' => TRUE,
|
||||
'title' => ts('Language'),
|
||||
),
|
||||
),
|
||||
'filters' => array(
|
||||
$this->_demoLangCol => array(
|
||||
'title' => ts('Language'),
|
||||
'operatorType' => CRM_Report_Form::OP_SELECT,
|
||||
'type' => CRM_Report_Form::OP_STRING,
|
||||
'options' => $this->_languages,
|
||||
),
|
||||
),
|
||||
'grouping' => 'contact-fields',
|
||||
),
|
||||
$this->_coreInfoTable => array(
|
||||
'dao' => 'CRM_Contact_DAO_Contact',
|
||||
'fields' => array(
|
||||
$this->_coreTypeCol => array(
|
||||
'type' => CRM_Report_Form::OP_STRING,
|
||||
'required' => TRUE,
|
||||
'title' => ts('Constituent Type'),
|
||||
),
|
||||
$this->_coreOtherCol => array(
|
||||
'type' => CRM_Report_Form::OP_STRING,
|
||||
'required' => TRUE,
|
||||
'title' => ts('Other Name'),
|
||||
),
|
||||
),
|
||||
'filters' => array(
|
||||
$this->_coreTypeCol => array(
|
||||
'title' => ts('Constituent Type'),
|
||||
'operatorType' => CRM_Report_Form::OP_SELECT,
|
||||
'type' => CRM_Report_Form::OP_STRING,
|
||||
'options' => $this->_contactType,
|
||||
),
|
||||
),
|
||||
'grouping' => 'contact-fields',
|
||||
),
|
||||
'civicrm_contact' => array(
|
||||
'dao' => 'CRM_Contact_DAO_Contact',
|
||||
'fields' => array(
|
||||
'gender_id' => array(
|
||||
'title' => ts('Sex'),
|
||||
'required' => TRUE,
|
||||
),
|
||||
'birth_date' => array(
|
||||
'title' => ts('Age'),
|
||||
'required' => TRUE,
|
||||
'type' => CRM_Report_Form::OP_INT,
|
||||
),
|
||||
'id' => array(
|
||||
'title' => ts('Contact ID'),
|
||||
'required' => TRUE,
|
||||
),
|
||||
'display_name' => array(
|
||||
'title' => ts('Contact Name'),
|
||||
'required' => TRUE,
|
||||
'no_repeat' => TRUE,
|
||||
),
|
||||
),
|
||||
'filters' => array(
|
||||
'gender_id' => array(
|
||||
'title' => ts('Sex'),
|
||||
'operatorType' => CRM_Report_Form::OP_SELECT,
|
||||
'type' => CRM_Report_Form::OP_STRING,
|
||||
'options' => array('' => '') + CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'),
|
||||
),
|
||||
'sort_name' => array(
|
||||
'title' => ts('Contact Name'),
|
||||
'operator' => 'like',
|
||||
),
|
||||
),
|
||||
'grouping' => 'contact-fields',
|
||||
'order_bys' => array(
|
||||
'sort_name' => array(
|
||||
'title' => ts('Contact Name'),
|
||||
'required' => TRUE,
|
||||
),
|
||||
),
|
||||
),
|
||||
'civicrm_address' => array(
|
||||
'dao' => 'CRM_Core_DAO_Address',
|
||||
'fields' => array(
|
||||
'street_number' => array(
|
||||
'required' => TRUE,
|
||||
'title' => ts('Street#'),
|
||||
),
|
||||
'street_name' => array(
|
||||
'title' => ts('Street Name'),
|
||||
'nodisplay' => TRUE,
|
||||
'required' => TRUE,
|
||||
),
|
||||
'street_address' => array(
|
||||
'required' => TRUE,
|
||||
'title' => ts('Street Address'),
|
||||
),
|
||||
'street_unit' => array(
|
||||
'required' => TRUE,
|
||||
'title' => ts('Apt.'),
|
||||
),
|
||||
'city' => array(
|
||||
'required' => TRUE,
|
||||
),
|
||||
'postal_code' => array(
|
||||
'title' => 'Zip',
|
||||
'required' => TRUE,
|
||||
),
|
||||
'state_province_id' => array(
|
||||
'title' => ts('State/Province'),
|
||||
'required' => TRUE,
|
||||
),
|
||||
'country_id' => array(
|
||||
'title' => ts('Country'),
|
||||
),
|
||||
),
|
||||
'filters' => array(
|
||||
'street_address' => NULL,
|
||||
'city' => NULL,
|
||||
'postal_code' => array('title' => 'Zip'),
|
||||
),
|
||||
'grouping' => 'location-fields',
|
||||
),
|
||||
'civicrm_phone' => array(
|
||||
'dao' => 'CRM_Core_DAO_Phone',
|
||||
'fields' => array(
|
||||
'phone' => array(
|
||||
'default' => TRUE,
|
||||
'required' => TRUE,
|
||||
),
|
||||
),
|
||||
'grouping' => 'location-fields',
|
||||
),
|
||||
'civicrm_email' => array(
|
||||
'dao' => 'CRM_Core_DAO_Email',
|
||||
'fields' => array(
|
||||
'email' => NULL,
|
||||
),
|
||||
'grouping' => 'location-fields',
|
||||
),
|
||||
$this->_voterInfoTable => array(
|
||||
'dao' => 'CRM_Contact_DAO_Contact',
|
||||
'fields' => array(
|
||||
$this->_partyCol => array(
|
||||
'type' => CRM_Report_Form::OP_STRING,
|
||||
'required' => TRUE,
|
||||
'title' => ts('Party Reg'),
|
||||
),
|
||||
$this->_vhCol => array(
|
||||
'type' => CRM_Report_Form::OP_STRING,
|
||||
'required' => TRUE,
|
||||
'title' => ts('VH'),
|
||||
),
|
||||
),
|
||||
'filters' => array(),
|
||||
'grouping' => 'contact-fields',
|
||||
),
|
||||
'civicrm_group' => array(
|
||||
'dao' => 'CRM_Contact_DAO_GroupContact',
|
||||
'alias' => 'cgroup',
|
||||
'filters' => array(
|
||||
'gid' => array(
|
||||
'name' => 'group_id',
|
||||
'title' => ts('Group'),
|
||||
'operatorType' => CRM_Report_Form::OP_MULTISELECT,
|
||||
'group' => TRUE,
|
||||
'options' => CRM_Core_PseudoConstant::group(),
|
||||
),
|
||||
),
|
||||
),
|
||||
'civicrm_contribution_lastcont' => array(
|
||||
'dao' => 'CRM_Contribute_DAO_Contribution',
|
||||
),
|
||||
'civicrm_contribution_cont' => array(
|
||||
'dao' => 'CRM_Contribute_DAO_Contribution',
|
||||
'alias' => 'cont',
|
||||
'fields' => array(
|
||||
'receive_date' => array(
|
||||
'default' => TRUE,
|
||||
'title' => 'Last Receipt',
|
||||
),
|
||||
'total_amount' => array(
|
||||
'default' => TRUE,
|
||||
'title' => 'Amount received',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate WHERE clauses for SQL SELECT
|
||||
* FIXME: deal with age filter
|
||||
*/
|
||||
public function where() {
|
||||
$clauses = array("{$this->_aliases['civicrm_address']}.id IS NOT NULL");
|
||||
|
||||
foreach ($this->_columns as $tableName => $table) {
|
||||
//echo "where: table name $tableName<br>";
|
||||
|
||||
// Treatment of normal filters
|
||||
if (array_key_exists('filters', $table)) {
|
||||
foreach ($table['filters'] as $fieldName => $field) {
|
||||
//echo " field name $fieldName<br>";
|
||||
$clause = NULL;
|
||||
|
||||
if (CRM_Utils_Array::value('type', $field) & CRM_Utils_Type::T_DATE) {
|
||||
$relative = CRM_Utils_Array::value("{$fieldName}_relative", $this->_params);
|
||||
$from = CRM_Utils_Array::value("{$fieldName}_from", $this->_params);
|
||||
$to = CRM_Utils_Array::value("{$fieldName}_to", $this->_params);
|
||||
|
||||
$clause = $this->dateClause($field['name'], $relative, $from, $to);
|
||||
}
|
||||
elseif ($fieldName == $this->_demoLangCol) {
|
||||
if (!empty($this->_params[$this->_demoLangCol . '_value'])) {
|
||||
$clause = "{$field['dbAlias']}='" . $this->_params[$this->_demoLangCol . '_value'] . "'";
|
||||
}
|
||||
}
|
||||
else {
|
||||
$op = CRM_Utils_Array::value("{$fieldName}_op", $this->_params);
|
||||
if ($op == 'mand') {
|
||||
$clause = TRUE;
|
||||
}
|
||||
elseif ($op) {
|
||||
$clause = $this->whereClause($field,
|
||||
$op,
|
||||
CRM_Utils_Array::value("{$fieldName}_value", $this->_params),
|
||||
CRM_Utils_Array::value("{$fieldName}_min", $this->_params),
|
||||
CRM_Utils_Array::value("{$fieldName}_max", $this->_params)
|
||||
);
|
||||
}
|
||||
}
|
||||
//var_dump($clause);
|
||||
if (!empty($clause)) {
|
||||
if (!empty($field['group'])) {
|
||||
$clauses[] = $this->engageWhereGroupClause($clause);
|
||||
}
|
||||
else {
|
||||
$clauses[] = $clause;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($clauses)) {
|
||||
$this->_where = "WHERE ( 1 ) ";
|
||||
}
|
||||
else {
|
||||
$this->_where = "WHERE " . implode(' AND ', $clauses);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process submitted form
|
||||
*/
|
||||
public function postProcess() {
|
||||
parent::postProcess();
|
||||
}
|
||||
|
||||
public function alterDisplay(&$rows) {
|
||||
|
||||
if ($this->_outputMode == 'print' || $this->_outputMode == 'pdf') {
|
||||
$this->executePrintmode($rows);
|
||||
return;
|
||||
}
|
||||
// custom code to alter rows
|
||||
//var_dump($rows);
|
||||
$genderList = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id');
|
||||
$entryFound = FALSE;
|
||||
foreach ($rows as $rowNum => $row) {
|
||||
// handle state province
|
||||
if (array_key_exists('civicrm_address_state_province_id', $row)) {
|
||||
if ($value = $row['civicrm_address_state_province_id']) {
|
||||
$rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant::stateProvince($value);
|
||||
}
|
||||
$entryFound = TRUE;
|
||||
}
|
||||
|
||||
// handle country
|
||||
if (array_key_exists('civicrm_address_country_id', $row)) {
|
||||
if ($value = $row['civicrm_address_country_id']) {
|
||||
$rows[$rowNum]['civicrm_address_country_id'] = CRM_Core_PseudoConstant::country($value);
|
||||
}
|
||||
$entryFound = TRUE;
|
||||
}
|
||||
|
||||
// Handle contactType
|
||||
if (!empty($row[$this->_coreInfoTable . '_' . $this->_coreTypeCol])) {
|
||||
$rows[$rowNum][$this->_coreInfoTable . '_' . $this->_coreTypeCol] = $this->hexOne2str($rows[$rowNum][$this->_coreInfoTable . '_' . $this->_coreTypeCol]);
|
||||
$entryFound = TRUE;
|
||||
}
|
||||
|
||||
// date of birth to age
|
||||
if (!empty($row['civicrm_contact_birth_date'])) {
|
||||
$rows[$rowNum]['civicrm_contact_birth_date'] = $this->dob2age($row['civicrm_contact_birth_date'] . " 00:00:00");
|
||||
$entryFound = TRUE;
|
||||
}
|
||||
|
||||
// gender label
|
||||
if (!empty($row['civicrm_contact_gender_id'])) {
|
||||
$rows[$rowNum]['civicrm_contact_gender_id'] = $genderList[$row['civicrm_contact_gender_id']];
|
||||
$entryFound = TRUE;
|
||||
}
|
||||
|
||||
// Abbreviate party registration to first letter
|
||||
if (!empty($row["{$this->_voterInfoTable}_{$this->_partyCol}"])) {
|
||||
$rows[$rowNum]["{$this->_voterInfoTable}_{$this->_partyCol}"] = substr($row["{$this->_voterInfoTable}_{$this->_partyCol}"], 0, 1);
|
||||
$entryFound = TRUE;
|
||||
}
|
||||
|
||||
// skip looking further in rows, if first row itself doesn't
|
||||
// have the column we need
|
||||
if (!$entryFound) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// make sure column order is same as in print mode
|
||||
$columnOrder = array(
|
||||
'civicrm_address_street_number',
|
||||
'civicrm_address_street_unit',
|
||||
'civicrm_contact_display_name',
|
||||
'civicrm_phone_phone',
|
||||
'civicrm_contact_birth_date',
|
||||
'civicrm_contact_gender_id',
|
||||
$this->_demoTable . '_' . $this->_demoLangCol,
|
||||
$this->_voterInfoTable . '_' . $this->_partyCol,
|
||||
$this->_voterInfoTable . '_' . $this->_vhCol,
|
||||
$this->_coreInfoTable . '_' . $this->_coreTypeCol,
|
||||
'civicrm_contact_id',
|
||||
);
|
||||
$tempHeaders = $this->_columnHeaders;
|
||||
$this->_columnHeaders = array();
|
||||
foreach ($columnOrder as $col) {
|
||||
if (array_key_exists($col, $tempHeaders)) {
|
||||
$this->_columnHeaders[$col] = $tempHeaders[$col];
|
||||
unset($tempHeaders[$col]);
|
||||
}
|
||||
}
|
||||
$this->_columnHeaders = $this->_columnHeaders + $tempHeaders;
|
||||
}
|
||||
|
||||
public function executePrintmode($rows) {
|
||||
//only get these last contribution related variables in print mode if selected on previous form
|
||||
if (array_key_exists('civicrm_contribution_cont_receive_date', $rows[0])) {
|
||||
$receiveDate = ', date_received DATE';
|
||||
}
|
||||
if (array_key_exists('civicrm_contribution_cont_total_amount', $rows[0])) {
|
||||
$contAmount = ' , total_amount FLOAT';
|
||||
}
|
||||
// Separate out fields and build a temporary table
|
||||
$tempTable = "WalkList_" . uniqid();
|
||||
$sql = "CREATE TEMPORARY TABLE {$tempTable}" . " ( id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
|
||||
street_name VARCHAR(255),
|
||||
s_street_number VARCHAR(32),
|
||||
i_street_number INT,
|
||||
odd TINYINT,
|
||||
apt_number VARCHAR(32),
|
||||
city VARCHAR(64),
|
||||
state VARCHAR(32),
|
||||
zip VARCHAR(32),
|
||||
name VARCHAR(255),
|
||||
phone VARCHAR(255),
|
||||
age INT,
|
||||
sex VARCHAR(16),
|
||||
lang CHAR(2),
|
||||
party CHAR(1),
|
||||
vh CHAR(1),
|
||||
contact_type VARCHAR(128),
|
||||
other_name VARCHAR(128),
|
||||
contact_id INT
|
||||
$receiveDate $contAmount
|
||||
)
|
||||
ENGINE=HEAP
|
||||
DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci";
|
||||
CRM_Core_DAO::executeQuery($sql);
|
||||
|
||||
$gender = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id');
|
||||
|
||||
foreach ($rows as $key => $value) {
|
||||
|
||||
$dob = $value['civicrm_contact_birth_date'];
|
||||
$age = empty($dob) ? 0 : $this->dob2age($dob);
|
||||
if (!empty($value['civicrm_contact_gender_id'])) {
|
||||
$sex = $gender[CRM_Utils_Array::value('civicrm_contact_gender_id', $value)];
|
||||
}
|
||||
$sex = empty($sex) ? '' : $sex;
|
||||
$lang = strtoupper(substr($value[$this->_demoTable . '_' . $this->_demoLangCol], 0, 2));
|
||||
$party = substr($value["{$this->_voterInfoTable}_{$this->_partyCol}"], 0, 1);
|
||||
$vh = substr($value["{$this->_voterInfoTable}_{$this->_vhCol}"], 0, 1);
|
||||
$contactType = $value[$this->_coreInfoTable . '_' . $this->_coreTypeCol];
|
||||
$on = $value[$this->_coreInfoTable . '_' . $this->_coreOtherCol];
|
||||
$otherName = empty($on) ? 0 : "'{$on}'";
|
||||
$type = '';
|
||||
if (!empty($contactType)) {
|
||||
$type = $this->hexOne2str($contactType);
|
||||
}
|
||||
$contact_id = (int) $value['civicrm_contact_id'];
|
||||
|
||||
$state = '';
|
||||
if (!empty($value['civicrm_address_state_province_id'])) {
|
||||
$state = CRM_Core_PseudoConstant::stateProvince(
|
||||
$value['civicrm_address_state_province_id']
|
||||
);
|
||||
}
|
||||
|
||||
$sStreetNumber = $value['civicrm_address_street_number'];
|
||||
$iStreetNumber = $value['civicrm_address_street_number'] ? (int) $value['civicrm_address_street_number'] : 0;
|
||||
$odd = $value['civicrm_address_street_number'] ? ((int) $value['civicrm_address_street_number'] % 2) : 0;
|
||||
$apt_number = $value['civicrm_address_street_number'] ? $value['civicrm_address_street_number'] : '';
|
||||
$phone_number = $value['civicrm_phone_phone'] ? $value['civicrm_phone_phone'] : '';
|
||||
$query = "INSERT INTO {$tempTable} SET
|
||||
street_name = %1,
|
||||
s_street_number = %2,
|
||||
i_street_number = %3,
|
||||
odd = %4,
|
||||
apt_number = %5,
|
||||
city = %6,
|
||||
state = %7,
|
||||
zip = %8,
|
||||
name = %9,
|
||||
phone = %10,
|
||||
age = %11,
|
||||
sex = %12,
|
||||
lang = %13,
|
||||
party = %14,
|
||||
vh = %15,
|
||||
contact_type = %16,
|
||||
other_name = %17,
|
||||
contact_id = %18";
|
||||
$params = array(
|
||||
1 => array($value['civicrm_address_street_name'] ? $value['civicrm_address_street_name'] : '', 'String'),
|
||||
2 => array((String) $sStreetNumber, 'String'),
|
||||
3 => array($iStreetNumber, 'Integer'),
|
||||
4 => array($odd, 'Integer'),
|
||||
5 => array((String) $apt_number , 'String'),
|
||||
6 => array($value['civicrm_address_city'] ? $value['civicrm_address_city'] : '', 'String'),
|
||||
7 => array((String) $state , 'String'),
|
||||
8 => array($value['civicrm_address_postal_code'] ? $value['civicrm_address_postal_code'] : '', 'String'),
|
||||
9 => array($value['civicrm_contact_display_name'] ? $value['civicrm_contact_display_name'] : '', 'String'),
|
||||
10 => array((String) $phone_number, 'String'),
|
||||
11 => array($age, 'Integer'),
|
||||
12 => array((String) $sex, 'String'),
|
||||
13 => array((String) $lang, 'String'),
|
||||
14 => array((String) $party, 'String'),
|
||||
15 => array((String) $vh, 'String'),
|
||||
16 => array((String) $type, 'String'),
|
||||
17 => array((String) $otherName, 'String'),
|
||||
18 => array((String) $contact_id, 'Integer'),
|
||||
);
|
||||
|
||||
if (!empty($contAmount)) {
|
||||
$query .= ", total_amount = %19";
|
||||
$total_amount = $value['civicrm_contribution_cont_total_amount'] ? $value['civicrm_contribution_cont_total_amount'] : 0;
|
||||
$params[19] = array($total_amount, 'Money');
|
||||
}
|
||||
if (!empty($receiveDate)) {
|
||||
$query .= ",date_received = %20";
|
||||
$date_received = $value['civicrm_contribution_cont_receive_date'] ? CRM_Utils_Date::isoToMysql($value['civicrm_contribution_cont_receive_date']) : NULL;
|
||||
$params[20] = array($date_received, 'Timestamp');
|
||||
}
|
||||
CRM_Core_DAO::executeQuery($query, $params);
|
||||
}
|
||||
|
||||
// With the data normalized and in a table, we can
|
||||
// retrieve it in the order we need to present it
|
||||
$query = "SELECT * FROM {$tempTable} ORDER BY state, city, zip,
|
||||
street_name, odd, i_street_number, apt_number";
|
||||
$dao = CRM_Core_DAO::executeQuery($query);
|
||||
|
||||
// Initialize output state
|
||||
$first = TRUE;
|
||||
$state = '';
|
||||
$city = '';
|
||||
$zip = '';
|
||||
$street_name = '';
|
||||
$odd = '';
|
||||
$pageRow = 0;
|
||||
$reportDate = date('F j, Y');
|
||||
|
||||
$pdfRows = array();
|
||||
$groupRows = array();
|
||||
$groupCounts = 0;
|
||||
|
||||
$pdfHeaders = array(
|
||||
's_street_number' => array('title' => 'STREET#'),
|
||||
'apt_number' => array('title' => 'APT'),
|
||||
'name' => array('title' => 'Name'),
|
||||
'phone' => array('title' => 'PHONE'),
|
||||
'age' => array('title' => 'AGE'),
|
||||
'sex' => array('title' => 'SEX'),
|
||||
'lang' => array('title' => 'Lang'),
|
||||
'party' => array('title' => 'Party'),
|
||||
'vh' => array('title' => 'VH'),
|
||||
'contact_type' => array('title' => 'Constituent Type'),
|
||||
'note' => array('title' => 'NOTES'),
|
||||
'rcode' => array('title' => 'RESPONSE CODES'),
|
||||
'status' => array('title' => 'STATUS'),
|
||||
'contact_id' => array(
|
||||
'title' => 'ID',
|
||||
'class' => 'width=7%',
|
||||
),
|
||||
);
|
||||
|
||||
if (variable_get('civicrm_engage_groupbreak_street', "1") != 1) {
|
||||
$pdfHeaders['street_name']['title'] = 'Street';
|
||||
}
|
||||
if ($receiveDate) {
|
||||
$pdfHeaders['date_received'] = array('title' => 'Last donation Date');
|
||||
}
|
||||
if ($contAmount) {
|
||||
$pdfHeaders['total_amount'] = array('title' => 'Last donation');
|
||||
}
|
||||
|
||||
$groupInfo = array(
|
||||
'date' => $reportDate,
|
||||
'descr' => empty($this->_groupDescr) ? '' : "<br>Group {$this->_groupDescr}",
|
||||
);
|
||||
|
||||
while ($dao->fetch()) {
|
||||
|
||||
if (strtolower($state) != strtolower($dao->state)
|
||||
|| (variable_get('civicrm_engage_groupbreak_city', "1") == 1 && strtolower($city) != strtolower($dao->city))
|
||||
|| (variable_get('civicrm_engage_groupbreak_zip', "1") == 1 && strtolower($zip) != strtolower($dao->zip))
|
||||
|| (variable_get('civicrm_engage_groupbreak_street', "1") == 1 && strtolower($street_name) != strtolower($dao->street_name))
|
||||
|| (variable_get('civicrm_engage_groupbreak_odd_even', "1") == 1 && $odd != $dao->odd)
|
||||
|| $pageRow > variable_get('civicrm_engage_lines_per_group', "6") - 1
|
||||
) {
|
||||
$state = $dao->state;
|
||||
$city = $dao->city;
|
||||
$zip = $dao->zip;
|
||||
$street_name = $dao->street_name;
|
||||
$odd = $dao->odd;
|
||||
$pageRow = 0;
|
||||
$groupRow['city_zip'] = '';
|
||||
$groupRow['org'] = $this->_orgName;
|
||||
if (variable_get('civicrm_engage_groupbreak_street', "1") == 1) {
|
||||
$groupRow['street_name'] = $street_name;
|
||||
}
|
||||
if (variable_get('civicrm_engage_groupbreak_city', "1") == 1) {
|
||||
$groupRow['city_zip'] .= $city . ', ';
|
||||
}
|
||||
$groupRow['city_zip'] .= $state;
|
||||
//don't give zip or odd-even if not grouped on
|
||||
if (variable_get('civicrm_engage_groupbreak_zip', "1") == 1) {
|
||||
$groupRow['city_zip'] .= ' ' . $zip;
|
||||
}
|
||||
if (variable_get('civicrm_engage_groupbreak_odd_even', "1") == 1) {
|
||||
$groupRow['odd'] = $odd ? 'Odd' : 'Even';
|
||||
}
|
||||
$groupCounts++;
|
||||
$groupRows[$groupCounts] = $groupRow;
|
||||
}
|
||||
|
||||
// if admin settings have been defined to specify not to canvas people for a period change date to specified text
|
||||
if (variable_get('civicrm_engage_no_canvas_period', "0") > 0 && $dao->date_received > 0
|
||||
&& ((strtotime("now") - strtotime($dao->date_received)) / 60 / 60 / 24 / 30) < variable_get('civicrm_engage_no_canvas_period', "0")
|
||||
) {
|
||||
$dao->date_received = variable_get('civicrm_engage_no_canvass_text', "Do Not Canvass");
|
||||
}
|
||||
|
||||
$pdfRow = array();
|
||||
foreach ($pdfHeaders as $k => $v) {
|
||||
if (property_exists($dao, $k)) {
|
||||
if ($k == 'name' && $dao->other_name) {
|
||||
$pdfRow[$k] = $dao->$k . "<br />" . $dao->other_name;
|
||||
continue;
|
||||
}
|
||||
$pdfRow[$k] = $dao->$k;
|
||||
}
|
||||
else {
|
||||
$pdfRow[$k] = "";
|
||||
}
|
||||
}
|
||||
|
||||
$pdfRows[$groupCounts][] = $pdfRow;
|
||||
|
||||
$pageRow++;
|
||||
}
|
||||
if (variable_get('civicrm_engage_group_per_page', "1")) {
|
||||
$this->assign('newgroupdiv', 'class="page"');
|
||||
}
|
||||
$this->assign('pageTotal', $groupCounts);
|
||||
$this->assign('pdfHeaders', $pdfHeaders);
|
||||
$this->assign('groupInfo', $groupInfo);
|
||||
$this->assign('pdfRows', $pdfRows);
|
||||
$this->assign('groupRows', $groupRows);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,757 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1" ?>
|
||||
<!-- This xml file defines the custom data, option values, and profiles to be used with CiviEngage, PB / CiviEngage v2.0 -->
|
||||
<CustomData>
|
||||
<CustomGroups>
|
||||
<CustomGroup>
|
||||
<name>Voter_Info</name>
|
||||
<title>Voter Info</title>
|
||||
<extends>Individual</extends>
|
||||
<style>Tab</style>
|
||||
<collapse_display>0</collapse_display>
|
||||
<help_pre></help_pre>
|
||||
<help_post></help_post>
|
||||
<weight>3</weight>
|
||||
<is_active>1</is_active>
|
||||
<table_name>civicrm_value_voter_info</table_name>
|
||||
<is_multiple>0</is_multiple>
|
||||
<collapse_adv_display>0</collapse_adv_display>
|
||||
</CustomGroup>
|
||||
</CustomGroups>
|
||||
<CustomFields>
|
||||
<CustomField>
|
||||
<custom_group_name>Voter_Info</custom_group_name>
|
||||
<label>Precinct</label>
|
||||
<column_name>precinct</column_name>
|
||||
<data_type>String</data_type>
|
||||
<html_type>Text</html_type>
|
||||
<is_required>0</is_required>
|
||||
<is_searchable>1</is_searchable>
|
||||
<is_search_range>0</is_search_range>
|
||||
<weight>124</weight>
|
||||
<is_active>1</is_active>
|
||||
<is_view>0</is_view>
|
||||
<text_length>255</text_length>
|
||||
<date_format>M:;:;:;d:;:;:;Y</date_format>
|
||||
<note_columns>60</note_columns>
|
||||
<note_rows>4</note_rows>
|
||||
</CustomField>
|
||||
<CustomField>
|
||||
<custom_group_name>Voter_Info</custom_group_name>
|
||||
<label>State Senate District</label>
|
||||
<column_name>state_senate_district</column_name>
|
||||
<data_type>String</data_type>
|
||||
<html_type>Text</html_type>
|
||||
<is_required>0</is_required>
|
||||
<is_searchable>1</is_searchable>
|
||||
<is_search_range>0</is_search_range>
|
||||
<weight>140</weight>
|
||||
<is_active>1</is_active>
|
||||
<is_view>0</is_view>
|
||||
<text_length>255</text_length>
|
||||
<note_columns>60</note_columns>
|
||||
<note_rows>4</note_rows>
|
||||
</CustomField>
|
||||
<CustomField>
|
||||
<custom_group_name>Voter_Info</custom_group_name>
|
||||
<label>City District</label>
|
||||
<column_name>city_district</column_name>
|
||||
<data_type>String</data_type>
|
||||
<html_type>Text</html_type>
|
||||
<is_required>0</is_required>
|
||||
<is_searchable>1</is_searchable>
|
||||
<is_search_range>0</is_search_range>
|
||||
<weight>133</weight>
|
||||
<is_active>1</is_active>
|
||||
<is_view>0</is_view>
|
||||
<text_length>255</text_length>
|
||||
<date_format>M:;:;:;d:;:;:;Y</date_format>
|
||||
<note_columns>60</note_columns>
|
||||
<note_rows>4</note_rows>
|
||||
</CustomField>
|
||||
<CustomField>
|
||||
<custom_group_name>Voter_Info</custom_group_name>
|
||||
<label>School District</label>
|
||||
<column_name>school_district</column_name>
|
||||
<data_type>String</data_type>
|
||||
<html_type>Text</html_type>
|
||||
<is_required>0</is_required>
|
||||
<is_searchable>1</is_searchable>
|
||||
<is_search_range>0</is_search_range>
|
||||
<weight>149</weight>
|
||||
<is_active>1</is_active>
|
||||
<is_view>0</is_view>
|
||||
<text_length>255</text_length>
|
||||
<note_columns>60</note_columns>
|
||||
<note_rows>4</note_rows>
|
||||
</CustomField>
|
||||
<CustomField>
|
||||
<custom_group_name>Voter_Info</custom_group_name>
|
||||
<label>County District</label>
|
||||
<column_name>county_district</column_name>
|
||||
<data_type>String</data_type>
|
||||
<html_type>Text</html_type>
|
||||
<is_required>0</is_required>
|
||||
<is_searchable>1</is_searchable>
|
||||
<is_search_range>0</is_search_range>
|
||||
<weight>154</weight>
|
||||
<is_active>1</is_active>
|
||||
<is_view>0</is_view>
|
||||
<text_length>255</text_length>
|
||||
<note_columns>60</note_columns>
|
||||
<note_rows>4</note_rows>
|
||||
</CustomField>
|
||||
<CustomField>
|
||||
<custom_group_name>Voter_Info</custom_group_name>
|
||||
<label>Congressional District</label>
|
||||
<column_name>congressional_district</column_name>
|
||||
<data_type>String</data_type>
|
||||
<html_type>Text</html_type>
|
||||
<is_required>0</is_required>
|
||||
<is_searchable>1</is_searchable>
|
||||
<is_search_range>0</is_search_range>
|
||||
<weight>158</weight>
|
||||
<is_active>1</is_active>
|
||||
<is_view>0</is_view>
|
||||
<text_length>255</text_length>
|
||||
<date_format>M:;:;:;d:;:;:;Y</date_format>
|
||||
<note_columns>60</note_columns>
|
||||
<note_rows>4</note_rows>
|
||||
</CustomField>
|
||||
<CustomField>
|
||||
<label>Voter History</label>
|
||||
<data_type>String</data_type>
|
||||
<html_type>Radio</html_type>
|
||||
<is_required>0</is_required>
|
||||
<is_searchable>1</is_searchable>
|
||||
<is_search_range>0</is_search_range>
|
||||
<weight>125</weight>
|
||||
<help_post>A - Always
|
||||
O - Occasional
|
||||
N - New</help_post>
|
||||
<is_active>1</is_active>
|
||||
<is_view>0</is_view>
|
||||
<text_length>255</text_length>
|
||||
<date_format>M:;:;:;d:;:;:;Y</date_format>
|
||||
<note_columns>60</note_columns>
|
||||
<note_rows>4</note_rows>
|
||||
<column_name>voter_history</column_name>
|
||||
<option_group_name>voter_history_options</option_group_name>
|
||||
<custom_group_name>Voter_Info</custom_group_name>
|
||||
</CustomField>
|
||||
<CustomField>
|
||||
<custom_group_name>Voter_Info</custom_group_name>
|
||||
<label>Party Registration</label>
|
||||
<column_name>party_registration</column_name>
|
||||
<data_type>String</data_type>
|
||||
<html_type>Radio</html_type>
|
||||
<is_required>0</is_required>
|
||||
<is_searchable>1</is_searchable>
|
||||
<is_search_range>0</is_search_range>
|
||||
<weight>8</weight>
|
||||
<is_active>1</is_active>
|
||||
<is_view>0</is_view>
|
||||
<text_length>255</text_length>
|
||||
<date_format>M:;:;:;d:;:;:;Y</date_format>
|
||||
<note_columns>60</note_columns>
|
||||
<note_rows>4</note_rows>
|
||||
<option_group_name>party_registration_options</option_group_name>
|
||||
</CustomField>
|
||||
<CustomField>
|
||||
<custom_group_name>Voter_Info</custom_group_name>
|
||||
<label>If other party...</label>
|
||||
<column_name>if_other_party</column_name>
|
||||
<data_type>String</data_type>
|
||||
<html_type>Text</html_type>
|
||||
<is_required>0</is_required>
|
||||
<is_searchable>1</is_searchable>
|
||||
<is_search_range>0</is_search_range>
|
||||
<weight>30</weight>
|
||||
<is_active>1</is_active>
|
||||
<is_view>0</is_view>
|
||||
<text_length>255</text_length>
|
||||
<date_format>M:;:;:;d:;:;:;Y</date_format>
|
||||
<note_columns>60</note_columns>
|
||||
<note_rows>4</note_rows>
|
||||
</CustomField>
|
||||
<CustomField>
|
||||
<custom_group_name>Voter_Info</custom_group_name>
|
||||
<label>County Name</label>
|
||||
<column_name>county_name</column_name>
|
||||
<data_type>String</data_type>
|
||||
<html_type>Select</html_type>
|
||||
<is_required>0</is_required>
|
||||
<is_searchable>1</is_searchable>
|
||||
<is_search_range>0</is_search_range>
|
||||
<weight>166</weight>
|
||||
<is_active>1</is_active>
|
||||
<is_view>0</is_view>
|
||||
<text_length>255</text_length>
|
||||
<date_format>M:;:;:;d:;:;:;Y</date_format>
|
||||
<note_columns>60</note_columns>
|
||||
<note_rows>4</note_rows>
|
||||
<option_group_name>county_name_options</option_group_name>
|
||||
</CustomField>
|
||||
<CustomField>
|
||||
<custom_group_name>Voter_Info</custom_group_name>
|
||||
<name>Van_ID</name>
|
||||
<label>Van ID</label>
|
||||
<column_name>van_id</column_name>
|
||||
<data_type>String</data_type>
|
||||
<html_type>Text</html_type>
|
||||
<is_required>0</is_required>
|
||||
<is_searchable>1</is_searchable>
|
||||
<is_search_range>0</is_search_range>
|
||||
<weight>188</weight>
|
||||
<is_active>1</is_active>
|
||||
<is_view>0</is_view>
|
||||
<text_length>255</text_length>
|
||||
<note_columns>60</note_columns>
|
||||
<note_rows>4</note_rows>
|
||||
</CustomField>
|
||||
<CustomField>
|
||||
<custom_group_name>Voter_Info</custom_group_name>
|
||||
<name>DW_ID</name>
|
||||
<column_name>dw_id</column_name>
|
||||
<label>DW ID</label>
|
||||
<data_type>String</data_type>
|
||||
<html_type>Text</html_type>
|
||||
<is_required>0</is_required>
|
||||
<is_searchable>1</is_searchable>
|
||||
<is_search_range>0</is_search_range>
|
||||
<weight>186</weight>
|
||||
<is_active>1</is_active>
|
||||
<is_view>0</is_view>
|
||||
<text_length>255</text_length>
|
||||
<note_columns>60</note_columns>
|
||||
<note_rows>4</note_rows>
|
||||
</CustomField>
|
||||
<CustomField>
|
||||
<custom_group_name>Voter_Info</custom_group_name>
|
||||
<name>County_File_ID</name>
|
||||
<label>County File ID</label>
|
||||
<column_name>county_field_id</column_name>
|
||||
<data_type>String</data_type>
|
||||
<html_type>Text</html_type>
|
||||
<is_required>0</is_required>
|
||||
<is_searchable>0</is_searchable>
|
||||
<is_search_range>0</is_search_range>
|
||||
<weight>193</weight>
|
||||
<is_active>1</is_active>
|
||||
<is_view>0</is_view>
|
||||
<text_length>255</text_length>
|
||||
<note_columns>60</note_columns>
|
||||
<note_rows>4</note_rows>
|
||||
</CustomField>
|
||||
<CustomField>
|
||||
<custom_group_name>Voter_Info</custom_group_name>
|
||||
<name>Precinct_Name</name>
|
||||
<label>Precinct Name</label>
|
||||
<column_name>precinct_name</column_name>
|
||||
<data_type>String</data_type>
|
||||
<html_type>Text</html_type>
|
||||
<is_required>0</is_required>
|
||||
<is_searchable>1</is_searchable>
|
||||
<is_search_range>0</is_search_range>
|
||||
<weight>33</weight>
|
||||
<is_active>1</is_active>
|
||||
<is_view>0</is_view>
|
||||
<text_length>255</text_length>
|
||||
<note_columns>60</note_columns>
|
||||
<note_rows>4</note_rows>
|
||||
</CustomField>
|
||||
<CustomField>
|
||||
<custom_group_name>Voter_Info</custom_group_name>
|
||||
<name>Voter_Registration_Date</name>
|
||||
<label>Voter Registration Date</label>
|
||||
<column_name>voter_registration_date</column_name>
|
||||
<data_type>Date</data_type>
|
||||
<html_type>Select Date</html_type>
|
||||
<is_required>0</is_required>
|
||||
<is_searchable>1</is_searchable>
|
||||
<is_search_range>1</is_search_range>
|
||||
<weight>171</weight>
|
||||
<is_active>1</is_active>
|
||||
<is_view>0</is_view>
|
||||
<text_length>255</text_length>
|
||||
<date_format>M:;:;:;d:;:;:;Y</date_format>
|
||||
<note_columns>60</note_columns>
|
||||
<note_rows>4</note_rows>
|
||||
</CustomField>
|
||||
<CustomField>
|
||||
<custom_group_name>Voter_Info</custom_group_name>
|
||||
<name>State_Voter_File_ID</name>
|
||||
<label>State Voter File ID</label>
|
||||
<column_name>state_voter_file_id</column_name>
|
||||
<data_type>String</data_type>
|
||||
<html_type>Text</html_type>
|
||||
<is_required>0</is_required>
|
||||
<is_searchable>0</is_searchable>
|
||||
<is_search_range>0</is_search_range>
|
||||
<weight>192</weight>
|
||||
<is_active>1</is_active>
|
||||
<is_view>0</is_view>
|
||||
<text_length>255</text_length>
|
||||
<note_columns>60</note_columns>
|
||||
<note_rows>4</note_rows>
|
||||
</CustomField>
|
||||
<CustomField>
|
||||
<custom_group_name>Voter_Info</custom_group_name>
|
||||
<name>State_Assembly_District</name>
|
||||
<label>State Assembly District</label>
|
||||
<column_name>state_assembly_district</column_name>
|
||||
<data_type>String</data_type>
|
||||
<html_type>Text</html_type>
|
||||
<is_required>0</is_required>
|
||||
<is_searchable>1</is_searchable>
|
||||
<is_search_range>0</is_search_range>
|
||||
<weight>135</weight>
|
||||
<is_active>1</is_active>
|
||||
<is_view>0</is_view>
|
||||
<text_length>255</text_length>
|
||||
<note_columns>60</note_columns>
|
||||
<note_rows>4</note_rows>
|
||||
</CustomField>
|
||||
<CustomField>
|
||||
<custom_group_name>Voter_Info</custom_group_name>
|
||||
<name>Elections_2011</name>
|
||||
<label>Elections 2011</label>
|
||||
<column_name>elections_2011</column_name>
|
||||
<data_type>String</data_type>
|
||||
<html_type>CheckBox</html_type>
|
||||
<default_value>Array</default_value>
|
||||
<is_required>0</is_required>
|
||||
<is_searchable>1</is_searchable>
|
||||
<is_search_range>0</is_search_range>
|
||||
<weight>172</weight>
|
||||
<is_active>1</is_active>
|
||||
<is_view>0</is_view>
|
||||
<text_length>255</text_length>
|
||||
<note_columns>60</note_columns>
|
||||
<note_rows>4</note_rows>
|
||||
<option_group_name>election_options</option_group_name>
|
||||
</CustomField>
|
||||
<CustomField>
|
||||
<custom_group_name>Voter_Info</custom_group_name>
|
||||
<name>Elections_2010</name>
|
||||
<label>Elections 2010</label>
|
||||
<column_name>elections_2010</column_name>
|
||||
<data_type>String</data_type>
|
||||
<html_type>CheckBox</html_type>
|
||||
<default_value>Array</default_value>
|
||||
<is_required>0</is_required>
|
||||
<is_searchable>1</is_searchable>
|
||||
<is_search_range>0</is_search_range>
|
||||
<weight>173</weight>
|
||||
<is_active>1</is_active>
|
||||
<is_view>0</is_view>
|
||||
<text_length>255</text_length>
|
||||
<note_columns>60</note_columns>
|
||||
<note_rows>4</note_rows>
|
||||
<option_group_name>election_options</option_group_name>
|
||||
</CustomField>
|
||||
<CustomField>
|
||||
<custom_group_name>Voter_Info</custom_group_name>
|
||||
<name>Elections_2009</name>
|
||||
<label>Elections 2009</label>
|
||||
<column_name>elections_2009</column_name>
|
||||
<data_type>String</data_type>
|
||||
<html_type>CheckBox</html_type>
|
||||
<default_value>Array</default_value>
|
||||
<is_required>0</is_required>
|
||||
<is_searchable>1</is_searchable>
|
||||
<is_search_range>0</is_search_range>
|
||||
<weight>174</weight>
|
||||
<is_active>1</is_active>
|
||||
<is_view>0</is_view>
|
||||
<text_length>255</text_length>
|
||||
<note_columns>60</note_columns>
|
||||
<note_rows>4</note_rows>
|
||||
<option_group_name>election_options</option_group_name>
|
||||
</CustomField>
|
||||
<CustomField>
|
||||
<custom_group_name>Voter_Info</custom_group_name>
|
||||
<name>Elections_2008</name>
|
||||
<label>Elections 2008</label>
|
||||
<column_name>elections_2008</column_name>
|
||||
<data_type>String</data_type>
|
||||
<html_type>CheckBox</html_type>
|
||||
<default_value>Array</default_value>
|
||||
<is_required>0</is_required>
|
||||
<is_searchable>1</is_searchable>
|
||||
<is_search_range>0</is_search_range>
|
||||
<weight>176</weight>
|
||||
<is_active>1</is_active>
|
||||
<is_view>0</is_view>
|
||||
<text_length>255</text_length>
|
||||
<note_columns>60</note_columns>
|
||||
<note_rows>4</note_rows>
|
||||
<option_group_name>election_options</option_group_name>
|
||||
</CustomField>
|
||||
<CustomField>
|
||||
<custom_group_name>Voter_Info</custom_group_name>
|
||||
<name>Elections_2007</name>
|
||||
<label>Elections 2007</label>
|
||||
<column_name>elections_2007</column_name>
|
||||
<data_type>String</data_type>
|
||||
<html_type>CheckBox</html_type>
|
||||
<default_value>Array</default_value>
|
||||
<is_required>0</is_required>
|
||||
<is_searchable>1</is_searchable>
|
||||
<is_search_range>0</is_search_range>
|
||||
<weight>178</weight>
|
||||
<is_active>1</is_active>
|
||||
<is_view>0</is_view>
|
||||
<text_length>255</text_length>
|
||||
<note_columns>60</note_columns>
|
||||
<note_rows>4</note_rows>
|
||||
<option_group_name>election_options</option_group_name>
|
||||
</CustomField>
|
||||
<CustomField>
|
||||
<custom_group_name>Voter_Info</custom_group_name>
|
||||
<name>Elections_2006</name>
|
||||
<label>Elections 2006</label>
|
||||
<column_name>elections_2006</column_name>
|
||||
<data_type>String</data_type>
|
||||
<html_type>CheckBox</html_type>
|
||||
<default_value>Array</default_value>
|
||||
<is_required>0</is_required>
|
||||
<is_searchable>1</is_searchable>
|
||||
<is_search_range>0</is_search_range>
|
||||
<weight>180</weight>
|
||||
<is_active>1</is_active>
|
||||
<is_view>0</is_view>
|
||||
<text_length>255</text_length>
|
||||
<note_columns>60</note_columns>
|
||||
<note_rows>4</note_rows>
|
||||
<option_group_name>election_options</option_group_name>
|
||||
</CustomField>
|
||||
<CustomField>
|
||||
<custom_group_name>Voter_Info</custom_group_name>
|
||||
<name>Elections_2005</name>
|
||||
<label>Elections 2005</label>
|
||||
<column_name>elections_2005</column_name>
|
||||
<data_type>String</data_type>
|
||||
<html_type>CheckBox</html_type>
|
||||
<default_value>Array</default_value>
|
||||
<is_required>0</is_required>
|
||||
<is_searchable>1</is_searchable>
|
||||
<is_search_range>0</is_search_range>
|
||||
<weight>182</weight>
|
||||
<is_active>1</is_active>
|
||||
<is_view>0</is_view>
|
||||
<text_length>255</text_length>
|
||||
<note_columns>60</note_columns>
|
||||
<note_rows>4</note_rows>
|
||||
<option_group_name>election_options</option_group_name>
|
||||
</CustomField>
|
||||
<CustomField>
|
||||
<custom_group_name>Voter_Info</custom_group_name>
|
||||
<name>Date_of_Voter_Data</name>
|
||||
<label>Date of Voter Data</label>
|
||||
<column_name>date_of_voter_data</column_name>
|
||||
<data_type>Date</data_type>
|
||||
<html_type>Select Date</html_type>
|
||||
<is_required>0</is_required>
|
||||
<is_searchable>1</is_searchable>
|
||||
<is_search_range>1</is_search_range>
|
||||
<weight>183</weight>
|
||||
<is_active>1</is_active>
|
||||
<is_view>0</is_view>
|
||||
<text_length>255</text_length>
|
||||
<date_format>M:;:;:;d:;:;:;Y</date_format>
|
||||
<note_columns>60</note_columns>
|
||||
<note_rows>4</note_rows>
|
||||
</CustomField>
|
||||
</CustomFields>
|
||||
<OptionGroups>
|
||||
<OptionGroup>
|
||||
<name>voter_history_options</name>
|
||||
<title>Voter History Options</title>
|
||||
<is_active>1</is_active>
|
||||
</OptionGroup>
|
||||
<OptionGroup>
|
||||
<name>county_name_options</name>
|
||||
<title>County Name Options</title>
|
||||
<is_active>1</is_active>
|
||||
</OptionGroup>
|
||||
<OptionGroup>
|
||||
<name>party_registration_options</name>
|
||||
<title>Party Registration Options</title>
|
||||
<is_active>1</is_active>
|
||||
</OptionGroup>
|
||||
<OptionGroup>
|
||||
<name>election_options</name>
|
||||
<title>Election Options</title>
|
||||
<is_active>1</is_active>
|
||||
</OptionGroup>
|
||||
|
||||
</OptionGroups>
|
||||
<OptionValues>
|
||||
<OptionValue>
|
||||
<label>A</label>
|
||||
<value>A</value>
|
||||
<is_default>0</is_default>
|
||||
<weight>1</weight>
|
||||
<is_optgroup>0</is_optgroup>
|
||||
<is_reserved>0</is_reserved>
|
||||
<is_active>1</is_active>
|
||||
<option_group_name>voter_history_options</option_group_name>
|
||||
</OptionValue>
|
||||
<OptionValue>
|
||||
<label>O</label>
|
||||
<value>O</value>
|
||||
<is_default>0</is_default>
|
||||
<weight>2</weight>
|
||||
<is_optgroup>0</is_optgroup>
|
||||
<is_reserved>0</is_reserved>
|
||||
<is_active>1</is_active>
|
||||
<option_group_name>voter_history_options</option_group_name>
|
||||
</OptionValue>
|
||||
<OptionValue>
|
||||
<label>N</label>
|
||||
<value>N</value>
|
||||
<is_default>0</is_default>
|
||||
<weight>3</weight>
|
||||
<is_optgroup>0</is_optgroup>
|
||||
<is_reserved>0</is_reserved>
|
||||
<is_active>1</is_active>
|
||||
<option_group_name>voter_history_options</option_group_name>
|
||||
</OptionValue>
|
||||
<OptionValue>
|
||||
<label>Democrat</label>
|
||||
<value>Democrat</value>
|
||||
<is_default>0</is_default>
|
||||
<weight>1</weight>
|
||||
<is_optgroup>0</is_optgroup>
|
||||
<is_reserved>0</is_reserved>
|
||||
<is_active>1</is_active>
|
||||
<option_group_name>party_registration_options</option_group_name>
|
||||
</OptionValue>
|
||||
<OptionValue>
|
||||
<label>Republican</label>
|
||||
<value>Republican</value>
|
||||
<is_default>0</is_default>
|
||||
<weight>2</weight>
|
||||
<is_optgroup>0</is_optgroup>
|
||||
<is_reserved>0</is_reserved>
|
||||
<is_active>1</is_active>
|
||||
<option_group_name>party_registration_options</option_group_name>
|
||||
</OptionValue>
|
||||
<OptionValue>
|
||||
<label>Green</label>
|
||||
<value>Green</value>
|
||||
<is_default>0</is_default>
|
||||
<weight>3</weight>
|
||||
<is_optgroup>0</is_optgroup>
|
||||
<is_reserved>0</is_reserved>
|
||||
<is_active>1</is_active>
|
||||
<option_group_name>party_registration_options</option_group_name>
|
||||
</OptionValue>
|
||||
<OptionValue>
|
||||
<label>Libertarian</label>
|
||||
<value>Libertarian</value>
|
||||
<is_default>0</is_default>
|
||||
<weight>5</weight>
|
||||
<is_optgroup>0</is_optgroup>
|
||||
<is_reserved>0</is_reserved>
|
||||
<is_active>1</is_active>
|
||||
<option_group_name>party_registration_options</option_group_name>
|
||||
</OptionValue>
|
||||
<OptionValue>
|
||||
<label>Other</label>
|
||||
<value>Other</value>
|
||||
<is_default>0</is_default>
|
||||
<weight>7</weight>
|
||||
<is_optgroup>0</is_optgroup>
|
||||
<is_reserved>0</is_reserved>
|
||||
<is_active>1</is_active>
|
||||
<option_group_name>party_registration_options</option_group_name>
|
||||
</OptionValue>
|
||||
<OptionValue>
|
||||
<label>Undeclared</label>
|
||||
<value>Undeclared</value>
|
||||
<is_default>0</is_default>
|
||||
<weight>6</weight>
|
||||
<is_optgroup>0</is_optgroup>
|
||||
<is_reserved>0</is_reserved>
|
||||
<is_active>1</is_active>
|
||||
<option_group_name>party_registration_options</option_group_name>
|
||||
</OptionValue>
|
||||
<OptionValue>
|
||||
<label>Independent</label>
|
||||
<value>Independent</value>
|
||||
<is_default>0</is_default>
|
||||
<weight>4</weight>
|
||||
<is_optgroup>0</is_optgroup>
|
||||
<is_reserved>0</is_reserved>
|
||||
<is_active>1</is_active>
|
||||
<option_group_name>party_registration_options</option_group_name>
|
||||
</OptionValue>
|
||||
<OptionValue>
|
||||
<label>add county here</label>
|
||||
<value>add county here</value>
|
||||
<is_default>0</is_default>
|
||||
<weight>2</weight>
|
||||
<is_optgroup>0</is_optgroup>
|
||||
<is_reserved>0</is_reserved>
|
||||
<is_active>1</is_active>
|
||||
<option_group_name>county_name_options</option_group_name>
|
||||
</OptionValue>
|
||||
<OptionValue>
|
||||
<option_group_name>election_options</option_group_name>
|
||||
<label>G - N</label>
|
||||
<value>GN</value>
|
||||
<name>G__N</name>
|
||||
<is_default>0</is_default>
|
||||
<weight>2</weight>
|
||||
<is_optgroup>0</is_optgroup>
|
||||
<is_reserved>0</is_reserved>
|
||||
<is_active>1</is_active>
|
||||
</OptionValue>
|
||||
<OptionValue>
|
||||
<option_group_name>election_options</option_group_name>
|
||||
<label>G - Y</label>
|
||||
<value>GY</value>
|
||||
<name>G__Y</name>
|
||||
<is_default>0</is_default>
|
||||
<weight>1</weight>
|
||||
<is_optgroup>0</is_optgroup>
|
||||
<is_reserved>0</is_reserved>
|
||||
<is_active>1</is_active>
|
||||
</OptionValue>
|
||||
<OptionValue>
|
||||
<option_group_name>election_options</option_group_name>
|
||||
<label>P - N</label>
|
||||
<value>PN</value>
|
||||
<name>P__N</name>
|
||||
<is_default>0</is_default>
|
||||
<weight>4</weight>
|
||||
<is_optgroup>0</is_optgroup>
|
||||
<is_reserved>0</is_reserved>
|
||||
<is_active>1</is_active>
|
||||
</OptionValue>
|
||||
<OptionValue>
|
||||
<option_group_name>election_options</option_group_name>
|
||||
<label>P - Y</label>
|
||||
<value>PY</value>
|
||||
<name>P__Y</name>
|
||||
<is_default>0</is_default>
|
||||
<weight>3</weight>
|
||||
<is_optgroup>0</is_optgroup>
|
||||
<is_reserved>0</is_reserved>
|
||||
<is_active>1</is_active>
|
||||
</OptionValue>
|
||||
<OptionValue>
|
||||
<option_group_name>election_options</option_group_name>
|
||||
<label>PP - N</label>
|
||||
<value>PPN</value>
|
||||
<name>PP__N</name>
|
||||
<is_default>0</is_default>
|
||||
<weight>6</weight>
|
||||
<is_optgroup>0</is_optgroup>
|
||||
<is_reserved>0</is_reserved>
|
||||
<is_active>1</is_active>
|
||||
</OptionValue>
|
||||
<OptionValue>
|
||||
<option_group_name>election_options</option_group_name>
|
||||
<label>PP - Y</label>
|
||||
<value>PPY</value>
|
||||
<name>PP__Y</name>
|
||||
<is_default>0</is_default>
|
||||
<weight>5</weight>
|
||||
<is_optgroup>0</is_optgroup>
|
||||
<is_reserved>0</is_reserved>
|
||||
<is_active>1</is_active>
|
||||
</OptionValue>
|
||||
<OptionValue>
|
||||
<option_group_name>election_options</option_group_name>
|
||||
<label>S - N</label>
|
||||
<value>SN</value>
|
||||
<name>S__N</name>
|
||||
<is_default>0</is_default>
|
||||
<weight>8</weight>
|
||||
<is_optgroup>0</is_optgroup>
|
||||
<is_reserved>0</is_reserved>
|
||||
<is_active>1</is_active>
|
||||
</OptionValue>
|
||||
<OptionValue>
|
||||
<option_group_name>election_options</option_group_name>
|
||||
<label>S - Y</label>
|
||||
<value>SY</value>
|
||||
<name>S__Y</name>
|
||||
<is_default>0</is_default>
|
||||
<weight>7</weight>
|
||||
<is_optgroup>0</is_optgroup>
|
||||
<is_reserved>0</is_reserved>
|
||||
<is_active>1</is_active>
|
||||
</OptionValue>
|
||||
</OptionValues>
|
||||
<ProfileGroups>
|
||||
<ProfileGroup>
|
||||
<is_active>1</is_active>
|
||||
<group_type>Individual</group_type>
|
||||
<title>Update Voter Info</title>
|
||||
<add_captcha>0</add_captcha>
|
||||
<is_map>0</is_map>
|
||||
<is_edit_link>0</is_edit_link>
|
||||
<is_uf_link>0</is_uf_link>
|
||||
<is_update_dupe>0</is_update_dupe>
|
||||
<is_cms_user>0</is_cms_user>
|
||||
<name>update_voter_info</name>
|
||||
</ProfileGroup>
|
||||
</ProfileGroups>
|
||||
<ProfileFields>
|
||||
<ProfileField>
|
||||
<field_name>custom.civicrm_value_voter_info.party_registration</field_name>
|
||||
<is_active>1</is_active>
|
||||
<is_view>0</is_view>
|
||||
<is_required>0</is_required>
|
||||
<weight>2</weight>
|
||||
<help_post></help_post>
|
||||
<visibility>User and User Admin Only</visibility>
|
||||
<in_selector>0</in_selector>
|
||||
<is_searchable>0</is_searchable>
|
||||
<label>Party Registration</label>
|
||||
<field_type>Individual</field_type>
|
||||
<profile_group_name>update_voter_info</profile_group_name>
|
||||
</ProfileField>
|
||||
<ProfileField>
|
||||
<field_name>custom.civicrm_value_voter_info.voter_history</field_name>
|
||||
<is_active>1</is_active>
|
||||
<is_view>0</is_view>
|
||||
<is_required>0</is_required>
|
||||
<weight>3</weight>
|
||||
<help_post>A - Always
|
||||
O - Occasional
|
||||
N - New</help_post>
|
||||
<visibility>User and User Admin Only</visibility>
|
||||
<in_selector>0</in_selector>
|
||||
<is_searchable>0</is_searchable>
|
||||
<label>Voter History</label>
|
||||
<field_type>Individual</field_type>
|
||||
<profile_group_name>update_voter_info</profile_group_name>
|
||||
</ProfileField>
|
||||
<ProfileField>
|
||||
<field_name>custom.civicrm_value_voter_info.county_name</field_name>
|
||||
<is_active>1</is_active>
|
||||
<is_view>0</is_view>
|
||||
<is_required>0</is_required>
|
||||
<weight>1</weight>
|
||||
<help_post></help_post>
|
||||
<visibility>User and User Admin Only</visibility>
|
||||
<in_selector>0</in_selector>
|
||||
<is_searchable>0</is_searchable>
|
||||
<label>County Name</label>
|
||||
<field_type>Individual</field_type>
|
||||
<profile_group_name>update_voter_info</profile_group_name>
|
||||
</ProfileField>
|
||||
</ProfileFields>
|
||||
<ProfileJoins>
|
||||
<ProfileJoin>
|
||||
<is_active>1</is_active>
|
||||
<module>Profile</module>
|
||||
<weight>1</weight>
|
||||
<profile_group_name>update_voter_info</profile_group_name>
|
||||
</ProfileJoin>
|
||||
</ProfileJoins>
|
||||
</CustomData>
|
|
@ -0,0 +1,411 @@
|
|||
<?php
|
||||
/**
|
||||
* http://pastebin.com/U32jjBVu - D7 has renamed admin settings
|
||||
*/
|
||||
function civicrm_engage_admin_settings($form_state = NULL) {
|
||||
$form['last_donate'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('CiviEngage Walklist Last Donate presentation'),
|
||||
'#weight' => 0,
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => FALSE,
|
||||
);
|
||||
$form['last_donate']['civicrm_engage_no_canvas_period'] = array(
|
||||
'#title' => t("Exclusion Period"),
|
||||
'#type' => 'textfield',
|
||||
'#description' => t('If you wish to leave someone alone for a period after their last donation please enter it here (in months). 0 means disabled'),
|
||||
'#default_value' => variable_get('civicrm_engage_no_canvas_period', "0"),
|
||||
);
|
||||
$form['last_donate']['civicrm_engage_no_canvass_text'] = array(
|
||||
'#title' => t("Text when within exclusion period"),
|
||||
'#type' => 'textfield',
|
||||
'#description' => t('Text to put in if contact not to be canvassed'),
|
||||
'#default_value' => variable_get('civicrm_engage_no_canvass_text', "Do Not Canvass"),
|
||||
);
|
||||
$form['break_settings'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('CiviEngage Walklist data grouping'),
|
||||
'#weight' => 0,
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => FALSE,
|
||||
);
|
||||
$form['break_settings']['civicrm_engage_groupbreak_odd_even'] = array(
|
||||
'#title' => t("Group break on odds / evens"),
|
||||
'#type' => 'checkbox',
|
||||
'#description' => t('Do you want a group-break between each side of the street'),
|
||||
'#default_value' => variable_get('civicrm_engage_groupbreak_odd_even', "1"),
|
||||
);
|
||||
$form['break_settings']['civicrm_engage_groupbreak_street'] = array(
|
||||
'#title' => t("Group break on street"),
|
||||
'#type' => 'checkbox',
|
||||
'#description' => t('Do you want a group-break between each street'),
|
||||
'#default_value' => variable_get('civicrm_engage_groupbreak_street', "1"),
|
||||
);
|
||||
$form['break_settings']['civicrm_engage_groupbreak_city'] = array(
|
||||
'#title' => t("Group break on city"),
|
||||
'#type' => 'checkbox',
|
||||
'#description' => t('Do you want a group-break between each city'),
|
||||
'#default_value' => variable_get('civicrm_engage_groupbreak_city', "1"),
|
||||
);
|
||||
$form['break_settings']['civicrm_engage_groupbreak_zip'] = array(
|
||||
'#title' => t("Group break on zip code"),
|
||||
'#type' => 'checkbox',
|
||||
'#description' => t('Do you want a group-break between each side of the street'),
|
||||
'#default_value' => variable_get('civicrm_engage_groupbreak_zip', "1"),
|
||||
);
|
||||
$form['break_settings']['civicrm_engage_lines_per_group'] = array(
|
||||
'#title' => t("Row limit per group"),
|
||||
'#type' => 'textfield',
|
||||
'#description' => t('Limit rows per group - ie. if you want to print out in blocks of 6'),
|
||||
'#default_value' => variable_get('civicrm_engage_lines_per_group', "6"),
|
||||
);
|
||||
$form['break_settings']['civicrm_engage_group_per_page'] = array(
|
||||
'#title' => t("New page for each group?"),
|
||||
'#type' => 'checkbox',
|
||||
'#description' => t('Do you want each group to have new page? (default is yes)'),
|
||||
'#default_value' => variable_get('civicrm_engage_group_per_page', "1"),
|
||||
);
|
||||
return system_settings_form($form);
|
||||
}
|
||||
|
||||
function civicrm_engage_admin_load_data($form_state = NULL) {
|
||||
$subtypes_added = NULL;
|
||||
if (civicrm_engage_subtypes_added()) {
|
||||
$subtypes_added = ' <em>' . t("It appears that the contact sub types are present.") . '</em>';
|
||||
}
|
||||
$custom_data_added = NULL;
|
||||
if (civicrm_engage_custom_data_added()) {
|
||||
$custom_data_added = ' <em>' . t("It appears that the custom data is present.") . '</em>';
|
||||
}
|
||||
$custom_voter_us_data_added = NULL;
|
||||
if (civicrm_engage_custom_voter_us_data_added()) {
|
||||
$custom_voter_us_data_added = ' <em>' . t("It appears that the US custom voter data is present.") . '</em>';
|
||||
}
|
||||
$address_parsing_enabled = NULL;
|
||||
if (civicrm_engage_address_parsing_enabled()) {
|
||||
$address_parsing_enabled = ' <em>' . t("It appears that address parsing is enabled.") . '</em>';
|
||||
}
|
||||
$autocomplete_options_set = NULL;
|
||||
if (civicrm_engage_autocomplete_options_set()) {
|
||||
$autocomplete_options_set = ' <em>' . t("It appears that the autocomplete options are properly set.") . '</em>';
|
||||
}
|
||||
$form['load_data'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('CiviEngage Load Data and Set Configuration Options'),
|
||||
'#weight' => 0,
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => FALSE,
|
||||
);
|
||||
|
||||
$form['load_data']['contact_subtypes'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Add contact subtypes'),
|
||||
'#description' => t("Civicrm Engage depends on the presence of a Media, Funder, Elected Official, Media Outlet and Foundation contact subtypes. Check this box to add them. This step is not reversible.") . $subtypes_added,
|
||||
);
|
||||
$form['load_data']['address_parsing'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Enable address parsing'),
|
||||
'#description' => t("Street parsing is required for walk lists because it needs to sort by even/odd address numbers.") . $address_parsing_enabled,
|
||||
);
|
||||
$form['load_data']['autocomplete_options'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Set phone to autocomplete'),
|
||||
'#description' => t("Autocomplete options double as indicator of whether a field should show up in batch update. For civicrm engage to work properly, phone should be set to autocomplete so it shows up in batch update.") . $autocomplete_options_set,
|
||||
);
|
||||
$form['load_data']['custom_data'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Add general custom groups, fields and other data'),
|
||||
'#description' => t("Civicrm Engage depends on a number of custom data groups and fields and profiles. Check this box to add them. This step is not reversible and will take several minutes to complete.") . $custom_data_added,
|
||||
);
|
||||
$form['load_data']['custom_voter_us_data'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Add US voter custom groups, fields and other data'),
|
||||
'#description' => t("Civicrm Engage depends on voter-related fields being imported (to track congressional district, city district, etc.). Current only US-specific voter fields are available.") . $custom_voter_us_data_added,
|
||||
);
|
||||
$form['load_data']['submit'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => 'Submit',
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
||||
function civicrm_engage_admin_load_data_submit($form, &$form_state) {
|
||||
if ($form_state['values']['contact_subtypes'] == 1) {
|
||||
civicrm_engage_load_contact_subtypes();
|
||||
}
|
||||
if ($form_state['values']['custom_data'] == 1) {
|
||||
civicrm_engage_load_custom_data();
|
||||
}
|
||||
if ($form_state['values']['custom_voter_us_data'] == 1) {
|
||||
civicrm_engage_load_custom_voter_us_data();
|
||||
}
|
||||
if ($form_state['values']['address_parsing'] == 1) {
|
||||
civicrm_engage_enable_address_parsing();
|
||||
}
|
||||
if ($form_state['values']['autocomplete_options'] == 1) {
|
||||
civicrm_engage_set_autocomplete_options();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if the subtypes have already been added.
|
||||
*/
|
||||
function civicrm_engage_subtypes_added() {
|
||||
civicrm_initialize();
|
||||
require_once "CRM/Contact/BAO/ContactType.php";
|
||||
$existing_types = CRM_Contact_BAO_ContactType::subTypeInfo();
|
||||
if (array_key_exists('Media_Outlet', $existing_types)) {
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if the custom data has already been added.
|
||||
*/
|
||||
function civicrm_engage_custom_data_added() {
|
||||
civicrm_initialize();
|
||||
$sql = "SELECT is_active FROM civicrm_uf_group WHERE name = 'update_constituent_info'";
|
||||
$dao = CRM_Core_DAO::executeQuery($sql);
|
||||
$dao->fetch();
|
||||
if (!property_exists($dao, 'is_active')) {
|
||||
return FALSE;
|
||||
}
|
||||
if ($dao->is_active == 1) {
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if the custom voter us data has already been added.
|
||||
*/
|
||||
function civicrm_engage_custom_voter_us_data_added() {
|
||||
civicrm_initialize();
|
||||
$sql = "SELECT is_active FROM civicrm_uf_group WHERE name = 'update_voter_info'";
|
||||
$dao = CRM_Core_DAO::executeQuery($sql);
|
||||
$dao->fetch();
|
||||
if (!property_exists($dao, 'is_active')) {
|
||||
return FALSE;
|
||||
}
|
||||
if ($dao->is_active == 1) {
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create contact subtypes which are referenced in the
|
||||
* xml file that is imported to boostrap the CiviCRM
|
||||
* Campaign component. This function is indempotent, so
|
||||
* it's run on enable.
|
||||
*/
|
||||
function civicrm_engage_load_contact_subtypes() {
|
||||
// parent_id : 1 is Individual, 3 is Organization
|
||||
$create = array(
|
||||
'Media_Contact' => array(
|
||||
'label' => 'Media Contact',
|
||||
'parent_id' => 1,
|
||||
'is_active' => 1,
|
||||
'name' => 'Media_Contact',
|
||||
),
|
||||
'Funder_Contact' => array(
|
||||
'label' => 'Funder Contact',
|
||||
'parent_id' => 1,
|
||||
'is_active' => 1,
|
||||
'name' => 'Funder_Contact',
|
||||
),
|
||||
'Elected_Official' => array(
|
||||
'label' => 'Elected Official',
|
||||
'parent_id' => 1,
|
||||
'is_active' => 1,
|
||||
'name' => 'Elected_Official',
|
||||
),
|
||||
'Media_Outlet' => array(
|
||||
'label' => 'Media Outlet',
|
||||
'parent_id' => 3,
|
||||
'is_active' => 1,
|
||||
'name' => 'Media_Outlet',
|
||||
),
|
||||
'Foundation' => array(
|
||||
'label' => 'Foundation',
|
||||
'parent_id' => 3,
|
||||
'is_active' => 1,
|
||||
'name' => 'Foundation',
|
||||
),
|
||||
);
|
||||
require_once "CRM/Contact/BAO/ContactType.php";
|
||||
$existing_types = CRM_Contact_BAO_ContactType::subTypeInfo();
|
||||
while (list($k) = each($existing_types)) {
|
||||
if (array_key_exists($k, $create)) {
|
||||
drupal_set_message(t("Not creating @type, already exists.", array("@type" => $k)));
|
||||
unset($create[$k]);
|
||||
}
|
||||
}
|
||||
$contact_type = new CRM_Contact_BAO_ContactType();
|
||||
while (list($k, $v) = each($create)) {
|
||||
drupal_set_message(t("Creating %c", array('%c' => $k)));
|
||||
$contact_type->add($v);
|
||||
}
|
||||
}
|
||||
|
||||
function civicrm_engage_load_custom_data() {
|
||||
drupal_set_message("Loading default civicrm_engage custom data.");
|
||||
$xml_file = civicrm_engage_get_absolute_module_path() . '/CustomGroupData.xml';
|
||||
require_once 'CRM/Utils/Migrate/Import.php';
|
||||
$import = new CRM_Utils_Migrate_Import();
|
||||
$import->run($xml_file);
|
||||
|
||||
// The xml file sets up a field with a contact reference limited to the staff
|
||||
// group (staff responsible). So, we have to make sure the staff group exists
|
||||
// and if not create it and update the id number in the staff responsible
|
||||
// field definition.
|
||||
drupal_set_message("Creating staff group.");
|
||||
return civicrm_engage_load_staff_group();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create group that will be used to populate the responsible
|
||||
* staff custom data field.
|
||||
*/
|
||||
function civicrm_engage_load_staff_group() {
|
||||
// Record the id of the group we create so we can ensure that the
|
||||
// staff responsible contact reference field is restricted to the
|
||||
// right group.
|
||||
$id = NULL;
|
||||
try {
|
||||
// Check if it exists already
|
||||
$params = array('name' => 'staff');
|
||||
$result = civicrm_api3('Group', 'Get', $params);
|
||||
if ($result['count'] > 0) {
|
||||
// We already have the group in place.
|
||||
drupal_set_message(t("Staff group already exists."));
|
||||
$row = array_pop($result['values']);
|
||||
$id = $row['id'];
|
||||
}
|
||||
else {
|
||||
// Otherwise, we have to add it.
|
||||
$params = array(
|
||||
'name' => 'staff',
|
||||
'title' => 'Staff',
|
||||
'description' => 'Contacts in this group are used to populate the staff responsible field.',
|
||||
'is_active' => 1,
|
||||
'group_type' => '2',
|
||||
'is_hidden' => '0',
|
||||
'is_reserved' => '0',
|
||||
);
|
||||
$result = civicrm_api3('Group', 'create', $params);
|
||||
drupal_set_message(t("Staff group created."));
|
||||
$row = array_pop($result['values']);
|
||||
$id = $row['id'];
|
||||
}
|
||||
if ($id) {
|
||||
$sql = "UPDATE civicrm_custom_field SET filter = 'action=lookup&group=%0' WHERE
|
||||
name = 'staff_responsible' OR name = 'event_contact_person'";
|
||||
$params = array(
|
||||
0 => array($id, 'Integer'),
|
||||
);
|
||||
CRM_Core_DAO::executeQuery($sql, $params);
|
||||
}
|
||||
}
|
||||
catch (CiviCRM_API3_Exception $e) {
|
||||
drupal_set_message(t("Failed to load staff group."));
|
||||
drupal_set_message($e->getMessage());
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
function civicrm_engage_load_custom_voter_us_data() {
|
||||
drupal_set_message("Loading default civicrm_engage US custom voter data.");
|
||||
$xml_file = civicrm_engage_get_absolute_module_path() . '/Voter.us.xml';
|
||||
require_once 'CRM/Utils/Migrate/Import.php';
|
||||
$import = new CRM_Utils_Migrate_Import();
|
||||
$import->run($xml_file);
|
||||
}
|
||||
|
||||
function civicrm_engage_address_parsing_enabled() {
|
||||
civicrm_initialize();
|
||||
include_once 'CRM/Core/BAO/Setting.php';
|
||||
$address_options = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
|
||||
'address_options',
|
||||
TRUE, NULL, TRUE
|
||||
);
|
||||
if ($address_options['street_address_parsing'] == 1) {
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper file to get path to civicrm_engage directory
|
||||
*/
|
||||
function civicrm_engage_get_absolute_module_path() {
|
||||
// we need to build the path to the Voter.us.xml file
|
||||
// shipped in the civicrm_engage directory. civicrm_engage could
|
||||
// be installed outside of the civicrm root, so we can't rely on
|
||||
// that contstant.
|
||||
|
||||
// instead... start with the drupal root
|
||||
$root = getcwd();
|
||||
// and then added the relative path to the module
|
||||
return $root . '/' . drupal_get_path('module', 'civicrm_engage');
|
||||
}
|
||||
|
||||
/**
|
||||
* Street parsing is required for walk lists because it needs to
|
||||
* sort by even/odd address numbers so, when canvassing a street
|
||||
* in which even addresses are on one side and odd on the other, you
|
||||
* can divide the task between two people with two different lists.
|
||||
*/
|
||||
function civicrm_engage_enable_address_parsing() {
|
||||
civicrm_initialize();
|
||||
include_once 'CRM/Core/BAO/Setting.php';
|
||||
$address_options = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
|
||||
'address_options',
|
||||
TRUE, NULL, TRUE
|
||||
);
|
||||
$address_options['street_address_parsing'] = 1;
|
||||
CRM_Core_BAO_Setting::setValueOption(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
|
||||
'address_options',
|
||||
$address_options
|
||||
);
|
||||
drupal_set_message("Addressing parsing options saved.");
|
||||
}
|
||||
|
||||
function civicrm_engage_autocomplete_options_set() {
|
||||
civicrm_initialize();
|
||||
include_once 'CRM/Core/BAO/Setting.php';
|
||||
$contact_autocomplete_options = CRM_Core_BAO_Setting::valueOptions(
|
||||
CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
|
||||
'contact_autocomplete_options',
|
||||
TRUE, NULL, TRUE
|
||||
);
|
||||
if ($contact_autocomplete_options['phone'] == 1) {
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Phone Number for auto complete. This setting doubles for batch
|
||||
* update, and when making a phone list in CiviCampaign you really need
|
||||
* to have the phone number included.
|
||||
*/
|
||||
function civicrm_engage_set_autocomplete_options() {
|
||||
civicrm_initialize();
|
||||
include_once 'CRM/Core/BAO/Setting.php';
|
||||
$contact_autocomplete_options = CRM_Core_BAO_Setting::valueOptions(
|
||||
CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
|
||||
'contact_autocomplete_options',
|
||||
TRUE, NULL, TRUE
|
||||
);
|
||||
$contact_autocomplete_options['phone'] = 1;
|
||||
CRM_Core_BAO_Setting::setValueOption(
|
||||
CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
|
||||
'contact_autocomplete_options',
|
||||
$contact_autocomplete_options
|
||||
);
|
||||
drupal_set_message(t("Autocomplete options have been saved."));
|
||||
}
|
10
sites/all/modules/civicrm/drupal/modules/civicrm_engage/civicrm_engage.info
Executable file
10
sites/all/modules/civicrm/drupal/modules/civicrm_engage/civicrm_engage.info
Executable file
|
@ -0,0 +1,10 @@
|
|||
name = CiviEngage
|
||||
description = Walklist and Phone-banking support for CiviCRM.
|
||||
version = 7.x-4.7.29
|
||||
core = 7.x
|
||||
package = CiviCRM
|
||||
project = civicrm
|
||||
|
||||
dependencies[] = civicrm
|
||||
|
||||
files[] = civicrm_engage.module
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_enable().
|
||||
*/
|
||||
function civicrm_engage_enable() {
|
||||
db_query("UPDATE {system} SET weight = 110 WHERE name = 'civicrm_engage'");
|
||||
$url = url('admin/config/civicrm/civicrm_engage');
|
||||
drupal_set_message(t('CiviCRM Engage must be <a href="@url">configured</a> before it will work properly.', array('@url' => $url)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix the Participant Role field in the Update Event Invite Responses
|
||||
*/
|
||||
function civicrm_engage_update_7001() {
|
||||
civicrm_initialize();
|
||||
$sql = "UPDATE civicrm_uf_field SET field_name = 'participant_role' WHERE " .
|
||||
"field_name = 'participant_role_id' AND uf_group_id IN (SELECT id FROM " .
|
||||
"civicrm_uf_group WHERE name = 'update_event_invite_responses') ";
|
||||
CRM_Core_DAO::executeQuery($sql);
|
||||
}
|
|
@ -0,0 +1,246 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
define('CIVICRM_ENGAGE_CG_DEMOGRAPHICS_NAME', 'Demographics');
|
||||
define('CIVICRM_ENGAGE_DEMOGRAPHICS_PREFIX', 'demographics_');
|
||||
define('CIVICRM_ENGAGE_DEMOGRAPHICS_TITLE', 'Demographics');
|
||||
function _civicrm_engage_getCustomGroupID($customGroupName) {
|
||||
require_once 'CRM/Utils/Type.php';
|
||||
$customGroupName = CRM_Utils_Type::escape($customGroupName, 'String');
|
||||
return CRM_Core_DAO::getFieldValue("CRM_Core_DAO_CustomGroup", $customGroupName, 'id', 'name');
|
||||
}
|
||||
|
||||
function civicrm_engage_civicrm_buildForm($formName, &$form) {
|
||||
if ($formName == 'CRM_Contact_Form_Contact' || $formName == 'CRM_Contact_Form_Inline_Demographics') {
|
||||
$cgID = _civicrm_engage_getCustomGroupID(CIVICRM_ENGAGE_CG_DEMOGRAPHICS_NAME);
|
||||
if (empty($cgID)) {
|
||||
return;
|
||||
}
|
||||
$groupTree = CRM_Core_BAO_CustomGroup::getTree('Individual',
|
||||
NULL,
|
||||
$form->getVar('_contactId'),
|
||||
$cgID,
|
||||
NULL, NULL
|
||||
);
|
||||
|
||||
// we should use simplified formatted groupTree
|
||||
$groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, $form);
|
||||
|
||||
if (isset($groupTree) && is_array($groupTree)) {
|
||||
$defaults = array();
|
||||
CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $defaults);
|
||||
$form->setDefaults($defaults);
|
||||
|
||||
CRM_Core_BAO_CustomGroup::buildQuickForm($form, $groupTree, FALSE, CIVICRM_ENGAGE_DEMOGRAPHICS_PREFIX);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function civicrm_engage_civicrm_alterReportVar($varType, &$var, &$form) {
|
||||
$formName = get_class($form);
|
||||
if ($formName == 'CRM_Report_Form_Campaign_SurveyDetails') {
|
||||
if ($varType == 'columns') {
|
||||
$var['civicrm_contribution'] = array(
|
||||
'dao' => 'CRM_Contribute_DAO_Contribution',
|
||||
'fields' => array(
|
||||
'receive_date' => array(
|
||||
'title' => ts('Latest Contribution Date'),
|
||||
),
|
||||
'total_amount' => array(
|
||||
'title' => ts('Latest Contribution Amount'),
|
||||
),
|
||||
),
|
||||
'grouping' => 'survey-activity-fields',
|
||||
);
|
||||
}
|
||||
elseif ($varType == 'sql') {
|
||||
$params = $form->getVar('_params');
|
||||
if (CRM_Utils_Array::value('receive_date', $params['fields']) || CRM_Utils_Array::value('total_amount', $params['fields'])) {
|
||||
$var->_from .= "
|
||||
LEFT JOIN civicrm_contribution {$form->_aliases['civicrm_contribution']} ON ({$form->_aliases['civicrm_contribution']}.id = (select id from civicrm_contribution con where con.contact_id = {$form->_aliases['civicrm_contact']}.id ORDER BY con.receive_date DESC LIMIT 1 ))\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function civicrm_engage_civicrm_postProcess($class, &$form) {
|
||||
if (is_a($form, 'CRM_Contact_Form_Contact') || is_a($form, 'CRM_Contact_Form_Inline_Demographics')) {
|
||||
if (array_key_exists('_qf_Contact_refresh_dedupe', $form->_submitValues)) {
|
||||
// don't execute when checking for duplicates - it fails (CRM-8994)
|
||||
return;
|
||||
}
|
||||
else {
|
||||
$cgID = _civicrm_engage_getCustomGroupID(CIVICRM_ENGAGE_CG_DEMOGRAPHICS_NAME);
|
||||
if (empty($cgID)) {
|
||||
return;
|
||||
}
|
||||
$groupTree = CRM_Core_BAO_CustomGroup::getTree('Individual',
|
||||
NULL,
|
||||
$form->getVar('_contactId'),
|
||||
$cgID,
|
||||
NULL, NULL
|
||||
);
|
||||
|
||||
// we should use simplified formatted groupTree
|
||||
$groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, $form);
|
||||
|
||||
if (isset($groupTree) && is_array($groupTree)) {
|
||||
require_once 'CRM/Core/BAO/CustomValueTable.php';
|
||||
$params = $form->controller->exportValues($form->getVar('_name'));
|
||||
CRM_Core_BAO_CustomValueTable::postProcess($params,
|
||||
'civicrm_contact',
|
||||
$form->getVar('_contactId'),
|
||||
'Individual'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* The big picture is:
|
||||
* set our custom demographics group of fields to be a
|
||||
* tab; hide the tab; shove the fields into the core
|
||||
* Demographics display.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Alter the page as displayed on the contact summary
|
||||
* and inline demographics. This is the function where we
|
||||
* stick the custom demographics fields into the core
|
||||
* demographics displayed. It goes with the custom
|
||||
* Demographics.tpl file we are shipping.
|
||||
*/
|
||||
function civicrm_engage_civicrm_pageRun(&$page) {
|
||||
if ($page->getVar('_name') == 'CRM_Contact_Page_View_Summary' ||
|
||||
$page->getVar('_name') == 'CRM_Contact_Page_Inline_Demographics') {
|
||||
$cgID = _civicrm_engage_getCustomGroupID(CIVICRM_ENGAGE_CG_DEMOGRAPHICS_NAME);
|
||||
if (empty($cgID)) {
|
||||
return;
|
||||
}
|
||||
$contactId = $page->getVar('_contactId');
|
||||
if (empty($contactId)) {
|
||||
$contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE, NULL, $_REQUEST);
|
||||
}
|
||||
$groupTree = CRM_Core_BAO_CustomGroup::getTree('Individual',
|
||||
NULL,
|
||||
$contactId,
|
||||
$cgID,
|
||||
NULL, NULL
|
||||
);
|
||||
|
||||
CRM_Core_BAO_CustomGroup::buildCustomDataView($page,
|
||||
$groupTree,
|
||||
FALSE, NULL,
|
||||
CIVICRM_ENGAGE_DEMOGRAPHICS_PREFIX
|
||||
);
|
||||
|
||||
$cgID = _civicrm_engage_getCustomGroupID(CIVICRM_ENGAGE_CG_DEMOGRAPHICS_NAME);
|
||||
$page->assign('demographics_custom_group_id', $cgID);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide the custom demographics tab because we are handling
|
||||
* the custom demographics fields inline in the
|
||||
* civicrm_engage_civicrm_pageRun() function.
|
||||
*/
|
||||
function civicrm_engage_civicrm_tabs(&$tabs, $contactID) {
|
||||
foreach ($tabs as $tabID => $tabValue) {
|
||||
if ($tabValue['title'] == CIVICRM_ENGAGE_DEMOGRAPHICS_TITLE) {
|
||||
unset($tabs[$tabID]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function civicrm_engage_civicrm_config(&$config) {
|
||||
$engageRoot = dirname(__FILE__) . DIRECTORY_SEPARATOR;
|
||||
|
||||
// fix php include path
|
||||
$include_path = $engageRoot . PATH_SEPARATOR . get_include_path();
|
||||
set_include_path($include_path);
|
||||
|
||||
// fix template path
|
||||
$templateDir = $engageRoot . 'templates' . DIRECTORY_SEPARATOR;
|
||||
$template = CRM_Core_Smarty::singleton();
|
||||
if (is_array($template->template_dir)) {
|
||||
$template->template_dir = array_merge(array($templateDir), $template->template_dir);
|
||||
}
|
||||
else {
|
||||
$template->template_dir = array($templateDir, $template->template_dir);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_permission().
|
||||
*/
|
||||
function civicrm_engage_permission() {
|
||||
return array(
|
||||
'access civiengage settings' => array(
|
||||
'title' => t('Access CiviCRM engage setting'),
|
||||
'description' => t('Access CiviCRM engage setting.'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
function civicrm_engage_menu() {
|
||||
|
||||
$items['admin/config/civicrm/civicrm_engage'] = array(
|
||||
'title' => 'Civicrm engage settings',
|
||||
'description' => 'CiviCRM Engage Configuration',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('civicrm_engage_admin_settings'),
|
||||
'access arguments' => array('access civiengage settings'),
|
||||
'file' => 'civicrm_engage.admin.inc',
|
||||
);
|
||||
$items['admin/config/civicrm/civicrm_engage/settings'] = array(
|
||||
'title' => 'Civicrm engage settings',
|
||||
'description' => 'CiviCRM Engage Configuration',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('civicrm_engage_admin_settings'),
|
||||
'access arguments' => array('access civiengage settings'),
|
||||
'file' => 'civicrm_engage.admin.inc',
|
||||
'type' => MENU_DEFAULT_LOCAL_TASK,
|
||||
);
|
||||
$items['admin/config/civicrm/civicrm_engage/load-data'] = array(
|
||||
'title' => 'Civicrm engage load default data',
|
||||
'description' => 'CiviCRM Engage Load Data',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('civicrm_engage_admin_load_data'),
|
||||
'access arguments' => array('access civiengage settings'),
|
||||
'file' => 'civicrm_engage.admin.inc',
|
||||
'type' => MENU_LOCAL_TASK,
|
||||
);
|
||||
return $items;
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
Procedure to migrate database to CiviEngage format
|
||||
=====================================================
|
||||
1. After the db has been upgraded, import migrate/custom_groups_fields.sql file to -
|
||||
|
||||
A. For all $customGroups in DB2
|
||||
if ( $customGroups IS ONE OF standard custom group generated by xml )
|
||||
=> Fix table_name column to remove $_id suffix;
|
||||
|
||||
B. For all $customFields in DB2
|
||||
if ( $customFields IS ONE OF standard custom field generated by xml )
|
||||
=> Fix column_name column to remove $_id suffix;
|
||||
|
||||
C. Fix columns and tables which does not match even after removing $_id suffix.
|
||||
|
||||
Note above steps don't do any thing to structure / data of custom_value_*_id tables.
|
||||
|
||||
2. Import migrate/custom_tables.sql file to copy standard custom_value_* tables to the db. After importing the file, the db will have two different sets of tables -
|
||||
custom_value_* tables,
|
||||
custom_value_*_$id tables.
|
||||
|
||||
3. Import migrate/custom_data.sql file (after reading the note below) to -
|
||||
|
||||
A. Migrate data from custom "custom_value_*_$id" -to-> "custom_value_*" tables.
|
||||
|
||||
B. Migrate core data from "custom_value_*_$id" tables to contact core fields.
|
||||
|
||||
C. Migrate columns to be retained with data, from "custom_value_*_$id" -to-> "custom_value_*" tables.
|
||||
|
||||
B. Drop old "custom_value_*" tables at the end.
|
||||
|
||||
Note: Above script uses hard-coded old column and table names. Please verify these names and adjust if required before importing.
|
||||
|
||||
4. Import migrate/profiles.sql to re-create all standard profiles. Note rest of the extra profile's fields will need to be updated manually, to match with migrated custom groups and fields.
|
|
@ -0,0 +1,69 @@
|
|||
-- data migration from old custom tables to new
|
||||
|
||||
insert into civicrm_value_source_details (select * from civicrm_value_activity_source_details_18);
|
||||
|
||||
insert into civicrm_value_communication_details ( select * from civicrm_value_communication_details_19 );
|
||||
|
||||
insert into civicrm_value_contact_info (select * from civicrm_value_contact_info_6);
|
||||
|
||||
insert into civicrm_value_contribution_source (select * from civicrm_value_contribution_source_11);
|
||||
|
||||
insert into civicrm_value_door_knock_responses (select * from civicrm_value_door_knock_responses_12);
|
||||
|
||||
insert into civicrm_value_event_campaign_details (select * from civicrm_value_event_campaign_details_20);
|
||||
|
||||
insert into civicrm_value_grant_info (select * from civicrm_value_grant_info_7);
|
||||
|
||||
insert into civicrm_value_leadership_level (entity_id, leadership_level) (select entity_id, leadership_level_23 from civicrm_value_leadership_level_5);
|
||||
|
||||
insert into civicrm_value_participant_info (entity_id, childcare_needed, ride_to, ride_back, reminder_date, invitation_date, contact_attended, invitation_response, reminder_response, participant_campaign_code, second_call_date, second_call_response) (select entity_id, childcare_needed_42, ride_to_43, ride_back_44, reminderdate_86, invitation_date_90, contact_attended__91, invitation_response_92, reminder_response_93, participant_campaign_code_128, second_call_date_129, second_call_response_130 from civicrm_value_participant_info_10);
|
||||
|
||||
insert into civicrm_value_phone_bank_responses (select * from civicrm_value_phone_bank_responses_14);
|
||||
|
||||
insert into civicrm_value_primary_contact (select * from civicrm_value_primary_contact_1);
|
||||
|
||||
insert into civicrm_value_proposal_info (select * from civicrm_value_proposal_info_8);
|
||||
|
||||
insert into civicrm_value_voter_info (entity_id, precinct, state_district, city_district, federal_district, party_registration, if_other_party, state_voter_id, voted_in_2008_general_election, voted_in_2008_primary_election, voter_history, county_name )
|
||||
(select entity_id, precinct_5, state_district_6, city_district_7, federal_district_8, party_registration_16, if_other_party__17, state_voter_id_18, voted_in_2008_general_election__24, voted_in_2008_primary_election__25, voter_history_75, county_89 from civicrm_value_voter_info_2);
|
||||
|
||||
insert into civicrm_value_event_details (entity_id, event_contact_person, event_source_code)
|
||||
(select entity_id, event_contact_person_95, event_source_code_105 from civicrm_value_event_details_16);
|
||||
|
||||
alter table civicrm_value_grassroots_info
|
||||
add column `ehc_board_and_staff` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
add column `ehc_campaign` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL;
|
||||
|
||||
insert into civicrm_value_grassroots_info (entity_id, leadership_level, issues_interest, volunteer_interests, member_status, ehc_board_and_staff, ehc_campaign)
|
||||
(select entity_id, leadership_level_12 ,issues_interest_34, volunteer_interests_35, member_status_76, ehc_board_and_staff_113, ehc_campaign_133 from civicrm_value_grassroots_info_4);
|
||||
|
||||
insert into civicrm_value_demographics (entity_id, ethnicity, primary_language, secondary_language, kids)
|
||||
(select entity_id, ethnicity_19, primary_language_20, secondary_language_106, kids__21 from civicrm_value_demographics_3);
|
||||
|
||||
insert into civicrm_value_core_info (entity_id, constituent_type, staff_responsible, date_started, other_name, how_started)
|
||||
(select entity_id, contact_type_13, staff_responsible_22, date_started_57, other_name_72, how_started_73 from civicrm_value_demographics_3);
|
||||
|
||||
alter table civicrm_value_grassroots_info
|
||||
add column `other_affiliation` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
add column `toxinformer_flag` tinyint(4) DEFAULT NULL,
|
||||
add column `community` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
add column `owner_or_renter` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL;
|
||||
|
||||
insert into civicrm_value_grassroots_info (entity_id, other_affiliation, toxinformer_flag, community, owner_or_renter)
|
||||
(select entity_id, other_affiliation_108, toxinformer_flag_109, community_110, owner_or_renter_111 from civicrm_value_demographics_3)
|
||||
ON DUPLICATE KEY UPDATE other_affiliation=other_affiliation_108, toxinformer_flag=toxinformer_flag_109, community=community_110, owner_or_renter=owner_or_renter_111;
|
||||
|
||||
-- migrate gender and dob to contact tables
|
||||
update civicrm_contact cc
|
||||
inner join civicrm_value_demographics_3 demo on cc.id = demo.entity_id
|
||||
set cc.gender_id = IF(demo.gender_14 = 'Male', 2, IF(demo.gender_14 = 'Female', 1, NULL)),
|
||||
cc.birth_date = demo.dob_15,
|
||||
cc.postal_greeting_custom = demo.salutation_36,
|
||||
cc.postal_greeting_display = demo.salutation_36,
|
||||
cc.addressee_custom = demo.addressee_37,
|
||||
cc.addressee_display = demo.addressee_37,
|
||||
cc.email_greeting_custom = demo.email_salutation_38,
|
||||
cc.email_greeting_display = demo.email_salutation_38;
|
||||
|
||||
-- drop all successfully migrated custom tables
|
||||
DROP TABLE IF EXISTS `civicrm_value_activity_source_details_18`, `civicrm_value_communication_details_19`, `civicrm_value_contact_info_6`, `civicrm_value_contribution_source_11`, `civicrm_value_door_knock_responses_12`, `civicrm_value_event_campaign_details_20`, `civicrm_value_grant_info_7`, `civicrm_value_participant_info_10`, `civicrm_value_phone_bank_responses_14`, `civicrm_value_primary_contact_1`, `civicrm_value_proposal_info_8`, `civicrm_value_voter_info_2`, `civicrm_value_leadership_level_5`, `civicrm_value_demographics_3`, `civicrm_value_event_details_16`, `civicrm_value_grassroots_info_4`;
|
|
@ -0,0 +1,145 @@
|
|||
update civicrm_custom_group set table_name = replace(table_name, substring(table_name, - locate('_', reverse(table_name))), '')
|
||||
where replace(table_name, substring(table_name, - locate('_', reverse(table_name))), '')
|
||||
IN (
|
||||
'civicrm_value_primary_contact',
|
||||
'civicrm_value_voter_info',
|
||||
'civicrm_value_core_info',
|
||||
'civicrm_value_grassroots_info',
|
||||
'civicrm_value_leadership_level',
|
||||
'civicrm_value_contact_info',
|
||||
'civicrm_value_grant_info',
|
||||
'civicrm_value_proposal_info',
|
||||
'civicrm_value_participant_info',
|
||||
'civicrm_value_contribution_source',
|
||||
'civicrm_value_door_knock_responses',
|
||||
'civicrm_value_phone_bank_responses',
|
||||
'civicrm_value_event_details',
|
||||
'civicrm_value_source_details',
|
||||
'civicrm_value_activity_source_details',
|
||||
'civicrm_value_communication_details',
|
||||
'civicrm_value_event_campaign_details',
|
||||
'civicrm_value_organizational_details',
|
||||
'civicrm_value_demographics'
|
||||
);
|
||||
|
||||
update civicrm_custom_field set column_name = replace(column_name, substring(column_name, - locate('_', reverse(column_name))), '')
|
||||
where custom_group_id IN (select id from civicrm_custom_group where table_name IN (
|
||||
'civicrm_value_primary_contact',
|
||||
'civicrm_value_voter_info',
|
||||
'civicrm_value_core_info',
|
||||
'civicrm_value_grassroots_info',
|
||||
'civicrm_value_leadership_level',
|
||||
'civicrm_value_contact_info',
|
||||
'civicrm_value_grant_info',
|
||||
'civicrm_value_proposal_info',
|
||||
'civicrm_value_participant_info',
|
||||
'civicrm_value_contribution_source',
|
||||
'civicrm_value_door_knock_responses',
|
||||
'civicrm_value_phone_bank_responses',
|
||||
'civicrm_value_event_details',
|
||||
'civicrm_value_source_details',
|
||||
'civicrm_value_activity_source_details',
|
||||
'civicrm_value_communication_details',
|
||||
'civicrm_value_event_campaign_details',
|
||||
'civicrm_value_organizational_details',
|
||||
'civicrm_value_demographics'
|
||||
));
|
||||
|
||||
update civicrm_custom_field set column_name = TRIM(TRAILING '_' FROM column_name)
|
||||
where custom_group_id IN (select id from civicrm_custom_group where table_name IN (
|
||||
'civicrm_value_primary_contact',
|
||||
'civicrm_value_voter_info',
|
||||
'civicrm_value_core_info',
|
||||
'civicrm_value_grassroots_info',
|
||||
'civicrm_value_leadership_level',
|
||||
'civicrm_value_contact_info',
|
||||
'civicrm_value_grant_info',
|
||||
'civicrm_value_proposal_info',
|
||||
'civicrm_value_participant_info',
|
||||
'civicrm_value_contribution_source',
|
||||
'civicrm_value_door_knock_responses',
|
||||
'civicrm_value_phone_bank_responses',
|
||||
'civicrm_value_event_details',
|
||||
'civicrm_value_source_details',
|
||||
'civicrm_value_activity_source_details',
|
||||
'civicrm_value_communication_details',
|
||||
'civicrm_value_event_campaign_details',
|
||||
'civicrm_value_organizational_details',
|
||||
'civicrm_value_demographics'
|
||||
));
|
||||
|
||||
update civicrm_custom_group set table_name = 'civicrm_value_source_details' where table_name = 'civicrm_value_activity_source_details';
|
||||
|
||||
-- do column_mapping renaming, check migrate.sql
|
||||
|
||||
update civicrm_custom_field set column_name = 'county_name'
|
||||
where column_name like 'county%' AND
|
||||
custom_group_id IN (select id from civicrm_custom_group where table_name = 'civicrm_value_voter_info');
|
||||
|
||||
update civicrm_custom_field set column_name = 'constituent_type'
|
||||
where column_name like 'contact_type' AND custom_group_id IN
|
||||
(select id from civicrm_custom_group where table_name IN ( 'civicrm_value_demographics', 'civicrm_value_contact_info' ));
|
||||
|
||||
update civicrm_custom_field set column_name = 'reminder_date'
|
||||
where column_name like 'reminderdate' AND
|
||||
custom_group_id IN (select id from civicrm_custom_group where table_name = 'civicrm_value_participant_info');
|
||||
|
||||
update civicrm_custom_field set column_name = 'is_this_a_field_engage_campaign'
|
||||
where column_name like 'is_this_a_field_canvass_campaign' AND
|
||||
custom_group_id IN (select id from civicrm_custom_group where table_name = 'civicrm_value_door_knock_responses');
|
||||
|
||||
update civicrm_custom_group
|
||||
set name = 'Demographics', title = 'Demographics', style = 'Tab'
|
||||
where table_name = 'civicrm_value_demographics';
|
||||
|
||||
-- add missing custom groups in db like 'civicrm_value_organizational_details' and 'core_info'. add fields if not already present
|
||||
|
||||
INSERT INTO `civicrm_custom_group` (`name`, `title`, `extends`, `extends_entity_column_id`, `extends_entity_column_value`, `style`, `collapse_display`, `help_pre`, `help_post`, `weight`, `is_active`, `table_name`, `is_multiple`, `min_multiple`, `max_multiple`, `collapse_adv_display`, `created_id`, `created_date`) VALUES
|
||||
('Constituent_Info__Individuals', 'Constituent Info - Individuals', 'Individual', NULL, NULL, 'Inline', 0, '', '', 4, 1, 'civicrm_value_core_info', 0, NULL, NULL, 0, NULL, NULL),
|
||||
('Organizational_Details', 'Organizational Details', 'Organization', NULL, NULL, 'Inline', 1, '', '', 17, 1, 'civicrm_value_organizational_details', 0, NULL, NULL, 0, NULL, NULL);
|
||||
|
||||
select @cg_core_info_id := id from civicrm_custom_group where table_name = 'civicrm_value_core_info';
|
||||
select @cg_org_detail_id := id from civicrm_custom_group where table_name = 'civicrm_value_organizational_details';
|
||||
select @cg_demographics_id := id from civicrm_custom_group where table_name = 'civicrm_value_demographics';
|
||||
select @cg_grassroots_id := id from civicrm_custom_group where table_name = 'civicrm_value_grassroots_info';
|
||||
select @cg_event_details_id := id from civicrm_custom_group where table_name = 'civicrm_value_event_details';
|
||||
select @cg_leadership_level_id := id from civicrm_custom_group where table_name = 'civicrm_value_leadership_level';
|
||||
|
||||
INSERT INTO `civicrm_option_group` (`name`, `label`, `description`, `is_reserved`, `is_active`) VALUES
|
||||
(CONCAT('rating_' , DATE_FORMAT(NOW(), '%Y%m%d%H%i%s')) , 'Rating', NULL, NULL, 1);
|
||||
SET @opt_group_id := LAST_INSERT_ID();
|
||||
INSERT INTO `civicrm_option_value` (`option_group_id`, `label`, `value`, `name`, `grouping`, `filter`, `is_default`, `weight`, `description`, `is_optgroup`, `is_reserved`, `is_active`, `component_id`, `domain_id`, `visibility_id`) VALUES
|
||||
(@opt_group_id, 'Supporter or Ally', 'Supporter or Ally', NULL, NULL, NULL, 0, 2, NULL, 0, 0, 1, NULL, NULL, NULL),
|
||||
(@opt_group_id, 'Our Network', 'Our Network', 'Our_Network', NULL, NULL, 0, 1, NULL, 0, 0, 1, NULL, NULL, NULL);
|
||||
|
||||
INSERT INTO `civicrm_custom_field` (`custom_group_id`, `label`, `data_type`, `html_type`, `default_value`, `is_required`, `is_searchable`, `is_search_range`, `weight`, `help_pre`, `help_post`, `mask`, `attributes`, `javascript`, `is_active`, `is_view`, `options_per_line`, `text_length`, `start_date_years`, `end_date_years`, `date_format`, `time_format`, `note_columns`, `note_rows`, `column_name`, `option_group_id`) VALUES
|
||||
(@cg_org_detail_id, 'Rating', 'String', 'Select', NULL, 0, 1, 0, 2, NULL, NULL, NULL, NULL, NULL, 1, 0, NULL, 255, NULL, NULL, 'MdY', NULL, 60, 4, 'rating', @opt_group_id);
|
||||
|
||||
-- some of the old fields needs to be migrated to newly inserted group
|
||||
update civicrm_custom_field set custom_group_id = @cg_core_info_id
|
||||
where column_name IN ('constituent_type', 'staff_responsible', 'date_started', 'other_name', 'how_started') and custom_group_id = @cg_demographics_id;
|
||||
|
||||
update civicrm_custom_field set custom_group_id = @cg_grassroots_id
|
||||
where column_name IN ('other_affiliation', 'toxinformer_flag', 'community', 'owner_or_renter') and custom_group_id = @cg_demographics_id;
|
||||
|
||||
-- check dropped/migrated_to_core columns and drop them from custom_fields table too
|
||||
|
||||
delete from civicrm_custom_field
|
||||
where column_name IN ('salutation', 'addressee', 'email_salutation', 'gender', 'dob') and
|
||||
custom_group_id = @cg_demographics_id;
|
||||
|
||||
delete from civicrm_custom_field
|
||||
where column_name IN ('event_external_id') and custom_group_id = @cg_event_details_id;
|
||||
|
||||
delete from civicrm_custom_field
|
||||
where column_name IN ('ehc_board_and_staff') and custom_group_id = @cg_leadership_level_id;
|
||||
|
||||
-- add new report templates
|
||||
SELECT @option_group_id_report := max(id) from civicrm_option_group where name = 'report_template';
|
||||
SELECT @maxWeight := max(weight) from civicrm_option_value where option_group_id=@option_group_id_report;
|
||||
|
||||
INSERT INTO civicrm_option_value
|
||||
(option_group_id, label, value, name, weight, description, is_active, component_id)
|
||||
VALUES
|
||||
(@option_group_id_report, 'Phonebank List', 'contact/phonebank', 'Engage_Report_Form_CallList', (SELECT @maxWeight := @maxWeight + 1), 'Phonebank List', 1, NULL),
|
||||
(@option_group_id_report, 'Canvass Walk List', 'contact/walklist', 'Engage_Report_Form_WalkList', (SELECT @maxWeight := @maxWeight + 1), 'Canvass Walk List', 1, NULL);
|
|
@ -0,0 +1,515 @@
|
|||
-- phpMyAdmin SQL Dump
|
||||
-- version 3.2.2.1deb1
|
||||
-- http://www.phpmyadmin.net
|
||||
--
|
||||
-- Host: localhost
|
||||
-- Generation Time: Mar 03, 2010 at 08:02 PM
|
||||
-- Server version: 5.1.37
|
||||
-- PHP Version: 5.2.10-2ubuntu6.3
|
||||
|
||||
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
|
||||
|
||||
|
||||
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
|
||||
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
|
||||
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
|
||||
/*!40101 SET NAMES utf8 */;
|
||||
|
||||
--
|
||||
-- Database: `civicrm_31`
|
||||
--
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `civicrm_value_communication_details`
|
||||
--
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `civicrm_value_communication_details` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Default MySQL primary key',
|
||||
`entity_id` int(10) unsigned NOT NULL COMMENT 'Table that this extends',
|
||||
`best_time_to_contact` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`communication_status` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`reason_for_do_not_mail` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`reason_for_do_not_phone` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`reason_for_do_not_email` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `unique_entity_id` (`entity_id`),
|
||||
KEY `INDEX_best_time_to_contact` (`best_time_to_contact`),
|
||||
KEY `INDEX_communication_status` (`communication_status`),
|
||||
KEY `INDEX_reason_for_do_not_mail` (`reason_for_do_not_mail`),
|
||||
KEY `INDEX_reason_for_do_not_phone` (`reason_for_do_not_phone`),
|
||||
KEY `INDEX_reason_for_do_not_email` (`reason_for_do_not_email`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `civicrm_value_contact_info`
|
||||
--
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `civicrm_value_contact_info` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Default MySQL primary key',
|
||||
`entity_id` int(10) unsigned NOT NULL COMMENT 'Table that this extends',
|
||||
`constituent_type` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `unique_entity_id` (`entity_id`),
|
||||
KEY `INDEX_constituent_type` (`constituent_type`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `civicrm_value_contribution_source`
|
||||
--
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `civicrm_value_contribution_source` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Default MySQL primary key',
|
||||
`entity_id` int(10) unsigned NOT NULL COMMENT 'Table that this extends',
|
||||
`campaign_source_code` varchar(255) COLLATE utf8_unicode_ci DEFAULT 'General Donations',
|
||||
`campaign_method` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `unique_entity_id` (`entity_id`),
|
||||
KEY `INDEX_campaign_source_code` (`campaign_source_code`),
|
||||
KEY `INDEX_campaign_method` (`campaign_method`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `civicrm_value_core_info`
|
||||
--
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `civicrm_value_core_info` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Default MySQL primary key',
|
||||
`entity_id` int(10) unsigned NOT NULL COMMENT 'Table that this extends',
|
||||
`constituent_type` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`staff_responsible` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`date_started` datetime DEFAULT NULL,
|
||||
`other_name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`how_started` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `unique_entity_id` (`entity_id`),
|
||||
KEY `INDEX_constituent_type` (`constituent_type`),
|
||||
KEY `INDEX_staff_responsible` (`staff_responsible`),
|
||||
KEY `INDEX_date_started` (`date_started`),
|
||||
KEY `INDEX_other_name` (`other_name`),
|
||||
KEY `INDEX_how_started` (`how_started`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `civicrm_value_demographics`
|
||||
--
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `civicrm_value_demographics` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Default MySQL primary key',
|
||||
`entity_id` int(10) unsigned NOT NULL COMMENT 'Table that this extends',
|
||||
`ethnicity` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`primary_language` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`secondary_language` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`kids` tinyint(4) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `unique_entity_id` (`entity_id`),
|
||||
KEY `INDEX_ethnicity` (`ethnicity`),
|
||||
KEY `INDEX_primary_language` (`primary_language`),
|
||||
KEY `INDEX_secondary_language` (`secondary_language`),
|
||||
KEY `INDEX_kids` (`kids`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `civicrm_value_door_knock_responses`
|
||||
--
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `civicrm_value_door_knock_responses` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Default MySQL primary key',
|
||||
`entity_id` int(10) unsigned NOT NULL COMMENT 'Table that this extends',
|
||||
`is_this_a_field_engage_campaign` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`q1` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`q2` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`q3` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`q4` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`walk_list_status` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `unique_entity_id` (`entity_id`),
|
||||
KEY `INDEX_is_this_a_field_engage_campaign` (`is_this_a_field_engage_campaign`),
|
||||
KEY `INDEX_q1` (`q1`),
|
||||
KEY `INDEX_q2` (`q2`),
|
||||
KEY `INDEX_q3` (`q3`),
|
||||
KEY `INDEX_q4` (`q4`),
|
||||
KEY `INDEX_walk_list_status` (`walk_list_status`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `civicrm_value_event_campaign_details`
|
||||
--
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `civicrm_value_event_campaign_details` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Default MySQL primary key',
|
||||
`entity_id` int(10) unsigned NOT NULL COMMENT 'Table that this extends',
|
||||
`q1_text` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`q2_text` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`q3_text` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`q4_text` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `unique_entity_id` (`entity_id`),
|
||||
KEY `INDEX_q1_text` (`q1_text`),
|
||||
KEY `INDEX_q2_text` (`q2_text`),
|
||||
KEY `INDEX_q3_text` (`q3_text`),
|
||||
KEY `INDEX_q4_text` (`q4_text`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `civicrm_value_event_details`
|
||||
--
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `civicrm_value_event_details` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Default MySQL primary key',
|
||||
`entity_id` int(10) unsigned NOT NULL COMMENT 'Table that this extends',
|
||||
`event_contact_person` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`event_source_code` varchar(255) COLLATE utf8_unicode_ci DEFAULT 'General Donations',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `unique_entity_id` (`entity_id`),
|
||||
KEY `INDEX_event_contact_person` (`event_contact_person`),
|
||||
KEY `INDEX_event_source_code` (`event_source_code`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `civicrm_value_grant_info`
|
||||
--
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `civicrm_value_grant_info` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Default MySQL primary key',
|
||||
`entity_id` int(10) unsigned NOT NULL COMMENT 'Table that this extends',
|
||||
`average_amount` decimal(20,2) DEFAULT NULL,
|
||||
`funding_areas` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`requirements_notes` text COLLATE utf8_unicode_ci,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `unique_entity_id` (`entity_id`),
|
||||
KEY `INDEX_average_amount` (`average_amount`),
|
||||
KEY `INDEX_funding_areas` (`funding_areas`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `civicrm_value_grassroots_info`
|
||||
--
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `civicrm_value_grassroots_info` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Default MySQL primary key',
|
||||
`entity_id` int(10) unsigned NOT NULL COMMENT 'Table that this extends',
|
||||
`leadership_level` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`issues_interest` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`volunteer_interests` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`member_status` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `unique_entity_id` (`entity_id`),
|
||||
KEY `INDEX_leadership_level` (`leadership_level`),
|
||||
KEY `INDEX_issues_interest` (`issues_interest`),
|
||||
KEY `INDEX_volunteer_interests` (`volunteer_interests`),
|
||||
KEY `INDEX_member_status` (`member_status`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `civicrm_value_leadership_level`
|
||||
--
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `civicrm_value_leadership_level` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Default MySQL primary key',
|
||||
`entity_id` int(10) unsigned NOT NULL COMMENT 'Table that this extends',
|
||||
`leadership_level` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `unique_entity_id` (`entity_id`),
|
||||
KEY `INDEX_leadership_level` (`leadership_level`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `civicrm_value_organizational_details`
|
||||
--
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `civicrm_value_organizational_details` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Default MySQL primary key',
|
||||
`entity_id` int(10) unsigned NOT NULL COMMENT 'Table that this extends',
|
||||
`rating` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `unique_entity_id` (`entity_id`),
|
||||
KEY `INDEX_rating` (`rating`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `civicrm_value_participant_info`
|
||||
--
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `civicrm_value_participant_info` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Default MySQL primary key',
|
||||
`entity_id` int(10) unsigned NOT NULL COMMENT 'Table that this extends',
|
||||
`childcare_needed` int(11) DEFAULT NULL,
|
||||
`ride_to` int(11) DEFAULT NULL,
|
||||
`ride_back` int(11) DEFAULT NULL,
|
||||
`invitation_date` datetime DEFAULT NULL,
|
||||
`invitation_response` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`second_call_date` datetime DEFAULT NULL,
|
||||
`second_call_response` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`reminder_date` datetime DEFAULT NULL,
|
||||
`reminder_response` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`contact_attended` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`participant_campaign_code` varchar(255) COLLATE utf8_unicode_ci DEFAULT 'General Donations',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `unique_entity_id` (`entity_id`),
|
||||
KEY `INDEX_childcare_needed` (`childcare_needed`),
|
||||
KEY `INDEX_ride_to` (`ride_to`),
|
||||
KEY `INDEX_ride_back` (`ride_back`),
|
||||
KEY `INDEX_invitation_date` (`invitation_date`),
|
||||
KEY `INDEX_invitation_response` (`invitation_response`),
|
||||
KEY `INDEX_second_call_response` (`second_call_response`),
|
||||
KEY `INDEX_reminder_date` (`reminder_date`),
|
||||
KEY `INDEX_reminder_response` (`reminder_response`),
|
||||
KEY `INDEX_contact_attended` (`contact_attended`),
|
||||
KEY `INDEX_participant_campaign_code` (`participant_campaign_code`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `civicrm_value_phone_bank_responses`
|
||||
--
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `civicrm_value_phone_bank_responses` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Default MySQL primary key',
|
||||
`entity_id` int(10) unsigned NOT NULL COMMENT 'Table that this extends',
|
||||
`is_this_a_phone_bank` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`call_list_status` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`q1` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`q2` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`q3` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`q4` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `unique_entity_id` (`entity_id`),
|
||||
KEY `INDEX_is_this_a_phone_bank` (`is_this_a_phone_bank`),
|
||||
KEY `INDEX_call_list_status` (`call_list_status`),
|
||||
KEY `INDEX_q1` (`q1`),
|
||||
KEY `INDEX_q2` (`q2`),
|
||||
KEY `INDEX_q3` (`q3`),
|
||||
KEY `INDEX_q4` (`q4`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `civicrm_value_primary_contact`
|
||||
--
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `civicrm_value_primary_contact` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Default MySQL primary key',
|
||||
`entity_id` int(10) unsigned NOT NULL COMMENT 'Table that this extends',
|
||||
`name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`title` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`email` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`phone` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `unique_entity_id` (`entity_id`),
|
||||
KEY `INDEX_name` (`name`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `civicrm_value_proposal_info`
|
||||
--
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `civicrm_value_proposal_info` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Default MySQL primary key',
|
||||
`entity_id` int(10) unsigned NOT NULL COMMENT 'Table that this extends',
|
||||
`ask_amount` decimal(20,2) DEFAULT NULL,
|
||||
`amount_to_be_received` decimal(20,2) DEFAULT NULL,
|
||||
`date_to_be_received` datetime DEFAULT NULL,
|
||||
`multiyear_grant` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`years` double DEFAULT NULL,
|
||||
`proposal_status` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `unique_entity_id` (`entity_id`),
|
||||
KEY `INDEX_ask_amount` (`ask_amount`),
|
||||
KEY `INDEX_amount_to_be_received` (`amount_to_be_received`),
|
||||
KEY `INDEX_date_to_be_received` (`date_to_be_received`),
|
||||
KEY `INDEX_multiyear_grant` (`multiyear_grant`),
|
||||
KEY `INDEX_years` (`years`),
|
||||
KEY `INDEX_proposal_status` (`proposal_status`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `civicrm_value_source_details`
|
||||
--
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `civicrm_value_source_details` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Default MySQL primary key',
|
||||
`entity_id` int(10) unsigned NOT NULL COMMENT 'Table that this extends',
|
||||
`activity_source_code` varchar(255) COLLATE utf8_unicode_ci DEFAULT 'General Donations',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `unique_entity_id` (`entity_id`),
|
||||
KEY `INDEX_activity_source_code` (`activity_source_code`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `civicrm_value_voter_info`
|
||||
--
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `civicrm_value_voter_info` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Default MySQL primary key',
|
||||
`entity_id` int(10) unsigned NOT NULL COMMENT 'Table that this extends',
|
||||
`precinct` double DEFAULT NULL,
|
||||
`state_district` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`city_district` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`federal_district` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`party_registration` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`if_other_party` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`state_voter_id` double DEFAULT NULL,
|
||||
`voted_in_2008_general_election` tinyint(4) DEFAULT NULL,
|
||||
`voted_in_2008_primary_election` tinyint(4) DEFAULT NULL,
|
||||
`county_name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`voter_history` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `unique_entity_id` (`entity_id`),
|
||||
KEY `INDEX_precinct` (`precinct`),
|
||||
KEY `INDEX_state_district` (`state_district`),
|
||||
KEY `INDEX_city_district` (`city_district`),
|
||||
KEY `INDEX_federal_district` (`federal_district`),
|
||||
KEY `INDEX_party_registration` (`party_registration`),
|
||||
KEY `INDEX_if_other_party` (`if_other_party`),
|
||||
KEY `INDEX_state_voter_id` (`state_voter_id`),
|
||||
KEY `INDEX_voted_in_2008_general_election` (`voted_in_2008_general_election`),
|
||||
KEY `INDEX_voted_in_2008_primary_election` (`voted_in_2008_primary_election`),
|
||||
KEY `INDEX_county_name` (`county_name`),
|
||||
KEY `INDEX_voter_history` (`voter_history`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
|
||||
|
||||
--
|
||||
-- Constraints for dumped tables
|
||||
--
|
||||
|
||||
--
|
||||
-- Constraints for table `civicrm_value_communication_details`
|
||||
--
|
||||
ALTER TABLE `civicrm_value_communication_details`
|
||||
ADD CONSTRAINT `FK_civicrm_value_communication_details_entity_id` FOREIGN KEY (`entity_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE;
|
||||
|
||||
--
|
||||
-- Constraints for table `civicrm_value_contact_info`
|
||||
--
|
||||
ALTER TABLE `civicrm_value_contact_info`
|
||||
ADD CONSTRAINT `FK_civicrm_value_contact_info_entity_id` FOREIGN KEY (`entity_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE;
|
||||
|
||||
--
|
||||
-- Constraints for table `civicrm_value_contribution_source`
|
||||
--
|
||||
ALTER TABLE `civicrm_value_contribution_source`
|
||||
ADD CONSTRAINT `FK_civicrm_value_contribution_source_entity_id` FOREIGN KEY (`entity_id`) REFERENCES `civicrm_contribution` (`id`) ON DELETE CASCADE;
|
||||
|
||||
--
|
||||
-- Constraints for table `civicrm_value_core_info`
|
||||
--
|
||||
ALTER TABLE `civicrm_value_core_info`
|
||||
ADD CONSTRAINT `FK_civicrm_value_core_info_entity_id` FOREIGN KEY (`entity_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE;
|
||||
|
||||
--
|
||||
-- Constraints for table `civicrm_value_demographics`
|
||||
--
|
||||
ALTER TABLE `civicrm_value_demographics`
|
||||
ADD CONSTRAINT `FK_civicrm_value_demographics_entity_id` FOREIGN KEY (`entity_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE;
|
||||
|
||||
--
|
||||
-- Constraints for table `civicrm_value_door_knock_responses`
|
||||
--
|
||||
ALTER TABLE `civicrm_value_door_knock_responses`
|
||||
ADD CONSTRAINT `FK_civicrm_value_door_knock_responses_entity_id` FOREIGN KEY (`entity_id`) REFERENCES `civicrm_activity` (`id`) ON DELETE CASCADE;
|
||||
|
||||
--
|
||||
-- Constraints for table `civicrm_value_event_campaign_details`
|
||||
--
|
||||
ALTER TABLE `civicrm_value_event_campaign_details`
|
||||
ADD CONSTRAINT `FK_civicrm_value_event_campaign_details_entity_id` FOREIGN KEY (`entity_id`) REFERENCES `civicrm_event` (`id`) ON DELETE CASCADE;
|
||||
|
||||
--
|
||||
-- Constraints for table `civicrm_value_event_details`
|
||||
--
|
||||
ALTER TABLE `civicrm_value_event_details`
|
||||
ADD CONSTRAINT `FK_civicrm_value_event_details_entity_id` FOREIGN KEY (`entity_id`) REFERENCES `civicrm_event` (`id`) ON DELETE CASCADE;
|
||||
|
||||
--
|
||||
-- Constraints for table `civicrm_value_grant_info`
|
||||
--
|
||||
ALTER TABLE `civicrm_value_grant_info`
|
||||
ADD CONSTRAINT `FK_civicrm_value_grant_info_entity_id` FOREIGN KEY (`entity_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE;
|
||||
|
||||
--
|
||||
-- Constraints for table `civicrm_value_grassroots_info`
|
||||
--
|
||||
ALTER TABLE `civicrm_value_grassroots_info`
|
||||
ADD CONSTRAINT `FK_civicrm_value_grassroots_info_entity_id` FOREIGN KEY (`entity_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE;
|
||||
|
||||
--
|
||||
-- Constraints for table `civicrm_value_leadership_level`
|
||||
--
|
||||
ALTER TABLE `civicrm_value_leadership_level`
|
||||
ADD CONSTRAINT `FK_civicrm_value_leadership_level_entity_id` FOREIGN KEY (`entity_id`) REFERENCES `civicrm_activity` (`id`) ON DELETE CASCADE;
|
||||
|
||||
--
|
||||
-- Constraints for table `civicrm_value_organizational_details`
|
||||
--
|
||||
ALTER TABLE `civicrm_value_organizational_details`
|
||||
ADD CONSTRAINT `FK_civicrm_value_organizational_details_entity_id` FOREIGN KEY (`entity_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE;
|
||||
|
||||
--
|
||||
-- Constraints for table `civicrm_value_participant_info`
|
||||
--
|
||||
ALTER TABLE `civicrm_value_participant_info`
|
||||
ADD CONSTRAINT `FK_civicrm_value_participant_info_entity_id` FOREIGN KEY (`entity_id`) REFERENCES `civicrm_participant` (`id`) ON DELETE CASCADE;
|
||||
|
||||
--
|
||||
-- Constraints for table `civicrm_value_phone_bank_responses`
|
||||
--
|
||||
ALTER TABLE `civicrm_value_phone_bank_responses`
|
||||
ADD CONSTRAINT `FK_civicrm_value_phone_bank_responses_entity_id` FOREIGN KEY (`entity_id`) REFERENCES `civicrm_activity` (`id`) ON DELETE CASCADE;
|
||||
|
||||
--
|
||||
-- Constraints for table `civicrm_value_primary_contact`
|
||||
--
|
||||
ALTER TABLE `civicrm_value_primary_contact`
|
||||
ADD CONSTRAINT `FK_civicrm_value_primary_contact_entity_id` FOREIGN KEY (`entity_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE;
|
||||
|
||||
--
|
||||
-- Constraints for table `civicrm_value_proposal_info`
|
||||
--
|
||||
ALTER TABLE `civicrm_value_proposal_info`
|
||||
ADD CONSTRAINT `FK_civicrm_value_proposal_info_entity_id` FOREIGN KEY (`entity_id`) REFERENCES `civicrm_activity` (`id`) ON DELETE CASCADE;
|
||||
|
||||
--
|
||||
-- Constraints for table `civicrm_value_source_details`
|
||||
--
|
||||
ALTER TABLE `civicrm_value_source_details`
|
||||
ADD CONSTRAINT `FK_civicrm_value_source_details_entity_id` FOREIGN KEY (`entity_id`) REFERENCES `civicrm_activity` (`id`) ON DELETE CASCADE;
|
||||
|
||||
--
|
||||
-- Constraints for table `civicrm_value_voter_info`
|
||||
--
|
||||
ALTER TABLE `civicrm_value_voter_info`
|
||||
ADD CONSTRAINT `FK_civicrm_value_voter_info_entity_id` FOREIGN KEY (`entity_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE;
|
|
@ -0,0 +1,71 @@
|
|||
-- drop standard profiles
|
||||
delete from civicrm_uf_join where uf_group_id IN (select id from civicrm_uf_group where title IN ('Update Contact Information','Update Grassroots Info','Update Event Participant Info','Update Voter Info','Update Constituent Info', 'Update Core Info'));
|
||||
-- below also deletes fields
|
||||
delete from civicrm_uf_group where title IN ('Update Contact Information','Update Grassroots Info','Update Event Participant Info','Update Voter Info','Update Constituent Info', 'Update Core Info');
|
||||
|
||||
--
|
||||
-- Dumping data for table `civicrm_uf_group`
|
||||
--
|
||||
|
||||
INSERT INTO `civicrm_uf_group` (`is_active`, `group_type`, `title`, `help_pre`, `help_post`, `limit_listings_group_id`, `post_URL`, `add_to_group_id`, `add_captcha`, `is_map`, `is_edit_link`, `is_uf_link`, `is_update_dupe`, `cancel_URL`, `is_cms_user`, `notify`, `is_reserved`, `name`, `created_id`, `created_date`) VALUES
|
||||
( 1, 'Individual,Contact', 'Update Contact Information', '', NULL, NULL, NULL, NULL, 0, 0, 0, 0, 1, NULL, 0, NULL, NULL, 'update_contact_information', NULL, NULL),
|
||||
( 1, 'Individual', 'Update Grassroots Info', NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, 0, NULL, NULL, 'update_grassroots_info', NULL, NULL),
|
||||
( 1, 'Participant', 'Update Event Participant Info', NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, 0, NULL, NULL, 'update_event_participant_info', NULL, NULL),
|
||||
( 1, 'Individual', 'Update Voter Info', NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, 0, NULL, NULL, 'update_voter_info', NULL, NULL),
|
||||
( 1, 'Individual', 'Update Constituent Info', NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, 0, NULL, NULL, 'update_core_info', NULL, NULL);
|
||||
|
||||
--
|
||||
-- Dumping data for table `civicrm_uf_join`
|
||||
--
|
||||
SELECT @option_group_id_update_contact_information := min(id) from civicrm_uf_group where name = 'update_contact_information';
|
||||
SELECT @option_group_id_update_grassroots_info := min(id) from civicrm_uf_group where name = 'update_grassroots_info';
|
||||
SELECT @option_group_id_update_event_participant_info := min(id) from civicrm_uf_group where name = 'update_event_participant_info';
|
||||
SELECT @option_group_id_update_voter_info := min(id) from civicrm_uf_group where name = 'update_voter_info';
|
||||
SELECT @option_group_id_update_core_info := min(id) from civicrm_uf_group where name = 'update_core_info';
|
||||
|
||||
INSERT INTO `civicrm_uf_join` (`is_active`, `module`, `entity_table`, `entity_id`, `weight`, `uf_group_id`) VALUES
|
||||
( 1, 'Profile', NULL, NULL, 1, @option_group_id_update_contact_information),
|
||||
( 1, 'Profile', NULL, NULL, 1, @option_group_id_update_grassroots_info),
|
||||
( 1, 'Profile', NULL, NULL, 1, @option_group_id_update_event_participant_info),
|
||||
( 1, 'Profile', NULL, NULL, 1, @option_group_id_update_voter_info),
|
||||
( 1, 'Profile', NULL, NULL, 1, @option_group_id_update_core_info);
|
||||
|
||||
SELECT @option_custom_grassroots_info :=min(id) from civicrm_custom_group where table_name = 'civicrm_value_grassroots_info';
|
||||
SELECT @option_custom_participant_info :=min(id) from civicrm_custom_group where table_name = 'civicrm_value_participant_info';
|
||||
SELECT @option_custom_voter_info :=min(id) from civicrm_custom_group where table_name = 'civicrm_value_voter_info';
|
||||
SELECT @option_custom_demographics :=min(id) from civicrm_custom_group where table_name = 'civicrm_value_demographics';
|
||||
SELECT @option_custom_core_info :=min(id) from civicrm_custom_group where table_name = 'civicrm_value_core_info';
|
||||
|
||||
--
|
||||
-- Dumping data for table `civicrm_uf_field`
|
||||
--
|
||||
|
||||
INSERT INTO `civicrm_uf_field` (`uf_group_id`, `field_name`, `is_active`, `is_view`, `is_required`, `weight`, `help_post`, `visibility`, `in_selector`, `is_searchable`, `location_type_id`, `phone_type_id`, `label`, `field_type`, `is_reserved`) VALUES
|
||||
( @option_group_id_update_contact_information, 'first_name', 1, 0, 1, 1, '', 'Public Pages', 0, 1, NULL, NULL, 'First Name', 'Individual', NULL),
|
||||
( @option_group_id_update_contact_information, 'last_name', 1, 0, 1, 2, '', 'Public Pages', 0, 1, NULL, NULL, 'Last Name', 'Individual', NULL),
|
||||
( @option_group_id_update_contact_information, 'email', 1, 0, 1, 3, '', 'Public Pages', 0, 0, NULL, NULL, 'Email', 'Contact', NULL),
|
||||
( @option_group_id_update_contact_information, 'phone', 1, 0, 0, 4, '', 'Public Pages', 0, 0, NULL, NULL, 'Phone', 'Contact', NULL),
|
||||
( @option_group_id_update_contact_information, 'street_address', 1, 0, 0, 5, '', 'Public Pages', 0, 0, NULL, NULL, 'Street Address', 'Contact', NULL),
|
||||
( @option_group_id_update_contact_information, 'city', 1, 0, 0, 6, '', 'Public Pages', 0, 0, NULL, NULL, 'City', 'Contact', NULL),
|
||||
( @option_group_id_update_contact_information, 'state_province', 1, 0, 0, 7, '', 'Public Pages', 1, 1, NULL, NULL, 'State', 'Contact', NULL),
|
||||
( @option_group_id_update_contact_information, 'postal_code', 1, 0, 0, 8, '', 'Public Pages', 0, 0, NULL, NULL, 'Zip Code', 'Contact', NULL),
|
||||
( @option_group_id_update_contact_information, 'preferred_communication_method', 1, 0, 0, 9, '', 'Public Pages', 0, 0, NULL, NULL, 'Preferred Communication Method', 'Contact', NULL),
|
||||
( @option_group_id_update_grassroots_info,CONCAT('custom_',(SELECT min(id) from civicrm_custom_field where column_name = 'issues_interest' AND custom_group_id = @option_custom_grassroots_info) ), 1, 0, 0, 2, '', 'User and User Admin Only', 0, 0, NULL, NULL, 'Issues Interest', 'Individual', NULL),
|
||||
( @option_group_id_update_grassroots_info,CONCAT('custom_',(SELECT min(id) from civicrm_custom_field where column_name = 'leadership_level' AND custom_group_id = @option_custom_grassroots_info)), 1, 0, 0, 3, '', 'User and User Admin Only', 0, 0, NULL, NULL, 'Leadership Level', 'Individual', NULL),
|
||||
( @option_group_id_update_grassroots_info, CONCAT('custom_',(SELECT min(id) from civicrm_custom_field where column_name = 'volunteer_interests' AND custom_group_id = @option_custom_grassroots_info)), 1, 0, 0, 4, '', 'User and User Admin Only', 0, 0, NULL, NULL, 'Volunteer Interests', 'Individual', NULL),
|
||||
( @option_group_id_update_event_participant_info, 'participant_status_id', 1, 0, 0, 1, '', 'User and User Admin Only', 0, 0, NULL, NULL, 'Participant Status', 'Participant', NULL),
|
||||
( @option_group_id_update_event_participant_info, CONCAT('custom_',(SELECT min(id) from civicrm_custom_field where column_name = 'childcare_needed' AND custom_group_id = @option_custom_participant_info)), 1, 0, 0, 2, 'Enter number of children if participant needs childcare - otherwise leave it as 0 if no childcare is needed', 'User and User Admin Only', 0, 0, NULL, NULL, 'Childcare Needed', 'Participant', NULL),
|
||||
( @option_group_id_update_event_participant_info, CONCAT('custom_',(SELECT min(id) from civicrm_custom_field where column_name = 'ride_to' AND custom_group_id = @option_custom_participant_info)), 1, 0, 0, 3, 'Enter number of rides participant needs TO event (include children)', 'User and User Admin Only', 0, 0, NULL, NULL, 'Ride TO', 'Participant', NULL),
|
||||
( @option_group_id_update_event_participant_info, CONCAT('custom_',(SELECT min(id) from civicrm_custom_field where column_name = 'ride_back' AND custom_group_id = @option_custom_participant_info)), 1, 0, 0, 4, 'Enter number of rides participant needs BACK from event (include children)', 'User and User Admin Only', 0, 0, NULL, NULL, 'Ride BACK', 'Participant', NULL),
|
||||
( @option_group_id_update_voter_info, CONCAT('custom_',(SELECT min(id) from civicrm_custom_field where column_name = 'voted_in_2008_general_election' AND custom_group_id = @option_custom_voter_info)) , 1, 0, 0, 4, '', 'Public Pages and Listings', 1, 1, NULL, NULL, 'Voted in 2008 General Election?', 'Individual', NULL),
|
||||
( @option_group_id_update_voter_info, CONCAT('custom_',(SELECT min(id) from civicrm_custom_field where column_name = 'voted_in_2008_primary_election' AND custom_group_id = @option_custom_voter_info)), 1, 0, 0, 5, '', 'Public Pages and Listings', 1, 1, NULL, NULL, 'Voted in 2008 Primary Election?', 'Individual', NULL),
|
||||
( @option_group_id_update_voter_info, CONCAT('custom_',(SELECT min(id) from civicrm_custom_field where column_name = 'county_name' AND custom_group_id = @option_custom_voter_info)), 1, 0, 0, 1, '', 'User and User Admin Only', 0, 0, NULL, NULL, 'County Name', 'Individual', NULL),
|
||||
( @option_group_id_update_core_info, CONCAT('custom_',(SELECT min(id) from civicrm_custom_field where column_name = 'constituent_type' AND custom_group_id = @option_custom_core_info)), 1, 0, 0, 1, '', 'User and User Admin Only', 0, 0, NULL, NULL, 'Constituent Type', 'Individual', NULL),
|
||||
( @option_group_id_update_core_info, CONCAT('custom_',(SELECT min(id) from civicrm_custom_field where column_name = 'primary_language' AND custom_group_id = @option_custom_demographics)), 1, 0, 0, 2, '', 'User and User Admin Only', 0, 0, NULL, NULL, 'Primary Language', 'Individual', NULL),
|
||||
( @option_group_id_update_core_info, CONCAT('custom_',(SELECT min(id)from civicrm_custom_field where column_name = 'kids' AND custom_group_id = @option_custom_demographics)), 1, 0, 0, 3, '', 'User and User Admin Only', 0, 0, NULL, NULL, 'Kids?', 'Individual', NULL),
|
||||
( @option_group_id_update_core_info,CONCAT('custom_',(SELECT min(id) from civicrm_custom_field where column_name = 'date_started' AND custom_group_id = @option_custom_core_info)), 1, 0, 0, 4, '', 'User and User Admin Only', 0, 0, NULL, NULL, 'Date Started', 'Individual', NULL),
|
||||
( @option_group_id_update_core_info, CONCAT('custom_',(SELECT min(id) from civicrm_custom_field where column_name = 'staff_responsible' AND custom_group_id = @option_custom_core_info)), 1, 0, 0, 5, '', 'User and User Admin Only', 0, 0, NULL, NULL, 'Staff Responsible', 'Individual', NULL),
|
||||
( @option_group_id_update_voter_info, CONCAT('custom_',(SELECT min(id) from civicrm_custom_field where column_name = 'voter_history' AND custom_group_id = @option_custom_voter_info)), 1, 0, 0, 3, 'A - Always \nO - Occasional\nN - New', 'User and User Admin Only', 0, 0, NULL, NULL, 'Voter History', 'Individual', NULL),
|
||||
( @option_group_id_update_voter_info, CONCAT('custom_',(SELECT min(id) from civicrm_custom_field where column_name = 'party_registration' AND custom_group_id = @option_custom_voter_info)), 1, 0, 0, 2, '', 'User and User Admin Only', 0, 0, NULL, NULL, 'Party Registration', 'Individual', NULL),
|
||||
( @option_group_id_update_grassroots_info, CONCAT('custom_',(SELECT min(id) from civicrm_custom_field where column_name = 'member_status' AND custom_group_id = @option_custom_grassroots_info)), 1, 0, 0, 1, '', 'User and User Admin Only', 0, 0, NULL, NULL, 'Member Status', 'Individual', NULL);
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
{*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*}
|
||||
<div class="crm-accordion-wrapper crm-demographics-accordion collapsed">
|
||||
<div class="crm-accordion-header">
|
||||
{$title}
|
||||
</div><!-- /.crm-accordion-header -->
|
||||
<div id="demographics" class="crm-accordion-body">
|
||||
<div class="form-item">
|
||||
<span class="label">{$form.gender_id.label}</span>
|
||||
|
||||
<span class="value">
|
||||
{$form.gender_id.html}
|
||||
</span>
|
||||
</div>
|
||||
<div class="form-item">
|
||||
<span class="label">{$form.birth_date.label}</span>
|
||||
<span class="fields">{$form.birth_date.html}</span>
|
||||
</div>
|
||||
<div class="form-item">
|
||||
{$form.is_deceased.html}
|
||||
{$form.is_deceased.label}
|
||||
</div>
|
||||
<div id="showDeceasedDate" class="form-item">
|
||||
<span class="label">{$form.deceased_date.label}</span>
|
||||
<span class="fields">{$form.deceased_date.html}</span>
|
||||
</div>
|
||||
{if isset($demographics_groupTree)}{foreach from=$demographics_groupTree item=cd_edit key=group_id}
|
||||
{foreach from=$cd_edit.fields item=element key=field_id}
|
||||
<table class="form-layout-compressed">
|
||||
{include file="CRM/Custom/Form/CustomField.tpl"}
|
||||
</table>
|
||||
{/foreach}
|
||||
{/foreach}{/if}
|
||||
</div><!-- /.crm-accordion-body -->
|
||||
</div><!-- /.crm-accordion-wrapper -->
|
||||
|
||||
{literal}
|
||||
<script type="text/javascript">
|
||||
showDeceasedDate( );
|
||||
function showDeceasedDate( )
|
||||
{
|
||||
if ( cj("#is_deceased").is(':checked') ) {
|
||||
cj("#showDeceasedDate").show( );
|
||||
} else {
|
||||
cj("#showDeceasedDate").hide( );
|
||||
cj("#deceased_date").val('');
|
||||
}
|
||||
}
|
||||
</script>
|
||||
{/literal}
|
|
@ -0,0 +1,87 @@
|
|||
{*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*}
|
||||
{$form.oplock_ts.html}
|
||||
<div class="crm-inline-edit-form">
|
||||
<div class="crm-inline-button">
|
||||
{include file="CRM/common/formButtons.tpl"}
|
||||
</div>
|
||||
|
||||
<div class="crm-clear">
|
||||
<div class="crm-summary-row">
|
||||
<div class="crm-label">{$form.gender_id.label}</div>
|
||||
<div class="crm-content">{$form.gender_id.html}</div>
|
||||
</div>
|
||||
<div class="crm-summary-row">
|
||||
<div class="crm-label">{$form.birth_date.label}</div>
|
||||
<div class="crm-content">
|
||||
{$form.birth_date.html}
|
||||
</div>
|
||||
</div>
|
||||
<div class="crm-summary-row">
|
||||
<div class="crm-label"> </div>
|
||||
<div class="crm-content">
|
||||
{$form.is_deceased.html}
|
||||
{$form.is_deceased.label}
|
||||
</div>
|
||||
</div>
|
||||
<div class="crm-summary-row">
|
||||
<div class="crm-label crm-deceased-date">{$form.deceased_date.label}</div>
|
||||
<div class="crm-content crm-deceased-date">
|
||||
{$form.deceased_date.html}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{* Begin civicrm_engage customization *}
|
||||
{if isset($demographics_groupTree)}
|
||||
{foreach from=$demographics_groupTree item=cd_edit key=group_id}
|
||||
{foreach from=$cd_edit.fields item=element key=field_id}
|
||||
<table class="form-layout-compressed">
|
||||
{include file="CRM/Custom/Form/CustomField.tpl"}
|
||||
</table>
|
||||
{/foreach}
|
||||
{/foreach}
|
||||
{/if}
|
||||
{* End civicrm_engage customization *}
|
||||
|
||||
</div>
|
||||
</div> <!-- end of main -->
|
||||
|
||||
{literal}
|
||||
<script type="text/javascript">
|
||||
function showDeceasedDate( ) {
|
||||
if ( cj("#is_deceased").is(':checked') ) {
|
||||
cj(".crm-deceased-date").show( );
|
||||
} else {
|
||||
cj(".crm-deceased-date").hide( );
|
||||
cj("#deceased_date").val('');
|
||||
}
|
||||
}
|
||||
|
||||
CRM.$(function($) {
|
||||
showDeceasedDate( );
|
||||
});
|
||||
</script>
|
||||
{/literal}
|
|
@ -0,0 +1,82 @@
|
|||
{*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*}
|
||||
<div id="crm-demographic-content" {if $permission EQ 'edit'} class="crm-inline-edit" data-dependent-fields='["#crm-contactname-content"]' data-edit-params='{ldelim}"cid": "{$contactId}", "class_name": "CRM_Contact_Form_Inline_Demographics"{rdelim}'{/if}>
|
||||
<div class="crm-clear crm-inline-block-content" {if $permission EQ 'edit'}title="{ts}Edit demographics{/ts}"{/if}>
|
||||
{if $permission EQ 'edit'}
|
||||
<div class="crm-edit-help">
|
||||
<span class="crm-i fa-pencil"></span> {ts}Edit demographics{/ts}
|
||||
</div>
|
||||
{/if}
|
||||
<div class="crm-summary-row">
|
||||
<div class="crm-label">{ts}Gender{/ts}</div>
|
||||
<div class="crm-content crm-contact-gender_display">{$gender_display}</div>
|
||||
</div>
|
||||
|
||||
<div class="crm-summary-row">
|
||||
<div class="crm-label">{ts}Date of Birth{/ts}</div>
|
||||
<div class="crm-content crm-contact-birth_date_display">
|
||||
{assign var="date_format" value = $fields.birth_date.smarty_view_format}
|
||||
{$birth_date|crmDate:$date_format}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
{if $is_deceased eq 1}
|
||||
{if $deceased_date}
|
||||
<div class="crm-summary-row">
|
||||
<div class="crm-label">{ts}Date Deceased{/ts}</div>
|
||||
<div class="crm-content crm-contact-deceased_date_display">
|
||||
{$deceased_date}
|
||||
</div>
|
||||
</div>
|
||||
{else}
|
||||
<div class="crm-summary-row">
|
||||
<div class="crm-label"></div>
|
||||
<div class="crm-content crm-contact-deceased_message"><span class="font-red upper">{ts}Contact is Deceased{/ts}</span></div>
|
||||
</div>
|
||||
{/if}
|
||||
{else}
|
||||
<div class="crm-summary-row">
|
||||
<div class="crm-label">{ts}Age{/ts}</div>
|
||||
<div class="crm-content crm-contact-age_display">{if $age.y}{ts count=$age.y plural='%count years'}%count year{/ts}{elseif $age.m}{ts count=$age.m plural='%count months'}%count month{/ts}{/if}</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{* The block below is the only modification added by civicrm_engage *}
|
||||
{if isset($demographics_viewCustomData)}
|
||||
{foreach from=$demographics_viewCustomData item=customValues key=customGroupId}
|
||||
{foreach from=$customValues item=cd_edit key=cvID}
|
||||
{include file="CRM/Contact/Page/View/CustomDataFieldView.tpl"}
|
||||
{/foreach}
|
||||
{/foreach}
|
||||
{/if}
|
||||
{* We have to hide the edit link or we will get two of them for this block *}
|
||||
<script>
|
||||
cj("#custom-set-content-{$demographics_custom_group_id} .crm-edit-help").hide();
|
||||
</script>
|
||||
{* End of civicrm_engage modification *}
|
||||
|
||||
</div>
|
||||
</div>
|
|
@ -0,0 +1,51 @@
|
|||
<div class="contactCardRight">
|
||||
{if $contact_type eq 'Individual' AND $showDemographics}
|
||||
<table>
|
||||
<tr>
|
||||
<td class="label">{ts}Gender{/ts}</td><td>{$gender_display}</td>
|
||||
</tr>
|
||||
{if isset($birth_date_display)}
|
||||
<tr>
|
||||
<td class="label">{ts}Date of birth{/ts}</td><td>
|
||||
{if !empty($birthDateViewFormat)}
|
||||
{$birth_date_display|crmDate:$birthDateViewFormat}
|
||||
{else}
|
||||
{$birth_date_display|crmDate}</td>
|
||||
{/if}
|
||||
</tr>
|
||||
{/if}
|
||||
{if $is_deceased eq 1}
|
||||
{if $deceased_date}<td class="label">{ts}Date Deceased{/ts}</td>
|
||||
<tr>
|
||||
<td>
|
||||
{if $birthDateViewFormat}
|
||||
{$deceased_date_display|crmDate:$birthDateViewFormat}
|
||||
{else}
|
||||
{$deceased_date_display|crmDate}
|
||||
{/if}
|
||||
</td>
|
||||
{else}<td class="label" colspan=2><span class="font-red upper">{ts}Contact is Deceased{/ts}</span></td>
|
||||
{/if}
|
||||
</tr>
|
||||
{else}
|
||||
{if isset($age)}
|
||||
<tr>
|
||||
<td class="label">{ts}Age{/ts}</td>
|
||||
<td>{if $age.y}{ts count=$age.y plural='%count years'}%count year{/ts}{elseif $age.m}{ts count=$age.m plural='%count months'}%count month{/ts}{/if} </td>
|
||||
</tr>
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
{if isset($demographics_viewCustomData)}
|
||||
{foreach from=$demographics_viewCustomData item=customValues key=customGroupId}
|
||||
{foreach from=$customValues item=cd_edit key=cvID}
|
||||
{foreach from=$cd_edit.fields item=element key=field_id}
|
||||
{include file="CRM/Contact/Page/View/CustomDataFieldView.tpl"}
|
||||
{/foreach}
|
||||
{/foreach}
|
||||
{/foreach}
|
||||
{/if}
|
||||
|
||||
</table>
|
||||
{/if}
|
||||
</div><!-- #contactCardRight -->
|
|
@ -0,0 +1,164 @@
|
|||
{if !$printOnly}
|
||||
{include file="CRM/Report/Form.tpl"}
|
||||
{else}
|
||||
<h1>{$reportTitle}</h1>
|
||||
{if $statistics }
|
||||
{foreach from=$statistics.filters item=row}
|
||||
<h2>{$row.title}  :{$row.value}</h2>
|
||||
{/foreach}
|
||||
{/if}
|
||||
|
||||
{*include the graph*}
|
||||
{include file="CRM/Report/Form/Layout/Graph.tpl"}
|
||||
|
||||
{*modified table layout*}
|
||||
{if (!$chartEnabled || !$chartSupported )&& $rows}
|
||||
{if $pager and $pager->_response and $pager->_response.numPages > 1}
|
||||
<br />
|
||||
<div class="report-pager">
|
||||
{include file="CRM/common/pager.tpl" noForm=0}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<table class={if !$printOnly}"report-layout"{else}"body"{/if}>
|
||||
<thead class="sticky">
|
||||
<tr>
|
||||
{foreach from=$columnHeaders item=header key=field}
|
||||
{assign var=class value=""}
|
||||
{if $header.type eq 1024 OR $header.type eq 1}
|
||||
{assign var=class value="class='reports-header-right'"}
|
||||
{else}
|
||||
{assign var=class value="class='reports-header'"}
|
||||
{/if}
|
||||
{if !$skip}
|
||||
{if $header.colspan}
|
||||
<th {$header.class} colspan={$header.colspan}>{$header.title}</th>
|
||||
{assign var=skip value=true}
|
||||
{assign var=skipCount value=`$header.colspan`}
|
||||
{assign var=skipMade value=1}
|
||||
{else}
|
||||
<th {$class} {$header.class}>{$header.title}</th>
|
||||
{assign var=skip value=false}
|
||||
{/if}
|
||||
{else} {* for skip case *}
|
||||
{assign var=skipMade value=`$skipMade+1`}
|
||||
{if $skipMade >= $skipCount}{assign var=skip value=false}{/if}
|
||||
{/if}
|
||||
{/foreach}
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
{assign var=rowCount value=0}
|
||||
{foreach from=$rows item=row}
|
||||
{assign var=rowCount value=`$rowCount+1`}
|
||||
{assign var=nextRow value=`$rowCount+1`}
|
||||
<tr>
|
||||
{foreach from=$columnHeaders item=header key=field}
|
||||
{assign var=fieldLink value=$field|cat:"_link"}
|
||||
{assign var=fieldHover value=$field|cat:"_hover"}
|
||||
<td {if $header.type eq 1024 OR $header.type eq 1} class="report-contents-right"{elseif $row.$field eq 'Subtotal'} class="report-label"{/if}>
|
||||
{if $row.$fieldLink}
|
||||
<a title="{$row.$fieldHover}" href="{$row.$fieldLink}">
|
||||
{/if}
|
||||
|
||||
{if $row.$field eq 'Subtotal'}
|
||||
{$row.$field}
|
||||
{elseif $header.type & 4}
|
||||
{if $header.group_by eq 'MONTH' or $header.group_by eq 'QUARTER'}
|
||||
{$row.$field|crmDate:$config->dateformatPartial}
|
||||
{elseif $header.group_by eq 'YEAR'}
|
||||
{$row.$field|crmDate:$config->dateformatYear}
|
||||
{else}
|
||||
{$row.$field|truncate:10:''|crmDate}
|
||||
{/if}
|
||||
{elseif $header.type eq 1024}
|
||||
<span class="nowrap">{$row.$field|crmMoney}</span>
|
||||
{else}
|
||||
{$row.$field}
|
||||
{/if}
|
||||
|
||||
{if $row.$fieldLink}</a>{/if}
|
||||
</td>
|
||||
{/foreach}
|
||||
</tr>
|
||||
|
||||
{if $printOnly and $rowCount % 7 eq 0 and $rows.$nextRow}
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
<p>Response Codes: Y= Yes; N= No; U= Undecided; D= Declined to State</p>
|
||||
<p>Status Codes: NH= Not Home; MV= Moved; D= Deceased; WN= Wrong Number</p>
|
||||
{assign var=pageNum value= `$rowCount/7` }
|
||||
<p style="text-align: right;">Page {$pageNum|Ceil} of {$pageTotal}</p>
|
||||
<div class="page"></div>
|
||||
<h1>{$reportTitle}</h1>
|
||||
{if $statistics }
|
||||
{foreach from=$statistics.filters item=row}
|
||||
<h2>{$row.title}  :{$row.value}</h2>
|
||||
{/foreach}
|
||||
{/if}
|
||||
<table class={if !$printOnly}"report-layout"{else}"body"{/if}>
|
||||
<thead class="sticky">
|
||||
<tr>
|
||||
{foreach from=$columnHeaders item=header key=field}
|
||||
{assign var=class value=""}
|
||||
{if $header.type eq 1024 OR $header.type eq 1}
|
||||
{assign var=class value="class='reports-header-right'"}
|
||||
{else}
|
||||
{assign var=class value="class='reports-header'"}
|
||||
{/if}
|
||||
{if !$skip}
|
||||
{if $header.colspan}
|
||||
<th {$header.class} colspan={$header.colspan}>{$header.title}</th>
|
||||
{assign var=skip value=true}
|
||||
{assign var=skipCount value=`$header.colspan`}
|
||||
{assign var=skipMade value=1}
|
||||
{else}
|
||||
<th {$class} {$header.class}>{$header.title}</th>
|
||||
{assign var=skip value=false}
|
||||
{/if}
|
||||
{else} {* for skip case *}
|
||||
{assign var=skipMade value=`$skipMade+1`}
|
||||
{if $skipMade >= $skipCount}{assign var=skip value=false}{/if}
|
||||
{/if}
|
||||
{/foreach}
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
{/if}
|
||||
|
||||
{/foreach}
|
||||
|
||||
{if $grandStat}
|
||||
{* foreach from=$grandStat item=row*}
|
||||
<tr class="total-row">
|
||||
{foreach from=$columnHeaders item=header key=field}
|
||||
<td class="report-label">
|
||||
{if $header.type eq 1024}
|
||||
{$grandStat.$field|crmMoney}
|
||||
{else}
|
||||
{$grandStat.$field}
|
||||
{/if}
|
||||
</td>
|
||||
{/foreach}
|
||||
</tr>
|
||||
{* /foreach*}
|
||||
{/if}
|
||||
{if $printOnly}</tbody>{/if}
|
||||
</table>
|
||||
{if $printOnly}
|
||||
<p>Response Codes: Y= Yes; N= No; U= Undecided; D= Declined to State</p>
|
||||
<p>Status Codes: NH= Not Home; MV= Moved; D= Deceased; WN= Wrong Number</p>
|
||||
{assign var=pageNum value= `$rowCount/7` }
|
||||
<p style="text-align: right;">Page {$pageNum|Ceil} of {$pageTotal}</p>
|
||||
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
{* table layout ends *}
|
||||
{if !$printOnly}
|
||||
{*Statistics at the bottom of the page*}
|
||||
{include file="CRM/Report/Form/Statistics.tpl" bottom=true}
|
||||
{/if}
|
||||
{include file="CRM/Report/Form/ErrorMessage.tpl"}
|
||||
{/if}
|
|
@ -0,0 +1,72 @@
|
|||
{if !$printOnly }
|
||||
{include file="CRM/Report/Form.tpl"}
|
||||
{else}
|
||||
|
||||
{if $groupRows}
|
||||
{assign var=pageNum value=1}
|
||||
{foreach from=$groupRows item=groupData key=group}
|
||||
{if $pageNum eq 1}
|
||||
<div>
|
||||
{else}
|
||||
<div {$newgroupdiv}>
|
||||
{/if}
|
||||
<table class="head">
|
||||
|
||||
<tr><td style="text-align: left;">Organization Name: {$groupData.org}</td>
|
||||
<td style="text-align: center;"></td>
|
||||
<td style="text-align: right;">{if {$groupData.odd}Odd/Even: {$groupData.odd}{/if}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="text-align: left;">{if $groupData.street_name}Street Name: {$groupData.street_name}{/if}</td>
|
||||
<td style="text-align: center;">Walk List</td>
|
||||
<td style="text-align: right;"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="text-align: left;">{if $groupData.city_zip}City-Zip: {$groupData.city_zip}{/if}</td>
|
||||
<td style="text-align: center;">{$groupInfo.date}{$groupInfo.descr}
|
||||
{if $statistics }
|
||||
{foreach from=$statistics.filters item=row}
|
||||
<br /> {$row.title}  :{$row.value}
|
||||
{/foreach}
|
||||
{/if}
|
||||
</td>
|
||||
<td style="text-align: right;"> </td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
{if $pdfRows.$group}
|
||||
<table class="body">
|
||||
<tr>
|
||||
{foreach from=$pdfHeaders item=header}
|
||||
<th {$header.class} class='reports-header-right' >{$header.title}</th>
|
||||
{/foreach}
|
||||
</tr>
|
||||
{foreach from=$pdfRows.$group item=row}
|
||||
<tr>
|
||||
{foreach from=$pdfHeaders item=title key=k}
|
||||
{if $k eq 'rcode'}
|
||||
<td>Q1 Y N U D<br>
|
||||
Q2 Y N U D<br>
|
||||
Q3 Y N U D<br>
|
||||
Q4 Y N U D
|
||||
</td>
|
||||
{elseif $k eq 'status'}
|
||||
<td>NH MV D WN</td>
|
||||
{else}
|
||||
<td>{$row.$k}</td>
|
||||
{/if}
|
||||
{/foreach}
|
||||
</tr>
|
||||
{/foreach}
|
||||
</tr>
|
||||
</table>
|
||||
{/if}
|
||||
|
||||
<p>Response Codes: Y= Yes; N= No; U= Undecided; D= Declined to State</p>
|
||||
<p>Status Codes: NH= Not Home; MV= Moved; D= Deceased; WA= Wrong Address</p>
|
||||
<p>VH (Voting History): A=Always; O=Occasional; N=New</p>
|
||||
<br/>
|
||||
|
||||
{/foreach}
|
||||
{/if}
|
||||
{/if}
|
|
@ -0,0 +1,12 @@
|
|||
name = CiviGroup Roles Sync
|
||||
description = Sync Drupal Roles to CiviCRM Groups.
|
||||
version = 7.x-4.7.29
|
||||
core = 7.x
|
||||
package = CiviCRM
|
||||
project = civicrm
|
||||
configure = admin/config/civicrm/civicrm_group_roles
|
||||
|
||||
dependencies[] = civicrm
|
||||
|
||||
files[] = civicrm_group_roles.module
|
||||
files[] = civicrm_group_roles.install
|
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
// $Id: civicrm_group_roles.module,v 1.1.4.2 2008/10/14 00:20:36 matt2000 Exp $
|
||||
|
||||
|
||||
/* @file
|
||||
* A simple module to synchronize Drupal Roles with Specified CiviCRM Groups
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_install().
|
||||
*/
|
||||
function civicrm_group_roles_install() {
|
||||
$t = get_t();
|
||||
$here = l($t('here'), 'admin/config/civicrm/civicrm_group_roles/add_rule');
|
||||
drupal_set_message($t('CiviGroup Roles Sync installed. You will need to specify sync rules !1.', array('!1' => $here)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_enable().
|
||||
*/
|
||||
function civicrm_group_roles_enable() {
|
||||
db_query("UPDATE {system} SET weight = 110 WHERE name = 'civicrm_group_roles'");
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_schema().
|
||||
*/
|
||||
function civicrm_group_roles_schema() {
|
||||
$schema['civicrm_group_roles_rules'] = array(
|
||||
'fields' => array(
|
||||
'id' => array(
|
||||
'type' => 'serial',
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'role_id' => array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'group_id' => array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
),
|
||||
),
|
||||
'primary key' => array('id'),
|
||||
);
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update CiviGroup Roles Sync module weight to be greater than CiviCRM's.
|
||||
*/
|
||||
function civicrm_group_roles_update_7400(&$sandbox) {
|
||||
db_query("UPDATE {system} SET weight = 101 WHERE name = 'civicrm_group_roles'");
|
||||
}
|
|
@ -0,0 +1,900 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* A simple module that adds a user to groups based on Role.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_user_insert().
|
||||
*
|
||||
* When a new user is created, add them to Civi groups depending on their
|
||||
* assigned roles.
|
||||
*/
|
||||
function civicrm_group_roles_user_insert(&$edit, $account, $category) {
|
||||
if (!civicrm_initialize()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$all = user_roles(TRUE);
|
||||
// the insert form only stores role ids. :-P
|
||||
$rids = $edit['roles'];
|
||||
$rids = is_array($rids) ? $rids : array($rids);
|
||||
$roles = array_intersect_key($all, $rids);
|
||||
if ($roles) {
|
||||
civicrm_group_roles_add_groups_oncreate($account, $roles);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_user_update().
|
||||
*
|
||||
* When a user is updated, add/remove them from Civi groups according to their
|
||||
* roles.
|
||||
*/
|
||||
function civicrm_group_roles_user_update(&$edit, $account, $category) {
|
||||
if (!civicrm_initialize()) {
|
||||
return;
|
||||
}
|
||||
$roles = array_diff_key($account->roles, array(1 => 'anonymous user', 2 => 'authenticated user'));
|
||||
|
||||
if ($roles) {
|
||||
civicrm_group_roles_add_remove_groups($roles, $account, 'add');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_user_login().
|
||||
*
|
||||
* When a user logs in, update their roles depending on which Civi groups they
|
||||
* are a member of.
|
||||
*/
|
||||
function civicrm_group_roles_user_login(&$edit, $account) {
|
||||
civicrm_group_roles_sync_roles($account);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to add a user to Civi groups depending on their roles, when
|
||||
* the user is first created
|
||||
*/
|
||||
function civicrm_group_roles_add_groups_oncreate($account, $roles) {
|
||||
if (!civicrm_initialize()) {
|
||||
return;
|
||||
}
|
||||
|
||||
require_once 'CRM/Core/BAO/UFMatch.php';
|
||||
$contactId = CRM_Core_BAO_UFMatch::getContactId($account->uid);
|
||||
|
||||
if (!$contactId) {
|
||||
return;
|
||||
}
|
||||
|
||||
$result = db_select('civicrm_group_roles_rules', 'cgr')->fields('cgr', array('group_id'))->condition('role_id', array_keys($roles))->execute()->fetchAll();
|
||||
$groups = _civicrm_group_roles_validate_groups($result);
|
||||
foreach ($groups as $group) {
|
||||
$groupContact = new CRM_Contact_DAO_GroupContact();
|
||||
$groupContact->group_id = $group->group_id;
|
||||
$groupContact->contact_id = $contactId;
|
||||
|
||||
if (!$groupContact->find(TRUE)) {
|
||||
// add the contact to group
|
||||
$historyParams = array(
|
||||
'contact_id' => $contactId,
|
||||
'group_id' => $group->group_id,
|
||||
'method' => 'API',
|
||||
'status' => 'Added',
|
||||
'date' => date('YmdHis'),
|
||||
'tracking' => NULL,
|
||||
);
|
||||
CRM_Contact_BAO_SubscriptionHistory::create($historyParams);
|
||||
$groupContact->status = 'Added';
|
||||
$groupContact->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_alter().
|
||||
*
|
||||
* The updates CiviCRM when Drupal roles are changed
|
||||
*/
|
||||
function civicrm_group_roles_form_alter(&$form, &$form_state, $form_id) {
|
||||
// append this to change user edit submit function
|
||||
if (($form['#id'] == 'user-profile-form' && isset($form['#user']) && (module_exists('content_profile') ||
|
||||
isset($form['account']))) || $form['#id'] == 'user-edit-form') {
|
||||
$uid = $form['#user']->uid;
|
||||
if (!$uid) {
|
||||
return;
|
||||
}
|
||||
// make sure there is a civicrm record
|
||||
civicrm_initialize(TRUE);
|
||||
require_once 'CRM/Core/BAO/UFMatch.php';
|
||||
$contact_id = CRM_Core_BAO_UFMatch::getContactId($uid);
|
||||
if (!$contact_id) {
|
||||
return;
|
||||
}
|
||||
array_unshift($form['#submit'], '_civicrm_group_update');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to remove Groups when Drupal user form is saved, if a role
|
||||
* is removed in Drupal.
|
||||
*/
|
||||
function _civicrm_group_update($form, $form_values) {
|
||||
//note the drupal form calls this function directly so CiviCRM needs to be initialised
|
||||
if (!civicrm_initialize()) {
|
||||
return;
|
||||
}
|
||||
$uid = $form['#user']->uid;
|
||||
$user = user_load($uid);
|
||||
//load the currently saved roles
|
||||
$roles = $user->roles;
|
||||
//get the roles as submitted on the user form
|
||||
if (!is_array($form_values['values']['roles'])) {
|
||||
return;
|
||||
}
|
||||
$new_roles = array_filter($form_values['values']['roles']);
|
||||
|
||||
// if there is a difference then something was removed
|
||||
$removed_roles = array_diff_key($roles, $new_roles);
|
||||
|
||||
// now delete the corresponding group from the record in CiviCRM (if there is a corresponding group)
|
||||
if ($removed_roles) {
|
||||
civicrm_group_roles_add_remove_groups($removed_roles, $user, 'remove');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_civicrm_post().
|
||||
*
|
||||
* This provides sync from CiviCRM -> Drupal
|
||||
*/
|
||||
function civicrm_group_roles_civicrm_post($op, $objectName, $objectId, &$objectRef) {
|
||||
if (!civicrm_initialize()) {
|
||||
return;
|
||||
}
|
||||
if ($objectName != 'GroupContact') {
|
||||
// We only care about Group contact operations, so bail on anything else.
|
||||
return;
|
||||
}
|
||||
|
||||
$group_id = $objectId;
|
||||
|
||||
//Do we have any Role sync rules for this group?
|
||||
$groupRoles = db_select('civicrm_group_roles_rules', 'cgr')->fields('cgr', array('role_id'))->condition('group_id', $group_id)->execute()->fetchAll();
|
||||
|
||||
$rolesProcessed = array();
|
||||
foreach ($groupRoles as $groupRole) {
|
||||
$rid = $groupRole->role_id;
|
||||
// we need this to properly save the user account below.
|
||||
$role_name = db_select('role', 'r')->range(0, 1)->fields('r', array('name'))->condition('rid', $rid)->execute()->fetchField();
|
||||
foreach ($objectRef as $contact_id) {
|
||||
if (isset($rolesProcessed[$rid])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//Do we have a Drupal Account?
|
||||
require_once 'CRM/Core/BAO/UFMatch.php';
|
||||
$uid = CRM_Core_BAO_UFMatch::getUFId($contact_id);
|
||||
// make sure we have an actual user account
|
||||
if (!$uid) {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch ($op) {
|
||||
case 'create':
|
||||
// Contact added to group; add to corresponding role
|
||||
$rolesProcessed[$rid] = $rid;
|
||||
civicrm_group_roles_add_role($uid, $rid, $role_name);
|
||||
break;
|
||||
|
||||
// "edit" denotes both rejoining or being deleted from a group,
|
||||
// need to check which to perform appropriate action
|
||||
case 'edit':
|
||||
$rolesProcessed[$rid] = $rid;
|
||||
// Ideally would use GroupContact API with group_id as a parameter, currently broken (amend once bug fixed):
|
||||
// http://issues.civicrm.org/jira/browse/CRM-10331?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
|
||||
$contact_groups = civicrm_api('GroupContact', 'get', array(version => '3', 'contact_id' => $contact_id));
|
||||
$in_group = FALSE;
|
||||
foreach ($contact_groups['values'] as $group_row) {
|
||||
if ($group_row['group_id'] == $group_id) {
|
||||
$in_group = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($in_group) {
|
||||
// Contact rejoined the group; add to corresponding role
|
||||
civicrm_group_roles_add_role($uid, $rid, $role_name);
|
||||
}
|
||||
else {
|
||||
// Contact no longer belongs to group, remove corresponding role,
|
||||
// but only if the contact is in no other groups that grant this role
|
||||
if (!civicrm_role_granted_by_other_group($contact_id, $rid, $group_id)) {
|
||||
civicrm_group_roles_del_role($uid, $rid, $role_name);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'delete':
|
||||
$rolesProcessed[$rid] = $rid;
|
||||
//Contact is removed from group.
|
||||
//Remove the role, but only if the contact is in no other groups that grant this role
|
||||
if (!civicrm_role_granted_by_other_group($contact_id, $rid, $group_id)) {
|
||||
civicrm_group_roles_del_role($uid, $rid, $role_name);
|
||||
}
|
||||
break;
|
||||
}
|
||||
//end switch
|
||||
}
|
||||
//end foreach
|
||||
}
|
||||
//end while
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to add a role to a given user
|
||||
* Copied from user.module function user_multiple_role_edit()
|
||||
*
|
||||
* @param int $uid The user id of the account to modify
|
||||
* @param int $rid The debug_backtrace role id being added
|
||||
*/
|
||||
function civicrm_group_roles_add_role($uid, $rid, $role_name) {
|
||||
$account = user_load((int) $uid, TRUE);
|
||||
|
||||
// Skip adding the role to the user if they already have it.
|
||||
if ($account !== FALSE && !isset($account->roles[$rid])) {
|
||||
$roles = $account->roles + array($rid => $role_name);
|
||||
user_save($account, array('roles' => $roles));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to remove a role from a given user
|
||||
* Copied from user.module function user_multiple_role_edit()
|
||||
*
|
||||
* @param $uid The user id of the account to modify
|
||||
* @param $rid The role id being removd
|
||||
*/
|
||||
function civicrm_group_roles_del_role($uid, $rid, $role_name) {
|
||||
$account = user_load((int) $uid);
|
||||
// Skip removing the role from the user if they already don't have it.
|
||||
if ($account !== FALSE && isset($account->roles[$rid])) {
|
||||
$roles = array_diff($account->roles, array($rid => $role_name));
|
||||
user_save($account, array('roles' => $roles));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Count the groups this contact is in which grant this role
|
||||
*/
|
||||
function civicrm_role_granted_by_other_group($contact_id, $rid, $group_id) {
|
||||
if (!civicrm_initialize()) {
|
||||
return;
|
||||
}
|
||||
|
||||
//get all the groups this contact belongs to
|
||||
$params = array('version' => 3, 'contact_id' => $contact_id);
|
||||
$result = civicrm_api('group_contact', 'get', $params);
|
||||
|
||||
if (civicrm_error($result)) {
|
||||
return TRUE;
|
||||
}
|
||||
else {
|
||||
//contact is not in *any* other groups so delete the role
|
||||
if (count($result) == 0) {
|
||||
return FALSE;
|
||||
}
|
||||
//contact is in some groups, determine if any of them grant this role
|
||||
else {
|
||||
// check if group has been added by api or not.
|
||||
$groupIds = array();
|
||||
foreach ($result as $grpid => $grp) {
|
||||
$groupIds[] = CRM_Utils_Array::value('group_id', $grp);
|
||||
}
|
||||
}
|
||||
|
||||
$groupRules = db_query('SELECT COUNT(*) FROM {civicrm_group_roles_rules} WHERE group_id IN ( :group_ids ) ', array(':group_ids' => implode(",", $groupIds)))->fetchField();
|
||||
|
||||
return ($groupRules > 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_menu().
|
||||
*/
|
||||
function civicrm_group_roles_menu() {
|
||||
$items = array();
|
||||
$items['admin/config/civicrm/civicrm_group_roles'] = array(
|
||||
'title' => 'CiviGroup Roles Sync',
|
||||
'description' => 'Add/remove association rules and configure settings. Also perform manual synchronization.',
|
||||
'page callback' => 'civicrm_group_roles_show_rules',
|
||||
'access callback' => 'user_access',
|
||||
'access arguments' => array('access civicrm group role setting'),
|
||||
'type' => MENU_NORMAL_ITEM,
|
||||
);
|
||||
$items['admin/config/civicrm/civicrm_group_roles/show_rules'] = array(
|
||||
'title' => 'Association rules',
|
||||
'access callback' => 'user_access',
|
||||
'access arguments' => array('access civicrm group role setting'),
|
||||
'weight' => -5,
|
||||
'type' => MENU_DEFAULT_LOCAL_TASK,
|
||||
);
|
||||
$items['admin/config/civicrm/civicrm_group_roles/add_rule'] = array(
|
||||
'title' => 'Add association rule',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('civicrm_group_roles_add_rule_form'),
|
||||
'access callback' => 'user_access',
|
||||
'access arguments' => array('access civicrm group role setting'),
|
||||
'type' => MENU_LOCAL_ACTION,
|
||||
);
|
||||
$items['admin/config/civicrm/civicrm_group_roles/add_rule/%rule_id'] = array(
|
||||
'title' => 'Edit association rule',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('civicrm_group_roles_add_rule_form', 1),
|
||||
'access callback' => 'user_access',
|
||||
'access arguments' => array('access civicrm group role setting'),
|
||||
);
|
||||
$items['admin/config/civicrm/civicrm_group_roles/manual_sync'] = array(
|
||||
'title' => 'Manually synchronize',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('civicrm_group_roles_manual_sync'),
|
||||
'access callback' => 'user_access',
|
||||
'access arguments' => array('access civicrm group role setting'),
|
||||
'type' => MENU_LOCAL_TASK,
|
||||
);
|
||||
$items['admin/config/civicrm/civicrm_group_roles/settings'] = array(
|
||||
'title' => 'Settings',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('civicrm_group_roles_settings'),
|
||||
'access callback' => 'user_access',
|
||||
'access arguments' => array('access civicrm group role setting'),
|
||||
'type' => MENU_LOCAL_TASK,
|
||||
);
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_permission().
|
||||
*/
|
||||
function civicrm_group_roles_permission() {
|
||||
return array(
|
||||
'access civicrm group role setting' => array(
|
||||
'title' => t('Access CiviCRM group role setting'),
|
||||
'description' => t('Access Civicrm group roles synchronization.'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show stored association rules and delete rules.
|
||||
*/
|
||||
function civicrm_group_roles_show_rules($action = NULL, $id = NULL) {
|
||||
if (!civicrm_initialize()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($action == 'delete') {
|
||||
if (is_numeric($id)) {
|
||||
|
||||
$delete = db_delete('civicrm_group_roles_rules')->condition('id', $id)->execute();
|
||||
if ($delete) {
|
||||
drupal_set_message(t('Rule ID !1 was successfully deleted.', array('!1' => $id)));
|
||||
}
|
||||
else {
|
||||
drupal_set_message(t('There was an error deleting the association rule. Please check your database settings and try again. If you continue to get this error message then try to reinstall CiviGroup Roles Sync.'), $type = 'error');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// get drupal roles
|
||||
$roles = user_roles(TRUE);
|
||||
|
||||
// get civicrm groups
|
||||
$params = array('version' => 3, 'option.limit' => 0);
|
||||
$groups = civicrm_api('group', 'get', $params);
|
||||
$groups = CRM_Utils_Array::value('values', $groups);
|
||||
|
||||
//Begin building main output table.
|
||||
$header = array('rid' => t('Rule ID'), 'name' => t("Rule Name ('CiviCRM Group' <--> 'Drupal Role')"), 'op' => t('Operations'));
|
||||
$data = array();
|
||||
|
||||
$rules = db_query('SELECT * FROM {civicrm_group_roles_rules} ORDER BY id ASC')->fetchAll();
|
||||
foreach ($rules as $result) {
|
||||
$gid = CRM_Utils_Array::value($result->group_id, $groups);
|
||||
$data[] = array(
|
||||
'rid' => check_plain($result->id),
|
||||
'name' => check_plain(CRM_Utils_Array::value('title', $gid) . " <--> " . $roles[$result->role_id]),
|
||||
'op' => l(t('edit'), 'admin/config/civicrm/civicrm_group_roles/add_rule' . '/' . check_plain($result->id)) . ' ' . l(t('delete'), 'admin/config/civicrm/civicrm_group_roles/delete' . '/' . check_plain($result->id)),
|
||||
);
|
||||
}
|
||||
|
||||
if (!empty($data)) {
|
||||
$output['data'] = array(
|
||||
'#theme' => 'table',
|
||||
'#header' => $header,
|
||||
'#rows' => $data,
|
||||
);
|
||||
}
|
||||
else {
|
||||
$output = t('There are no rules currently set.');
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form().
|
||||
*
|
||||
* Add/edit association rules.
|
||||
*
|
||||
* @ingroup forms
|
||||
* @see civicrm_group_roles_add_rule_validate()
|
||||
* @see civicrm_group_roles_add_rule_submit()
|
||||
*/
|
||||
function civicrm_group_roles_add_rule_form($form, $form_state = array(), $edit_id = NULL) {
|
||||
if (!civicrm_initialize()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// retrieve drupal roles
|
||||
$roles = user_roles(TRUE);
|
||||
|
||||
// get civicrm groups
|
||||
require_once "CRM/Core/PseudoConstant.php";
|
||||
$groups = CRM_Core_PseudoConstant::group();
|
||||
|
||||
//Let's get rid of the authenticated role as it is a useless option for this module
|
||||
unset($roles[2]);
|
||||
|
||||
//Begin add form
|
||||
$form = array();
|
||||
$form['add_rule'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Association Rule'),
|
||||
'#description' => t('Choose a CiviCRM Group and a Drupal Role below.'),
|
||||
'#tree' => TRUE,
|
||||
'#parents' => array('add_rule'),
|
||||
);
|
||||
$form['add_rule']['select_group'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('CiviCRM Group'),
|
||||
'#options' => $groups,
|
||||
'#required' => TRUE,
|
||||
);
|
||||
$form['add_rule']['select_role'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Drupal Role'),
|
||||
'#options' => $roles,
|
||||
'#required' => TRUE,
|
||||
);
|
||||
$form['submit'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Add association rule'),
|
||||
);
|
||||
|
||||
//Begin edit form
|
||||
if (!empty($edit_id) && is_numeric($edit_id)) {
|
||||
$default_values = db_select('civicrm_group_roles_rules', 'cgr')->fields('cgr')->condition('id', $edit_id)->execute()->fetchObject();
|
||||
if (!$default_values) {
|
||||
drupal_set_message(t('There was an error in obtaining the association rule for edit. Please check your database settings and try again. If you continue to get this error message then try to reinstall CiviGroup Roles Sync.'));
|
||||
return $form;
|
||||
}
|
||||
|
||||
//Alter above add form with default values.
|
||||
$form['add_rule']['select_group']['#default_value'] = check_plain($default_values->group_id);
|
||||
$form['add_rule']['select_role']['#default_value'] = check_plain($default_values->role_id);
|
||||
$form['edit_flag'] = array('#type' => 'hidden', '#value' => check_plain($edit_id));
|
||||
$form['submit']['#value'] = t('Save changes');
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_validate().
|
||||
*
|
||||
* for the add/edit rule form.
|
||||
*/
|
||||
function civicrm_group_roles_add_rule_form_validate($form, &$form_state) {
|
||||
|
||||
//Make sure there is a CiviMember Membership Type and a Drupal Role selected.
|
||||
if (is_numeric($form_state['values']['add_rule']['select_group']) && is_numeric($form_state['values']['add_rule']['select_role'])) {
|
||||
if ($form_state['values']['add_rule']['select_group'] == 0 || $form_state['values']['add_rule']['select_role'] == 0) {
|
||||
form_set_error('add_rule', t('You must select both a CiviCRM Group and a Drupal Role from the "Association Rule" section.'));
|
||||
}
|
||||
}
|
||||
else {
|
||||
form_set_error('add_rule', t('Please select CiviCRM Group and Drupal Role.'));
|
||||
}
|
||||
|
||||
//Validate edit flag if set
|
||||
if (isset($form_state['values']['edit_flag']) && !is_numeric($form_state['values']['edit_flag'])) {
|
||||
for_set_error('', t('Edit flag was not numeric.'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_submit().
|
||||
*
|
||||
* For the add/edit rule form.
|
||||
*/
|
||||
function civicrm_group_roles_add_rule_form_submit($form, &$form_state) {
|
||||
if (!civicrm_initialize()) {
|
||||
return;
|
||||
}
|
||||
//If edit_flag is set then process as an edit form, if not then process as an add form.
|
||||
if (isset($form_state['values']['edit_flag'])) {
|
||||
|
||||
$edit_rule = db_update('civicrm_group_roles_rules')->fields(array(
|
||||
'role_id' => (int) $form_state['values']['add_rule']['select_role'],
|
||||
'group_id' => (int) $form_state['values']['add_rule']['select_group'],
|
||||
))->condition('id', (int) $form_state['values']['edit_flag'])->execute();
|
||||
|
||||
if ($edit_rule) {
|
||||
drupal_set_message(t('Your association rule has been edited.'));
|
||||
}
|
||||
}
|
||||
else {
|
||||
$add_rule = db_insert('civicrm_group_roles_rules')->fields(array(
|
||||
'role_id' => (int) $form_state['values']['add_rule']['select_role'],
|
||||
'group_id' => (int) $form_state['values']['add_rule']['select_group'],
|
||||
))->execute();
|
||||
|
||||
if ($add_rule) {
|
||||
drupal_set_message(t('Your association rule has been added.'));
|
||||
}
|
||||
}
|
||||
|
||||
$form_state['redirect'] = 'admin/config/civicrm/civicrm_group_roles';
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to add and remove users from groups, use after user_save to remove roles $roles = $edit['roles'] for user_save
|
||||
*
|
||||
* @param array $roles
|
||||
* list of role to add/remove
|
||||
* @param object $user
|
||||
* Drupal user object
|
||||
* @param string $op
|
||||
* either add or remove
|
||||
*/
|
||||
function civicrm_group_roles_add_remove_groups($roles, $user, $op) {
|
||||
if (!civicrm_initialize()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($op == 'add') {
|
||||
$txt = 'added';
|
||||
}
|
||||
elseif ($op == 'remove') {
|
||||
$txt = 'removed';
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
$debug_mode = FALSE;
|
||||
|
||||
// make sure user has other roles other than authenticated
|
||||
if ($roles) {
|
||||
//find the contact record
|
||||
$params = array(
|
||||
'version' => 3,
|
||||
'sequential' => 1,
|
||||
'return' => 'contact_id',
|
||||
'uf_id' => $user->uid,
|
||||
);
|
||||
$contact = civicrm_api('UFMatch', 'get', $params);
|
||||
|
||||
if (!empty($contact['values']) && !CRM_Utils_Array::value('is_error', $contact) && is_numeric($contact['values'][0]['contact_id'])) {
|
||||
$contact_id = CRM_Utils_Array::value('contact_id', $contact['values'][0]);
|
||||
|
||||
//loop over user's roles
|
||||
foreach ($roles as $rid => $role) {
|
||||
|
||||
// Find the group(s) for the role
|
||||
$result = db_select('civicrm_group_roles_rules', 'cgr')->fields('cgr', array('group_id'))->condition('role_id', $rid)->execute()->fetchAll();
|
||||
$groups = _civicrm_group_roles_validate_groups($result);
|
||||
foreach ($groups as $group) {
|
||||
//add the contact
|
||||
$gparams = array('version' => 3, 'group_id' => $group->group_id, 'contact_id' => $contact_id);
|
||||
if ($op == 'add') {
|
||||
$result = civicrm_api('GroupContact', 'create', $gparams);
|
||||
}
|
||||
else {
|
||||
$result = civicrm_api('GroupContact', 'delete', $gparams);
|
||||
}
|
||||
|
||||
if ($result['is_error'] > 0) {
|
||||
$msg = 'Error: Unable to sync role @role';
|
||||
$variables = array('@role' => $role);
|
||||
watchdog('civicrm_group_roles', $msg, $variables, WATCHDOG_ERROR);
|
||||
if ($debug_mode) {
|
||||
drupal_set_message(t('Error: Unable to sync role %role', array('%role' => $role)));
|
||||
}
|
||||
}
|
||||
elseif ($debug_mode && $result['values'][$txt] > 0) {
|
||||
drupal_set_message("$txt user $user->name Group: $role");
|
||||
drupal_set_message(var_export($result, TRUE));
|
||||
}
|
||||
elseif ($debug_mode) {
|
||||
drupal_set_message("User $user->name NOT $txt Group: $role");
|
||||
drupal_set_message(var_export($result, TRUE));
|
||||
}
|
||||
} //end foreach
|
||||
} //end foreach
|
||||
|
||||
} //end if contact_id
|
||||
|
||||
else {
|
||||
watchdog('civicrm_group_roles', $msg, $variables, WATCHDOG_ERROR);
|
||||
if ($debug_mode) {
|
||||
drupal_set_message(t('CiviCRM contact not found for Drupal user ID @id', array('@id' => $user->uid)));
|
||||
}
|
||||
}
|
||||
|
||||
} //endif $roles
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Manual sync form. Provides a submit button to manually sync groups to roles.
|
||||
*
|
||||
* @ingroup forms
|
||||
* @see civicrm_group_roles_manual_sync_submit()
|
||||
*/
|
||||
function civicrm_group_roles_manual_sync() {
|
||||
$form = array();
|
||||
$form['manual_sync'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Manual Synchronization'),
|
||||
'#description' => t('Manually synchronize CiviCRM group membership and Drupal roles according to the current association rules. This process may take a long time.'),
|
||||
);
|
||||
$form['manual_sync']['manual_sync_submit'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Synchronize now'),
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_submit().
|
||||
*
|
||||
* Dor the manual sync form.
|
||||
*/
|
||||
function civicrm_group_roles_manual_sync_submit($form, &$form_state) {
|
||||
if (!civicrm_initialize()) {
|
||||
return;
|
||||
}
|
||||
|
||||
return civicrm_group_roles_batch_init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Batch functions to manually update large number of users
|
||||
*/
|
||||
function civicrm_group_roles_batch_init() {
|
||||
|
||||
$batch = array(
|
||||
'title' => t('Updating Users...'),
|
||||
'operations' => array(),
|
||||
'init_message' => t('Starting Update'),
|
||||
'progress_message' => t('Processed @current out of @total.'),
|
||||
'error_message' => t('An error occurred during processing'),
|
||||
'finished' => 'civicrm_group_roles_batch_finished',
|
||||
'progressive' => FALSE,
|
||||
);
|
||||
|
||||
// Find all existing users
|
||||
$result = db_query('SELECT uid FROM {users}');
|
||||
|
||||
foreach ($result as $record) {
|
||||
$batch['operations'][] = array('civicrm_group_roles_batch_worker', array($record->uid));
|
||||
}
|
||||
|
||||
batch_set($batch);
|
||||
|
||||
batch_process('admin/config/civicrm/civicrm_group_roles');
|
||||
}
|
||||
|
||||
function civicrm_group_roles_batch_worker($uid, &$context) {
|
||||
if (!civicrm_initialize()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$account = user_load($uid);
|
||||
|
||||
if ($account !== FALSE) {
|
||||
|
||||
$roles = array_diff_key($account->roles, array(1 => 'anonymous user', 2 => 'authenticated user'));
|
||||
|
||||
// Add user to groups
|
||||
if ($roles) {
|
||||
civicrm_group_roles_add_remove_groups($roles, $account, 'add');
|
||||
}
|
||||
|
||||
// Add roles to user
|
||||
civicrm_group_roles_sync_roles($account);
|
||||
}
|
||||
|
||||
if (empty($context['results'])) {
|
||||
$context['results']['processed'] = 0;
|
||||
}
|
||||
$context['results']['processed']++;
|
||||
}
|
||||
|
||||
function civicrm_group_roles_batch_finished($success, $results, $operations) {
|
||||
if ($success) {
|
||||
$message = format_plural($results['processed'], 'One user processed.', '@count users processed.');
|
||||
}
|
||||
else {
|
||||
$message = 'some errors';
|
||||
}
|
||||
|
||||
drupal_set_message($message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters invalid groups out of a civicrm_group_roles_rules query result
|
||||
*
|
||||
* @param array $groups Result of a Drupal Query::execute() against
|
||||
* civicrm_group_roles_rules - An array of stdClass objects
|
||||
* having a group_id property
|
||||
* @return array
|
||||
*/
|
||||
function _civicrm_group_roles_validate_groups(array $groups) {
|
||||
foreach ($groups as $key => $group) {
|
||||
$groupId = $group->group_id;
|
||||
$group_result = civicrm_api('Group', 'get', array(
|
||||
'group_id' => $groupId,
|
||||
'sequential' => 1,
|
||||
'version' => 3,
|
||||
));
|
||||
|
||||
// CRM-16033: Ensure the group hasn't been deleted
|
||||
if ($group_result['count'] === 0) {
|
||||
$msg = 'Error: Cannot add contact to nonexistent group (ID @groupId)';
|
||||
$variables = array('@groupId' => $groupId);
|
||||
watchdog('civicrm_group_roles', $msg, $variables, WATCHDOG_ERROR);
|
||||
unset($groups[$key]);
|
||||
continue;
|
||||
}
|
||||
|
||||
// CRM-11161: Exclude smart groups as we don't want to add contacts statically to a smart group
|
||||
if (CRM_Utils_Array::value('saved_search_id', $group_result['values'][0])) {
|
||||
if (variable_get('civicrm_group_roles_debugging', 0)) {
|
||||
$msg = 'Group ID @groupId is a smart group, so the user was not added to it statically.';
|
||||
$variables = array('@groupId' => $groupId);
|
||||
watchdog('civicrm_group_roles', $msg, $variables, WATCHDOG_INFO);
|
||||
}
|
||||
unset($groups[$key]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return $groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to add and remove roles from a user depending on the groups
|
||||
* they are a member of
|
||||
*
|
||||
* @param $account object The user account being processed
|
||||
*/
|
||||
function civicrm_group_roles_sync_roles($account) {
|
||||
if (!civicrm_initialize()) {
|
||||
return;
|
||||
}
|
||||
|
||||
require_once 'api/api.php';
|
||||
require_once 'CRM/Core/BAO/UFMatch.php';
|
||||
|
||||
//find the contact record
|
||||
$contact = CRM_Core_BAO_UFMatch::getContactId($account->uid);
|
||||
if (!$contact) {
|
||||
return;
|
||||
}
|
||||
|
||||
// To account for the case of smart groups, we grab *all* the rules,
|
||||
// and look for this contact in a list of group members
|
||||
// CRM-11161
|
||||
$query = db_select('civicrm_group_roles_rules', 'cgr');
|
||||
$query->join('role', 'r', 'r.rid=cgr.role_id');
|
||||
$query->fields('r', array('name'))->fields('cgr', array('role_id', 'group_id'));
|
||||
|
||||
// Determine which group-role-sync'd roles the user should have.
|
||||
// Assemble a list of sync'd roles that the user currently has, in $currentSyncedRoles
|
||||
// and a list of sync'd roles that the user should have, in $correctSyncedRoles.
|
||||
$allCurrentRoleIDs = array_keys($account->roles);
|
||||
$currentSyncedRoles = array();
|
||||
$correctSyncedRoles = array();
|
||||
$result = $query->execute();
|
||||
foreach ($result as $group) {
|
||||
if (in_array($group->role_id, $allCurrentRoleIDs)) {
|
||||
$currentSyncedRoles[$group->role_id] = $group->name;
|
||||
}
|
||||
$params = array(
|
||||
'filter.group_id' => $group->group_id,
|
||||
'id' => $contact,
|
||||
'version' => 3,
|
||||
);
|
||||
$contacts = civicrm_api('contact', 'get', $params);
|
||||
// If we found a user
|
||||
if ($contacts['count'] > 0) {
|
||||
if (variable_get('civicrm_group_roles_debugging', 0)) {
|
||||
$message = 'Role @role (@rid) should be held by user @user (@uid) because they are part of group @group (contactID: @cid)';
|
||||
$params = array(
|
||||
'@role' => $group->name,
|
||||
'@rid' => $group->role_id,
|
||||
'@user' => $account->name,
|
||||
'@uid' => $account->uid,
|
||||
'@group' => $group->group_id,
|
||||
'@cid' => $contact,
|
||||
);
|
||||
watchdog('civicrm_group_roles', $message, $params, WATCHDOG_INFO);
|
||||
}
|
||||
$correctSyncedRoles[$group->role_id] = $group->name;
|
||||
}
|
||||
}
|
||||
|
||||
$rolesToAdd = array_diff_key($correctSyncedRoles, $currentSyncedRoles);
|
||||
$rolesToRemove = array_diff_key($currentSyncedRoles, $correctSyncedRoles);
|
||||
|
||||
$finalRoles = $account->roles + $rolesToAdd;
|
||||
$finalRoles = array_diff($finalRoles, $rolesToRemove);
|
||||
if (variable_get('civicrm_group_roles_debugging', 0)) {
|
||||
$params = array(
|
||||
'@initial' => print_r($account->roles, TRUE),
|
||||
'@add' => print_r($rolesToAdd, TRUE),
|
||||
'@remove' => print_r($rolesToRemove, TRUE),
|
||||
'@final' => print_r($finalRoles, TRUE),
|
||||
);
|
||||
watchdog('civicrm_group_roles', 'Initial roles: @initial, roles to add: @add, roles to remove: @remove, final roles: @final', $params, WATCHDOG_INFO);
|
||||
}
|
||||
|
||||
if ($account->roles !== $finalRoles) {
|
||||
user_save($account, array('roles' => $finalRoles));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings form
|
||||
*
|
||||
* @ingroup forms
|
||||
*/
|
||||
function civicrm_group_roles_settings($form, &$form_state) {
|
||||
|
||||
$form['civicrm_group_roles_debugging'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Enable detailed database logging'),
|
||||
'#default_value' => variable_get('civicrm_group_roles_debugging', 0),
|
||||
'#description' => 'Log the details of roles that are added and removed from users.',
|
||||
);
|
||||
|
||||
// Default handler to save form configuration
|
||||
return system_settings_form($form);
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
This module provides two-way synchronization between Drupal Roles and CiviCRM based on rules defined by the administrator.
|
||||
|
||||
Note that for now, removing from a Role does NOT remove the user from the CiviCRM group, so be sure to remove them manually from the group if you need to do so.
|
||||
|
||||
Original Author: Matt Chapman - http://drupal.org/user/143172
|
||||
|
||||
For support & feature requests, please visit http://forum.civicrm.org/
|
|
@ -0,0 +1,58 @@
|
|||
// $Id: CHANGELOG.txt,v 1.1.2.2 2008/09/01 04:43:43 posco Exp $
|
||||
|
||||
civimember_roles 6.x-3.0-beta1
|
||||
_____________________________________
|
||||
|
||||
- This is the first version of CiviMember Roles that works with Drupal 6.x
|
||||
and CiviCRM 2.1 alpha.
|
||||
|
||||
|
||||
civimember_roles 5.x-2.0
|
||||
_____________________________________
|
||||
|
||||
- This version works for CiviCRM 2.0 and Drupal 5.x. Use version
|
||||
5.x-1.2 if you are using CiviCRM 1.9 and Drupal 5.x.
|
||||
|
||||
|
||||
civimember_roles 5.x-2.0-alpha2
|
||||
_____________________________________
|
||||
|
||||
- Bug fixes from version 1.1 have been merged into version 2.0.
|
||||
|
||||
|
||||
civimember_roles 5.x-2.0-alpha1
|
||||
_____________________________________
|
||||
|
||||
- This release has all the same features as the 1.0 release but it works
|
||||
with CiviCRM 2.0 alpha 3 and Drupal 5.x.
|
||||
|
||||
|
||||
civimember_roles 5.x-1.2
|
||||
_____________________________________
|
||||
|
||||
- Major code revision. Drupal UID to CiviCRM Contact ID is done my the
|
||||
CRM_Core_BAO_UFMatch class now instead of by email. This should increase stability.
|
||||
- Added initial watchdog error reporting.
|
||||
- Permission work-around implemented. Normal users can now apply roles
|
||||
using various synchronize methods.
|
||||
|
||||
|
||||
civimember_roles 5.x-1.1
|
||||
_____________________________________
|
||||
|
||||
- #217237 by posco: Fixes a critical bug that prevents hook_cron() from
|
||||
running the sync function. Thanks to rallycivic for finding this bug.
|
||||
- #217201 by rallycivic: Fixed a bug that caused synchronization to fail if a
|
||||
Drupal user doesn't exist for every CiviCRM Contact.
|
||||
|
||||
|
||||
civimember_roles 5.x-1.0
|
||||
_____________________________________
|
||||
|
||||
- Beta status was lifted
|
||||
|
||||
|
||||
civimember_roles 5.x-1.0-beta1
|
||||
_____________________________________
|
||||
|
||||
- Initial version published on Drupal.org.
|
|
@ -0,0 +1,274 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc. 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. Everyone is permitted to copy and distribute
|
||||
verbatim copies of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your freedom to
|
||||
share and change it. By contrast, the GNU General Public License is
|
||||
intended to guarantee your freedom to share and change free software--to
|
||||
make sure the software is free for all its users. This General Public License
|
||||
applies to most of the Free Software Foundation's software and to any other
|
||||
program whose authors commit to using it. (Some other Free Software
|
||||
Foundation software is covered by the GNU Library General Public License
|
||||
instead.) You can apply it to your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not price. Our
|
||||
General Public Licenses are designed to make sure that you have the
|
||||
freedom to distribute copies of free software (and charge for this service if
|
||||
you wish), that you receive source code or can get it if you want it, that you
|
||||
can change the software or use pieces of it in new free programs; and that
|
||||
you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid anyone to
|
||||
deny you these rights or to ask you to surrender the rights. These restrictions
|
||||
translate to certain responsibilities for you if you distribute copies of the
|
||||
software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether gratis or for
|
||||
a fee, you must give the recipients all the rights that you have. You must make
|
||||
sure that they, too, receive or can get the source code. And you must show
|
||||
them these terms so they know their rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and (2)
|
||||
offer you this license which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain that
|
||||
everyone understands that there is no warranty for this free software. If the
|
||||
software is modified by someone else and passed on, we want its recipients
|
||||
to know that what they have is not the original, so that any problems
|
||||
introduced by others will not reflect on the original authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software patents. We
|
||||
wish to avoid the danger that redistributors of a free program will individually
|
||||
obtain patent licenses, in effect making the program proprietary. To prevent
|
||||
this, we have made it clear that any patent must be licensed for everyone's
|
||||
free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and modification
|
||||
follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND
|
||||
MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains a notice
|
||||
placed by the copyright holder saying it may be distributed under the terms
|
||||
of this General Public License. The "Program", below, refers to any such
|
||||
program or work, and a "work based on the Program" means either the
|
||||
Program or any derivative work under copyright law: that is to say, a work
|
||||
containing the Program or a portion of it, either verbatim or with
|
||||
modifications and/or translated into another language. (Hereinafter, translation
|
||||
is included without limitation in the term "modification".) Each licensee is
|
||||
addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not covered
|
||||
by this License; they are outside its scope. The act of running the Program is
|
||||
not restricted, and the output from the Program is covered only if its contents
|
||||
constitute a work based on the Program (independent of having been made
|
||||
by running the Program). Whether that is true depends on what the Program
|
||||
does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's source
|
||||
code as you receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice and
|
||||
disclaimer of warranty; keep intact all the notices that refer to this License
|
||||
and to the absence of any warranty; and give any other recipients of the
|
||||
Program a copy of this License along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and you
|
||||
may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion of it,
|
||||
thus forming a work based on the Program, and copy and distribute such
|
||||
modifications or work under the terms of Section 1 above, provided that you
|
||||
also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices stating that
|
||||
you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in whole or in
|
||||
part contains or is derived from the Program or any part thereof, to be
|
||||
licensed as a whole at no charge to all third parties under the terms of this
|
||||
License.
|
||||
|
||||
c) If the modified program normally reads commands interactively when run,
|
||||
you must cause it, when started running for such interactive use in the most
|
||||
ordinary way, to print or display an announcement including an appropriate
|
||||
copyright notice and a notice that there is no warranty (or else, saying that
|
||||
you provide a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this License.
|
||||
(Exception: if the Program itself is interactive but does not normally print such
|
||||
an announcement, your work based on the Program is not required to print
|
||||
an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If identifiable
|
||||
sections of that work are not derived from the Program, and can be
|
||||
reasonably considered independent and separate works in themselves, then
|
||||
this License, and its terms, do not apply to those sections when you distribute
|
||||
them as separate works. But when you distribute the same sections as part
|
||||
of a whole which is a work based on the Program, the distribution of the
|
||||
whole must be on the terms of this License, whose permissions for other
|
||||
licensees extend to the entire whole, and thus to each and every part
|
||||
regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest your rights to
|
||||
work written entirely by you; rather, the intent is to exercise the right to
|
||||
control the distribution of derivative or collective works based on the
|
||||
Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of a
|
||||
storage or distribution medium does not bring the other work under the scope
|
||||
of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it, under
|
||||
Section 2) in object code or executable form under the terms of Sections 1
|
||||
and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable source
|
||||
code, which must be distributed under the terms of Sections 1 and 2 above
|
||||
on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three years, to give
|
||||
any third party, for a charge no more than your cost of physically performing
|
||||
source distribution, a complete machine-readable copy of the corresponding
|
||||
source code, to be distributed under the terms of Sections 1 and 2 above on
|
||||
a medium customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer to distribute
|
||||
corresponding source code. (This alternative is allowed only for
|
||||
noncommercial distribution and only if you received the program in object
|
||||
code or executable form with such an offer, in accord with Subsection b
|
||||
above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source code
|
||||
means all the source code for all modules it contains, plus any associated
|
||||
interface definition files, plus the scripts used to control compilation and
|
||||
installation of the executable. However, as a special exception, the source
|
||||
code distributed need not include anything that is normally distributed (in
|
||||
either source or binary form) with the major components (compiler, kernel,
|
||||
and so on) of the operating system on which the executable runs, unless that
|
||||
component itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering access to
|
||||
copy from a designated place, then offering equivalent access to copy the
|
||||
source code from the same place counts as distribution of the source code,
|
||||
even though third parties are not compelled to copy the source along with the
|
||||
object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program except as
|
||||
expressly provided under this License. Any attempt otherwise to copy,
|
||||
modify, sublicense or distribute the Program is void, and will automatically
|
||||
terminate your rights under this License. However, parties who have received
|
||||
copies, or rights, from you under this License will not have their licenses
|
||||
terminated so long as such parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not signed it.
|
||||
However, nothing else grants you permission to modify or distribute the
|
||||
Program or its derivative works. These actions are prohibited by law if you
|
||||
do not accept this License. Therefore, by modifying or distributing the
|
||||
Program (or any work based on the Program), you indicate your acceptance
|
||||
of this License to do so, and all its terms and conditions for copying,
|
||||
distributing or modifying the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the original
|
||||
licensor to copy, distribute or modify the Program subject to these terms and
|
||||
conditions. You may not impose any further restrictions on the recipients'
|
||||
exercise of the rights granted herein. You are not responsible for enforcing
|
||||
compliance by third parties to this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues), conditions
|
||||
are imposed on you (whether by court order, agreement or otherwise) that
|
||||
contradict the conditions of this License, they do not excuse you from the
|
||||
conditions of this License. If you cannot distribute so as to satisfy
|
||||
simultaneously your obligations under this License and any other pertinent
|
||||
obligations, then as a consequence you may not distribute the Program at all.
|
||||
For example, if a patent license would not permit royalty-free redistribution
|
||||
of the Program by all those who receive copies directly or indirectly through
|
||||
you, then the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any
|
||||
particular circumstance, the balance of the section is intended to apply and
|
||||
the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any patents or
|
||||
other property right claims or to contest validity of any such claims; this
|
||||
section has the sole purpose of protecting the integrity of the free software
|
||||
distribution system, which is implemented by public license practices. Many
|
||||
people have made generous contributions to the wide range of software
|
||||
distributed through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing to
|
||||
distribute software through any other system and a licensee cannot impose
|
||||
that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to be a
|
||||
consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in certain
|
||||
countries either by patents or by copyrighted interfaces, the original copyright
|
||||
holder who places the Program under this License may add an explicit
|
||||
geographical distribution limitation excluding those countries, so that
|
||||
distribution is permitted only in or among countries not thus excluded. In such
|
||||
case, this License incorporates the limitation as if written in the body of this
|
||||
License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will be
|
||||
similar in spirit to the present version, but may differ in detail to address new
|
||||
problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program specifies
|
||||
a version number of this License which applies to it and "any later version",
|
||||
you have the option of following the terms and conditions either of that
|
||||
version or of any later version published by the Free Software Foundation. If
|
||||
the Program does not specify a version number of this License, you may
|
||||
choose any version ever published by the Free Software Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free programs
|
||||
whose distribution conditions are different, write to the author to ask for
|
||||
permission. For software which is copyrighted by the Free Software
|
||||
Foundation, write to the Free Software Foundation; we sometimes make
|
||||
exceptions for this. Our decision will be guided by the two goals of
|
||||
preserving the free status of all derivatives of our free software and of
|
||||
promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE,
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT
|
||||
PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE
|
||||
STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||
OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT
|
||||
WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND
|
||||
PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
|
||||
NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR
|
||||
AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR
|
||||
ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE
|
||||
LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL,
|
||||
SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES
|
||||
ARISING OUT OF THE USE OR INABILITY TO USE THE
|
||||
PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA
|
||||
OR DATA BEING RENDERED INACCURATE OR LOSSES
|
||||
SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE
|
||||
PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN
|
||||
IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF
|
||||
THE POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
|
@ -0,0 +1,85 @@
|
|||
// $Id: README.txt,v 1.2.2.2.2.1 2008/09/01 04:43:43 posco Exp $
|
||||
|
||||
============================
|
||||
CiviMember Roles Sync Readme
|
||||
============================
|
||||
|
||||
Requirements
|
||||
-------------------------------
|
||||
|
||||
This module requires CiviCRM 2.1.x or greater and Drupal 6.x. In order to use this module with
|
||||
other versions of Drupal and CiviCRM, please see the available versions
|
||||
at http://drupal.org/project/civimember_roles.
|
||||
|
||||
|
||||
Installation Instructions
|
||||
-------------------------------
|
||||
|
||||
To install the CiviMember Roles Sync module, unpack the .tar.gz archive
|
||||
file and move the `civimember_roles` directory to your sites' `modules` directory.
|
||||
Then navigate to Administer > Site building > Modules and enable the CiviMember
|
||||
Roles Sync module.
|
||||
|
||||
Refer to the Drupal documentation for further information on how to install modules.
|
||||
|
||||
|
||||
How to Use
|
||||
-------------------------------
|
||||
|
||||
After you have installed CiviMember Roles Sync following the above instructions,
|
||||
navigate to Administer > Site configuration > CiviMember Roles Sync. If you do not see
|
||||
this link, make sure you have given yourself permission to see it in the
|
||||
Administer > User management > Permissions section of Drupal.
|
||||
|
||||
Here you will be able to create "association rules." These rules determine how
|
||||
CiviMember Roles Sync should synchronize CiviMember Membership Types
|
||||
to Drupal Roles. Click the "Add Association Rule" tab to add your first rule. Select
|
||||
the CiviMember Membership Type and Drupal Role you wish to associate and then
|
||||
select the CiviMember Status Rules you wish to use. Currently, CiviMember Roles
|
||||
Sync only knows about two different kinds of rules: "Current" and "Expired." Any
|
||||
CiviMember Status Rule that is assigned to "Current" will be used to determine
|
||||
if a CiviCRM Contact's Drupal account should be given the role. Any CiviMember
|
||||
Status Rule that is assigned to "Expired" will be used to determine if a CiviCRM
|
||||
Contact's Drupal account should have the role removed. After you have finished
|
||||
filling out the form, click the "Add association rule" button to add the rule.
|
||||
|
||||
Next, click the Configure tab. This form allows you to configure how CiviMember
|
||||
Roles Sync should automatically synchronize Membership Types to Roles, or if
|
||||
it should do this automatically at all. If you choose the user login/logout method
|
||||
you may need to use the "Manually Synchronize" form each time you add an
|
||||
association rule in order to synchronize all Drupal Users initially. Otherwise,
|
||||
each users' roles will be updated on an individual basis each time they login or
|
||||
logout. If you select the Drupal cron method, all users' roles will be updated
|
||||
periodically each time the Drupal cron function is ran. Please refer to the Drupal
|
||||
documentation on how to configure Drupal cron.
|
||||
|
||||
User Import
|
||||
-------------------------------
|
||||
|
||||
Each CiviCRM Contact on your site will need a corresponding Drupal User account
|
||||
in order for CiviMember Roles Sync to synchronize Membership Types to Roles.
|
||||
Refer to the CiviCRM documentation:
|
||||
|
||||
http://wiki.civicrm.org/confluence/display/CRMDOC/Creating+a+Drupal+user+for+every+CiviCRM+contact
|
||||
|
||||
When a new Drupal account is created a new CiviCRM Contact will also be
|
||||
created. So you will only have to worry about the CiviCRM Contacts that you
|
||||
import into CiviCRM from a source outside of Drupal.
|
||||
|
||||
|
||||
Contact Information
|
||||
-------------------------------
|
||||
|
||||
All feedback and comments of a technical nature (including support questions)
|
||||
should be posted on the CiviMember Roles Sync project page at http://drupal.org/project/civimember_roles.
|
||||
For all other comments you can reach me at the following e-mail address. Please
|
||||
include "CiviMember Roles Sync" somewhere in the subject.
|
||||
|
||||
ngoodman AT wisc.edu
|
||||
|
||||
|
||||
License Information
|
||||
-------------------------------
|
||||
|
||||
Copyright (C) Neil Goodman 2010
|
||||
Released under GNU General Public License version 2 or later
|
|
@ -0,0 +1,7 @@
|
|||
This folder contains the member/role synchronization module for
|
||||
CiviCRM-Drupal. It does NOT contain tests for core functionality. (For
|
||||
tests of core functionality, see https://github.com/civicrm/civicrm-core .)
|
||||
|
||||
At time of writing, these tests execute within the context of the default
|
||||
Drupal database. Consequently, you must be quite careful to write tests
|
||||
which don't leave a mess in the database.
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Implements hook_drush_command().
|
||||
*
|
||||
* In this hook, you specify which commands your
|
||||
* drush module makes available, what it does and
|
||||
* description.
|
||||
*
|
||||
* Notice how this structure closely resembles how
|
||||
* you define menu hooks.
|
||||
*
|
||||
* @See drush_parse_command() for a list of recognized keys.
|
||||
*
|
||||
*/
|
||||
function civicrm_member_roles_drush_command() {
|
||||
$items = array();
|
||||
// the key in the $items array is the name of the command.
|
||||
$items['civicrm-member-role-sync'] = array(
|
||||
'description' => 'Run CiviCRM Member Role Sync',
|
||||
'examples' => array(
|
||||
'drush civicrm-member-role-sync --uid=8',
|
||||
'drush civicrm-member-role-sync --contact_id=89',
|
||||
),
|
||||
'options' => array(
|
||||
'uid' => 'Optional User ID',
|
||||
'contact_id' => 'Optional Contact ID',
|
||||
),
|
||||
'aliases' => array('cmrs'),
|
||||
);
|
||||
return $items;
|
||||
}
|
||||
/**
|
||||
* (Drush callback)
|
||||
*
|
||||
* Implementation of command 'civicrm-member-role-sync'
|
||||
*/
|
||||
function drush_civicrm_member_roles_civicrm_member_role_sync($uid = NULL, $contact_id = NULL) {
|
||||
return _civicrm_member_roles_sync(drush_get_option('uid'), drush_get_option('contact_id'));
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
name = CiviMember Roles Sync
|
||||
description = Synchronize CiviCRM Contacts with Membership Status to a specified Drupal Role both automatically and manually.
|
||||
version = 7.x-4.7.29
|
||||
core = 7.x
|
||||
package = CiviCRM
|
||||
project = civicrm
|
||||
|
||||
dependencies[] = civicrm
|
||||
|
||||
configure = admin/config/civicrm/civicrm_member_roles
|
||||
files[] = civicrm_member_roles.module
|
||||
files[] = civicrm_member_roles.install
|
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
// $Id: civicrm_member_roles.install,v 1.2.4.2 2008/08/17 21:44:19 posco Exp $
|
||||
|
||||
|
||||
/**
|
||||
* Copyright (C) 2010 Neil Goodman
|
||||
* @license GNU General Public License version 2 or later
|
||||
*
|
||||
* @file
|
||||
* Install CiviMember Role Sync database table and provide hook_uninstall.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_enable().
|
||||
*/
|
||||
function civicrm_member_roles_enable() {
|
||||
db_query("UPDATE {system} SET weight = 110 WHERE name = 'civicrm_member_roles'");
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_schema().
|
||||
*/
|
||||
function civicrm_member_roles_schema() {
|
||||
$schema['civicrm_member_roles_rules'] = array(
|
||||
'fields' => array(
|
||||
'rule_id' => array(
|
||||
'type' => 'serial',
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'rid' => array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'type_id' => array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'status_codes' => array(
|
||||
'type' => 'text',
|
||||
'not null' => TRUE,
|
||||
),
|
||||
),
|
||||
'primary key' => array('rule_id'),
|
||||
);
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_uninstall().
|
||||
*/
|
||||
function civicrm_member_roles_uninstall() {
|
||||
variable_del('civicrm_member_roles_sync_method');
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate the old integer-based data format for synchronization settings to
|
||||
* the array-based format which supports multiple sync options.
|
||||
*/
|
||||
function civicrm_member_roles_update_7400() {
|
||||
// Get the current sync method and see if a format update is needed.
|
||||
$sync_method = variable_get('civicrm_member_roles_sync_method');
|
||||
if (is_numeric($sync_method)) {
|
||||
// Translate the old value to the new.
|
||||
switch ($sync_method) {
|
||||
case '0':
|
||||
variable_set('civicrm_member_roles_sync_method', array('login'));
|
||||
break;
|
||||
|
||||
case '1':
|
||||
variable_set('civicrm_member_roles_sync_method', array('cron'));
|
||||
break;
|
||||
|
||||
case '2':
|
||||
variable_set('civicrm_member_roles_sync_method', array());
|
||||
break;
|
||||
|
||||
case '3':
|
||||
variable_set('civicrm_member_roles_sync_method', array('update'));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,680 @@
|
|||
<?php
|
||||
// $Id: civicrm_member_roles.module,v 1.3.2.4.2.5 2008/09/01 04:17:11 posco Exp $
|
||||
|
||||
|
||||
/**
|
||||
* Copyright (C) 2010 Neil Goodman
|
||||
* @license GNU General Public License version 2 or later
|
||||
*
|
||||
* @file
|
||||
* Synchronize CiviCRM Contacts with Membership Status to a specified Drupal Role both automatically and manually.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_menu().
|
||||
*/
|
||||
function civicrm_member_roles_menu() {
|
||||
if (!civicrm_initialize()) {
|
||||
return;
|
||||
}
|
||||
$items = array();
|
||||
$items['admin/config/civicrm/civicrm_member_roles'] = array(
|
||||
'title' => 'CiviMember Roles Sync',
|
||||
'description' => 'Add/remove association rules and configure settings. Also perform manual synchronization.',
|
||||
'page callback' => 'civicrm_member_roles_show_rules',
|
||||
'access callback' => 'user_access',
|
||||
'access arguments' => array('access civicrm member role setting'),
|
||||
'type' => MENU_NORMAL_ITEM,
|
||||
);
|
||||
|
||||
$items['admin/config/civicrm/civicrm_member_roles/show_rules'] = array(
|
||||
'title' => 'List Association Rule(s)',
|
||||
'access callback' => 'user_access',
|
||||
'access arguments' => array('access civicrm member role setting'),
|
||||
'weight' => -5,
|
||||
'type' => MENU_DEFAULT_LOCAL_TASK,
|
||||
);
|
||||
|
||||
$items['admin/config/civicrm/civicrm_member_roles/add_rule'] = array(
|
||||
'title' => 'Add Association Rule',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('civicrm_member_roles_add_rule_form'),
|
||||
'access callback' => 'user_access',
|
||||
'access arguments' => array('access civicrm member role setting'),
|
||||
'type' => MENU_LOCAL_TASK,
|
||||
);
|
||||
|
||||
$items['admin/config/civicrm/civicrm_member_roles/add_rule/%rule_id'] = array(
|
||||
'title' => 'Add Association Rule',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('civicrm_member_roles_add_rule_form', 1),
|
||||
'access callback' => 'user_access',
|
||||
'access arguments' => array('access civicrm member role setting'),
|
||||
'type' => MENU_LOCAL_TASK,
|
||||
);
|
||||
|
||||
$items['admin/config/civicrm/civicrm_member_roles/configure'] = array(
|
||||
'title' => 'Configure',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('civicrm_member_roles_configure'),
|
||||
'access callback' => 'user_access',
|
||||
'access arguments' => array('access civicrm member role setting'),
|
||||
'type' => MENU_LOCAL_TASK,
|
||||
);
|
||||
|
||||
$items['admin/config/civicrm/civicrm_member_roles/manual_sync'] = array(
|
||||
'title' => 'Manually Synchronize',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('civicrm_member_roles_manual_sync'),
|
||||
'access callback' => 'user_access',
|
||||
'access arguments' => array('access civicrm member role setting'),
|
||||
'type' => MENU_LOCAL_TASK,
|
||||
);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_permission().
|
||||
*/
|
||||
function civicrm_member_roles_permission() {
|
||||
return array(
|
||||
'access civicrm member role setting' => array(
|
||||
'title' => t('Access CiviCRM member role setting'),
|
||||
'description' => t('Access Civicrm member roles synchronization.'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_user_login().
|
||||
*/
|
||||
function civicrm_member_roles_user_login(&$edit, $account) {
|
||||
civicrm_member_roles_sync_user($account);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_user_logout().
|
||||
*/
|
||||
function civicrm_member_roles_user_logout($account) {
|
||||
civicrm_member_roles_sync_user($account);
|
||||
}
|
||||
|
||||
function civicrm_member_roles_sync_user($account) {
|
||||
if (!civicrm_initialize()) {
|
||||
return;
|
||||
}
|
||||
if (in_array('login', variable_get('civicrm_member_roles_sync_method', array('login')), TRUE)) {
|
||||
_civicrm_member_roles_sync($account->uid);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_cron().
|
||||
*/
|
||||
function civicrm_member_roles_cron() {
|
||||
if (!civicrm_initialize(TRUE)) {
|
||||
return;
|
||||
}
|
||||
if (in_array('cron', variable_get('civicrm_member_roles_sync_method', array('login')), TRUE)) {
|
||||
_civicrm_member_roles_sync(NULL, NULL, 'cron');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show stored association rules and delete rules.
|
||||
*/
|
||||
function civicrm_member_roles_show_rules($action = NULL, $id = NULL) {
|
||||
if (!civicrm_initialize()) {
|
||||
return;
|
||||
}
|
||||
//Delete rule
|
||||
if ($action == 'delete') {
|
||||
if (is_numeric($id)) {
|
||||
$delete = db_delete('civicrm_member_roles_rules')->condition('rule_id', $id)->execute();
|
||||
if ($delete) {
|
||||
drupal_set_message(t('Rule ID !1 was successfully deleted.', array('!1' => $id)));
|
||||
}
|
||||
else {
|
||||
drupal_set_message(t('There was an error deleting the association rule. Please check your database settings and try again. If you continue to get this error message then try to reinstall CiviMember Roles Sync.'), $type = 'error');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$status = _civicrm_member_roles_get_data('status');
|
||||
$type = _civicrm_member_roles_get_data('types');
|
||||
$roles = user_roles(TRUE);
|
||||
|
||||
//Begin building main output table.
|
||||
$header = array(
|
||||
'rid' => t('Rule ID'),
|
||||
'rule_name' => t('Rule Name ("CiviMember Membership Type" --> "Drupal Role")'),
|
||||
'current_code' => t('Add When Status Is'),
|
||||
'expired_code' => t('Remove When Status Is'),
|
||||
'options' => t('Operation'),
|
||||
);
|
||||
$data = array();
|
||||
|
||||
$rules = db_select('civicrm_member_roles_rules', 'cmr')->fields('cmr')->orderBy('rule_id', 'ASC')->execute()->fetchAll();
|
||||
foreach ($rules as $result) {
|
||||
$codes = unserialize($result->status_codes);
|
||||
$current = "";
|
||||
$expired = "";
|
||||
foreach ($codes['current'] as $value) {
|
||||
$current .= $status[$value] . ", ";
|
||||
}
|
||||
|
||||
foreach ($codes['expired'] as $value) {
|
||||
$expired .= $status[$value] . ", ";
|
||||
}
|
||||
|
||||
$data[] = array(
|
||||
'rid' => check_plain($result->rule_id),
|
||||
'rule_name' => check_plain($type[$result->type_id] . " --> " . $roles[$result->rid]),
|
||||
'current_code' => check_plain(trim($current, ", ")),
|
||||
'expired_code' => check_plain(trim($expired, ", ")),
|
||||
'options' => l(t('edit'), 'admin/config/civicrm/civicrm_member_roles/add_rule' . '/' . check_plain($result->rule_id)) . ' ' . l(t('delete'), 'admin/config/civicrm/civicrm_member_roles/delete' . '/' . check_plain($result->rule_id)),
|
||||
);
|
||||
}
|
||||
|
||||
if (!empty($data)) {
|
||||
$output['data'] = array(
|
||||
'#prefix' => t("Use the 'Add Association Rule' form to add new rules.") . '<br/><br/>',
|
||||
'#theme' => 'table',
|
||||
'#header' => $header,
|
||||
'#rows' => $data,
|
||||
);
|
||||
}
|
||||
else {
|
||||
$output = t("There are no rules currently set. Use the 'Add Association Rule' form to add one.");
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Manual sync form. Provides a sumbit button to manually sync memberships to roles.
|
||||
*
|
||||
* @ingroup forms
|
||||
* @see civicrm_member_roles_manual_sync_submit()
|
||||
*/
|
||||
function civicrm_member_roles_manual_sync() {
|
||||
$form = array();
|
||||
$form['manual_sync'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Manual Synchronization:'),
|
||||
);
|
||||
$form['manual_sync']['manual_sync_submit'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Synchronize CiviMember Membership Types to Drupal Roles now'),
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_submit().
|
||||
*
|
||||
* For the manual sync form.
|
||||
*/
|
||||
function civicrm_member_roles_manual_sync_submit($form, &$form_state) {
|
||||
if (!civicrm_initialize()) {
|
||||
return;
|
||||
}
|
||||
if (_civicrm_member_roles_sync()) {
|
||||
drupal_set_message(t('CiviMember Memberships and Drupal Roles have been synchronized using available rules. Note: if no association rules exist then synchronization has not been completed.'));
|
||||
}
|
||||
else {
|
||||
drupal_set_message(t('There was an error. CiviMember Memberships and Drupal Roles could not be synchronized.'), $type = 'error');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configuration form. Allows user to edit the Automatic Synchronization Method.
|
||||
*
|
||||
* @ingroup forms
|
||||
*/
|
||||
function civicrm_member_roles_configure() {
|
||||
$form = array();
|
||||
$form['settings'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Settings'),
|
||||
);
|
||||
$form['settings']['civicrm_member_roles_sync_method'] = array(
|
||||
'#type' => 'checkboxes',
|
||||
'#title' => t('Automatic Synchronization Method'),
|
||||
'#description' => t('Select which method CiviMember Roles Sync will use to automatically synchronize Memberships and Roles. If you choose user login/logout, you will have to run an initial "Manual Synchronization" after you create a new rule for it to be applied to all users and contacts. If you do not select an option, automatic synchronization will be disabled. You will have to use the "Manually Synchronize" form to synchronize memberships and roles yourself. Leave the default setting if you are unsure which method to use.'),
|
||||
'#default_value' => variable_get('civicrm_member_roles_sync_method', array('login')),
|
||||
'#options' => array(
|
||||
'login' => t('Synchronize whenever a user logs in or logs out. This action is performed only on the user logging in or out.'),
|
||||
'cron' => t('Synchronize when Drupal cron is ran. This action will be performed on all users and contacts.'),
|
||||
'update' => t('Synchronize when membership is updated.'),
|
||||
),
|
||||
);
|
||||
$form['settings']['civicrm_member_roles_cron_limit'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Memberships Synchronized on Cron'),
|
||||
'#description' => t('Enter how many Memberships and Roles you would like to synchronize per cron run. Synchronization will be performed randomly. This prevents the operation from timing out when too many items are processed at once. If this is empty, all Memberships and Roles will be processed.'),
|
||||
'#default_value' => variable_get('civicrm_member_roles_cron_limit', 150),
|
||||
'#element_validate' => array('element_validate_integer_positive'),
|
||||
'#size' => 15,
|
||||
'#maxlength' => 4,
|
||||
);
|
||||
|
||||
return system_settings_form($form);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form().
|
||||
*
|
||||
* Add/edit association rules.
|
||||
*
|
||||
* @ingroup forms
|
||||
* @see civicrm_member_roles_add_rule_validate()
|
||||
* @see civicrm_member_roles_add_rule_submit()
|
||||
*/
|
||||
function civicrm_member_roles_add_rule_form($form = NULL, $form_state = NULL, $id = NULL) {
|
||||
if (!civicrm_initialize()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$membership_options = _civicrm_member_roles_get_data('types');
|
||||
$status_options = _civicrm_member_roles_get_data('status');
|
||||
$roles = user_roles(TRUE);
|
||||
|
||||
//Let's get rid of the authenticated role as it is a useless option for this module
|
||||
unset($roles[2]);
|
||||
|
||||
//Begin add form
|
||||
$form = array();
|
||||
$form['add_rule'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Association Rule'),
|
||||
'#description' => t('Choose a CiviMember Membership Type and a Drupal Role below. This will associate that Membership with the Role. If you would like the have the same Membership be associated with more than one role, you will need to add a second association rule after you have completed this one.'),
|
||||
'#tree' => TRUE,
|
||||
'#parents' => array('add_rule'),
|
||||
);
|
||||
$form['add_rule']['select_membership'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Select a CiviMember Membership Type'),
|
||||
'#options' => $membership_options,
|
||||
'#required' => TRUE,
|
||||
);
|
||||
$form['add_rule']['select_role'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Select a Drupal Role'),
|
||||
'#options' => $roles,
|
||||
'#required' => TRUE,
|
||||
);
|
||||
$form['status_code'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('CiviMember Status Rules'),
|
||||
'#description' => t('Select which CiviMember Statuses will be used to add or remove from the Drupal Role. An "Add" status rule will add the above role to a user account. A "Removal" status rule will remove the above role from a user account.'),
|
||||
'#tree' => TRUE,
|
||||
);
|
||||
$form['status_code']['current'] = array(
|
||||
'#type' => 'checkboxes',
|
||||
'#title' => t('Add Statuses'),
|
||||
'#description' => t("Select all CiviMember Status Rule(s) that represent an 'add' status."),
|
||||
'#options' => $status_options,
|
||||
'#required' => TRUE,
|
||||
);
|
||||
$form['status_code']['expired'] = array(
|
||||
'#type' => 'checkboxes',
|
||||
'#title' => t('Removal Statuses'),
|
||||
'#description' => t("Select all CiviMember Status Rule(s) that represent a 'removal' status."),
|
||||
'#options' => $status_options,
|
||||
'#required' => TRUE,
|
||||
);
|
||||
$form['submit'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Add association rule'),
|
||||
);
|
||||
|
||||
//Begin edit form
|
||||
if (!empty($id) && is_numeric($id)) {
|
||||
|
||||
$default_values = db_select('civicrm_member_roles_rules', 'cmr')->fields('cmr')->condition('rule_id', $id)->execute()->fetchObject();
|
||||
if (!$default_values) {
|
||||
drupal_set_message(t('There was an error in obtaining the association rule for edit. Please check your database settings and try again. If you continue to get this error message then try to reinstall CiviMember Roles Sync.'));
|
||||
return $form;
|
||||
}
|
||||
|
||||
$codes = unserialize($default_values->status_codes);
|
||||
foreach ($codes['current'] as $key => $value) {
|
||||
$codes['current'][$key] = check_plain($value);
|
||||
}
|
||||
foreach ($codes['expired'] as $key => $value) {
|
||||
$codes['expired'][$key] = check_plain($value);
|
||||
}
|
||||
|
||||
//Alter above add form with default values.
|
||||
$form['add_rule']['select_membership']['#default_value'] = $default_values->type_id;
|
||||
$form['add_rule']['select_role']['#default_value'] = $default_values->rid;
|
||||
$form['status_code']['current']['#default_value'] = $codes['current'];
|
||||
$form['status_code']['expired']['#default_value'] = $codes['expired'];
|
||||
$form['edit_flag'] = array('#type' => 'hidden', '#value' => check_plain($id));
|
||||
$form['submit']['#value'] = t('Edit association rule');
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_validate().
|
||||
*
|
||||
* For the add/edit rule form.
|
||||
*/
|
||||
function civicrm_member_roles_add_rule_form_validate($form, &$form_state) {
|
||||
//Make sure there is a CiviMember Membership Type and a Drupal Role selected.
|
||||
if (is_numeric($form_state['values']['add_rule']['select_membership']) && is_numeric($form_state['values']['add_rule']['select_role'])) {
|
||||
if ($form_state['values']['add_rule']['select_membership'] == 0 || $form_state['values']['add_rule']['select_role'] == 0) {
|
||||
form_set_error('add_rule', t('You must select both a CiviMember Membership Type and a Drupal Role from the "Association Rule" section.'));
|
||||
}
|
||||
}
|
||||
else {
|
||||
form_set_error('add_rule', t('CiviMember Membership Type and Drupal Role values were not numeric.'));
|
||||
}
|
||||
|
||||
//Check for conflicting status rules.
|
||||
foreach ($form_state['values']['status_code']['current'] as $current_key => $current_value) {
|
||||
if (is_numeric($form_state['values']['status_code']['expired'][$current_key]) && is_numeric($current_value)) {
|
||||
if ($form_state['values']['status_code']['expired'][$current_key] > 0 && $current_value > 0) {
|
||||
form_set_error('', t('You can not have the same Status Rule registered as both "Current" and "Expired".'));
|
||||
}
|
||||
}
|
||||
else {
|
||||
form_set_error('', t('Status Rules values were not numeric.'));
|
||||
}
|
||||
}
|
||||
|
||||
//Validate edit flag if set
|
||||
if (isset($form_state['values']['edit_flag']) && !is_numeric($form_state['values']['edit_flag'])) {
|
||||
form_set_error('', t('Edit flag was not numeric.'));
|
||||
}
|
||||
|
||||
//Validate duplicate rules
|
||||
if (!isset($form_state['values']['edit_flag'])) {
|
||||
$result = FALSE;
|
||||
$membershipTypeId = (int) $form_state['values']['add_rule']['select_membership'];
|
||||
$roleId = (int) $form_state['values']['add_rule']['select_role'];
|
||||
|
||||
$sql = db_select('civicrm_member_roles_rules', 'cmr')->fields('cmr')->condition('rid', $roleId)->condition('type_id', $membershipTypeId)->execute()->fetchAll();
|
||||
foreach ($sql as $values) {
|
||||
if ($values) {
|
||||
$result = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($result) {
|
||||
form_set_error('', t('This rule set is already exist in data base.'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_submit().
|
||||
*
|
||||
* For the add/edit rule form.
|
||||
*/
|
||||
function civicrm_member_roles_add_rule_form_submit($form, &$form_state) {
|
||||
if (!civicrm_initialize()) {
|
||||
return;
|
||||
}
|
||||
//Build array of status rules in order to serialize into the database
|
||||
$codes = array('current', 'expired');
|
||||
$codes['current'] = array();
|
||||
$codes['expired'] = array();
|
||||
|
||||
foreach ($form_state['values']['status_code']['current'] as $key => $value) {
|
||||
if ($form_state['values']['status_code']['expired'][$key] > 0) {
|
||||
$codes['expired'][] = $form_state['values']['status_code']['expired'][$key];
|
||||
}
|
||||
elseif ($value > 0) {
|
||||
$codes['current'][] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
//If edit_flag is set then process as an edit form, if not then process as an add form.
|
||||
if (isset($form_state['values']['edit_flag'])) {
|
||||
$edit_rule = db_update('civicrm_member_roles_rules')->fields(array(
|
||||
'rid' => (int) $form_state['values']['add_rule']['select_role'],
|
||||
'type_id' => (int) $form_state['values']['add_rule']['select_membership'],
|
||||
'status_codes' => serialize($codes),
|
||||
))->condition('rule_id', (int) $form_state['values']['edit_flag'])->execute();
|
||||
|
||||
if ($edit_rule) {
|
||||
drupal_set_message(t('Your association rule has been edited.'));
|
||||
}
|
||||
}
|
||||
else {
|
||||
$add_rule = db_insert('civicrm_member_roles_rules')->fields(array(
|
||||
'rid' => (int) $form_state['values']['add_rule']['select_role'],
|
||||
'type_id' => (int) $form_state['values']['add_rule']['select_membership'],
|
||||
'status_codes' => serialize($codes),
|
||||
))->execute();
|
||||
if ($add_rule) {
|
||||
drupal_set_message(t('Your association rule has been added.'));
|
||||
}
|
||||
else {
|
||||
drupal_set_message(t('There was an error adding the association rule. Please check your database settings and try again. If you continue to get this error message then try to reinstall CiviMember Roles Sync.'), $type = 'error');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds members and applies roles based on the rules defined in the settings page. If the ext_uid param is defined then
|
||||
* this function will only sync one user.
|
||||
*
|
||||
* @param string $sync_type
|
||||
* Whether we are syncing on cron, login, etc. Only cron is handled at this time.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function _civicrm_member_roles_sync($ext_uid = NULL, $cid = NULL, $sync_type = NULL) {
|
||||
if (!civicrm_initialize()) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$rules = db_query('SELECT * FROM {civicrm_member_roles_rules}')->fetchAll();
|
||||
if (empty($rules) || $rules === FALSE) {
|
||||
return FALSE;
|
||||
}
|
||||
$memberroles = $rid = array();
|
||||
foreach ($rules as $ruleValues) {
|
||||
$memberroles[$ruleValues->type_id][] = array(
|
||||
'rid' => $ruleValues->rid,
|
||||
'codes' => unserialize($ruleValues->status_codes),
|
||||
);
|
||||
$rid[] = $ruleValues->rid;
|
||||
}
|
||||
//Find all contacts that have membership rules (or just use $ext_uid)
|
||||
if (empty($ext_uid) && empty($cid)) {
|
||||
// Get the number of contacts to sync at once, if we're syncing on cron.
|
||||
$cron_limit = variable_get('civicrm_member_roles_cron_limit', 150);
|
||||
if ($sync_type == 'cron' && is_numeric($cron_limit) && $cron_limit > 0) {
|
||||
$sql = "SELECT DISTINCT uf.contact_id FROM civicrm_uf_match uf
|
||||
LEFT JOIN civicrm_membership m ON uf.contact_id = m.contact_id
|
||||
WHERE m.id IS NOT NULL AND m.membership_type_id IN (" . implode(',', array_keys($memberroles)) . ")
|
||||
ORDER BY RAND() LIMIT " . $cron_limit;
|
||||
}
|
||||
else {
|
||||
$sql = "SELECT DISTINCT uf.contact_id, m.end_date FROM civicrm_uf_match uf
|
||||
LEFT JOIN civicrm_membership m ON uf.contact_id = m.contact_id
|
||||
WHERE m.id IS NOT NULL AND m.membership_type_id IN (" . implode(',', array_keys($memberroles)) . ")
|
||||
ORDER BY m.end_date DESC";
|
||||
//let's prioritise those ending last as then we are more likely to get relevant ones if it doesn't complete
|
||||
//obviously a better fix would be for it to chunk & save where it is up to
|
||||
}
|
||||
$params = CRM_Core_DAO::$_nullArray;
|
||||
$errorMsg = 'unknown error';
|
||||
$errorParams = array();
|
||||
}
|
||||
else {
|
||||
if (!empty($ext_uid)) {
|
||||
//Let's get the UID's Contact ID so we only grab one record from the CiviCRM DB.
|
||||
$uid = $ext_uid;
|
||||
$sql = "SELECT contact_id FROM civicrm_uf_match WHERE uf_id = %1";
|
||||
$params = array(1 => array($uid, "Integer"));
|
||||
$errorMsg = 'The uid: @uid did not have a CiviCRM Contact ID.';
|
||||
$errorParams = array('@uid' => (int) $ext_uid);
|
||||
}
|
||||
else {
|
||||
// Seems silly to add this query, but the while loop below needs result set.
|
||||
$sql = "SELECT id AS contact_id FROM civicrm_contact WHERE id = %1";
|
||||
$params = array(1 => array($cid, "Integer"));
|
||||
$errorMsg = 'Unable to get CiviCRM Contact ID @cid.';
|
||||
$errorParams = array('@uid' => (int) $cid);
|
||||
}
|
||||
}
|
||||
$contacts = CRM_Core_DAO::executeQuery($sql, $params);
|
||||
if ($contacts->N == 0) {
|
||||
watchdog('civicrm_member_roles',
|
||||
$errorMsg,
|
||||
$errorParams,
|
||||
WATCHDOG_ERROR
|
||||
);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$allRoles = user_roles(TRUE);
|
||||
while ($contacts->fetch()) {
|
||||
$cid = $contacts->contact_id;
|
||||
$uid = CRM_Core_BAO_UFMatch::getUFId($cid);
|
||||
if (empty($uid)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//Get all memberships of contact
|
||||
$memParams = array(
|
||||
'contact_id' => $cid,
|
||||
'options' => array('limit' => 0),
|
||||
);
|
||||
//CRM-16000 added try/catch to api call
|
||||
try {
|
||||
$memberships = civicrm_api3('membership', 'get', $memParams);
|
||||
}
|
||||
catch (CiviCRM_API3_Exception $e) {
|
||||
$error = $e->getMessage();
|
||||
return $error;
|
||||
}
|
||||
//CRM-16000 remove inactive memberships if member has both active and inactive memberships
|
||||
if ($memberships['count'] > 1) {
|
||||
$params = array(
|
||||
'sequential' => 1,
|
||||
'name' => array('IN' => array("Deceased", "Cancelled", "Pending", "Expired")),
|
||||
);
|
||||
try {
|
||||
$result = civicrm_api3('MembershipStatus', 'get', $params);
|
||||
}
|
||||
catch (CiviCRM_API3_Exception $e) {
|
||||
$error = $e->getMessage();
|
||||
return $error;
|
||||
}
|
||||
foreach ($result['values'] as $value) {
|
||||
$inactive[] = $value['id'];
|
||||
}
|
||||
foreach ($memberships['values'] as $key => $membership) {
|
||||
if (in_array($membership['status_id'], $inactive)) {
|
||||
unset($memberships['values'][$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$contactMemberships = CRM_Utils_Array::value('values', $memberships);
|
||||
$addRoles = array();
|
||||
$expRoles = array();
|
||||
|
||||
$roleCondition = is_array($rid) ? 'IN' : '=';
|
||||
|
||||
if (empty($contactMemberships) && !empty($rid)) {
|
||||
db_delete('users_roles')->condition('uid', $uid)->condition('rid', $rid, $roleCondition)->execute();
|
||||
}
|
||||
else {
|
||||
foreach ($contactMemberships as $membership) {
|
||||
if (!empty($rid)) {
|
||||
db_delete('users_roles')->condition('uid', $uid)->condition('rid', $rid, $roleCondition)->execute();
|
||||
}
|
||||
if (is_array($memberroles[$membership['membership_type_id']])) {
|
||||
foreach ($memberroles[$membership['membership_type_id']] as $rolerule) {
|
||||
if (in_array($membership['status_id'], $rolerule['codes']['current'])) {
|
||||
$addRoles[] = $rolerule['rid'];
|
||||
}
|
||||
elseif (in_array($membership['status_id'], $rolerule['codes']['expired'])) {
|
||||
$expRoles[] = $rolerule['rid'];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count($addRoles) > 0 || count($expRoles) > 0) {
|
||||
$addRoles = array_unique($addRoles);
|
||||
$expRoles = array_unique($expRoles);
|
||||
$account = user_load($uid, TRUE);
|
||||
if ($account !== FALSE) {
|
||||
// Retain a user's existing roles that aren't explicitly expired--the assumption is that roles granted
|
||||
// manually won't have expired memberships that correspond to those roles. If a status is neither
|
||||
// current nor expired, the membership will have no effect on the role.
|
||||
|
||||
$rolesRetain = array_diff_key($account->roles, array_flip($expRoles));
|
||||
|
||||
// Certainly add all roles that correspond to current memberships
|
||||
|
||||
foreach ($addRoles as $addRole) {
|
||||
$rolesRetain[$addRole] = $allRoles[$addRole];
|
||||
}
|
||||
|
||||
// Overwrite the user's roles to the ones we've set
|
||||
user_save($account, array('roles' => $rolesRetain));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function returns an array of either membership types or status rules depending on the $type param.
|
||||
*/
|
||||
function _civicrm_member_roles_get_data($type) {
|
||||
if (!civicrm_initialize()) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch ($type) {
|
||||
case 'status':
|
||||
$sql = 'SELECT id, name FROM civicrm_membership_status;';
|
||||
break;
|
||||
|
||||
case 'types':
|
||||
$sql = 'SELECT id, name FROM civicrm_membership_type;';
|
||||
break;
|
||||
|
||||
default:
|
||||
$sql = '';
|
||||
drupal_set_message(t('Invalid parameter was given to _civicrm_member_roles_get_data(). Param: "!1".', array('!1' => $type)));
|
||||
break;
|
||||
}
|
||||
|
||||
$dao = CRM_Core_DAO::executeQuery($sql);
|
||||
|
||||
$result = array();
|
||||
while ($dao->fetch()) {
|
||||
$result[$dao->id] = $dao->name;
|
||||
}
|
||||
|
||||
unset($dao);
|
||||
|
||||
if (empty($result)) {
|
||||
drupal_set_message(t('CiviMember Membership Types or Status Rules have not been configured. Please do so on the "Administer CiviCRM" page.'), $type = 'error');
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
function civicrm_member_roles_civicrm_post($op, $objname, $objid, &$objref) {
|
||||
if ($objname == "Membership") {
|
||||
if (in_array('update', variable_get('civicrm_member_roles_sync_method', array('login')), TRUE)) {
|
||||
_civicrm_member_roles_sync(NULL, $objref->contact_id);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
<phpunit backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
colors="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
syntaxCheck="false"
|
||||
beStrictAboutTestsThatDoNotTestAnything="false"
|
||||
bootstrap="../../tests/phpunit/bootstrap.php"
|
||||
>
|
||||
<testsuites>
|
||||
<testsuite name="civicrm_member_roles Test Suite">
|
||||
<directory>./tests/phpunit</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory suffix=".php">./CiviDrupalMemberRoles</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
|
@ -0,0 +1,141 @@
|
|||
<?php
|
||||
namespace CiviDrupalMemberRoles;
|
||||
|
||||
use Civi\Test\EndToEndInterface;
|
||||
|
||||
/**
|
||||
* Class MemberSyncTest
|
||||
* @package CiviDrupalMemberRoles
|
||||
* @group e2e
|
||||
*/
|
||||
class MemberSyncTest extends \PHPUnit_Framework_TestCase implements EndToEndInterface {
|
||||
|
||||
protected function setUp() {
|
||||
$this->assertTrue(module_exists('civicrm_member_roles'), 'civicrm_member_roles should be enabled');
|
||||
parent::setUp();
|
||||
$this->cleanup();
|
||||
}
|
||||
|
||||
protected function tearDown() {
|
||||
parent::tearDown();
|
||||
$this->cleanup();
|
||||
}
|
||||
|
||||
public function testCron() {
|
||||
$prefix = 'MemberSyncTest' . \CRM_Utils_String::createRandom(8, \CRM_Utils_String::ALPHANUMERIC);
|
||||
$demoContact = $this->getDemoContact();
|
||||
|
||||
$role = $this->createRole("{$prefix}Role");
|
||||
|
||||
$org = civicrm_api3('Contact', 'create', array(
|
||||
'sequential' => 1,
|
||||
'contact_type' => "Organization",
|
||||
'organization_name' => "{$prefix}Org",
|
||||
));
|
||||
|
||||
$memType = civicrm_api3('MembershipType', 'create', array(
|
||||
'sequential' => 1,
|
||||
'domain_id' => \CRM_Core_Config::domainID(),
|
||||
'member_of_contact_id' => $org['id'],
|
||||
'financial_type_id' => "Donation",
|
||||
'duration_unit' => "year",
|
||||
'duration_interval' => 1,
|
||||
'name' => "{$prefix}MemType",
|
||||
));
|
||||
|
||||
// Cron doesn't any do anything yet. We haven't configured memberships or rules.
|
||||
_civicrm_member_roles_sync(NULL, NULL, 'cron');
|
||||
$this->assertFalse($this->checkUserRole($GLOBALS['_CV']['DEMO_USER'], "{$prefix}Role"));
|
||||
|
||||
// We'll setup the membership... but not the rule!
|
||||
civicrm_api3('Membership', 'create', array(
|
||||
'sequential' => 1,
|
||||
'membership_type_id' => $memType['id'],
|
||||
'contact_id' => $demoContact['id'],
|
||||
));
|
||||
$this->assertFalse($this->checkUserRole($GLOBALS['_CV']['DEMO_USER'], "{$prefix}Role"));
|
||||
|
||||
// Now we get the rule. All conditions are met!
|
||||
$this->createRule($role->rid, $memType['id']);
|
||||
_civicrm_member_roles_sync(NULL, NULL, 'cron');
|
||||
$this->assertTrue($this->checkUserRole($GLOBALS['_CV']['DEMO_USER'], "{$prefix}Role"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $roleName
|
||||
* @return \stdClass
|
||||
*/
|
||||
protected function createRole($roleName) {
|
||||
$role = new \stdClass();
|
||||
$role->name = $roleName;
|
||||
user_role_save($role);
|
||||
return $role;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws \CiviCRM_API3_Exception
|
||||
*/
|
||||
protected function getDemoContact() {
|
||||
$this->assertNotEmpty($GLOBALS['_CV']['DEMO_USER']);
|
||||
$demoContact = civicrm_api3('Contact', 'getsingle', array(
|
||||
'id' => '@user:' . $GLOBALS['_CV']['DEMO_USER'],
|
||||
));
|
||||
return $demoContact;
|
||||
}
|
||||
|
||||
protected function checkUserRole($userName, $roleName) {
|
||||
$user = user_load_by_name($userName);
|
||||
return in_array($roleName, $user->roles);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $roleId
|
||||
* @param $memTypeId
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function createRule($roleId, $memTypeId) {
|
||||
$codes = array(
|
||||
0 => 'current',
|
||||
1 => 'expired',
|
||||
'current' => array(
|
||||
0 => '1',
|
||||
1 => '2',
|
||||
),
|
||||
'expired' => array(
|
||||
0 => '3',
|
||||
1 => '4',
|
||||
2 => '5',
|
||||
3 => '6',
|
||||
4 => '7',
|
||||
),
|
||||
);
|
||||
db_insert('civicrm_member_roles_rules')->fields(array(
|
||||
'rid' => (int) $roleId,
|
||||
'type_id' => (int) $memTypeId,
|
||||
'status_codes' => serialize($codes),
|
||||
))->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete any records created with the "MemberSyncTest" prefix.
|
||||
* @throws \CiviCRM_API3_Exception
|
||||
*/
|
||||
protected function cleanup() {
|
||||
\db_delete('role')->condition('name', 'MemberSyncTest%', 'LIKE')->execute();
|
||||
\db_delete('civicrm_member_roles_rules')->execute();
|
||||
\civicrm_api3('Membership', 'get', array(
|
||||
'contact_id' => '@user:' . $GLOBALS['_CV']['DEMO_USER'],
|
||||
'api.Membership.delete' => 1,
|
||||
));
|
||||
\civicrm_api3('MembershipType', 'get', array(
|
||||
'name' => array('LIKE' => 'MemberSyncTest%'),
|
||||
'api.MembershipType.delete' => 1,
|
||||
));
|
||||
\civicrm_api3('Contact', 'get', array(
|
||||
'organization_name' => 'MemberSyncTest%',
|
||||
'api.Contact.delete' => 1,
|
||||
));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
name = CiviCRM OG Sync
|
||||
description = Synchronize Organic Groups and CiviCRM Groups and ACL's. More information at: http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+vs.+Organic+Groups
|
||||
version = 7.x-4.7.29
|
||||
core = 7.x
|
||||
package = CiviCRM
|
||||
project = civicrm
|
||||
|
||||
dependencies[] = civicrm
|
||||
dependencies[] = og
|
||||
|
||||
files[] = civicrm_og_sync.module
|
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implemenation of hook_enable. Use to synchronise with pre-existing groups
|
||||
*/
|
||||
function civicrm_og_sync_enable() {
|
||||
db_query("UPDATE {system} SET weight = 110 WHERE name = 'civicrm_og_sync'");
|
||||
|
||||
if (!civicrm_initialize()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (function_exists('og_get_group_ids')) {
|
||||
$ogGroupIds = og_get_group_ids('node');
|
||||
}
|
||||
else {
|
||||
$ogGroupIds = og_get_all_group('node');
|
||||
}
|
||||
|
||||
// FIX ME
|
||||
$subscribers = array();
|
||||
// $subscribers = og_get_group_ids('user');
|
||||
|
||||
foreach ($ogGroupIds as $nid => $gid) {
|
||||
$node = node_load($gid);
|
||||
$title = trim($node->title);
|
||||
// length of 49 so that the admin group can fit ': administrator' afterwards within 64 char field
|
||||
$params = array(
|
||||
'name' => substr(trim($title), 0, 49),
|
||||
'title' => $title,
|
||||
'is_active' => 1,
|
||||
'og_id' => $gid,
|
||||
);
|
||||
|
||||
_civicrm_og_sync_skip_process_request(TRUE);
|
||||
|
||||
// add the group
|
||||
require_once 'CRM/Bridge/OG/Drupal.php';
|
||||
CRM_Bridge_OG_Drupal::nodeapi($params, 'add');
|
||||
|
||||
// add the subscribers
|
||||
foreach ($subscribers as $uid) {
|
||||
$is_admin = FALSE;
|
||||
if ($uid == $node->uid) {
|
||||
$is_admin = TRUE;
|
||||
}
|
||||
|
||||
$addToGroupParams = array(
|
||||
'og_id' => $gid,
|
||||
'uf_id' => $uid,
|
||||
'is_active' => 1,
|
||||
'is_admin' => $is_admin,
|
||||
);
|
||||
|
||||
// add contact in group
|
||||
CRM_Bridge_OG_Drupal::og($addToGroupParams, 'add');
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,319 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Reimplementation of civicrm_og_sync
|
||||
*
|
||||
* The implementation of this module in versions up to 3.3 is one way --
|
||||
* actions taken in Drupal are reflected in CiviCRM, but not the other way
|
||||
* around. The work here now implements some events going the other way.
|
||||
*
|
||||
* Groups will still be synced one way only. This is necessary, since CiviCRM
|
||||
* does not know enough about OG enabled content types to create them on its own.
|
||||
* Folks who need this would probably need at least a callback of some kind, and
|
||||
* probably a configuration UI. This is beyond the scope of the work here.
|
||||
*
|
||||
* Changes in contacts and group memberships, however, can readily be handled.
|
||||
* The old code calls into group creation code, which is probably why it was
|
||||
* so hard to get right. This update will instead do a "look before you leap"
|
||||
* approach, and if a group in CiviCRM does not have a counterpart in OG, it
|
||||
* will be treated as "a feature", since there's a lot of use for groups beyond
|
||||
* mirroring OG for most organizations.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_node_update().
|
||||
*/
|
||||
function civicrm_og_sync_node_insert($node) {
|
||||
_civicrm_og_sync_node_action($node);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_node_insert().
|
||||
*/
|
||||
function civicrm_og_sync_node_update($node) {
|
||||
_civicrm_og_sync_node_action($node);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_node_delete().
|
||||
*/
|
||||
function civicrm_og_sync_node_delete($node) {
|
||||
if (!_civicrm_og_sync_check_isvalid($node)) {
|
||||
return;
|
||||
}
|
||||
require_once 'CRM/Bridge/OG/Drupal.php';
|
||||
|
||||
$groupid = 0;
|
||||
|
||||
if (function_exists('og_get_group')) {
|
||||
if ($group = og_get_group('node', $node->nid)) {
|
||||
if (empty($group->gid)) {
|
||||
return;
|
||||
}
|
||||
$groupid = $group->gid;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$groupid = $node->nid;
|
||||
}
|
||||
|
||||
if ($groupid == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
_civicrm_og_sync_skip_process_request(TRUE);
|
||||
|
||||
$params = array(
|
||||
'name' => $node->title,
|
||||
'title' => $node->title,
|
||||
'og_id' => $groupid,
|
||||
);
|
||||
|
||||
CRM_Bridge_OG_Drupal::nodeapi($params, 'delete');
|
||||
|
||||
}
|
||||
|
||||
function civicrm_og_sync_og_membership_insert($membership) {
|
||||
_civicrm_og_sync_group_action($membership, 'add');
|
||||
}
|
||||
|
||||
function civicrm_og_sync_og_membership_update($membership) {
|
||||
if ($membership->entity_type != 'user') {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($membership->original->state != OG_STATE_ACTIVE && $membership->state == OG_STATE_ACTIVE) {
|
||||
_civicrm_og_sync_group_action($membership, 'add');
|
||||
}
|
||||
if ($membership->original->state != OG_STATE_BLOCKED && $membership->state == OG_STATE_BLOCKED) {
|
||||
_civicrm_og_sync_group_action($membership, 'remove');
|
||||
}
|
||||
}
|
||||
|
||||
function civicrm_og_sync_og_membership_delete($membership) {
|
||||
_civicrm_og_sync_group_action($membership, 'remove');
|
||||
}
|
||||
|
||||
function civicrm_og_sync_civicrm_post($op, $objectName, $objectID, $objectRef) {
|
||||
//If this is called, we need to ignore hook_og.
|
||||
if (_civicrm_og_sync_skip_process_request()) {
|
||||
return;
|
||||
}
|
||||
|
||||
require_once 'CRM/Bridge/OG/Utils.php';
|
||||
if (!CRM_Bridge_OG_Utils::syncFromCiviCRM()) {
|
||||
return;
|
||||
}
|
||||
|
||||
_civicrm_og_sync_skip_process_request(TRUE);
|
||||
|
||||
switch ($objectName) {
|
||||
case 'Group':
|
||||
require_once 'CRM/Bridge/OG/CiviCRM.php';
|
||||
switch ($op) {
|
||||
case 'create':
|
||||
case 'edit':
|
||||
//We have created a CiviCRM group, but if no OG exists,
|
||||
//we *do not* create one.
|
||||
//CRM_Bridge_OG_CiviCRM::group( $objectID, $objectRef, 'add' );
|
||||
break;
|
||||
|
||||
case 'delete':
|
||||
//This is a corner case. Actually, we should
|
||||
//try to make sure that the group delete *fails* on the
|
||||
//CiviCRM side, but that will be done later, if hook_pre
|
||||
//even makes this possible.
|
||||
|
||||
//TODO: block CRM group deletes if an OG exists for it.
|
||||
//CRM_Bridge_OG_CiviCRM::group( $objectID, $objectRef, 'delete' );
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'GroupContact':
|
||||
require_once 'CRM/Bridge/OG/CiviCRM.php';
|
||||
switch ($op) {
|
||||
case 'create':
|
||||
case 'edit':
|
||||
CRM_Bridge_OG_CiviCRM::groupContact($objectID, $objectRef, 'add');
|
||||
break;
|
||||
|
||||
case 'delete':
|
||||
CRM_Bridge_OG_CiviCRM::groupContact($objectID, $objectRef, 'delete');
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update or Add node
|
||||
*/
|
||||
function _civicrm_og_sync_node_action($node) {
|
||||
if (!_civicrm_og_sync_check_isvalid($node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$title = substr(trim($node->title), 0, 49);
|
||||
|
||||
$groupid = 0;
|
||||
|
||||
if (function_exists('og_get_group')) {
|
||||
if ($group = og_get_group('node', $node->nid)) {
|
||||
if (empty($group->gid)) {
|
||||
return;
|
||||
}
|
||||
$groupid = $group->gid;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$groupid = $node->nid;
|
||||
}
|
||||
|
||||
if ($groupid == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$params = array(
|
||||
'name' => $title,
|
||||
'title' => $title,
|
||||
'is_active' => 1,
|
||||
'og_id' => $groupid,
|
||||
);
|
||||
|
||||
require_once 'CRM/Bridge/OG/Drupal.php';
|
||||
|
||||
CRM_Bridge_OG_Drupal::nodeapi($params, 'add');
|
||||
|
||||
_civicrm_og_sync_skip_process_request(TRUE);
|
||||
|
||||
// also call the user hook since OG does not for admin
|
||||
$params = array(
|
||||
'og_id' => $groupid,
|
||||
'uf_id' => $node->uid,
|
||||
'is_active' => 1,
|
||||
'is_admin' => 1,
|
||||
);
|
||||
|
||||
CRM_Bridge_OG_Drupal::og($params, 'add');
|
||||
}
|
||||
|
||||
function _civicrm_og_sync_group_action($membership, $op = 'add') {
|
||||
if ($membership->entity_type != 'user' || !civicrm_initialize() || _civicrm_og_sync_skip_process_request() || $membership->type == "trusted_contacts") {
|
||||
return;
|
||||
}
|
||||
|
||||
require_once 'CRM/Bridge/OG/Drupal.php';
|
||||
|
||||
if (function_exists('og_load')) {
|
||||
$group = og_load($membership->gid);
|
||||
}
|
||||
else {
|
||||
// og-7.x-2.x does not have og_load, but uses entity_load_single($entity_type, $entity_id)
|
||||
// Right now we don't really know how to get a valid $entity_type for the group node, so we'll assume it's a node
|
||||
$group = entity_load_single('node', $membership->gid);
|
||||
}
|
||||
|
||||
_civicrm_og_sync_skip_process_request(TRUE);
|
||||
|
||||
// add node
|
||||
// OG 7.x-2.x changes the parameters, so we need to check
|
||||
// testing using a function that only appears in og-7.x-2.x
|
||||
if (function_exists('og_entity_query_alter')) {
|
||||
$createGroupParams = array(
|
||||
'og_id' => $group->nid,
|
||||
'title' => substr(trim($group->title), 0, 49),
|
||||
// length of 49 so that the admin group can fit ': administrator' afterwards within 64 char field
|
||||
'name' => substr(trim($group->title), 0, 49),
|
||||
'is_active' => 1,
|
||||
);
|
||||
}
|
||||
else {
|
||||
$createGroupParams = array(
|
||||
'og_id' => $group->gid,
|
||||
'title' => substr(trim($group->label), 0, 49),
|
||||
// length of 49 so that the admin group can fit ': administrator' afterwards within 64 char field
|
||||
'name' => substr(trim($group->label), 0, 49),
|
||||
'is_active' => 1,
|
||||
);
|
||||
}
|
||||
|
||||
CRM_Bridge_OG_Drupal::nodeapi($createGroupParams, 'add');
|
||||
|
||||
$addToGroupParams = array(
|
||||
'og_id' => $membership->gid,
|
||||
'uf_id' => $membership->etid,
|
||||
'is_active' => 1,
|
||||
'is_admin' => 0,
|
||||
);
|
||||
|
||||
// add contact in group
|
||||
CRM_Bridge_OG_Drupal::og($addToGroupParams, $op);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for context ,node type & civicrm initialization
|
||||
*/
|
||||
function _civicrm_og_sync_check_isvalid($node) {
|
||||
|
||||
// check if the node if of type og
|
||||
if (!og_is_group_type('node', $node->type)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!civicrm_initialize()) {
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
function _civicrm_og_sync_skip_process_request($skip = FALSE) {
|
||||
static $_process_request;
|
||||
if ($skip) {
|
||||
$_process_request = $skip;
|
||||
}
|
||||
return $_process_request;
|
||||
}
|
|
@ -0,0 +1,146 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains rules integration for the user module needed during evaluation.
|
||||
*
|
||||
* @addtogroup rules
|
||||
* @{
|
||||
*/
|
||||
require_once 'civicrm_rules_utils.inc';
|
||||
function civicrm_rules_rules_action_contact_send_email($to, $subject, $message, $from = NULL, $settings, RulesState$state, RulesPlugin$element) {
|
||||
|
||||
$to = str_replace(array("\r", "\n"), ',', $to);
|
||||
$toEmails = explode(',', $to);
|
||||
if (empty($toEmails)) {
|
||||
return;
|
||||
}
|
||||
foreach ($toEmails as $toEmail) {
|
||||
$params = array();
|
||||
$params['from'] = !empty($from) ? str_replace(array(
|
||||
"\r", "\n"), '', $from) : 'Admin';
|
||||
$params['toEmail'] = $toEmail;
|
||||
$params['subject'] = $subject;
|
||||
$params['text'] = is_array($message) ? implode("\n", $message) : $message;
|
||||
|
||||
CRM_Utils_Mail::send($params);
|
||||
}
|
||||
// FIX ME: add watchdog
|
||||
}
|
||||
|
||||
/**
|
||||
* Action contact: add a contact to a group
|
||||
*/
|
||||
function civicrm_rules_rules_action_add_to_group($contact, $settings) {
|
||||
$contactId = !empty($contact->id) ? $contact->id : $contact->getVar('_contactId');
|
||||
|
||||
if ($contactId) {
|
||||
foreach ($settings as $gid) {
|
||||
_civicrm_rules_group_contact($contactId, $gid);
|
||||
}
|
||||
return array('contact' => $contact);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Action contact: remove a contact from a group
|
||||
*/
|
||||
function civicrm_rules_rules_action_remove_from_group($contact, $settings) {
|
||||
$contactId = !empty($contact->id) ? $contact->id : $contact->getVar('_contactId');
|
||||
if ($contactId) {
|
||||
foreach ($settings as $gid) {
|
||||
_civicrm_rules_group_contact($contactId, $gid, 'delete');
|
||||
}
|
||||
return array('contact' => $contact);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Action contact: add a contact to a group
|
||||
*/
|
||||
function civicrm_rules_rules_action_add_tag($contact, $settings) {
|
||||
$contactId = !empty($contact->id) ? $contact->id : $contact->getVar('_contactId');
|
||||
|
||||
if ($contactId) {
|
||||
foreach ($settings as $tagid) {
|
||||
_civicrm_rules_tag_contact($contactId, $tagid);
|
||||
}
|
||||
return array('contact' => $contact);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Action contact: remove a contact from a group
|
||||
*/
|
||||
function civicrm_rules_rules_action_remove_tag($contact, $settings) {
|
||||
$contactId = !empty($contact->id) ? $contact->id : $contact->getVar('_contactId');
|
||||
if ($contactId) {
|
||||
foreach ($settings as $tagid) {
|
||||
_civicrm_rules_tag_contact($contactId, $tagid, 'delete');
|
||||
}
|
||||
return array('contact' => $contact);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Action: Creates a contact.
|
||||
* FIX ME: This function is not called, hence can be deleted
|
||||
*/
|
||||
function civicrm_rules_rules_contact_create($first_name, $last_name, $email) {
|
||||
$params = array(
|
||||
'first_name' => $first_name,
|
||||
'last_name' => $last_name,
|
||||
'email' => $email,
|
||||
'version' => 3,
|
||||
);
|
||||
|
||||
$contact = civicrm_api('contact', 'create', $params);
|
||||
|
||||
if (!$contact['is_error']) {
|
||||
return array('contact' => _civicrm_rules_load_contact($contact['id']));
|
||||
}
|
||||
else {
|
||||
return array('contact' => NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Options list callback for possible lising of CiviCRM Groups
|
||||
*/
|
||||
function civicrm_rules_options_list() {
|
||||
$settings['groups'] = _civicrm_get_groups();
|
||||
return $settings;
|
||||
}
|
|
@ -0,0 +1,94 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
require_once 'civicrm_rules_utils.inc';
|
||||
function civicrm_rules_condition_event_node(&$entityobj, $roleID, $field) {
|
||||
//just a hack for our site
|
||||
//SELECT * FROM `content_type_og_node` WHERE `field_civicrm_event_value` =993
|
||||
$sql = "SELECT * FROM `content_type_og_node` WHERE `field_civicrm_event_value` = $entityobj->id";
|
||||
$nid = db_result(db_query($sql));
|
||||
return $entityobj->id == $nid ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Condition civicrm_event type
|
||||
*/
|
||||
function civicrm_rules_condition_event_type($entityobj, $eventTypes) {
|
||||
if (!isset($eventTypes[$entityobj->event_type_id]) ||
|
||||
empty($eventTypes[$entityobj->event_type_id])
|
||||
) {
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler to get the user.
|
||||
* @todo this should either move into an event specific file or be more generic
|
||||
*/
|
||||
function civicrm_rules_events_argument_civicrm_event($eventobj) {
|
||||
if (!isset($eventobj['event'])) {
|
||||
return;
|
||||
}
|
||||
static $result;
|
||||
static $contact;
|
||||
|
||||
if (empty($result) || empty($contact)) {
|
||||
$event = $eventobj['event'];
|
||||
//todo BAO POST hook leaves created_id blank, the api call is a work-around for now
|
||||
if (empty($event->created_id)) {
|
||||
require_once 'api/api.php';
|
||||
$result = civicrm_api('Event', 'get', array('version' => 3, 'id' => $event->id, 'sequential' => 1));
|
||||
if (!CRM_Utils_Array::value('is_error', $result) && CRM_Utils_Array::value('created_id', $result['values'][0])) {
|
||||
$contact = civicrm_api('UFMatch', 'get', array('version' => 3, 'contact_id' => $result['values'][0]['created_id'], 'sequential' => 1));
|
||||
}
|
||||
}
|
||||
else {
|
||||
$contact = civicrm_api('UFMatch', 'get', array('version' => 3, 'contact_id' => $event->created_id, 'sequential' => 1));
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($contact) && !CRM_Utils_Array::value('is_error', $result) && is_numeric($contact['values'][0]['uf_id'])) {
|
||||
return $contact['values'][0]['uf_id'];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Event type options
|
||||
*/
|
||||
function civicrm_rules_get_event_type_options() {
|
||||
return civicrm_rules_get_options('event_type');
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
name = CiviCRM Rules Integration
|
||||
description = Integrate CiviCRM and Drupal Rules Module. Expose Contact, Contribution and other Objects along with Form / Page Operations.
|
||||
version = 7.x-4.7.29
|
||||
core = 7.x
|
||||
package = CiviCRM
|
||||
project = civicrm
|
||||
|
||||
dependencies[] = civicrm
|
||||
dependencies[] = rules
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_enable().
|
||||
*/
|
||||
function civicrm_rules_enable() {
|
||||
db_query("UPDATE {system} SET weight = 110 WHERE name = 'civicrm_rules'");
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
require_once 'civicrm_rules_utils.inc';
|
||||
function civicrm_rules_rules_action_mailing_send_email($to,
|
||||
$subject,
|
||||
$message,
|
||||
$from = NULL,
|
||||
$settings,
|
||||
RulesState$state,
|
||||
RulesPlugin$element
|
||||
) {
|
||||
if (isset($state->variables['mailing']) && $state->variables['mailing']->id) {
|
||||
$to = str_replace(array("\r", "\n"), ',', $to);
|
||||
$toEmails = explode(',', $to);
|
||||
if (empty($toEmails)) {
|
||||
return;
|
||||
}
|
||||
require_once 'CRM/Utils/Token.php';
|
||||
$tokens['mailing'] = array(
|
||||
'mailing.editUrl',
|
||||
'mailing.scheduleUrl',
|
||||
'mailing.html',
|
||||
'mailing.creatorEmail',
|
||||
'mailing.creator',
|
||||
);
|
||||
|
||||
$params = array();
|
||||
$params['from'] = !empty($from) ? str_replace(array(
|
||||
"\r", "\n"), '', $from) : 'Admin';
|
||||
$params['subject'] = CRM_Utils_Token::replaceMailingTokens($subject, $state->variables['mailing'], NULL, $tokens);
|
||||
$params['html'] = CRM_Utils_Token::replaceMailingTokens($message, $state->variables['mailing'], NULL, $tokens);
|
||||
|
||||
// also allow some user permission tokens for the toEmail
|
||||
$tokens['user'] = array(
|
||||
'user.permission-schedule mailings',
|
||||
'user.permission-create mailings',
|
||||
'user.permission-approve mailings',
|
||||
);
|
||||
foreach ($toEmails as $toEmail) {
|
||||
$params['toEmail'] = CRM_Utils_Token::replaceMailingTokens($toEmail, $state->variables['mailing'], NULL, $tokens);
|
||||
|
||||
//only process user permission tokens if used in toEmail
|
||||
if (in_array(trim($toEmail, '{}'), $tokens['user'])) {
|
||||
//we require a TO email, but can only send one; so we strip the first off and send the rest as CCs
|
||||
$userEmails = explode(',', CRM_Utils_Token::replaceUserTokens($params['toEmail'], $tokens));
|
||||
$params['toEmail'] = $userEmails[0];
|
||||
array_shift($userEmails);
|
||||
$params['cc'] = implode(',', $userEmails);
|
||||
}
|
||||
|
||||
CRM_Utils_Mail::send($params);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function civicrm_rules_condition_mailing_approved($mailing, $settings) {
|
||||
return $mailing->approval_status_id == 1;
|
||||
}
|
||||
|
||||
function civicrm_rules_condition_mailing_rejected($mailing, $settings) {
|
||||
return $mailing->approval_status_id != 1;
|
||||
}
|
|
@ -0,0 +1,212 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implement the post hook and fire the corresponding rules event
|
||||
*/
|
||||
function civicrm_rules_civicrm_post($op, $objectName, $objectId, &$objectRef) {
|
||||
if (!module_exists('rules')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (in_array($objectName,
|
||||
array('Individual', 'Household', 'Organization')
|
||||
)) {
|
||||
$objectName = 'Contact';
|
||||
}
|
||||
|
||||
// process only contacts for now
|
||||
$validObjects = array_merge(
|
||||
variable_get('civicrm_rules_post_entities', array()),
|
||||
array('contact' => 'contact')
|
||||
);
|
||||
|
||||
if (!in_array(strtolower($objectName), $validObjects, TRUE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$eventObject = strtolower($objectName);
|
||||
if (!in_array($eventObject, $validObjects) &&
|
||||
!in_array($eventObject, array('contact'))
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($eventObject != 'contact') {
|
||||
// without the civicrm prefix too much chance of another drupal module being enabled
|
||||
$eventObject = 'civicrm_' . $eventObject;
|
||||
}
|
||||
|
||||
$eventName = NULL;
|
||||
switch ($op) {
|
||||
case 'create':
|
||||
case 'edit':
|
||||
case 'delete':
|
||||
$eventName = "{$eventObject}_{$op}";
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if ($eventName) {
|
||||
rules_invoke_event($eventName, $objectRef);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement civicrm pageRun hook and fire the corresponding rules event
|
||||
*/
|
||||
function civicrm_rules_civicrm_pageRun(&$page) {
|
||||
if (!module_exists('rules')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// process only contacts for now
|
||||
$validObjects = array('CRM_Contact_Page_View_Summary');
|
||||
|
||||
$className = get_class($page);
|
||||
if (!in_array($className, $validObjects)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$eventName = NULL;
|
||||
switch ($className) {
|
||||
case 'CRM_Contact_Page_View_Summary':
|
||||
$eventName = 'contact_view';
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if ($eventName) {
|
||||
rules_invoke_event($eventName, $page);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement the postProcess hook and fire the corresponding rules event
|
||||
* We'll do this for specific forms only (for now)
|
||||
*/
|
||||
function civicrm_rules_civicrm_postProcess($formName, &$form) {
|
||||
require_once 'CRM/Mailing/Info.php';
|
||||
if (CRM_Mailing_Info::workflowEnabled()) {
|
||||
$eventName = $eventParams = NULL;
|
||||
|
||||
switch ($formName) {
|
||||
case 'CRM_Mailing_Form_Group':
|
||||
if ($form->get('continue') == TRUE) {
|
||||
$eventName = 'mailing_edit';
|
||||
$mailingId = $form->get('mid');
|
||||
}
|
||||
else {
|
||||
$query = "
|
||||
SELECT max(id)
|
||||
FROM civicrm_mailing
|
||||
";
|
||||
$mailingId = CRM_Core_DAO::singleValueQuery($query);
|
||||
$eventName = 'mailing_create';
|
||||
}
|
||||
break;
|
||||
|
||||
case 'CRM_Mailing_Form_Schedule':
|
||||
if ($form->get('mid')) {
|
||||
$mailingId = $form->get('mid');
|
||||
}
|
||||
else {
|
||||
$mailingId = $form->_mailingID;
|
||||
}
|
||||
$eventName = 'mailing_scheduled';
|
||||
break;
|
||||
|
||||
case 'CRM_Mailing_Form_Approve':
|
||||
if ($form->_mailingID) {
|
||||
$mailingId = $form->_mailingID;
|
||||
}
|
||||
else {
|
||||
$mailingId = $form->get('mid');
|
||||
}
|
||||
$eventName = 'mailing_approved';
|
||||
break;
|
||||
|
||||
case 'CRM_Mailing_Form_Upload':
|
||||
$eventName = 'mailing_uploaded';
|
||||
$mailingId = $form->_mailingID;
|
||||
break;
|
||||
|
||||
case 'CRM_Mailing_Form_Test':
|
||||
$eventName = 'mailing_inform';
|
||||
$mailingId = $form->get('mailing_id') ? $form->get('mailing_id') : $form->get('mid');
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if ($eventName) {
|
||||
require_once 'CRM/Mailing/DAO/Mailing.php';
|
||||
$eventParams = new CRM_Mailing_DAO_Mailing();
|
||||
$eventParams->id = $mailingId;
|
||||
$eventParams->find(TRUE);
|
||||
rules_invoke_event($eventName, $eventParams);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Implements hook_permission().
|
||||
*/
|
||||
function civicrm_rules_permission() {
|
||||
return array(
|
||||
'access civicrm rules settings' => array(
|
||||
'title' => t('Access CiviCRM Rules Settings'),
|
||||
'description' => t('Access CiviCRM Rules Settings.'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
function civicrm_rules_menu() {
|
||||
|
||||
$items['admin/config/civicrm/rules'] = array(
|
||||
'title' => 'CiviCRM Rules settings',
|
||||
'description' => 'CiviCRM Rules Configuration',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('civicrm_rules_admin_settings'),
|
||||
'access arguments' => array('access civicrm rules settings'),
|
||||
'file' => 'civicrm_rules_admin_form.inc',
|
||||
'type' => MENU_NORMAL_ITEM,
|
||||
);
|
||||
return $items;
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
require_once 'civicrm_rules_utils.inc';
|
||||
|
||||
/**
|
||||
* Participant role options
|
||||
*/
|
||||
function civicrm_rules_get_participant_role_options() {
|
||||
return civicrm_rules_get_options('participant_role');
|
||||
}
|
||||
|
||||
function civicrm_rules_condition_participant_role($entityobj, $roleIDs) {
|
||||
if (!isset($roleIDs[$entityobj->role_id]) ||
|
||||
empty($roleIDs[$entityobj->role_id])
|
||||
) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* get node related via cck - this relies on there being a field called civicrm_event.
|
||||
* If you use this field on more than one event type it will load the last one (not something you should do)
|
||||
* I wanted to do it using a civicrm_event cck type but got a bit stuck.
|
||||
*/
|
||||
function civicrm_rules_events_argument_civicrm_eventnode($participantobj) {
|
||||
if (!module_exists('field') || !isset($participantobj['participant'])) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$participant = $participantobj['participant'];
|
||||
$eventID = $participant->event_id;
|
||||
$results = db_select('field_config_instance', 'i')
|
||||
->fields('i', array('field_name', 'entity_type', 'bundle'))
|
||||
->condition('field_name', '%' . db_like('civicrm_event'), 'LIKE')
|
||||
->execute()
|
||||
->fetchAllAssoc('id');
|
||||
foreach ($results as $result) {
|
||||
$nid = db_select('field_data_' . $result->field_name, 'fd')
|
||||
->fields('fd', array('entity_id'))
|
||||
->condition('bundle', $result->bundle, '=')
|
||||
->condition($result->field_name . '_value', $eventID, '=')
|
||||
->condition('entity_type', $result->entity_type, '=')
|
||||
->execute()
|
||||
->fetchAssoc();
|
||||
return $nid['entity_id'];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler to get the user. This will work if $entityobj->contact_id is defined
|
||||
* e.g. for participant object, contribution object
|
||||
*/
|
||||
function civicrm_rules_events_argument_civicrm_contactID_load_user($entityobj) {
|
||||
require_once 'api/api.php';
|
||||
$contact = civicrm_api('UFMatch', 'get', array('version' => 3, 'contact_id' => $entityobj['participant']->contact_id, 'sequential' => 1));
|
||||
if (!empty($contact) && is_numeric($contact['values'][0]['uf_id'])) {
|
||||
return $contact['values'][0]['uf_id'];
|
||||
}
|
||||
return NULL;
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
require_once 'civicrm_rules_utils.inc';
|
||||
require_once 'civicrm_rules.contact-eval.inc';
|
||||
require_once 'civicrm_rules.mailing-eval.inc';
|
||||
require_once 'civicrm_rules.event-eval.inc';
|
||||
require_once 'civicrm_rules.participant-eval.inc';
|
||||
|
||||
/**
|
||||
* Implements hook_rules_file_info().
|
||||
*/
|
||||
function civicrm_rules_rules_file_info() {
|
||||
return array(
|
||||
'civicrm_rules.contact-eval',
|
||||
'civicrm_rules.mailing-eval',
|
||||
'civicrm_rules.event-eval',
|
||||
'civicrm_rules.participant-eval',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_rules_event_info().
|
||||
*/
|
||||
function civicrm_rules_rules_event_info() {
|
||||
require_once 'civicrm_rules_event.inc';
|
||||
return civicrm_rules_get_event();
|
||||
}
|
||||
|
||||
function civicrm_rules_rules_condition_info() {
|
||||
require_once 'civicrm_rules_condition.inc';
|
||||
return civicrm_rules_get_condition();
|
||||
}
|
||||
|
||||
/**
|
||||
* CiviCRM integration access callback.
|
||||
*/
|
||||
function civicrm_rules_rules_integration_access($type, $name) {
|
||||
if ($type == 'event' || $type == 'condition') {
|
||||
return user_access('access CiviCRM');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* CiviCRM integration admin access callback.
|
||||
*/
|
||||
function civicrm_rules_rules_admin_access() {
|
||||
return user_access('administer CiviCRM');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_rules_action_info().
|
||||
*/
|
||||
function civicrm_rules_rules_action_info() {
|
||||
require_once 'civicrm_rules_action.inc';
|
||||
return civicrm_rules_get_action();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_rules_data_type_info().
|
||||
*/
|
||||
function civicrm_rules_rules_data_info() {
|
||||
require_once 'civicrm_rules_entity.inc';
|
||||
return civicrm_rules_get_entity();
|
||||
}
|
|
@ -0,0 +1,183 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_rules_action_info().
|
||||
*/
|
||||
function civicrm_rules_get_action() {
|
||||
civicrm_initialize();
|
||||
//get the default from email address.
|
||||
require_once 'CRM/Core/OptionGroup.php';
|
||||
$defaultAddress = CRM_Core_OptionGroup::values('from_email_address', NULL, NULL, NULL, ' AND is_default = 1');
|
||||
|
||||
$settings['message'] = '
|
||||
A new mailing has been scheduled: {mailing.name}
|
||||
|
||||
{mailing.viewUrl}
|
||||
You can review the mail here: {mailing.editUrl}
|
||||
You can schedule the mail for here: {mailing.scheduleUrl}
|
||||
|
||||
The content of the email is:
|
||||
<pre>
|
||||
{mailing.html}
|
||||
</pre>
|
||||
';
|
||||
$settings['from'] = (isset($defaultAddress[1])) ? $defaultAddress[1] : NULL;
|
||||
|
||||
if (!CRM_Utils_Array::value('subject', $settings)) {
|
||||
$settings['subject'] = 'New Email: {mailing.subject}';
|
||||
}
|
||||
|
||||
$defaults = array(
|
||||
'parameter' => array(
|
||||
'contact' => array(
|
||||
'type' => 'contact',
|
||||
'label' => t('Contact'),
|
||||
'save' => TRUE,
|
||||
),
|
||||
'civicrm_group' => array(
|
||||
'type' => 'list<integer>',
|
||||
'label' => t('CiviCRM Groups'),
|
||||
'options list' => 'civicrm_rules_options_list',
|
||||
),
|
||||
),
|
||||
'group' => t('CiviCRM Contact'),
|
||||
'access callback' => 'civicrm_rules_rules_admin_access',
|
||||
);
|
||||
|
||||
$items['add_to_group'] = $defaults + array(
|
||||
'label' => t('Add Contact to CiviCRM Group'),
|
||||
'base' => 'civicrm_rules_rules_action_add_to_group',
|
||||
);
|
||||
$items['remove_from_group'] = $defaults + array(
|
||||
'label' => t('Remove Contact from CiviCRM Group'),
|
||||
'base' => 'civicrm_rules_rules_action_remove_from_group',
|
||||
);
|
||||
|
||||
$defaults = array(
|
||||
'parameter' => array(
|
||||
'contact' => array(
|
||||
'type' => 'contact',
|
||||
'label' => t('Contact'),
|
||||
'save' => TRUE,
|
||||
),
|
||||
'civicrm_tags' => array(
|
||||
'type' => 'list<integer>',
|
||||
'label' => t('CiviCRM Tags'),
|
||||
'options list' => 'civicrm_rules_options_list',
|
||||
),
|
||||
),
|
||||
'group' => t('CiviCRM Contact'),
|
||||
'access callback' => 'civicrm_rules_rules_admin_access',
|
||||
);
|
||||
|
||||
$items['add_tag'] = $defaults + array(
|
||||
'label' => t('Add CiviCRM Tag to Contact'),
|
||||
'base' => 'civicrm_rules_rules_action_add_tag',
|
||||
);
|
||||
$items['remove_tag'] = $defaults + array(
|
||||
'label' => t('Remove CiviCRM Tag from Contact'),
|
||||
'base' => 'civicrm_rules_rules_action_remove_tag',
|
||||
);
|
||||
|
||||
$defaults = array(
|
||||
'parameter' => array(
|
||||
'to' => array(
|
||||
'type' => 'text',
|
||||
'label' => t('To'),
|
||||
'description' => t('The e-mail address or addresses where the message will be sent to. The formatting of this string must comply with RFC 2822.'),
|
||||
),
|
||||
'subject' => array(
|
||||
'type' => 'text',
|
||||
'label' => t('Subject'),
|
||||
'description' => t("The mail's subject."),
|
||||
),
|
||||
'message' => array(
|
||||
'type' => 'text',
|
||||
'label' => t('Message'),
|
||||
'description' => t("The mail's message body."),
|
||||
),
|
||||
'from' => array(
|
||||
'type' => 'text',
|
||||
'label' => t('From'),
|
||||
'description' => t("The mail's from address. Leave it empty to use the site-wide configured address."),
|
||||
'optional' => TRUE,
|
||||
),
|
||||
),
|
||||
'group' => t('CiviCRM Contact'),
|
||||
'access callback' => 'civicrm_rules_rules_admin_access',
|
||||
);
|
||||
|
||||
$items['contact_send_email'] = $defaults + array(
|
||||
'label' => t('Send Email'),
|
||||
'base' => 'civicrm_rules_rules_action_contact_send_email',
|
||||
);
|
||||
|
||||
$defaults = array(
|
||||
'parameter' => array(
|
||||
'to' => array(
|
||||
'type' => 'text',
|
||||
'label' => t('To'),
|
||||
'description' => t('The e-mail address or addresses where the message will be sent to. The formatting of this string must comply with RFC 2822.'),
|
||||
),
|
||||
'subject' => array(
|
||||
'type' => 'text',
|
||||
'label' => t('Subject'),
|
||||
'description' => t("The mail's subject."),
|
||||
'default value' => $settings['subject'],
|
||||
),
|
||||
'message' => array(
|
||||
'type' => 'text',
|
||||
'label' => t('Message'),
|
||||
'description' => t("The mail's message body."),
|
||||
'default value' => $settings['message'],
|
||||
),
|
||||
'from' => array(
|
||||
'type' => 'text',
|
||||
'label' => t('From'),
|
||||
'description' => t("The mail's from address. Leave it empty to use the site-wide configured address."),
|
||||
'default value' => $settings['from'],
|
||||
'optional' => TRUE,
|
||||
),
|
||||
),
|
||||
'group' => t('CiviCRM Mailing'),
|
||||
);
|
||||
|
||||
$items['mailing_send_email'] = $defaults + array(
|
||||
'label' => t('Send Email'),
|
||||
'base' => 'civicrm_rules_rules_action_mailing_send_email',
|
||||
);
|
||||
return $items;
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
function civicrm_rules_admin_settings($form_state = NULL) {
|
||||
|
||||
$form['civicrm_rules_post_entities'] = array(
|
||||
'#title' => t("Entities enabled for Post Rules"),
|
||||
'#type' => 'checkboxes',
|
||||
'#options' => _civicrm_rules_admin_getEntities(),
|
||||
'#description' => t('Which Entities Do you want POST rules activated for'),
|
||||
'#default_value' => variable_get('civicrm_rules_post_entities', array()),
|
||||
);
|
||||
|
||||
return system_settings_form($form);
|
||||
}
|
||||
|
||||
function _civicrm_rules_admin_getEntities() {
|
||||
//Todo Use civicrm_api('Entities', 'Get', array('version' => 3));
|
||||
// to extend entities to all API entities
|
||||
return array('event' => 'Event', 'participant' => 'Participant');
|
||||
}
|
|
@ -0,0 +1,101 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
function civicrm_rules_get_condition() {
|
||||
return array(
|
||||
'civicrm_rules_condition_mailing_approved' =>
|
||||
array(
|
||||
'label' => t('Approval Status: Approved'),
|
||||
'arguments' => array(
|
||||
'approvalstatus' => array(
|
||||
'type' => 'mailing',
|
||||
'label' => t('Approved'),
|
||||
),
|
||||
),
|
||||
'base' => 'civicrm_rules_condition_mailing_approved',
|
||||
'group' => 'CiviCRM Mailing',
|
||||
),
|
||||
'civicrm_rules_condition_mailing_rejected' =>
|
||||
array(
|
||||
'label' => t('Approval Status: Rejected'),
|
||||
'arguments' => array(
|
||||
'approvalstatus' => array(
|
||||
'type' => 'mailing',
|
||||
'label' => t('Rejected'),
|
||||
),
|
||||
),
|
||||
'base' => 'civicrm_rules_condition_mailing_rejected',
|
||||
'group' => 'CiviCRM Mailing',
|
||||
),
|
||||
'civicrm_rules_condition_participant_role' =>
|
||||
array(
|
||||
'label' => t('Participant Role'),
|
||||
'base' => 'civicrm_rules_condition_participant_role',
|
||||
'parameter' => civicrm_rules_condition_parameter(t('Participant Role'), 'participant'),
|
||||
'group' => 'CiviCRM participant',
|
||||
),
|
||||
'civicrm_rules_condition_event_type' =>
|
||||
array(
|
||||
'label' => t('Event Type'),
|
||||
'base' => 'civicrm_rules_condition_event_type',
|
||||
'parameter' => civicrm_rules_condition_parameter(t('Created Event'), 'event'),
|
||||
'group' => 'CiviCRM event',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
function civicrm_rules_condition_parameter($label, $type = 'contact') {
|
||||
|
||||
$default = array($type => array('type' => $type, 'label' => $label));
|
||||
|
||||
if ($type == 'participant') {
|
||||
return $default + array(
|
||||
'civicrm_participant_role' => array(
|
||||
'type' => 'list<integer>',
|
||||
'label' => t('Participant role'),
|
||||
'options list' => 'civicrm_rules_get_participant_role_options',
|
||||
));
|
||||
}
|
||||
|
||||
if ($type == 'event') {
|
||||
return $default + array(
|
||||
'civicrm_event_type' => array(
|
||||
'type' => 'list<integer>',
|
||||
'label' => t('CiviCRM event type'),
|
||||
'options list' => 'civicrm_rules_get_event_type_options',
|
||||
));
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
function civicrm_rules_get_entity() {
|
||||
|
||||
return array(
|
||||
'contact' => array(
|
||||
'label' => t('Contact'),
|
||||
'class' => 'rules_data_type_contact',
|
||||
'savable' => FALSE,
|
||||
'identifiable' => TRUE,
|
||||
),
|
||||
'mailing' => array(
|
||||
'label' => t('Mailing'),
|
||||
'class' => 'rules_data_type_mailing',
|
||||
'savable' => FALSE,
|
||||
'identifiable' => TRUE,
|
||||
),
|
||||
'event' => array(
|
||||
'label' => t('Event'),
|
||||
'class' => 'rules_data_type_event',
|
||||
'savable' => FALSE,
|
||||
'identifiable' => TRUE,
|
||||
),
|
||||
'participant' => array(
|
||||
'label' => t('Participant'),
|
||||
'class' => 'rules_data_type_participant',
|
||||
'savable' => FALSE,
|
||||
'identifiable' => TRUE,
|
||||
),
|
||||
);
|
||||
}
|
|
@ -0,0 +1,189 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
function civicrm_rules_get_event() {
|
||||
$defaults = array(
|
||||
'access callback' => 'civicrm_rules_rules_integration_access',
|
||||
'module' => 'civicrm',
|
||||
);
|
||||
|
||||
$events = array(
|
||||
'contact_create' =>
|
||||
array(
|
||||
'label' => t('Contact has been created'),
|
||||
'group' => 'CiviCRM Contact',
|
||||
'variables' => civicrm_rules_rules_events_variables(t('created contact')),
|
||||
),
|
||||
'contact_edit' =>
|
||||
array(
|
||||
'label' => t('Contact has been updated'),
|
||||
'group' => 'CiviCRM Contact',
|
||||
'variables' => civicrm_rules_rules_events_variables(t('update contact')),
|
||||
),
|
||||
'contact_view' =>
|
||||
array(
|
||||
'label' => t('Contact has been viewed'),
|
||||
'group' => 'CiviCRM Contact',
|
||||
'variables' => civicrm_rules_rules_events_variables(t('viewed contact')),
|
||||
),
|
||||
'contact_delete' =>
|
||||
array(
|
||||
'label' => t('Contact has been deleted'),
|
||||
'group' => 'CiviCRM Contact',
|
||||
'variables' => civicrm_rules_rules_events_variables(t('deleted contact')),
|
||||
),
|
||||
'mailing_create' =>
|
||||
array(
|
||||
'label' => t('Mailing has been created'),
|
||||
'group' => 'CiviCRM Mailing',
|
||||
'variables' => civicrm_rules_rules_events_variables(t('created mailing'), 'mailing'),
|
||||
),
|
||||
'mailing_edit' =>
|
||||
array(
|
||||
'label' => t('Mailing has been updated'),
|
||||
'group' => 'CiviCRM Mailing',
|
||||
'variables' => civicrm_rules_rules_events_variables(t('updated mailing'), 'mailing'),
|
||||
),
|
||||
'mailing_uploaded' =>
|
||||
array(
|
||||
'label' => t('Mailing content has been uploaded'),
|
||||
'group' => 'CiviCRM Mailing',
|
||||
'variables' => civicrm_rules_rules_events_variables(t('mailing content uploaded'), 'mailing'),
|
||||
),
|
||||
'mailing_scheduled' =>
|
||||
array(
|
||||
'label' => t('Mailing has been scheduled'),
|
||||
'group' => 'CiviCRM Mailing',
|
||||
'variables' => civicrm_rules_rules_events_variables(t('scheduled mailing'), 'mailing'),
|
||||
),
|
||||
'mailing_approved' =>
|
||||
array(
|
||||
'label' => t('Mailing has been approved/rejected'),
|
||||
'group' => 'CiviCRM Mailing',
|
||||
'variables' => civicrm_rules_rules_events_variables(t('approved mailing'), 'mailing'),
|
||||
),
|
||||
'mailing_inform' =>
|
||||
array(
|
||||
'label' => t('Inform scheduler about the mailing'),
|
||||
'group' => 'CiviCRM Mailing',
|
||||
'variables' => civicrm_rules_rules_events_variables(t('inform mailing'), 'mailing'),
|
||||
),
|
||||
'mailing_queued' =>
|
||||
array(
|
||||
'label' => t('Mailing has been queued'),
|
||||
'group' => 'CiviCRM Mailing',
|
||||
'variables' => civicrm_rules_rules_events_variables(t('queued mailing'), 'mailing'),
|
||||
),
|
||||
'mailing_complete' => array(
|
||||
'label' => t('Mailing has been completed'),
|
||||
'group' => 'CiviCRM Mailing',
|
||||
'variables' => civicrm_rules_rules_events_variables(t('completed mailing'), 'mailing'),
|
||||
),
|
||||
);
|
||||
|
||||
$validObjects = variable_get('civicrm_rules_post_entities', array());
|
||||
|
||||
if (is_array($validObjects)) {
|
||||
foreach ($validObjects as $entity => $enabled) {
|
||||
$entity = strtolower($entity);
|
||||
if (!$enabled == 0) {
|
||||
//todo consider building the entity name into the argument rather than calling the same argument for each
|
||||
$events['civicrm_' . $entity . '_create'] = $defaults + array(
|
||||
'label' => t("%entity has been created", array('%entity' => $entity)),
|
||||
'group' => 'CiviCRM ' . $entity,
|
||||
'variables' => civicrm_rules_rules_events_variables(t('Created %entity', array('%entity' => $entity)), $entity),
|
||||
);
|
||||
$events['civicrm_' . $entity . '_edit'] = $defaults + array(
|
||||
'group' => 'CiviCRM ' . $entity,
|
||||
'label' => t("%entity has been updated", array('%entity' => $entity)),
|
||||
'variables' => civicrm_rules_rules_events_variables(t('Updated %entity', array('%entity' => $entity)), $entity),
|
||||
);
|
||||
$events['civicrm_' . $entity . '_view'] = $defaults + array(
|
||||
'group' => 'CiviCRM ' . $entity,
|
||||
'label' => t("%entity has been viewed", array('%entity' => $entity)),
|
||||
'variables' => civicrm_rules_rules_events_variables(t('Viewed %entity', array('%entity' => $entity)), $entity),
|
||||
);
|
||||
$events['civicrm_' . $entity . '_delete'] = $defaults + array(
|
||||
'group' => 'CiviCRM ' . $entity,
|
||||
'label' => t("%entity has been deleted", array('%entity' => $entity)),
|
||||
'variables' => civicrm_rules_rules_events_variables(t('Deleted %entity', array('%entity' => $entity)), $entity),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($events as $key => $event) {
|
||||
$events[$key] = $defaults + $event;
|
||||
}
|
||||
|
||||
return $events;
|
||||
}
|
||||
|
||||
function civicrm_rules_rules_events_variables($label, $type = 'contact') {
|
||||
|
||||
$default = array(
|
||||
$type => array(
|
||||
'type' => $type,
|
||||
'label' => $label,
|
||||
),
|
||||
);
|
||||
|
||||
if ($type == 'event') {
|
||||
return $default + array(
|
||||
'cms_user' => array(
|
||||
'type' => 'user',
|
||||
'label' => t('User that created the event'),
|
||||
'handler' => 'civicrm_rules_events_argument_civicrm_event',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if ($type == 'participant') {
|
||||
|
||||
return $default + array(
|
||||
'event_node' => array(
|
||||
'type' => 'node',
|
||||
'label' => t('Node related to the event'),
|
||||
'handler' => 'civicrm_rules_events_argument_civicrm_eventnode',
|
||||
),
|
||||
'cms_user' => array(
|
||||
'type' => 'user',
|
||||
'label' => t('User that registered for the event'),
|
||||
'handler' => 'civicrm_rules_events_argument_civicrm_contactID_load_user',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
|
@ -0,0 +1,153 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This file contains functions that calls civicrm apis for data manupulation / retrieval
|
||||
*/
|
||||
|
||||
/**
|
||||
* Function to get the list of groups
|
||||
*/
|
||||
function _civicrm_get_groups() {
|
||||
civicrm_initialize();
|
||||
$groupInformation = civicrm_api('group', 'get', array(
|
||||
'version' => 3,
|
||||
'options' => array(
|
||||
'limit' => 0,
|
||||
'sort' => 'title ASC',
|
||||
),
|
||||
));
|
||||
|
||||
$groups = array();
|
||||
foreach ($groupInformation['values'] as $values) {
|
||||
$groups[$values['id']] = $values['title'];
|
||||
}
|
||||
|
||||
return $groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to add contacts to group
|
||||
*/
|
||||
function _civicrm_rules_group_contact($contactId, $groupId, $action = 'create') {
|
||||
civicrm_initialize();
|
||||
$params = array(
|
||||
'contact_id' => $contactId,
|
||||
'group_id' => $groupId,
|
||||
'version' => 3,
|
||||
);
|
||||
// This used to be civicrm_group_contact_common($params, $action);
|
||||
civicrm_api('group_contact', $action, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get the list of tags
|
||||
*/
|
||||
function _civicrm_get_tags() {
|
||||
civicrm_initialize();
|
||||
$tagInformation = civicrm_api3('Tag', 'get', array('options' => array('limit' => 0)));
|
||||
|
||||
$tags = array();
|
||||
foreach ($tagInformation['values'] as $values) {
|
||||
$tags[$values['id']] = $values['title'];
|
||||
}
|
||||
|
||||
return $tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to add tag to contacts
|
||||
*/
|
||||
function _civicrm_rules_tag_contact($contactId, $tagId, $action = 'create') {
|
||||
civicrm_initialize();
|
||||
$params = array(
|
||||
'entity_table' => "civicrm_contact",
|
||||
'entity_id' => $contactId,
|
||||
'tag_id' => $tagId,
|
||||
);
|
||||
|
||||
civicrm_api3('EntityTag', $action, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a contact into a version suitable for the rules actions
|
||||
*/
|
||||
function _civicrm_rules_load_contact($contactID) {
|
||||
$contact = new CRM_Contact_DAO_Contact();
|
||||
$contact->id = $contactID;
|
||||
|
||||
if ($contact->id) {
|
||||
// load the contact data here
|
||||
$contact->find(TRUE);
|
||||
}
|
||||
|
||||
return $contact;
|
||||
}
|
||||
|
||||
function _civicrm_rules_in_group($contact, $group) {
|
||||
// check if contact is in the group gid
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a mailing into a version suitable for the rules actions
|
||||
*/
|
||||
function _civicrm_rules_load_mailing($mailingID) {
|
||||
$mailing = new CRM_Mailing_DAO_Mailing();
|
||||
$mailing->id = $mailingID;
|
||||
|
||||
if ($mailing->id) {
|
||||
// load the mailing data here
|
||||
$mailing->find(TRUE);
|
||||
}
|
||||
|
||||
return $mailing;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* function to return labels for checkboxes & stuff
|
||||
*/
|
||||
function civicrm_rules_get_options($type) {
|
||||
if (!civicrm_initialize()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$result = civicrm_api('OptionValue', 'get', array('version' => 3, 'option_group_name' => $type));
|
||||
foreach ($result['values'] as $options) {
|
||||
$values[$options['value']] = $options['label'];
|
||||
}
|
||||
return $values;
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
array (
|
||||
'rules' =>
|
||||
array (
|
||||
'rules_1' =>
|
||||
array (
|
||||
'#type' => 'rule',
|
||||
'#set' => 'event_mailing_test',
|
||||
'#label' => 'Send Mail to Scheduling Services',
|
||||
'#active' => 1,
|
||||
'#weight' => '0',
|
||||
'#categories' =>
|
||||
array (
|
||||
),
|
||||
'#status' => 'custom',
|
||||
'#conditions' =>
|
||||
array (
|
||||
),
|
||||
'#actions' =>
|
||||
array (
|
||||
0 =>
|
||||
array (
|
||||
'#weight' => 0,
|
||||
'#type' => 'action',
|
||||
'#settings' =>
|
||||
array (
|
||||
'to' => 'conference.services@example.com',
|
||||
'from' => '',
|
||||
'subject' => 'New Scheduling Services Email: {mailing.subject}',
|
||||
'message' => 'A new mailing has been scheduled: {mailing.name}
|
||||
|
||||
You can review the mail here: {mailing.editURL}
|
||||
You can schedule the mail here: {mailing.scheduleURL}
|
||||
|
||||
The content of the email is:
|
||||
<pre>
|
||||
{mailing.html}
|
||||
</pre>
|
||||
',
|
||||
),
|
||||
'#name' => 'rules_action_civicrm_mailing_send_email',
|
||||
'#info' =>
|
||||
array (
|
||||
'label' => 'Send Email',
|
||||
'arguments' =>
|
||||
array (
|
||||
'mailing' =>
|
||||
array (
|
||||
'type' => 'mailing',
|
||||
'label' => 'Send Email',
|
||||
),
|
||||
),
|
||||
'module' => 'CiviCRM Mailing',
|
||||
),
|
||||
),
|
||||
),
|
||||
'#version' => 6003,
|
||||
),
|
||||
'rules_2' =>
|
||||
array (
|
||||
'#type' => 'rule',
|
||||
'#set' => 'event_mailing_scheduled',
|
||||
'#label' => 'Send Mail to Print Production',
|
||||
'#active' => 1,
|
||||
'#weight' => '0',
|
||||
'#categories' =>
|
||||
array (
|
||||
),
|
||||
'#status' => 'custom',
|
||||
'#conditions' =>
|
||||
array (
|
||||
),
|
||||
'#actions' =>
|
||||
array (
|
||||
0 =>
|
||||
array (
|
||||
'#weight' => 0,
|
||||
'#info' =>
|
||||
array (
|
||||
'label' => 'Send Email',
|
||||
'arguments' =>
|
||||
array (
|
||||
'mailing' =>
|
||||
array (
|
||||
'type' => 'mailing',
|
||||
'label' => 'Send Email',
|
||||
),
|
||||
),
|
||||
'module' => 'CiviCRM Mailing',
|
||||
),
|
||||
'#name' => 'rules_action_civicrm_mailing_send_email',
|
||||
'#settings' =>
|
||||
array (
|
||||
'to' => print.production@example.com',
|
||||
'from' => '',
|
||||
'subject' => 'New Email to Print Production: {mailing.subject}',
|
||||
'message' => 'A new mailing has been scheduled: {mailing.name}
|
||||
|
||||
You can review the mail here: {mailing.viewURL}
|
||||
You can approve the mail here: {mailing.approveURL}
|
||||
|
||||
The content of the email is:
|
||||
<pre>
|
||||
{mailing.html}
|
||||
</pre>
|
||||
',
|
||||
),
|
||||
'#type' => 'action',
|
||||
),
|
||||
),
|
||||
'#version' => 6003,
|
||||
),
|
||||
),
|
||||
)
|
|
@ -0,0 +1,11 @@
|
|||
name = CiviCRM Theme
|
||||
description = Define alternate themes for CiviCRM.
|
||||
version = 7.x-4.7.29
|
||||
core = 7.x
|
||||
package = CiviCRM
|
||||
project = civicrm
|
||||
|
||||
dependencies[] = civicrm
|
||||
|
||||
files[] = civicrmtheme.module
|
||||
files[] = civicrmtheme.install
|
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_enable().
|
||||
*/
|
||||
function civicrmtheme_enable() {
|
||||
// update module weight to 110, to make it run after system and civicrm
|
||||
db_query("UPDATE {system} SET weight = 110 WHERE name = 'civicrmtheme'");
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_install().
|
||||
*/
|
||||
function civicrmtheme_install() {
|
||||
$t = get_t();
|
||||
$link = l($t('Administer > Appearance > Administration theme'), 'admin/appearance');
|
||||
drupal_set_message($t("CiviCRM theme configuration setting is available under !link", array('!link' => $link)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_uninstall().
|
||||
*/
|
||||
function civicrmtheme_uninstall() {
|
||||
// cleaning variables
|
||||
variable_del('civicrmtheme_theme_admin');
|
||||
variable_del('civicrmtheme_theme_public');
|
||||
}
|
|
@ -0,0 +1,137 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Get all available themes.
|
||||
*/
|
||||
function civicrmtheme_list_themes() {
|
||||
$theme_list = array();
|
||||
// Get current list of themes.
|
||||
$themes = system_rebuild_theme_data();
|
||||
uasort($themes, 'system_sort_modules_by_info_name');
|
||||
|
||||
foreach ($themes as & $theme) {
|
||||
if (!empty($theme->info['hidden'])) {
|
||||
continue;
|
||||
}
|
||||
$theme_list[$theme->name] = $theme->info['name'];
|
||||
}
|
||||
|
||||
return $theme_list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_alter().
|
||||
*/
|
||||
function civicrmtheme_form_system_themes_admin_form_alter(&$form, $form_state) {
|
||||
// Define a fieldset for civicrm theme setting section
|
||||
$form['admin_theme']['civicrm'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('CiviCRM'),
|
||||
'#collapsible' => TRUE,
|
||||
'#description' => t('Choose theme for CiviCRM.'),
|
||||
);
|
||||
|
||||
$theme_list = civicrmtheme_list_themes();
|
||||
|
||||
$form['admin_theme']['civicrm']['civicrm_admin'] = array(
|
||||
'#type' => 'select',
|
||||
'#options' => array(
|
||||
0 => t('Default theme')) + $theme_list,
|
||||
'#title' => t('CiviCRM Administration theme'),
|
||||
'#description' => t('Choose theme for CiviCRM administration/backend pages.'),
|
||||
'#default_value' => variable_get('civicrmtheme_theme_admin', 0),
|
||||
);
|
||||
|
||||
$form['admin_theme']['civicrm']['civicrm_public'] = array(
|
||||
'#type' => 'select',
|
||||
'#options' => array(
|
||||
0 => t('Default theme')) + $theme_list,
|
||||
'#title' => t('CiviCRM Public theme'),
|
||||
'#description' => t('Choose theme for CiviCRM frontend pages.'),
|
||||
'#default_value' => variable_get('civicrmtheme_theme_public', 0),
|
||||
);
|
||||
|
||||
// Add extra submit
|
||||
$form['#submit'][] = 'civicrmtheme_system_themes_admin_form_submit';
|
||||
$form['admin_theme']['actions']['#weight'] = 10;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process system_themes_form extra submit.
|
||||
*/
|
||||
function civicrmtheme_system_themes_admin_form_submit($form, &$form_state) {
|
||||
variable_set('civicrmtheme_theme_admin', $form_state['values']['civicrm_admin']);
|
||||
variable_set('civicrmtheme_theme_public', $form_state['values']['civicrm_public']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_custom_theme().
|
||||
*/
|
||||
function civicrmtheme_custom_theme() {
|
||||
if (arg(0) != 'civicrm') {
|
||||
return;
|
||||
}
|
||||
if (arg(1) == 'upgrade') {
|
||||
return;
|
||||
}
|
||||
|
||||
$admin_theme = variable_get('civicrmtheme_theme_admin', 0);
|
||||
$public_theme = variable_get('civicrmtheme_theme_public', 0);
|
||||
|
||||
if ((!$admin_theme && !$public_theme) || !civicrm_initialize()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the menu items.
|
||||
$args = explode('?', $_GET['q']);
|
||||
$path = $args[0];
|
||||
|
||||
// Get the menu for above URL.
|
||||
$item = CRM_Core_Menu::get($path);
|
||||
|
||||
// Check for public pages
|
||||
// If public page and civicrm public theme is set, apply civicrm public theme
|
||||
// If user does not have access to CiviCRM use the public page for the error message
|
||||
if (!user_access('access CiviCRM') || CRM_Utils_Array::value('is_public', $item)) {
|
||||
if ($public_theme) {
|
||||
return $public_theme;
|
||||
}
|
||||
}
|
||||
elseif ($admin_theme) {
|
||||
// If admin page and civicrm admin theme is set, apply civicrm admin theme
|
||||
return $admin_theme;
|
||||
}
|
||||
}
|
808
sites/all/modules/civicrm/drupal/modules/views/civicrm.views.inc
Normal file
808
sites/all/modules/civicrm/drupal/modules/views/civicrm.views.inc
Normal file
|
@ -0,0 +1,808 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2009 James Rakich
|
||||
* Licensed to CiviCRM under the Academic Free License version 3.0.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* civicrm.views.inc Called from civicrm.module, gives the views cache all information it needs
|
||||
* to access CiviCRM's database for use in Views, as well as referencing the
|
||||
* custom handlers for displaying, sorting, filtering and accepting arguments
|
||||
* for this data.
|
||||
*
|
||||
// Defines tables, joins and relationships
|
||||
* function civicrm_views_data() {
|
||||
* CiviCRM Contacts Base Table
|
||||
* CiviCRM Activities Base Table
|
||||
* CiviCRM Relationships Base Table
|
||||
* Custom Data Cache Query and Calls
|
||||
*
|
||||
* function civicrm_views_href( $text, $path, $query )
|
||||
* Generates a link for CiviCRM Paths - unchanged from previous code (anonymous donation)
|
||||
*
|
||||
* function civicrm_views_custom_data_cache($data, $entity_type, $groupID, $subType, $style)
|
||||
* Collects the data from Custom Data Groups and assigns them to base tables.
|
||||
*
|
||||
* function civicrm_views_get_field ($type)
|
||||
* function civicrm_views_get_argument ($type)
|
||||
* function civicrm_views_get_filter ($type)
|
||||
* function civicrm_views_get_sort ($type)
|
||||
* Assign handlers to custom fields based on the data type (from the database records)
|
||||
*
|
||||
* function civicrm_date_api_tables()
|
||||
* function civicrm_date_api_fields()
|
||||
* Tells Views which fields to expose as Date API fields
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_views_data().
|
||||
*
|
||||
* Run hook_views_data for active CiviCRM components
|
||||
*/
|
||||
function civicrm_views_data_alter(&$data) {
|
||||
if (!civicrm_initialize() || CRM_Utils_System::isInUpgradeMode()) {
|
||||
return;
|
||||
}
|
||||
|
||||
require_once 'CRM/Core/Config.php';
|
||||
require_once 'CRM/Core/BAO/CustomGroup.php';
|
||||
require_once 'CRM/Core/DAO.php';
|
||||
require_once 'CRM/Core/Error.php';
|
||||
require_once 'CRM/Contact/BAO/Contact.php';
|
||||
require_once 'CRM/Event/BAO/Query.php';
|
||||
require_once 'CRM/Case/BAO/Case.php';
|
||||
require_once 'components/civicrm.core.inc';
|
||||
|
||||
// Get list of enabled CiviCRM components
|
||||
$enabled = CRM_Core_Component::getEnabledComponents();
|
||||
|
||||
// $data = array();
|
||||
// Load Core CiviCRM data
|
||||
_civicrm_core_data($data, $enabled);
|
||||
|
||||
// Load enabled optional components
|
||||
if (isset($enabled['CiviCampaign'])) {
|
||||
include_once 'components/civicrm.campaign.inc';
|
||||
_civicrm_campaign_data($data, $enabled);
|
||||
}
|
||||
// Though not explicitly effectively CiviPledge depends on CiviContribute
|
||||
// so they share an include file
|
||||
if (isset($enabled['CiviContribute']) ||
|
||||
isset($enabled['CiviPledge'])
|
||||
) {
|
||||
include_once 'components/civicrm.contribute.inc';
|
||||
_civicrm_contribute_data($data, $enabled);
|
||||
include_once 'components/civicrm.lineitem.inc';
|
||||
_civicrm_lineitem_data($data, $enabled);
|
||||
}
|
||||
if (isset($enabled['CiviEvent'])) {
|
||||
include_once 'components/civicrm.event.inc';
|
||||
_civicrm_event_data($data, $enabled);
|
||||
}
|
||||
if (isset($enabled['CiviGrant'])) {
|
||||
include_once 'components/civicrm.grant.inc';
|
||||
_civicrm_grant_data($data, $enabled);
|
||||
}
|
||||
if (isset($enabled['CiviMail'])) {
|
||||
include_once 'components/civicrm.mail.inc';
|
||||
_civicrm_mail_data($data, $enabled);
|
||||
}
|
||||
if (isset($enabled['CiviMember'])) {
|
||||
include_once 'components/civicrm.member.inc';
|
||||
_civicrm_member_data($data, $enabled);
|
||||
}
|
||||
if (isset($enabled['CiviCase'])) {
|
||||
include_once 'components/civicrm.case.inc';
|
||||
_civicrm_case_data($data, $enabled);
|
||||
}
|
||||
if (isset($enabled['CiviContribute']) ||
|
||||
isset($enabled['CiviEvent']) ||
|
||||
isset($enabled['CiviMember'])
|
||||
) {
|
||||
include_once 'components/civicrm.price_set.inc';
|
||||
_civicrm_price_set_data($data, $enabled);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return link to CiviCRM path
|
||||
*
|
||||
* @param $text
|
||||
*
|
||||
* @param $path
|
||||
*
|
||||
* @param $query
|
||||
*
|
||||
* @return String path to CiviCRM
|
||||
*/
|
||||
function civicrm_views_href($text, $path, $query) {
|
||||
$url = civicrm_views_url($path, $query);
|
||||
return "<a href=\"$url\">$text</a>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return url to CiviCRM path
|
||||
*
|
||||
* @param $path string The path being linked to, such as "civicrm/add"
|
||||
* @param $query string A query string to append to the link.
|
||||
* @param $absolute boolean Whether to force the output to be an absolute link (beginning with http:).
|
||||
* Useful for links that will be displayed outside the site, such as in an
|
||||
* RSS feed.
|
||||
*
|
||||
* @return string an HTML string containing a link to the given path.
|
||||
*/
|
||||
function civicrm_views_url($path, $query, $absolute = FALSE) {
|
||||
// Force alphabetical order of query params, for consistent support
|
||||
// of Drupal aliases. This is required because $query is a string that may
|
||||
// be coming to us in any order; but query parameter order matters when
|
||||
// passing that query string as part of $path in url($path). Admittedly it's
|
||||
// not common to passt the query string as part of $path in url($path) (you
|
||||
// would normally pass it as $options['query'] in url($path, $options)), but
|
||||
// doing so is required for Drupal alias support.
|
||||
if (!empty($query)) {
|
||||
if (is_array($query)) {
|
||||
$query_data = $query;
|
||||
}
|
||||
else {
|
||||
parse_str($query, $query_data);
|
||||
}
|
||||
ksort($query_data);
|
||||
$query = http_build_query($query_data);
|
||||
$path .= "?{$query}";
|
||||
}
|
||||
$options = array(
|
||||
'absolute' => $absolute,
|
||||
);
|
||||
$url = url($path, $options);
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new View fields from CiviCRM fields
|
||||
*
|
||||
* @param $fields
|
||||
* Array of fields in a table obtained from a DAO fields method for $tableName
|
||||
*
|
||||
* @param $data
|
||||
* Array returned to hook_views_data
|
||||
*
|
||||
* @param $tableName
|
||||
* String tabled nam of field whose DAO is returned in $fields
|
||||
*
|
||||
* @param $skipFields
|
||||
* (optional) Array of fields not to add form the $fields table
|
||||
*/
|
||||
function civicrm_views_add_fields(&$fields, &$data, $tableName, &$skipFields = NULL) {
|
||||
foreach ($fields as $name => $value) {
|
||||
// Only add fields not in $data or $skipFields and has a ['title']
|
||||
if (isset($value['custom_field_id']) ||
|
||||
CRM_Utils_Array::value($name, $skipFields) ||
|
||||
CRM_Utils_Array::value($name, $data) ||
|
||||
!isset($value['title']) ||
|
||||
(isset($value['where']) &&
|
||||
substr($value['where'], 0, strlen($tableName) + 1) != "{$tableName}."
|
||||
)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ensure the field isn't alredy defined in $data using $data[$xyz]['real field'] where $xyz is a field name passed in $data
|
||||
foreach ($data as $field => $current) {
|
||||
if (isset($current['real field']) and $current['real field'] == $name) {
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
|
||||
$type = CRM_Utils_Array::value('type', $value, 'String');
|
||||
$data[$value['name']] = array(
|
||||
'title' => $value['title'],
|
||||
'help' => $value['title'],
|
||||
'field' => civicrm_views_get_field($type),
|
||||
'sort' => civicrm_views_get_sort($type),
|
||||
'filter' => civicrm_views_get_filter($type),
|
||||
'argument' => civicrm_views_get_argument($type),
|
||||
);
|
||||
|
||||
// For date fields add in 6 arguments
|
||||
// not sure how its numeric here, but leaving it as is for now
|
||||
if ($type == 4) {
|
||||
civicrm_views_add_date_arguments($data, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function adds 6 date arguments to a date field
|
||||
*
|
||||
* @param $data
|
||||
* Array passed back to hook_views_data()
|
||||
*
|
||||
* @param $value
|
||||
* Array contains meta data about field from DAO fields function
|
||||
*
|
||||
*/
|
||||
function civicrm_views_add_date_arguments(&$data, $value) {
|
||||
|
||||
$data[$value['name']]['argument'] = array(
|
||||
'handler' => 'date_views_argument_handler',
|
||||
'empty field name' => t('Undated'),
|
||||
'is date' => TRUE,
|
||||
);
|
||||
$data[$value['name'] . '_full'] = array(
|
||||
'title' => $value['title'],
|
||||
'help' => t('In the form of CCYYMMDD.'),
|
||||
'argument' => array(
|
||||
'field' => $value['name'],
|
||||
'handler' => 'views_handler_argument_civicrm_fulldate',
|
||||
),
|
||||
);
|
||||
$data[$value['name'] . '_year_month'] = array(
|
||||
'title' => t('%title year + month', array('%title' => $value['title'])),
|
||||
'help' => t('In the form of YYYYMM.'),
|
||||
'argument' => array(
|
||||
'field' => $value['name'],
|
||||
'handler' => 'views_handler_argument_civicrm_year_month',
|
||||
),
|
||||
);
|
||||
$data[$value['name'] . '_year'] = array(
|
||||
'title' => t('%title year', array('%title' => $value['title'])),
|
||||
'help' => t('In the form of YYYY.'),
|
||||
'argument' => array(
|
||||
'field' => $value['name'],
|
||||
'handler' => 'views_handler_argument_civicrm_year',
|
||||
),
|
||||
);
|
||||
$data[$value['name'] . '_month'] = array(
|
||||
'title' => t('%title month', array('%title' => $value['title'])),
|
||||
'help' => t('In the form of MM (01 - 12).'),
|
||||
'argument' => array(
|
||||
'field' => $value['name'],
|
||||
'handler' => 'views_handler_argument_civicrm_month',
|
||||
),
|
||||
);
|
||||
$data[$value['name'] . '_day'] = array(
|
||||
'title' => t('%title day', array('%title' => $value['title'])),
|
||||
'help' => t('In the form of DD (01 - 31).'),
|
||||
'argument' => array(
|
||||
'field' => $value['name'],
|
||||
'handler' => 'views_handler_argument_civicrm_day',
|
||||
),
|
||||
);
|
||||
$data[$value['name'] . '_week'] = array(
|
||||
'title' => t('%title week', array('%title' => $value['title'])),
|
||||
'help' => t('In the form of WW (01 - 53).'),
|
||||
'argument' => array(
|
||||
'field' => $value['name'],
|
||||
'handler' => 'views_handler_argument_civicrm_week',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Custom Fields to $data array
|
||||
*
|
||||
* @param $data
|
||||
* Array of fields passed to hook_views_data()
|
||||
*
|
||||
* @param $entity_type
|
||||
* String CivicRM entity Type ie "Contact"
|
||||
*
|
||||
* @param $group_id
|
||||
* Integer Id of the Custom Field Group
|
||||
*
|
||||
* @param $sub_type
|
||||
* (optional) Integer Id of the Sub-Type, ie Contact Sub Type
|
||||
*
|
||||
* @return mixed
|
||||
* $Data array with the new custom field appended or void
|
||||
*/
|
||||
function civicrm_views_custom_data_cache(&$data, $entity_type, $group_id, $sub_type) {
|
||||
if (CRM_Core_Config::isUpgradeMode()) {
|
||||
return;
|
||||
}
|
||||
// From http://forum.civicrm.org/index.php/topic,17658.msg73901.html#msg73901, CRM-7860.
|
||||
$tree = CRM_Core_BAO_CustomGroup::getTree($entity_type, NULL, NULL, $group_id, $sub_type, NULL);
|
||||
|
||||
$join_table = civicrm_views_get_join_table($entity_type);
|
||||
foreach ($tree as $groupkey => $current_group) {
|
||||
// Ignore 'info' key as it is not a real field.
|
||||
if ($groupkey == 'info') {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Provide custom table data, including group title and implicit table join.
|
||||
$data[$current_group['table_name']]['table'] = array(
|
||||
'group' => t('CiviCRM Custom: !title', array('!title' => $current_group['title'])),
|
||||
'join' => array(
|
||||
$join_table => array(
|
||||
'left_field' => 'id',
|
||||
'field' => 'entity_id',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Provide implicit joins in the other direction.
|
||||
// Skip 'contribution', activity' and 'event' as these are not directly related to users.
|
||||
if ($join_table != 'civicrm_event' && $join_table != 'civicrm_activity' && $join_table != 'civicrm_contribution') {
|
||||
// Expose custom data to users view.
|
||||
$data[$current_group['table_name']]['table']['join']['users'] = array(
|
||||
'left_table' => $join_table,
|
||||
'left_field' => 'id',
|
||||
'field' => 'entity_id',
|
||||
);
|
||||
|
||||
// Expose custom data to contact view.
|
||||
if ($join_table != 'civicrm_contact') {
|
||||
$data[$current_group['table_name']]['table']['join']['civicrm_contact'] = array(
|
||||
'left_table' => $join_table,
|
||||
'left_field' => 'id',
|
||||
'field' => 'entity_id',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($current_group['fields'] as $key => $current_field) {
|
||||
//Create the Views Field
|
||||
$option_group_id = isset($current_field['option_group_id']) ? $current_field['option_group_id'] : NULL;
|
||||
$data[$current_group['table_name']][$current_field['column_name']] = array(
|
||||
'title' => $current_field['label'],
|
||||
'help' => empty($current_field['help_post']) ? t('Custom Data Field') : $current_field['help_post'],
|
||||
'field' => civicrm_views_get_field($current_field['data_type'], $current_field['html_type']),
|
||||
'argument' => civicrm_views_get_argument($current_field['data_type']),
|
||||
'filter' => civicrm_views_get_filter($current_field['data_type'], $current_field['html_type'], $option_group_id),
|
||||
'sort' => civicrm_views_get_sort($current_field['data_type']),
|
||||
'relationship' => civicrm_views_get_relationship($current_field['data_type']),
|
||||
);
|
||||
|
||||
//For date fields add in 6 arguments
|
||||
if ($current_field['data_type'] == 'Date') {
|
||||
//@TODO Still need to get the field under it's respecitve group, I may e able to set the civicrm_views_add_date_arguments() function with a group variable and default it to null
|
||||
$value = array();
|
||||
$value['title'] = $current_field['label'];
|
||||
$value['name'] = $current_field['column_name'];
|
||||
civicrm_views_add_date_arguments($data[$current_group['table_name']], $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the implicit join table for a custom group table based on its entity type.
|
||||
*/
|
||||
function civicrm_views_get_join_table($entity_type) {
|
||||
switch ($entity_type) {
|
||||
case "Contact":
|
||||
case "Individual":
|
||||
case "Household":
|
||||
case "Organization":
|
||||
return 'civicrm_contact';
|
||||
|
||||
case "Group":
|
||||
return 'civicrm_group';
|
||||
|
||||
case "Address":
|
||||
return 'civicrm_address';
|
||||
|
||||
case "Event":
|
||||
return 'civicrm_event';
|
||||
|
||||
case "Participant":
|
||||
return 'civicrm_participant';
|
||||
|
||||
case "Contribution":
|
||||
return 'civicrm_contribution';
|
||||
|
||||
case "Activity":
|
||||
return 'civicrm_activity';
|
||||
|
||||
case "Relationship":
|
||||
return 'civicrm_relationship';
|
||||
|
||||
case "Membership":
|
||||
return 'civicrm_membership';
|
||||
|
||||
case "Grant":
|
||||
return 'civicrm_grant';
|
||||
|
||||
case "Campaign":
|
||||
case "Survey":
|
||||
return 'civicrm_campaign';
|
||||
|
||||
case "Case":
|
||||
return 'civicrm_case';
|
||||
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Acquire the proper field handler by checking against the field's data_type as defined by CRM_Utils_Type.
|
||||
*
|
||||
* @param $data_type
|
||||
* A String containing the field data type
|
||||
* @param $html_type
|
||||
* A String containing the field html type
|
||||
*
|
||||
* @return array
|
||||
* An array containing the handler name and any extra settings
|
||||
*/
|
||||
function civicrm_views_get_field($data_type, $html_type = NULL) {
|
||||
// Relying on html types as opposed to data types seems like a code smell.
|
||||
// Would love to be able to remove this logic.
|
||||
$customHTMLTypes = array(
|
||||
'Select', 'Multi-Select', 'AdvMulti-Select', 'Radio', 'CheckBox',
|
||||
'Select State/Province', 'Select Country', 'Multi-Select Country',
|
||||
'Multi-Select State/Province', 'Autocomplete-Select',
|
||||
);
|
||||
if (in_array($html_type, $customHTMLTypes)) {
|
||||
return array(
|
||||
'handler' => 'civicrm_handler_field_custom',
|
||||
'click sortable' => TRUE,
|
||||
);
|
||||
}
|
||||
if ($html_type == 'File') {
|
||||
return array(
|
||||
'handler' => 'civicrm_handler_field_custom_file',
|
||||
'click sortable' => TRUE,
|
||||
);
|
||||
}
|
||||
|
||||
switch ($data_type) {
|
||||
case "String":
|
||||
case "Memo":
|
||||
return array('handler' => 'civicrm_handler_field_markup', 'click sortable' => TRUE);
|
||||
|
||||
case "Float":
|
||||
return array('handler' => 'views_handler_field_numeric', 'click sortable' => TRUE, 'float' => TRUE);
|
||||
|
||||
case "Int":
|
||||
return array('handler' => 'civicrm_handler_field_custom', 'click sortable' => TRUE);
|
||||
|
||||
case "Date":
|
||||
return array('handler' => 'civicrm_handler_field_datetime', 'click sortable' => TRUE);
|
||||
|
||||
case "Boolean":
|
||||
return array('handler' => 'views_handler_field_boolean', 'click sortable' => TRUE);
|
||||
|
||||
case "StateProvince":
|
||||
return array('handler' => 'civicrm_handler_field_state', 'click sortable' => TRUE);
|
||||
|
||||
case "Country":
|
||||
return array('handler' => 'civicrm_handler_field_country', 'click sortable' => TRUE);
|
||||
|
||||
case "County":
|
||||
return array('handler' => 'civicrm_handler_field_pseudo_constant', 'click sortable' => TRUE, 'pseudo class' => 'CRM_Core_PseudoConstant', 'pseudo method' => 'county');
|
||||
|
||||
default:
|
||||
return array('views_handler_field', 'click sortable' => TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Acquire the proper argument handler by checking against the field's data_type as defined by CRM_Utils_Type.
|
||||
*
|
||||
* @param $type
|
||||
* A String containing the field type
|
||||
*
|
||||
* @return array
|
||||
* An array containing the handler name and any extra settings
|
||||
*/
|
||||
function civicrm_views_get_argument($type) {
|
||||
switch ($type) {
|
||||
case "String":
|
||||
case "Memo":
|
||||
return array('handler' => 'views_handler_argument');
|
||||
|
||||
case "Float":
|
||||
case "Int":
|
||||
return array('handler' => 'views_handler_argument_numeric');
|
||||
|
||||
case "Date":
|
||||
return array('handler' => 'views_handler_argument_date');
|
||||
|
||||
case "Boolean":
|
||||
return array('handler' => 'views_handler_argument');
|
||||
|
||||
case "StateProvince":
|
||||
return array('handler' => 'views_handler_argument');
|
||||
|
||||
case "Country":
|
||||
return array('handler' => 'views_handler_argument');
|
||||
|
||||
case "County":
|
||||
return array('handler' => 'views_handler_argument');
|
||||
|
||||
default:
|
||||
return array('handler' => 'views_handler_argument');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Acquire the proper filter handler by checking against the field's data_type as defined by CRM_Utils_Type.
|
||||
*
|
||||
* @param $data_type
|
||||
* A String containing the field data type
|
||||
* @param $html_type
|
||||
* A string containing the field html type
|
||||
*
|
||||
* @return array
|
||||
* An array containing the handler name and any extra settings
|
||||
*/
|
||||
function civicrm_views_get_filter($data_type, $html_type = NULL, $option_group_id = NULL) {
|
||||
// Relying on html types as opposed to data types seems like a code smell.
|
||||
// Would love to be able to remove this logic.
|
||||
$customMultiValueHTMLTypes = array(
|
||||
'Multi-Select', 'AdvMulti-Select', 'CheckBox', 'Multi-Select Country',
|
||||
'Multi-Select State/Province',
|
||||
);
|
||||
if ($html_type == 'Multi-Select Country') {
|
||||
return array(
|
||||
'handler' => 'civicrm_handler_filter_country_multi',
|
||||
);
|
||||
}
|
||||
elseif ($html_type == 'Multi-Select State/Province') {
|
||||
return array(
|
||||
'handler' => 'civicrm_handler_filter_state_multi',
|
||||
);
|
||||
}
|
||||
elseif (!empty($option_group_id) && in_array($html_type, $customMultiValueHTMLTypes)) {
|
||||
return array(
|
||||
'handler' => 'civicrm_handler_filter_custom_option',
|
||||
);
|
||||
}
|
||||
elseif (!empty($option_group_id)) {
|
||||
return array(
|
||||
'handler' => 'civicrm_handler_filter_custom_single_option',
|
||||
);
|
||||
}
|
||||
|
||||
switch ($data_type) {
|
||||
case "String":
|
||||
case "Memo":
|
||||
return array('handler' => 'views_handler_filter_string', 'allow empty' => TRUE);
|
||||
|
||||
case "Float":
|
||||
case "Int":
|
||||
return array('handler' => 'views_handler_filter_numeric', 'allow empty' => TRUE);
|
||||
|
||||
case "Date":
|
||||
return array('handler' => 'civicrm_handler_filter_datetime');
|
||||
|
||||
case "Boolean":
|
||||
return array('handler' => 'views_handler_filter_boolean_operator');
|
||||
|
||||
case "StateProvince":
|
||||
return array('handler' => 'civicrm_handler_filter_pseudo_constant', 'pseudo class' => 'CRM_Core_PseudoConstant', 'pseudo method' => 'stateProvince', 'allow empty' => TRUE);
|
||||
|
||||
case "Country":
|
||||
return array('handler' => 'civicrm_handler_filter_pseudo_constant', 'pseudo class' => 'CRM_Core_PseudoConstant', 'pseudo method' => 'country', 'allow empty' => TRUE);
|
||||
|
||||
case "County":
|
||||
return array('handler' => 'civicrm_handler_filter_pseudo_constant', 'pseudo class' => 'CRM_Core_PseudoConstant', 'pseudo method' => 'county', 'allow empty' => TRUE);
|
||||
|
||||
default:
|
||||
return array('handler' => 'views_handler_filter_string', 'allow empty' => TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Acquire the proper sort handler by checking against the field's data_type as defined by CRM_Utils_Type.
|
||||
*
|
||||
* @param $type
|
||||
* A String containing the field type
|
||||
*
|
||||
* @return array
|
||||
* An array containing the handler name and any extra settings
|
||||
*/
|
||||
function civicrm_views_get_sort($type) {
|
||||
switch ($type) {
|
||||
case "String":
|
||||
case "Memo":
|
||||
case "Float":
|
||||
case "Int":
|
||||
return array('handler' => 'views_handler_sort');
|
||||
|
||||
case "Date":
|
||||
return array('handler' => 'views_handler_sort_date');
|
||||
|
||||
case "Boolean":
|
||||
return array('handler' => 'views_handler_sort');
|
||||
|
||||
case "StateProvince":
|
||||
return array('handler' => 'views_handler_sort');
|
||||
|
||||
case "Country":
|
||||
return array('handler' => 'views_handler_sort');
|
||||
|
||||
case "County":
|
||||
return array('handler' => 'views_handler_sort');
|
||||
|
||||
default:
|
||||
return array('handler' => 'views_handler_sort');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Acquire the proper relationship handler by checking against the field's data_type as defined by CRM_Utils_Type.
|
||||
*
|
||||
* @param $type
|
||||
* A String containing the field type
|
||||
*
|
||||
* @return array
|
||||
* An array containing the handler name and any extra settings
|
||||
*/
|
||||
function civicrm_views_get_relationship($type) {
|
||||
switch ($type) {
|
||||
case "ContactReference":
|
||||
return array('handler' => 'views_handler_relationship', 'base' => 'civicrm_contact', 'base field' => 'id');
|
||||
|
||||
default:
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_date_views_fields().
|
||||
*/
|
||||
function civicrm_date_views_fields($field) {
|
||||
$values = array(
|
||||
// The type of date: DATE_UNIX, DATE_ISO, DATE_DATETIME.
|
||||
'sql_type' => DATE_DATETIME,
|
||||
// Timezone handling options: 'none', 'site', 'date', 'utc'.
|
||||
'tz_handling' => 'none',
|
||||
// Needed only for dates that use 'date' tz_handling.
|
||||
'timezone_field' => '',
|
||||
// Needed only for dates that use 'date' tz_handling.
|
||||
'offset_field' => '',
|
||||
// Array of "table.field" values for related fields that should be
|
||||
// loaded automatically in the Views SQL.
|
||||
'related_fields' => array(),
|
||||
// Granularity of this date field's db data.
|
||||
'granularity' => array('year', 'month', 'day', 'hour', 'minute', 'second'),
|
||||
);
|
||||
|
||||
switch ($field) {
|
||||
case 'civicrm_event.start_date':
|
||||
case 'civicrm_event.end_date':
|
||||
case 'civicrm_event.registration_start_date':
|
||||
case 'civicrm_event.registration_end_date':
|
||||
case 'civicrm_mailing_job.scheduled_date':
|
||||
case 'civicrm_mailing_job.start_date':
|
||||
case 'civicrm_mailing_job.end_date':
|
||||
case 'civicrm_activity.activity_date_time':
|
||||
case 'civicrm_campaign.start_date':
|
||||
case 'civicrm_campaign.end_date':
|
||||
case 'civicrm_case.start_date':
|
||||
case 'civicrm_case.end_date':
|
||||
return $values;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_date_api_tables().
|
||||
*/
|
||||
function civicrm_date_views_tables() {
|
||||
return array(
|
||||
'civicrm_mailing_job',
|
||||
'civicrm_event',
|
||||
'civicrm_case',
|
||||
'civicrm_activity',
|
||||
'civicrm_campaign',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_views_plugins().
|
||||
*/
|
||||
function civicrm_views_plugins() {
|
||||
$data = array();
|
||||
|
||||
// This just tells us that the themes are elsewhere
|
||||
$data['module'] = 'civicrm';
|
||||
|
||||
// Default argument to pull CiviCRM IDs from the URL
|
||||
$data['argument default']['civicrm_id'] = array(
|
||||
'title' => t('CiviCRM ID from URL'),
|
||||
'handler' => 'civicrm_plugin_argument_default_civicrm_id',
|
||||
);
|
||||
|
||||
// Calendar module integration
|
||||
if (module_exists('calendar')) {
|
||||
$civicrm_module_path = drupal_get_path('module', 'civicrm');
|
||||
$data['row'] = array(
|
||||
'civicrm_event_calendar' => array(
|
||||
'title' => t('Calendar Items'),
|
||||
'help' => t('Displays each selected event as a Calendar item.'),
|
||||
'handler' => 'calendar_plugin_row_civicrm',
|
||||
'path' => "$civicrm_module_path/modules/views/plugins",
|
||||
'base' => array('civicrm_event'),
|
||||
'uses options' => TRUE,
|
||||
'uses fields' => TRUE,
|
||||
'type' => 'normal',
|
||||
'dao class' => 'CRM_Event_DAO_Event',
|
||||
'title field' => 'title',
|
||||
),
|
||||
'civicrm_activity_calendar' => array(
|
||||
'title' => t('Calendar Items'),
|
||||
'help' => t('Displays each selected activity as a Calendar item.'),
|
||||
'handler' => 'calendar_plugin_row_civicrm',
|
||||
'path' => "$civicrm_module_path/modules/views/plugins",
|
||||
'base' => array('civicrm_activity'),
|
||||
'uses options' => TRUE,
|
||||
'uses fields' => TRUE,
|
||||
'type' => 'normal',
|
||||
'dao class' => 'CRM_Activity_DAO_Activity',
|
||||
'title field' => 'subject',
|
||||
),
|
||||
'civicrm_case_calendar' => array(
|
||||
'title' => t('Case Items'),
|
||||
'help' => t('Displays each selected case as a Calendar item.'),
|
||||
'handler' => 'calendar_plugin_row_civicrm',
|
||||
'path' => "$civicrm_module_path/modules/views/plugins",
|
||||
'base' => array('civicrm_case'),
|
||||
'uses options' => TRUE,
|
||||
'uses fields' => TRUE,
|
||||
'type' => 'normal',
|
||||
'dao class' => 'CRM_Case_DAO_Case',
|
||||
'title field' => 'subject',
|
||||
),
|
||||
'civicrm_mail_calendar' => array(
|
||||
'title' => t('Calendar Items'),
|
||||
'help' => t('Displays each selected mailing as a Calendar item.'),
|
||||
'handler' => 'calendar_plugin_row_civicrm',
|
||||
'path' => "$civicrm_module_path/modules/views/plugins",
|
||||
'base' => array('civicrm_mail'),
|
||||
'uses options' => TRUE,
|
||||
'uses fields' => TRUE,
|
||||
'type' => 'normal',
|
||||
'dao class' => 'CRM_Mailing_DAO_MailingJob',
|
||||
// @TODO come up with a better title field
|
||||
'title field' => 'mailing_id',
|
||||
),
|
||||
'civicrm_campaign_calendar' => array(
|
||||
'title' => t('Calendar Items'),
|
||||
'help' => t('Displays each selected campaign as a Calendar item.'),
|
||||
'handler' => 'calendar_plugin_row_civicrm',
|
||||
'path' => "$civicrm_module_path/modules/views/plugins",
|
||||
'base' => array('civicrm_campaign'),
|
||||
'uses options' => TRUE,
|
||||
'uses fields' => TRUE,
|
||||
'type' => 'normal',
|
||||
'dao class' => 'CRM_Campaign_DAO_Campaign',
|
||||
'title field' => 'title',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
|
@ -0,0 +1,819 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
* CiviCRM default views
|
||||
* @return array|null
|
||||
*/
|
||||
function civicrm_views_default_views() {
|
||||
$views = NULL;
|
||||
|
||||
if (module_exists('date_views') && module_exists('calendar')) {
|
||||
$view = new view();
|
||||
$view->name = 'civicrm_events';
|
||||
$view->description = 'Calendar of CiviCRM Events';
|
||||
$view->tag = 'civicrm';
|
||||
$view->base_table = 'civicrm_event';
|
||||
$view->human_name = 'CiviCRM Events';
|
||||
$view->core = 7;
|
||||
$view->api_version = '3.0';
|
||||
$view->disabled = TRUE;
|
||||
|
||||
/* Display: Master */
|
||||
$handler = $view->new_display('default', 'Master', 'default');
|
||||
$handler->display->display_options['title'] = 'CiviCRM Event Calendar';
|
||||
$handler->display->display_options['access']['type'] = 'perm';
|
||||
$handler->display->display_options['access']['perm'] = 'view event info';
|
||||
$handler->display->display_options['cache']['type'] = 'none';
|
||||
$handler->display->display_options['query']['type'] = 'views_query';
|
||||
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
|
||||
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
||||
$handler->display->display_options['pager']['type'] = 'some';
|
||||
$handler->display->display_options['pager']['options']['items_per_page'] = '5';
|
||||
$handler->display->display_options['pager']['options']['offset'] = '0';
|
||||
$handler->display->display_options['style_plugin'] = 'calendar_style';
|
||||
$handler->display->display_options['style_options']['name_size'] = '3';
|
||||
$handler->display->display_options['style_options']['mini'] = '0';
|
||||
$handler->display->display_options['style_options']['with_weekno'] = '0';
|
||||
$handler->display->display_options['style_options']['multiday_theme'] = '1';
|
||||
$handler->display->display_options['style_options']['theme_style'] = '1';
|
||||
$handler->display->display_options['style_options']['max_items'] = '0';
|
||||
$handler->display->display_options['row_plugin'] = 'civicrm_event_calendar';
|
||||
$handler->display->display_options['row_options']['colors']['calendar_colors_type'] = array(
|
||||
'article' => '#ffffff',
|
||||
'page' => '#ffffff',
|
||||
);
|
||||
|
||||
/* Field: CiviCRM Events: Title */
|
||||
$handler->display->display_options['fields']['title']['id'] = 'title';
|
||||
$handler->display->display_options['fields']['title']['table'] = 'civicrm_event';
|
||||
$handler->display->display_options['fields']['title']['field'] = 'title';
|
||||
$handler->display->display_options['fields']['title']['label'] = '';
|
||||
$handler->display->display_options['fields']['title']['alter']['alter_text'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['make_link'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['absolute'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['external'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['replace_spaces'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['trim_whitespace'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['nl2br'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = 1;
|
||||
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = 1;
|
||||
$handler->display->display_options['fields']['title']['alter']['strip_tags'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['trim'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['html'] = 0;
|
||||
$handler->display->display_options['fields']['title']['element_label_colon'] = FALSE;
|
||||
$handler->display->display_options['fields']['title']['element_default_classes'] = 1;
|
||||
$handler->display->display_options['fields']['title']['hide_empty'] = 0;
|
||||
$handler->display->display_options['fields']['title']['empty_zero'] = 0;
|
||||
$handler->display->display_options['fields']['title']['hide_alter_empty'] = 0;
|
||||
|
||||
/* Field: CiviCRM Events: Start Date */
|
||||
$handler->display->display_options['fields']['start_date']['id'] = 'start_date';
|
||||
$handler->display->display_options['fields']['start_date']['table'] = 'civicrm_event';
|
||||
$handler->display->display_options['fields']['start_date']['field'] = 'start_date';
|
||||
$handler->display->display_options['fields']['start_date']['label'] = '';
|
||||
$handler->display->display_options['fields']['start_date']['alter']['alter_text'] = 0;
|
||||
$handler->display->display_options['fields']['start_date']['alter']['make_link'] = 0;
|
||||
$handler->display->display_options['fields']['start_date']['alter']['absolute'] = 0;
|
||||
$handler->display->display_options['fields']['start_date']['alter']['external'] = 0;
|
||||
$handler->display->display_options['fields']['start_date']['alter']['replace_spaces'] = 0;
|
||||
$handler->display->display_options['fields']['start_date']['alter']['trim_whitespace'] = 0;
|
||||
$handler->display->display_options['fields']['start_date']['alter']['nl2br'] = 0;
|
||||
$handler->display->display_options['fields']['start_date']['alter']['word_boundary'] = 1;
|
||||
$handler->display->display_options['fields']['start_date']['alter']['ellipsis'] = 1;
|
||||
$handler->display->display_options['fields']['start_date']['alter']['strip_tags'] = 0;
|
||||
$handler->display->display_options['fields']['start_date']['alter']['trim'] = 0;
|
||||
$handler->display->display_options['fields']['start_date']['alter']['html'] = 0;
|
||||
$handler->display->display_options['fields']['start_date']['element_label_colon'] = FALSE;
|
||||
$handler->display->display_options['fields']['start_date']['element_default_classes'] = 1;
|
||||
$handler->display->display_options['fields']['start_date']['hide_empty'] = 0;
|
||||
$handler->display->display_options['fields']['start_date']['empty_zero'] = 0;
|
||||
$handler->display->display_options['fields']['start_date']['hide_alter_empty'] = 0;
|
||||
$handler->display->display_options['fields']['start_date']['date_format'] = 'long';
|
||||
|
||||
/* Sort criterion: CiviCRM Events: Start Date */
|
||||
$handler->display->display_options['sorts']['start_date']['id'] = 'start_date';
|
||||
$handler->display->display_options['sorts']['start_date']['table'] = 'civicrm_event';
|
||||
$handler->display->display_options['sorts']['start_date']['field'] = 'start_date';
|
||||
|
||||
/* Contextual filter: CiviCRM Events: Start Date */
|
||||
$handler->display->display_options['arguments']['start_date']['id'] = 'start_date';
|
||||
$handler->display->display_options['arguments']['start_date']['table'] = 'civicrm_event';
|
||||
$handler->display->display_options['arguments']['start_date']['field'] = 'start_date';
|
||||
$handler->display->display_options['arguments']['start_date']['default_action'] = 'default';
|
||||
$handler->display->display_options['arguments']['start_date']['default_argument_skip_url'] = 0;
|
||||
$handler->display->display_options['arguments']['start_date']['summary']['format'] = 'default_summary';
|
||||
$handler->display->display_options['arguments']['start_date']['granularity'] = 'year';
|
||||
$handler->display->display_options['arguments']['start_date']['add_delta'] = 'yes';
|
||||
$handler->display->display_options['arguments']['start_date']['date_fields'] = array(
|
||||
'civicrm_event.start_date' => 'civicrm_event.start_date',
|
||||
);
|
||||
|
||||
/* Filter criterion: CiviCRM Events: Is Active */
|
||||
$handler->display->display_options['filters']['is_active']['id'] = 'is_active';
|
||||
$handler->display->display_options['filters']['is_active']['table'] = 'civicrm_event';
|
||||
$handler->display->display_options['filters']['is_active']['field'] = 'is_active';
|
||||
$handler->display->display_options['filters']['is_active']['value'] = '1';
|
||||
$handler->display->display_options['filters']['is_active']['group'] = 0;
|
||||
|
||||
/* Filter criterion: CiviCRM Events: Is Public */
|
||||
$handler->display->display_options['filters']['is_public']['id'] = 'is_public';
|
||||
$handler->display->display_options['filters']['is_public']['table'] = 'civicrm_event';
|
||||
$handler->display->display_options['filters']['is_public']['field'] = 'is_public';
|
||||
$handler->display->display_options['filters']['is_public']['value'] = '1';
|
||||
$handler->display->display_options['filters']['is_public']['group'] = 0;
|
||||
|
||||
/* Display: Month */
|
||||
$handler = $view->new_display('page', 'Month', 'page');
|
||||
$handler->display->display_options['display_description'] = 'Monthly calendar of events';
|
||||
$handler->display->display_options['defaults']['pager'] = FALSE;
|
||||
$handler->display->display_options['pager']['type'] = 'date_views_pager';
|
||||
$handler->display->display_options['pager']['options']['date_id'] = 'month';
|
||||
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
|
||||
$handler->display->display_options['style_plugin'] = 'calendar_style';
|
||||
$handler->display->display_options['style_options']['name_size'] = '3';
|
||||
$handler->display->display_options['style_options']['mini'] = '0';
|
||||
$handler->display->display_options['style_options']['with_weekno'] = '0';
|
||||
$handler->display->display_options['style_options']['multiday_theme'] = '1';
|
||||
$handler->display->display_options['style_options']['theme_style'] = '1';
|
||||
$handler->display->display_options['style_options']['max_items'] = '0';
|
||||
$handler->display->display_options['defaults']['style_options'] = FALSE;
|
||||
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
|
||||
$handler->display->display_options['row_plugin'] = 'civicrm_event_calendar';
|
||||
$handler->display->display_options['row_options']['colors']['calendar_colors_type'] = array(
|
||||
'article' => '#ffffff',
|
||||
'page' => '#ffffff',
|
||||
);
|
||||
$handler->display->display_options['defaults']['row_options'] = FALSE;
|
||||
$handler->display->display_options['defaults']['arguments'] = FALSE;
|
||||
|
||||
/* Contextual filter: CiviCRM Events: Start Date */
|
||||
$handler->display->display_options['arguments']['start_date']['id'] = 'start_date';
|
||||
$handler->display->display_options['arguments']['start_date']['table'] = 'civicrm_event';
|
||||
$handler->display->display_options['arguments']['start_date']['field'] = 'start_date';
|
||||
$handler->display->display_options['arguments']['start_date']['default_action'] = 'default';
|
||||
$handler->display->display_options['arguments']['start_date']['default_argument_skip_url'] = 0;
|
||||
$handler->display->display_options['arguments']['start_date']['summary']['format'] = 'default_summary';
|
||||
$handler->display->display_options['arguments']['start_date']['add_delta'] = 'yes';
|
||||
$handler->display->display_options['arguments']['start_date']['date_fields'] = array(
|
||||
'civicrm_event.start_date' => 'civicrm_event.start_date',
|
||||
);
|
||||
$handler->display->display_options['path'] = 'events/month';
|
||||
|
||||
/* Display: Week */
|
||||
$handler = $view->new_display('page', 'Week', 'page_1');
|
||||
$handler->display->display_options['display_description'] = 'Weekly calendar of events';
|
||||
$handler->display->display_options['defaults']['pager'] = FALSE;
|
||||
$handler->display->display_options['pager']['type'] = 'date_views_pager';
|
||||
$handler->display->display_options['pager']['options']['date_id'] = 'month';
|
||||
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
|
||||
$handler->display->display_options['style_plugin'] = 'calendar_style';
|
||||
$handler->display->display_options['style_options']['calendar_type'] = 'week';
|
||||
$handler->display->display_options['style_options']['name_size'] = '3';
|
||||
$handler->display->display_options['style_options']['mini'] = '0';
|
||||
$handler->display->display_options['style_options']['with_weekno'] = '0';
|
||||
$handler->display->display_options['style_options']['multiday_theme'] = '1';
|
||||
$handler->display->display_options['style_options']['theme_style'] = '1';
|
||||
$handler->display->display_options['style_options']['max_items'] = '0';
|
||||
$handler->display->display_options['defaults']['style_options'] = FALSE;
|
||||
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
|
||||
$handler->display->display_options['row_plugin'] = 'civicrm_event_calendar';
|
||||
$handler->display->display_options['row_options']['colors']['calendar_colors_type'] = array(
|
||||
'article' => '#ffffff',
|
||||
'page' => '#ffffff',
|
||||
);
|
||||
$handler->display->display_options['defaults']['row_options'] = FALSE;
|
||||
$handler->display->display_options['defaults']['arguments'] = FALSE;
|
||||
|
||||
/* Contextual filter: CiviCRM Events: Start Date */
|
||||
$handler->display->display_options['arguments']['start_date']['id'] = 'start_date';
|
||||
$handler->display->display_options['arguments']['start_date']['table'] = 'civicrm_event';
|
||||
$handler->display->display_options['arguments']['start_date']['field'] = 'start_date';
|
||||
$handler->display->display_options['arguments']['start_date']['default_action'] = 'default';
|
||||
$handler->display->display_options['arguments']['start_date']['default_argument_skip_url'] = 0;
|
||||
$handler->display->display_options['arguments']['start_date']['summary']['format'] = 'default_summary';
|
||||
$handler->display->display_options['arguments']['start_date']['granularity'] = 'week';
|
||||
$handler->display->display_options['arguments']['start_date']['add_delta'] = 'yes';
|
||||
$handler->display->display_options['arguments']['start_date']['date_fields'] = array(
|
||||
'civicrm_event.start_date' => 'civicrm_event.start_date',
|
||||
);
|
||||
$handler->display->display_options['path'] = 'events/week';
|
||||
|
||||
/* Display: Day */
|
||||
$handler = $view->new_display('page', 'Day', 'page_2');
|
||||
$handler->display->display_options['display_description'] = 'Daily calendar of events';
|
||||
$handler->display->display_options['defaults']['pager'] = FALSE;
|
||||
$handler->display->display_options['pager']['type'] = 'date_views_pager';
|
||||
$handler->display->display_options['pager']['options']['date_id'] = 'month';
|
||||
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
|
||||
$handler->display->display_options['style_plugin'] = 'calendar_style';
|
||||
$handler->display->display_options['style_options']['calendar_type'] = 'day';
|
||||
$handler->display->display_options['style_options']['name_size'] = '3';
|
||||
$handler->display->display_options['style_options']['mini'] = '0';
|
||||
$handler->display->display_options['style_options']['with_weekno'] = '0';
|
||||
$handler->display->display_options['style_options']['multiday_theme'] = '1';
|
||||
$handler->display->display_options['style_options']['theme_style'] = '1';
|
||||
$handler->display->display_options['style_options']['max_items'] = '0';
|
||||
$handler->display->display_options['defaults']['style_options'] = FALSE;
|
||||
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
|
||||
$handler->display->display_options['row_plugin'] = 'civicrm_event_calendar';
|
||||
$handler->display->display_options['row_options']['colors']['calendar_colors_type'] = array(
|
||||
'article' => '#ffffff',
|
||||
'page' => '#ffffff',
|
||||
);
|
||||
$handler->display->display_options['defaults']['row_options'] = FALSE;
|
||||
$handler->display->display_options['defaults']['arguments'] = FALSE;
|
||||
|
||||
/* Contextual filter: CiviCRM Events: Start Date */
|
||||
$handler->display->display_options['arguments']['start_date']['id'] = 'start_date';
|
||||
$handler->display->display_options['arguments']['start_date']['table'] = 'civicrm_event';
|
||||
$handler->display->display_options['arguments']['start_date']['field'] = 'start_date';
|
||||
$handler->display->display_options['arguments']['start_date']['default_action'] = 'default';
|
||||
$handler->display->display_options['arguments']['start_date']['default_argument_skip_url'] = 0;
|
||||
$handler->display->display_options['arguments']['start_date']['summary']['format'] = 'default_summary';
|
||||
$handler->display->display_options['arguments']['start_date']['granularity'] = 'day';
|
||||
$handler->display->display_options['arguments']['start_date']['add_delta'] = 'yes';
|
||||
$handler->display->display_options['arguments']['start_date']['date_fields'] = array(
|
||||
'civicrm_event.start_date' => 'civicrm_event.start_date',
|
||||
);
|
||||
$handler->display->display_options['path'] = 'events/day';
|
||||
|
||||
/* Display: Year */
|
||||
$handler = $view->new_display('page', 'Year', 'page_3');
|
||||
$handler->display->display_options['display_description'] = 'Annual calendar of events';
|
||||
$handler->display->display_options['defaults']['pager'] = FALSE;
|
||||
$handler->display->display_options['pager']['type'] = 'date_views_pager';
|
||||
$handler->display->display_options['pager']['options']['date_id'] = 'month';
|
||||
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
|
||||
$handler->display->display_options['style_plugin'] = 'calendar_style';
|
||||
$handler->display->display_options['style_options']['calendar_type'] = 'year';
|
||||
$handler->display->display_options['style_options']['name_size'] = '3';
|
||||
$handler->display->display_options['style_options']['mini'] = '0';
|
||||
$handler->display->display_options['style_options']['with_weekno'] = '0';
|
||||
$handler->display->display_options['style_options']['multiday_theme'] = '1';
|
||||
$handler->display->display_options['style_options']['theme_style'] = '1';
|
||||
$handler->display->display_options['style_options']['max_items'] = '0';
|
||||
$handler->display->display_options['defaults']['style_options'] = FALSE;
|
||||
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
|
||||
$handler->display->display_options['row_plugin'] = 'civicrm_event_calendar';
|
||||
$handler->display->display_options['row_options']['colors']['calendar_colors_type'] = array(
|
||||
'article' => '#ffffff',
|
||||
'page' => '#ffffff',
|
||||
);
|
||||
$handler->display->display_options['defaults']['row_options'] = FALSE;
|
||||
$handler->display->display_options['defaults']['arguments'] = FALSE;
|
||||
|
||||
/* Contextual filter: CiviCRM Events: Start Date */
|
||||
$handler->display->display_options['arguments']['start_date']['id'] = 'start_date';
|
||||
$handler->display->display_options['arguments']['start_date']['table'] = 'civicrm_event';
|
||||
$handler->display->display_options['arguments']['start_date']['field'] = 'start_date';
|
||||
$handler->display->display_options['arguments']['start_date']['default_action'] = 'default';
|
||||
$handler->display->display_options['arguments']['start_date']['default_argument_skip_url'] = 0;
|
||||
$handler->display->display_options['arguments']['start_date']['summary']['format'] = 'default_summary';
|
||||
$handler->display->display_options['arguments']['start_date']['granularity'] = 'year';
|
||||
$handler->display->display_options['arguments']['start_date']['add_delta'] = 'yes';
|
||||
$handler->display->display_options['arguments']['start_date']['date_fields'] = array(
|
||||
'civicrm_event.start_date' => 'civicrm_event.start_date',
|
||||
);
|
||||
$handler->display->display_options['path'] = 'events/year';
|
||||
|
||||
/* Display: Block */
|
||||
$handler = $view->new_display('block', 'Block', 'block_1');
|
||||
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
|
||||
$handler->display->display_options['style_plugin'] = 'calendar_style';
|
||||
$handler->display->display_options['style_options']['name_size'] = '3';
|
||||
$handler->display->display_options['style_options']['mini'] = '0';
|
||||
$handler->display->display_options['style_options']['with_weekno'] = '0';
|
||||
$handler->display->display_options['style_options']['multiday_theme'] = '1';
|
||||
$handler->display->display_options['style_options']['theme_style'] = '1';
|
||||
$handler->display->display_options['style_options']['max_items'] = '0';
|
||||
$handler->display->display_options['defaults']['style_options'] = FALSE;
|
||||
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
|
||||
$handler->display->display_options['row_plugin'] = 'civicrm_event_calendar';
|
||||
$handler->display->display_options['row_options']['colors']['calendar_colors_type'] = array(
|
||||
'article' => '#ffffff',
|
||||
'page' => '#ffffff',
|
||||
);
|
||||
$handler->display->display_options['defaults']['row_options'] = FALSE;
|
||||
$handler->display->display_options['defaults']['arguments'] = FALSE;
|
||||
|
||||
/* Contextual filter: CiviCRM Events: Start Date */
|
||||
$handler->display->display_options['arguments']['start_date']['id'] = 'start_date';
|
||||
$handler->display->display_options['arguments']['start_date']['table'] = 'civicrm_event';
|
||||
$handler->display->display_options['arguments']['start_date']['field'] = 'start_date';
|
||||
$handler->display->display_options['arguments']['start_date']['default_action'] = 'default';
|
||||
$handler->display->display_options['arguments']['start_date']['default_argument_skip_url'] = 0;
|
||||
$handler->display->display_options['arguments']['start_date']['summary']['format'] = 'default_summary';
|
||||
$handler->display->display_options['arguments']['start_date']['add_delta'] = 'yes';
|
||||
$handler->display->display_options['arguments']['start_date']['date_fields'] = array(
|
||||
'civicrm_event.start_date' => 'civicrm_event.start_date',
|
||||
);
|
||||
|
||||
/* Display: Upcoming */
|
||||
$handler = $view->new_display('block', 'Upcoming', 'block_2');
|
||||
$handler->display->display_options['display_description'] = 'Upcoming Events';
|
||||
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
|
||||
$handler->display->display_options['style_plugin'] = 'list';
|
||||
$handler->display->display_options['defaults']['style_options'] = FALSE;
|
||||
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
|
||||
$handler->display->display_options['row_plugin'] = 'fields';
|
||||
$handler->display->display_options['row_options']['hide_empty'] = 0;
|
||||
$handler->display->display_options['row_options']['default_field_elements'] = 1;
|
||||
$handler->display->display_options['defaults']['row_options'] = FALSE;
|
||||
$handler->display->display_options['defaults']['arguments'] = FALSE;
|
||||
$translatables['test_events'] = array(
|
||||
t('Master'),
|
||||
t('CiviCRM Events'),
|
||||
t('more'),
|
||||
t('Apply'),
|
||||
t('Reset'),
|
||||
t('Sort by'),
|
||||
t('Asc'),
|
||||
t('Desc'),
|
||||
t('All'),
|
||||
t('Month'),
|
||||
t('Monthly calendar of events'),
|
||||
t('Week'),
|
||||
t('Weekly calendar of events'),
|
||||
t('Day'),
|
||||
t('Daily calendar of events'),
|
||||
t('Year'),
|
||||
t('Annual calendar of events'),
|
||||
t('Block'),
|
||||
t('Upcoming'),
|
||||
t('Upcoming Events'),
|
||||
);
|
||||
$views[] = $view;
|
||||
|
||||
$view = new view();
|
||||
$view->name = 'civicrm_my_activities';
|
||||
$view->description = 'Calendar of CiviCRM Activities - Assigned to logged in user';
|
||||
$view->tag = 'civicrm';
|
||||
$view->base_table = 'civicrm_activity';
|
||||
$view->human_name = 'CiviCRM My Activities';
|
||||
$view->core = 7;
|
||||
$view->api_version = '3.0';
|
||||
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
|
||||
|
||||
/* Display: Master */
|
||||
$handler = $view->new_display('default', 'Master', 'default');
|
||||
$handler->display->display_options['title'] = 'CiviCRM My Activities Calendar';
|
||||
$handler->display->display_options['use_more_always'] = FALSE;
|
||||
$handler->display->display_options['access']['type'] = 'perm';
|
||||
$handler->display->display_options['access']['perm'] = 'view all activities';
|
||||
$handler->display->display_options['cache']['type'] = 'none';
|
||||
$handler->display->display_options['query']['type'] = 'views_query';
|
||||
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
|
||||
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
||||
$handler->display->display_options['exposed_form']['options']['reset_button_label'] = 'Reset';
|
||||
$handler->display->display_options['pager']['type'] = 'some';
|
||||
$handler->display->display_options['pager']['options']['items_per_page'] = '5';
|
||||
$handler->display->display_options['pager']['options']['offset'] = '0';
|
||||
$handler->display->display_options['style_plugin'] = 'calendar_style';
|
||||
$handler->display->display_options['style_options']['name_size'] = '3';
|
||||
$handler->display->display_options['style_options']['mini'] = '0';
|
||||
$handler->display->display_options['style_options']['with_weekno'] = '0';
|
||||
$handler->display->display_options['style_options']['multiday_theme'] = '1';
|
||||
$handler->display->display_options['style_options']['theme_style'] = '1';
|
||||
$handler->display->display_options['style_options']['max_items'] = '0';
|
||||
$handler->display->display_options['row_plugin'] = 'civicrm_event_calendar';
|
||||
$handler->display->display_options['row_options']['colors']['calendar_colors_type'] = array(
|
||||
'article' => '#ffffff',
|
||||
'page' => '#ffffff',
|
||||
);
|
||||
|
||||
/* Relationship: CiviCRM Activity Assignments: Assignee Contact ID */
|
||||
$handler->display->display_options['relationships']['assignee_contact_id']['id'] = 'assignee_contact_id';
|
||||
$handler->display->display_options['relationships']['assignee_contact_id']['table'] = 'civicrm_activity_assignment';
|
||||
$handler->display->display_options['relationships']['assignee_contact_id']['field'] = 'assignee_contact_id';
|
||||
|
||||
/* Field: CiviCRM Activities: Scheduled Activity Date */
|
||||
$handler->display->display_options['fields']['activity_date_time']['id'] = 'activity_date_time';
|
||||
$handler->display->display_options['fields']['activity_date_time']['table'] = 'civicrm_activity';
|
||||
$handler->display->display_options['fields']['activity_date_time']['field'] = 'activity_date_time';
|
||||
$handler->display->display_options['fields']['activity_date_time']['label'] = '';
|
||||
$handler->display->display_options['fields']['activity_date_time']['element_label_colon'] = FALSE;
|
||||
$handler->display->display_options['fields']['activity_date_time']['hide_alter_empty'] = FALSE;
|
||||
$handler->display->display_options['fields']['activity_date_time']['date_format'] = 'short';
|
||||
$handler->display->display_options['fields']['activity_date_time']['custom_date_format'] = 'g:i';
|
||||
|
||||
/* Field: CiviCRM Activities: Activity Type */
|
||||
$handler->display->display_options['fields']['activity_type']['id'] = 'activity_type';
|
||||
$handler->display->display_options['fields']['activity_type']['table'] = 'civicrm_activity';
|
||||
$handler->display->display_options['fields']['activity_type']['field'] = 'activity_type';
|
||||
$handler->display->display_options['fields']['activity_type']['label'] = '';
|
||||
$handler->display->display_options['fields']['activity_type']['element_label_colon'] = FALSE;
|
||||
|
||||
/* Field: CiviCRM Activities: Activity Status */
|
||||
$handler->display->display_options['fields']['status']['id'] = 'status';
|
||||
$handler->display->display_options['fields']['status']['table'] = 'civicrm_activity';
|
||||
$handler->display->display_options['fields']['status']['field'] = 'status';
|
||||
$handler->display->display_options['fields']['status']['label'] = '';
|
||||
$handler->display->display_options['fields']['status']['element_label_colon'] = FALSE;
|
||||
|
||||
/* Field: CiviCRM Activities: Onderwerp */
|
||||
$handler->display->display_options['fields']['subject']['id'] = 'subject';
|
||||
$handler->display->display_options['fields']['subject']['table'] = 'civicrm_activity';
|
||||
$handler->display->display_options['fields']['subject']['field'] = 'subject';
|
||||
$handler->display->display_options['fields']['subject']['label'] = '';
|
||||
$handler->display->display_options['fields']['subject']['element_label_colon'] = FALSE;
|
||||
$handler->display->display_options['fields']['subject']['hide_alter_empty'] = FALSE;
|
||||
|
||||
/* Sort criterion: CiviCRM Activities: Scheduled Activity Date */
|
||||
$handler->display->display_options['sorts']['activity_date_time']['id'] = 'activity_date_time';
|
||||
$handler->display->display_options['sorts']['activity_date_time']['table'] = 'civicrm_activity';
|
||||
$handler->display->display_options['sorts']['activity_date_time']['field'] = 'activity_date_time';
|
||||
|
||||
/* Contextual filter: CiviCRM Activities: Scheduled Activity Date */
|
||||
$handler->display->display_options['arguments']['activity_date_time']['id'] = 'activity_date_time';
|
||||
$handler->display->display_options['arguments']['activity_date_time']['table'] = 'civicrm_activity';
|
||||
$handler->display->display_options['arguments']['activity_date_time']['field'] = 'activity_date_time';
|
||||
$handler->display->display_options['arguments']['activity_date_time']['default_action'] = 'default';
|
||||
$handler->display->display_options['arguments']['activity_date_time']['exception']['title'] = 'All';
|
||||
$handler->display->display_options['arguments']['activity_date_time']['summary']['format'] = 'default_summary';
|
||||
$handler->display->display_options['arguments']['activity_date_time']['granularity'] = 'year';
|
||||
$handler->display->display_options['arguments']['activity_date_time']['add_delta'] = 'yes';
|
||||
$handler->display->display_options['arguments']['activity_date_time']['date_fields'] = array(
|
||||
'civicrm_activity.activity_date_time' => 'civicrm_activity.activity_date_time',
|
||||
);
|
||||
|
||||
/* Contextual filter: CiviCRM Contacts: Contact ID */
|
||||
$handler->display->display_options['arguments']['id']['id'] = 'id';
|
||||
$handler->display->display_options['arguments']['id']['table'] = 'civicrm_contact';
|
||||
$handler->display->display_options['arguments']['id']['field'] = 'id';
|
||||
$handler->display->display_options['arguments']['id']['relationship'] = 'assignee_contact_id';
|
||||
$handler->display->display_options['arguments']['id']['default_action'] = 'default';
|
||||
$handler->display->display_options['arguments']['id']['exception']['title'] = 'All';
|
||||
$handler->display->display_options['arguments']['id']['default_argument_type'] = 'php';
|
||||
$handler->display->display_options['arguments']['id']['default_argument_options']['code'] = 'global $user;
|
||||
civicrm_initialize( );
|
||||
$results=civicrm_api("UFMatch","get", array (version => \'3\',\'sequential\' =>\'1\', \'uf_id\' =>$user->uid));
|
||||
|
||||
return $results["id"]?$results["id"]:"";';
|
||||
$handler->display->display_options['arguments']['id']['summary']['number_of_records'] = '0';
|
||||
$handler->display->display_options['arguments']['id']['summary']['format'] = 'default_summary';
|
||||
$handler->display->display_options['arguments']['id']['summary_options']['items_per_page'] = '25';
|
||||
|
||||
/* Filter criterion: CiviCRM Activities: Activity Type */
|
||||
$handler->display->display_options['filters']['activity_type']['id'] = 'activity_type';
|
||||
$handler->display->display_options['filters']['activity_type']['table'] = 'civicrm_activity';
|
||||
$handler->display->display_options['filters']['activity_type']['field'] = 'activity_type';
|
||||
$handler->display->display_options['filters']['activity_type']['value'] = array(
|
||||
1 => '1',
|
||||
2 => '2',
|
||||
);
|
||||
$handler->display->display_options['filters']['activity_type']['group'] = 1;
|
||||
|
||||
/* Display: Month */
|
||||
$handler = $view->new_display('page', 'Month', 'page');
|
||||
$handler->display->display_options['display_description'] = 'Monthly calendar of activities';
|
||||
$handler->display->display_options['defaults']['hide_admin_links'] = FALSE;
|
||||
$handler->display->display_options['defaults']['pager'] = FALSE;
|
||||
$handler->display->display_options['pager']['type'] = 'date_views_pager';
|
||||
$handler->display->display_options['pager']['options']['date_id'] = 'month';
|
||||
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
|
||||
$handler->display->display_options['style_plugin'] = 'calendar_style';
|
||||
$handler->display->display_options['style_options']['name_size'] = '3';
|
||||
$handler->display->display_options['style_options']['mini'] = '0';
|
||||
$handler->display->display_options['style_options']['with_weekno'] = '0';
|
||||
$handler->display->display_options['style_options']['multiday_theme'] = '1';
|
||||
$handler->display->display_options['style_options']['theme_style'] = '1';
|
||||
$handler->display->display_options['style_options']['max_items'] = '0';
|
||||
$handler->display->display_options['defaults']['style_options'] = FALSE;
|
||||
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
|
||||
$handler->display->display_options['row_plugin'] = 'civicrm_activity_calendar';
|
||||
$handler->display->display_options['defaults']['row_options'] = FALSE;
|
||||
$handler->display->display_options['defaults']['arguments'] = FALSE;
|
||||
|
||||
/* Contextual filter: CiviCRM Activities: Scheduled Activity Date */
|
||||
$handler->display->display_options['arguments']['activity_date_time']['id'] = 'activity_date_time';
|
||||
$handler->display->display_options['arguments']['activity_date_time']['table'] = 'civicrm_activity';
|
||||
$handler->display->display_options['arguments']['activity_date_time']['field'] = 'activity_date_time';
|
||||
$handler->display->display_options['arguments']['activity_date_time']['default_action'] = 'default';
|
||||
$handler->display->display_options['arguments']['activity_date_time']['exception']['title'] = 'All';
|
||||
$handler->display->display_options['arguments']['activity_date_time']['add_delta'] = 'yes';
|
||||
$handler->display->display_options['arguments']['activity_date_time']['use_fromto'] = 'no';
|
||||
$handler->display->display_options['arguments']['activity_date_time']['date_fields'] = array(
|
||||
'civicrm_activity.activity_date_time' => 'civicrm_activity.activity_date_time',
|
||||
);
|
||||
|
||||
/* Contextual filter: CiviCRM Contacts: Contact ID */
|
||||
$handler->display->display_options['arguments']['id']['id'] = 'id';
|
||||
$handler->display->display_options['arguments']['id']['table'] = 'civicrm_contact';
|
||||
$handler->display->display_options['arguments']['id']['field'] = 'id';
|
||||
$handler->display->display_options['arguments']['id']['relationship'] = 'assignee_contact_id';
|
||||
$handler->display->display_options['arguments']['id']['default_action'] = 'default';
|
||||
$handler->display->display_options['arguments']['id']['exception']['title'] = 'All';
|
||||
$handler->display->display_options['arguments']['id']['default_argument_type'] = 'php';
|
||||
$handler->display->display_options['arguments']['id']['default_argument_options']['code'] = 'global $user;
|
||||
civicrm_initialize( );
|
||||
$results=civicrm_api("UFMatch","get", array (version => \'3\',\'sequential\' =>\'1\', \'uf_id\' =>$user->uid));
|
||||
|
||||
return $results["id"]?$results["id"]:""; ';
|
||||
$handler->display->display_options['arguments']['id']['summary']['number_of_records'] = '0';
|
||||
$handler->display->display_options['arguments']['id']['summary']['format'] = 'default_summary';
|
||||
$handler->display->display_options['arguments']['id']['summary_options']['items_per_page'] = '25';
|
||||
$handler->display->display_options['path'] = 'myactivities/month';
|
||||
|
||||
/* Display: Week */
|
||||
$handler = $view->new_display('page', 'Week', 'page_1');
|
||||
$handler->display->display_options['display_description'] = 'Weekly calendar of activities';
|
||||
$handler->display->display_options['defaults']['hide_admin_links'] = FALSE;
|
||||
$handler->display->display_options['defaults']['pager'] = FALSE;
|
||||
$handler->display->display_options['pager']['type'] = 'date_views_pager';
|
||||
$handler->display->display_options['pager']['options']['date_id'] = 'month';
|
||||
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
|
||||
$handler->display->display_options['style_plugin'] = 'calendar_style';
|
||||
$handler->display->display_options['style_options']['calendar_type'] = 'week';
|
||||
$handler->display->display_options['style_options']['name_size'] = '3';
|
||||
$handler->display->display_options['style_options']['mini'] = '0';
|
||||
$handler->display->display_options['style_options']['with_weekno'] = '0';
|
||||
$handler->display->display_options['style_options']['multiday_theme'] = '1';
|
||||
$handler->display->display_options['style_options']['theme_style'] = '1';
|
||||
$handler->display->display_options['style_options']['max_items'] = '0';
|
||||
$handler->display->display_options['defaults']['style_options'] = FALSE;
|
||||
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
|
||||
$handler->display->display_options['row_plugin'] = 'civicrm_activity_calendar';
|
||||
$handler->display->display_options['defaults']['row_options'] = FALSE;
|
||||
$handler->display->display_options['defaults']['arguments'] = FALSE;
|
||||
|
||||
/* Contextual filter: CiviCRM Activities: Scheduled Activity Date */
|
||||
$handler->display->display_options['arguments']['activity_date_time']['id'] = 'activity_date_time';
|
||||
$handler->display->display_options['arguments']['activity_date_time']['table'] = 'civicrm_activity';
|
||||
$handler->display->display_options['arguments']['activity_date_time']['field'] = 'activity_date_time';
|
||||
$handler->display->display_options['arguments']['activity_date_time']['default_action'] = 'default';
|
||||
$handler->display->display_options['arguments']['activity_date_time']['exception']['title'] = 'All';
|
||||
$handler->display->display_options['arguments']['activity_date_time']['summary']['format'] = 'default_summary';
|
||||
$handler->display->display_options['arguments']['activity_date_time']['granularity'] = 'week';
|
||||
$handler->display->display_options['arguments']['activity_date_time']['add_delta'] = 'yes';
|
||||
$handler->display->display_options['arguments']['activity_date_time']['date_fields'] = array(
|
||||
'civicrm_activity.activity_date_time' => 'civicrm_activity.activity_date_time',
|
||||
);
|
||||
|
||||
/* Contextual filter: CiviCRM Contacts: Contact ID */
|
||||
$handler->display->display_options['arguments']['id']['id'] = 'id';
|
||||
$handler->display->display_options['arguments']['id']['table'] = 'civicrm_contact';
|
||||
$handler->display->display_options['arguments']['id']['field'] = 'id';
|
||||
$handler->display->display_options['arguments']['id']['relationship'] = 'assignee_contact_id';
|
||||
$handler->display->display_options['arguments']['id']['default_action'] = 'default';
|
||||
$handler->display->display_options['arguments']['id']['exception']['title'] = 'All';
|
||||
$handler->display->display_options['arguments']['id']['default_argument_type'] = 'php';
|
||||
$handler->display->display_options['arguments']['id']['default_argument_options']['code'] = '
|
||||
global $user;
|
||||
civicrm_initialize( );
|
||||
$results=civicrm_api("UFMatch","get", array (version => \'3\',\'sequential\' =>\'1\', \'uf_id\' =>$user->uid));
|
||||
|
||||
return $results["id"]?$results["id"]:"";
|
||||
';
|
||||
$handler->display->display_options['arguments']['id']['summary']['number_of_records'] = '0';
|
||||
$handler->display->display_options['arguments']['id']['summary']['format'] = 'default_summary';
|
||||
$handler->display->display_options['arguments']['id']['summary_options']['items_per_page'] = '25';
|
||||
$handler->display->display_options['path'] = 'myactivities/week';
|
||||
|
||||
/* Display: Day */
|
||||
$handler = $view->new_display('page', 'Day', 'page_2');
|
||||
$handler->display->display_options['display_description'] = 'Daily calendar of activities';
|
||||
$handler->display->display_options['defaults']['hide_admin_links'] = FALSE;
|
||||
$handler->display->display_options['defaults']['pager'] = FALSE;
|
||||
$handler->display->display_options['pager']['type'] = 'date_views_pager';
|
||||
$handler->display->display_options['pager']['options']['date_id'] = 'month';
|
||||
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
|
||||
$handler->display->display_options['style_plugin'] = 'calendar_style';
|
||||
$handler->display->display_options['style_options']['calendar_type'] = 'day';
|
||||
$handler->display->display_options['style_options']['name_size'] = '3';
|
||||
$handler->display->display_options['style_options']['mini'] = '0';
|
||||
$handler->display->display_options['style_options']['with_weekno'] = '0';
|
||||
$handler->display->display_options['style_options']['multiday_theme'] = '1';
|
||||
$handler->display->display_options['style_options']['theme_style'] = '1';
|
||||
$handler->display->display_options['style_options']['max_items'] = '0';
|
||||
$handler->display->display_options['defaults']['style_options'] = FALSE;
|
||||
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
|
||||
$handler->display->display_options['row_plugin'] = 'civicrm_activity_calendar';
|
||||
$handler->display->display_options['defaults']['row_options'] = FALSE;
|
||||
$handler->display->display_options['defaults']['arguments'] = FALSE;
|
||||
|
||||
/* Contextual filter: CiviCRM Activities: Scheduled Activity Date */
|
||||
$handler->display->display_options['arguments']['activity_date_time']['id'] = 'activity_date_time';
|
||||
$handler->display->display_options['arguments']['activity_date_time']['table'] = 'civicrm_activity';
|
||||
$handler->display->display_options['arguments']['activity_date_time']['field'] = 'activity_date_time';
|
||||
$handler->display->display_options['arguments']['activity_date_time']['default_action'] = 'default';
|
||||
$handler->display->display_options['arguments']['activity_date_time']['exception']['title'] = 'All';
|
||||
$handler->display->display_options['arguments']['activity_date_time']['summary']['format'] = 'default_summary';
|
||||
$handler->display->display_options['arguments']['activity_date_time']['granularity'] = 'day';
|
||||
$handler->display->display_options['arguments']['activity_date_time']['add_delta'] = 'yes';
|
||||
$handler->display->display_options['arguments']['activity_date_time']['date_fields'] = array(
|
||||
'civicrm_activity.activity_date_time' => 'civicrm_activity.activity_date_time',
|
||||
);
|
||||
|
||||
/* Contextual filter: CiviCRM Contacts: Contact ID */
|
||||
$handler->display->display_options['arguments']['id']['id'] = 'id';
|
||||
$handler->display->display_options['arguments']['id']['table'] = 'civicrm_contact';
|
||||
$handler->display->display_options['arguments']['id']['field'] = 'id';
|
||||
$handler->display->display_options['arguments']['id']['relationship'] = 'assignee_contact_id';
|
||||
$handler->display->display_options['arguments']['id']['default_action'] = 'default';
|
||||
$handler->display->display_options['arguments']['id']['exception']['title'] = 'All';
|
||||
$handler->display->display_options['arguments']['id']['default_argument_type'] = 'php';
|
||||
$handler->display->display_options['arguments']['id']['default_argument_options']['code'] = 'global $user;
|
||||
civicrm_initialize( );
|
||||
$results=civicrm_api("UFMatch","get", array (version => \'3\',\'sequential\' =>\'1\', \'uf_id\' =>$user->uid));
|
||||
|
||||
return $results["id"]? $results["id"]:"";';
|
||||
$handler->display->display_options['arguments']['id']['summary']['number_of_records'] = '0';
|
||||
$handler->display->display_options['arguments']['id']['summary']['format'] = 'default_summary';
|
||||
$handler->display->display_options['arguments']['id']['summary_options']['items_per_page'] = '25';
|
||||
$handler->display->display_options['path'] = 'myactivities/day';
|
||||
|
||||
/* Display: Year */
|
||||
$handler = $view->new_display('page', 'Year', 'page_3');
|
||||
$handler->display->display_options['display_description'] = 'Annual calendar of activities';
|
||||
$handler->display->display_options['defaults']['hide_admin_links'] = FALSE;
|
||||
$handler->display->display_options['defaults']['pager'] = FALSE;
|
||||
$handler->display->display_options['pager']['type'] = 'date_views_pager';
|
||||
$handler->display->display_options['pager']['options']['date_id'] = 'month';
|
||||
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
|
||||
$handler->display->display_options['style_plugin'] = 'calendar_style';
|
||||
$handler->display->display_options['style_options']['calendar_type'] = 'year';
|
||||
$handler->display->display_options['style_options']['name_size'] = '3';
|
||||
$handler->display->display_options['style_options']['mini'] = '0';
|
||||
$handler->display->display_options['style_options']['with_weekno'] = '0';
|
||||
$handler->display->display_options['style_options']['multiday_theme'] = '1';
|
||||
$handler->display->display_options['style_options']['theme_style'] = '1';
|
||||
$handler->display->display_options['style_options']['max_items'] = '0';
|
||||
$handler->display->display_options['defaults']['style_options'] = FALSE;
|
||||
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
|
||||
$handler->display->display_options['row_plugin'] = 'civicrm_activity_calendar';
|
||||
$handler->display->display_options['defaults']['row_options'] = FALSE;
|
||||
$handler->display->display_options['defaults']['arguments'] = FALSE;
|
||||
|
||||
/* Contextual filter: CiviCRM Activities: Scheduled Activity Date */
|
||||
$handler->display->display_options['arguments']['activity_date_time']['id'] = 'activity_date_time';
|
||||
$handler->display->display_options['arguments']['activity_date_time']['table'] = 'civicrm_activity';
|
||||
$handler->display->display_options['arguments']['activity_date_time']['field'] = 'activity_date_time';
|
||||
$handler->display->display_options['arguments']['activity_date_time']['default_action'] = 'default';
|
||||
$handler->display->display_options['arguments']['activity_date_time']['exception']['title'] = 'All';
|
||||
$handler->display->display_options['arguments']['activity_date_time']['summary']['format'] = 'default_summary';
|
||||
$handler->display->display_options['arguments']['activity_date_time']['granularity'] = 'year';
|
||||
$handler->display->display_options['arguments']['activity_date_time']['add_delta'] = 'yes';
|
||||
$handler->display->display_options['arguments']['activity_date_time']['date_fields'] = array(
|
||||
'civicrm_activity.activity_date_time' => 'civicrm_activity.activity_date_time',
|
||||
);
|
||||
|
||||
/* Contextual filter: CiviCRM Contacts: Contact ID */
|
||||
$handler->display->display_options['arguments']['id']['id'] = 'id';
|
||||
$handler->display->display_options['arguments']['id']['table'] = 'civicrm_contact';
|
||||
$handler->display->display_options['arguments']['id']['field'] = 'id';
|
||||
$handler->display->display_options['arguments']['id']['relationship'] = 'assignee_contact_id';
|
||||
$handler->display->display_options['arguments']['id']['default_action'] = 'default';
|
||||
$handler->display->display_options['arguments']['id']['exception']['title'] = 'All';
|
||||
$handler->display->display_options['arguments']['id']['default_argument_type'] = 'php';
|
||||
$handler->display->display_options['arguments']['id']['default_argument_options']['code'] = 'global $user;
|
||||
civicrm_initialize( );
|
||||
$results=civicrm_api("UFMatch","get", array (version => \'3\',\'sequential\' =>\'1\', \'uf_id\' =>$user->uid));
|
||||
|
||||
return $results["id"]?$results["id"]:"";';
|
||||
$handler->display->display_options['arguments']['id']['summary']['number_of_records'] = '0';
|
||||
$handler->display->display_options['arguments']['id']['summary']['format'] = 'default_summary';
|
||||
$handler->display->display_options['arguments']['id']['summary_options']['items_per_page'] = '25';
|
||||
$handler->display->display_options['path'] = 'myactivities/year';
|
||||
|
||||
/* Display: Block */
|
||||
$handler = $view->new_display('block', 'Block', 'block_1');
|
||||
$handler->display->display_options['defaults']['hide_admin_links'] = FALSE;
|
||||
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
|
||||
$handler->display->display_options['style_plugin'] = 'calendar_style';
|
||||
$handler->display->display_options['style_options']['name_size'] = '3';
|
||||
$handler->display->display_options['style_options']['mini'] = '0';
|
||||
$handler->display->display_options['style_options']['with_weekno'] = '0';
|
||||
$handler->display->display_options['style_options']['multiday_theme'] = '1';
|
||||
$handler->display->display_options['style_options']['theme_style'] = '1';
|
||||
$handler->display->display_options['style_options']['max_items'] = '0';
|
||||
$handler->display->display_options['defaults']['style_options'] = FALSE;
|
||||
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
|
||||
$handler->display->display_options['row_plugin'] = 'civicrm_activity_calendar';
|
||||
$handler->display->display_options['defaults']['row_options'] = FALSE;
|
||||
|
||||
/* Display: Scheduled */
|
||||
$handler = $view->new_display('block', 'Scheduled', 'block_2');
|
||||
$handler->display->display_options['display_description'] = 'Scheduled Activities';
|
||||
$handler->display->display_options['defaults']['hide_admin_links'] = FALSE;
|
||||
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
|
||||
$handler->display->display_options['style_plugin'] = 'list';
|
||||
$handler->display->display_options['defaults']['style_options'] = FALSE;
|
||||
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
|
||||
$handler->display->display_options['row_plugin'] = 'fields';
|
||||
$handler->display->display_options['defaults']['row_options'] = FALSE;
|
||||
$handler->display->display_options['defaults']['fields'] = FALSE;
|
||||
|
||||
/* Field: CiviCRM Activities: Scheduled Activity Date */
|
||||
$handler->display->display_options['fields']['activity_date_time']['id'] = 'activity_date_time';
|
||||
$handler->display->display_options['fields']['activity_date_time']['table'] = 'civicrm_activity';
|
||||
$handler->display->display_options['fields']['activity_date_time']['field'] = 'activity_date_time';
|
||||
$handler->display->display_options['fields']['activity_date_time']['label'] = '';
|
||||
$handler->display->display_options['fields']['activity_date_time']['element_label_colon'] = FALSE;
|
||||
$handler->display->display_options['fields']['activity_date_time']['hide_alter_empty'] = FALSE;
|
||||
$handler->display->display_options['fields']['activity_date_time']['date_format'] = 'long';
|
||||
|
||||
/* Field: CiviCRM Activities: Activity Type */
|
||||
$handler->display->display_options['fields']['activity_type']['id'] = 'activity_type';
|
||||
$handler->display->display_options['fields']['activity_type']['table'] = 'civicrm_activity';
|
||||
$handler->display->display_options['fields']['activity_type']['field'] = 'activity_type';
|
||||
$handler->display->display_options['fields']['activity_type']['label'] = '';
|
||||
$handler->display->display_options['fields']['activity_type']['element_label_colon'] = FALSE;
|
||||
|
||||
/* Field: CiviCRM Activities: Subject */
|
||||
$handler->display->display_options['fields']['subject']['id'] = 'subject';
|
||||
$handler->display->display_options['fields']['subject']['table'] = 'civicrm_activity';
|
||||
$handler->display->display_options['fields']['subject']['field'] = 'subject';
|
||||
$handler->display->display_options['fields']['subject']['label'] = '';
|
||||
$handler->display->display_options['fields']['subject']['element_label_colon'] = FALSE;
|
||||
$handler->display->display_options['fields']['subject']['hide_alter_empty'] = FALSE;
|
||||
$handler->display->display_options['defaults']['arguments'] = FALSE;
|
||||
|
||||
/* Contextual filter: CiviCRM Contacts: Contact ID */
|
||||
$handler->display->display_options['arguments']['id']['id'] = 'id';
|
||||
$handler->display->display_options['arguments']['id']['table'] = 'civicrm_contact';
|
||||
$handler->display->display_options['arguments']['id']['field'] = 'id';
|
||||
$handler->display->display_options['arguments']['id']['relationship'] = 'assignee_contact_id';
|
||||
$handler->display->display_options['arguments']['id']['default_action'] = 'default';
|
||||
$handler->display->display_options['arguments']['id']['exception']['title'] = 'All';
|
||||
$handler->display->display_options['arguments']['id']['default_argument_type'] = 'php';
|
||||
$handler->display->display_options['arguments']['id']['default_argument_options']['code'] = 'global $user;
|
||||
civicrm_initialize( );
|
||||
$results=civicrm_api("UFMatch","get", array (version => \'3\',\'sequential\' =>\'1\', \'uf_id\' =>$user->uid));
|
||||
|
||||
return $results["id"]?$results["id"]:"";';
|
||||
$handler->display->display_options['arguments']['id']['summary']['number_of_records'] = '0';
|
||||
$handler->display->display_options['arguments']['id']['summary']['format'] = 'default_summary';
|
||||
$handler->display->display_options['arguments']['id']['summary_options']['items_per_page'] = '25';
|
||||
$handler->display->display_options['defaults']['filter_groups'] = FALSE;
|
||||
$handler->display->display_options['defaults']['filters'] = FALSE;
|
||||
|
||||
/* Filter criterion: CiviCRM Activities: Activity Type */
|
||||
$handler->display->display_options['filters']['activity_type']['id'] = 'activity_type';
|
||||
$handler->display->display_options['filters']['activity_type']['table'] = 'civicrm_activity';
|
||||
$handler->display->display_options['filters']['activity_type']['field'] = 'activity_type';
|
||||
$handler->display->display_options['filters']['activity_type']['value'] = array(
|
||||
1 => '1',
|
||||
2 => '2',
|
||||
);
|
||||
$handler->display->display_options['filters']['activity_type']['group'] = 1;
|
||||
|
||||
/* Filter criterion: CiviCRM Activities: Activity Status */
|
||||
$handler->display->display_options['filters']['status']['id'] = 'status';
|
||||
$handler->display->display_options['filters']['status']['table'] = 'civicrm_activity';
|
||||
$handler->display->display_options['filters']['status']['field'] = 'status';
|
||||
$handler->display->display_options['filters']['status']['value'] = array(
|
||||
1 => '1',
|
||||
);
|
||||
$handler->display->display_options['filters']['status']['group'] = 1;
|
||||
$translatables['civicrm_my_activities'] = array(
|
||||
t('Master'),
|
||||
t('CiviCRM My Activities Calendar'),
|
||||
t('More'),
|
||||
t('Apply'),
|
||||
t('Reset'),
|
||||
t('Sort by'),
|
||||
t('Asc'),
|
||||
t('Desc'),
|
||||
t('CiviCRM Assignee Contact ID'),
|
||||
t('All'),
|
||||
t('Month'),
|
||||
t('Monthly calendar of activities'),
|
||||
t('Week'),
|
||||
t('Weekly calendar of activities'),
|
||||
t('Day'),
|
||||
t('Daily calendar of activities'),
|
||||
t('Year'),
|
||||
t('Annual calendar of activities'),
|
||||
t('Block'),
|
||||
t('Scheduled'),
|
||||
t('Scheduled Activities'),
|
||||
);
|
||||
|
||||
$views[] = $view;
|
||||
}
|
||||
|
||||
return $views;
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
* Field handler to provide simple renderer that allows linking to a user.
|
||||
*
|
||||
* @ingroup civicrm_field_handlers
|
||||
*/
|
||||
class civicrm_handler_field extends views_handler_field {
|
||||
|
||||
/**
|
||||
* Override init function to provide generic option to link to user.
|
||||
*/
|
||||
public function init(&$view, &$data) {
|
||||
parent::init($view, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide link to node option
|
||||
*/
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
$form['link_to_civicrm'] = array(
|
||||
'#title' => t('Link this field to its user'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => isset($this->options['link_to_civicrm']) ? $this->options['link_to_civicrm'] : '',
|
||||
);
|
||||
}
|
||||
|
||||
public function render_link($data, $values) {
|
||||
$data = str_replace('', ', ', trim($data, ''));
|
||||
if (!empty($this->options['link_to_civicrm']) && user_access('access CiviCRM') && $values->id) {
|
||||
return civicrm_views_href($data,
|
||||
'civicrm/contact/view',
|
||||
"reset=1&cid={$values->id}"
|
||||
);
|
||||
}
|
||||
else {
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
public function render($values) {
|
||||
return $this->render_link(check_plain($values->{$this->field_alias}), $values);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,119 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
* Field handler for activity contact field
|
||||
*
|
||||
* @ingroup civicrm_field_handlers
|
||||
*/
|
||||
class civicrm_handler_field_activity extends civicrm_handler_field {
|
||||
static $_recordType;
|
||||
public function construct() {
|
||||
parent::construct();
|
||||
if (!self::$_recordType) {
|
||||
if (!civicrm_initialize()) {
|
||||
return;
|
||||
}
|
||||
self::$_recordType = CRM_Core_PseudoConstant::get('CRM_Activity_DAO_ActivityContact', 'record_type_id');
|
||||
}
|
||||
}
|
||||
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['record_type'] = array('default' => 0);
|
||||
return $options;
|
||||
}
|
||||
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
$recordTypes = array(0 => 'Any');
|
||||
foreach (self::$_recordType as $id => $type) {
|
||||
$recordTypes[$id] = $type;
|
||||
}
|
||||
$form['record_type'] = array(
|
||||
'#type' => 'radios',
|
||||
'#title' => 'Record type for this field',
|
||||
'#options' => $recordTypes,
|
||||
'#description' => t('Record type to be displayed for this field'),
|
||||
'#default_value' => $this->options['record_type'],
|
||||
'#fieldset' => 'record_type_choices',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to link activity contact with civicrm_contact in a query.
|
||||
*/
|
||||
public function query() {
|
||||
|
||||
// Figure out what base table
|
||||
$table_data = views_fetch_data($this->definition['base']);
|
||||
$base_field = empty($this->definition['base field']) ? $table_data['table']['base']['field'] : $this->definition['base field'];
|
||||
$this->table_alias = $this->query->add_table($this->table, $this->relationship);
|
||||
|
||||
// Make sure the join to civicrm_contact form the civicrm_activity_contact table
|
||||
// Otherwise the displayed field will always be the same as the base table's record
|
||||
if ($this->table == 'civicrm_activity_contact' && isset($this->view->query->table_queue[$this->table_alias]['join']->field)) {
|
||||
$this->view->query->table_queue[$this->table_alias]['join']->field = $this->definition['relationship field'];
|
||||
}
|
||||
|
||||
$def = $this->definition;
|
||||
|
||||
$leftField = $this->definition['base'] == 'civicrm_activity_contact' ? $this->field : $this->definition['other_field'];
|
||||
$def['table'] = $this->definition['base'];
|
||||
$def['field'] = $this->definition['base field'];
|
||||
$def['left_table'] = $this->table_alias;
|
||||
$def['left_field'] = $leftField;
|
||||
if (!empty($this->options['required'])) {
|
||||
$def['type'] = 'INNER';
|
||||
}
|
||||
|
||||
if (!empty($def['join_handler']) && class_exists($def['join_handler'])) {
|
||||
$join = new $def['join_handler']();
|
||||
}
|
||||
else {
|
||||
$join = new views_join();
|
||||
}
|
||||
|
||||
$join->definition = $def;
|
||||
$join->construct();
|
||||
$join->adjusted = TRUE;
|
||||
|
||||
// Add a join condition to the on clause to narrow down the relationship type shown
|
||||
if (isset($this->options['record_type']) && $this->options['record_type']) {
|
||||
$this->query->table_queue[$this->table_alias]['join']->extra[] = array(
|
||||
'value' => $this->options['record_type'],
|
||||
'numeric' => TRUE,
|
||||
'field' => 'record_type_id',
|
||||
'operator' => '=',
|
||||
);
|
||||
}
|
||||
|
||||
// use a short alias for this:
|
||||
$alias = $def['table'] . '_' . $this->table;
|
||||
|
||||
$this->alias = $this->query->add_relationship($alias, $join, $this->definition['base'], $this->relationship);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,94 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
* Generic field handler for address and location fields
|
||||
*
|
||||
* @ingroup civicrm_field_handlers
|
||||
*/
|
||||
class civicrm_handler_field_address extends civicrm_handler_field_location {
|
||||
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['is_billing'] = array('default' => 0);
|
||||
return $options;
|
||||
}
|
||||
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
$form['is_billing'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => 'Show only Billing Address record?',
|
||||
'#options' => array(0 => 'No', 1 => 'Yes'),
|
||||
'#description' => t('Check above box if you want only the <strong>Billing Address</strong> record displayed.'),
|
||||
'#default_value' => $this->options['is_billing'],
|
||||
'#fieldset' => 'location_choices',
|
||||
);
|
||||
}
|
||||
|
||||
public function join_address($join = array()) {
|
||||
$extra = array();
|
||||
if (isset($join->extra)) {
|
||||
$extra = $join->extra;
|
||||
}
|
||||
if (isset($this->options['is_billing']) && $this->options['is_billing']) {
|
||||
$extra[] = array(
|
||||
'value' => $this->options['is_billing'],
|
||||
'numeric' => TRUE,
|
||||
'field' => 'is_billing',
|
||||
'operator' => '=',
|
||||
);
|
||||
}
|
||||
if (!empty($extra)) {
|
||||
$join->extra = $extra;
|
||||
}
|
||||
return $join;
|
||||
}
|
||||
|
||||
public function get_join() {
|
||||
$join = parent::get_join();
|
||||
$join = $this->join_address($join);
|
||||
return $join;
|
||||
}
|
||||
|
||||
public function ensure_my_table() {
|
||||
if (!isset($this->table_alias)) {
|
||||
if (!method_exists($this->query, 'ensure_table')) {
|
||||
vpr_trace();
|
||||
exit;
|
||||
}
|
||||
$join = $this->get_join();
|
||||
if (empty($this->relationship)) {
|
||||
//https://www.drupal.org/node/2617032
|
||||
$this->table_alias = $this->query->add_table($this->table, $this->relationship, $join);
|
||||
}
|
||||
else {
|
||||
$this->table_alias = $this->query->ensure_table($this->table, $this->relationship, $join);
|
||||
}
|
||||
}
|
||||
return $this->table_alias;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
* Field handler to provide a human-readable CiviCRM component name
|
||||
*
|
||||
* @ingroup civicrm_field_handlers
|
||||
*/
|
||||
class civicrm_handler_field_component extends views_handler_field {
|
||||
public function render($values) {
|
||||
$value = $this->get_value($values);
|
||||
return CRM_Core_Component::getComponentName($value);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,162 @@
|
|||
<?php
|
||||
|
||||
class civicrm_handler_field_contact_image extends views_handler_field {
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['url_only'] = array(
|
||||
'default' => FALSE,
|
||||
'boolean' => TRUE,
|
||||
);
|
||||
$options['title'] = array(
|
||||
'default' => '',
|
||||
);
|
||||
$options['alt'] = array(
|
||||
'default' => '',
|
||||
);
|
||||
$directory = $this->get_civi_relative_upload_path();
|
||||
if (module_exists('image') && $directory !== FALSE) {
|
||||
$options['image_style'] = array(
|
||||
'default' => '',
|
||||
);
|
||||
}
|
||||
$options['width'] = array(
|
||||
'default' => '',
|
||||
);
|
||||
$options['height'] = array(
|
||||
'default' => '',
|
||||
);
|
||||
return $options;
|
||||
}
|
||||
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
$directory = $this->get_civi_relative_upload_path();
|
||||
|
||||
$form['url_only'] = array(
|
||||
'#title' => t('Output the image URL only'),
|
||||
'#description' => t('This option stops the URL being wrapped in an html <code>img</code> tag and ignores the title, alt, width and height settings. This may be useful for rewriting the results.'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => $this->options['url_only'],
|
||||
);
|
||||
|
||||
$form['title'] = array(
|
||||
'#title' => t('Title attribute'),
|
||||
'#description' => t('The text to use as value for the <code>img</code> tag <code>title</code> attribute.'),
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => $this->options['title'],
|
||||
'#dependency' => array(
|
||||
'edit-options-url-only' => array(0),
|
||||
),
|
||||
);
|
||||
|
||||
$form['alt'] = array(
|
||||
'#title' => t('Alt attribute'),
|
||||
'#description' => t('The text to use as value for the <code>img</code> tag <code>alt</code> attribute.'),
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => $this->options['alt'],
|
||||
'#dependency' => array(
|
||||
'edit-options-url-only' => array(0),
|
||||
),
|
||||
);
|
||||
|
||||
if (module_exists('image') && $directory !== FALSE) {
|
||||
$styles = image_styles();
|
||||
$style_options = array('' => t('None (original image)'));
|
||||
foreach ($styles as $style) {
|
||||
$style_options[$style['name']] = $style['name'];
|
||||
}
|
||||
$form['image_style'] = array(
|
||||
'#title' => t('Image style'),
|
||||
'#description' => t('Display the contact image using an image style'),
|
||||
'#type' => 'select',
|
||||
'#options' => $style_options,
|
||||
'#default_value' => $this->options['image_style'],
|
||||
'#dependency' => array(
|
||||
'edit-options-url-only' => array(0),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
$form['width'] = array(
|
||||
'#title' => t('Width'),
|
||||
'#description' => t('Resize the image in the browser to this width. If left empty, the width will scale proportionally with the height.'),
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => $this->options['width'],
|
||||
'#element_validate' => array('element_validate_integer_positive'),
|
||||
'#dependency' => array(
|
||||
'edit-options-url-only' => array(0),
|
||||
),
|
||||
);
|
||||
|
||||
$form['height'] = array(
|
||||
'#title' => t('Height'),
|
||||
'#description' => t('Resize the image in the browser to this height. If left empty, the height will scale proportionally with the width.'),
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => $this->options['height'],
|
||||
'#element_validate' => array('element_validate_integer_positive'),
|
||||
'#dependency' => array(
|
||||
'edit-options-url-only' => array(0),
|
||||
),
|
||||
);
|
||||
|
||||
if (module_exists('image') && $directory !== FALSE) {
|
||||
$form['width']['#dependency']['edit-options-image-style'] = array('');
|
||||
$form['width']['#dependency_count'] = 2;
|
||||
$form['height']['#dependency']['edit-options-image-style'] = array('');
|
||||
$form['height']['#dependency_count'] = 2;
|
||||
}
|
||||
}
|
||||
|
||||
public function render($values) {
|
||||
$value = $this->get_value($values);
|
||||
if (empty($value)) {
|
||||
return;
|
||||
}
|
||||
if ($this->options['url_only']) {
|
||||
return $value;
|
||||
}
|
||||
$image = array(
|
||||
'path' => $value,
|
||||
'title' => $this->options['title'],
|
||||
'alt' => $this->options['alt'],
|
||||
);
|
||||
$directory = $this->get_civi_relative_upload_path();
|
||||
if ($this->options['image_style'] && module_exists('image') && $directory !== FALSE) {
|
||||
$image['style_name'] = empty($this->options['image_style']) ? '' : $this->options['image_style'];
|
||||
$image_path = $directory . substr(strstr($value, 'photo='), 6);
|
||||
$image['path'] = str_replace('\\', '/', $image_path);
|
||||
return theme('image_style', $image);
|
||||
}
|
||||
else {
|
||||
$image['width'] = empty($this->options['width']) ? 'auto' : $this->options['width'];
|
||||
$image['height'] = empty($this->options['height']) ? 'auto' : $this->options['height'];
|
||||
return theme('image', $image);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the CiviCRM upload directory relative to the Drupal public upload
|
||||
* directory so that we can support image styles.
|
||||
*
|
||||
* Returns the relative path if it is supported, otherwise returns FALSE.
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
public function get_civi_relative_upload_path() {
|
||||
civicrm_initialize();
|
||||
$wrapper = file_stream_wrapper_get_instance_by_uri('public://');
|
||||
$drupal_upload_path = $wrapper->getDirectoryPath();
|
||||
$civi_upload_path = Civi::paths()->getUrl(Civi::settings()->get('customFileUploadDir'));
|
||||
$relative_upload_path = explode($drupal_upload_path, $civi_upload_path);
|
||||
|
||||
// If we couldn't explode() then Civi's upload path is not in the public://
|
||||
// directory, so we cannot support image styles.
|
||||
if (count($relative_upload_path) != 2) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Otherwise, return the relative path without the leading slash
|
||||
return substr($relative_upload_path[1], 1);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
* Unchanged anonymous code contribution. No claim.
|
||||
*
|
||||
* civicrm_handler_field_contact_link.inc
|
||||
* Display text data and has the option to link to it's related contact.
|
||||
*
|
||||
*/
|
||||
class civicrm_handler_field_contact_link extends views_handler_field {
|
||||
|
||||
/**
|
||||
* Constructor to provide additional field to add.
|
||||
*/
|
||||
public function construct() {
|
||||
parent::construct();
|
||||
$this->additional_fields['id'] = 'id';
|
||||
}
|
||||
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['link_to_civicrm_contact'] = array('default' => FALSE);
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide link to node option
|
||||
*/
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
$form['link_to_civicrm_contact'] = array(
|
||||
'#title' => t('Link this field to its CiviCRM Contact'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => !empty($this->options['link_to_civicrm_contact']),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render whatever the data is as a link to the node.
|
||||
*
|
||||
* Data should be made XSS safe prior to calling this function.
|
||||
*/
|
||||
public function render_link($data, $values) {
|
||||
if (!empty($this->options['link_to_civicrm_contact']) && user_access('access CiviCRM') && $data !== NULL && $data !== '') {
|
||||
return civicrm_views_href($data,
|
||||
'civicrm/contact/view',
|
||||
"reset=1&cid={$values->{$this->aliases['id']}}"
|
||||
);
|
||||
}
|
||||
else {
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
public function render($values) {
|
||||
return $this->render_link(check_plain($values->{$this->field_alias}), $values);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Heavily based on anonymous code contribution. No claim.
|
||||
*
|
||||
* civicrm_handler_field_country.inc
|
||||
* Displays Country after grabbing the label from the database
|
||||
*
|
||||
*/
|
||||
class civicrm_handler_field_country extends civicrm_handler_field_address {
|
||||
static $_countries;
|
||||
static $_countries_full;
|
||||
public function construct() {
|
||||
parent::construct();
|
||||
if (!self::$_countries) {
|
||||
if (!civicrm_initialize()) {
|
||||
return;
|
||||
}
|
||||
require_once 'CRM/Core/PseudoConstant.php';
|
||||
self::$_countries = CRM_Core_PseudoConstant::countryIsoCode();
|
||||
self::$_countries_full = CRM_Core_PseudoConstant::country();
|
||||
}
|
||||
}
|
||||
|
||||
public function render($values) {
|
||||
$sid = $values->{$this->field_alias};
|
||||
if (empty($sid) ||
|
||||
(int ) $sid <= 0
|
||||
) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ($this->options['country_display'] == 1) {
|
||||
return self::$_countries[$values->{$this->field_alias}];
|
||||
}
|
||||
else {
|
||||
return self::$_countries_full[$values->{$this->field_alias}];
|
||||
}
|
||||
}
|
||||
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['country_display'] = array('default' => '');
|
||||
return $options;
|
||||
}
|
||||
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
$form['country_display'] = array(
|
||||
'#type' => 'radios',
|
||||
'#title' => 'Type of display for country field',
|
||||
'#options' => array(1 => 'Display two letter country code', 2 => 'Display full country name'),
|
||||
'#description' => t('Display full or abbreviated country name'),
|
||||
'#default_value' => $this->options['country_display'],
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* civicrm_handler_field_county.inc
|
||||
* Displays County after grabbing the label from the database
|
||||
*
|
||||
*/
|
||||
class civicrm_handler_field_county extends civicrm_handler_field_address {
|
||||
static $_counties;
|
||||
public function construct() {
|
||||
parent::construct();
|
||||
if (!self::$_counties) {
|
||||
if (!civicrm_initialize()) {
|
||||
return;
|
||||
}
|
||||
require_once 'CRM/Core/PseudoConstant.php';
|
||||
self::$_counties = CRM_Core_PseudoConstant::county();
|
||||
}
|
||||
}
|
||||
|
||||
public function render($values) {
|
||||
$sid = $values->{$this->field_alias};
|
||||
if (empty($sid) ||
|
||||
(int ) $sid <= 0
|
||||
) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return self::$_counties[$values->{$this->field_alias}];
|
||||
}
|
||||
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
return $options;
|
||||
}
|
||||
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
* Field handler to render a custom field with options
|
||||
*
|
||||
* @ingroup civicrm_field_handlers
|
||||
*/
|
||||
class civicrm_handler_field_custom extends views_handler_field {
|
||||
public function construct() {
|
||||
parent::construct();
|
||||
civicrm_initialize();
|
||||
}
|
||||
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['civicrm_custom_formatter'] = array(
|
||||
'default' => 'label',
|
||||
);
|
||||
return $options;
|
||||
}
|
||||
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
// Replicate Drupal UI for formatter options, but with CiviCRM
|
||||
// terminology.
|
||||
$form['civicrm_custom_formatter'] = array(
|
||||
'#title' => 'Formatter',
|
||||
'#type' => 'select',
|
||||
'#default_value' => $this->options['civicrm_custom_formatter'],
|
||||
'#options' => array(
|
||||
'label' => t('Label'),
|
||||
'value' => t('Value'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function render($values) {
|
||||
$value = $values->{$this->field_alias};
|
||||
switch ($this->options['civicrm_custom_formatter']) {
|
||||
case 'value':
|
||||
$value = trim($value, CRM_Core_DAO::VALUE_SEPARATOR);
|
||||
$value = implode(', ', explode(CRM_Core_DAO::VALUE_SEPARATOR, $value));
|
||||
return $value;
|
||||
|
||||
case 'label':
|
||||
default:
|
||||
if (!is_null($value)) {
|
||||
// get the field id from the db
|
||||
if (!empty($this->definition['title'])) {
|
||||
$customFieldID = CRM_Core_DAO::getFieldValue('CRM_Core_BAO_CustomField', $this->definition['title'], 'id', 'label');
|
||||
return CRM_Core_BAO_CustomField::displayValue($value, $customFieldID);
|
||||
}
|
||||
// could not get custom id, lets just return what we have
|
||||
return $value;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/*
|
||||
/ * Unchanged anonymous code contribution. No claim.
|
||||
*
|
||||
* civicrm_handler_field_custom_file.inc
|
||||
* Displays File field uri instead of id.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Field handler to provide acess control for the File field
|
||||
*
|
||||
* @ingroup civicrm_field_handlers
|
||||
*/
|
||||
class civicrm_handler_field_custom_file extends views_handler_field {
|
||||
public function construct() {
|
||||
parent::construct();
|
||||
civicrm_initialize();
|
||||
$this->additional_fields['entity_id'] = 'entity_id';
|
||||
}
|
||||
|
||||
public function render($values) {
|
||||
$value = $values->{$this->field_alias};
|
||||
if (!is_null($value)) {
|
||||
$path = 'civicrm/file';
|
||||
$fileType = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_File',
|
||||
$value,
|
||||
'mime_type'
|
||||
);
|
||||
|
||||
if ($fileType && in_array($fileType, array(
|
||||
"image/jpeg", "image/pjpeg", "image/gif", "image/x-png", "image/png"))) {
|
||||
$uri = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_File',
|
||||
$value,
|
||||
'uri'
|
||||
);
|
||||
|
||||
$path = sprintf('%s/imagefile', $path);
|
||||
}
|
||||
$entityField = $this->aliases['entity_id'];
|
||||
$url = CRM_Utils_System::url($path,
|
||||
"id={$value}&eid={$values->$entityField}",
|
||||
TRUE, FALSE, FALSE, TRUE
|
||||
);
|
||||
return CRM_Utils_System::url($path,
|
||||
"id={$value}&eid={$values->$entityField}",
|
||||
TRUE, FALSE, FALSE, TRUE
|
||||
);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Unchanged anonymous code contribution. No claim.
|
||||
*
|
||||
* civicrm_handler_field_datetime.inc
|
||||
* Converts and displays text to something views friendly.
|
||||
*
|
||||
*/
|
||||
class civicrm_handler_field_datetime extends views_handler_field_date {
|
||||
|
||||
/**
|
||||
* Convert the DATETIME from the database into unixtime then allow
|
||||
* views_handler_field_date to render as usual.
|
||||
* Also trick php into thinking the time is in the same timezone, no
|
||||
* matter the default timezone
|
||||
*/
|
||||
public function render($values) {
|
||||
$value = $values->{$this->field_alias};
|
||||
|
||||
if (is_string($value) && strpos($value, "-")) {
|
||||
$value = strtotime($value);
|
||||
|
||||
if ($value) {
|
||||
$values->{$this->field_alias} = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return parent::render($values);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
* Field handler to provide relationship to Drupal User ID
|
||||
*
|
||||
* @ingroup civicrm_field_handlers
|
||||
*/
|
||||
class civicrm_handler_field_drupalid extends views_handler_field {
|
||||
public function construct() {
|
||||
parent::construct();
|
||||
if (!civicrm_initialize()) {
|
||||
return;
|
||||
}
|
||||
require_once 'CRM/Core/BAO/UFMatch.php';
|
||||
}
|
||||
|
||||
public function render($values) {
|
||||
$cid = $values->{$this->field_alias};
|
||||
$uf_id = CRM_Core_BAO_UFMatch::getUFId($cid);
|
||||
return $uf_id;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
* Unchanged anonymous code contribution. No claim.
|
||||
*
|
||||
* civicrm_handler_field_email.inc
|
||||
* Displays Email and links to email address.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Field handler to provide acess control for the email field
|
||||
*
|
||||
* @ingroup civicrm_field_handlers
|
||||
*/
|
||||
class civicrm_handler_field_email extends civicrm_handler_field_location {
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['link_to_user'] = array('default' => 'mailto');
|
||||
return $options;
|
||||
}
|
||||
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
$form['link_to_user'] = array(
|
||||
'#title' => t('Link this field'),
|
||||
'#type' => 'radios',
|
||||
'#options' => array(
|
||||
0 => t('No link'),
|
||||
'mailto' => t("With a mailto:"),
|
||||
),
|
||||
'#default_value' => $this->options['link_to_user'],
|
||||
);
|
||||
}
|
||||
|
||||
public function render($values) {
|
||||
if ($this->options['link_to_user'] == 'mailto') {
|
||||
return l($values->{$this->field_alias}, "mailto:" . $values->{$this->field_alias});
|
||||
}
|
||||
return check_plain($values->{$this->field_alias});
|
||||
}
|
||||
|
||||
public function render_link($input, $values) {
|
||||
return $input;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
* Heavily based on anonymous code contribution. No claim.
|
||||
*
|
||||
* civicrm_handler_field_event_type.inc
|
||||
* Display's Event Type after grabbing the label from the database
|
||||
*
|
||||
*/
|
||||
class civicrm_handler_field_encounter_medium extends views_handler_field {
|
||||
static $_encounter_medium;
|
||||
public function construct() {
|
||||
parent::construct();
|
||||
if (!self::$_encounter_medium) {
|
||||
if (!civicrm_initialize()) {
|
||||
return;
|
||||
}
|
||||
require_once 'CRM/Core/OptionGroup.php';
|
||||
self::$_encounter_medium = CRM_Core_OptionGroup::values('encounter_medium', FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
public function render($values) {
|
||||
$sid = $values->{$this->field_alias};
|
||||
if (empty($sid) ||
|
||||
(int ) $sid <= 0
|
||||
) {
|
||||
return NULL;
|
||||
}
|
||||
return self::$_encounter_medium[$values->{$this->field_alias}];
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
* Field handler for events to provide simple renderer that allows linking
|
||||
* to the event page.
|
||||
*
|
||||
* @ingroup civicrm_field_handlers
|
||||
*/
|
||||
class civicrm_handler_field_event extends views_handler_field_markup {
|
||||
|
||||
/**
|
||||
* Provide link to node option
|
||||
*/
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
$form['link_to_event'] = array(
|
||||
'#title' => t('Link this field to its event page'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => $this->options['link_to_event'],
|
||||
);
|
||||
}
|
||||
|
||||
public function render_link($data, $values) {
|
||||
if (!empty($this->options['link_to_event']) && user_access('view event info') && $values->id) {
|
||||
return civicrm_views_href($data,
|
||||
'civicrm/event/info',
|
||||
"reset=1&id={$values->id}"
|
||||
);
|
||||
}
|
||||
else {
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
public function render($values) {
|
||||
$format = is_numeric($this->format) ? $this->format : $values->{$this->aliases['format']};
|
||||
return $this->render_link(check_markup($values->{$this->field_alias}, $format, FALSE), $values);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,161 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
* Heavily based on anonymous code contribution. No claim.
|
||||
*
|
||||
* civicrm_handler_field_event_link.inc
|
||||
* Displays Text Data and can be set to link to various pages related to the event.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Field handler to provide simple renderer that allows linking to an Event Page or it's Management Page.
|
||||
*/
|
||||
class civicrm_handler_field_event_link extends views_handler_field {
|
||||
|
||||
/**
|
||||
* Constructor to provide additional field to add.
|
||||
*/
|
||||
public function construct() {
|
||||
parent::construct();
|
||||
$this->additional_fields['id'] = 'id';
|
||||
}
|
||||
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['link_to_civicrm_event'] = array('default' => 'none');
|
||||
$options['custom_link'] = array('default' => '');
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide link to node option
|
||||
*/
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
$form['link_to_civicrm_event'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Choose where to link this field'),
|
||||
'#options' => array(
|
||||
'none' => t("Don't Link this Field"),
|
||||
'page' => t('Link to Event Page'),
|
||||
'registration' => t('Link to Event Registration'),
|
||||
'config' => t('Link to Event Configuration'),
|
||||
'participants' => t('Link to Event Participants'),
|
||||
'custom' => t('Link to a Custom Node'),
|
||||
),
|
||||
'#default_value' => !empty($this->options['link_to_civicrm_event']),
|
||||
);
|
||||
|
||||
$form['custom_link'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Custom Link to a Drupal Node'),
|
||||
'#description' => t('Link to a Drupal Node or View, from the base path. The Event ID will be appended to the end of the link.'),
|
||||
'#default_value' => isset($this->options['custom_link']) ? $this->options['custom_link'] : '',
|
||||
'#dependency' => array('link_to_civicrm_event' => array('custom')),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render whatever the data is as a link to the node.
|
||||
*
|
||||
* Data should be made XSS safe prior to calling this function.
|
||||
*/
|
||||
public function render_link($data, $values) {
|
||||
|
||||
$link_choice = $this->options['link_to_civicrm_event'];
|
||||
|
||||
$custom_link = NULL;
|
||||
if ($link_choice == 'custom') {
|
||||
$custom_link = $this->options['custom_link'];
|
||||
}
|
||||
|
||||
switch ($link_choice) {
|
||||
|
||||
// LINKING TO EVENT PAGE (PUBLICLY ACCESSIBLE)
|
||||
|
||||
case 'page':
|
||||
if (user_access('view event info') && $data !== NULL && $data !== '') {
|
||||
return civicrm_views_href($data,
|
||||
'civicrm/event/info',
|
||||
"reset=1&id={$values->{$this->aliases['id']}}"
|
||||
);
|
||||
}
|
||||
|
||||
// LINKING TO EVENT REGISTRATION PAGE
|
||||
case 'registration':
|
||||
if (user_access('register for events') && $data !== NULL && $data !== '') {
|
||||
require_once 'CRM/Core/Config.php';
|
||||
$config = CRM_Core_Config::singleton();
|
||||
if ($enable_cart = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::EVENT_PREFERENCES_NAME, 'enable_cart')) {
|
||||
require_once 'CRM/Event/Cart/BAO/EventInCart.php';
|
||||
//TODO don't call for every row
|
||||
$link = CRM_Event_Cart_BAO_EventInCart::get_registration_link($values->{$this->aliases['id']});
|
||||
return civicrm_views_href($link['label'], $link['path'], $link['query']);
|
||||
}
|
||||
else {
|
||||
return civicrm_views_href($data,
|
||||
'civicrm/event/register',
|
||||
"reset=1&id={$values->{$this->aliases['id']}}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// LINKING TO EVENT CONFIG PAGE
|
||||
case 'config':
|
||||
if (user_access('access CiviEvent') && $data !== NULL && $data !== '') {
|
||||
return civicrm_views_href($data,
|
||||
'civicrm/event/manage/eventInfo',
|
||||
"action=update&id={$values->{$this->aliases['id']}}&reset=1"
|
||||
);
|
||||
}
|
||||
|
||||
// LINKING TO EVENT PARTICIPANTS LIST
|
||||
case 'participants':
|
||||
if (user_access('access CiviEvent') && $data !== NULL && $data !== '') {
|
||||
return civicrm_views_href($data,
|
||||
'civicrm/event/search',
|
||||
"reset=1&force=1&event={$values->{$this->aliases['id']}}"
|
||||
);
|
||||
}
|
||||
|
||||
// CUSTOM NODE LINKAGE, GOOD FOR LINKING TO OTHER VIEWS WITH AN ARGUMENT
|
||||
case 'custom':
|
||||
if ($custom_link !== NULL && $custom_link !== '' && $data !== NULL && $data !== '') {
|
||||
return l($data, $custom_link . "{$values->{$this->aliases['id']}}", array('html' => TRUE));
|
||||
}
|
||||
|
||||
// IF THE OTHER CASES AREN'T IN PLAY, THEN JUST PRINT THE DATA
|
||||
default:
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
public function render($values) {
|
||||
return $this->render_link(check_plain($values->{$this->field_alias}), $values);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
* Unchanged anonymous code contribution. No claim.
|
||||
*
|
||||
* civicrm_handler_field_custom_file.inc
|
||||
* Displays File field uri instead of id.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Field handler to provide acess control for the File field
|
||||
*
|
||||
* @ingroup civicrm_field_handlers
|
||||
*/
|
||||
class civicrm_handler_field_custom_file extends views_handler_field {
|
||||
public function construct() {
|
||||
parent::construct();
|
||||
civicrm_initialize();
|
||||
$this->additional_fields['entity_id'] = 'entity_id';
|
||||
}
|
||||
|
||||
public function render($values) {
|
||||
$value = $values->{$this->field_alias};
|
||||
if (!is_null($value)) {
|
||||
$path = 'civicrm/file';
|
||||
$fileType = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_File',
|
||||
$value,
|
||||
'mime_type'
|
||||
);
|
||||
|
||||
if ($fileType && in_array($fileType, array(
|
||||
"image/jpeg", "image/pjpeg", "image/gif", "image/x-png", "image/png"))) {
|
||||
$uri = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_File',
|
||||
$value,
|
||||
'uri'
|
||||
);
|
||||
|
||||
$path = sprintf('%s/imagefile', $path);
|
||||
}
|
||||
$entityField = $this->aliases['entity_id'];
|
||||
$url = CRM_Utils_System::url($path,
|
||||
"id={$value}&eid={$values->$entityField}",
|
||||
TRUE, FALSE, FALSE, TRUE
|
||||
);
|
||||
return CRM_Utils_System::url($path,
|
||||
"id={$value}&eid={$values->$entityField}",
|
||||
TRUE, FALSE, FALSE, TRUE
|
||||
);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
* Field handler for Instant Messaging field
|
||||
*
|
||||
* @ingroup civicrm_field_handlers
|
||||
*/
|
||||
class civicrm_handler_field_im extends civicrm_handler_field_location {
|
||||
static $_provider;
|
||||
|
||||
public function construct() {
|
||||
parent::construct();
|
||||
if (!self::$_provider) {
|
||||
if (!civicrm_initialize()) {
|
||||
return;
|
||||
}
|
||||
self::$_provider = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id');
|
||||
}
|
||||
}
|
||||
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['provider'] = array('default' => 0);
|
||||
return $options;
|
||||
}
|
||||
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
$imOptions = array(0 => 'Any');
|
||||
foreach (self::$_provider as $id => $type) {
|
||||
$imOptions[$id] = $type;
|
||||
}
|
||||
$form['provider'] = array(
|
||||
'#type' => 'radios',
|
||||
'#title' => 'Instant Messaging provider for this field',
|
||||
'#options' => $imOptions,
|
||||
'#description' => t('Instant Messaging provider to be displayed for this field'),
|
||||
'#default_value' => $this->options['provider'],
|
||||
'#fieldset' => 'location_choices',
|
||||
);
|
||||
}
|
||||
|
||||
public function join_im($join = array()) {
|
||||
$extra = array();
|
||||
if (isset($join->extra)) {
|
||||
$extra = $join->extra;
|
||||
}
|
||||
if (isset($this->options['provider']) && $this->options['provider']) {
|
||||
$extra[] = array(
|
||||
'value' => $this->options['provider'],
|
||||
'numeric' => TRUE,
|
||||
'field' => 'provider_id',
|
||||
'operator' => '=',
|
||||
);
|
||||
}
|
||||
if (!empty($extra)) {
|
||||
$join->extra = $extra;
|
||||
}
|
||||
return $join;
|
||||
}
|
||||
|
||||
public function get_join() {
|
||||
$join = parent::get_join();
|
||||
$join = $this->join_im($join);
|
||||
return $join;
|
||||
}
|
||||
|
||||
public function ensure_my_table() {
|
||||
if (!isset($this->table_alias)) {
|
||||
if (!method_exists($this->query, 'ensure_table')) {
|
||||
vpr_trace();
|
||||
exit;
|
||||
}
|
||||
$join = $this->get_join();
|
||||
if (empty($this->relationship)) {
|
||||
//https://www.drupal.org/node/2617032
|
||||
$this->table_alias = $this->query->add_table($this->table, $this->relationship, $join);
|
||||
}
|
||||
else {
|
||||
$this->table_alias = $this->query->ensure_table($this->table, $this->relationship, $join);
|
||||
}
|
||||
}
|
||||
return $this->table_alias;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
* Field handler to present a link to the user.
|
||||
*
|
||||
* @ingroup civicrm_field_handlers
|
||||
*/
|
||||
class civicrm_handler_field_link extends civicrm_handler_field {
|
||||
public function construct() {
|
||||
parent::construct();
|
||||
$this->additional_fields['id'] = 'id';
|
||||
}
|
||||
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['text'] = array('default' => '', 'translatable' => TRUE);
|
||||
return $options;
|
||||
}
|
||||
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
$form['text'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Text to display'),
|
||||
'#default_value' => $this->options['text'],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* An example of field level access control.
|
||||
*/
|
||||
public function access() {
|
||||
return user_access('access CiviCRM');
|
||||
}
|
||||
|
||||
public function query() {
|
||||
$this->ensure_my_table();
|
||||
$this->add_additional_fields();
|
||||
}
|
||||
|
||||
public function render($values) {
|
||||
$text = !empty($this->options['text']) ? $this->options['text'] : t('view');
|
||||
$id = $values->{$this->aliases['id']};
|
||||
return civicrm_views_href($text, "civicrm/contact/view", "reset=1&id=$id");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,152 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2009 James Rakich
|
||||
* Licensed to CiviCRM under the Academic Free License version 3.0.
|
||||
*
|
||||
*
|
||||
* civicrm_handler_field_link_activity.inc
|
||||
* Completely customizable text that can be linked to numerous places related to the activity.
|
||||
* View, Edit and Delete Pages, as well as a custom Drupal Link with the activity ID appended,
|
||||
* which is great for linking to other views using the activity base table.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Field handler to provide simple renderer that allows linking to various pages involving the activity.
|
||||
*/
|
||||
class civicrm_handler_field_link_activity extends views_handler_field {
|
||||
|
||||
/**
|
||||
* Constructor to provide additional field to add.
|
||||
*/
|
||||
public function construct() {
|
||||
parent::construct();
|
||||
$this->additional_fields['id'] = 'id';
|
||||
$this->additional_fields['activity_type_id'] = 'activity_type_id';
|
||||
}
|
||||
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['link_to_civicrm_activity'] = array('default' => 'view');
|
||||
$options['custom_link'] = array('default' => '');
|
||||
$options['link_text'] = array('default' => '');
|
||||
return $options;
|
||||
}
|
||||
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
$form['link_to_civicrm_activity'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Choose where to link this field'),
|
||||
'#options' => array(
|
||||
'view' => t('Link to View Activity'),
|
||||
'edit' => t('Link to Edit Activity'),
|
||||
'delete' => t('Link to Delete Activity'),
|
||||
'custom' => t('Link to a Custom Node'),
|
||||
),
|
||||
'#default_value' => $this->options['link_to_civicrm_activity'],
|
||||
'#required' => TRUE,
|
||||
);
|
||||
|
||||
$form['custom_link'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Custom Link to a Drupal Node'),
|
||||
'#description' => t('Link to a Drupal Node or View, from the base path. The Activity ID will be appended to the end of the link.'),
|
||||
'#default_value' => isset($this->options['custom_link']) ? $this->options['custom_link'] : '',
|
||||
'#dependency' => array('edit-options-link-to-civicrm-activity' => array('custom')),
|
||||
);
|
||||
|
||||
$form['link_text'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Link Text'),
|
||||
'#description' => t('The text that will display in the field with the link.'),
|
||||
'#default_value' => isset($this->options['link_text']) ? $this->options['link_text'] : '',
|
||||
'#required' => TRUE,
|
||||
);
|
||||
}
|
||||
|
||||
public function render_link($data, $values) {
|
||||
|
||||
$link_text = $this->options['link_text'];
|
||||
$link_choice = $this->options['link_to_civicrm_activity'];
|
||||
|
||||
if ($link_choice == 'custom') {
|
||||
$custom_link = $this->options['custom_link'];
|
||||
}
|
||||
|
||||
switch ($link_choice) {
|
||||
|
||||
// LINKING TO activity VIEW PAGE
|
||||
|
||||
case 'view':
|
||||
if (user_access('view all activities') && $link_text !== NULL && $link_text !== '') {
|
||||
return civicrm_views_href($link_text,
|
||||
'civicrm/contact/view/activity',
|
||||
"atype={$values->civicrm_activity_activity_type_id}&action=view&reset=1&id={$values->id}&cid={$values->civicrm_contact_civicrm_activity_contact_id}&context=home"
|
||||
);
|
||||
}
|
||||
|
||||
// LINKING TO activity EDIT PAGE
|
||||
case 'edit':
|
||||
if (user_access('view all activities') && $link_text !== NULL && $link_text !== '') {
|
||||
return civicrm_views_href($link_text,
|
||||
'civicrm/contact/view/activity',
|
||||
"atype={$values->civicrm_activity_activity_type_id}&action=update&reset=1&id={$values->id}&cid={$values->civicrm_contact_civicrm_activity_contact_id}&context=home"
|
||||
);
|
||||
}
|
||||
|
||||
// LINKING TO activity DELETE PAGE
|
||||
case 'delete':
|
||||
if (user_access('view all activities') && $link_text !== NULL && $link_text !== '') {
|
||||
return civicrm_views_href($link_text,
|
||||
'civicrm/contact/view/activity',
|
||||
"atype={$values->civicrm_activity_activity_type_id}&action=delete&reset=1&id={$values->id}&cid={$values->civicrm_contact_civicrm_activity_contact_id}&context=home"
|
||||
);
|
||||
}
|
||||
|
||||
// CUSTOM NODE LINKAGE, GOOD FOR LINKING TO OTHER VIEWS WITH AN ARGUMENT
|
||||
case 'custom':
|
||||
if ($custom_link !== NULL && $custom_link !== '' && $link_text !== NULL && $link_text !== '') {
|
||||
return l($link_text, $custom_link . "{$values->id}");
|
||||
}
|
||||
|
||||
// IF THE OTHER CASES AREN'T IN PLAY, THEN JUST PRINT THE TEXT
|
||||
default:
|
||||
return $link_text;
|
||||
}
|
||||
}
|
||||
|
||||
public function query() {
|
||||
$this->ensure_my_table();
|
||||
$this->add_additional_fields();
|
||||
}
|
||||
|
||||
public function render($values) {
|
||||
return $this->render_link(NULL, $values);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,150 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
* Copyright (C) 2009 James Rakich
|
||||
* Licensed to CiviCRM under the Academic Free License version 3.0.
|
||||
*/
|
||||
|
||||
/**
|
||||
* civicrm_handler_field_link_contact
|
||||
*
|
||||
* Completely customizable text that can be linked to numerous places related to the activity.
|
||||
* View, Edit and Delete Pages, as well as a custom Drupal Link with the Contact ID appended,
|
||||
* which is great for linking to other views using contact or other base tables.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Field handler to provide simple renderer that allows linking to various pages involving the contact.
|
||||
*/
|
||||
class civicrm_handler_field_link_contact extends views_handler_field {
|
||||
|
||||
/**
|
||||
* Constructor to provide additional field to add.
|
||||
*/
|
||||
public function construct() {
|
||||
parent::construct();
|
||||
$this->additional_fields['id'] = 'id';
|
||||
}
|
||||
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['link_to_civicrm_contact'] = array('default' => 'view');
|
||||
$options['custom_link'] = array('default' => '');
|
||||
$options['link_text'] = array('default' => '');
|
||||
return $options;
|
||||
}
|
||||
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
$form['link_to_civicrm_contact'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Choose where to link this field'),
|
||||
'#options' => array(
|
||||
'view' => t('Link to View Contact'),
|
||||
'edit' => t('Link to Edit Contact'),
|
||||
'delete' => t('Link to Delete Contact'),
|
||||
'custom' => t('Link to a Custom Node'),
|
||||
),
|
||||
'#default_value' => $this->options['link_to_civicrm_contact'],
|
||||
'#required' => TRUE,
|
||||
);
|
||||
|
||||
$form['custom_link'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Custom Link to a Drupal Node'),
|
||||
'#description' => t('Link to a Drupal Node or View, from the base path. The Contact ID will be appended to the end of the link.'),
|
||||
'#default_value' => isset($this->options['custom_link']) ? $this->options['custom_link'] : '',
|
||||
'#dependency' => array('edit-options-link-to-civicrm-contact' => array('custom')),
|
||||
);
|
||||
|
||||
$form['link_text'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Link Text'),
|
||||
'#description' => t('The text that will display in the field with the link.'),
|
||||
'#default_value' => isset($this->options['link_text']) ? $this->options['link_text'] : '',
|
||||
'#required' => TRUE,
|
||||
);
|
||||
}
|
||||
|
||||
public function render_link($data, $values) {
|
||||
$link_text = $this->options['link_text'];
|
||||
$link_choice = $this->options['link_to_civicrm_contact'];
|
||||
if ($link_choice == 'custom') {
|
||||
$custom_link = $this->options['custom_link'];
|
||||
}
|
||||
|
||||
switch ($link_choice) {
|
||||
|
||||
// LINKING TO CONTACT VIEW PAGE
|
||||
|
||||
case 'view':
|
||||
if (user_access('view all contacts') && $link_text !== NULL && $link_text !== '') {
|
||||
return civicrm_views_href($link_text,
|
||||
'civicrm/contact/view',
|
||||
"reset=1&cid={$values->id}"
|
||||
);
|
||||
}
|
||||
|
||||
// LINKING TO CONTACT EDIT PAGE
|
||||
case 'edit':
|
||||
if (user_access('edit all contacts') && $link_text !== NULL && $link_text !== '') {
|
||||
return civicrm_views_href($link_text,
|
||||
'civicrm/contact/add',
|
||||
"reset=1&action=update&cid={$values->id}"
|
||||
);
|
||||
}
|
||||
|
||||
// LINKING TO CONTACT DELETE PAGE
|
||||
case 'delete':
|
||||
if (user_access('edit all contacts') && $link_text !== NULL && $link_text !== '') {
|
||||
return civicrm_views_href($link_text,
|
||||
'civicrm/contact/view/delete',
|
||||
"reset=1&delete=1&cid={$values->id}"
|
||||
);
|
||||
}
|
||||
|
||||
// CUSTOM NODE LINKAGE, GOOD FOR LINKING TO OTHER VIEWS WITH AN ARGUMENT
|
||||
case 'custom':
|
||||
if ($custom_link !== NULL && $custom_link !== '' && $link_text !== NULL && $link_text !== '') {
|
||||
return l($link_text, $custom_link . "{$values->id}");
|
||||
}
|
||||
// IF THE OTHER CASES AREN'T IN PLAY, THEN JUST PRINT THE TEXT
|
||||
default:
|
||||
return $link_text;
|
||||
}
|
||||
}
|
||||
|
||||
public function query() {
|
||||
$this->ensure_my_table();
|
||||
$this->add_additional_fields();
|
||||
}
|
||||
|
||||
public function render($values) {
|
||||
return $this->render_link(check_plain(property_exists($values, $this->field_alias)), $values);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,152 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
* Copyright (C) 2009 James Rakich
|
||||
* Licensed to CiviCRM under the Academic Free License version 3.0.
|
||||
*/
|
||||
|
||||
/**
|
||||
* civicrm_handler_field_link_contribution.inc
|
||||
* Completely customizable text that can be linked to numerous places related to the contribution.
|
||||
* View, Edit and Delete Pages, as well as a custom Drupal Link with the activity ID appended,
|
||||
* which is great for linking to other views using the contribution base table.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Field handler to provide simple renderer that allows linking to various pages involving the contribution.
|
||||
*/
|
||||
class civicrm_handler_field_link_contribution extends views_handler_field {
|
||||
|
||||
/**
|
||||
* Constructor to provide additional field to add.
|
||||
*/
|
||||
public function construct() {
|
||||
parent::construct();
|
||||
$this->additional_fields['contact_id'] = 'contact_id';
|
||||
$this->additional_fields['id'] = 'id';
|
||||
}
|
||||
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['link_to_civicrm_contribution'] = array('default' => 'view');
|
||||
$options['custom_link'] = array('default' => '');
|
||||
$options['link_text'] = array('default' => '');
|
||||
return $options;
|
||||
}
|
||||
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
$form['link_to_civicrm_contribution'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Choose where to link this field'),
|
||||
'#options' => array(
|
||||
'view' => t('Link to View Contribution'),
|
||||
'edit' => t('Link to Edit Contribution'),
|
||||
'delete' => t('Link to Delete Contribution'),
|
||||
'custom' => t('Link to a Custom Node'),
|
||||
),
|
||||
'#default_value' => $this->options['link_to_civicrm_contribution'],
|
||||
'#required' => TRUE,
|
||||
);
|
||||
|
||||
$form['custom_link'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Custom Link to a Drupal Node'),
|
||||
'#description' => t('Link to a Drupal Node or View, from the base path. The Contribution ID will be appended to the end of the link.'),
|
||||
'#default_value' => isset($this->options['custom_link']) ? $this->options['custom_link'] : '',
|
||||
'#dependency' => array('edit-options-link-to-civicrm-contribution' => array('custom')),
|
||||
);
|
||||
|
||||
$form['link_text'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Link Text'),
|
||||
'#description' => t('The text that will display in the field with the link.'),
|
||||
'#default_value' => isset($this->options['link_text']) ? $this->options['link_text'] : '',
|
||||
'#required' => TRUE,
|
||||
);
|
||||
}
|
||||
|
||||
public function render_link($data, $values) {
|
||||
|
||||
$link_text = $this->options['link_text'];
|
||||
$link_choice = $this->options['link_to_civicrm_contribution'];
|
||||
|
||||
if ($link_choice == 'custom') {
|
||||
$custom_link = $this->options['custom_link'];
|
||||
}
|
||||
|
||||
switch ($link_choice) {
|
||||
|
||||
// LINKING TO CONTRIBUTION VIEW PAGE
|
||||
|
||||
case 'view':
|
||||
if (user_access('edit contributions') && $link_text !== NULL && $link_text !== '') {
|
||||
return civicrm_views_href($link_text,
|
||||
'civicrm/contact/view/contribution',
|
||||
"reset=1&id={$values->id}&cid={$values->civicrm_contribution_contact_id}&action=view&context=search&selectedChild=contribute"
|
||||
);
|
||||
}
|
||||
|
||||
// LINKING TO CONTRIBUTION EDIT PAGE
|
||||
case 'edit':
|
||||
if (user_access('edit contributions') && $link_text !== NULL && $link_text !== '') {
|
||||
return civicrm_views_href($link_text,
|
||||
'civicrm/contact/view/contribution',
|
||||
"reset=1&action=update&id={$values->id}&cid={$values->civicrm_contribution_contact_id}&context=search"
|
||||
);
|
||||
}
|
||||
|
||||
// LINKING TO CONTRIBUTION DELETE PAGE
|
||||
case 'delete':
|
||||
if (user_access('edit contributions') && $link_text !== NULL && $link_text !== '') {
|
||||
return civicrm_views_href($link_text,
|
||||
'civicrm/contact/view/contribution',
|
||||
"reset=1&action=delete&id={$values->id}&cid={$values->civicrm_contribution_contact_id}&context=search"
|
||||
);
|
||||
}
|
||||
|
||||
// CUSTOM NODE LINKAGE, GOOD FOR LINKING TO OTHER VIEWS WITH AN ARGUMENT
|
||||
case 'custom':
|
||||
if ($custom_link !== NULL && $custom_link !== '' && $link_text !== NULL && $link_text !== '') {
|
||||
return l($link_text, $custom_link . "{$values->id}");
|
||||
}
|
||||
|
||||
// IF THE OTHER CASES AREN'T IN PLAY, THEN JUST PRINT THE TEXT
|
||||
default:
|
||||
return $link_text;
|
||||
}
|
||||
}
|
||||
|
||||
public function query() {
|
||||
$this->ensure_my_table();
|
||||
$this->add_additional_fields();
|
||||
}
|
||||
|
||||
public function render($values) {
|
||||
return $this->render_link(NULL, $values);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
* Field handler to present a link to user delete.
|
||||
*
|
||||
* @ingroup civicrm_field_handlers
|
||||
*/
|
||||
class civicrm_handler_field_link_delete extends civicrm_handler_field_link {
|
||||
|
||||
/**
|
||||
* An example of field level access control.
|
||||
*/
|
||||
public function access() {
|
||||
return user_access('access CiviCRM');
|
||||
}
|
||||
|
||||
public function render($values) {
|
||||
$text = !empty($this->options['text']) ? $this->options['text'] : t('delete');
|
||||
$id = $values->{$this->aliases['id']};
|
||||
return civicrm_views_href($text,
|
||||
'civicrm/contact/delete',
|
||||
"reset=1&id=$id"
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
* Field handler to present a link to user edit.
|
||||
*
|
||||
* @ingroup civicrm_field_handlers
|
||||
*/
|
||||
class civicrm_handler_field_link_edit extends civicrm_handler_field_link {
|
||||
/**
|
||||
* An example of field level access control.
|
||||
*/
|
||||
public function access() {
|
||||
return user_access('access CiviCRM');
|
||||
}
|
||||
|
||||
public function render($values) {
|
||||
$text = !empty($this->options['text']) ? $this->options['text'] : t('edit');
|
||||
$id = $values->id;
|
||||
return civicrm_views_href($text,
|
||||
'civicrm/contact/add',
|
||||
"reset=1&action=update&cid=$id"
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,181 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2009 James Rakich
|
||||
* Licensed to CiviCRM under the Academic Free License version 3.0.
|
||||
*/
|
||||
|
||||
/**
|
||||
* civicrm_handler_field_link_event.inc
|
||||
* Completely customizable text that can be linked to numerous places related to the event.
|
||||
* Info, Register, Config etc pages, as well as a custom Drupal Link with the Event ID appended,
|
||||
* which is great for linking to other views using the event or participant base table.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Field handler to provide simple renderer that allows linking to various pages involving the event.
|
||||
*/
|
||||
class civicrm_handler_field_link_event extends views_handler_field {
|
||||
|
||||
/**
|
||||
* Constructor to provide additional field to add.
|
||||
*/
|
||||
public function construct() {
|
||||
parent::construct();
|
||||
$this->additional_fields['id'] = 'id';
|
||||
}
|
||||
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['link_to_civicrm_event'] = array('default' => 'view');
|
||||
$options['custom_link'] = array('default' => '');
|
||||
$options['link_text'] = array('default' => '');
|
||||
return $options;
|
||||
}
|
||||
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
$form['link_to_civicrm_event'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Choose where to link this field'),
|
||||
'#options' => array(
|
||||
'page' => t('Link to Event Page'),
|
||||
'register' => t('Link to Registration Page'),
|
||||
'config' => t('Link to Event Configuration'),
|
||||
'listing' => t('Link to Participant Listing'),
|
||||
'participants' => t('Link to Edit Event Participants'),
|
||||
'delete' => t('Link to Delete Event'),
|
||||
'custom' => t('Link to a Custom Node'),
|
||||
),
|
||||
'#default_value' => $this->options['link_to_civicrm_event'],
|
||||
'#required' => TRUE,
|
||||
);
|
||||
|
||||
$form['custom_link'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Custom Link to a Drupal Node'),
|
||||
'#description' => t('Link to a Drupal Node or View, from the base path. The Event ID will be appended to the end of the link.'),
|
||||
'#default_value' => isset($this->options['custom_link']) ? $this->options['custom_link'] : '',
|
||||
'#dependency' => array('edit-options-link-to-civicrm-event' => array('custom')),
|
||||
);
|
||||
|
||||
$form['link_text'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Link Text'),
|
||||
'#description' => t('The text that will display in the field with the link.'),
|
||||
'#default_value' => isset($this->options['link_text']) ? $this->options['link_text'] : '',
|
||||
'#required' => TRUE,
|
||||
);
|
||||
}
|
||||
|
||||
public function render_link($data, $values) {
|
||||
|
||||
$link_text = $this->options['link_text'];
|
||||
$link_choice = $this->options['link_to_civicrm_event'];
|
||||
|
||||
if ($link_choice == 'custom') {
|
||||
$custom_link = $this->options['custom_link'];
|
||||
}
|
||||
|
||||
switch ($link_choice) {
|
||||
|
||||
// LINKING TO EVENT INFO
|
||||
|
||||
case 'page':
|
||||
if (user_access('view event info') && $link_text !== NULL && $link_text !== '') {
|
||||
return civicrm_views_href($link_text,
|
||||
'civicrm/event/info',
|
||||
"id={$values->id}&reset=1"
|
||||
);
|
||||
}
|
||||
|
||||
// LINKING TO EVENT REGISTRATION
|
||||
case 'register':
|
||||
if (user_access('register for events') && $link_text !== NULL && $link_text !== '') {
|
||||
return civicrm_views_href($link_text,
|
||||
'civicrm/event/register',
|
||||
"id={$values->id}&reset=1"
|
||||
);
|
||||
}
|
||||
|
||||
// LINKING TO EVENT CONFIG
|
||||
case 'config':
|
||||
if (user_access('access CiviEvent') && $link_text !== NULL && $link_text !== '') {
|
||||
return civicrm_views_href($link_text,
|
||||
'civicrm/event/manage',
|
||||
"action=update&id={$values->id}&reset=1"
|
||||
);
|
||||
}
|
||||
|
||||
// LINKING TO EVENT PARTICIPANT LISTING
|
||||
case 'listing':
|
||||
if (user_access('view event participants') && $link_text !== NULL && $link_text !== '') {
|
||||
return civicrm_views_href($link_text,
|
||||
'civicrm/event/participant',
|
||||
"reset=1&id={$values->id}"
|
||||
);
|
||||
}
|
||||
|
||||
// LINKING TO EVENT PARTICIPANTS
|
||||
case 'participants':
|
||||
if (user_access('edit event participants') && $link_text !== NULL && $link_text !== '') {
|
||||
return civicrm_views_href($link_text,
|
||||
'civicrm/event/search',
|
||||
"reset=1&force=1&event={$values->id}"
|
||||
);
|
||||
}
|
||||
|
||||
// LINKING TO EVENT DELETION
|
||||
case 'delete':
|
||||
if (user_access('access CiviEvent') && $link_text !== NULL && $link_text !== '') {
|
||||
return civicrm_views_href($link_text,
|
||||
'civicrm/event/manage',
|
||||
"action=delete&id={$values->id}"
|
||||
);
|
||||
}
|
||||
|
||||
// CUSTOM NODE LINKAGE, GOOD FOR LINKING TO OTHER VIEWS WITH AN ARGUMENT
|
||||
case 'custom':
|
||||
if ($custom_link !== NULL && $custom_link !== '' && $link_text !== NULL && $link_text !== '') {
|
||||
return l($link_text, $custom_link . "{$values->id}");
|
||||
}
|
||||
|
||||
// see CRM-CRM-14251 - if we return null here then views is able to be configured as to what to do
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
public function query() {
|
||||
$this->ensure_my_table();
|
||||
$this->add_additional_fields();
|
||||
}
|
||||
|
||||
public function render($values) {
|
||||
return $this->render_link(NULL, $values);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,152 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2009 James Rakich
|
||||
* Licensed to CiviCRM under the Academic Free License version 3.0.
|
||||
*/
|
||||
|
||||
/**
|
||||
* civicrm_handler_field_link_participant.inc
|
||||
* Completely customizable text that can be linked to numerous places related to the participant.
|
||||
* View, Edit and Delete Pages, as well as a custom Drupal Link with the participant ID appended,
|
||||
* which is great for linking to other views using the activity base table.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Field handler to provide simple renderer that allows linking to various pages involving the participant.
|
||||
*/
|
||||
class civicrm_handler_field_link_participant extends views_handler_field {
|
||||
|
||||
/**
|
||||
* Constructor to provide additional field to add.
|
||||
*/
|
||||
public function construct() {
|
||||
parent::construct();
|
||||
$this->additional_fields['contact_id'] = array('table' => 'civicrm_participant', 'field' => 'contact_id');
|
||||
$this->additional_fields['id'] = 'id';
|
||||
}
|
||||
|
||||
public function query() {
|
||||
$this->ensure_my_table();
|
||||
$this->add_additional_fields();
|
||||
}
|
||||
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['link_to_civicrm_participant'] = array('default' => 'view');
|
||||
$options['custom_link'] = array('default' => '');
|
||||
$options['link_text'] = array('default' => '');
|
||||
return $options;
|
||||
}
|
||||
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
$form['link_to_civicrm_participant'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Choose where to link this field'),
|
||||
'#options' => array(
|
||||
'view' => t('Link to View Participant'),
|
||||
'edit' => t('Link to Edit Participant'),
|
||||
'delete' => t('Link to Delete Participant'),
|
||||
'custom' => t('Link to a Custom Node'),
|
||||
),
|
||||
'#default_value' => $this->options['link_to_civicrm_participant'],
|
||||
'#required' => TRUE,
|
||||
);
|
||||
|
||||
$form['custom_link'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Custom Link to a Drupal Node'),
|
||||
'#description' => t('Link to a Drupal Node or View, from the base path. The Participant ID will be appended to the end of the link.'),
|
||||
'#default_value' => isset($this->options['custom_link']) ? $this->options['custom_link'] : '',
|
||||
'#dependency' => array('edit-options-link-to-civicrm-participant' => array('custom')),
|
||||
);
|
||||
|
||||
$form['link_text'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Link Text'),
|
||||
'#description' => t('The text that will display in the field with the link.'),
|
||||
'#default_value' => isset($this->options['link_text']) ? $this->options['link_text'] : '',
|
||||
'#required' => TRUE,
|
||||
);
|
||||
}
|
||||
|
||||
public function render_link($data, $values) {
|
||||
|
||||
$link_text = $this->options['link_text'];
|
||||
$link_choice = $this->options['link_to_civicrm_participant'];
|
||||
|
||||
if ($link_choice == 'custom') {
|
||||
$custom_link = $this->options['custom_link'];
|
||||
}
|
||||
|
||||
switch ($link_choice) {
|
||||
|
||||
// LINKING TO PARTICIPANT VIEW PAGE
|
||||
case 'view':
|
||||
if (user_access('edit event participants') && $link_text !== NULL && $link_text !== '') {
|
||||
return civicrm_views_href($link_text,
|
||||
'civicrm/contact/view/participant',
|
||||
"reset=1&id={$values->id}&cid={$values->civicrm_participant_contact_id}&action=view&context=search&selectedChild=event"
|
||||
);
|
||||
}
|
||||
|
||||
// LINKING TO PARTICIPANT EDIT PAGE
|
||||
case 'edit':
|
||||
if (user_access('edit event participants') && $link_text !== NULL && $link_text !== '') {
|
||||
return civicrm_views_href($link_text,
|
||||
'civicrm/contact/view/participant',
|
||||
"reset=1&action=update&id={$values->id}&cid={$values->civicrm_participant_contact_id}&context=search"
|
||||
);
|
||||
}
|
||||
|
||||
// LINKING TO PARTICIPANT DELETE PAGE
|
||||
case 'delete':
|
||||
if (user_access('edit event participants') && $link_text !== NULL && $link_text !== '') {
|
||||
return civicrm_views_href($link_text,
|
||||
'civicrm/contact/view/participant',
|
||||
"reset=1&action=delete&id={$values->id}&cid={$values->civicrm_participant_contact_id}&context=search"
|
||||
);
|
||||
}
|
||||
|
||||
// CUSTOM NODE LINKAGE, GOOD FOR LINKING TO OTHER VIEWS WITH AN ARGUMENT
|
||||
case 'custom':
|
||||
if ($custom_link !== NULL && $custom_link !== '' && $link_text !== NULL && $link_text !== '') {
|
||||
return l($link_text, $custom_link . "{$values->id}");
|
||||
}
|
||||
|
||||
// IF THE OTHER CASES AREN'T IN PLAY, THEN JUST PRINT THE TEXT
|
||||
default:
|
||||
return $link_text;
|
||||
}
|
||||
}
|
||||
|
||||
public function render($values) {
|
||||
return $this->render_link(NULL, $values);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* civicrm_handler_field_link_pcp.inc
|
||||
*
|
||||
* Creates Personal Campaign Page-relate links.
|
||||
* At this time the View and Contribute Pages are supported.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Field handler to provide simple renderer that allows linking to various pages involving the PCP.
|
||||
*/
|
||||
class civicrm_handler_field_link_pcp extends views_handler_field {
|
||||
|
||||
/**
|
||||
* Constructor to provide additional field to add.
|
||||
*/
|
||||
public function construct() {
|
||||
parent::construct();
|
||||
$this->additional_fields['id'] = 'id';
|
||||
$this->additional_fields['page_id'] = 'page_id';
|
||||
}
|
||||
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['link_to_civicrm_pcp'] = array('default' => 'view');
|
||||
return $options;
|
||||
}
|
||||
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
$form['link_to_civicrm_pcp'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Choose which kind of link to create'),
|
||||
'#options' => array(
|
||||
'view' => t('Link to View Personal Campaign Page'),
|
||||
'contribute' => t('Link to Make Contribution via Personal Campaign Page'),
|
||||
),
|
||||
'#default_value' => $this->options['link_to_civicrm_pcp'],
|
||||
);
|
||||
}
|
||||
|
||||
public function render_link($data, $values) {
|
||||
|
||||
$link_choice = $this->options['link_to_civicrm_pcp'];
|
||||
|
||||
switch ($link_choice) {
|
||||
|
||||
// LINKING TO PCP VIEW PAGE - this provides a URL for users to use however they like in their view
|
||||
// (e.g., exclude this field from view and output the Title of the PCP as a link, using Views'
|
||||
// replacement patterns to supply the link path
|
||||
case 'view':
|
||||
// why bother displaying PCP pages if the user can't follow through with a donation?
|
||||
if (user_access('make online contributions')) {
|
||||
return civicrm_views_url(
|
||||
'civicrm/pcp/info',
|
||||
"reset=1&id={$values->id}",
|
||||
// results in an absolute URL
|
||||
TRUE
|
||||
);
|
||||
}
|
||||
|
||||
// LINKING TO PCP CONTRIBUTION PAGE - this provides a URL for users to use however they like in their view
|
||||
// (e.g., exclude this field from view and output the Text For Donate Link of the PCP as a link, using Views'
|
||||
// replacement patterns to supply the link path
|
||||
case 'contribute':
|
||||
if (user_access('make online contributions')) {
|
||||
return civicrm_views_url(
|
||||
'civicrm/contribute/transact',
|
||||
"id={$values->page_id}&pcpId={$values->id}&reset=1",
|
||||
// results in an absolute URL
|
||||
TRUE
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function query() {
|
||||
$this->ensure_my_table();
|
||||
$this->add_additional_fields();
|
||||
}
|
||||
|
||||
public function render($values) {
|
||||
return $this->render_link(check_plain($values->{$this->field_alias}), $values);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,172 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2009 James Rakich, minor changes by Danila Deliya.
|
||||
* Licensed to CiviCRM under the Academic Free License version 3.0.
|
||||
*
|
||||
*
|
||||
* civicrm_handler_field_link_relationship.inc
|
||||
* Completely customizable text that can be linked to numerous places related to the relationship.
|
||||
* View, Edit and Delete Pages, as well as a custom Drupal Link with the relationship ID appended,
|
||||
* which is great for linking to other views using the relationship base table.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Field handler to provide simple renderer that allows linking to various pages involving the relationship.
|
||||
*/
|
||||
class civicrm_handler_field_link_relationship extends views_handler_field {
|
||||
|
||||
/**
|
||||
* Constructor to provide additional field to add.
|
||||
*/
|
||||
public function construct() {
|
||||
parent::construct();
|
||||
$this->additional_fields['contact_id_a'] = 'contact_id_a';
|
||||
$this->additional_fields['contact_id_b'] = 'contact_id_b';
|
||||
$this->additional_fields['id'] = 'id';
|
||||
}
|
||||
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['link_to_civicrm_relationship'] = array('default' => 'view');
|
||||
$options['custom_link'] = array('default' => '');
|
||||
$options['link_text'] = array('default' => '');
|
||||
return $options;
|
||||
}
|
||||
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
$form['link_to_civicrm_relationship'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Choose where to link this field'),
|
||||
'#options' => array(
|
||||
'view_A_B' => t('Link to View Relationship A-B'),
|
||||
'edit_A_B' => t('Link to Edit Relationship A-B'),
|
||||
'view_B_A' => t('Link to View Relationship B-A'),
|
||||
'edit_B_A' => t('Link to Edit Relationship B-A'),
|
||||
'delete' => t('Link to Delete Relationship'),
|
||||
'custom' => t('Link to a Custom Node'),
|
||||
),
|
||||
'#default_value' => $this->options['link_to_civicrm_relationship'],
|
||||
'#required' => TRUE,
|
||||
);
|
||||
|
||||
$form['custom_link'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Custom Link to a Drupal Node'),
|
||||
'#description' => t('Link to a Drupal Node or View, from the base path. The relationship ID will be appended to the end of the link.'),
|
||||
'#default_value' => isset($this->options['custom_link']) ? $this->options['custom_link'] : '',
|
||||
'#dependency' => array('edit-options-link-to-civicrm-relationship' => array('custom')),
|
||||
);
|
||||
|
||||
$form['link_text'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Link Text'),
|
||||
'#description' => t('The text that will display in the field with the link.'),
|
||||
'#default_value' => isset($this->options['link_text']) ? $this->options['link_text'] : '',
|
||||
'#required' => TRUE,
|
||||
);
|
||||
}
|
||||
|
||||
public function render_link($data, $values) {
|
||||
|
||||
$link_text = $this->options['link_text'];
|
||||
$link_choice = $this->options['link_to_civicrm_relationship'];
|
||||
|
||||
if ($link_choice == 'custom') {
|
||||
$custom_link = $this->options['custom_link'];
|
||||
}
|
||||
|
||||
switch ($link_choice) {
|
||||
|
||||
// LINKING TO RELATIONSHIP VIEW PAGE
|
||||
case 'view_A_B':
|
||||
|
||||
if (user_access('view all contacts') && $link_text !== NULL && $link_text !== '') {
|
||||
return civicrm_views_href($link_text,
|
||||
'civicrm/contact/view/rel',
|
||||
"reset=1&id={$values->id}&cid={$values->civicrm_relationship_contact_id_a}&action=view&rtype=a_b&selectedChild=rel"
|
||||
);
|
||||
}
|
||||
|
||||
// LINKING TO RELATIONSHIP EDIT PAGE
|
||||
case 'edit_A_B':
|
||||
if (user_access('edit all contacts') && $link_text !== NULL && $link_text !== '') {
|
||||
return civicrm_views_href($link_text,
|
||||
'civicrm/contact/view/rel',
|
||||
"reset=1&action=update&id={$values->id}&cid={$values->civicrm_relationship_contact_id_a}&rtype=a_b"
|
||||
);
|
||||
}
|
||||
case 'view_B_A':
|
||||
|
||||
if (user_access('view all contacts') && $link_text !== NULL && $link_text !== '') {
|
||||
return civicrm_views_href($link_text,
|
||||
'civicrm/contact/view/rel',
|
||||
"reset=1&id={$values->id}&cid={$values->civicrm_relationship_contact_id_b}&action=view&rtype=b_a&selectedChild=rel"
|
||||
);
|
||||
}
|
||||
|
||||
// LINKING TO RELATIONSHIP EDIT PAGE
|
||||
case 'edit_B_A':
|
||||
if (user_access('edit all contacts') && $link_text !== NULL && $link_text !== '') {
|
||||
return civicrm_views_href($link_text,
|
||||
'civicrm/contact/view/rel',
|
||||
"reset=1&action=update&id={$values->id}&cid={$values->civicrm_relationship_contact_id_b}&rtype=b_a"
|
||||
);
|
||||
}
|
||||
|
||||
// LINKING TO RELATIONSHIP DELETE PAGE
|
||||
case 'delete':
|
||||
if (user_access('edit all contacts') && $link_text !== NULL && $link_text !== '') {
|
||||
return civicrm_views_href($link_text,
|
||||
'civicrm/contact/view/rel',
|
||||
"reset=1&action=delete&id={$values->id}&cid={$values->civicrm_relationship_contact_id_a}&rtype=a_b"
|
||||
);
|
||||
}
|
||||
|
||||
// CUSTOM NODE LINKAGE, GOOD FOR LINKING TO OTHER VIEWS WITH AN ARGUMENT
|
||||
case 'custom':
|
||||
if ($custom_link !== NULL && $custom_link !== '' && $link_text !== NULL && $link_text !== '') {
|
||||
return l($link_text, $custom_link . "{$values->id}");
|
||||
}
|
||||
|
||||
// IF THE OTHER CASES AREN'T IN PLAY, THEN JUST PRINT THE TEXT
|
||||
default:
|
||||
return $link_text;
|
||||
}
|
||||
}
|
||||
|
||||
public function query() {
|
||||
$this->ensure_my_table();
|
||||
$this->add_additional_fields();
|
||||
}
|
||||
|
||||
public function render($values) {
|
||||
return $this->render_link(NULL, $values);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,165 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
* Generic field handler for address and location fields
|
||||
*
|
||||
* @ingroup civicrm_field_handlers
|
||||
*/
|
||||
class civicrm_handler_field_location extends civicrm_handler_field {
|
||||
static $_locationTypes;
|
||||
static $_locationOps;
|
||||
static $location_op;
|
||||
|
||||
public function construct() {
|
||||
parent::construct();
|
||||
if (!self::$_locationTypes) {
|
||||
if (!civicrm_initialize()) {
|
||||
return;
|
||||
}
|
||||
require_once 'CRM/Core/PseudoConstant.php';
|
||||
self::$_locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
|
||||
self::$_locationOps = array(0 => 'AND', 1 => 'OR');
|
||||
}
|
||||
}
|
||||
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['location_type'] = array('default' => 0);
|
||||
$options['location_op'] = array('default' => 0);
|
||||
$options['is_primary'] = array('default' => '');
|
||||
return $options;
|
||||
}
|
||||
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
$locationOptions = array(0 => 'Any');
|
||||
foreach (self::$_locationTypes as $id => $type) {
|
||||
$locationOptions[$id] = $type;
|
||||
}
|
||||
$label = $this->label();
|
||||
$form['label'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Label'),
|
||||
'#default_value' => $label,
|
||||
'#dependency' => array(
|
||||
'edit-options-custom-label' => array(1),
|
||||
),
|
||||
'#weight' => -102,
|
||||
);
|
||||
$form['location_choices'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('CiviCRM Location Display Options'),
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
'#description' => '<strong>Note:</strong> it is possible to choose display options that result in nothing being displayed for this field',
|
||||
'#weight' => 1,
|
||||
);
|
||||
$form['location_op'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => 'And/Or',
|
||||
'#options' => self::$_locationOps,
|
||||
'#description' => t('Display option are joined by And/Or?'),
|
||||
'#default_value' => $this->options['location_op'],
|
||||
'#fieldset' => 'location_choices',
|
||||
);
|
||||
$form['location_type'] = array(
|
||||
'#type' => 'radios',
|
||||
'#title' => 'Location type for this field',
|
||||
'#options' => $locationOptions,
|
||||
'#description' => t('Location type to be displayed for this field'),
|
||||
'#default_value' => $this->options['location_type'],
|
||||
'#fieldset' => 'location_choices',
|
||||
);
|
||||
$form['is_primary'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => 'Show only Primary record?',
|
||||
'#options' => array(0 => 'No', 1 => 'Yes'),
|
||||
'#description' => t('Check above box if you want only the <strong>Primary</strong> record displayed.'),
|
||||
'#default_value' => $this->options['is_primary'],
|
||||
'#fieldset' => 'location_choices',
|
||||
);
|
||||
}
|
||||
|
||||
public function ensure_my_table() {
|
||||
if (!isset($this->table_alias)) {
|
||||
if (!method_exists($this->query, 'ensure_table')) {
|
||||
vpr_trace();
|
||||
exit;
|
||||
}
|
||||
$join = $this->get_join();
|
||||
if (empty($this->relationship)) {
|
||||
//https://www.drupal.org/node/2617032
|
||||
$this->table_alias = $this->query->add_table($this->table, $this->relationship, $join);
|
||||
}
|
||||
else {
|
||||
$this->table_alias = $this->query->ensure_table($this->table, $this->relationship, $join);
|
||||
}
|
||||
}
|
||||
return $this->table_alias;
|
||||
}
|
||||
|
||||
public function location_extras() {
|
||||
$extra = array();
|
||||
if (!empty($this->options['location_type'])) {
|
||||
$extra[] = array(
|
||||
'value' => $this->options['location_type'],
|
||||
'numeric' => TRUE,
|
||||
'field' => 'location_type_id',
|
||||
'operator' => '=',
|
||||
);
|
||||
}
|
||||
if (!empty($this->options['is_primary'])) {
|
||||
$extra[] = array(
|
||||
'value' => $this->options['is_primary'],
|
||||
'numeric' => TRUE,
|
||||
'field' => 'is_primary',
|
||||
'operator' => '=',
|
||||
);
|
||||
}
|
||||
return $extra;
|
||||
}
|
||||
|
||||
public function join_location($join = array()) {
|
||||
$extra = array();
|
||||
if (isset($join->extra)) {
|
||||
$extra = $join->extra;
|
||||
}
|
||||
$extra = array_merge($extra, $this->location_extras());
|
||||
if (!empty($extra)) {
|
||||
$join->extra = $extra;
|
||||
$join->extra_type = self::$_locationOps[$this->options['location_op']];
|
||||
}
|
||||
return $join;
|
||||
}
|
||||
|
||||
public function get_join() {
|
||||
$join = parent::get_join();
|
||||
$join = $this->join_location($join);
|
||||
return $join;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
* Field handler to provide acess control for the email field
|
||||
*
|
||||
* @ingroup civicrm_field_handlers
|
||||
*/
|
||||
class civicrm_handler_field_mail extends civicrm_handler_field {
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['link_to_civicrm'] = array('default' => 'mailto');
|
||||
return $options;
|
||||
}
|
||||
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
$form['link_to_civicrm'] = array(
|
||||
'#title' => t('Link this field'),
|
||||
'#type' => 'radios',
|
||||
'#options' => array(
|
||||
0 => t('No link'),
|
||||
'user' => t('To the user'),
|
||||
'mailto' => t("With a mailto:"),
|
||||
),
|
||||
'#default_value' => $this->options['link_to_civicrm'],
|
||||
);
|
||||
}
|
||||
|
||||
public function render($values) {
|
||||
if ($this->options['link_to_civicrm'] == 'mailto') {
|
||||
return l($values->{$this->field_alias}, "mailto:" . $values->{$this->field_alias});
|
||||
}
|
||||
return $this->render_link(check_plain($values->{$this->field_alias}), $values);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* A handler to run a field through check_markup, using the default format
|
||||
*
|
||||
*/
|
||||
class civicrm_handler_field_markup extends views_handler_field {
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
|
||||
$options['text_format'] = array('default' => filter_fallback_format());
|
||||
return $options;
|
||||
}
|
||||
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
$form['text_format'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => 'Text format',
|
||||
'#default_value' => $this->options['text_format'],
|
||||
'#options' => $this->get_formats(),
|
||||
);
|
||||
}
|
||||
|
||||
public function render($values) {
|
||||
$value = $values->{$this->field_alias};
|
||||
$retval = check_markup($value, $this->options['text_format'], FALSE);
|
||||
return ($retval == 'n/a') ? NULL : $retval;
|
||||
}
|
||||
|
||||
public function get_formats() {
|
||||
$formats = array();
|
||||
foreach (filter_formats() as $format) {
|
||||
$formats[$format->format] = $format->name;
|
||||
}
|
||||
return $formats;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
* Field handler to provide a formatted monetary string
|
||||
*
|
||||
* @ingroup civicrm_field_handlers
|
||||
*/
|
||||
class civicrm_handler_field_money extends views_handler_field {
|
||||
public function construct() {
|
||||
parent::construct();
|
||||
if (!civicrm_initialize()) {
|
||||
return;
|
||||
}
|
||||
require_once 'CRM/Utils/Money.php';
|
||||
|
||||
if (!empty($this->definition['currency field'])) {
|
||||
$this->additional_fields['currency'] = array('field' => $this->definition['currency field']);
|
||||
}
|
||||
}
|
||||
|
||||
public function render($values) {
|
||||
$value = $this->get_value($values);
|
||||
$currency = $this->get_value($values, 'currency');
|
||||
|
||||
switch ($this->options['display_format']) {
|
||||
case 'formatted':
|
||||
return CRM_Utils_Money::format($value, $currency);
|
||||
|
||||
case 'raw':
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
|
||||
$options['display_format'] = array('default' => 'formatted');
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
$form['display_format'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Display format'),
|
||||
'#options' => array(
|
||||
'formatted' => t('Currency formatted amount ($123.45)'),
|
||||
'raw' => t('Raw amount (123.45)'),
|
||||
),
|
||||
'#default_value' => $this->options['display_format'],
|
||||
);
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue