Skip to content

Commit

Permalink
Remove not needed counters from repos
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelfolaron committed Aug 29, 2024
1 parent 46a5179 commit f51cccb
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 52 deletions.
23 changes: 3 additions & 20 deletions app/Domain/Projects/Repositories/Projects.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,6 @@ public function getUserProjects(int $userId, string $projectStatus = "all", int

// Deprecated

/**
* @param $userId
* @param $status
* @param $clientId
* @return array|false
*/
/**
* @param $userId
* @param string $status
Expand All @@ -330,14 +324,12 @@ public function getProjectsUserHasAccessTo($userId, string $status = "all", stri
project.menuType,
project.type,
project.modified,
SUM(case when ticket.type <> 'milestone' then 1 else 0 end) as numberOfTickets,
client.name AS clientName,
client.id AS clientId,
IF(favorite.id IS NULL, false, true) as isFavorite
FROM zp_projects AS project
LEFT JOIN zp_relationuserproject as relation ON project.id = relation.projectId
LEFT JOIN zp_clients as client ON project.clientId = client.id
LEFT JOIN zp_tickets as ticket ON project.id = ticket.projectId
LEFT JOIN zp_reactions as favorite ON project.id = favorite.moduleId AND favorite.module = 'project' AND favorite.reaction = 'favorite' AND favorite.userId = :id
WHERE
( relation.userId = :id
Expand Down Expand Up @@ -435,12 +427,10 @@ public function getClientProjects($clientId): false|array
project.state,
project.menuType,
project.modified,
SUM(case when ticket.type <> 'milestone' AND ticket.type <> 'subtask' then 1 else 0 end) as numberOfTickets,
client.name AS clientName,
client.id AS clientId
FROM zp_projects as project
LEFT JOIN zp_clients as client ON project.clientId = client.id
LEFT JOIN zp_tickets as ticket ON project.id = ticket.projectId
WHERE
(project.active > '-1' OR project.active IS NULL)
AND clientId = :clientId
Expand Down Expand Up @@ -517,23 +507,16 @@ public function getProject($id): array|bool
zp_projects.parent,
zp_projects.modified,
zp_clients.name AS clientName,
zp_projects.start,
zp_projects.end,
SUM(case when zp_tickets.type <> 'milestone' then 1 else 0 end) as numberOfTickets,
SUM(case when zp_tickets.type = 'milestone' then 1 else 0 end) as numberMilestones,
COUNT(relation.projectId) AS numUsers,
COUNT(definitionCanvas.id) AS numDefinitionCanvas,
zp_projects.start,
zp_projects.end,
IF(favorite.id IS NULL, false, true) as isFavorite
FROM zp_projects
LEFT JOIN zp_tickets ON zp_projects.id = zp_tickets.projectId
LEFT JOIN zp_clients ON zp_projects.clientId = zp_clients.id
LEFT JOIN zp_relationuserproject as relation ON zp_projects.id = relation.projectId
LEFT JOIN zp_canvas as definitionCanvas ON zp_projects.id = definitionCanvas.projectId AND definitionCanvas.type NOT IN('idea', 'retroscanvas', 'goalcanvas', 'wiki')
LEFT JOIN zp_reactions as favorite ON zp_projects.id = favorite.moduleId
AND favorite.module = 'project'
AND favorite.reaction = 'favorite'
AND favorite.userId = :id
LEFT JOIN zp_user as requestingUser ON requestingUser.id = :id
LEFT JOIN zp_user as requestingUser ON requestingUser.id = :id
WHERE zp_projects.id = :projectId
GROUP BY
zp_projects.id,
Expand Down
6 changes: 4 additions & 2 deletions app/Domain/Projects/Services/Projects.php
Original file line number Diff line number Diff line change
Expand Up @@ -1322,13 +1322,14 @@ public function getProjectSetupChecklist($projectId): array
$progressSteps["define"]["tasks"]["description"]["status"] = "done";
}

/*
if ($project['numUsers'] > 1) {
$progressSteps["define"]["tasks"]["defineTeam"]["status"] = "done";
}
if ($project['numDefinitionCanvas'] >= 1) {
$progressSteps["define"]["tasks"]["createBlueprint"]["status"] = "done";
}
}*/

$goals = app()->make(GoalcanvaRepository::class);
$allCanvas = $goals->getAllCanvas($projectId);
Expand All @@ -1341,13 +1342,14 @@ public function getProjectSetupChecklist($projectId): array
$progressSteps["define"]["goals"]["setGoals"]["status"] = "done";
}

/*
if ($project['numberMilestones'] >= 1) {
$progressSteps["timeline"]["tasks"]["createMilestones"]["status"] = "done";
}
if ($project['numberOfTickets'] >= 1) {
$progressSteps["implementation"]["tasks"]["createTasks"]["status"] = "done";
}
}*/

$percentDone = $this->getProjectProgress($projectId);
if ($percentDone['percent'] >= 80) {
Expand Down
44 changes: 21 additions & 23 deletions app/Domain/Tickets/Repositories/Tickets.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,9 @@ public function getUsersTickets($id, $limit): false|array
* @param null $limit
* @return array | bool
*/
public function getAllBySearchCriteria(array $searchCriteria, string $sort = 'standard', $limit = null): bool|array
public function getAllBySearchCriteria(array $searchCriteria, string $sort = 'standard', $limit = null, $includeCounts = true): bool|array
{
$query = <<<SQL
$query = "
SELECT
zp_tickets.id,
zp_tickets.headline,
Expand All @@ -395,7 +395,7 @@ public function getAllBySearchCriteria(array $searchCriteria, string $sort = 'st
zp_tickets.dateToFinish,
zp_tickets.projectId,
zp_tickets.priority,
IF(zp_tickets.type <> "", zp_tickets.type, "task") AS type,
IF(zp_tickets.type <> '', zp_tickets.type, 'task') AS type,
zp_tickets.status,
zp_tickets.tags,
zp_tickets.editorId,
Expand All @@ -417,10 +417,23 @@ public function getAllBySearchCriteria(array $searchCriteria, string $sort = 'st
t2.lastname AS editorLastname,
t2.profileId AS editorProfileId,
milestone.headline AS milestoneHeadline,
IF((milestone.tags IS NULL OR milestone.tags = ''), 'var(--grey)', milestone.tags) AS milestoneColor,
(SELECT COUNT(*) FROM zp_comment WHERE zp_tickets.id = zp_comment.moduleId and zp_comment.module = 'ticket') AS commentCount,
(SELECT COUNT(*) FROM zp_file WHERE zp_tickets.id = zp_file.moduleId and zp_file.module = 'ticket') AS fileCount,
(SELECT COUNT(*) FROM zp_tickets AS subtasks WHERE zp_tickets.id = subtasks.dependingTicketId AND subtasks.dependingTicketId > 0) AS subtaskCount,
IF((milestone.tags IS NULL OR milestone.tags = ''), 'var(--grey)', milestone.tags) AS milestoneColor,";

if($includeCounts) {
$query .= "
(SELECT COUNT(*) FROM zp_comment WHERE zp_tickets.id = zp_comment.moduleId and zp_comment.module = 'ticket') AS commentCount,
(SELECT COUNT(*) FROM zp_file WHERE zp_tickets.id = zp_file.moduleId and zp_file.module = 'ticket') AS fileCount,
(SELECT COUNT(*) FROM zp_tickets AS subtasks WHERE zp_tickets.id = subtasks.dependingTicketId AND subtasks.dependingTicketId > 0) AS subtaskCount,
";
}else{
$query .= "
0 AS commentCount,
0 AS fileCount,
0 AS subtaskCount,
";
}

$query .= "
parent.headline AS parentHeadline
FROM
zp_tickets
Expand All @@ -438,7 +451,7 @@ public function getAllBySearchCriteria(array $searchCriteria, string $sort = 'st
OR (zp_projects.psettings = 'client' AND zp_projects.clientId = :clientId)
OR (requestor.role >= 40)
)
SQL;
";

if (isset($searchCriteria["excludeType"]) && $searchCriteria["excludeType"] != "") {
$query .= " AND zp_tickets.type <> :excludeType";
Expand Down Expand Up @@ -1723,21 +1736,6 @@ public function addTicket(array $values): bool|int
}


/**
* @param $id
* @param $params
* @return bool
*/
/**
* @param $id
* @param $params
* @return bool
*/
/**
* @param $id
* @param $params
* @return bool
*/
/**
* @param $id
* @param $params
Expand Down
29 changes: 22 additions & 7 deletions app/Domain/Tickets/Services/Tickets.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,10 @@ public function getSetFilters(array $searchCriteria, bool $includeGroup = false)
public function getAll(?array $searchCriteria = null): array|false
{
return $this->ticketRepository->getAllBySearchCriteria(
$searchCriteria ?? [],
$searchCriteria['orderBy'] ?? 'date'
searchCriteria: $searchCriteria ?? [],
sort: $searchCriteria['orderBy'] ?? 'date',
includeCounts: false

);
}

Expand Down Expand Up @@ -433,7 +435,8 @@ public function getAllOpenUserTickets(?int $userId = null, ?int $project = null)
$projectStatusLabels[$ticket['projectId']] = $this->ticketRepository->getStateLabels($ticket['projectId']);
}

if ($projectStatusLabels[$ticket['projectId']][$ticket['status']]["statusType"] !== "DONE") {
if (isset($projectStatusLabels[$ticket['projectId']][$ticket['status']]) &&
$projectStatusLabels[$ticket['projectId']][$ticket['status']]["statusType"] !== "DONE") {
$ticketArray[] = $ticket;
}
}
Expand Down Expand Up @@ -659,7 +662,10 @@ public function getOpenUserTicketsThisWeekAndLater($userId, $projectId, bool $in
$searchStatus = "not_done";
}
$searchCriteria = $this->prepareTicketSearchArray(array("currentProject" => $projectId, "currentUser" => $userId, "users" => $userId, "status" => $searchStatus, "sprint" => ""));
$allTickets = $this->ticketRepository->getAllBySearchCriteria($searchCriteria, "duedate");
$allTickets = $this->ticketRepository->getAllBySearchCriteria(
searchCriteria: $searchCriteria,
sort: "duedate",
includeCounts: false);

$statusLabels = $this->getAllStatusLabelsByUserId($userId);

Expand Down Expand Up @@ -757,7 +763,10 @@ public function getOpenUserTicketsByProject($userId, $projectId): array
{

$searchCriteria = $this->prepareTicketSearchArray(array("currentProject" => $projectId, "users" => $userId, "status" => "", "sprint" => ""));
$allTickets = $this->ticketRepository->getAllBySearchCriteria($searchCriteria, "duedate");
$allTickets = $this->ticketRepository->getAllBySearchCriteria(
searchCriteria: $searchCriteria,
sort: "duedate",
includeCounts: false);

$statusLabels = $this->getAllStatusLabelsByUserId($userId);

Expand Down Expand Up @@ -794,7 +803,10 @@ public function getOpenUserTicketsByPriority($userId, $projectId): array
{

$searchCriteria = $this->prepareTicketSearchArray(array("users" => $userId, "status" => "", "sprint" => ""));
$allTickets = $this->ticketRepository->getAllBySearchCriteria($searchCriteria, "priority");
$allTickets = $this->ticketRepository->getAllBySearchCriteria(
searchCriteria: $searchCriteria,
sort: "priority",
includeCounts: false);

$statusLabels = $this->getAllStatusLabelsByUserId($userId);

Expand Down Expand Up @@ -837,7 +849,10 @@ public function getOpenUserTicketsBySprint($userId, $projectId): array
{

$searchCriteria = $this->prepareTicketSearchArray(array("currentProject" => $projectId, "users" => $userId, "status" => "", "sprint" => ""));
$allTickets = $this->ticketRepository->getAllBySearchCriteria($searchCriteria, "duedate");
$allTickets = $this->ticketRepository->getAllBySearchCriteria(
searchCriteria: $searchCriteria,
sort: "duedate",
includeCounts: false);

$statusLabels = $this->getAllStatusLabelsByUserId($userId);

Expand Down

0 comments on commit f51cccb

Please sign in to comment.