Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/Contracts/IssueOwnerModelContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace AuroraWebSoftware\AIssue\Contracts;

use AuroraWebSoftware\AIssue\Models\AIssue;
use AuroraWebSoftware\Connective\Collections\ConnectiveCollection;
use AuroraWebSoftware\Connective\Contracts\ConnectiveContract;
use Illuminate\Database\Query\Builder;
Expand All @@ -11,13 +12,17 @@
*/
interface IssueOwnerModelContract extends ConnectiveContract
{
public function ownIssue(AIssue $issue): void;

public function disownIssue(AIssue $issue): void;

/**
* ConnectiveCollection<AIssue>
*/
public function getOwningIssues(): ConnectiveCollection;
public function getOwningIssues(): ?ConnectiveCollection;

/**
* ConnectiveCollection<AIssue>
*/
public function scopeAllOwningIssues(Builder $query): ConnectiveCollection;
public function scopeAllOwningIssues(Builder $query): ?ConnectiveCollection;
}
20 changes: 20 additions & 0 deletions src/Models/AIssue.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use AuroraWebSoftware\ACalendar\Models\Event;
use AuroraWebSoftware\ACalendar\Traits\HasEvents;
use AuroraWebSoftware\AIssue\Contracts\IssueActorModelContract;
use AuroraWebSoftware\AIssue\Contracts\IssueOwnerModelContract;
use AuroraWebSoftware\ArFlow\Contacts\StateableModelContract;
use AuroraWebSoftware\ArFlow\Traits\HasState;
use AuroraWebSoftware\Connective\Collections\ConnectiveCollection;
Expand Down Expand Up @@ -180,4 +181,23 @@ public function removeAllObservers(): void
$observer->delete();
}
}

public function getOwnerModel(): IssueOwnerModelContract|Model|null
{
return $this->connectives('issue_owner_model')?->first();
}

/**
* @throws ConnectionTypeNotSupportedException
* @throws ConnectionTypeException
*/
public function setOwnerModel(IssueActorModelContract&Model $issueOwnerModel): void
{
if ($this->connections('issue_owner_model')) {
$this->connections('issue_owner_model')
->each(fn (Model $connection) => $connection->delete());
}

$this->connectTo($issueOwnerModel, 'issue_owner_model');
}
}
30 changes: 30 additions & 0 deletions src/Traits/AIssueOwner.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,34 @@
namespace AuroraWebSoftware\AIssue\Traits;

use AuroraWebSoftware\AIssue\Contracts\IssueOwnerModelContract;
use AuroraWebSoftware\AIssue\Models\AIssue;
use AuroraWebSoftware\Connective\Collections\ConnectiveCollection;
use AuroraWebSoftware\Connective\Exceptions\ConnectionTypeException;
use AuroraWebSoftware\Connective\Exceptions\ConnectionTypeNotSupportedException;
use Illuminate\Database\Query\Builder;

trait AIssueOwner
{
/**
* @throws ConnectionTypeNotSupportedException
* @throws ConnectionTypeException
*/
public function ownIssue(AIssue $issue): void
{
$issue->connectTo($this, 'issue_owner_model');
}

public function disownIssue(AIssue $issue): void
{
// todo
foreach ($this->getOwningIssues() ?? [] as $issueItem) {
if ($issue->getId() === $issueItem->getId()) {
$issue->connections('issue_owner_model')->delete();
break;
}
}
}

/**
* ConnectiveCollection<AIssue>
*/
Expand All @@ -18,4 +42,10 @@ public function getOwningIssues(): ConnectiveCollection

return $this->inverseConnectives('issue_owner_model');
}

public function scopeAllOwningIssues(Builder $query): ?ConnectiveCollection
{
// todo will be implemented
return ConnectiveCollection::make();
}
}
26 changes: 26 additions & 0 deletions tests/Models/ExampleIssueOwner.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace AuroraWebSoftware\AIssue\Tests\Models;

use AuroraWebSoftware\AIssue\Contracts\IssueOwnerModelContract;
use AuroraWebSoftware\AIssue\Traits\AIssueOwner;
use AuroraWebSoftware\Connective\Traits\Connective;
use Illuminate\Database\Eloquent\Model;

/**
* @property string $name
*
* @method static ExampleIssueOwner create(array $attributes = [])
*/
class ExampleIssueOwner extends Model implements IssueOwnerModelContract
{
use AIssueOwner;
use Connective;

protected $guarded = [];

public static function supportedConnectionTypes(): array
{
return [];
}
}
13 changes: 13 additions & 0 deletions tests/Unit/AIssueTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use AuroraWebSoftware\AIssue\Models\AIssue;
use AuroraWebSoftware\AIssue\Tests\Models\ExampleIssueOwner;
use AuroraWebSoftware\AIssue\Tests\Models\User;
use AuroraWebSoftware\Connective\Contracts\ConnectiveContract;
use Illuminate\Database\Schema\Blueprint;
Expand All @@ -19,6 +20,12 @@
$table->timestamps();
});

Schema::create('example_issue_owners', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->timestamps();
});

$classArflow = require __DIR__.'/../../vendor/aurorawebsoftware/arflow/database/migrations/create_arflow_history_table.php';
(new $classArflow)->up();

Expand Down Expand Up @@ -192,4 +199,10 @@

expect($issue->currentState())->toEqual('state2');

$exampleIssueOwner1 = ExampleIssueOwner::create(['name' => 'example issue owner 1']);
$exampleIssueOwner1->ownIssue($issue);
expect($exampleIssueOwner1->getOwningIssues())->toHaveCount(1);

// todo delete kısmı yazılmadı henüz

});