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 2 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
59 changes: 12 additions & 47 deletions include/class.project.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,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 Eindeutige Mitgliedsnummer
* @param int $status Bearbeitungsstatus von Projekten (1 = offenes Projekt)
Expand All @@ -394,60 +394,25 @@ function getMyProjects($user, $status = 1)

$myprojekte = array();
$user = (int) $user;
$status = (int) $status;

$sel = $conn->prepare("SELECT projekt FROM projekte_assigned WHERE user = ? ORDER BY ID ASC");
//$sel = $conn->prepare("SELECT projekt FROM projekte_assigned WHERE user = ? ORDER BY ID ASC");
$sel = $conn->prepare("SELECT projekte.ID
FROM projekte LEFT join projekte_assigned
ON projekte.ID=projekte_assigned.projekt
WHERE user=? AND status=$status
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im Prinzip könnte man die query auch direkt ohne prepare abfeuern, der Typ von user wird ja vorher geprüft, so dass da keine insertion möglich ist.

ORDER BY name"); // you may apply id here, but i prefere sorting by name
$selStmt = $sel->execute(array($user));

while ($projs = $sel->fetch()) {
$projekt = $conn->query("SELECT ID FROM projekte WHERE ID = " . $projs[0] . " AND status={$conn->quote((int) $status)}")->fetch();
if ($projekt) {
$project = $this->getProject($projekt["ID"]);
array_push($myprojekte, $project);
}
}

if (!empty($myprojekte)) {
// Sort projects by due date ascending
$date = array();
foreach ($myprojekte as $key => $row) {
$date[$key] = $row['end'];
}
array_multisort($date, SORT_ASC, $myprojekte);

return $myprojekte;
} else {
return false;
while ($proj = $sel->fetch()) {
$project = $this->getProject($proj["ID"]);
array_push($myprojekte, $project);
}
}

/**
* Lists all project IDs assigned to a user
*
* @param int $user ID of the user
* @return array $myprojekte Project IDs for user
*/
function getMyProjectIds($user)
{
global $conn;

$myprojekte = array();
$sel = $conn->prepare("SELECT projekt FROM projekte_assigned WHERE user = ? ORDER BY end ASC");
$selStmt = $sel->execute(array($user));

if ($sel) {
while ($projs = $sel->fetch()) {
$sel2 = $conn->query("SELECT ID FROM projekte WHERE ID = " . $projs[0]);
$projekt = $sel2->fetch();
if ($projekt) {
array_push($myprojekte, $projekt);
}
}
}
if (!empty($myprojekte)) {
return $myprojekte;
} else {
return false;
}
return false;
}

/**
Expand Down