[TYPO3-mvc] relations with metadata
Franz Koch
typo3.RemoveForMessage at elements-net.de
Thu Jun 3 14:05:30 CEST 2010
Hi,
> I'm currently working on tx_community for the Google Summer of Code and, starting with profiles, I have a question about relations. In particular it's about the friendship (yes, that's the common term in social networks) between users.
> When one user wants to add another user as a friend, the other one gets notified and has to confirm the friendship. My question is how to technically implement those relations. Ingo and I have had several ideas:
I'd say I'd use a intermediate object called 'friend' or 'friendship'.
USER1 -> FRIENDSHIP <- USER2
The friendship model could look like this:
----------------------------------------------------
class Tx_Community_Domain_Model_Friendship {
/**
* the user who initiated the friendship
*/
protected $initiator;
/**
* the friend that got invited/added
*/
protected $friend;
protected $dateOfRequest;
protected $dateOfAcceptance;
/**
* a comment/message the initiator wrote in his friendship request
*/
protected $comment;
# some other
}
----------------------------------------------------
Then, a user model could look like:
----------------------------------------------------
class Tx_Community_Domain_Model_User extends
Tx_ExtBase_Domain_Model_FeUser {
/**
* the friendships this user has initiated
* @var
Tx_Extbase_Persistence_ObjectStorage<Tx_Community_Domain_Model_Frienship>
* @lazy
*/
protected $friendships;
/**
* method that's returning all friends, that get fetched by a userService
* the service itself is calling a special method in the userRepository
* like $this->userRepository->getFriendsByUser($user);
* @return
Tx_Extbase_Persistence_ObjectStorage<Tx_Community_Domain_Model_User>
*/
public function getFriends() {
// the service can/should maybe initiated in the constructor
return $this->userService->getFriendsByUser($this);
}
/**
* Is returning all related friendships, not only the ones initiated by
this user
* @return
Tx_Extbase_Persistence_ObjectStorage<Tx_Community_Domain_Model_Frienship>
*/
public function getAllFriendships() {
$this->userService->getAllFriendshipsByUser($this);
}
/**
* only returning friendships initiated by this user
* @return
Tx_Extbase_Persistence_ObjectStorage<Tx_Community_Domain_Model_Frienship>
*/
public function getFriendships() {
return $this->friendships;
}
}
----------------------------------------------------
Something like that I think. As you will always need a intermediate
table, simply make it a intermediate object and use it to also store
meta data. You won't get a direct relation between the two persons -
there's always a friendship/relation inbetween.
--
kind regards,
Franz Koch
More information about the TYPO3-project-typo3v4mvc
mailing list