From 301f02eb2516c93ac54644f2086b9e7b31626757 Mon Sep 17 00:00:00 2001 From: Stephan Richter Date: Sat, 26 Oct 2013 00:08:40 +0200 Subject: [PATCH 1/4] =?UTF-8?q?Sortierung=20f=C3=BCr=20getMyProjects=20ge?= =?UTF-8?q?=C3=A4ndert.=20Dabei=20fiel=20auf,=20dass=20auch=20die=20Abfrag?= =?UTF-8?q?en=20in=20getMyProjectIds=20mit=20einem=20Join=20verbessert=20w?= =?UTF-8?q?erden=20k=C3=B6nnten.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/class.project.php | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/include/class.project.php b/include/class.project.php index 319f7cc6..d204f388 100644 --- a/include/class.project.php +++ b/include/class.project.php @@ -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) @@ -394,26 +394,18 @@ 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 order 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); - } + while ($proj = $sel->fetch()) { + $project = $this->getProject($proj["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; From a2660cb599c7358209bcd342b44ba297556c4751 Mon Sep 17 00:00:00 2001 From: Stephan Richter Date: Sun, 27 Oct 2013 21:12:14 +0100 Subject: [PATCH 2/4] imprved mysel queue within getMyProjects, removed getMyProjectIds which contained an invalud queue (projecte_assigned does not have a 'end' column) and is not used anywhere within collabtive. --- include/class.project.php | 41 +++++++-------------------------------- 1 file changed, 7 insertions(+), 34 deletions(-) diff --git a/include/class.project.php b/include/class.project.php index d204f388..b04a826e 100644 --- a/include/class.project.php +++ b/include/class.project.php @@ -397,49 +397,22 @@ function getMyProjects($user, $status = 1) $status = (int) $status; //$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 order by name"); + $sel = $conn->prepare("SELECT projekte.ID + FROM projekte LEFT join projekte_assigned + ON projekte.ID=projekte_assigned.projekt + WHERE user=? AND status=$status + ORDER BY name"); // you may apply id here, but i prefere sorting by name $selStmt = $sel->execute(array($user)); while ($proj = $sel->fetch()) { $project = $this->getProject($proj["ID"]); - array_push($myprojekte, $project); + array_push($myprojekte, $project); } if (!empty($myprojekte)) { return $myprojekte; - } else { - return false; - } - } - - /** - * 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; } /** From 3380cd7ffb17436bd274b618231a0a4c66736f2e Mon Sep 17 00:00:00 2001 From: Stephan Richter Date: Mon, 28 Oct 2013 09:10:05 +0100 Subject: [PATCH 3/4] replaced two occurences of array_push(...) by ...[] = ... --- include/class.project.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/include/class.project.php b/include/class.project.php index b04a826e..6a80ba06 100644 --- a/include/class.project.php +++ b/include/class.project.php @@ -370,8 +370,7 @@ function getProjects($status = 1, $lim = 10) $selStmt = $sel->execute(array($status)); while ($projekt = $sel->fetch()) { - $project = $this->getProject($projekt["ID"]); - array_push($projekte, $project); + $projekte[]=$this->getProject($projekt["ID"]); // unneeded array_push would create overhead } if (!empty($projekte)) { @@ -405,8 +404,7 @@ function getMyProjects($user, $status = 1) $selStmt = $sel->execute(array($user)); while ($proj = $sel->fetch()) { - $project = $this->getProject($proj["ID"]); - array_push($myprojekte, $project); + $myprojekte[] = $this->getProject($proj["ID"]); // useless array_push would create overhead } if (!empty($myprojekte)) { From 7b8cc6e19465365522e70343a7119150e1546e0f Mon Sep 17 00:00:00 2001 From: Stephan Richter Date: Tue, 9 Dec 2014 01:15:44 +0100 Subject: [PATCH 4/4] reverted sorting by due date --- include/class.project.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/include/class.project.php b/include/class.project.php index 6e304c80..3fd4f8df 100644 --- a/include/class.project.php +++ b/include/class.project.php @@ -384,13 +384,6 @@ function getMyProjects($user, $status = 1) } 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; } return false;