File tree Expand file tree Collapse file tree 5 files changed +96
-2
lines changed Expand file tree Collapse file tree 5 files changed +96
-2
lines changed Original file line number Diff line number Diff line change 22
33namespace AuroraWebSoftware \AIssue \Contracts ;
44
5+ use AuroraWebSoftware \AIssue \Models \AIssue ;
56use AuroraWebSoftware \Connective \Collections \ConnectiveCollection ;
67use AuroraWebSoftware \Connective \Contracts \ConnectiveContract ;
78use Illuminate \Database \Query \Builder ;
1112 */
1213interface IssueOwnerModelContract extends ConnectiveContract
1314{
15+ public function ownIssue (AIssue $ issue ): void ;
16+
17+ public function disownIssue (AIssue $ issue ): void ;
18+
1419 /**
1520 * ConnectiveCollection<AIssue>
1621 */
17- public function getOwningIssues (): ConnectiveCollection ;
22+ public function getOwningIssues (): ? ConnectiveCollection ;
1823
1924 /**
2025 * ConnectiveCollection<AIssue>
2126 */
22- public function scopeAllOwningIssues (Builder $ query ): ConnectiveCollection ;
27+ public function scopeAllOwningIssues (Builder $ query ): ? ConnectiveCollection ;
2328}
Original file line number Diff line number Diff line change 88use AuroraWebSoftware \ACalendar \Models \Event ;
99use AuroraWebSoftware \ACalendar \Traits \HasEvents ;
1010use AuroraWebSoftware \AIssue \Contracts \IssueActorModelContract ;
11+ use AuroraWebSoftware \AIssue \Contracts \IssueOwnerModelContract ;
1112use AuroraWebSoftware \ArFlow \Contacts \StateableModelContract ;
1213use AuroraWebSoftware \ArFlow \Traits \HasState ;
1314use AuroraWebSoftware \Connective \Collections \ConnectiveCollection ;
@@ -180,4 +181,23 @@ public function removeAllObservers(): void
180181 $ observer ->delete ();
181182 }
182183 }
184+
185+ public function getOwnerModel (): IssueOwnerModelContract |Model |null
186+ {
187+ return $ this ->connectives ('issue_owner_model ' )?->first();
188+ }
189+
190+ /**
191+ * @throws ConnectionTypeNotSupportedException
192+ * @throws ConnectionTypeException
193+ */
194+ public function setOwnerModel (IssueActorModelContract &Model $ issueOwnerModel ): void
195+ {
196+ if ($ this ->connections ('issue_owner_model ' )) {
197+ $ this ->connections ('issue_owner_model ' )
198+ ->each (fn (Model $ connection ) => $ connection ->delete ());
199+ }
200+
201+ $ this ->connectTo ($ issueOwnerModel , 'issue_owner_model ' );
202+ }
183203}
Original file line number Diff line number Diff line change 33namespace AuroraWebSoftware \AIssue \Traits ;
44
55use AuroraWebSoftware \AIssue \Contracts \IssueOwnerModelContract ;
6+ use AuroraWebSoftware \AIssue \Models \AIssue ;
67use AuroraWebSoftware \Connective \Collections \ConnectiveCollection ;
8+ use AuroraWebSoftware \Connective \Exceptions \ConnectionTypeException ;
9+ use AuroraWebSoftware \Connective \Exceptions \ConnectionTypeNotSupportedException ;
10+ use Illuminate \Database \Query \Builder ;
711
812trait AIssueOwner
913{
14+ /**
15+ * @throws ConnectionTypeNotSupportedException
16+ * @throws ConnectionTypeException
17+ */
18+ public function ownIssue (AIssue $ issue ): void
19+ {
20+ $ issue ->connectTo ($ this , 'issue_owner_model ' );
21+ }
22+
23+ public function disownIssue (AIssue $ issue ): void
24+ {
25+ // todo
26+ foreach ($ this ->getOwningIssues () ?? [] as $ issueItem ) {
27+ if ($ issue ->getId () === $ issueItem ->getId ()) {
28+ $ issue ->connections ('issue_owner_model ' )->delete ();
29+ break ;
30+ }
31+ }
32+ }
33+
1034 /**
1135 * ConnectiveCollection<AIssue>
1236 */
@@ -18,4 +42,10 @@ public function getOwningIssues(): ConnectiveCollection
1842
1943 return $ this ->inverseConnectives ('issue_owner_model ' );
2044 }
45+
46+ public function scopeAllOwningIssues (Builder $ query ): ?ConnectiveCollection
47+ {
48+ // todo will be implemented
49+ return ConnectiveCollection::make ();
50+ }
2151}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace AuroraWebSoftware \AIssue \Tests \Models ;
4+
5+ use AuroraWebSoftware \AIssue \Contracts \IssueOwnerModelContract ;
6+ use AuroraWebSoftware \AIssue \Traits \AIssueOwner ;
7+ use AuroraWebSoftware \Connective \Traits \Connective ;
8+ use Illuminate \Database \Eloquent \Model ;
9+
10+ /**
11+ * @property string $name
12+ *
13+ * @method static ExampleIssueOwner create(array $attributes = [])
14+ */
15+ class ExampleIssueOwner extends Model implements IssueOwnerModelContract
16+ {
17+ use AIssueOwner;
18+ use Connective;
19+
20+ protected $ guarded = [];
21+
22+ public static function supportedConnectionTypes (): array
23+ {
24+ return [];
25+ }
26+ }
Original file line number Diff line number Diff line change 11<?php
22
33use AuroraWebSoftware \AIssue \Models \AIssue ;
4+ use AuroraWebSoftware \AIssue \Tests \Models \ExampleIssueOwner ;
45use AuroraWebSoftware \AIssue \Tests \Models \User ;
56use AuroraWebSoftware \Connective \Contracts \ConnectiveContract ;
67use Illuminate \Database \Schema \Blueprint ;
1920 $ table ->timestamps ();
2021 });
2122
23+ Schema::create ('example_issue_owners ' , function (Blueprint $ table ) {
24+ $ table ->id ();
25+ $ table ->string ('name ' );
26+ $ table ->timestamps ();
27+ });
28+
2229 $ classArflow = require __DIR__ .'/../../vendor/aurorawebsoftware/arflow/database/migrations/create_arflow_history_table.php ' ;
2330 (new $ classArflow )->up ();
2431
192199
193200 expect ($ issue ->currentState ())->toEqual ('state2 ' );
194201
202+ $ exampleIssueOwner1 = ExampleIssueOwner::create (['name ' => 'example issue owner 1 ' ]);
203+ $ exampleIssueOwner1 ->ownIssue ($ issue );
204+ expect ($ exampleIssueOwner1 ->getOwningIssues ())->toHaveCount (1 );
205+
206+ // todo delete kısmı yazılmadı henüz
207+
195208});
You can’t perform that action at this time.
0 commit comments