Modified:
/trunk/vanillaapp/controllers/class.problemscontroller.php
/trunk/vanillaapp/models/class.submissionmodel.php
=======================================
--- /trunk/vanillaapp/controllers/class.problemscontroller.php Sat Jul 10
22:17:37 2010
+++ /trunk/vanillaapp/controllers/class.problemscontroller.php Sat Jul 10
22:18:04 2010
@@ -227,14 +227,13 @@
$this->AddModule("NewProblemModule");
$this->Render();
}
- private function ParseDataTablesQuery() {
+ private function ParseDataTablesQuery($ColumnNames) {
$OrderFields = "ID";
$OrderDirection = "asc";
$Limit = 9999;
$Offset = 0;
$SearchTerm = FALSE;
$Echo = "";
- $Columns =
Array("State", "Solved", "ID", "Name", "Accepted", "Accepted /
Submissions");
foreach($_GET as $key => $value) {
if($key == "sEcho")
@@ -246,7 +245,7 @@
elseif($key == "sSearch" && $value != "")
$SearchTerm = $value;
elseif($key == "iSortCol_0") {
- $OrderFields = $Columns[$value];
+ $OrderFields = $ColumnNames[$value];
}
elseif($key == "sSortDir_0") {
$OrderDirection = $value;
@@ -262,7 +261,7 @@
}
public function GetList() {
$this->MasterView = "json";
- $params = $this->ParseDataTablesQuery();
+ $params = $this->ParseDataTablesQuery(
Array("State", "Solved", "ID", "Name", "Accepted", "Accepted /
Submissions"));
$Author = FALSE;
$PublishedOnly = !$this->IsAdmin();
@@ -293,7 +292,7 @@
$this->ForceEditPermissions();
$this->MasterView = "json";
- $params = $this->ParseDataTablesQuery();
+ $params = $this->ParseDataTablesQuery(Array());
$Count = $this->AttachmentModel->GetCount($this->Problem->No);
$this->SetData("Count", $Count, TRUE);
@@ -315,7 +314,7 @@
}
public function ListSubmissions() {
$this->MasterView = "json";
- $params = $this->ParseDataTablesQuery();
+ $params =
$this->ParseDataTablesQuery(array("No", "Problem", "Author", "Language", "Length", "State",
array("Time", "Memory"), "Submitted"));
$ShowHidden = $this->IsAdmin();
if(isset($_GET["Author"]) && $_GET["Author"] != -1) {
$Author = $_GET["Author"];
@@ -331,7 +330,7 @@
}
$Count = $this->SubmissionModel->GetCount($Author, $ShowHidden);
- $Submissions = $this->SubmissionModel->GetList($Author,
$ShowHidden, $params["Limit"], $params["Offset"], $ExcludeState);
+ $Submissions = $this->SubmissionModel->GetList($Author,
$ShowHidden, $params["Limit"], $params["Offset"], $ExcludeState,
$params["OrderFields"], $params["OrderDirection"]);
$this->SetData("Count", $Count, TRUE);
$this->SetData("Submissions", $Submissions, TRUE);
$this->Render();
=======================================
--- /trunk/vanillaapp/models/class.submissionmodel.php Sat Jul 10 22:17:56
2010
+++ /trunk/vanillaapp/models/class.submissionmodel.php Sat Jul 10 22:18:04
2010
@@ -55,7 +55,7 @@
$this->SQL->Put("Submission", $NewValues, array("No" => $No));
}
- public function GetList($Author, $ShowHidden, $Limit, $Offset,
$ExcludeState=array()) {
+ public function GetList($Author, $ShowHidden, $Limit, $Offset,
$ExcludeState=array(), $SortBy="No", $SortDirection="desc") {
$this->SQL->Select("s.No", "", "No")
->Select("p.ID", "", "ProblemID")
->Select("s.Problem", "", "Problem")
@@ -68,9 +68,14 @@
->Select("s.IsPublic", "", "IsPublic")
->Select("s.Submitted", "", "Submitted")
->Select("s.Length", "", "Length")
- ->From("Submission s")
- ->OrderBy("s.No", "desc")
- ->Join("Problem p", "p.No = s.Problem", "left");
+ ->From("Submission s");
+
+ if(!is_array($SortBy)) $SortBy = array($SortBy);
+ foreach($SortBy as $Column) {
+ $this->SQL->OrderBy("s." . $Column, $SortDirection);
+ }
+
+ $this->SQL->Join("Problem p", "p.No = s.Problem", "left");
$Session = Gdn::Session();
$UserID = $Session->IsValid() ? $Session->UserID : -1;
$this->Where($Author, $ShowHidden, $UserID, $ExcludeState);