I wrote a tutorial on how I did this, but I can't find it, it was dead simple at the time. I used it to allow users create/delete their public profiles, and of course one profile per user.
I had a tiny getresources or own snippet to go check if a certain parent resource had any children whose
createdby/publishedby value matched the username of current attempting user.
If there was a match, the NP create/edit page would redirect to the existing profile. And the user had to go to their account to edit the public profile, as I removed the edit button o the profile page.
And if no match, the NP page proceeded to present itself.
In a more evolved and developed mental unsteadiness, I made TinyMagicPublisher that has all of this under perfect control.
Here is an excerpt from the TinymceWrapper Suite
<?php
//You simply have to force your resource url to have parameters
//www.about.com/profiles?create=1
//www.about.com/profiles?edit=1
//And make sure that the [[!NewsPublisher]] never is fired without a valid parameter
function redirectTo($desti,$param){
global $modx;
$url = $modx->makeUrl($desti,'',$param,'full');
$modx->sendRedirect($url);
}
// $npCreateResource = the id of ya newspublisher resource
//let's set up some restrictions
if (isset($_GET['edit']) && !isset($_GET['create']) && $modx->resource->get('id') !== $npCreateResource ) {
$legalEDITparam = 1;
}
if (isset($_GET['create']) && !isset($_GET['edit']) && $modx->resource->get('id') == $npCreateResource ) {
$legalCREATEparam = 1;
}
if (!$modx->hasPermission('new_document') || $_GET['create'] !== 'true') {
// at this point you may add more logic to find if this user has created a resource before. Best to check against a resource parent to see if any child belongs to said user
$legalHASpermission = 1;
}
if ($modx->resource->get('createdby') == $modx->user->get('id') || $modx->user->isMember(listArray($editorAdminGroups))) {
$legalOWNER = 1;
}
//reset these session variables so that NewsPublisher can have clean slate for Editing existing resource or creating a new one
if(isset($_SESSION['np_doc_id'], $_SESSION['np_doc_to_edit'])) {
unset($_SESSION['np_doc_id'], $_SESSION['np_doc_to_edit']);
}
//grab url parameters and init NewsPublisher accordingly
if ($legalEDITparam == 1) {
//return to resource url withou the edit parameter
if ($_GET['edit'] !== 'true' || !$legalOWNER == 1) {
redirectTo($modx->resource->get('id'),'');
}
//restrict editing to owner of resource or Admin editors
if ($legalOWNER == 1) {
//give NewsPublisher snippet some food
$_SESSION['np_doc_to_edit'] = $modx->resource->get('id');
$_SESSION['np_doc_id'] = $modx->resource->get('id');
echo $buttonsANDnewspublisher; //e.g [[!NewsPublisher]]
}
}
elseif ($legalCREATEparam == 1) {
if ($legalHASpermission) {
redirectTo($npCancelCreateId,'');
}
echo $buttonsANDnewspublisher; //e.g [[!NewsPublisher]]
}
else{
if($createNewButton){
$createNewButton = '<a href="[[~'.$npCreateResource.' ? &create=`true` &scheme=`full`]]">'.$createNewButton.'</a>';
}
else{
$createNewButton = '';
}
if($editThisButton){
$editThisButton = '<a href="[[~[[*id]]? &edit=`true` &scheme=`full`]]">'.$editThisButton.'</a>';
}
else{
$editThisButton = '';
}
if (!$modx->hasPermission('new_document')) {
$createNewButton = '';
}
if (!$legalOWNER || !$modx->hasPermission('edit_document') ) {
$editThisButton = '';
}
if (!$legalOWNER || !$modx->hasPermission('edit_document') && !$modx->hasPermission('new_document') ) {
return;
}
$editCreateButtons = '<div class="publishButtons">'.$editThisButton.$createNewButton.'</div>';
echo $editCreateButtons;
}