Jump to content

Working with profile fields in settings


Recommended Posts

So I utilize profile fields in one instance in a template hook and one instance in a widget.

For the template hook I've created a select setting in the setting area for my app which lists all the profile fields of type URL. On the frontend this creates a link (if that URL profile field is set for the member) beneath their content with that target.

For the widget (which is a list of members) I intend to do pretty much the same. I've created a widget setting that also lists all profile fields of type URL. If that widget setting is set, the idea is that instead of having the member name link go to their profile, it will go to the target of the profile field URL. 

My problem with this, is that there is no simple way for me to simply pass in the profile field ID and have the raw data of the profile field (the raw data being the url target) returned. 

First problem: 

$member->profileFields() returns an array that consists of the profile field groups, which is not something I need or know the value of. Meaning I would have to loop through all the profile field groups in order to find my value.  

Second problem:

You return the URL already inside an <a>-element, which I can't use. I need to be able to create the <a>-element myself, to have the member name as the title.


Currently I have the following code in the widget for the setting: 

		$urlProfileFields = \IPS\Db::i()->select('*', 'core_pfields_data', array("pf_type='Url'") );
		$profileField_select = array();
		$profileField_select[ 0 ] = 'none';

		foreach( $urlProfileFields as $pf )
			$profileField_select[ $pf['pf_id'] ] = "core_pfield_{$pf['pf_id']}";

		$form->add( new \IPS\Helpers\Form\Select( 'tekFeaturedMemberTopic_pfield', \IPS\Settings::i()->tekFeaturedMemberTopic_pfield ? \IPS\Settings::i()->tekFeaturedMemberTopic_pfield : 0, NULL, array(
				'options' => $profileField_select
			) ) );

And then elsewhere I have the following code to return the URL target: 

		if ( $pf_id )
			try {
				# $pf = \IPS\Db::i()->select('*', 'core_pfields_data', array( "pf_id=? AND pf_type='Url'", $pf_id ) )->first();
				# $url = $this->profileFields()["core_pfieldgroups_{$pf['pf_group_id']}"]["core_pfield_{$pf_id}"];
				$pf_content = (string) \IPS\Db::i()->select('field_' . $pf_id, 'core_pfields_content', array( "member_id=?", $this->member_id ) )->first();
				$url = $pf_content;

				if ( $url )
					return $url;
			} catch( \Exception $e ) { }


My request/question: 

Surely it would be beneficial to have a method that simply returns a single layered-array with just the raw values of the profile fields?

Something like \IPS\Member::loggedIn()->pfields()['pfield_3'] that would return simply "http://www.google.com" and not "<a href=...>http://www.google.com</a>". 

Alternatively, how would you have me work around this / How should I do this?

Link to comment
Share on other sites

  • 4 weeks later...


This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...