Joomla additional User Data - php

Im trying to create some new extensions in joomla.
I want to add additional information for each user. I know I could achieve this by creating my own custom user profile plugin and adding additional fields, but this will then add those fields to the users profile page.
I want to show the new fields separately. For example i may have one link on the users page which takes them to there basic information e.g. name, email etc. And another link which shows them the 'additional' fields.
The additional fields will not be personal information, that's why I want to display them separately.
My question is, how do I achieve this? Can I simply add additional fields to each user or will I have to write a completely new component?
UPDATE: I cannot use an existing extension as I want full control over the code. Also, the additional information will NOT be added by the user, it will only be added by admin.

You do not have to display profile fields on the user profile page with the standard user profile You can configure it only to display to the administrator. You simply make different settings for the different forms (there are 4 throughout the cms). Follow the pattern in the core plugin.

In the end I decided it was better to create my own component. Mainly because hacking joomla would be a pest when updates came out and JED did not provide the specific extension that I wanted.

There are probably 2 main way of doing this.
You can create an extension where user fill in the information and it stores the data in separate database table which connects to the #__users table.
You could download an extension from JED for extended profiles. There are non-commercial and commercial extensions so take a look here to see if there is anything that might suit your needs.
Personally I would install a pre-made extension and it will save a lot of work/trial and error.
check this out: http://extensions.joomla.org/extensions/clients-a-communities/user-management

If you have added or changed any coding like adding fields to user table or customize registration page in joomla it will restore to default once you upgrade your Joomla version.
The way to do this is:
You have to create another table which contains the other extra information and should with userid from #__users.
When submitting the form you have get the another table by using this Joomla code.
$module_table = JTable::getInstance('modules', 'profileTable');
Modules -> means table name which you created.
ProfileTable -> means "component name" is Model name and "Table" is common.
Then you have to pass the post values to this table like this..
if (!$module_table->bind($post))
{
return 0;
}
if (!$module_table->check())
{
return 0;
}
if (!$module_table->store())
{
return 0;
}
This way, you can store additional data for users. For displaying purposes, you will need to join the two tables by using userid and display it...
All the best..

Related

Wordpress ask user's their desired role as a dropdown menu while registration

I want to add a custom field to the Wordpress registration form without using any plugins. I want to add a dropdown menu with user-roles ( some roles I have created). Once the registration is complete the user should not have the ability to change their roles ( only admin can do that, selecting role as admin should not be allowed).
Any help will be appreciated.
I understand that you do not intend to use plugins, but you nevertheless use a theme, be it implemented by your team or some widely available theme. In any case, that theme has an implementation for your registration, so:
Find the registration form
Make sure that you find out where the registration form is.
Add a field to the form
Be it in a CMS editor or in a PHP/HTML file you must be able to edit it and add a field
Find the code which runs when a registration is posted
Again, you need to seek and find.
Enhance your functionalities which save fields
You will need to track and save the posted value
Change the database schema
You will need to do some changes on the MySQL schema in order to support the new field on database-level.

How can I build "user group" access control into WordPress?

WordPress has some lovely features for storing revisions, editor approval of content, etc.
I'd like to expand on them by creating the concept of a user group/organisation.
I want:
to be able to attach posts to an organisation
to be able to attach users to an organisation (and ideally make it so that users can invite other users to their same org)
users can only make changes to posts in the same org as them, everything else is read only.
I can do the first two with a custom post type and an Advanced Custom Fields post object field, but I'm stumbling on the last one and would appreciate some pointers.
I imagine I would need to create a custom role with add_role(), but I'm not sure what capabilities it should have.
I imagine I'll need to override a hook somewhere to check if the thing the user is trying to edit is in their org.
Only relevant code so far is:
register_post_type("organisation");
First, on WordPress, the default user system is: admin can do everything, editors can edit every post, authors can only edit their posts.
There are some plugins like https://es.wordpress.org/plugins/user-role-editor/ that may be useful for your needs. Have a look at that!

Custom table queries in WordPress

I am developing a WordPress site for a client and they would like me to setup a custom page that allows logged in users to query a custom table in the WordPress database. I'll be naming the custom table 'inspectors' and will import the data from a CSV file.
I've found this helpful tutorial on doing this
But the 'fly in the ointment' is that they want the results to be displayed according to location - so the user would enter a postal code or town and will get results for inspectors that are located within a 50 k radius. I'm pretty sure I could manage a basic query to the custom table, but getting it to return location-based results is beyond me.
Is it even possible - and if so, is it worth the time and effort it would take to make it happen - or is there a simple solution I just don't know about?
Also, they also would like me to create a custom form (that is available only to the admin user role) so they can update the info from WordPress and not have to update the info in the spreadsheet. They'd like to be able to export the data in the table to CSV easily too ...
Thanks for any help on this!
Refer the below link and write your own custom queries.
http://codex.wordpress.org/Class_Reference/wpdb

Create new tables or use the native in joomla

I need to write a component that have a per profile page where the user can add articles,
and i dont know if I need to create a new table for users, articles, user_articles, or use the native joomla tables??
and if yes how can I override the methods JFactory::getUser(); - and others...
and if yes will i have to create own methods to save sessions, or use the native $user->is_guest() ???, i am confused about that.
There are a couple of ways you could go about this.
First, you really don't need any new tables at all. There isn't any information you need that isn't already being saved in either the user or article tables. If you want to use Joomla articles, then you would need a new view and model for com_content that displays articles by article author. Use the built in front end content entry and make users register before they can submit articles.
The other option is to switch to using K2 for your content display. K2 already has article by author built in so you wouldn't need to do anything. Again, use the built in front end content entry and require registration before submission.

Drupal 6: custom profile fields and saving data to a DB

So i've added several some custom profile fields (administer -> profiles) which is all fine but completely useless if I can't store the information in a database. I've been searching for hours now trying to figure out the "best practices" way for doing this with very little luck.
Do I add the new columns to the Users table? Do I create a whole new table? I even found a vague reference that the core profile module should have added those columns for me anyway? And that you should be able to use CCK in the core profile module (but I don't have any options for that)?
And then I would obviously want to allow user to update their own fields but the the custom profile fields aren't included in the $form array...
PS arrrggg! Drupal is driving me around the bend with its inconsistencies and having to hack it all the time!
If you use the core profile module, the database storage is provided automatically and you will not need to modify anything in the database. On install, the module adds two tables to the database, profile_fields to store your custom field definitions and profile_values to store the user supplied data for those fields.
The fields are automatically added to the user edit forms, via the hook_user implementation in profile_user() - the same mechanism is used to add the values of those fields to the user object when that gets loaded.
So if those fields don't show up for you, something is fishy - have you added your fields with 'categories'? If so, they won't show on the standard user edit page, but on additional new pages (one per category). These are added as menu type MENU_LOCAL_TASK, so they should create new 'tab' entries at the top of the user edit page - maybe you have a theme that does not display the tabs?
Another thing to check would be the fields visibility settings chosen on the fields configuration form. If that is set to 'hidden', the field is only accessible for administrators and module/theme code. You should at least set it to 'private' if the user is supposed to edit it himself.
As for using CCK fields, I don't think that this is possible with the core profile module (maybe some extension module provides this). A different approach is taken by the Content Profile Module. It creates a custom node type for user profiles so that the profile values are stored as standard Drupal nodes. One advantage of this is that you can use all CCK fields for profiles, as you just need to add those to the created node type.

Categories