From ef3d487ae02a6333b4e0f0714599ff1c3b7b729e Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 8 Dec 2008 13:57:28 -0500 Subject: enable block API darcs-hash:20081208185728-5ed1f-8d5f6be6decfbb50deb4ca50bee13404d0c51b72.gz --- classes/User.php | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'classes') diff --git a/classes/User.php b/classes/User.php index 10c6d6b24..04558d43a 100644 --- a/classes/User.php +++ b/classes/User.php @@ -422,4 +422,63 @@ class User extends Memcached_DataObject function setSelfTags($newtags) { return Profile_tag::setTags($this->id, $this->id, $newtags); } + + function block($other) { + + # Add a new block record + + $block = new Profile_block(); + + # Begin a transaction + + $block->query('BEGIN'); + + $block->blocker = $this->id; + $block->blocked = $other->id; + + $result = $block->insert(); + + if (!$result) { + common_log_db_error($block, 'INSERT', __FILE__); + return false; + } + + # Cancel their subscription, if it exists + + $sub = Subscription::pkeyGet(array('subscriber' => $other->id, + 'subscribed' => $this->id)); + + if ($sub) { + $result = $sub->delete(); + if (!$result) { + common_log_db_error($sub, 'DELETE', __FILE__); + return false; + } + } + + $block->query('COMMIT'); + + return true; + } + + function unblock($other) { + + # Get the block record + + $block = Profile_block::get($this->id, $other->id); + + if (!$block) { + return false; + } + + $result = $block->delete(); + + if (!$result) { + common_log_db_error($block, 'DELETE', __FILE__); + return false; + } + + return true; + } + } -- cgit v1.2.3-54-g00ecf