The Joomla! Forum ™



Forum rules


Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.



Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Fri Aug 19, 2011 6:39 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Fri Jun 17, 2011 1:49 am
Posts: 46
I've been working with the included user "profiles" plugin and ran into a roadblock earlier this week.

I needed to add an "interests" value, selected using a set of checkboxes. Adding the checkboxes to the two profile.xml documents was easy (one controls the 'required' popups, the other actually generates the checkboxes).

The problem was that since the checkboxes added to the various forms was a set of checkboxes, the data returning to be processed was in an array, and the profiles.php document couldn't handle that, not storing any value at all. For a while I looked at the available parameter filters, but that was a dead end.

So I examined the goals and purposes of both the "profiles" plugin and my own long-term plans and determined:

A) the profiles plugin is the only system I am aware of and/or intend to develop that needs to access the #__user_profiles database table.

B) for my purposes, I can safely assume that any array value stored into that database would be required to be an array once recovered from the database.

So I added two small routines into profiles.php:

In the method onContentPrepareData() I added to the foreach loop that restored the stored info back into $data:
Code:
if( preg_match( "~^\[.*\]$~", $v[1], $value ) )
    $data->profile[ $k ] = json_decode( $value[0] );

This identifies anything stored in a json format and translates it back into an array.

Then, in the method onUserAfterSave(), I replaced the contents of its foreach loop with:
Code:
if( is_array( $v ) )
    $tuples[] = '('.$userId.', '.$db->quote('profile.'.$k).', '.$db->quote(json_encode($v)).', '.$order++.')';
else
    $tuples[] = '('.$userId.', '.$db->quote('profile.'.$k).', '.$db->quote($v).', '.$order++.')';

which json encodes any array value which needed to be stored in the DB.

It's tested well, so, not wanting to modify the core files on a live site, I restored the original profiles plugin disabled it, and replaced it all with a duplicate custom plugin which includes my changes.

I think the supporting assumptions are broad enough to be acceptable by the Joomla community at large, and it's certainly proving to be a very useful patch for me, so I'd like to recommend it to be considered for the next Joomla release. (At the very least, it should probably be discussed in the wiki's "Creating a profile plugin" article.)


Top
 Profile  
 
PostPosted: Thu Dec 08, 2011 12:04 pm 
Joomla! Fledgling
Joomla! Fledgling

Joined: Thu Dec 08, 2011 12:00 pm
Posts: 1
This works for me, but the checkboxes data stored in the database is directly shown in the user profile. I like to format that instead of showing the json array to the user. Any idea's on that?


Top
 Profile  
 
PostPosted: Mon Apr 30, 2012 8:57 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Mon Apr 18, 2011 9:57 pm
Posts: 7
Hiya, Would you be able to show me your finished code for profiles.php please? (or maybe the line numbers of where to insert?) I've tried to add your functions but I'm a noob and things aren't saving for me!

+1 vote for improved checkboxes in jforms


Top
 Profile  
 
PostPosted: Mon Apr 30, 2012 9:13 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Fri Jun 17, 2011 1:49 am
Posts: 46
stevegreenham wrote:
Hiya, Would you be able to show me your finished code for profiles.php please? (or maybe the line numbers of where to insert?) I've tried to add your functions but I'm a noob and things aren't saving for me!


I did this eight months ago on an earlier version of Joomla, probably v1.5, and I honestly don't even remember what site or where. I don't even think JForms - in it's current incarnation - existed. Meanwhile, the v1.6/v1.7/v2.5 upgrade path of Joomla has dramatically improved the flexibility of the profiles system, so I'm not even sure it's necessary any more. Absolutely everything I do now is for the v2.5 world, where there are rarely reasons to mess with the core.

If you're still working in 1.5, I can't offer much help beyond the above. If you're engaged with v2.5 etc., there are better solutions when it comes to touching up a wonky back end.

Let me take a look at it when I get a free moment, and I'll see if I can help.


Top
 Profile  
 
PostPosted: Mon Apr 30, 2012 9:59 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Mon Apr 18, 2011 9:57 pm
Posts: 7
I am working in 2.5, and i just came across this issue which should be the answer i'm looking for, however I am using the profile5 plugin tutorial (http://docs.joomla.org/Creating_a_profile_plugin) and it still doesnt save for me (think it may be to do with the JForm::addFormPath and getInstance?):

Details
The profile plugin should be able to handle any type of field but checkboxES and
lists with multiple="true" are not saving.
http://joomlacode.org/gf/project/joomla ... m_id=26676

Patch attached


You do not have the required permissions to view the files attached to this post.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 



Who is online

Users browsing this forum: No registered users and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group