CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Implementing Phone Campaigns
Pages: [1]

Author Topic: Implementing Phone Campaigns  (Read 1117 times)

Manonline

  • Guest
Implementing Phone Campaigns
March 11, 2010, 10:10:23 am
Hello everybody, first I'm sorry for my English.

I need to do something similar like the CiviMail campaigns, but with phone calls. I'm new in CiviCRM, but I have some time in Drupal. I'm not PHP Coder, but I do something.

I didn't find anywhere a function provided by CiviCRM to create phone campaigns, so I wrote a Drupal module to use de CiviCRM API, but I have a few problems creating activities.

The module creates two Activity Types: "Phone Campaign" and "Campaign Phone Call". Theoricly, when a "Phone Campaign" activity is created, the module creates much "Campaign Phone Call" as target in "Phone Campaign" are.

I can create activity types with the API, but I couldn't create activities, or I'm not implementing the hooks in the right way.

Here is the code where the hook_civicrm_post is implemented:

Code: [Select]
<?php

function civicrm_phonecampaign_civicrm_post($op, $objectName, $objectId, &$objectRef) {
  
Logger::debug_var("op        ", $op);
  
Logger::debug_var("objectName", $objectName);
  
Logger::debug_var("objectId  ", $objectId);
  
Logger::debug_var("objectRef ", $objectRef);
  if (
$op == 'create' && $objectName == 'Activity') {
    
$atid = db_result(db_query('SELECT activity_type_id FROM civicrm_activity WHERE id=%d', $objectId));
    
$activity = db_result(db_query('SELECT label FROM civicrm_option_value WHERE value=%d', $atid));
    if (
$activity == 'Phone Campaign') {
      
$result = db_query('SELECT target_contact_id FROM civicrm_activity_target WHERE activity_id = %d', $objectId);

      while (
$row  =  db_fetch_array($result))  {
        
$idsarr[] = $row['target_contact_id'];
      }

      
$iatid = db_result(db_query("SELECT value FROM civicrm_option_value WHERE label='Campaign Phone Call'"));
      
$source_contact_id = db_result(db_query('SELECT source_contact_id FROM civicrm_activity WHERE id = %d', $objectId));
      
$assignee_contact_id = db_result(db_query('SELECT assignee_contact_id FROM civicrm_activity WHERE id = %d', $objectId));
      
$subject = db_result(db_query('SELECT subject FROM civicrm_activity WHERE id = %d', $objectId));
      
$details = db_result(db_query('SELECT details FROM civicrm_activity WHERE id = %d', $objectId));
      
$activity_date_time = db_result(db_query('SELECT activity_date_time FROM civicrm_activity WHERE id = %d', $objectId));
      
$status_id = db_result(db_query('SELECT status_id FROM civicrm_activity WHERE id = %d', $objectId));

      foreach (
$idsarr as $tcid) {
        
$params = array(
          
'activity_type_id' => $iatid,
          
'source_contact_id' => $source_contact_id,
          
'assignee_contact_id' => $assignee_contact_id,
          
'target_contact_id' => $tcid,
          
'subject' => $subject,
          
'details' => $details,
          
'status_id' => $status_id,
          
'activity_date_time' => $activity_date_time
        
);
        
$act = civicrm_activity_create($params);
      }
    }
  }
}

if anyone can give me a clue, I will be wondered :)

thanks in advance,
mano.
« Last Edit: March 11, 2010, 10:44:46 am by Manonline »

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: Implementing Phone Campaigns
March 11, 2010, 10:59:49 am
hey - you need to do a search on forum/blog for civiengage and for willsbrownburger - there are two projects for doing phone canvassing that are being worked on and integrated in to civicrm - check here http://wiki.civicrm.org/confluence/display/CRM/CiviCRM+for+Canvassing+and+GOTV

would be great if your code, time or money could help this happen
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

Manonline

  • Guest
Re: Implementing Phone Campaigns
March 12, 2010, 07:30:52 am
Yes, but the code doesn't work, and I need help to find out what I'm doing wrong to improve it. If anyone can help me implementing those hooks I'll be wondered.

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Implementing Phone Campaigns
March 12, 2010, 11:18:28 pm
Not sure I understand what you want to do:
on the post hook after a user has created an activity, you want to create another activity ?

Otherwise, avoid doing the sql directly, try rather to use the apis, or the BAO/DAO Objects if the apis don't exist.

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Implementing Phone Campaigns

This forum was archived on 2017-11-26.