]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/User_group.php
function delete in dataobjects now don't break strict syntax
[quix0rs-gnu-social.git] / classes / User_group.php
1 <?php
2 /**
3  * Table Definition for user_group
4  */
5
6 class User_group extends Managed_DataObject
7 {
8     const JOIN_POLICY_OPEN = 0;
9     const JOIN_POLICY_MODERATE = 1;
10     const CACHE_WINDOW = 201;
11
12     ###START_AUTOCODE
13     /* the code below is auto generated do not remove the above tag */
14
15     public $__table = 'user_group';                      // table name
16     public $id;                              // int(4)  primary_key not_null
17     public $nickname;                        // varchar(64)
18     public $fullname;                        // varchar(255)
19     public $homepage;                        // varchar(255)
20     public $description;                     // text
21     public $location;                        // varchar(255)
22     public $original_logo;                   // varchar(255)
23     public $homepage_logo;                   // varchar(255)
24     public $stream_logo;                     // varchar(255)
25     public $mini_logo;                       // varchar(255)
26     public $created;                         // datetime   not_null default_0000-00-00%2000%3A00%3A00
27     public $modified;                        // timestamp   not_null default_CURRENT_TIMESTAMP
28     public $uri;                             // varchar(255)  unique_key
29     public $mainpage;                        // varchar(255)
30     public $join_policy;                     // tinyint
31     public $force_scope;                     // tinyint
32
33     /* the code above is auto generated do not remove the tag below */
34     ###END_AUTOCODE
35
36     public static function schemaDef()
37     {
38         return array(
39             'fields' => array(
40                 'id' => array('type' => 'serial', 'not null' => true, 'description' => 'unique identifier'),
41                 'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to profile table'),
42
43                 'nickname' => array('type' => 'varchar', 'length' => 64, 'description' => 'nickname for addressing'),
44                 'fullname' => array('type' => 'varchar', 'length' => 255, 'description' => 'display name'),
45                 'homepage' => array('type' => 'varchar', 'length' => 255, 'description' => 'URL, cached so we dont regenerate'),
46                 'description' => array('type' => 'text', 'description' => 'group description'),
47                 'location' => array('type' => 'varchar', 'length' => 255, 'description' => 'related physical location, if any'),
48
49                 'original_logo' => array('type' => 'varchar', 'length' => 255, 'description' => 'original size logo'),
50                 'homepage_logo' => array('type' => 'varchar', 'length' => 255, 'description' => 'homepage (profile) size logo'),
51                 'stream_logo' => array('type' => 'varchar', 'length' => 255, 'description' => 'stream-sized logo'),
52                 'mini_logo' => array('type' => 'varchar', 'length' => 255, 'description' => 'mini logo'),
53
54                 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
55                 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
56
57                 'uri' => array('type' => 'varchar', 'length' => 255, 'description' => 'universal identifier'),
58                 'mainpage' => array('type' => 'varchar', 'length' => 255, 'description' => 'page for group info to link to'),
59                 'join_policy' => array('type' => 'int', 'size' => 'tiny', 'description' => '0=open; 1=requires admin approval'),      
60                 'force_scope' => array('type' => 'int', 'size' => 'tiny', 'description' => '0=never,1=sometimes,-1=always'),
61             ),
62             'primary key' => array('id'),
63             'unique keys' => array(
64                 'user_group_uri_key' => array('uri'),
65             ),
66             'foreign keys' => array(
67                 'user_group_id_fkey' => array('profile', array('profile_id' => 'id')),
68             ),
69             'indexes' => array(
70                 'user_group_nickname_idx' => array('nickname'),
71                 'user_group_profile_id_idx' => array('profile_id'), //make this unique in future
72             ),
73         );
74     }
75
76     protected $_profile = null;
77
78     /**
79      * @return Profile
80      *
81      * @throws UserNoProfileException if user has no profile
82      */
83     public function getProfile()
84     {
85         if (!($this->_profile instanceof Profile)) {
86             $this->_profile = Profile::getKV('id', $this->profile_id);
87             if (!($this->_profile instanceof Profile)) {
88                 throw new GroupNoProfileException($this);
89             }
90         }
91
92         return $this->_profile;
93     }
94
95     public static function defaultLogo($size)
96     {
97         static $sizenames = array(AVATAR_PROFILE_SIZE => 'profile',
98                                   AVATAR_STREAM_SIZE => 'stream',
99                                   AVATAR_MINI_SIZE => 'mini');
100         return Theme::path('default-avatar-'.$sizenames[$size].'.png');
101     }
102
103     function homeUrl()
104     {
105         $url = null;
106         if (Event::handle('StartUserGroupHomeUrl', array($this, &$url))) {
107             // normally stored in mainpage, but older ones may be null
108             if (!empty($this->mainpage)) {
109                 $url = $this->mainpage;
110             } else {
111                 $url = common_local_url('showgroup',
112                                         array('nickname' => $this->nickname));
113             }
114         }
115         Event::handle('EndUserGroupHomeUrl', array($this, &$url));
116         return $url;
117     }
118
119     function getUri()
120     {
121         $uri = null;
122         if (Event::handle('StartUserGroupGetUri', array($this, &$uri))) {
123             if (!empty($this->uri)) {
124                 $uri = $this->uri;
125             } else {
126                 $uri = common_local_url('groupbyid',
127                                         array('id' => $this->id));
128             }
129         }
130         Event::handle('EndUserGroupGetUri', array($this, &$uri));
131         return $uri;
132     }
133
134     function permalink()
135     {
136         $url = null;
137         if (Event::handle('StartUserGroupPermalink', array($this, &$url))) {
138             $url = common_local_url('groupbyid',
139                                     array('id' => $this->id));
140         }
141         Event::handle('EndUserGroupPermalink', array($this, &$url));
142         return $url;
143     }
144
145     function getNotices($offset, $limit, $since_id=null, $max_id=null)
146     {
147         $stream = new GroupNoticeStream($this);
148
149         return $stream->getNotices($offset, $limit, $since_id, $max_id);
150     }
151
152     function getMembers($offset=0, $limit=null) {
153         $ids = null;
154         if (is_null($limit) || $offset + $limit > User_group::CACHE_WINDOW) {
155             $ids = $this->getMemberIDs($offset,
156                                        $limit);
157         } else {
158             $key = sprintf('group:member_ids:%d', $this->id);
159             $window = self::cacheGet($key);
160             if ($window === false) {
161                 $window = $this->getMemberIDs(0,
162                                               User_group::CACHE_WINDOW);
163                 self::cacheSet($key, $window);
164             }
165
166             $ids = array_slice($window,
167                                $offset,
168                                $limit);
169         }
170
171         return Profile::multiGet('id', $ids);
172     }
173
174     function getMemberIDs($offset=0, $limit=null)
175     {
176         $gm = new Group_member();
177
178         $gm->selectAdd();
179         $gm->selectAdd('profile_id');
180
181         $gm->group_id = $this->id;
182
183         $gm->orderBy('created DESC');
184
185         if (!is_null($limit)) {
186             $gm->limit($offset, $limit);
187         }
188
189         $ids = array();
190
191         if ($gm->find()) {
192             while ($gm->fetch()) {
193                 $ids[] = $gm->profile_id;
194             }
195         }
196
197         return $ids;
198     }
199
200     /**
201      * Get pending members, who have not yet been approved.
202      *
203      * @param int $offset
204      * @param int $limit
205      * @return Profile
206      */
207     function getRequests($offset=0, $limit=null)
208     {
209         $qry =
210           'SELECT profile.* ' .
211           'FROM profile JOIN group_join_queue '.
212           'ON profile.id = group_join_queue.profile_id ' .
213           'WHERE group_join_queue.group_id = %d ' .
214           'ORDER BY group_join_queue.created DESC ';
215
216         if ($limit != null) {
217             if (common_config('db','type') == 'pgsql') {
218                 $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
219             } else {
220                 $qry .= ' LIMIT ' . $offset . ', ' . $limit;
221             }
222         }
223
224         $members = new Profile();
225
226         $members->query(sprintf($qry, $this->id));
227         return $members;
228     }
229
230     public function getAdminCount()
231     {
232         return $this->getAdmins()->N;
233     }
234
235     public function getMemberCount()
236     {
237         $key = sprintf("group:member_count:%d", $this->id);
238
239         $cnt = self::cacheGet($key);
240
241         if (is_integer($cnt)) {
242             return (int) $cnt;
243         }
244
245         $mem = new Group_member();
246         $mem->group_id = $this->id;
247
248         // XXX: why 'distinct'?
249
250         $cnt = (int) $mem->count('distinct profile_id');
251
252         self::cacheSet($key, $cnt);
253
254         return $cnt;
255     }
256
257     function getBlockedCount()
258     {
259         // XXX: WORM cache this
260
261         $block = new Group_block();
262         $block->group_id = $this->id;
263
264         return $block->count();
265     }
266
267     function getQueueCount()
268     {
269         // XXX: WORM cache this
270
271         $queue = new Group_join_queue();
272         $queue->group_id = $this->id;
273
274         return $queue->count();
275     }
276
277     function getAdmins($offset=0, $limit=null)
278     {
279         $qry =
280           'SELECT profile.* ' .
281           'FROM profile JOIN group_member '.
282           'ON profile.id = group_member.profile_id ' .
283           'WHERE group_member.group_id = %d ' .
284           'AND group_member.is_admin = 1 ' .
285           'ORDER BY group_member.modified ASC ';
286
287         if ($limit != null) {
288             if (common_config('db','type') == 'pgsql') {
289                 $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
290             } else {
291                 $qry .= ' LIMIT ' . $offset . ', ' . $limit;
292             }
293         }
294
295         $admins = new Profile();
296
297         $admins->query(sprintf($qry, $this->id));
298         return $admins;
299     }
300
301     function getBlocked($offset=0, $limit=null)
302     {
303         $qry =
304           'SELECT profile.* ' .
305           'FROM profile JOIN group_block '.
306           'ON profile.id = group_block.blocked ' .
307           'WHERE group_block.group_id = %d ' .
308           'ORDER BY group_block.modified DESC ';
309
310         if ($limit != null) {
311             if (common_config('db','type') == 'pgsql') {
312                 $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
313             } else {
314                 $qry .= ' LIMIT ' . $offset . ', ' . $limit;
315             }
316         }
317
318         $blocked = new Profile();
319
320         $blocked->query(sprintf($qry, $this->id));
321         return $blocked;
322     }
323
324     function setOriginal($filename)
325     {
326         $imagefile = new ImageFile($this->id, Avatar::path($filename));
327
328         $orig = clone($this);
329         $this->original_logo = Avatar::url($filename);
330         $this->homepage_logo = Avatar::url($imagefile->resize(AVATAR_PROFILE_SIZE));
331         $this->stream_logo = Avatar::url($imagefile->resize(AVATAR_STREAM_SIZE));
332         $this->mini_logo = Avatar::url($imagefile->resize(AVATAR_MINI_SIZE));
333         common_debug(common_log_objstring($this));
334         return $this->update($orig);
335     }
336
337     function getBestName()
338     {
339         return ($this->fullname) ? $this->fullname : $this->nickname;
340     }
341
342     /**
343      * Gets the full name (if filled) with nickname as a parenthetical, or the nickname alone
344      * if no fullname is provided.
345      *
346      * @return string
347      */
348     function getFancyName()
349     {
350         if ($this->fullname) {
351             // TRANS: Full name of a profile or group followed by nickname in parens
352             return sprintf(_m('FANCYNAME','%1$s (%2$s)'), $this->fullname, $this->nickname);
353         } else {
354             return $this->nickname;
355         }
356     }
357
358     function getAliases()
359     {
360         $aliases = array();
361
362         // XXX: cache this
363
364         $alias = new Group_alias();
365
366         $alias->group_id = $this->id;
367
368         if ($alias->find()) {
369             while ($alias->fetch()) {
370                 $aliases[] = $alias->alias;
371             }
372         }
373
374         $alias->free();
375
376         return $aliases;
377     }
378
379     function setAliases($newaliases) {
380
381         $newaliases = array_unique($newaliases);
382
383         $oldaliases = $this->getAliases();
384
385         // Delete stuff that's old that not in new
386
387         $to_delete = array_diff($oldaliases, $newaliases);
388
389         // Insert stuff that's in new and not in old
390
391         $to_insert = array_diff($newaliases, $oldaliases);
392
393         $alias = new Group_alias();
394
395         $alias->group_id = $this->id;
396
397         foreach ($to_delete as $delalias) {
398             $alias->alias = $delalias;
399             $result = $alias->delete();
400             if (!$result) {
401                 common_log_db_error($alias, 'DELETE', __FILE__);
402                 return false;
403             }
404         }
405
406         foreach ($to_insert as $insalias) {
407             if ($insalias === $this->nickname) {
408                 continue;
409             }
410             $alias->alias = Nickname::normalize($insalias, true);
411             $result = $alias->insert();
412             if (!$result) {
413                 common_log_db_error($alias, 'INSERT', __FILE__);
414                 return false;
415             }
416         }
417
418         return true;
419     }
420
421     static function getForNickname($nickname, $profile=null)
422     {
423         $nickname = Nickname::normalize($nickname);
424
425         // Are there any matching remote groups this profile's in?
426         if ($profile) {
427             $group = $profile->getGroups(0, null);
428             while ($group->fetch()) {
429                 if ($group->nickname == $nickname) {
430                     // @fixme is this the best way?
431                     return clone($group);
432                 }
433             }
434         }
435
436         // If not, check local groups.
437
438         $group = Local_group::getKV('nickname', $nickname);
439         if (!empty($group)) {
440             return User_group::getKV('id', $group->group_id);
441         }
442         $alias = Group_alias::getKV('alias', $nickname);
443         if (!empty($alias)) {
444             return User_group::getKV('id', $alias->group_id);
445         }
446         return null;
447     }
448
449     function getUserMembers()
450     {
451         // XXX: cache this
452
453         $user = new User();
454         if(common_config('db','quote_identifiers'))
455             $user_table = '"user"';
456         else $user_table = 'user';
457
458         $qry =
459           'SELECT id ' .
460           'FROM '. $user_table .' JOIN group_member '.
461           'ON '. $user_table .'.id = group_member.profile_id ' .
462           'WHERE group_member.group_id = %d ';
463
464         $user->query(sprintf($qry, $this->id));
465
466         $ids = array();
467
468         while ($user->fetch()) {
469             $ids[] = $user->id;
470         }
471
472         $user->free();
473
474         return $ids;
475     }
476
477     static function maxDescription()
478     {
479         $desclimit = common_config('group', 'desclimit');
480         // null => use global limit (distinct from 0!)
481         if (is_null($desclimit)) {
482             $desclimit = common_config('site', 'textlimit');
483         }
484         return $desclimit;
485     }
486
487     static function descriptionTooLong($desc)
488     {
489         $desclimit = self::maxDescription();
490         return ($desclimit > 0 && !empty($desc) && (mb_strlen($desc) > $desclimit));
491     }
492
493     function asAtomEntry($namespace=false, $source=false)
494     {
495         $xs = new XMLStringer(true);
496
497         if ($namespace) {
498             $attrs = array('xmlns' => 'http://www.w3.org/2005/Atom',
499                            'xmlns:thr' => 'http://purl.org/syndication/thread/1.0');
500         } else {
501             $attrs = array();
502         }
503
504         $xs->elementStart('entry', $attrs);
505
506         if ($source) {
507             $xs->elementStart('source');
508             $xs->element('id', null, $this->permalink());
509             $xs->element('title', null, $profile->nickname . " - " . common_config('site', 'name'));
510             $xs->element('link', array('href' => $this->permalink()));
511             $xs->element('updated', null, $this->modified);
512             $xs->elementEnd('source');
513         }
514
515         $xs->element('title', null, $this->nickname);
516         $xs->element('summary', null, common_xml_safe_str($this->description));
517
518         $xs->element('link', array('rel' => 'alternate',
519                                    'href' => $this->permalink()));
520
521         $xs->element('id', null, $this->permalink());
522
523         $xs->element('published', null, common_date_w3dtf($this->created));
524         $xs->element('updated', null, common_date_w3dtf($this->modified));
525
526         $xs->element(
527             'content',
528             array('type' => 'html'),
529             common_xml_safe_str($this->description)
530         );
531
532         $xs->elementEnd('entry');
533
534         return $xs->getString();
535     }
536
537     function asAtomAuthor()
538     {
539         $xs = new XMLStringer(true);
540
541         $xs->elementStart('author');
542         $xs->element('name', null, $this->nickname);
543         $xs->element('uri', null, $this->permalink());
544         $xs->elementEnd('author');
545
546         return $xs->getString();
547     }
548
549     /**
550      * Returns an XML string fragment with group information as an
551      * Activity Streams noun object with the given element type.
552      *
553      * Assumes that 'activity', 'georss', and 'poco' namespace has been
554      * previously defined.
555      *
556      * @param string $element one of 'actor', 'subject', 'object', 'target'
557      *
558      * @return string
559      */
560     function asActivityNoun($element)
561     {
562         $noun = ActivityObject::fromGroup($this);
563         return $noun->asString('activity:' . $element);
564     }
565
566     function getAvatar()
567     {
568         return empty($this->homepage_logo)
569             ? User_group::defaultLogo(AVATAR_PROFILE_SIZE)
570             : $this->homepage_logo;
571     }
572
573     static function register($fields) {
574         if (!empty($fields['userid'])) {
575             $profile = Profile::getKV('id', $fields['userid']);
576             if ($profile && !$profile->hasRight(Right::CREATEGROUP)) {
577                 common_log(LOG_WARNING, "Attempted group creation from banned user: " . $profile->nickname);
578
579                 // TRANS: Client exception thrown when a user tries to create a group while banned.
580                 throw new ClientException(_('You are not allowed to create groups on this site.'), 403);
581             }
582         }
583
584         $fields['nickname'] = Nickname::normalize($fields['nickname']);
585
586         // MAGICALLY put fields into current scope
587         // @fixme kill extract(); it makes debugging absurdly hard
588
589                 $defaults = array('nickname' => null,
590                                                   'fullname' => null,
591                                                   'homepage' => null,
592                                                   'description' => null,
593                                                   'location' => null,
594                                                   'uri' => null,
595                                                   'mainpage' => null,
596                                                   'aliases' => array(),
597                                                   'userid' => null);
598                 
599                 $fields = array_merge($defaults, $fields);
600                 
601         extract($fields);
602
603         $group = new User_group();
604
605         if (empty($uri)) {
606             // fill in later...
607             $uri = null;
608         }
609         if (empty($mainpage)) {
610             $mainpage = common_local_url('showgroup', array('nickname' => $nickname));
611         }
612
613         // We must create a new, incrementally assigned profile_id
614         $profile = new Profile();
615         $profile->nickname   = $nickname;
616         $profile->fullname   = $fullname;
617         $profile->profileurl = $mainpage;
618         $profile->homepage   = $homepage;
619         $profile->bio        = $description;
620         $profile->location   = $location;
621         $profile->created    = common_sql_now();
622
623         $group->nickname    = $profile->nickname;
624         $group->fullname    = $profile->fullname;
625         $group->homepage    = $profile->homepage;
626         $group->description = $profile->bio;
627         $group->location    = $profile->location;
628         $group->mainpage    = $profile->profileurl;
629         $group->created     = $profile->created;
630
631         $profile->query('BEGIN');
632         $id = $profile->insert();
633         if ($id === false) {
634             $profile->query('ROLLBACK');
635             throw new ServerException(_('Profile insertion failed'));
636         }
637
638         $group->profile_id = $id;
639         $group->uri        = $uri;
640
641         if (isset($fields['join_policy'])) {
642             $group->join_policy = intval($fields['join_policy']);
643         } else {
644             $group->join_policy = 0;
645         }
646
647         if (isset($fields['force_scope'])) {
648             $group->force_scope = intval($fields['force_scope']);
649         } else {
650             $group->force_scope = 0;
651         }
652
653         if (Event::handle('StartGroupSave', array(&$group))) {
654
655             $result = $group->insert();
656
657             if ($result === false) {
658                 common_log_db_error($group, 'INSERT', __FILE__);
659                 // TRANS: Server exception thrown when creating a group failed.
660                 throw new ServerException(_('Could not create group.'));
661             }
662
663             if (!isset($uri) || empty($uri)) {
664                 $orig = clone($group);
665                 $group->uri = common_local_url('groupbyid', array('id' => $group->id));
666                 $result = $group->update($orig);
667                 if (!$result) {
668                     common_log_db_error($group, 'UPDATE', __FILE__);
669                     // TRANS: Server exception thrown when updating a group URI failed.
670                     throw new ServerException(_('Could not set group URI.'));
671                 }
672             }
673
674             $result = $group->setAliases($aliases);
675
676             if (!$result) {
677                 // TRANS: Server exception thrown when creating group aliases failed.
678                 throw new ServerException(_('Could not create aliases.'));
679             }
680
681             $member = new Group_member();
682
683             $member->group_id   = $group->id;
684             $member->profile_id = $userid;
685             $member->is_admin   = 1;
686             $member->created    = $group->created;
687
688             $result = $member->insert();
689
690             if (!$result) {
691                 common_log_db_error($member, 'INSERT', __FILE__);
692                 // TRANS: Server exception thrown when setting group membership failed.
693                 throw new ServerException(_('Could not set group membership.'));
694             }
695
696             self::blow('profile:groups:%d', $userid);
697             
698             if ($local) {
699                 $local_group = new Local_group();
700
701                 $local_group->group_id = $group->id;
702                 $local_group->nickname = $nickname;
703                 $local_group->created  = common_sql_now();
704
705                 $result = $local_group->insert();
706
707                 if (!$result) {
708                     common_log_db_error($local_group, 'INSERT', __FILE__);
709                     // TRANS: Server exception thrown when saving local group information failed.
710                     throw new ServerException(_('Could not save local group info.'));
711                 }
712             }
713
714             Event::handle('EndGroupSave', array($group));
715         }
716
717         $profile->query('COMMIT');
718
719         return $group;
720     }
721
722     /**
723      * Handle cascading deletion, on the model of notice and profile.
724      *
725      * This should handle freeing up cached entries for the group's
726      * id, nickname, URI, and aliases. There may be other areas that
727      * are not de-cached in the UI, including the sidebar lists on
728      * GroupsAction
729      */
730     function delete($useWhere=false)
731     {
732         if (empty($this->id)) {
733             common_log(LOG_WARNING, "Ambiguous User_group->delete(); skipping related tables.");
734             return parent::delete($useWhere);
735         }
736
737         try {
738             $profile = $this->getProfile();
739             $profile->delete();
740         } catch (GroupNoProfileException $unp) {
741             common_log(LOG_INFO, "Group {$this->nickname} has no profile; continuing deletion.");
742         }
743
744         // Safe to delete in bulk for now
745
746         $related = array('Group_inbox',
747                          'Group_block',
748                          'Group_member',
749                          'Related_group');
750
751         Event::handle('UserGroupDeleteRelated', array($this, &$related));
752
753         foreach ($related as $cls) {
754             $inst = new $cls();
755             $inst->group_id = $this->id;
756
757             if ($inst->find()) {
758                 while ($inst->fetch()) {
759                     $dup = clone($inst);
760                     $dup->delete();
761                 }
762             }
763         }
764
765         // And related groups in the other direction...
766         $inst = new Related_group();
767         $inst->related_group_id = $this->id;
768         $inst->delete();
769
770         // Aliases and the local_group entry need to be cleared explicitly
771         // or we'll miss clearing some cache keys; that can make it hard
772         // to create a new group with one of those names or aliases.
773         $this->setAliases(array());
774         $local = Local_group::getKV('group_id', $this->id);
775         if ($local instanceof Local_group) {
776             $local->delete();
777         }
778
779         // blow the cached ids
780         self::blow('user_group:notice_ids:%d', $this->id);
781
782         return parent::delete($useWhere);
783     }
784
785     public function update($dataObject=false)
786     {
787         // Whenever the User_group is updated, find the Local_group
788         // and update its nickname too.
789         if ($this->nickname != $dataObject->nickname) {
790             $local = Local_group::getKV('group_id', $this->id);
791             if ($local instanceof Local_group) {
792                 common_debug("Updating Local_group ({$this->id}) nickname from {$dataObject->nickname} to {$this->nickname}");
793                 $local->setNickname($this->nickname);
794             }
795         }
796
797         // Also make sure the Profile table is up to date!
798         $fields = array(/*group field => profile field*/
799                     'nickname'      => 'nickname',
800                     'fullname'      => 'fullname',
801                     'mainpage'      => 'profileurl',
802                     'homepage'      => 'homepage',
803                     'description'   => 'bio',
804                     'location'      => 'location',
805                     'created'       => 'created',
806                     'modified'      => 'modified',
807                     );
808         $profile = $this->getProfile();
809         $origpro = clone($profile);
810         foreach ($fields as $gf=>$pf) {
811             $profile->$pf = $this->$gf;
812         }
813         if ($profile->update($origpro) === false) {
814             throw new ServerException(_('Unable to update profile'));
815         }
816
817         return parent::update($dataObject);
818     }
819
820     function isPrivate()
821     {
822         return ($this->join_policy == self::JOIN_POLICY_MODERATE &&
823                 $this->force_scope == 1);
824     }
825 }