17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 3727 Views |
-
Extend Member using DataObjectDecorator

3 December 2008 at 10:03am
Can anyone give me a code example or a link showing how to extend a member object to have additional fields using a DataObjectDecorator? As simple as you have got.
Thanks -
Re: Extend Member using DataObjectDecorator

3 December 2008 at 3:20pm
check the forum's ForumRole.php
-
Re: Extend Member using DataObjectDecorator

3 December 2008 at 6:12pm
Have you checked the docs? A lot of info in there.
-
Re: Extend Member using DataObjectDecorator

6 December 2008 at 6:50am
In the ForumRole decorator there is reference to a table ForumMember in a function called augmentDatabase.
I don't see that table. What is this all about?
function augmentDatabase() {
$exist = DB::query( "SHOW TABLES LIKE 'ForumMember'" )->numRecords();
if( $exist > 0 ) {
DB::query( "UPDATE `Member`, `ForumMember` " .
"SET `Member`.`ClassName` = 'Member'," .
"`Member`.`ForumRank` = `ForumMember`.`ForumRank`," .
"`Member`.`Occupation` = `ForumMember`.`Occupation`," .
"`Member`.`Country` = `ForumMember`.`Country`," .
"`Member`.`Nickname` = `ForumMember`.`Nickname`," .
"`Member`.`FirstNamePublic` = `ForumMember`.`FirstNamePublic`," .
"`Member`.`SurnamePublic` = `ForumMember`.`SurnamePublic`," .
"`Member`.`OccupationPublic` = `ForumMember`.`OccupationPublic`," .
"`Member`.`CountryPublic` = `ForumMember`.`CountryPublic`," .
"`Member`.`EmailPublic` = `ForumMember`.`EmailPublic`," .
"`Member`.`AvatarID` = `ForumMember`.`AvatarID`," .
"`Member`.`LastViewed` = `ForumMember`.`LastViewed`" .
"WHERE `Member`.`ID` = `ForumMember`.`ID`"
);
echo("<div style=\"padding:5px; color:white; background-color:blue;\">" . _t('ForumRole.TRANSFERSUCCEEDED','The data transfer has succeeded. However, to complete it, you must delete the ForumMember table. To do this, execute the query \"DROP TABLE \'ForumMember\'\".') . "</div>" );
}
} -
Re: Extend Member using DataObjectDecorator

9 December 2008 at 11:59pm
I have a much simpler example:
===mysite/code/MyMemberExtension===
<?php
class MyMemberExtension extends DataObjectDecorator {
function extraDBFields() {
return array(
'db' => array(
'Website'=>'Varchar'
),
'has_one' => array(
'Avatar' => 'Image'
),
);
}
public function updateCMSFields(FieldSet &$fields) {
$fields->push(new TextField('Website', 'Website-URL'));
$fields->push(new ImageField('Avatar', 'Profile Image'));
}
}
?>
===In mysite/_config.php:
Object::add_extension('Member', 'MyMemberExtension');
-
Re: Extend Member using DataObjectDecorator

10 December 2008 at 4:31am
Thanks for responding adiwidjaja.
That is a much simpler example. Also pointing out the _config.php inclusion is good too as this is how the system knows of the decorator's existence. The forum code takes days to ponder.
Do you happen to know what is going on in the ForumRole function augmentDatabase() and the ForumMember table reference?
| 3727 Views | ||
|
Page:
1
|
Go to Top |




