test path fixes

This commit is contained in:
Dennis Eichhorn 2020-03-28 16:27:03 +01:00
parent 7dc06860a6
commit bc9eca06df
8 changed files with 60 additions and 54 deletions

View File

@ -15,6 +15,7 @@ declare(strict_types=1);
namespace Modules\Tasks\Models; namespace Modules\Tasks\Models;
use Modules\Admin\Models\Account; use Modules\Admin\Models\Account;
use Modules\Admin\Models\NullAccount;
/** /**
* Task relation to account * Task relation to account
@ -29,33 +30,33 @@ class AccountRelation extends RelationAbstract
/** /**
* Relation object * Relation object
* *
* @var int|Account * @var Account
* @since 1.0.0 * @since 1.0.0
*/ */
private $relation = null; private Account $relation;
/** /**
* Constructor. * Constructor.
* *
* @param int|Account $account Account * @param null|Account $account Account
* @param int $duty Duty type * @param int $duty Duty type
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function __construct($account = 0, int $duty = DutyType::TO) public function __construct(Account $account = null, int $duty = DutyType::TO)
{ {
$this->relation = $account; $this->relation = $account ?? new NullAccount();
$this->duty = $duty; $this->duty = $duty;
} }
/** /**
* Get relation object. * Get relation object.
* *
* @return int|Account * @return Account
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function getRelation() public function getRelation() : Account
{ {
return $this->relation; return $this->relation;
} }

View File

@ -15,6 +15,7 @@ declare(strict_types=1);
namespace Modules\Tasks\Models; namespace Modules\Tasks\Models;
use Modules\Admin\Models\Group; use Modules\Admin\Models\Group;
use Modules\Admin\Models\NullGroup;
/** /**
* Task relation to group * Task relation to group
@ -29,33 +30,33 @@ class GroupRelation extends RelationAbstract
/** /**
* Relation object * Relation object
* *
* @var int|Group * @var Group
* @since 1.0.0 * @since 1.0.0
*/ */
private $relation = null; private Group $relation;
/** /**
* Constructor. * Constructor.
* *
* @param int|Group $group Group * @param null|Group $group Group
* @param int $duty Duty type * @param int $duty Duty type
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function __construct($group = 0, int $duty = DutyType::TO) public function __construct(Group $group = null, int $duty = DutyType::TO)
{ {
$this->relation = $group; $this->relation = $group ?? new NullGroup();
$this->duty = $duty; $this->duty = $duty;
} }
/** /**
* Get relation object. * Get relation object.
* *
* @return int|Group * @return Group
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function getRelation() public function getRelation() : Group
{ {
return $this->relation; return $this->relation;
} }

View File

@ -358,10 +358,8 @@ class TaskElement implements \JsonSerializable
public function isToAccount(int $id) : bool public function isToAccount(int $id) : bool
{ {
foreach ($this->accRelation as $acc) { foreach ($this->accRelation as $acc) {
if (($acc->getDuty() === DutyType::TO if ($acc->getDuty() === DutyType::TO
&& ($acc->getRelation() instanceof Account) && $acc->getRelation()->getId() === $id) && $acc->getRelation()->getId() === $id
|| ($acc->getDuty() === DutyType::TO
&& $acc->getRelation() === $id)
) { ) {
return true; return true;
} }
@ -382,10 +380,8 @@ class TaskElement implements \JsonSerializable
public function isToGroup(int $id) : bool public function isToGroup(int $id) : bool
{ {
foreach ($this->grpRelation as $grp) { foreach ($this->grpRelation as $grp) {
if (($grp->getDuty() === DutyType::TO if ($grp->getDuty() === DutyType::TO
&& ($grp->getRelation() instanceof Group) && $grp->getRelation()->getId() === $id) && $grp->getRelation()->getId() === $id
|| ($grp->getDuty() === DutyType::TO
&& $grp->getRelation() === $id)
) { ) {
return true; return true;
} }
@ -406,10 +402,8 @@ class TaskElement implements \JsonSerializable
public function isCCAccount(int $id) : bool public function isCCAccount(int $id) : bool
{ {
foreach ($this->accRelation as $acc) { foreach ($this->accRelation as $acc) {
if (($acc->getDuty() === DutyType::CC if ($acc->getDuty() === DutyType::CC
&& ($acc->getRelation() instanceof Account) && $acc->getRelation()->getId() === $id) && $acc->getRelation()->getId() === $id
|| ($acc->getDuty() === DutyType::CC
&& $acc->getRelation() === $id)
) { ) {
return true; return true;
} }
@ -430,10 +424,8 @@ class TaskElement implements \JsonSerializable
public function isCCGroup(int $id) : bool public function isCCGroup(int $id) : bool
{ {
foreach ($this->grpRelation as $grp) { foreach ($this->grpRelation as $grp) {
if (($grp->getDuty() === DutyType::CC if ($grp->getDuty() === DutyType::CC
&& ($grp->getRelation() instanceof Group) && $grp->getRelation()->getId() === $id) && $grp->getRelation()->getId() === $id
|| ($grp->getDuty() === DutyType::CC
&& $grp->getRelation() === $id)
) { ) {
return true; return true;
} }
@ -474,7 +466,7 @@ class TaskElement implements \JsonSerializable
$groupId = $group->getId(); $groupId = $group->getId();
foreach ($this->grpRelation as $grp) { foreach ($this->grpRelation as $grp) {
$grpId = !\is_int($grp->getRelation()) ? $grp->getRelation()->getId() : $grp->getRelation(); $grpId = $grp->getRelation()->getId();
if ($grpId === $groupId && $grp->getDuty() === DutyType::TO) { if ($grpId === $groupId && $grp->getDuty() === DutyType::TO) {
return; return;
@ -498,7 +490,7 @@ class TaskElement implements \JsonSerializable
$accountId = $account->getId(); $accountId = $account->getId();
foreach ($this->accRelation as $acc) { foreach ($this->accRelation as $acc) {
$accId = !\is_int($acc->getRelation()) ? $acc->getRelation()->getId() : $acc->getRelation(); $accId = $acc->getRelation()->getId();
if ($accId === $accountId && $acc->getDuty() === DutyType::TO) { if ($accId === $accountId && $acc->getDuty() === DutyType::TO) {
return; return;
@ -566,7 +558,7 @@ class TaskElement implements \JsonSerializable
$groupId = $group->getId(); $groupId = $group->getId();
foreach ($this->grpRelation as $grp) { foreach ($this->grpRelation as $grp) {
$grpId = !\is_int($grp->getRelation()) ? $grp->getRelation()->getId() : $grp->getRelation(); $grpId = $grp->getRelation()->getId();
if ($grpId === $groupId && $grp->getDuty() === DutyType::CC) { if ($grpId === $groupId && $grp->getDuty() === DutyType::CC) {
return; return;
@ -590,7 +582,7 @@ class TaskElement implements \JsonSerializable
$accountId = $account->getId(); $accountId = $account->getId();
foreach ($this->accRelation as $acc) { foreach ($this->accRelation as $acc) {
$accId = !\is_int($acc->getRelation()) ? $acc->getRelation()->getId() : $acc->getRelation(); $accId = $acc->getRelation()->getId();
if ($accId === $accountId && $acc->getDuty() === DutyType::CC) { if ($accId === $accountId && $acc->getDuty() === DutyType::CC) {
return; return;

View File

@ -19,6 +19,7 @@ use Modules\Calendar\Models\ScheduleMapper;
use Modules\Media\Models\MediaMapper; use Modules\Media\Models\MediaMapper;
use phpOMS\DataStorage\Database\DataMapperAbstract; use phpOMS\DataStorage\Database\DataMapperAbstract;
use phpOMS\DataStorage\Database\Query\Builder; use phpOMS\DataStorage\Database\Query\Builder;
use phpOMS\DataStorage\Database\RelationType;
/** /**
* Mapper class. * Mapper class.
@ -131,6 +132,14 @@ final class TaskMapper extends DataMapperAbstract
*/ */
protected static string $primaryField = 'task_id'; protected static string $primaryField = 'task_id';
/**
* {@inheritdoc}
*/
public static function get($primaryKey, int $relations = RelationType::ALL, int $depth = 3, string $ref = null, Builder $query = null)
{
return parent::get($primaryKey, $relations, $depth, $ref, $query);
}
/** /**
* Get open tasks by createdBy * Get open tasks by createdBy
* *
@ -142,9 +151,10 @@ final class TaskMapper extends DataMapperAbstract
*/ */
public static function getOpenCreatedBy(int $user) : array public static function getOpenCreatedBy(int $user) : array
{ {
$depth = 3;
$query = self::getQuery(); $query = self::getQuery();
$query->where(self::$table . '.task_created_by', '=', $user) $query->where(self::$table . '_' . $depth . '.task_created_by', '=', $user)
->where(self::$table . '.task_status', '=', TaskStatus::OPEN); ->where(self::$table . '_' . $depth . '.task_status', '=', TaskStatus::OPEN);
return self::getAllByQuery($query); return self::getAllByQuery($query);
} }
@ -160,12 +170,13 @@ final class TaskMapper extends DataMapperAbstract
*/ */
public static function getOpenTo(int $user) : array public static function getOpenTo(int $user) : array
{ {
$depth = 3;
$query = self::getQuery(); $query = self::getQuery();
$query->innerJoin(TaskElementMapper::getTable()) $query->innerJoin(TaskElementMapper::getTable())
->on(self::$table . '.task_id', '=', TaskElementMapper::getTable() . '.task_element_task') ->on(self::$table . '.task_id', '=', TaskElementMapper::getTable() . '.task_element_task')
->innerJoin(AccountRelationMapper::getTable()) ->innerJoin(AccountRelationMapper::getTable())
->on(TaskElementMapper::getTable() . '.task_element_id', '=', AccountRelationMapper::getTable() . '.task_account_task_element') ->on(TaskElementMapper::getTable() . '.task_element_id', '=', AccountRelationMapper::getTable() . '.task_account_task_element')
->where(self::$table . '.task_status', '=', TaskStatus::OPEN) ->where(self::$table . '_' . $depth . '.task_status', '=', TaskStatus::OPEN)
->andWhere(AccountRelationMapper::getTable() . '.task_account_account', '=', $user) ->andWhere(AccountRelationMapper::getTable() . '.task_account_account', '=', $user)
->andWhere(AccountRelationMapper::getTable() . '.task_account_duty', '=', DutyType::TO); ->andWhere(AccountRelationMapper::getTable() . '.task_account_duty', '=', DutyType::TO);
@ -183,12 +194,13 @@ final class TaskMapper extends DataMapperAbstract
*/ */
public static function getOpenAny(int $user) : array public static function getOpenAny(int $user) : array
{ {
$depth = 3;
$query = self::getQuery(); $query = self::getQuery();
$query->innerJoin(TaskElementMapper::getTable()) $query->innerJoin(TaskElementMapper::getTable())
->on(self::$table . '.task_id', '=', TaskElementMapper::getTable() . '.task_element_task') ->on(self::$table . '.task_id', '=', TaskElementMapper::getTable() . '.task_element_task')
->innerJoin(AccountRelationMapper::getTable()) ->innerJoin(AccountRelationMapper::getTable())
->on(TaskElementMapper::getTable() . '.task_element_id', '=', AccountRelationMapper::getTable() . '.task_account_task_element') ->on(TaskElementMapper::getTable() . '.task_element_id', '=', AccountRelationMapper::getTable() . '.task_account_task_element')
->where(self::$table . '.task_status', '=', TaskStatus::OPEN) ->where(self::$table . '_' . $depth . '.task_status', '=', TaskStatus::OPEN)
->andWhere(AccountRelationMapper::getTable() . '.task_account_account', '=', $user); ->andWhere(AccountRelationMapper::getTable() . '.task_account_account', '=', $user);
return self::getAllByQuery($query); return self::getAllByQuery($query);
@ -205,12 +217,13 @@ final class TaskMapper extends DataMapperAbstract
*/ */
public static function getOpenCC(int $user) : array public static function getOpenCC(int $user) : array
{ {
$depth = 3;
$query = self::getQuery(); $query = self::getQuery();
$query->innerJoin(TaskElementMapper::getTable()) $query->innerJoin(TaskElementMapper::getTable())
->on(self::$table . '.task_id', '=', TaskElementMapper::getTable() . '.task_element_task') ->on(self::$table . '.task_id', '=', TaskElementMapper::getTable() . '.task_element_task')
->innerJoin(AccountRelationMapper::getTable()) ->innerJoin(AccountRelationMapper::getTable())
->on(TaskElementMapper::getTable() . '.task_element_id', '=', AccountRelationMapper::getTable() . '.task_account_task_element') ->on(TaskElementMapper::getTable() . '.task_element_id', '=', AccountRelationMapper::getTable() . '.task_account_task_element')
->where(self::$table . '.task_status', '=', TaskStatus::OPEN) ->where(self::$table . '_' . $depth . '.task_status', '=', TaskStatus::OPEN)
->andWhere(AccountRelationMapper::getTable() . '.task_account_account', '=', $user) ->andWhere(AccountRelationMapper::getTable() . '.task_account_account', '=', $user)
->andWhere(AccountRelationMapper::getTable() . '.task_account_duty', '=', DutyType::CC); ->andWhere(AccountRelationMapper::getTable() . '.task_account_duty', '=', DutyType::CC);
@ -228,8 +241,9 @@ final class TaskMapper extends DataMapperAbstract
*/ */
public static function getCreatedBy(int $user) : array public static function getCreatedBy(int $user) : array
{ {
$depth = 3;
$query = self::getQuery(); $query = self::getQuery();
$query->where(self::$table . '.task_created_by', '=', $user); $query->where(self::$table . '_' . $depth . '.task_created_by', '=', $user);
return self::getAllByQuery($query); return self::getAllByQuery($query);
} }

View File

@ -14,8 +14,6 @@ declare(strict_types=1);
namespace Modules\Task\tests; namespace Modules\Task\tests;
require_once __DIR__ . '/../../tests/Autoloader.php';
use Model\CoreSettings; use Model\CoreSettings;
use Modules\Admin\Models\AccountPermission; use Modules\Admin\Models\AccountPermission;

View File

@ -14,8 +14,6 @@ declare(strict_types=1);
namespace Modules\Task\tests; namespace Modules\Task\tests;
require_once __DIR__ . '/../../tests/Autoloader.php';
use Model\CoreSettings; use Model\CoreSettings;
use Modules\Admin\Models\AccountPermission; use Modules\Admin\Models\AccountPermission;
use Modules\Tasks\Models\TaskPriority; use Modules\Tasks\Models\TaskPriority;

View File

@ -14,6 +14,7 @@ declare(strict_types=1);
namespace Modules\Tasks\tests\Models; namespace Modules\Tasks\tests\Models;
use Modules\Admin\Models\NullAccount;
use Modules\Tasks\Models\AccountRelation; use Modules\Tasks\Models\AccountRelation;
use Modules\Tasks\Models\DutyType; use Modules\Tasks\Models\DutyType;
@ -26,20 +27,20 @@ class AccountRelationTest extends \PHPUnit\Framework\TestCase
{ {
$obj = new AccountRelation(); $obj = new AccountRelation();
self::assertEquals(0, $obj->getId()); self::assertEquals(0, $obj->getId());
self::assertEquals(0, $obj->getRelation()); self::assertEquals(0, $obj->getRelation()->getId());
self::assertEquals(DutyType::TO, $obj->getDuty()); self::assertEquals(DutyType::TO, $obj->getDuty());
} }
public function testSetGet() : void public function testSetGet() : void
{ {
$obj = new AccountRelation(1, DutyType::CC); $obj = new AccountRelation($a = new NullAccount(1), DutyType::CC);
self::assertEquals(1, $obj->getRelation()); self::assertEquals(1, $obj->getRelation()->getId());
self::assertEquals(DutyType::CC, $obj->getDuty()); self::assertEquals(DutyType::CC, $obj->getDuty());
self::assertEquals([ self::assertEquals([
'id' => 0, 'id' => 0,
'duty' => DutyType::CC, 'duty' => DutyType::CC,
'relation' => 1, 'relation' => $a,
], $obj->toArray()); ], $obj->toArray());
self::assertEquals($obj->toArray(), $obj->jsonSerialize()); self::assertEquals($obj->toArray(), $obj->jsonSerialize());

View File

@ -14,6 +14,7 @@ declare(strict_types=1);
namespace Modules\Tasks\tests\Models; namespace Modules\Tasks\tests\Models;
use Modules\Admin\Models\NullGroup;
use Modules\Tasks\Models\DutyType; use Modules\Tasks\Models\DutyType;
use Modules\Tasks\Models\GroupRelation; use Modules\Tasks\Models\GroupRelation;
@ -26,20 +27,20 @@ class GroupRelationTest extends \PHPUnit\Framework\TestCase
{ {
$obj = new GroupRelation(); $obj = new GroupRelation();
self::assertEquals(0, $obj->getId()); self::assertEquals(0, $obj->getId());
self::assertEquals(0, $obj->getRelation()); self::assertEquals(0, $obj->getRelation()->getId());
self::assertEquals(DutyType::TO, $obj->getDuty()); self::assertEquals(DutyType::TO, $obj->getDuty());
} }
public function testSetGet() : void public function testSetGet() : void
{ {
$obj = new GroupRelation(1, DutyType::CC); $obj = new GroupRelation($g = new NullGroup(1), DutyType::CC);
self::assertEquals(1, $obj->getRelation()); self::assertEquals(1, $obj->getRelation()->getId());
self::assertEquals(DutyType::CC, $obj->getDuty()); self::assertEquals(DutyType::CC, $obj->getDuty());
self::assertEquals([ self::assertEquals([
'id' => 0, 'id' => 0,
'duty' => DutyType::CC, 'duty' => DutyType::CC,
'relation' => 1, 'relation' => $g,
], $obj->toArray()); ], $obj->toArray());
self::assertEquals($obj->toArray(), $obj->jsonSerialize()); self::assertEquals($obj->toArray(), $obj->jsonSerialize());