PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.8.1
GiveWP – Donation Plugin and Fundraising Platform v4.16.8.1
4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 All 254 releases
give / src / Subscriptions / Models / SubscriptionNote.php

SubscriptionNote.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.8.1, at src/Subscriptions/Models/SubscriptionNote.php

137 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\Subscriptions\Models;
4
5 use DateTime;
6 use Give\Subscriptions\Factories\SubscriptionNoteFactory;
7 use Give\Subscriptions\ValueObjects\SubscriptionNoteType;
8 use Give\Framework\Exceptions\Primitives\Exception;
9 use Give\Framework\Exceptions\Primitives\InvalidArgumentException;
10 use Give\Framework\Models\Contracts\ModelCrud;
11 use Give\Framework\Models\Contracts\ModelHasFactory;
12 use Give\Framework\Models\Model;
13 use Give\Framework\Models\ModelQueryBuilder;
14 use Give\Framework\Models\ValueObjects\Relationship;
15 use Give\Subscriptions\DataTransferObjects\SubscriptionNoteQueryData;
16
17 /**
18 * @since 4.8.0
19 *
20 * @property int $id
21 * @property string $content
22 * @property int $subscriptionId
23 * @property SubscriptionNoteType $type
24 * @property DateTime $createdAt
25 * @property Subscription $subscription
26 */
27 class SubscriptionNote extends Model implements ModelCrud, ModelHasFactory
28 {
29 /**
30 * {@inheritdoc}
31 */
32 protected $properties = [
33 'id' => 'int',
34 'content' => 'string',
35 'subscriptionId' => 'int',
36 'type' => SubscriptionNoteType::class,
37 'createdAt' => DateTime::class,
38 ];
39
40 /**
41 * {@inheritdoc}
42 */
43 protected $relationships = [
44 'subscription' => Relationship::BELONGS_TO,
45 ];
46
47 /**
48 * @since 4.8.0
49 *
50 * @return SubscriptionNote|null
51 */
52 public static function find($id)
53 {
54 return give()->subscriptions->notes->getById($id);
55 }
56
57 /**
58 * @since 4.8.0
59 *
60 * @return $this
61 *
62 * @throws Exception|InvalidArgumentException
63 */
64 public static function create(array $attributes): SubscriptionNote
65 {
66 $subscriptionNote = new static($attributes);
67
68 give()->subscriptions->notes->insert($subscriptionNote);
69
70 return $subscriptionNote;
71 }
72
73 /**
74 * @since 4.8.0
75 *
76 * @return void
77 *
78 * @throws Exception|InvalidArgumentException
79 */
80 public function save()
81 {
82 if (! $this->id) {
83 give()->subscriptions->notes->insert($this);
84 } else {
85 give()->subscriptions->notes->update($this);
86 }
87 }
88
89 /**
90 * @since 4.8.0
91 *
92 * @throws Exception|InvalidArgumentException
93 */
94 public function delete(): bool
95 {
96 return give()->subscriptions->notes->delete($this);
97 }
98
99 /**
100 * @since 4.8.0
101 *
102 * @return ModelQueryBuilder<SubscriptionNote>
103 */
104 public static function query(): ModelQueryBuilder
105 {
106 return give()->subscriptions->notes->prepareQuery();
107 }
108
109 /**
110 * @since 4.8.0
111 *
112 * @return ModelQueryBuilder<Subscription>
113 */
114 public function subscription(): ModelQueryBuilder
115 {
116 return give()->subscriptions->queryById($this->subscriptionId);
117 }
118
119 /**
120 * @since 4.8.0
121 *
122 * @param object $object
123 */
124 public static function fromQueryBuilderObject($object): SubscriptionNote
125 {
126 return SubscriptionNoteQueryData::fromObject($object)->toSubscriptionNote();
127 }
128
129 /**
130 * @since 4.8.0
131 */
132 public static function factory(): SubscriptionNoteFactory
133 {
134 return new SubscriptionNoteFactory(static::class);
135 }
136 }
137