Ejemplo n.º 1
0
 static function updateCiviGroup(&$params, $op, $groupType = null)
 {
     $abort = $op == 'delete' ? true : false;
     $params['id'] = CRM_Bridge_OG_Utils::groupID($params['source'], $params['title'], $abort);
     if ($op == 'add') {
         require_once 'api/v2/Group.php';
         if ($groupType) {
             $params['group_type'] = $groupType;
         }
         $group = civicrm_group_add($params);
         if (!civicrm_error($group)) {
             $params['group_id'] = $group['result'];
         }
     } else {
         // do this only if we have a valid id
         if ($params['id']) {
             require_once 'CRM/Contact/BAO/Group.php';
             CRM_Contact_BAO_Group::discard($params['id']);
             $params['group_id'] = $params['id'];
         }
     }
     unset($params['id']);
 }
function run($argc, $argv)
{
    global $debug;
    session_start();
    require_once '../civicrm.config.php';
    require_once 'api/v2/Domain.php';
    require_once 'api/v2/Group.php';
    require_once 'api/v2/GroupNesting.php';
    require_once 'api/v2/GroupOrganization.php';
    require_once 'api/v2/Contact.php';
    if ($argc < 3 || $argc > 4) {
        #var_dump($argv);
        print_usage($argv[0]);
        exit(-1);
    }
    $org_name = $argv[1];
    $org_desc = $argv[2];
    $config = CRM_Core_Config::singleton();
    //load bootstrap to call hooks
    require_once 'CRM/Utils/System.php';
    CRM_Utils_System::loadBootStrap();
    # create the domain
    $existing_domain = civicrm_domain_get();
    $domain_params = array('name' => $org_name, 'description' => $org_desc, 'version' => $existing_domain['version']);
    $domain = civicrm_domain_create($domain_params);
    if ($debug) {
        print "Create domain result: " . var_export($domain) . "\n";
    }
    $domain_id = $domain['id'];
    # find the parent group, if necessary
    if (!is_null($argv[3])) {
        $parent_group_name = $argv[3];
        $parent_group_params = array('title' => $parent_group_name);
        $parent_groups = civicrm_group_get($parent_group_params);
        if ($debug) {
            print "Find parent group result: " . var_export($parent_groups) . "\n";
        }
        $parent_group_keys = array_keys($parent_groups);
        $parent_group_id = $parent_group_keys[0];
    }
    # create the group
    $group_params = array('title' => $org_name, 'description' => $org_desc, 'is_active' => 1);
    $group = civicrm_group_add($group_params);
    if ($debug) {
        print "Create group result: " . var_export($group) . "\n";
    }
    $group_id = $group['result'];
    # create the org nesting if necessary
    if (!is_null($parent_group_id)) {
        $group_nesting_params = array('parent_group_id' => $parent_group_id, 'child_group_id' => $group_id);
        $group_nesting = civicrm_group_nesting_create($group_nesting_params);
        if ($debug) {
            print "Create group nesting result: " . var_export($group_nesting) . "\n";
        }
    }
    # create the org contact
    $org_params = array('organization_name' => $org_name, 'contact_type' => 'Organization');
    $org = civicrm_contact_create($org_params);
    if ($debug) {
        print "Create org contact result: " . var_export($org) . "\n";
    }
    $org_id = $org['contact_id'];
    # associate the two
    $group_org_params = array('group_id' => $group_id, 'organization_id' => $org_id);
    $group_org_id = civicrm_group_organization_create($group_org_params);
    if ($debug) {
        print "Create group-org association result: " . var_export($group_org_id) . "\n";
    }
    print "\n";
    print "Add or modify the following lines in the appropriate ";
    print "civicrm.settings.php file for {$org_name}:\n";
    print "\tdefine( 'CIVICRM_DOMAIN_ID', {$domain_id} );\n";
    print "\tdefine( 'CIVICRM_DOMAIN_GROUP_ID', {$group_id} );\n";
    print "\tdefine( 'CIVICRM_DOMAIN_ORG_ID', {$org_id} );\n";
    print "\n";
}
Ejemplo n.º 3
0
 /**
  * takes an associative array and sends a thank you or email verification email
  *
  * @param array  $params (reference ) an assoc array of name/value pairs
  *
  * @return 
  * @access public
  * @static
  */
 function sendEmail($params, $sendEmailMode)
 {
     /* sendEmailMode
      * CRM_Campaign_Form_Petition_Signature::EMAIL_THANK
      * 		connected user via login/pwd - thank you
      * 	 	or dedupe contact matched who doesn't have a tag CIVICRM_TAG_UNCONFIRMED - thank you
      *  	or login using fb connect - thank you + click to add msg to fb wall
      *
      * CRM_Campaign_Form_Petition_Signature::EMAIL_CONFIRM
      *		send a confirmation request email     
      */
     require_once 'CRM/Campaign/Form/Petition/Signature.php';
     // define constant CIVICRM_PETITION_CONTACTS, if not exist in civicrm.settings.php
     if (!defined('CIVICRM_PETITION_CONTACTS')) {
         define('CIVICRM_PETITION_CONTACTS', 'Petition Contacts');
     }
     // check if the group defined by CIVICRM_PETITION_CONTACTS exists, else create it
     require_once 'api/v2/Group.php';
     $group_params['title'] = CIVICRM_PETITION_CONTACTS;
     $groups = civicrm_group_get($group_params);
     if (CRM_Utils_Array::value('is_error', $groups) == 1 && CRM_Utils_Array::value('error_message', $groups) == 'No such group exists') {
         $group_params['is_active'] = 1;
         $group_params['visibility'] = 'Public Pages';
         $newgroup = civicrm_group_add($group_params);
         if ($newgroup['is_error'] == 0) {
             $group_id[0] = $newgroup['result'];
         }
     } else {
         $group_id = array_keys($groups);
     }
     // get petition info
     $petitionParams['id'] = $params['sid'];
     $petitionInfo = array();
     CRM_Campaign_BAO_Survey::retrieve($petitionParams, $petitionInfo);
     if (empty($petitionInfo)) {
         CRM_Core_Error::fatal('Petition doesn\'t exist.');
     }
     require_once 'CRM/Core/BAO/Domain.php';
     //get the default domain email address.
     list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail();
     require_once 'CRM/Core/BAO/MailSettings.php';
     $emailDomain = CRM_Core_BAO_MailSettings::defaultDomain();
     require_once 'CRM/Contact/BAO/Contact.php';
     $toName = CRM_Contact_BAO_Contact::displayName($params['contactId']);
     $replyTo = "do-not-reply@{$emailDomain}";
     // set additional general message template params (custom tokens to use in email msg templates)
     // tokens then available in msg template as {$petition.title}, etc
     $petitionTokens['title'] = $petitionInfo['title'];
     $petitionTokens['petitionId'] = $params['sid'];
     $tplParams['petition'] = $petitionTokens;
     switch ($sendEmailMode) {
         case CRM_Campaign_Form_Petition_Signature::EMAIL_THANK:
             //add this contact to the CIVICRM_PETITION_CONTACTS group
             require_once 'api/v2/GroupContact.php';
             $params['group_id'] = $group_id[0];
             $params['contact_id'] = $params['contactId'];
             civicrm_group_contact_add($params);
             require_once 'CRM/Core/BAO/MessageTemplates.php';
             if ($params['email-Primary']) {
                 CRM_Core_BAO_MessageTemplates::sendTemplate(array('groupName' => 'msg_tpl_workflow_petition', 'valueName' => 'petition_sign', 'contactId' => $params['contactId'], 'tplParams' => $tplParams, 'from' => "\"{$domainEmailName}\" <{$domainEmailAddress}>", 'toName' => $toName, 'toEmail' => $params['email-Primary'], 'replyTo' => $replyTo, 'petitionId' => $params['sid'], 'petitionTitle' => $petitionInfo['title']));
             }
             break;
         case CRM_Campaign_Form_Petition_Signature::EMAIL_CONFIRM:
             // create mailing event subscription record for this contact
             // this will allow using a hash key to confirm email address by sending a url link
             require_once 'CRM/Mailing/Event/BAO/Subscribe.php';
             $se = CRM_Mailing_Event_BAO_Subscribe::subscribe($group_id[0], $params['email-Primary'], $params['contactId']);
             //				require_once 'CRM/Core/BAO/Domain.php';
             //				$domain =& CRM_Core_BAO_Domain::getDomain();
             $config = CRM_Core_Config::singleton();
             $localpart = CRM_Core_BAO_MailSettings::defaultLocalpart();
             require_once 'CRM/Utils/Verp.php';
             $replyTo = implode($config->verpSeparator, array($localpart . 'c', $se->contact_id, $se->id, $se->hash)) . "@{$emailDomain}";
             $confirmUrl = CRM_Utils_System::url('civicrm/petition/confirm', "reset=1&cid={$se->contact_id}&sid={$se->id}&h={$se->hash}&a={$params['activityId']}&p={$params['sid']}", true);
             $confirmUrlPlainText = CRM_Utils_System::url('civicrm/petition/confirm', "reset=1&cid={$se->contact_id}&sid={$se->id}&h={$se->hash}&a={$params['activityId']}&p={$params['sid']}", true, null, false);
             // set email specific message template params and assign to tplParams
             $petitionTokens['confirmUrl'] = $confirmUrl;
             $petitionTokens['confirmUrlPlainText'] = $confirmUrlPlainText;
             $tplParams['petition'] = $petitionTokens;
             require_once 'CRM/Core/BAO/MessageTemplates.php';
             if ($params['email-Primary']) {
                 CRM_Core_BAO_MessageTemplates::sendTemplate(array('groupName' => 'msg_tpl_workflow_petition', 'valueName' => 'petition_confirmation_needed', 'contactId' => $params['contactId'], 'tplParams' => $tplParams, 'from' => "\"{$domainEmailName}\" <{$domainEmailAddress}>", 'toName' => $toName, 'toEmail' => $params['email-Primary'], 'replyTo' => $replyTo, 'petitionId' => $params['sid'], 'petitionTitle' => $petitionInfo['title'], 'confirmUrl' => $confirmUrl));
             }
             break;
     }
 }
Ejemplo n.º 4
0
function civicrm_group_create(&$params)
{
    $result = civicrm_group_add($params);
    return $result;
}
Ejemplo n.º 5
0
 /** 
  * Function to add a Group
  *
  *@params array to add group
  *
  *@return int groupId of created group
  * 
  */
 function groupCreate($params = null)
 {
     if ($params === null) {
         $params = array('name' => 'Test Group 1', 'domain_id' => 1, 'title' => 'New Test Group Created', 'description' => 'New Test Group Created', 'is_active' => 1, 'visibility' => 'Public Pages', 'group_type' => array('1' => 1, '2' => 1));
     }
     require_once 'api/v2/Group.php';
     $result =& civicrm_group_add($params);
     return $result['result'];
 }
Ejemplo n.º 6
0
 function testgroupAddNoTitle()
 {
     $params = array('name' => 'Test Group No title ', 'domain_id' => 1, 'description' => 'New Test Group Created', 'is_active' => 1, 'visibility' => 'Public Pages', 'group_type' => array('1' => 1, '2' => 1));
     $group =& civicrm_group_add(&$params);
     $this->assertEquals($group['error_message'], 'Required parameter title missing');
 }