Modified:
/trunk/vanillaapp/controllers/class.problemscontroller.php
/trunk/vanillaapp/models/class.problemmodel.php
/trunk/vanillaapp/views/problems/my.php
=======================================
--- /trunk/vanillaapp/controllers/class.problemscontroller.php Sat Jul 10
22:19:39 2010
+++ /trunk/vanillaapp/controllers/class.problemscontroller.php Sat Jul 10
22:19:58 2010
@@ -270,16 +270,33 @@
$params = $this->ParseDataTablesQuery(
Array("State", "Solved", "ID", "Name", "Accepted", "Accepted /
Submissions"));
$Author = FALSE;
- $PublishedOnly = !$this->IsAdmin();
- if(isset($_GET["MineOnly"])) {
+ $ProblemStates = array(ProblemState::PUBLISHED);
+ if(isset($_GET["ProblemFilter"])) {
$this->ForceLogin();
- $Author = $this->IsAdmin() ? FALSE : $this->Session->UserID;
- $PublishedOnly = FALSE;
- }
- $Count = $this->ProblemModel->GetCount($params["SearchTerm"],
$Author, $PublishedOnly);
+ $filter = $_GET["ProblemFilter"];
+ if($filter == "MineOnly") {
+ $Author = $this->Session->UserID;
+ }
+ else {
+ $this->ForceAdmin();
+ }
+ if($filter == "MineOnly" || $filter == "All") {
+ array_push($ProblemStates, ProblemState::DRAFT);
+ array_push($ProblemStates, ProblemState::PENDING_REVIEW);
+ array_push($ProblemStates, ProblemState::HIDDEN);
+ }
+ elseif($filter == "PendingReview") {
+ $ProblemStates = array(ProblemState::PENDING_REVIEW);
+ }
+ elseif($filter == "Approved") {
+ array_push($ProblemStates, ProblemState::HIDDEN);
+ }
+ }
+
+ $Count = $this->ProblemModel->GetCount($params["SearchTerm"],
$Author, $ProblemStates);
$this->SetData("Count", $Count, TRUE);
if($Count > 0)
- $Problems = $this->ProblemModel->GetList($PublishedOnly,
+ $Problems = $this->ProblemModel->GetList($ProblemStates,
$Author,
$params["SearchTerm"],
$params["OrderFields"],
=======================================
--- /trunk/vanillaapp/models/class.problemmodel.php Sat Jul 10 22:19:44 2010
+++ /trunk/vanillaapp/models/class.problemmodel.php Sat Jul 10 22:19:58 2010
@@ -40,8 +40,7 @@
return $ret;
}
- public function GetList($OpenOnly, $Author, $SearchTerm, $OrderFields,
$OrderDirection,
- $Limit, $Offset) {
+ public function GetList($ProblemStates, $Author, $SearchTerm,
$OrderFields, $OrderDirection, $Limit, $Offset) {
$Session = Gdn::Session();
$this->SQL->Select("p.ID", "", "ID")
@@ -63,7 +62,7 @@
$UserID = $Session->UserID;
$this->SQL->Join("Submission s", "s.Problem = p.No AND
s.Author = $UserID AND s.State = " . SubmissionState::ACCEPTED, "left");
}
- $this->Where($OpenOnly, $Author, $SearchTerm);
+ $this->Where($ProblemStates, $Author, $SearchTerm);
$this->SQL->Limit($Limit, $Offset);
$ret = $this->SQL->Get()->Result();
for($i = 0; $i < Count($ret); ++$i) {
@@ -72,19 +71,19 @@
return $ret;
}
- public function GetCount($SearchTerm, $Author, $OpenOnly) {
+ public function GetCount($SearchTerm, $Author, $ProblemStates) {
$this->SQL->Select("Count(No) as Cnt")->From("Problem p");
- $this->Where($OpenOnly, $Author, $SearchTerm);
+ $this->Where($ProblemStates, $Author, $SearchTerm);
$ret = $this->SQL->Get();
return $ret->FirstRow()->Cnt;
}
- public function Where($OpenOnly, $Author, $SearchTerm) {
- if($SearchTerm !== FALSE || $Author !== FALSE || $OpenOnly) {
+ public function Where($ProblemStates, $Author, $SearchTerm) {
+ if($SearchTerm !== FALSE || $Author !== FALSE ||
$ProblemStates !== FALSE) {
$this->SQL->BeginWhereGroup();
$first = true;
- if($OpenOnly) {
- $this->SQL->Where("p.State", ProblemState::PUBLISHED);
+ if($ProblemStates !== FALSE) {
+ $this->SQL->WhereIn("p.State", $ProblemStates);
$first = false;
}
if($SearchTerm !== FALSE) {
=======================================
--- /trunk/vanillaapp/views/problems/my.php Sat Jul 10 22:18:45 2010
+++ /trunk/vanillaapp/views/problems/my.php Sat Jul 10 22:19:58 2010
@@ -6,6 +6,13 @@
<?=T("guide before submitting problems.")?>
</p>
</div>
+<? if($this->IsAdmin()) { ?>
+<div class="Note">
+ <p>
+ <?=T("Show")?> <?=$this->Form->DropDown("State", array("MineOnly"
=> "only my problems", "PendingReview" => "all problems pending
review", "Approved" => "all approved problems", "All" => "all problems"),
array("id" => "ProblemFilter"))?>
+ </p>
+</div>
+<? } ?>
<div class="ProblemList">
<table cellpadding="0" cellspacing="0" border="0" class="display"
id="ProblemListTable" width="100%">
<thead>
@@ -34,7 +41,20 @@
"bServerSide": true,
"iDisplayLength": 25,
"sPaginationType": "full_numbers",
- "sAjaxSource": "<?=Url("/aoj/problems/getlist")?>&DeliveryType=3&MineOnly=1",
+ "sAjaxSource": "<?=Url("/aoj/problems/getlist")?>",
+ "fnServerData": function ( sSource, aoData, fnCallback ) {
+ if(aoData == null) {
+ aoData = [];
+ }
+ aoData.push({ name: "DeliveryType", value: 3});
+ if($("#ProblemFilter").length == 0) {
+ aoData.push({ name: "ProblemFilter", value: "MineOnly"
});
+ }
+ else {
+ aoData.push({ name: "ProblemFilter", value:
$("#ProblemFilter").val() });
+ }
+ $.getJSON( sSource, aoData, fnCallback);
+ },
"aaSorting": [[1, "asc"]],
"aoColumns": [
{
@@ -82,8 +102,9 @@
}
]
} );
- } );
-
+
+ $("#ProblemFilter").change(function() { table.fnReloadAjax(); });
+ } );
function confirmDeletion(link, elem) {
var e = $(elem);