Page 1 of 1

"Posted by" showing number

PostPosted: Wed Jan 25, 2012 10:16 am
by titleistfour
Hello,

Just wanted to first say that I discovered Xataface 2 days and love it! Great piece of software, thank you for the work you have put in it.

So, my small issue. When I post a record, the "Posted by" text is showing a number. For example, "Posted by 9", "Posted by 2". Should that be more description? Such as "Posted by jsmith"? I know can hide this, but I think for us it would be useful to see how posted the record.

I am running xataface 1.3rc6

Thanks for any pointers!

Jay

Re: "Posted by" showing number

PostPosted: Wed Jan 25, 2012 11:06 am
by titleistfour
Ok, so did a little digging and found the code the builds the text to display 'Posted by'.

getCreatorField() and getCreator() in Table.php. These 2 functions query my tables to find out the creator if the field falls in this set of column names

/(created.*by)|(owner)|(posted*by)|(author)|(creator)/


So, that being found, I updated my tables to add that column, and filled in some test data. That fixed my original problem, but leads to another question.

How do I get Xataface to add the creator in automatically based on the logged in user?

Thanks

Re: "Posted by" showing number

PostPosted: Wed Jan 25, 2012 11:43 am
by shannah
Good question. Currently there's nothing automatic. You would need to do it in your beforeInsert() trigger.
e.g.
Code: Select all
function beforeInsert($record){
    $username = Dataface_AuthenticationTool::getInstance()->getLoggedInUserName();
    $record->setValue('creator', $username);
}


It would be a good feature to make this configurable in the fields.ini ... but that isn't set up yet (that I can recall).

Steve

Re: "Posted by" showing number

PostPosted: Wed Jan 25, 2012 1:18 pm
by titleistfour
Ok, thank you for the code snippet!

Re: "Posted by" showing number

PostPosted: Thu Jan 26, 2012 12:55 am
by sim
I think there is a typo shouldnt it be prefixed with &
like follows
function beforeInsert(&$record){
$username = Dataface_AuthenticationTool::getInstance()->getLoggedInUserName();
$record->setValue('creator', $username);
}

Re: "Posted by" showing number

PostPosted: Thu Jan 26, 2012 10:31 am
by titleistfour
You are correct. I fixed that, but forgot to reply to the previous post. Thanks

Re: "Posted by" showing number

PostPosted: Thu Jan 26, 2012 10:41 am
by shannah
Actually since we're all on PHP 5 now, it doesn't make a difference. Usually I now omit the &.
The only exception to this rule is if you're passing an array and it needs to be by reference. Arrays are still passed by value by default. Objects are now always passed by reference.

-Steve