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 (Moderator: Donald Lobo) »
  • sql query while event creation
Pages: [1]

Author Topic: sql query while event creation  (Read 1574 times)

nmudgal

  • I post occasionally
  • **
  • Posts: 31
  • Karma: 0
    • It's Really Me
  • CiviCRM version: civicrm 3.3
  • CMS version: Drupal 6.20
  • MySQL version: mysql 5
  • PHP version: php 5
sql query while event creation
April 01, 2011, 06:18:29 am
When a new event is saved, From which file query is fired to update db?
Or As If I have to add one more column in event table & need to update that column fields while event creation along with other event information , in which file I should put query of updating that particular column ?
Help please!
Thanks
GPG Key Fingerprint: 8B97 082A D923 2860 E0BE 3ED3 8F81 0702 6AE9 2A57

Kiran Jagtap

  • Ask me questions
  • ****
  • Posts: 533
  • Karma: 51
Re: sql query while event creation
April 01, 2011, 06:32:34 am
when user start creating new event :

CRM/Event/Form/ManageEvent/EventInfo.php is the first file going to load first event info form
and call to db to create event is done from same file postProcess() function.

$event =  CRM_Event_BAO_Event::create( $params );

this is the call which responsible to create / update event record.

hope this help

kiran
You Are Designed To Choose... Defined By Choice.

Kiran Jagtap

  • Ask me questions
  • ****
  • Posts: 533
  • Karma: 51
Re: sql query while event creation
April 01, 2011, 06:38:06 am
also to update and keep your column data up to date,

here civi hooks also play a key role and no need to modify main files

you might wanna take a look for
1. hook_civicrm_postProcess
2. hook_civicrm_pre
3. hook_civicrm_post

here is the doc : http://wiki.civicrm.org/confluence/display/CRMDOC40/CiviCRM+hook+specification

kiran
You Are Designed To Choose... Defined By Choice.

nmudgal

  • I post occasionally
  • **
  • Posts: 31
  • Karma: 0
    • It's Really Me
  • CiviCRM version: civicrm 3.3
  • CMS version: Drupal 6.20
  • MySQL version: mysql 5
  • PHP version: php 5
Re: sql query while event creation
April 01, 2011, 06:46:01 am
What am I trying to do is to fetch drupal current user logged in uid & put that into (e.g.)"user_id" column in civicrm_event table in respective event that is being created by that user.
So that I can keep track which drupal user what event ?
GPG Key Fingerprint: 8B97 082A D923 2860 E0BE 3ED3 8F81 0702 6AE9 2A57

Kiran Jagtap

  • Ask me questions
  • ****
  • Posts: 533
  • Karma: 51
Re: sql query while event creation
April 01, 2011, 07:02:37 am
hey you could get all these info w/o any db schema changes.

civicrm_event table store contact id of person who created event in 'created_id' column
civicrm_uf_match gives you mapping between drupal user and civicrm contact.

query might be like :

Code: [Select]
     
    SELECT  event.id as eventId,
            civicrm_drupal_mapping.uf_id drupalUserId,
            event.created_id  CiviCRMEventCreatedContactId
      FROM  civicrm_uf_match civicrm_drupal_mapping
INNER JOIN  civicrm_event as event ON ( event.created_id = civicrm_drupal_mapping.contact_id )

hope this help

kiran
You Are Designed To Choose... Defined By Choice.

nmudgal

  • I post occasionally
  • **
  • Posts: 31
  • Karma: 0
    • It's Really Me
  • CiviCRM version: civicrm 3.3
  • CMS version: Drupal 6.20
  • MySQL version: mysql 5
  • PHP version: php 5
Re: sql query while event creation
April 01, 2011, 07:33:39 am
I wasn't able to find this table for mapping between drupal user id & contact id of civicrm.
So I was creating this.
Thanks anyways.
GPG Key Fingerprint: 8B97 082A D923 2860 E0BE 3ED3 8F81 0702 6AE9 2A57

Rajan Mayekar

  • I post frequently
  • ***
  • Posts: 177
  • Karma: 20
    • Rajan's Blogs
Re: sql query while event creation
April 04, 2011, 09:35:38 pm
Mapping between drupal ( or cms ) user id with civicrm contacts stored in table 'civicrm_uf_match' where column 'uf_id' is nothing but drupal user Id and 'contact_id' is nothing but civicrm contact Id.
In 'civcrm_event' table, field 'created_id' specify the event creator contact id of that event.

I think using civicrm api will be more useful here.
Code: [Select]
<?php
global $user;
if ( !
module_exists('civicrm') || !$user->uid || !civicrm_initialize()) {
return;
}

require_once 
'api/v2/UFGroup.php'; 
require_once 
'api/v2/Event.php'; 

// get civicrm contact Id from drupal user id.
$civicrm_contact_id = civicrm_uf_match_id_get( $user->uid );

// Find events created by specified contact id.
$params = array( 'created_id' => $civicrm_contact_id );
$events = civicrm_event_search($params);

// Evens created by current logged in user ( array ).
print_r( $events );
?>



Hope this will help you.

Rajan

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: sql query while event creation
April 05, 2011, 03:38:36 am
I don't recommend you write new code using v2 api - you can backport v3 easily - see thread on this forum or the wiki

 http://wiki.civicrm.org/confluence/display/CRMDOC40/CiviCRM+Public+APIs

, here's the code below re-written to api v3

Code: [Select]
<?php
global $user;
if ( !
module_exists('civicrm') || !$user->uid || !civicrm_initialize()) {
return;
}

require_once 
'api/api.php'; 

// get civicrm contact Id from drupal user id.
$contact = civicrm_api('UFMatch','Get', array('version' =>3, 'uf_id' => $user->uid);

// Find events created by specified contact id.
$params = array( 'version' =>3, 'created_id' => $contact['values'][$contact['id']]['contact_id'] );
$events = civicrm_api('Event','Get',$params);

// Events created by current logged in user ( array ).
print_r( $events );
?>
« Last Edit: April 05, 2011, 03:41:44 am by Eileen »
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: sql query while event creation
April 05, 2011, 03:41:03 am
OR if you prefer (slightly less verbose)


Code: [Select]
<?php
global $user;
if ( !
module_exists('civicrm') || !$user->uid || !civicrm_initialize()) {
return;
}

require_once 
'api/api.php'; 

// get civicrm contact Id from drupal user id.
$contact = civicrm_api('UFMatch','Get', array('version' =>3, 'uf_id' => $user->uid, 'sequential' =>1);

// Find events created by specified contact id.
$events = civicrm_api('Event','Get', array( 'version' = > 3, 'created_id' => $contact['values'][0]['contact_id'] ));

// Events created by current logged in user ( array ).
print_r( $events );
?>
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

nmudgal

  • I post occasionally
  • **
  • Posts: 31
  • Karma: 0
    • It's Really Me
  • CiviCRM version: civicrm 3.3
  • CMS version: Drupal 6.20
  • MySQL version: mysql 5
  • PHP version: php 5
Re: sql query while event creation
April 05, 2011, 05:49:05 am
Cool thanks I forgot the power of apis :-) & reinvented wheel kinda!
GPG Key Fingerprint: 8B97 082A D923 2860 E0BE 3ED3 8F81 0702 6AE9 2A57

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • sql query while event creation

This forum was archived on 2017-11-26.