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) »
  • Views 2 integration - website field
Pages: [1]

Author Topic: Views 2 integration - website field  (Read 1471 times)

ericaordinary

  • Guest
Views 2 integration - website field
August 09, 2010, 05:01:12 pm
I hacked around a bit with the civicrm.views.inc file to get the website field displaying in views integration.  It seems to be working OK for me, but feel free to make any comments or changes.  This won't let me attach files, so the code is below.

Code I added into the civicrm.views.inc file

Code: [Select]
// CIVICRM_WEBSITE TABLE

    $data['civicrm_website']['table']['group']  = t('CiviCRM Website');

    // Explain how this table joins to others.
    $data['civicrm_website']['table']['join'] = array(
                                                    // Directly links to contact table.
                                                    'civicrm_contact' => array(
                                                                               'left_field' => 'id',
                                                                               'field' => 'contact_id',
                                                                               ),
                                                    );

    //CiviCRM Website Using Contacts as a pitstop before going on to Participants
    $data['civicrm_website']['table']['join']['civicrm_participant'] = array(
                                                                           'left_table' => 'civicrm_contact',
                                                                           'left_field' => 'id',
                                                                           'field' => 'contact_id',
                                                                           );

    //CiviCRM Website Using Contacts as a pitstop before going on to Contributions
    $data['civicrm_website']['table']['join']['civicrm_contribution'] = array(
                                                                            'left_table' => 'civicrm_contact',
                                                                            'left_field' => 'id',
                                                                            'field' => 'contact_id',
                                                                            );

    //CiviCRM Website Using Contacts as a pitstop before going on to Activities
    $data['civicrm_website']['table']['join']['civicrm_activity'] = array(
                                                                        'left_table' => 'civicrm_contact',
                                                                        'left_field' => 'id',
                                                                        'field' => 'contact_id',
                                                                        );

    //CiviCRM Website Using Locations as a pitstop before going on to Events
    $data['civicrm_website']['table']['join']['civicrm_event'] = array(
                                                                     'left_table' => 'civicrm_loc_block',
                                                                     'left_field' => 'email_id',
                                                                     'field' => 'id',
                                                                     );
   //CiviCRM Website Using Contacts as a pitstop before going on to Memberhsips
    $data['civicrm_website']['table']['join']['civicrm_membership'] = array(
                                                                     'left_table' => 'civicrm_contact',
                                                                     'left_field' => 'id',
                                                                     'field' => 'contact_id',
                                                                     );

   
   //Display Website in User Views
    $data['civicrm_website']['table']['join']['users'] = array(
           'left_table'   => 'civicrm_uf_match',
           'left_field'   => 'contact_id',
           'field'        => 'contact_id',
    );

    //WEBSITE'S LOCATION TYPE
    $data['civicrm_website']['location_type'] = array(
                                                    'title' => t('Website Type'),
                                                    'real field' => 'website_type_id',
                                                    'help' => t('The type of website for the Contact'),
                                                    'field' => array(
                                                                     'handler' => 'civicrm_handler_field_location_type',
                                                                     'click sortable' => TRUE,
                                                                     ),

                                                    'argument' => array(
                                                                        'handler' => 'views_handler_argument',
                                                                        ),

                                                    'filter' => array(
                                                                      'handler' => 'civicrm_handler_filter_location_type',
                                                                      'allow empty' => TRUE,
                                                                      ),

                                                    'sort' => array(
                                                                    'handler' => 'views_handler_sort',
                                                                    ),
                                                    );


    //FULL WEBSITE
    $data['civicrm_website']['website'] = array(
                                            'title' => t('Website'),
                                            'help' => t('Full website address'),
                                            'real field' => 'url',
                                            'field' => array(
                                                             'handler' => 'civicrm_handler_field_website',
                                                             'click sortable' => TRUE,
                                                             ),

                                            'argument' => array(
                                                                'handler' => 'views_handler_argument',
                                                                ),

                                            'filter' => array(
                                                              'handler' => 'views_handler_filter_string',
                                                              'allow empty' => TRUE,
                                                              ),

                                            'sort' => array(
                                                            'handler' => 'views_handler_sort',
                                                            ),
                                            );


And this line in the Field Handlers section of the file:

Code: [Select]
                       'civicrm_handler_field_website' => array(
                                                              'parent' => 'views_handler_field_url',
                                                              ),

And this is the code for the civicrm_handler_field_website.inc file I created:

Code: [Select]
<?php
/*
 +--------------------------------------------------------------------+
 | CiviCRM version 3.1                                                |
 +--------------------------------------------------------------------+
 | This file is a part of CiviCRM.                                    |
 |                                                                    |
 | CiviCRM is free software; you can copy, modify, and distribute it  |
 | under the terms of the GNU Affero General Public License           |
 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
 |                                                                    |
 | CiviCRM is distributed in the hope that it will be useful, but     |
 | WITHOUT ANY WARRANTY; without even the implied warranty of         |
 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
 | See the GNU Affero General Public License for more details.        |
 |                                                                    |
 | You should have received a copy of the GNU Affero General Public   |
 | License and the CiviCRM Licensing Exception along                  |
 | with this program; if not, contact CiviCRM LLC                     |
 | at info[AT]civicrm[DOT]org. If you have questions about the        |
 | GNU Affero General Public License or the licensing of CiviCRM,     |
 | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
 +--------------------------------------------------------------------+
*/
/*
 * Unchanged anonymous code contribution. No claim.
 *
 * civicrm_handler_field_website.inc
 * Displays Website address and links to website address.
 *
 */
/**
 * Field handler to provide acess control for the website field
 *
 * @ingroup civicrm_field_handlers
 */
class civicrm_handler_field_website extends views_handler_field {
  function 
option_definition() {
    
$options = parent::option_definition();

    
$options['display_as_link'] = array('default' => TRUE);

    return 
$options;
  }

  
/**
   * Provide link to the page being visited.
   */
  
function options_form(&$form, &$form_state) {
    
parent::options_form($form, $form_state);
    
$form['display_as_link'] = array(
      
'#title' => t('Display as link'),
      
'#type' => 'checkbox',
      
'#default_value' => !empty($this->options['display_as_link']),
    );
  }

  function 
render($values) {
    
$value = $values->{$this->field_alias};
    if (!empty(
$this->options['display_as_link'])) {
      return 
l(check_plain($value), $value, array('html' => TRUE));
    }
    else {
      return 
check_url($value);
    }
  }
}
?>


Cheers,
Erica.

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: Views 2 integration - website field
August 09, 2010, 06:06:03 pm

erica:

congrats on submitting a patch :)

Andrew H had filed an issue and a patch sometime back. Can you please download and test his patch available here:

http://issues.civicrm.org/jira/browse/CRM-6566

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

ericaordinary

  • Guest
Re: Views 2 integration - website field
August 09, 2010, 06:35:53 pm
Aww, you mean it was already fixed?  It was a good learning experience anyhow.

ericaordinary

  • Guest
Re: Views 2 integration - website field
August 09, 2010, 07:50:49 pm
I just tried out Andrew H's patch but it doesn't output the URL as a link, which my patch does.  I think I used up all my brain power creating my own patch, because I can't work out how to modify Andrew's patch (which is slightly different to mine) so that it does output the URL as a link.  For now I've reverted back to my own patch, and perhaps someone else can work out which is the better approach of the two and mesh them into one super-patch.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Drupal Modules (Moderator: Donald Lobo) »
  • Views 2 integration - website field

This forum was archived on 2017-11-26.