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 Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Default Profiles
Pages: [1] 2

Author Topic: Default Profiles  (Read 3916 times)

emilyf

  • Ask me questions
  • ****
  • Posts: 696
  • Karma: 54
  • CiviCRM version: 2.x - 4.x
  • CMS version: Drupal 5, 6, 7
Default Profiles
July 02, 2007, 09:34:47 am
I have a couple questions relating to profiles. First, on the CiviCRM wiki in relation to profiles, it says:
Check Profile if you want it to be used as the default search and listings screens for the civicrm/profile path.

So I assume this means I should check this box on a profile that I want to be the default return list after a search...?I have done this, but it's not overriding the default. The profile is listed in the advanced search area as an option for results display. Should this override the default or am I missing something?

Also, how can I change the default columns displaying when I go to the CiviMember and CiviEvent pages? Is this a simple task?

Thanks.

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Default Profiles
July 03, 2007, 11:09:26 pm
Quote
Check Profile if you want it to be used as the default search and listings screens for the civicrm/profile path.
This refers to Profile forms and listings - not the built-in "Find Contacts" and "Advanced Search" screens.

You can modify the Advanced Search results columns by marking a Profile as "Used For" => "Search Results" and then selectin g that profile in the Advanced Search form.

Changing the display columns on CiviMember and CiviEvent pages is probably non-trivial unless the data you want is already being "delivered" to the page templates. You can enable Debugging and then add &smartyDebug=1 to see what data is available in each row.
Protect your investment in CiviCRM by  becoming a Member!

emilyf

  • Ask me questions
  • ****
  • Posts: 696
  • Karma: 54
  • CiviCRM version: 2.x - 4.x
  • CMS version: Drupal 5, 6, 7
Re: Default Profiles
December 10, 2008, 06:57:53 am
Over a year later, I have another situation where I need to modify the default columns on the CiviMember dashboard. I want to replace the "Source" column with a custom data column of mine called "Member Town". I am on CiviCRM 2.1.

I enabled debugging, and unfortunately the {$rows} array doesn't include my custom data field. However, the {$form} array does. I'm trying to figure out how I could possibly access this or if it's even possible. Here's what an example $row looks like:

Code: [Select]
Array (3)
0 => Array (13)
  contact_id => "1"
  membership_id => "3"
  contact_type => "<img src="mysite"
  sort_name => "Frazier, Emily"
  membership_type_id => "Residence"
  join_date => "2008-12-10"
  membership_start_date => "2008-12-10"
  membership_end_date => null
  membership_source => "Georgia"
  status_id => "New"
  member_is_test => "0"
  checkbox => "mark_x_3"
  action => "<a href="mysite"

And here is my custom data fieldset in the $form array:

Code: [Select]
custom_2 => Array (9)
  name => "custom_2"
  value => null
  type => "select"
  frozen => false
  required => false
  error => null
  id => "custom_2"
  label => "<label for="custom_2">Member Town</la..."
  html => "<select size="5" multiple="multiple" ..."

Is there any way I can grab that value for the CRM/Member/Form/Selector.tpl ?? My custom data type is specific to memberships. Any insight greatly appreciated!
« Last Edit: December 10, 2008, 06:59:45 am by emilyf »

Kurund Jalmi

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4169
  • Karma: 128
    • CiviCRM
  • CiviCRM version: 4.x, future
  • CMS version: Drupal 7, Joomla 3.x
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Default Profiles
December 11, 2008, 05:18:16 am
This would involve considerable amount of changes to Membership search.
You will have to modify following files:
CRM/Member/Selector/Search.php
templates/CRM/Member/Form/Selector.tpl

Ping us on #civicrm if you get stuck.

Kurund
Found this reply helpful? Support CiviCRM

emilyf

  • Ask me questions
  • ****
  • Posts: 696
  • Karma: 54
  • CiviCRM version: 2.x - 4.x
  • CMS version: Drupal 5, 6, 7
Re: Default Profiles
December 15, 2008, 09:37:51 am
OK, making a little progress here....

In CRM/Member/Selector/Search.php

I adjusted the $_properties array in CRM_Member_Selector_Search class to now include my custom_2 fieldset, so now it looks like this (I replaced membership_source with my field):

Code: [Select]
    static $_properties = array( 'contact_id', 'membership_id',
                                 'contact_type',
                                 'sort_name',
                                 'membership_type_id',
                                 'join_date',
                                 'membership_start_date',
                                 'membership_end_date',
                                 'custom_2',
                                 'status_id',
                                 'member_is_test'
                                 );

then in this same file in function &getColumnHeaders() I also replaced the source field with
Code: [Select]
array(
                                                'name'      => ts('Town'),
                                                'sort'      => 'custom_2',
                                                'direction' => CRM_Utils_Sort::DONTCARE,
                                                ),

and then in the corresponding tpl file I replaced
Code: [Select]
    <td>{$row.membership_source}</td>
with
Code: [Select]
    <td>{$row.custom_2}</td>

However, I'm still not getting the right thing. Now in my selector column I get the options of that custom data set but it doesn't give me the selected values. See screenshot attached. How can I access the values properl? I assume I'm in need of a more complicated adjustment of the php file...advice?

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: Default Profiles
December 15, 2008, 09:50:26 am

can u add custom_2 to the properties array in:

CRM/Member/BAO/Query.php, function defaultReturnProperties( ) (line 289 or so)

is custom_2 a custom field of type Membership or Contact/Individual?

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

emilyf

  • Ask me questions
  • ****
  • Posts: 696
  • Karma: 54
  • CiviCRM version: 2.x - 4.x
  • CMS version: Drupal 5, 6, 7
Re: Default Profiles
December 15, 2008, 11:53:55 am
custom_2 is a multi-select alphanumeric option used for membership.

i added custom_2 to the page you suggested but do not see any difference with the debug arrays or in the selector...

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: Default Profiles
December 15, 2008, 12:09:23 pm

in that case, u'll need to start digging a bit through the code and figure out what needs to change for the query to return custom_2

ping me on irc later this week and i can help out (a bit busy first part of the week with the 2.2 deadline)

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

emilyf

  • Ask me questions
  • ****
  • Posts: 696
  • Karma: 54
  • CiviCRM version: 2.x - 4.x
  • CMS version: Drupal 5, 6, 7
Re: Default Profiles
December 19, 2008, 10:00:59 am
actually,i do appear to be pulling the data correctly (YES!!!!). But it's formatting it oddly. I also checked my custom_value table and the odd formatting is in that table, too. I wonder if this is because it's a mutli-select custom field?? I'm attaching a screenshot of how this field ends up looking on my membership summary. This same formatting is in the table itself. How can I replace/reformat the display??

emilyf

  • Ask me questions
  • ****
  • Posts: 696
  • Karma: 54
  • CiviCRM version: 2.x - 4.x
  • CMS version: Drupal 5, 6, 7
Re: Default Profiles
December 19, 2008, 10:51:56 am
GOT IT PEOPLE. This is excellent. So the whole process is as follows:

- As Kurund mentioned, I needed to modify these files:
CRM/Member/Selector/Search.php
templates/CRM/Member/Form/Selector.tpl

and add my 'custom_2' to the $properties array, $columnHeaders and the tpl file row (see my above post on how I did all that)

- As Lobo mentioned, I needed to modify CRM/Member/BAO/Query.php, function defaultReturnProperties( ) to include my custom_2 field

Then, in fact it is returning what I needed. But since it's a multi-select field, the display formatting was all funky and I needed to use CRM/Core/BAO/CustomField.php
function getDisplayValue

to properly format it. This function looks like this (just including it to show the parameters it needs):
Code: [Select]
  /**
     * Given a custom field value, its id and the set of options
     * find the display value for this field
     *
     * @param mixed  $value     the custom field value
     * @param int    $id        the custom field id
     * @param int    $options   the assoc array of option name/value pairs
     *
     * @return  string   the display value
     *
     * @static
     * @access public
     */
    static function getDisplayValue( $value, $id, &$options, $contactID = null )

So then I was trying to call this function on my field directly from CRM/Member/BAO/Query.php but couldn't get the third parameter to work. Lobo directed me back to CRM/Member/Selector/Search.php and told me that the query object I needed was available in the getRows function (would have been stuck for hours without this pointer). Once in there, it was very easy to access what I needed as Lobo had also previously mentioned to me that query objects are usually supposed to have _options associated with it. So I simply added the following line (any $row modification just needs to be within the while loop around line 326):

Code: [Select]
             $row['custom_2'] = CRM_Core_BAO_CustomField::getDisplayValue($row['custom_2'], 2, $this->_query->_options);

Voila! Beautiful displaying custom fields on my membership dashboard. This is VERY exciting! hopefully it will help someone else. Thanks so much Kurund and Lobo for all the help.

emilyf

  • Ask me questions
  • ****
  • Posts: 696
  • Karma: 54
  • CiviCRM version: 2.x - 4.x
  • CMS version: Drupal 5, 6, 7
Re: Default Profiles
December 19, 2008, 12:44:43 pm
OK, next step. I need to also modify the membership tab on every contact to show my custom field (instead of the source field). i was talking with lobo on irc, and we determined that I need to modify the browse() of CRM/Member/Page/Tab.php.

We also determined that the easiest route will be to write a query returning the correct values for my custom field and then  just add that in to the $membership array which in turn gets added into the $activeMembers array which is called on the template file. OK, so here's where my trouble begins. I wrote my query, and I think I'm doing it properly, but I get 'sorry, an error occurred' on the membership tab. Not very helpful. can someone have a look at this query code below and tell me what i've done wrong (i know i will still have to properly format my display, but first i just want to return something!!). i am adding the code below to line 120 of the browse() function.
Code: [Select]
  <?php

        $sql 
= "SELECT members_town_2 
FROM civicrm_value_member_town_1 mt
LEFT JOIN civicrm_membership m ON (m.id = mt.entity_id)
WHERE m.contact_id = '"
$dao->contact_id."'";
        
        
$dao_cus = CRM_Core_DAO::executeQuery( $sql,
                                           
CRM_Core_DAO::$_nullArray );
        
        while ( 
$dao_cus->fetch( ) ){     
          
$membership[$dao->id]['custom_2'] = $dao_cus->members_town_2;
        }
?>

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: Default Profiles
December 19, 2008, 01:59:36 pm

there is an error in your sql clause. firebug is your friend to detect such errrors. A valid version of the clause is:

Code: [Select]
$sql = "SELECT members_town_2
FROM civicrm_value_member_town_1 mt
LEFT JOIN civicrm_membership m ON (m.id = mt.entity_id)
WHERE m.contact_id = {$dao->contact_id}";
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: Default Profiles
December 19, 2008, 07:37:47 pm
Quote from: emilyf on December 19, 2008, 10:51:56 am
Voila! Beautiful displaying custom fields on my membership dashboard. This is VERY exciting! hopefully it will help someone else. Thanks so much Kurund and Lobo for all the help.
Emily - can you paste an image of this beautiful profile. I presume it is displaying each of the town options the person has chosed as checked?
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

emilyf

  • Ask me questions
  • ****
  • Posts: 696
  • Karma: 54
  • CiviCRM version: 2.x - 4.x
  • CMS version: Drupal 5, 6, 7
Re: Default Profiles
December 22, 2008, 07:41:35 am
two more questions and i think this will be solved. first -- lobo i don't see where in firebug this would come up. there are no errors in the error console related to this file. am i looking in the wrong place?

second, yes, that query change resolved and now i'm getting my results, which brings me back to the need to format it. I am again having trouble with the third $options parameter CRM_Core_BAO_CustomField::getDisplayValue. How do I set options on my custom query? I don't understand exactly how this works or what it does. Is it built in somehow? Ideally my final code would look like this except the result is not formatting correctly:
Code: [Select]
$sql = "SELECT members_town_2
FROM civicrm_value_member_town_1 mt
LEFT JOIN civicrm_membership m ON (m.id = mt.entity_id)
WHERE m.contact_id = '{$dao->contact_id}'";
       
        $dao_cus = CRM_Core_DAO::executeQuery( $sql,
                                           CRM_Core_DAO::$_nullArray );
       
        while ( $dao_cus->fetch( ) ){     
          $membership[$dao->id]['custom_2'] =  CRM_Core_BAO_CustomField::getDisplayValue($dao_cus->members_town_2, 2, $dao_cus->_options);
        }

peterd - posting a screenshot of my membership dashboard. yes, it's working as you suggest.

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: Default Profiles
December 22, 2008, 11:29:07 am
Thanks Emily. So this is in civiMember - I'm curious whether what you have done steps around a Custom Search? I.e. if you run this search, get the results as demonstrated, and export it, does the custom data field = TOWN get included in the Export?
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

Pages: [1] 2
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Default Profiles

This forum was archived on 2017-11-26.