Example #1
0
 /**
  * Method to add a user to a group.
  * In most cases, you should call Profile->joinGroup() instead.
  *
  * @param integer $group_id   Group to add to
  * @param integer $profile_id Profile being added
  * 
  * @return Group_member new membership object
  */
 static function join($group_id, $profile_id)
 {
     $member = new Group_member();
     $member->group_id = $group_id;
     $member->profile_id = $profile_id;
     $member->created = common_sql_now();
     $member->uri = self::newUri(Profile::getByID($profile_id), User_group::getByID($group_id), $member->created);
     $result = $member->insert();
     if (!$result) {
         common_log_db_error($member, 'INSERT', __FILE__);
         // TRANS: Exception thrown when joining a group fails.
         throw new Exception(_("Group join failed."));
     }
     return $member;
 }
Example #2
0
 public static function figureOutScope(Profile $actor, array $groups, $scope = null)
 {
     $scope = is_null($scope) ? self::defaultScope() : intval($scope);
     // For private streams
     try {
         $user = $actor->getUser();
         // FIXME: We can't do bit comparison with == (Legacy StatusNet thing. Let's keep it for now.)
         if ($user->private_stream && ($scope === Notice::PUBLIC_SCOPE || $scope === Notice::SITE_SCOPE)) {
             $scope |= Notice::FOLLOWER_SCOPE;
         }
     } catch (NoSuchUserException $e) {
         // TODO: Not a local user, so we don't know about scope preferences... yet!
     }
     // Force the scope for private groups
     foreach ($groups as $group_id) {
         try {
             $group = User_group::getByID($group_id);
             if ($group->force_scope) {
                 $scope |= Notice::GROUP_SCOPE;
                 break;
             }
         } catch (Exception $e) {
             common_log(LOG_ERR, 'Notice figureOutScope threw exception: ' . $e->getMessage());
         }
     }
     return $scope;
 }
Example #3
0
function initGroupMemberURI()
{
    printfnq("Ensuring all group memberships have a URI...");
    $mem = new Group_member();
    $mem->whereAdd('uri IS NULL');
    if ($mem->find()) {
        while ($mem->fetch()) {
            try {
                $mem->decache();
                $mem->query(sprintf('update group_member set uri = "%s" ' . 'where profile_id = %d ' . 'and group_id = %d ', Group_member::newUri(Profile::getByID($mem->profile_id), User_group::getByID($mem->group_id), $mem->created), $mem->profile_id, $mem->group_id));
            } catch (Exception $e) {
                common_log(LOG_ERR, "Error updated membership URI: " . $e->getMessage());
            }
        }
    }
    printfnq("DONE.\n");
}
Example #4
0
 protected function doPreparation()
 {
     $this->group = User_group::getByID($this->arg('id'));
 }