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 new Tokens for date access
Pages: [1]

Author Topic: Implementing new Tokens for date access  (Read 649 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
Implementing new Tokens for date access
December 11, 2012, 02:26:12 am
I have tried turning on Smarty so that I could use the smarty date token {$smarty.now} but try as I might I cannot get it to create a date in a PDF generated from a Thank You letter template.

So, I am now looking to implement the example date Tokens (ie  'date.date_short' etc) in the following example.

http://wiki.civicrm.org/confluence/display/CRMDOC42/Hook+Reference#HookReference-hook_civicrm_tokens

But having read the documentation I am no wiser as to where abouts in the CiviCRM/Joomla directory structure I am to put the code and what code is needed around this example for full implementation.

Can anyone help me?

regards
Simon

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 new Tokens for date access
December 11, 2012, 03:11:24 am
Hi,
I would recommend to implement that using the new native civicrm extension, civix is a really nice tool to create the structure and codes for a new extension

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

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: Implementing new Tokens for date access
December 11, 2012, 11:32:53 am
X+,

Thanks.

I have seen this: http://wiki.civicrm.org/confluence/display/CRMDOC42/Create+an+Extension so will have a read and reply if need be.

Following through to the Extensions forum lead me to your reply to a post:

> Read this chapter in our book, should get you started:
> http://en.flossmanuals.net/civicrm/ch067_hooks/

This then presented me with:

> Custom mail merge token

With the example being for "Drupal syntax" but I am on Joomla. Is there much difference?

Also, the example doesn't provide a link to how to package and install the example. I followed links and arrived at:

http://wiki.civicrm.org/confluence/display/CRMDOC42/Hook+Reference

Here it seems to indicate that Joomla and Drupal hooks differently. But then I ended up at:

http://wiki.civicrm.org/confluence/display/CRMDOC42/Create+a+Module+Extension

Which seems to have what I need but I need to have my hosting company install the civix command line module.

If I don't use an extension, I think this is what I need to do:

http://wiki.civicrm.org/confluence/display/CRMDOC42/Example+Joomla+Plugin+for+implementing+hooks

So, would the code look like?:


<?php
/**
 * @version
 * @package     Civicrm
 * @subpackage  Joomla Plugin
 * @copyright   Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */
 
// No direct access
defined('_JEXEC') or die;
 
jimport('joomla.plugin.plugin');
class plgCivicrmTabs extends JPlugin
{
  function hook_civicrm_tokens(&$tokens) {
    $tokens['date'] = array(
      'date.date_short' => 'Today\'s Date: mm/dd/yyyy',
      'date.date_med' => 'Today\'s Date: Mon d yyyy',
      'date.date_long' => 'Today\'s Date: Month dth, yyyy',
    );
  }

  function hook_civicrm_tokenValues(&$values, $cids, $job = null, $tokens = array(), $context = null) {
    // Date tokens
    if (!empty($tokens['date'])) {
      $date = array(
        'date.date_short' => date('m/d/Y'),
        'date.date_med' => date('M j Y'),
        'date.date_long' => date('F jS, Y'),
      );
      foreach ($cids as $cid) {
        $values[$cid] = empty($values[$cid]) ? $date : $values[$cid] + $date;
      }
    }
  }
}


PS My customer has 4.2.6 installed.

regards
Simon

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

This forum was archived on 2017-11-26.