WebMonetization.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. declare(strict_types = 1);
  3. namespace Plugin\WebMonetization\Entity;
  4. use App\Core\Entity;
  5. class WebMonetization extends Entity
  6. {
  7. // These tags are meant to be literally included and will be populated with the appropriate fields, setters and getters by `bin/generate_entity_fields`
  8. // {{{ Autocode
  9. // @codeCoverageIgnoreStart
  10. private int $id;
  11. private int $sender;
  12. private int $receiver;
  13. private float $sent;
  14. private bool $active;
  15. public function setId(int $id): self
  16. {
  17. $this->id = $id;
  18. return $this;
  19. }
  20. public function getId(): int
  21. {
  22. return $this->id;
  23. }
  24. public function setSender(int $sender): self
  25. {
  26. $this->sender = $sender;
  27. return $this;
  28. }
  29. public function getSender(): int
  30. {
  31. return $this->sender;
  32. }
  33. public function setReceiver(int $receiver): self
  34. {
  35. $this->receiver = $receiver;
  36. return $this;
  37. }
  38. public function getReceiver(): int
  39. {
  40. return $this->receiver;
  41. }
  42. public function setSent(float $sent): self
  43. {
  44. $this->sent = $sent;
  45. return $this;
  46. }
  47. public function getSent(): float
  48. {
  49. return $this->sent;
  50. }
  51. public function setActive(bool $active): self
  52. {
  53. $this->active = $active;
  54. return $this;
  55. }
  56. public function getActive(): bool
  57. {
  58. return $this->active;
  59. }
  60. // @codeCoverageIgnoreEnd
  61. // }}} Autocode
  62. public function getNotificationTargetIds(array $ids_already_known = [], ?int $sender_id = null, bool $include_additional = true): array
  63. {
  64. if (\array_key_exists('object', $ids_already_known)) {
  65. $target_ids = $ids_already_known['object'];
  66. } else {
  67. $target_ids = [$this->getReceiver()];
  68. }
  69. // Additional actors that should know about this
  70. if ($include_additional && \array_key_exists('additional', $ids_already_known)) {
  71. array_push($target_ids, ...$ids_already_known['additional']);
  72. return array_unique($target_ids);
  73. }
  74. return $target_ids;
  75. }
  76. public static function schemaDef()
  77. {
  78. return [
  79. 'name' => 'webmonetization',
  80. 'fields' => [
  81. 'id' => ['type' => 'serial', 'not null' => true, 'description' => 'unique identifier'],
  82. 'sender' => ['type' => 'int', 'foreign key' => true, 'target' => 'Actor.id', 'multiplicity' => 'many to one', 'not null' => true, 'description' => 'actor sending money'],
  83. 'receiver' => ['type' => 'int', 'foreign key' => true, 'target' => 'Actor.id', 'multiplicity' => 'many to one', 'not null' => true, 'description' => 'actor receiving money'],
  84. 'sent' => ['type' => 'float', 'not null' => true, 'description' => 'how much sender has sent to receiver'],
  85. 'active' => ['type' => 'bool', 'not null' => true, 'description' => 'whether it should donate'],
  86. ],
  87. 'primary key' => ['id'],
  88. ];
  89. }
  90. }