Weatherangel wrote:mikko wrote:
list tab
Allows user to make tab "list enabled", that is, a tab can have several entries with the field
+does not work on registration
+a minor useability bug on the admin side
-might cause data loss if set up carelessly
Mikko,
I am trying to get the update working at registration, and I'm having issues. I was wondering how much you've looked into the option, and if you think this code should fix the problem?
[code:1]
$_PLUGINS->registerFunction( 'onBeforeUserProfileDisplay', 'checkForConfigUpdates','listTab' );
$_PLUGINS->registerFunction( 'onAfterUserUpdate', 'checkForConfigUpdates','listTab' );
$_PLUGINS->registerFunction( 'onAfterUserRegistration', 'checkForConfigUpdates','listTab' );
[/code:1]
I was thinking that it should, but it's not. Do you have any thoughts? Am I calling the wrong method?
The locations that I've added into registerFunctions may be over board, but this code seems to be working, at least in my instance. The ONE draw back is that I have the
tabid hardcoded for the time being in my code. For me it works and I can leave it this way for my purposes, however for a general roll out, it would need to be a little more self sufficent, maybe going through each of the listtabs that are available? I don't know. Anyway, I hope this code helps your efforts
[code:1]
$_PLUGINS->registerFunction( 'onBeforeUserProfileDisplay', 'checkForConfigUpdates','listTab' );
$_PLUGINS->registerFunction( 'onAfterUserUpdate', 'updateListTab','listTab' );
$_PLUGINS->registerFunction( 'onAfterUserRegistration', 'updateListTab','listTab' );
$_PLUGINS->registerFunction( 'onAfterNewUser', 'updateListTab','listTab' );
function updateListTab($user, $ui, $postvars)
{
global $database;
$tab = new stdClass;
//TODO: switch this from being hard coded to variable based.
$tab->tabid = "23";
$database->setQuery("SELECT * FROM #__comprofiler_fields WHERE published=1 and tabid = ".$tab->tabid." and readonly=0"«»);
$rowFields = $database->loadObjectList();
$cbFields=new cbFields();^M
$dataFound=false;
$rowExtras = new stdClass();
for($i=0, $n=count( $rowFields ); $i < $n; $i++)
{
$field=cbGetEscaped($rowFields[$i]->name);
$value=null;
if(isset($_POST[$rowFields[$i]->name]))
{
$value=$cbFields->prepareFieldDataSave($rowFields[$i]->type,$rowFields[$i]->name,$_POST[$rowFields[$i]->name]);
if($value!='')
$dataFound=true;
}
$rowExtras->$field=$value;
}
$rowExtras->userid=$user->id;
$rowExtras->tabid=$tab->tabid;
//If data is found, do INSERT
if($dataFound)
{
$database->insertObject( '#__comprofiler_listtab_'.$tab->tabid, $rowExtras);
if($database->getErrorNum()==1054)
{
$database->insertObject( '#__comprofiler_listtab_'.$tab->tabid, $rowExtras);
}
}
}
[/code:1]
Post edited by: Weatherangel, at: 2006/10/05 07:54