summaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
authorEvan Prodromou <evan@controlyourself.ca>2008-12-08 13:57:28 -0500
committerEvan Prodromou <evan@controlyourself.ca>2008-12-08 13:57:28 -0500
commitef3d487ae02a6333b4e0f0714599ff1c3b7b729e (patch)
treef1e93c561e35ecc23fda597fd145bf3daf8ac733 /classes
parentcd5eec767aaa88fab29e781b12d53d0c92226f3b (diff)
enable block API
darcs-hash:20081208185728-5ed1f-8d5f6be6decfbb50deb4ca50bee13404d0c51b72.gz
Diffstat (limited to 'classes')
-rw-r--r--classes/User.php59
1 files changed, 59 insertions, 0 deletions
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;
+ }
+
}