#2 Relationship plugin: mutual relationship

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

It'd be better to have a checkbox so you could set it on any given relationship, rather than hard-coding "spouse", etc. Though hard-coding could lead to handy things like "Mother->daughter" (or son, automatically) What do you think about those thoughts? Do you want patches if I end up doing that?

addressbook/plugins/Relationships>svn diff -c7835
Index: Relationships.plugin.php
===================================================================
--- Relationships.plugin.php (revision 7834)
+++ Relationships.plugin.php (revision 7835)
@@ -263,6 +263,18 @@
$contact->contact['id'] .','. $db->escape($rShip['relatedToId']) .','. $db->escape($rShip['relationship']).')';

$db->query($sql);
+
+ // mutual relationship - maybe use a checkmark instead?
+ // Note: we can't/shouldn't erase the relatedToId's former relationships
+ // so, use an IGNORE and call it good enough
+ if(strtolower($rShip["relationship"]) == "spouse"){
+ $sql = 'INSERT IGNORE INTO ' . $tbl . ' (ownerId, relatedToId, relationship) VALUES ('.
+ $db->escape($rShip['relatedToId']) .','.
+ $contact->contact['id'] .','.
+ $db->escape($rShip['relationship']).')';
+
+ $db->query($sql);
+ }
}

// Remove overhead
@@ -275,13 +287,14 @@
{
global $CONFIG_DB_PREFIX;
$db = DB::getSingleton();
-
+
// DB extensions
$db->query("CREATE TABLE IF NOT EXISTS `{$CONFIG_DB_PREFIX}Relationships` (
`ownerId` int(11) NOT NULL default '0',
`relatedToId` int(11) NOT NULL default '0',
- `relationship` TEXT NOT NULL )
- DEFAULT CHARSET=utf8;"); // , PRIMARY KEY (`requestId`) )
+ `relationship` varchar(255) NOT NULL,
+ PRIMARY KEY (`ownerId`,`relatedToId`,`relationship`))
+ DEFAULT CHARSET=utf8");
}

/** DB statements to drop table within the TABR DB -- MUST USE PLUGIN NAME as table name

Discussion