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) »
  • General Discussion (please no support requests here!) (Moderator: Michał Mach) »
  • how to add hook for civibooking
Pages: [1]

Author Topic: how to add hook for civibooking  (Read 706 times)

henro

  • I post occasionally
  • **
  • Posts: 115
  • Karma: -1
  • CiviCRM version: 4.5.0
  • CMS version: drupal
  • MySQL version: 4.2.7.1
  • PHP version: 5.2.0
how to add hook for civibooking
February 25, 2015, 07:08:21 pm
hi all ,
ho do i add hook for civibooking


appreciate for your suggestion

thanks henro tanjung

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: how to add hook for civibooking
February 26, 2015, 01:01:09 am
Henro,

can you expand on your question? What hook do you want to use? Do you mean what entity to use?
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

henro

  • I post occasionally
  • **
  • Posts: 115
  • Karma: -1
  • CiviCRM version: 4.5.0
  • CMS version: drupal
  • MySQL version: 4.2.7.1
  • PHP version: 5.2.0
Re: how to add hook for civibooking
February 26, 2015, 02:47:38 am
thanks erick,

so my case is :

i have 3 resources for booking :
1. room physioterapy
2. Bed A001
3. Chair 001

so, when room physioterapy has booked, bed A001 and chair 001 cannot be booking in the same time ( time for physioterapy booking ).

but if bed or chair already book, room physioterapy still can be booking

thanks again

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: how to add hook for civibooking
February 26, 2015, 04:05:39 am
I understand. So what do you want to do with what hook? Or do you want to create a new hook? I am not sure about the hook bit :-)
Do you want to add validation? You should use a hook civicrm_validateForm and check for the form name, see http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_validateForm.
You will need to find out what the formname is (the namespace of the class). You can do that by checking which file is used (should be something like CRM/Civibooking/Form/xxxxxxx.php meaning the form name is CRM_Civibooking_Form_xxxxxx), by setting the CiviCRM setting debug to Yes and then adding &smartyDebug=1 at the end of your URL (which brings up a separate window showing you all your form fields) OR by adding a debug at the beginning of the validateForm hook whilst you are at that form, and the refreshing the form.
Does it make sense?
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

henro

  • I post occasionally
  • **
  • Posts: 115
  • Karma: -1
  • CiviCRM version: 4.5.0
  • CMS version: drupal
  • MySQL version: 4.2.7.1
  • PHP version: 5.2.0
Re: how to add hook for civibooking
February 26, 2015, 04:13:55 am
thanks again erick  :)

here is a bit of my code

 
Quote
function myextension_civicrm_validateForm( $formName, &$fields, &$files, &$form, &$errors)

{
include "koneksi.php";                  
               $query = "select civicrm_booking.id as bookingid,
               
               civicrm_booking.start_date as datebooking
               from civicrm_booking
                   
               where civicrm_booking.id = 16";
               $exe = mysql_query($query);
               while($row = mysql_fetch_assoc($exe))
               {
               $booking = $row['bookingid'];
               $parent = $row['parent'];
               $start_date = $row['datebooking'];
               }
watchdog('myextension', print_r($fields, false), array(), WATCHDOG_DEBUG);
  drupal_set_message( '<b>TESTING: </b><pre>' . print_r($formName,1) . '</pre>');


if (($formName=='CRM_Booking_Form_SelectResource') || ($formName=='CRM_Booking_Form_SelectResource'))   {
 
     if ( $fields['event_start_date'] == $start_date ){
    $errors[$fields['event_start_date']] = ts('parent already book');
   
  }
  else{

  }
  }
  }
 
  return;

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: how to add hook for civibooking
February 26, 2015, 04:16:51 am
I do not know all the details of CiviBooking so I have no idea if you are evaluating the right fields? I find this hard to relate to the question 'how do I add a hook to CiviBooking' :-))))) ;D ;D ???
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: how to add hook for civibooking
February 26, 2015, 04:19:36 am
but I would recommend that you do not access the civicrm database directly but use this pattern:
Code: [Select]
$targetQuery = 'SELECT contact_id FROM civicrm_activity_contact WHERE activity_id = %1 AND record_type_id = %2';
$targetParams = array(
      1 => array($activityId, 'Integer'),
      2 => array(3, 'Integer'));
$daoTargets = CRM_Core_DAO::executeQuery($targetQuery, $targetParams);
while ($daoTargets->fetch()) {
     $targetContactNames[] = CRM_Costinvoicelink_Utils::getContactName($daoTargets->contact_id);
}

Does it make sense? That way your code will always work with whatever database or DB toolset CiviCRM uses, and you do not have to manage your own connections.
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

henro

  • I post occasionally
  • **
  • Posts: 115
  • Karma: -1
  • CiviCRM version: 4.5.0
  • CMS version: drupal
  • MySQL version: 4.2.7.1
  • PHP version: 5.2.0
Re: how to add hook for civibooking
March 03, 2015, 06:49:23 pm
thanks Erick
 :)

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • General Discussion (please no support requests here!) (Moderator: Michał Mach) »
  • how to add hook for civibooking

This forum was archived on 2017-11-26.