MODX Community

Assign user to one ressource - Front -end edition

I have to create a site where society can make a profile and edit it.
I have done user creation with Login Extra.
I think i can “link” user and ressource by using user custom fields and let them edit the content of ressource with NewPublisher Extra

But i cant figure how to automaticaly create the ressources and fill/edit the TV in front-end
I have to assign different model for this ressource depending on a TV vallue of this ressource
I have to put ressources in a different folder (selected, not selected) depending on TV vallue

i found this solution
https://forums.modx.com/thread/31314/how-to-create-resources-documents-from-the-front-end-with-a-form

and i have to send message to user for let him know the state of his ressources depending TV value or ressource folder location
for this one i dont have any idea, i heard abour hook, prehook and i think it may be the way

(it’s a site who show innovative project and make video on them. I have to sort society depending if they accept to be filmed or not, and i have to send message for user if they are selected or not for the video making)

Have you some advices ?

1 Like

I’m not sure if this article is what you want, but it might be.

1 Like

Thanks Bob, I take some time to see if i really wish to deliver ressources access to web user and the answer is no. I prefer to store data from users in extended user field and update an associated resource with moderator aproval.

I will use a form with a snippet in hook to create a new modx ressources from input form, get the id of the new resource created and put it in an extended user field.
may be newpublisher can do this easily but i prefer to manage it by snippet

process will be liket this:
i have to check if user are logged in:
[[!isLoggedIn? &ctxs=`web`]]
and then if he have an resource id on a user extended field that mean he have already made one resource so i hide my chunk form

if not, i have to show a form who will create only one ressource once.
template of the ressource will be defined by checkbox from the form
some field will be used to fill resource field and some other one will be stored to extended user fields

i dont really know how to acces extended user fields from snippet, i ear about json , i imagine i will need to parse data en check value but i dont know if i had to make/name extended user fields at user creation or if i can make it with snippet

1 Like

The extended fields are in the user profile (modUserProfile) object.

So:

/* Assuming that you have the $user object */

$profile = $user->getOne('Profile');
if ($profile) {
    $extendedFields = $profile->get('extended');
} else {
    /*  user has no profile */
}
/* $extendedFields is a regular PHP associative array. */
$value = $profile['some_field']

/* If you need to change the value, get the extended fields as above, then: */

$profile['some_field'] = 'newValue';
$profile->save();

This is another option: ClassExtender.

1 Like

i can’t make it work :confused:

Fatal error: Uncaught Error: Call to a member function getOne() on null

i found this tread in old modx forum : https://forums.modx.com/thread/44021/accessing-extended-fields-revo-user-management

i make a snippet call getUserExtendedFields

<?php
$profile = $modx->user->getOne('Profile');
$modx->toPlaceholders($profile->get('extended'), 'userext');
$extended = $profile->get('extended');
echo $extended['RessourcesId'];
echo $extended['Test'];
if($extended['RessourcesId'] == ''){ echo "Ressources Id vide"; return $modx->getChunk('InscriptionForm');}else{echo $extended['RessourcesId'];}

and put placeholder in model

PlaceHolder Ressource ID : [[+userext.RessourcesId]]<br/>
PlaceHolder Test : [[+userext.Test]]<br/>

it works BUT, when i disconnect the user and reconnect another user witout any extend field… it show me the last result. i clean web browser cache, event use another web browser, i always saw the last request…
i have to go to modx administration -> clean cache to get the snippet work properly with new user.
what am i doing wrong ?

1 Like

ok… my fault i call snippet with cache: [[getUserExtendedFields]].
using uncached make it work : [[!getUserExtendedFields]]

1 Like

About my code above. Notice the very first line:

/* Assuming that you have the $user object */

$profile = $user->getOne('Profile');

If you don’t already have the user object, you have to get it before calling getOne().

In the front end, that would be either this at the top:

$user = $modx->user;

or just changing the code to:

$profile = $modx->user->getOne('Profile');
1 Like

haaa ok $user : $ for variable
i just needed to fill it with user data
thanks

1 Like