private function handleUserFriend($type, TableInterface $table, RecordInterface $record) { if ($type == RecordAbstract::INSERT) { $date = new DateTime('NOW', $this->registry['core.default_timezone']); if ($record->status == Friend\Record::REQUEST) { } else { if ($record->status == Friend\Record::NORMAL) { // insert activity for user who has accepted the friend request $handler = $this->hm->getHandler('AmunService\\User\\Activity', $this->user); $activity = $handler->getRecord(); $activity->verb = 'make-friend'; $activity->summary = '<p><a href="' . $record->getUser()->profileUrl . '">' . $record->getUser()->name . '</a> and <a href="' . $record->getFriend()->profileUrl . '">' . $record->getFriend()->name . '</a> are now friends</p>'; $handler->create($activity); } } } }
/** * If the status of the friendhip request is "REQUEST" then we look whether * the user wich receives the friendship request is a remote user. If its a * remote user we send an notification to the website that the user has * received a friendship request. If the status is "NORMAL" the request was * accepted. If the user who has made the request was an remote user we send * and notification to the website that the request was accepted. * * @param RecordInterface $record * @return void */ protected function handleRemoteSubscription(RecordInterface $record) { $cred = null; switch ($record->status) { // a remote user wants to request a user as friend. We must notify // the remote website about the friendship request case Record::REQUEST: if ($record->getUser()->getStatus() == Account\Record::REMOTE) { $url = new Url($record->getUser()->getHost()->url); $mode = Relation::REQUEST; $host = $this->base->getHost(); $name = $record->getFriend()->name; $cred = $record->getUser()->getRemoteCredentials(); } break; // a user accepted a friendship request where the initiator was an // remote user we must inform the remote website that the request // was accepted // a user accepted a friendship request where the initiator was an // remote user we must inform the remote website that the request // was accepted case Record::NORMAL: if ($record->getFriend()->getStatus() == Account\Record::REMOTE) { $url = new Url($record->getFriend()->getHost()->url); $mode = Relation::ACCEPT; $host = $this->base->getHost(); $name = $record->getUser()->name; $cred = $record->getFriend()->getRemoteCredentials(); } break; } if ($cred instanceof Consumer) { $http = new Http(); $relation = new Relation($http, $cred); $relation->request($url, $mode, $host, $name); } }