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) »
  • Support »
  • Using CiviCRM »
  • Using Drupal Modules (Moderator: Donald Lobo) »
  • Views2 date arguments not working
Pages: [1]

Author Topic: Views2 date arguments not working  (Read 3636 times)

jalama

  • I post frequently
  • ***
  • Posts: 176
  • Karma: 22
    • Rooty Hollow LLC
  • CiviCRM version: 3.3.5
  • CMS version: Drupal 6 and 7
  • MySQL version: 5.1
  • PHP version: 5.2.5 and 5.3
Views2 date arguments not working
April 12, 2009, 08:07:38 am
I noticed that the date arguments are not working in views2.  The error is the where part of the SQL statement has no field ie WHERE = '2009-08-01' in lieu of WHERE start_date = '2009-08-01'.  All the date arguments call the views_handler_argument_date which requires more pre-formatting before it can be executed.

I put together a handler, pasted in below, based on the node views date handler.  I would like to clean up the code a bit by minimizing the # of distinct handlers a little before submitting a patch.  Currently, you can expose 6 arguments per field, full date (YYYYMMDD), Year Month (YYYYMM), Year (YYYY), Day (DD), Month (MM), Week (WW).  I think I can combine the first 3, or at least the first 2, into one handler that determines which parameter is being passed into the argument based on the length of the argument's string.

If I'm correct and I didn't miss something.  Do you think it makes sense to have the date argument in all 18 date fields exposed in the views2 module? I don't mind putting together the code for all 18, but think it may be a bit of overkill.  The fields that seem the biggest priority are the event dates (start_date, end date), birth date, membership dates (start & end and maybe renewal dates), activity dates?

current handler code I have in file called drupal/modules/views/civicrm/views_handler_argument_civicrm_dates_various.inc
Code: [Select]
<?php
// $Id: views_handler_argument_dates_various.inc,v 1.4 2009/01/08 00:25:19 merlinofchaos Exp $
/**
 * Argument handler for a full date (CCYYMMDD)
 */
class views_handler_argument_civicrm_fulldate extends views_handler_argument_date {
  
/**
   * Constructor implementation
   */
  
function construct() {
    
parent::construct();
    
$this->format = 'F j, Y';
    
$this->arg_format = 'Ymd';
    
$this->formula = views_date_sql_format($this->arg_format, "***table***.$this->real_field", "datetime");
  }

  
/**
   * Provide a link to the next level of the view
   */
  
function summary_name($data) {
    
$created = $data->{$this->name_alias};
    return 
format_date(strtotime($created), 'custom', $this->format, 0);
  }

  
/**
   * Provide a link to the next level of the view
   */
  
function title() {
    return 
format_date(strtotime($this->argument), 'custom', $this->format, 0);
  }
}

/**
 * Argument handler for a year (CCYY)
 */
class views_handler_argument_civicrm_year extends views_handler_argument_date {
  
/**
   * Constructor implementation
   */
  
function construct() {
    
parent::construct();
    
$this->arg_format = 'Y';
    
$this->formula = views_date_sql_extract('YEAR', "***table***.$this->real_field","datetime");
  }
}

/**
 * Argument handler for a year plus month (CCYYMM)
 */
class views_handler_argument_civicrm_year_month extends views_handler_argument_date {
  
/**
   * Constructor implementation
   */
  
function construct() {
    
parent::construct();
    
$this->format = 'F Y';
    
$this->arg_format = 'Ym';
    
$this->formula = views_date_sql_format($this->arg_format, "***table***.$this->real_field","datetime");
  }

  
/**
   * Provide a link to the next level of the view
   */
  
function summary_name($data) {
    
$created = $data->{$this->name_alias};
    return 
format_date(strtotime($created . "15"), 'custom', $this->format, 0);
  }

  
/**
   * Provide a link to the next level of the view
   */
  
function title() {
    return 
format_date(strtotime($this->argument . "15"), 'custom', $this->format, 0);
  }
}

/**
 * Argument handler for a month (MM)
 */
class views_handler_argument_civicrm_month extends views_handler_argument_date {
  
/**
   * Constructor implementation
   */
  
function construct() {
    
parent::construct();
    
$this->formula = views_date_sql_extract('MONTH', "***table***.$this->real_field","datetime");
    
$this->format = 'F';
    
$this->arg_format = 'm';
  }

  
/**
   * Provide a link to the next level of the view
   */
  
function summary_name($data) {
    
$month = str_pad($data->{$this->name_alias}, 2, '0', STR_PAD_LEFT);
    return 
format_date(strtotime("2005" . $month . "15"), 'custom', $this->format);
  }

  
/**
   * Provide a link to the next level of the view
   */
  
function title() {
    
$month = str_pad($this->argument, 2, '0', STR_PAD_LEFT);
    return 
format_date(strtotime("2005" . $month . "15"), 'custom', $this->format, 0);
  }

  function 
summary_argument($data) {
    
// Make sure the argument contains leading zeroes.
    
return str_pad($data->{$this->base_alias}, 2, '0', STR_PAD_LEFT);
  }
}

/**
 * Argument handler for a day (DD)
 */
class views_handler_argument_civicrm_day extends views_handler_argument_date {
  
/**
   * Constructor implementation
   */
  
function construct() {
    
parent::construct();
    
$this->formula = views_date_sql_extract('DAY', "***table***.$this->real_field","datetime");
    
$this->format = 'j';
    
$this->arg_format = 'd';
  }

  
/**
   * Provide a link to the next level of the view
   */
  
function summary_name($data) {
    
$day = str_pad($data->{$this->name_alias}, 2, '0', STR_PAD_LEFT);
    return 
format_date(strtotime("2005" . "05" . $day), 'custom', $this->format, 0);
  }

  
/**
   * Provide a link to the next level of the view
   */
  
function title() {
    
$day = str_pad($this->argument, 2, '0', STR_PAD_LEFT);
    return 
format_date(strtotime("2005" . "05" . $day), 'custom', $this->format, 0);
  }

  function 
summary_argument($data) {
    
// Make sure the argument contains leading zeroes.
    
return str_pad($data->{$this->base_alias}, 2, '0', STR_PAD_LEFT);
  }
}

/**
 * Argument handler for a week.
 */
class views_handler_argument_civicrm_week extends views_handler_argument_date {
  
/**
   * Constructor implementation
   */
  
function construct() {
    
parent::construct();
    
$this->arg_format = 'w';
    
$this->formula = views_date_sql_extract('WEEK', "***table***.$this->real_field","datetime");
  }

  
/**
   * Provide a link to the next level of the view
   */
  
function summary_name($data) {
    
$created = $data->{$this->name_alias};
    return 
t('Week @week', array('@week' => $created));
  }
}
http://www.rootyhollow.com

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Views2 date arguments not working
April 12, 2009, 05:58:49 pm
Hey - great to see someone sorting this out. In addition to the obvious start and end dates for events the other dates that would be really useful to us are profile dates created as a multi field. I want to use this to create a set of dates against each funding organisation relating to their grant rounds
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

jalama

  • I post frequently
  • ***
  • Posts: 176
  • Karma: 22
    • Rooty Hollow LLC
  • CiviCRM version: 3.3.5
  • CMS version: Drupal 6 and 7
  • MySQL version: 5.1
  • PHP version: 5.2.5 and 5.3
Re: Views2 date arguments not working
April 13, 2009, 05:50:45 am
If I'm not mistaken custom fields are supported by this function, civicrm_views_add_fields, which has no argument handler.  Am I correct here?  I could see adding one if the field type is date as dates are pretty generic.  In other words that make be feasible.
http://www.rootyhollow.com

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Views2 date arguments not working
April 13, 2009, 06:58:07 am

civicrm_views_custom_data_cache

is the function that adds the custom data fields to the data definition

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

jalama

  • I post frequently
  • ***
  • Posts: 176
  • Karma: 22
    • Rooty Hollow LLC
  • CiviCRM version: 3.3.5
  • CMS version: Drupal 6 and 7
  • MySQL version: 5.1
  • PHP version: 5.2.5 and 5.3
Re: Views2 date arguments not working
April 13, 2009, 08:17:15 am
Given their unique nature does it make sense to add a function that add the arguments for date fields?  In other words if $currentfield['data_type'] = 'date' then run a function to add the arguments to $data before it gets returned from civicrm_views_custom_data_cache function.  This could be used to populate the date argument fields for custom fields and any other date fields.
http://www.rootyhollow.com

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Views2 date arguments not working
April 13, 2009, 10:04:37 am

yes, that makes sense and that function should be able to handle different date formats. wanna do it and submit a patch

thanx

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

jalama

  • I post frequently
  • ***
  • Posts: 176
  • Karma: 22
    • Rooty Hollow LLC
  • CiviCRM version: 3.3.5
  • CMS version: Drupal 6 and 7
  • MySQL version: 5.1
  • PHP version: 5.2.5 and 5.3
Re: Views2 date arguments not working
April 13, 2009, 10:24:55 am
Sure

Though I'm not quite following the format issue.  can you elaborate?
http://www.rootyhollow.com

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Views2 date arguments not working
April 13, 2009, 10:30:48 am

civicrm dates are configurable by the user and some are implicit in the system. Some are date and time, while others are date only. Would be good to propagate this information to views, so that only the appropriate elements are rendered etc. To begin with we can display all elements and then tweak it as needed

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

jalama

  • I post frequently
  • ***
  • Posts: 176
  • Karma: 22
    • Rooty Hollow LLC
  • CiviCRM version: 3.3.5
  • CMS version: Drupal 6 and 7
  • MySQL version: 5.1
  • PHP version: 5.2.5 and 5.3
Re: Views2 date arguments not working
April 13, 2009, 01:13:05 pm
Sorry I think I'm being a little dense here, but how would that info be useful to a views argument handler?

Either way, determining formats date v datetime should be easy, but how would one tell programaticly which are implicit v user configurable?
http://www.rootyhollow.com

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Views2 date arguments not working
April 13, 2009, 02:23:38 pm

might be easier to have this conversation on IRC

My views knowledge is a bit limited, so i dont know the various date formats that views accepts. I suspect it accepts a few different type of formats, and my main point was we should try to let views know what format we are using, to be more specific:

birth_date is a date field only
start_date is a datetime field

all custom date fields have a date_parts / start_date / end_date which control the date display and format

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Drupal Modules (Moderator: Donald Lobo) »
  • Views2 date arguments not working

This forum was archived on 2017-11-26.