Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 protected function getDefaultAttributes($user)
 {
     $attributes = parent::getDefaultAttributes($user);
     $canEdit = $user->can($this->actor, 'edit');
     $attributes += ['bio' => $user->bio, 'joinTime' => $user->join_time ? $user->join_time->toRFC3339String() : null, 'discussionsCount' => (int) $user->discussions_count, 'commentsCount' => (int) $user->comments_count, 'canEdit' => $canEdit, 'canDelete' => $user->can($this->actor, 'delete')];
     if ($user->getPreference('discloseOnline')) {
         $attributes += ['lastSeenTime' => $user->last_seen_time ? $user->last_seen_time->toRFC3339String() : null];
     }
     if ($canEdit || $this->actor->id === $user->id) {
         $attributes += ['isActivated' => $user->is_activated, 'email' => $user->email];
     }
     return $attributes;
 }
Beispiel #2
0
 /**
  * Serialize attributes of a User model for JSON output.
  *
  * @param User $user The User model to serialize.
  * @return array
  */
 protected function attributes($user)
 {
     $attributes = parent::attributes($user);
     $actorUser = $this->actor->getUser();
     $canEdit = $user->can($actorUser, 'edit');
     $attributes += ['bioHtml' => $user->bio_html, 'joinTime' => $user->join_time ? $user->join_time->toRFC3339String() : null, 'discussionsCount' => (int) $user->discussions_count, 'commentsCount' => (int) $user->comments_count, 'canEdit' => $canEdit, 'canDelete' => $user->can($actorUser, 'delete')];
     if ($user->preference('discloseOnline')) {
         $attributes += ['lastSeenTime' => $user->last_seen_time ? $user->last_seen_time->toRFC3339String() : null];
     }
     if ($canEdit) {
         $attributes += ['bio' => $user->bio, 'isActivated' => $user->is_activated, 'email' => $user->email, 'isConfirmed' => $user->is_confirmed];
     }
     if ($user->id === $actorUser->id) {
         $attributes += ['readTime' => $user->read_time ? $user->read_time->toRFC3339String() : null, 'unreadNotificationsCount' => $user->getUnreadNotificationsCount(), 'preferences' => $user->preferences];
     }
     return $this->extendAttributes($user, $attributes);
 }