123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <?php
- if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
- require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
- class Group_block extends Managed_DataObject
- {
-
-
- public $__table = 'group_block';
- public $group_id;
- public $blocked;
- public $blocker;
- public $modified;
-
-
- public static function schemaDef()
- {
- return array(
- 'fields' => array(
- 'group_id' => array('type' => 'int', 'not null' => true, 'description' => 'group profile is blocked from'),
- 'blocked' => array('type' => 'int', 'not null' => true, 'description' => 'profile that is blocked'),
- 'blocker' => array('type' => 'int', 'not null' => true, 'description' => 'user making the block'),
- 'modified' => array('type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date of blocking'),
- ),
- 'primary key' => array('group_id', 'blocked'),
- 'foreign keys' => array(
- 'group_block_group_id_fkey' => array('user_group', array('group_id' => 'id')),
- 'group_block_blocked_fkey' => array('profile', array('blocked' => 'id')),
- 'group_block_blocker_fkey' => array('user', array('blocker' => 'id')),
- ),
- );
- }
- static function isBlocked($group, $profile)
- {
- $block = Group_block::pkeyGet(array('group_id' => $group->id,
- 'blocked' => $profile->id));
- return !empty($block);
- }
- static function blockProfile($group, $profile, $blocker)
- {
-
- $block = new Group_block();
- $block->query('BEGIN');
- $block->group_id = $group->id;
- $block->blocked = $profile->id;
- $block->blocker = $blocker->id;
- $result = $block->insert();
- if ($result === false) {
- common_log_db_error($block, 'INSERT', __FILE__);
- return null;
- }
-
- $member = new Group_member();
- $member->group_id = $group->id;
- $member->profile_id = $profile->id;
- if ($member->find(true)) {
- $result = $member->delete();
- if ($result === false) {
- common_log_db_error($member, 'DELETE', __FILE__);
- return null;
- }
- }
-
- $block->query('COMMIT');
- return $block;
- }
- static function unblockProfile($group, $profile)
- {
- $block = Group_block::pkeyGet(array('group_id' => $group->id,
- 'blocked' => $profile->id));
- if (empty($block)) {
- return null;
- }
- $result = $block->delete();
- if (!$result) {
- common_log_db_error($block, 'DELETE', __FILE__);
- return null;
- }
- return true;
- }
- }
|