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;
use Modules\Admin\Models\Account;
use Modules\Admin\Models\NullAccount;
/**
* Task relation to account
@ -29,33 +30,33 @@ class AccountRelation extends RelationAbstract
/**
* Relation object
*
* @var int|Account
* @var Account
* @since 1.0.0
*/
private $relation = null;
private Account $relation;
/**
* Constructor.
*
* @param int|Account $account Account
* @param int $duty Duty type
* @param null|Account $account Account
* @param int $duty Duty type
*
* @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;
}
/**
* Get relation object.
*
* @return int|Account
* @return Account
*
* @since 1.0.0
*/
public function getRelation()
public function getRelation() : Account
{
return $this->relation;
}

View File

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

View File

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

View File

@ -19,6 +19,7 @@ use Modules\Calendar\Models\ScheduleMapper;
use Modules\Media\Models\MediaMapper;
use phpOMS\DataStorage\Database\DataMapperAbstract;
use phpOMS\DataStorage\Database\Query\Builder;
use phpOMS\DataStorage\Database\RelationType;
/**
* Mapper class.
@ -131,6 +132,14 @@ final class TaskMapper extends DataMapperAbstract
*/
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
*
@ -142,9 +151,10 @@ final class TaskMapper extends DataMapperAbstract
*/
public static function getOpenCreatedBy(int $user) : array
{
$depth = 3;
$query = self::getQuery();
$query->where(self::$table . '.task_created_by', '=', $user)
->where(self::$table . '.task_status', '=', TaskStatus::OPEN);
$query->where(self::$table . '_' . $depth . '.task_created_by', '=', $user)
->where(self::$table . '_' . $depth . '.task_status', '=', TaskStatus::OPEN);
return self::getAllByQuery($query);
}
@ -160,12 +170,13 @@ final class TaskMapper extends DataMapperAbstract
*/
public static function getOpenTo(int $user) : array
{
$depth = 3;
$query = self::getQuery();
$query->innerJoin(TaskElementMapper::getTable())
->on(self::$table . '.task_id', '=', TaskElementMapper::getTable() . '.task_element_task')
->innerJoin(AccountRelationMapper::getTable())
->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_duty', '=', DutyType::TO);
@ -183,12 +194,13 @@ final class TaskMapper extends DataMapperAbstract
*/
public static function getOpenAny(int $user) : array
{
$depth = 3;
$query = self::getQuery();
$query->innerJoin(TaskElementMapper::getTable())
->on(self::$table . '.task_id', '=', TaskElementMapper::getTable() . '.task_element_task')
->innerJoin(AccountRelationMapper::getTable())
->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);
return self::getAllByQuery($query);
@ -205,12 +217,13 @@ final class TaskMapper extends DataMapperAbstract
*/
public static function getOpenCC(int $user) : array
{
$depth = 3;
$query = self::getQuery();
$query->innerJoin(TaskElementMapper::getTable())
->on(self::$table . '.task_id', '=', TaskElementMapper::getTable() . '.task_element_task')
->innerJoin(AccountRelationMapper::getTable())
->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_duty', '=', DutyType::CC);
@ -228,8 +241,9 @@ final class TaskMapper extends DataMapperAbstract
*/
public static function getCreatedBy(int $user) : array
{
$depth = 3;
$query = self::getQuery();
$query->where(self::$table . '.task_created_by', '=', $user);
$query->where(self::$table . '_' . $depth . '.task_created_by', '=', $user);
return self::getAllByQuery($query);
}

View File

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

View File

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

View File

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

View File

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