Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort and simplify #34

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
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
26 changes: 13 additions & 13 deletions include/class.project.php
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,7 @@ function getProjects($status = 1, $lim = 10)
$projectIdStmt->execute(array($status));

while ($projectId = $projectIdStmt->fetch()) {
$project = $this->getProject($projectId["ID"]);
array_push($projects, $project);
$projects[] = $this->getProject($projectId["ID"]); // unneeded array_push would create overhead
}

if (!empty($projects)) {
Expand All @@ -473,7 +472,7 @@ function getProjects($status = 1, $lim = 10)
}

/**
* Lists all projects assigned to a given member ordered by due date ascending
* Lists all projects assigned to a given member ordered by name ascending
*
* @param int $user User id
* @param int $status Status of a project (1= open, 0 = closed)
Expand All @@ -493,16 +492,17 @@ function getMyProjects($user, $status = 1, $offset = 0, $limit = 10)

//$sel = $conn->prepare("SELECT projekt FROM projekte_assigned WHERE user = ? ORDER BY ID ASC LIMIT $offset,$limit ");

//get the projekt IDs of projects assigned to this user
$selAssigned = $conn->query("SELECT projekt, status FROM projekte_assigned JOIN projekte ON projekte.ID = projekte_assigned.projekt WHERE user = $user AND projekte.status = $status ORDER BY projekt DESC LIMIT $limit OFFSET $offset");

$projectsAssigned = $selAssigned->fetchAll();

//loop by reference and assign the project details to eahc project
foreach ($projectsAssigned as $project) {
if (!empty($project[0])) {
array_push($myProjects,$this->getProject($project[0]));
}
$selAssigned = $conn->prepare("SELECT projekte.ID
FROM projekte LEFT JOIN projekte_assigned
ON projekte.ID = projekte_assigned.projekt
WHERE user=? AND status=?
ORDER BY name
LIMIT $limit
OFFSET $offset"); // you may apply id here, but i prefere sorting by name
$selStmt = $selAssigned->execute(array($user,$status));

while ($project = $selAssigned->fetch()) {
$myProjects[] = $this->getProject($project["ID"]); // useless array_push would create overhead
}

if (!empty($myProjects)) {
Expand Down