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) »
  • Worked Example Hook Joomla not Drupal: hook_civicrm_post
Pages: [1]

Author Topic: Worked Example Hook Joomla not Drupal: hook_civicrm_post  (Read 1227 times)

sggreener

  • I post occasionally
  • **
  • Posts: 35
  • Karma: 0
    • The SpatialDB Advisor
  • CiviCRM version: 4.6.15
  • CMS version: Joomla 5.5.1
  • MySQL version: 5.6.29
  • PHP version: 5.3.8
Worked Example Hook Joomla not Drupal: hook_civicrm_post
November 17, 2013, 01:02:57 am
I've had a look at the API documentation and can't seem to work out how to implement a hook for Joomla.

Can anyone point me to a reasonably complete example of a Joomla (not Drupal) hook that would allow me to:

1. Use hook_civicrm_post to detect a create or update of an Individual's address in the database;
2. Use data from the new/changed address to execute a SQL query against a MySQL table (worked example of how to use BAO rather than native SQL - I am comfortable with all things SQL and not PHP);
3. Computes new values from the data of 1 and 2;
4. Assigns the calculated values to custom fields.
5. Outlines how to install the hook and test it.

If there are no reasonably compete examples around, then a template hook that does all I want so I can fill in the blanks.

regards
Simon

sggreener

  • I post occasionally
  • **
  • Posts: 35
  • Karma: 0
    • The SpatialDB Advisor
  • CiviCRM version: 4.6.15
  • CMS version: Joomla 5.5.1
  • MySQL version: 5.6.29
  • PHP version: 5.3.8
Re: Worked Example Hook Joomla not Drupal: hook_civicrm_post
November 18, 2013, 01:49:14 am
I have 30 years experience in the IT industry.

I am not afraid of new technologies, but I find the documentation of the APIs of Joomla and CiviCRM not easy to follow.

I don't want to spend days hacking and using "trial and error" to get a result.

If anyone is interested I am willing to PAY for such a hook to be created. I will provide a fuller description to anyone interested in providing me with a working hook to my specifications.

simon at spatialdbadvisor dot com

regards
Simon

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Worked Example Hook Joomla not Drupal: hook_civicrm_post
November 18, 2013, 02:12:54 am
Hi,

If you are pretty clear about the sql you want to use you might want to try using a mysql trigger - e.g if you look at this extension (which you can easily download, install & modify). As it is an civicrm native extension it should be CMS-agnostic.

https://github.com/eileenmcnaughton/nz.co.fuzion.regionfields

The code is the function

https://github.com/eileenmcnaughton/nz.co.fuzion.regionfields/blob/master/regionfields.php#L85

& the query enacted is

https://github.com/eileenmcnaughton/nz.co.fuzion.regionfields/blob/master/regionfields.php#L97

The trigger simply updates a (hard-coded) custom field based on a lookup in a table that exists in this particular DB. Although I haven't played with it in theory both old & new values are available to you as if they were in the tables aliased in 'old' & 'new'.


The value of doing a trigger this way as opposed to just creating it in your DB is that CiviCRM re-instates it after upgrades etc & integrates it with any other triggers on that table

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

sggreener

  • I post occasionally
  • **
  • Posts: 35
  • Karma: 0
    • The SpatialDB Advisor
  • CiviCRM version: 4.6.15
  • CMS version: Joomla 5.5.1
  • MySQL version: 5.6.29
  • PHP version: 5.3.8
Re: Worked Example Hook Joomla not Drupal: hook_civicrm_post
November 18, 2013, 08:47:54 pm
Eileen,

Thank you for taking the time to reply.

My preferred method is to use a trigger BUT the version of MySQL that my client is using does not provide the functionality that I need to implement a trigger. I need MySQL 5.6 or above. The shared hosting environment that my client uses cannot provide a 5.6 MySQL database for a indeterminate amount of time, hence am forced to look at a solution that uses a hook and a library of Python functions.

regards
SImon

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Worked Example Hook Joomla not Drupal: hook_civicrm_post
November 18, 2013, 11:25:13 pm
hmm - have you considered investing your $$ in switching to something like civihosting which provides civi-suitable shared hosting for very reasonable $$$?
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

sggreener

  • I post occasionally
  • **
  • Posts: 35
  • Karma: 0
    • The SpatialDB Advisor
  • CiviCRM version: 4.6.15
  • CMS version: Joomla 5.5.1
  • MySQL version: 5.6.29
  • PHP version: 5.3.8
Re: Worked Example Hook Joomla not Drupal: hook_civicrm_post
November 19, 2013, 01:43:39 am
Eileen,

My customer uses CiviHosting. They cannot host more than one MySQL at a time. I have contacted them and checked. In fact, I have been checking for over a year+. I need to get this functionality implemented. I have no other option than a hook.

regards
SImon

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Worked Example Hook Joomla not Drupal: hook_civicrm_post
November 19, 2013, 04:13:11 am
Quote from: sggreener on November 18, 2013, 08:47:54 pm
My preferred method is to use a trigger BUT the version of MySQL that my client is using does not provide the functionality that I need to implement a trigger. I need MySQL 5.6 or above.

Quote from: sggreener on November 19, 2013, 01:43:39 am
My customer uses CiviHosting.

To clarify this situation, the feature sggreener is looking for is not simple a MySQL trigger. That of course is available in MySQL 5.5, which is what CiviHosting provides as of this writing. sggreener needs what is called a "point in polygon" operation, which is a function required for geospatial calculations. This unique feature is available only in MySQL 5.6+ however.

Thus sggreener must resort to a PHP-based hook so that he can execute PHP or Python code to achieve this functionality.

Anyhow, sggreener, there are examples here:

http://wiki.civicrm.org/confluence/display/CRMDOC42/Example+Joomla+Plugin+for+implementing+hooks
https://civicrm.org/blogs/mcsmom/hooks-and-joomla

and to execute your own SQL, this code works (in Drupal at least):

Code: [Select]
  require_once "CRM/Core/DAO.php";
  $sql = "SELECT something OR UPDATE something etc.";
  $dao =& CRM_Core_DAO::executeQuery($sql);
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

sggreener

  • I post occasionally
  • **
  • Posts: 35
  • Karma: 0
    • The SpatialDB Advisor
  • CiviCRM version: 4.6.15
  • CMS version: Joomla 5.5.1
  • MySQL version: 5.6.29
  • PHP version: 5.3.8
Re: Worked Example Hook Joomla not Drupal: hook_civicrm_post
November 19, 2013, 02:34:10 pm
Hershel,

Thanks for adding the clarification re MySQL 5.6.

The second hook URL example is better than most I have seen: I will have a look at it.

regards
Simon

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Worked Example Hook Joomla not Drupal: hook_civicrm_post
November 19, 2013, 03:04:45 pm
That require_once is no longer required in the example
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

lcdweb

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1620
  • Karma: 116
    • www.lcdservices.biz
  • CiviCRM version: many versions...
  • CMS version: Joomla/Drupal
  • MySQL version: 5.1+
  • PHP version: 5.2+
Re: Worked Example Hook Joomla not Drupal: hook_civicrm_post
November 23, 2013, 08:23:55 pm
little late to this discussion --
but did you look on the wiki? http://wiki.civicrm.org/confluence/display/CRMDOC/Joomla%21+Extensions+for+CiviCRM+%283rd+party%29

there is a "base plugin" that can be used as a starting point for implementing hooks via a joomla plugin. it may need to be dusted off a bit, but should get you going.
support CiviCRM through 'make it happen' initiatives!
http://civicrm.org/mih

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Worked Example Hook Joomla not Drupal: hook_civicrm_post

This forum was archived on 2017-11-26.