Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'dev' into test

  • Loading branch information...
commit 67e5158d0a1a78b36d49bc0401e5cde7381025ed 2 parents cae5282 + 1995934
@kzalewski kzalewski authored
View
164 civicrm/custom/php/CRM/NYSS/BAO/Integration.php
@@ -0,0 +1,164 @@
+<?php
+
+/*
+ * Project: BluebirdCRM
+ * Authors: Brian Shaughnessy
+ * Organization: New York State Senate
+ * Date: 2015-04-10
+ */
+
+class CRM_NYSS_BAO_Integration {
+
+ /*
+ * given a website user Id, conduct a lookup to get the contact Id
+ * if none, return empty
+ */
+ static function getContact($userId) {
+ $cid = CRM_Core_DAO::singleValueQuery("
+ SELECT id
+ FROM civicrm_contact
+ WHERE web_user_id = {$userId}
+ ");
+
+ return $cid;
+ }//getContact
+
+ /*
+ * attempt to match the record with existing contacts
+ */
+ static function matchContact($params) {
+ //format params to pass to dedupe tool
+ $dedupeParams = array(
+ 'civicrm_contact' => array(
+ 'first_name' => $params['first_name'],
+ 'last_name' => $params['last_name'],
+ 'postal_code' => $params['postal_code'],
+ 'birth_date' => $params['birth_date'],
+ 'gender_id' => $params['gender_id'],
+ ),
+ 'civicrm_address' => array(
+ 'street_address' => $params['street_address'],
+ 'city' => $params['city'],
+ 'postal_code' => $params['postal_code'],
+ ),
+ );
+
+ if ( !empty($params['email']) ) {
+ $dedupeParams['civicrm_email']['email'] = $params['email'];
+ }
+
+ $dedupeParams = CRM_Dedupe_Finder::formatParams($dedupeParams, 'Individual');
+ $dedupeParams['check_permission'] = 0;
+
+ //get indiv unsupervised rule
+ $ruleTitle = CRM_Core_DAO::singleValueQuery("
+ SELECT title
+ FROM civicrm_dedupe_rule_group
+ WHERE id = 1
+ ");
+
+ $o = new stdClass();
+ $o->title = $ruleTitle;
+ $o->params = $dedupeParams;
+ $o->noRules = FALSE;
+ $tableQueries = array();
+ nyss_dedupe_civicrm_dupeQuery($o, 'table', $tableQueries);
+ $sql = $tableQueries['civicrm.custom.5'];
+ $sql = "
+ SELECT contact.id
+ FROM civicrm_contact as contact JOIN ($sql) as dupes
+ WHERE dupes.id1 = contact.id AND contact.is_deleted = 0
+ ";
+ $r = CRM_Core_DAO::executeQuery($sql);
+
+ $dupeIDs = array();
+ while($r->fetch()) {
+ $dupeIDs[] = $r->id;
+ }
+
+ //if dupe found, return id
+ if ( !empty( $dupeIDs ) ) {
+ $cid = $dupeIDs[0];
+ }
+ else {
+ //if not found, create new contact
+ $cid = self::createContact($params);
+ }
+
+ //set user id
+ if (!empty($cid)) {
+ CRM_Core_DAO::executeQuery("
+ UPDATE civicrm_contact
+ SET web_user_id = {$params['web_user_id']}
+ WHERE id = {$cid}
+ ");
+
+ return $cid;
+ }
+ else {
+ return array(
+ 'is_error' => 'Unable to match or create contact',
+ 'params' => $params,
+ );
+ }
+ }
+
+ /*
+ * create a new contact
+ */
+ static function createContact($params) {
+ $contact = civicrm_api('contact', 'create', array('version' => 3, 'contact_type' => 'Individual') + $params);
+ //CRM_Core_Error::debug_var('contact', $contact);
+
+ return $contact['id'];
+ }//createContact
+
+ //TODO when a user moves to a different district, need to reset web_user_id
+
+ static function processIssue($contactId, $action, $params) {
+ //bbscript_log('trace', '$contactId', $contactId);
+ //bbscript_log('trace', '$action', $action);
+ //bbscript_log('trace', '$params', $params);
+
+ //find out if tag exists
+ $parentId = CRM_Core_DAO::singleValueQuery("
+ SELECT id
+ FROM civicrm_tag
+ WHERE name = 'Website Issues'
+ AND is_tagset = 1
+ ");
+ $tagId = CRM_Core_DAO::singleValueQuery("
+ SELECT id
+ FROM civicrm_tag
+ WHERE name = '{$params->issue_name}'
+ AND parent_id = {$parentId}
+ ");
+ //CRM_Core_Error::debug_var('tagId', $tagId);
+
+ if (!$tagId) {
+ $tag = civicrm_api('tag', 'create', array(
+ 'version' => 3,
+ 'name' => $params->issue_name,
+ 'parent_id' => $parentId,
+ 'is_selectable' => 0,
+ 'is_reserved' => 1,
+ 'used_for' => 'civicrm_contact',
+ 'created_date' => date('Y-m-d H:i:s'),
+ ));
+ //CRM_Core_Error::debug_var('$tag', $tag);
+
+ $tagId = $tag['id'];
+ }
+
+ $apiAction = ($action == 'follow') ? 'create' : 'delete';
+
+ $et = civicrm_api('entity_tag', $apiAction, array(
+ 'version' => 3,
+ 'entity_table' => 'civicrm_contact',
+ 'entity_id' => $contactId,
+ 'tag_id' => $tagId,
+ ));
+
+ //TODO also store is_website flag
+ }//processIssue
+}//end class
View
36 civicrm/custom/php/CRM/Report/Form/Activity.php
@@ -58,8 +58,8 @@ function __construct() {
$this->activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE);
asort( $this->activityTypes );
- //NYSS get activity keyword tags
- $this->tags = CRM_Core_BAO_Tag::getTagsUsedFor('civicrm_activity', true, false, 296);
+ //NYSS get activity and contact tags
+ $this->tags = CRM_Core_BAO_Tag::getTagsUsedFor(array('civicrm_contact', 'civicrm_activity'), true, false, 296);
//CRM_Core_Error::debug_var('tags', $this->tags);
$this->_columns = array(
@@ -118,6 +118,14 @@ function __construct() {
'default' => TRUE,
'required' => TRUE,
),
+ //NYSS 8396
+ 'contact_tag_name' =>
+ array(
+ 'name' => 'id',
+ 'alias' => 'civicrm_contact_target',
+ 'dbAlias' => "civicrm_contact_target.id",
+ 'title' => ts('Contact Tags'),
+ ),
),
'filters' =>
array(
@@ -276,10 +284,10 @@ function __construct() {
'default' => TRUE,//NYSS
),
//NYSS 8396
- 'tag_name' =>
+ 'activity_tag_name' =>
array(
'name' => 'id',
- 'title' => ts('Tag Name'),
+ 'title' => ts('Activity Tags'),
),
),
'filters' => array(
@@ -937,12 +945,26 @@ function alterDisplay(&$rows) {
}
//NYSS 8396
- if (array_key_exists('civicrm_activity_tag_name', $row)) {
- $actTags = CRM_Core_BAO_EntityTag::getTag($row['civicrm_activity_tag_name'], 'civicrm_activity');
+ if (array_key_exists('civicrm_activity_activity_tag_name', $row)) {
+ $actTags = CRM_Core_BAO_EntityTag::getTag($row['civicrm_activity_activity_tag_name'], 'civicrm_activity');
foreach ($actTags as $k => &$v) {
$v = $this->tags[$k];
}
- $rows[$rowNum]['civicrm_activity_tag_name'] = implode(', ', $actTags);
+ $rows[$rowNum]['civicrm_activity_activity_tag_name'] = implode(', ', $actTags);
+ $entryFound = TRUE;
+ }
+ if (array_key_exists('civicrm_contact_contact_tag_name', $row)) {
+ $conTags = CRM_Core_BAO_EntityTag::getTag($row['civicrm_contact_contact_tag_name'], 'civicrm_contact');
+ foreach ($conTags as $k => &$v) {
+ //only display keywords; we retrieved entire list earlier, so if not in list, exclude
+ if (isset($this->tags[$k])) {
+ $v = $this->tags[$k];
+ }
+ else {
+ unset($conTags[$k]);
+ }
+ }
+ $rows[$rowNum]['civicrm_contact_contact_tag_name'] = implode(', ', $conTags);
$entryFound = TRUE;
}
View
100 civicrm/custom/php/api/v3/NYSS.php
@@ -1,100 +0,0 @@
-<?php
-
-/*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.4 |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013 |
- +--------------------------------------------------------------------+
- | 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 for the CiviCRM APIv3 NYSS functions
- *
- * @package CiviCRM_APIv3
- * @subpackage API_NYSS
- * @copyright CiviCRM LLC (c) 2004-2013
- */
-
-/*
- * Where most apis are object-oriented (they create/update/delete rows in a table),
- * this API is more like a BAO layer specific to NYSS interaction from the public website
- * (and other purposes).
- */
-
-/**
- * Create or update a nyss
- *
- * @param array $params Associative array of property
- * name/value pairs to insert in new 'nyss'
- * @example nyssCreate.php Std Create example
- *
- * @return array api result array
- * {@getfields nyss_create}
- * @access public
- */
-function civicrm_api3_nyss_create($params) {
- return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
-}
-
-/**
- * Adjust Metadata for Create action
- *
- * The metadata is used for setting defaults, documentation & validation
- * @param array $params array or parameters determined by getfields
- */
-function _civicrm_api3_nyss_create_spec(&$params) {
- $params['title']['api.required'] = 1;
-}
-
-/**
- * Returns array of nyss matching a set of one or more group properties
- *
- * @param array $params (referance) Array of one or more valid
- * property_name=>value pairs. If $params is set
- * as null, all nyss will be returned
- *
- * @return array (referance) Array of matching nyss
- * {@getfields nyss_get}
- * @access public
- */
-function civicrm_api3_nyss_get($params) {
- return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
-}
-
-/**
- * delete an existing nyss
- *
- * This method is used to delete any existing nyss. id of the group
- * to be deleted is required field in $params array
- *
- * @param array $params (reference) array containing id of the group
- * to be deleted
- *
- * @return array (referance) returns flag true if successfull, error
- * message otherwise
- * {@getfields nyss_delete}
- * @access public
- */
-function civicrm_api3_nyss_delete($params) {
- return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
-}
-
View
149 civicrm/scripts/integration/process.php
@@ -0,0 +1,149 @@
+<?php
+
+// Project: BluebirdCRM
+// Authors: Brian Shaughnessy
+// Organization: New York State Senate
+// Date: 2015-04-10
+
+error_reporting(E_ERROR | E_PARSE | E_WARNING);
+set_time_limit(0);
+
+define('DEFAULT_LOG_LEVEL', 'TRACE');
+define('DB_INTEGRATION', 'senate_integration');
+
+class CRM_Integration_Process {
+
+ function run() {
+ require_once '../script_utils.php';
+
+ // Parse the options
+ $shortopts = "d:s";
+ $longopts = array("dryrun", "stats");
+ $optlist = civicrm_script_init($shortopts, $longopts);
+
+ if ($optlist === null) {
+ $stdusage = civicrm_script_usage();
+ $usage = '[--dryrun] [--tbl TABLENAME]';
+ error_log("Usage: ".basename(__FILE__)." $stdusage $usage\n");
+ exit(1);
+ }
+
+ bbscript_log('info', 'Initiating integration processing...');
+
+ //get instance settings
+ $bbcfg = get_bluebird_instance_config($optlist['site']);
+ //bbscript_log("trace", "bbcfg", $bbcfg);
+
+ $civicrm_root = $bbcfg['drupal.rootdir'].'/sites/all/modules/civicrm';
+ $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
+ if (!CRM_Utils_System::loadBootstrap(array(), FALSE, FALSE, $civicrm_root)) {
+ CRM_Core_Error::debug_log_message('Failed to bootstrap CMS from cleanLogs.');
+ return FALSE;
+ }
+
+ //set integration DB
+ $intDB = DB_INTEGRATION;
+
+ //get all accumulator records for instance (target)
+ $row = CRM_Core_DAO::executeQuery("
+ SELECT *
+ FROM {$intDB}.accumulator
+ WHERE target_shortname = '{$bbcfg['db.basename']}'
+ ");
+
+ $errors = $status = array();
+
+ while ($row->fetch()) {
+ //bbscript_log('trace', 'row', $row);
+
+ //check contact/user
+ if (!$cid = CRM_NYSS_BAO_Integration::getContact($row->user_id)) {
+ $contactParams = array(
+ 'web_user_id' => $row->user_id,
+ 'first_name' => $row->first_name,
+ 'last_name' => $row->last_name,
+ 'email' => $row->email_address,
+ 'street_address' => $row->street_number,//TODO check
+ 'street_unit' => $row->apt_no,
+ 'city' => $row->city,
+ 'state' => $row->state,
+ 'postal_code' => $row->zip,
+ 'birth_date' => $row->birth_date,
+ 'gender_id' => ($row->gender == 'M') ? 2 : 1,//TODO check
+ );
+
+ $cid = CRM_NYSS_BAO_Integration::matchContact($contactParams);
+ }
+ //CRM_Core_Error::debug_var('cid', $cid);
+
+ if ($cid['is_error']) {
+ $stats['error'][] = $cid;
+ continue;
+ }
+
+ //prep params
+ $params = json_decode($row->msg_info);
+
+ switch ($row->msg_type) {
+ case 'ISSUE':
+ $result = CRM_NYSS_BAO_Integration::processIssue($cid, $row->msg_action, $params);
+ break;
+
+ case 'COMMITTEE':
+ break;
+
+ case 'PETITION':
+ break;
+
+ case 'CONTACT':
+ break;
+
+ case 'BILL':
+ break;
+
+ case 'ACCOUNT':
+ break;
+
+ case 'PROFILE':
+ break;
+
+ default:
+ bbscript_log('error', 'Unable to process row. Message type is unknown.', $row);
+ $stats['unprocessed'][] = $row;
+ }
+
+ if ($result['is_error']) {
+ //TODO error handling
+ $stats['error'][] = $result;
+
+ }
+ else {
+ //TODO archive rows by ID
+ $stats['processed'][] = $row->id;
+
+ }
+ }
+
+ //report stats
+ $stats['counts'] = array(
+ 'processed' => count($stats['processed']),
+ 'unprocessed' => count($stats['unprocessed']),
+ 'error' => count($stats['error']),
+ );
+
+ echo "Processing stats:\n";
+ print_r($stats['counts']);
+
+ if ($optlist['stats']) {
+ echo "\nProcessing details:\n";
+ print_r($stats['processed']);
+ print_r($stats['unprocessed']);
+ print_r($stats['error']);
+ }
+ }//run
+
+}//end class
+
+//run the script
+$script = new CRM_Integration_Process();
+$script->run();
View
48 scripts/v157.sh
@@ -0,0 +1,48 @@
+#!/bin/sh
+#
+# v157.sh
+#
+# Project: BluebirdCRM
+# Authors: Brian Shaughnessy and Ken Zalewski
+# Organization: New York State Senate
+# Date: 2015-04-14
+#
+
+prog=`basename $0`
+script_dir=`dirname $0`
+execSql=$script_dir/execSql.sh
+readConfig=$script_dir/readConfig.sh
+
+. $script_dir/defaults.sh
+
+if [ $# -ne 1 ]; then
+ echo "Usage: $prog instanceName" >&2
+ exit 1
+fi
+
+instance="$1"
+
+if ! $readConfig --instance $instance --quiet; then
+ echo "$prog: $instance: Instance not found in config file" >&2
+ exit 1
+fi
+
+app_rootdir=`$readConfig --ig $instance app.rootdir` || app_rootdir="$DEFAULT_APP_ROOTDIR"
+
+echo "$prog: create website user id field in contacts table"
+sql="
+ ALTER TABLE civicrm_contact ADD web_user_id INT(10) NULL AFTER modified_date, ADD INDEX index_web_user_id (web_user_id);
+"
+$execSql $instance -c "$sql" -q
+
+echo "$prog: create issues tagset"
+sql="
+ DELETE FROM civicrm_tag
+ WHERE name = 'Website Issues'
+ AND is_tagset = 1;
+ INSERT INTO civicrm_tag (name, description, parent_id, is_selectable, is_reserved, is_tagset, used_for, created_id, created_date)
+ VALUES ('Website Issues', 'Tagset for issues generated from nysenate.gov', NULL, 1, 1, 1, 'civicrm_contact', NULL, NULL);
+"
+$execSql $instance -c "$sql" -q
+
+#TODO create column in entity_tag for flag from website
Please sign in to comment.
Something went wrong with that request. Please try again.