|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is a part of the DiscordPHP project. |
| 5 | + * |
| 6 | + * Copyright (c) 2015-present David Cole <david.cole1340@gmail.com> |
| 7 | + * |
| 8 | + * This file is subject to the MIT license that is bundled |
| 9 | + * with this source code in the LICENSE.md file. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Discord\Parts\Channel; |
| 13 | + |
| 14 | +use Discord\Parts\Guild\Guild; |
| 15 | +use Discord\Parts\Part; |
| 16 | + |
| 17 | +/** |
| 18 | + * A Stage Instance holds information about a live stage. on a Discord guild. |
| 19 | + * |
| 20 | + * @property string $id The unique identifier of the Stage Instance. |
| 21 | + * @property string $guild_id The unique identifier of the guild that the stage instance associated to. |
| 22 | + * @property Guild $guild The guild that the stage instance associated to. |
| 23 | + * @property string $channel_id The id of the associated Stage channel. |
| 24 | + * @property Channel $channel The channel that the stage instance associated to. |
| 25 | + * @property string $topic The topic of the Stage instance (1-120 characters). |
| 26 | + * @property int $privacy_level The privacy level of the Stage instance. |
| 27 | + * @property bool $discoverable_disabled Whether or not Stage Discovery is disabled. |
| 28 | + */ |
| 29 | +class StageInstance extends Part |
| 30 | +{ |
| 31 | + public const PRIVACY_LEVEL_PUBLIC = 1; |
| 32 | + public const PRIVACY_LEVEL_GROUP_ONLY = 2; |
| 33 | + |
| 34 | + /** |
| 35 | + * @inheritdoc |
| 36 | + */ |
| 37 | + protected $fillable = [ |
| 38 | + 'id', |
| 39 | + 'guild_id', |
| 40 | + 'channel_id', |
| 41 | + 'topic', |
| 42 | + 'privacy_level', |
| 43 | + 'discoverable_disabled', |
| 44 | + ]; |
| 45 | + |
| 46 | + /** |
| 47 | + * Returns the guild attribute. |
| 48 | + * |
| 49 | + * @return Guild The guild attribute. |
| 50 | + */ |
| 51 | + protected function getGuildAttribute(): Guild |
| 52 | + { |
| 53 | + return $this->discord->guilds->get('id', $this->guild_id); |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * Returns the channel attribute. |
| 58 | + * |
| 59 | + * @return Channel The Stage channel. |
| 60 | + */ |
| 61 | + protected function getChannelAttribute(): Part |
| 62 | + { |
| 63 | + if ($channel = $this->discord->getChannel($this->channel_id)) { |
| 64 | + return $channel; |
| 65 | + } |
| 66 | + |
| 67 | + return $this->factory->create(Channel::class, [ |
| 68 | + 'id' => $this->channel_id, |
| 69 | + 'type' => Channel::TYPE_STAGE_CHANNEL, |
| 70 | + ], true); |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * @inheritdoc |
| 75 | + */ |
| 76 | + public function getCreatableAttributes(): array |
| 77 | + { |
| 78 | + return [ |
| 79 | + 'channel_id' => $this->channel_id, |
| 80 | + 'topic' => $this->topic, |
| 81 | + 'privacy_level' => $this->privacy_level, |
| 82 | + ]; |
| 83 | + } |
| 84 | + |
| 85 | + /** |
| 86 | + * @inheritdoc |
| 87 | + */ |
| 88 | + public function getUpdatableAttributes(): array |
| 89 | + { |
| 90 | + return [ |
| 91 | + 'topic' => $this->topic, |
| 92 | + 'privacy_level' => $this->privacy_level, |
| 93 | + ]; |
| 94 | + } |
| 95 | + |
| 96 | + /** |
| 97 | + * @inheritdoc |
| 98 | + */ |
| 99 | + public function getRepositoryAttributes(): array |
| 100 | + { |
| 101 | + return [ |
| 102 | + 'channel_id' => $this->channel_id, |
| 103 | + ]; |
| 104 | + } |
| 105 | +} |
0 commit comments