Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

Commit

Permalink
Update GetContributionList() with extra parameter for Weekly Report a…
Browse files Browse the repository at this point in the history
…nd extra code to change the table depending on $weeklyreport = true/false.

Add Wordcount and Part number on normal contribution listing AND weekly report listing.
Add GetUsername() to fetch the username from a user id (to be used in Weekly Reviews).
Implement GetSingleReport() to show a single weekly report with its comment and the corresponding contributions.
Implement Weekly Report view on weeklyreports.php.
  • Loading branch information
dimitrisp2 committed Oct 28, 2018
1 parent c26be19 commit f73a08d
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 9 deletions.
99 changes: 92 additions & 7 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,22 @@ function GetUserID($username) {
}
}

// Get the User of the id set in $userid
function GetUsername($userid) {
$result = mysqli_query($GLOBALS['sqlcon'], "SELECT `username` FROM `users` WHERE `id` = " . $userid);
if ($result) {
$userfound = mysqli_num_rows($result);
if ($userfound == 1) {
$row = mysqli_fetch_assoc($result);
return $row['username'];
} else {
return "notfound";
}
} else {
return "error";
}
}

// Get the ID of the project set in $project
function GetProjectID($project) {
$result = mysqli_query($GLOBALS['sqlcon'], "SELECT `id` FROM `projects` WHERE `name` = '" . $project . "'");
Expand Down Expand Up @@ -258,7 +274,7 @@ function AddContribution($project, $translator, $link, $created, $partno = NULL,
}
}

function GetContributionList($user = NULL, $project = NULL, $from = NULL, $to = NULL, $voted = NULL, $reviewed = NULL, $proofreader = NULL, $title = NULL) {
function GetContributionList($user = NULL, $project = NULL, $from = NULL, $to = NULL, $voted = NULL, $reviewed = NULL, $proofreader = NULL, $title = NULL, $weeklyreport = NULL) {
// $limit will be used if no other arguments are set.
$limit = "";
// prepare SQL action if any/all of the arguments are set.
Expand All @@ -269,34 +285,64 @@ function GetContributionList($user = NULL, $project = NULL, $from = NULL, $to =
$sqlaction = "";
$limit = " LIMIT " . $GLOBALS['contlimit'];
}

// Hack to show "AND" between two "WHERE" actions
$showand = FALSE;

if (!is_null($user)) {
$sqlaction = $sqlaction . "`c`.`translator` = " . $user . " ";
$showand = TRUE;
}

if (!is_null($project)) {
if ($showand == TRUE) {
$sqlaction .= "AND ";
}
$showand = TRUE;
$sqlaction = $sqlaction . "`c`.`project` = " . $project . " ";
}

if (!is_null($from)) {
$sqlaction = $sqlaction . "`c`.`submit` >= " . $from . " ";
if ($showand == TRUE) {

}
$showand = TRUE;
$sqlaction = $sqlaction . "`c`.`submit` >= '" . $from . "' ";
}

if (!is_null($to)) {
$sqlaction = $sqlaction . "`c`.`submit` <= " . $to . " ";
if ($showand == TRUE) {
$sqlaction .= "AND ";
}
$showand = TRUE;
$sqlaction = $sqlaction . "`c`.`submit` <= '" . $to . "' ";
}

if (!is_null($voted)) {
if ($showand == TRUE) {
$sqlaction .= "AND ";
}
$showand = TRUE;
$sqlaction = $sqlaction . "`c`.`vote-utopian` = " . $voted . " ";
}

if (!is_null($reviewed)) {
if ($showand == TRUE) {
$sqlaction .= "AND ";
}
$sqlaction = $sqlaction . "`c`.`review` = " . $reviewed . " ";
}

if ($weeklyreport == TRUE ) {
$weeklyreportaction = ", `c`.`score` AS `contrscore`, `c`.`comment` AS `contrcomment`";
} else {
$weeklyreportaction = "";
}

// Fetch all Contributions that fit the seach criteria
// By default there are no search criteria, should return a full list of all contributions
$result = mysqli_query($GLOBALS['sqlcon'], "SELECT `c`.`id` AS `cid`, `c`.`translator` AS `tid`, `c`.`proofreader` AS `pid`, `c`.`link` AS `contrlink`, `c`.`submit` AS `submitdate`, `c`.`review` AS `reviewdate`, `c`.`vote-utopian` AS `vote-utopian`, `p`.`name` AS `projectname`, `p`.`crowdin` AS `crowdinlink`, `p`.`github` AS `githublink`, `u1`.`username` AS `translator`, `u2`.`username` AS `proofreader` FROM `contributions` AS `c` LEFT JOIN `users` AS `u1` on `c`.`translator` = `u1`.`id` LEFT JOIN `users` AS `u2` on `c`.`proofreader` = `u2`.`id` LEFT JOIN `projects` AS `p` ON `c`.`project` = `p`.`id` ".$sqlaction."ORDER BY `c`.`submit` DESC" . $limit);

$result = mysqli_query($GLOBALS['sqlcon'], "SELECT `c`.`id` AS `cid`, `c`.`translator` AS `tid`, `c`.`proofreader` AS `pid`, `c`.`link` AS `contrlink`, `c`.`submit` AS `submitdate`, `c`.`review` AS `reviewdate`, `c`.`vote-utopian` AS `vote-utopian`, `p`.`name` AS `projectname`, `p`.`crowdin` AS `crowdinlink`, `p`.`github` AS `githublink`, `c`.`wordcount` AS `wordcount`, `c`.`partno` AS `partno`, `u1`.`username` AS `translator`, `u2`.`username` AS `proofreader`". $weeklyreportaction . " FROM `contributions` AS `c` LEFT JOIN `users` AS `u1` on `c`.`translator` = `u1`.`id` LEFT JOIN `users` AS `u2` on `c`.`proofreader` = `u2`.`id` LEFT JOIN `projects` AS `p` ON `c`.`project` = `p`.`id` ".$sqlaction."ORDER BY `c`.`submit` DESC" . $limit);
if ($result) {
// Initialise an empty variable to store the content
$contributionlist = "";
Expand All @@ -314,6 +360,13 @@ function GetContributionList($user = NULL, $project = NULL, $from = NULL, $to =
$project = $row['projectname'];
$contributionlink = $row['contrlink'];
$crowdin = $row['crowdinlink'];
$partno = $row['partno'];
$wordcount = $row['wordcount'];
// If it's a weekly report, assign score and contribution comment to the variable
if ($weeklyreport == TRUE ) {
$score = $row['contrscore'];
$comment = $row['contrcomment'];
}

// Show if/when a review has been added
if ($row['reviewdate'] == NULL) {
Expand Down Expand Up @@ -351,11 +404,19 @@ function GetContributionList($user = NULL, $project = NULL, $from = NULL, $to =

if (!$tabled) {
$tabled = TRUE;
$contributionlist .= "<table class=\"table table-striped table-hover\"><thead><tr><th>Project</th><th>Submit</th><th>Review</th><th>Links</th><th></th></tr></thead><tbody>";
if ($weeklyreport == TRUE) {
$contributionlist .= "<table class=\"table table-striped table-hover\"><thead><tr><th>Project</th><th>Submit</th><th>Review</th><th>Links</th><th>Score</th><th>Wordcount</th><th>Comment</th></tr></thead><tbody>";
} else {
$contributionlist .= "<table class=\"table table-striped table-hover\"><thead><tr><th>Project</th><th>Submit</th><th>Review</th><th>Links</th><th>Wordcount<th></th></tr></thead><tbody>";
}
}

// Add the project to the list
$contributionlist .= "<tr><td>".$project."</td><td>".$submit.$voteutopian."<br />(".$translator.")</td><td>".$review."</td><td><a href=\"".$contributionlink."\" target=\"_blank\">Post</a> | <a href=\"".$crowdin."\" target=\"_blank\">[C]</a></td><td>(TBC)</td>";
if ($weeklyreport == TRUE) {
$contributionlist = $contributionlist .= "<tr><td>".$project." (p.".$partno.")</td><td>".$submit.$voteutopian."<br />(".$translator.")</td><td>".$review."</td><td><a href=\"".$contributionlink."\" target=\"_blank\">Post</a> | <a href=\"".$crowdin."\" target=\"_blank\">[C]</a></td><td>".$score."</td><td>".$wordcount."</td><td>".$comment."</td><td>(TBC)</td>";
} else {
$contributionlist .= "<tr><td>".$project." (p.".$partno.")</td><td>".$submit.$voteutopian."<br />(".$translator.")</td><td>".$review."</td><td><a href=\"".$contributionlink."\" target=\"_blank\">Post</a> | <a href=\"".$crowdin."\" target=\"_blank\">[C]</a></td><td>".$wordcount."</td><td>(TBC)</td>";
}
}
if ($tabled) {
$contributionlist .= "</table>";
Expand Down Expand Up @@ -781,6 +842,8 @@ function GetReportList($user = NULL) {
$limit = " LIMIT 15";
}

// Fetch all Contributions that fit the seach criteria
// By default there are no search criteria, should return a full list of all contributions
$result = mysqli_query($GLOBALS['sqlcon'], "SELECT `w`.`id` AS `rid`, `w`.`weekend` AS `enddate`, `w`.`overview` AS `overview`, `u`.`username` AS `username` FROM `weeklyreports` AS `w` LEFT JOIN `users` AS `u` ON `w`.`user` = `u`.`id` ".$sqlaction."ORDER BY `weekend` DESC" . $limit);
if ($result) {
// Initialise an empty variable to store the content
Expand All @@ -796,7 +859,29 @@ function GetReportList($user = NULL) {
}
}

function GetSingleReport($reportid) {
// Get the proofreader's ID, the report date and the overview comment from the $reportid.
$result = mysqli_query($GLOBALS['sqlcon'], "SELECT `weekend`, `overview`, `user` FROM `weeklyreports` WHERE `id` = ". $reportid);
$row = mysqli_fetch_assoc($result);

$weekend = $row['weekend'];
$proofreader = $row['user'];
$overview = $row['overview'];

// We want the reviews of the past 7 dates, so we need to get the actual date of $weekend - 6 days.
$weekstart = date('Y-m-d', strtotime('-6 days', strtotime($weekend)));

// Now we want to get all the contributions from that week, in a table.
$contributions = GetContributionList(NULL, NULL, $weekstart, $weekend, NULL, NULL, $proofreader, NULL, true);

$username = GetUsername($proofreader);
if ($username != "error" && $username != "notfound") {
$GLOBALS['page'] = $username . " Report " . $weekstart . " to " . $weekend;
}

$returncontent = "<br /><b>Overview</b>: " . $overview . "<br /><br />" . $contributions;
return $returncontent;
}

function GetMainPageContent() {
if (isset($_COOKIE['username'])) {
Expand Down
10 changes: 8 additions & 2 deletions weeklyreports.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php
$page = "Weekly Reports";
include("functions.php");

if (isset($_GET['a'])) {
Expand All @@ -9,10 +8,17 @@
}

if ($action == NULL || $action == "list") {
$page = "Weekly Reports";
$reviewlist = GetReportList();
$pagecontent = "<table class=\"table table-striped table-hover\"><thead><tr><th>Week</th><th>Moderator</th><th></th></tr></thead><tbody>$reviewlist</tbody></table>";
} else if ($action = "view") {

$page = "";
$rid = intval($_GET['id']);
if (is_int($rid)) {
$pagecontent = GetSingleReport($_GET['id']);
} else {
$pagecontent = "Invalid ID. Please try again";
}
} else if ($action == "add") {

} else if ($action = "processadd") {
Expand Down

1 comment on commit f73a08d

@dimitrisp2
Copy link
Owner Author

Choose a reason for hiding this comment

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

Forgot to mention a hack/fix on GetContributionList that wouldn't work when multiple fields where defined on the "Filter results" form.

Please sign in to comment.