username => source */ public array $members = []; /** @var string[] addresses or @domain */ public array $sendAs = []; /** @var array[] {owner, rights, subscribe, state, last_error}: members may open these mailboxes (ACL group=mcg_) */ public array $imapGrants = []; /** @var array[] {owner, type, folder, access, subscribe, state, last_error}: SOGo folders shared with the members */ public array $sogoGrants = []; /** @var array[] warnings of the last write (msg values), not stored */ public array $warnings = []; /** Builds a group from a `mailbox_group` row (`template_name` optional) */ public static function fromRow(array $row): self { $group = new self(); $group->id = isset($row['id']) ? (int)$row['id'] : null; $group->domain = (string)($row['domain'] ?? ''); $group->name = (string)($row['name'] ?? ''); $group->description = (string)($row['description'] ?? ''); $group->address = isset($row['address']) ? (string)$row['address'] : null; $group->senderAllowed = (int)($row['sender_allowed'] ?? 0); $group->sogoVisible = (int)($row['sogo_visible'] ?? 0); $group->internal = (int)($row['internal'] ?? 0); $group->templateId = isset($row['template_id']) ? (int)$row['template_id'] : null; $group->template = isset($row['template_name']) ? (string)$row['template_name'] : null; $group->priority = (int)($row['priority'] ?? 0); $group->idpRef = isset($row['idp_ref']) ? (string)$row['idp_ref'] : null; $group->active = (int)($row['active'] ?? 1); $group->created = isset($row['created']) ? (string)$row['created'] : null; $group->modified = isset($row['modified']) ? (string)$row['modified'] : null; return $group; } /** @return string[] */ public function usernames(): array { return array_keys($this->members); } /** API representation (GET mailbox-group) */ public function toArray(bool $canEdit): array { $members = []; foreach ($this->members as $username => $source) { $members[] = ['username' => (string)$username, 'source' => $source]; } return [ 'id' => $this->id, 'domain' => $this->domain, 'name' => $this->name, 'description' => $this->description, 'address' => $this->address, 'sender_allowed' => $this->senderAllowed, 'sogo_visible' => $this->sogoVisible, 'internal' => $this->internal, 'template_id' => $this->templateId, 'template' => $this->template, 'priority' => $this->priority, 'idp_ref' => $this->idpRef, 'members' => $members, 'send_as' => $this->sendAs, 'imap_grants' => $this->imapGrants, 'sogo_grants' => $this->sogoGrants, 'active' => $this->active, 'created' => $this->created, 'modified' => $this->modified, 'can_edit' => $canEdit, ]; } }