Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#4 Relationship plugin update - show links on contactPage

open
nobody
None
5
2009-02-11
2009-02-11
Jonathan Daley
No

I wanted to be able to link between the contacts quickly when they are in a "relationship" to each other.
This bit of code adds a label and a link to the related-to contact on the contact page.

Index: plugins/Relationships/Relationships.plugin.php

--- plugins/Relationships/Relationships.plugin.php (revision 7836)
+++ plugins/Relationships/Relationships.plugin.php (revision 7837)
@@ -11,8 +11,47 @@

class Relationships {

-function isType($t) { return $t=='editContactInterface' || $t=='changedContactRecord' || $t=='xmlExport'; }
-
+ function isType($t)
+ {
+ return $t=='editContactInterface' ||
+ $t=='contactOutput' ||
+ $t=='changedContactRecord' ||
+ $t=='xmlExport';
+ }
+
+function contactOutput(&$contact,$location)
+{
+ if($location != "beforeNotes"){
+ return "";
+ }
+
+ global $CONFIG_DB_PREFIX;
+ $db = DB::getSingleton();
+ $content = "";
+
+ // list existing relationships if any
+ $id = $contact->contact['id'];
+ $db->query("SELECT r.* FROM `{$CONFIG_DB_PREFIX}Relationships` as r, ".
+ "`{$CONFIG_DB_PREFIX}contact` as c ".
+ "WHERE r.ownerId=$id AND c.id=r.ownerId AND c.hidden=0",'Relationships');
+
+ while($r = $db->next('Relationships')){
+ $content .= '<span class="other-label">'.$r['relationship'].' of</span>';
+ $content .= '<span class="other-info"><a href="../contact/contact.php?id='.$r['relatedToId'].'">';
+ $relContact = Contact::newContact($r['relatedToId']);
+ if(!$relContact){
+ $content .= 'Contact not found.';
+ }
+ else{
+ $content .= $relContact->contact['firstname'] . ' ' . $relContact->contact['lastname'];
+ }
+ $content .= '</a></span>';
+ }
+
+ return $content;
+}
+
+
/**
* Returns the Javascript to generate the help text for the admin. Used by {@link PluginManager}.
* @return string script type="text/javascript" section for HTML output

Discussion