[algospot-judge] r233 committed - Can specify categories in edit

9 views
Skip to first unread message

codesite...@google.com

unread,
Jul 11, 2010, 4:48:29 AM7/11/10
to algospo...@googlegroups.com
Revision: 233
Author: jongman
Date: Sat Jul 10 22:20:45 2010
Log: Can specify categories in edit
http://code.google.com/p/algospot-judge/source/detail?r=233

Modified:
/trunk/vanillaapp/controllers/class.problemscontroller.php
/trunk/vanillaapp/design/problems.css
/trunk/vanillaapp/models/class.problemmodel.php
/trunk/vanillaapp/models/class.tagmodel.php
/trunk/vanillaapp/views/problems/edit.php

=======================================
--- /trunk/vanillaapp/controllers/class.problemscontroller.php Sat Jul 10
22:20:19 2010
+++ /trunk/vanillaapp/controllers/class.problemscontroller.php Sat Jul 10
22:20:45 2010
@@ -3,7 +3,7 @@
require_once("vendors" . DS . "markdown" . DS . "markdown.php");

class ProblemsController extends AOJController {
- public $Uses =
array("ProblemModel", "AttachmentModel", "SubmissionModel", "UserModel", "Form", "Gdn_Upload");
+ public $Uses =
array("ProblemModel", "AttachmentModel", "SubmissionModel", "TagModel", "UserModel", "Form", "Gdn_Upload");
public function Initialize() {
if ($this->DeliveryType() == DELIVERY_TYPE_ALL) {
$this->AddCssFile("problems.css");
@@ -106,12 +106,34 @@
$this->Form->SetFormValue("State",
ProblemState::PENDING_REVIEW);

}
- print_r($_POST);
if($this->Form->Save()) {
+ $Categories = explode(" ", trim($_POST["Categories"]));
+ $this->TagModel->SetTags($this->Problem->No, $Categories);
$Values = $this->Form->FormValues();
Redirect("/problems/read/" . $Values["ID"]);
}
}
+ $AllCategories = array();
+ $AllCategories["-1"] = T("Add a category");
+ foreach($this->TagModel->GetList() as $Tag) {
+ $AllCategories[$Tag->No] = $Tag->Name;
+ }
+ $ProblemCategories = array();
+ if(isset($_POST["Categories"])) {
+ $Categories = explode(" ", trim($_POST["Categories"]));
+ foreach($Categories as $Cat) {
+ $Cat = intval($Cat);
+ $ProblemCategories[$Cat] = $AllCategories[$Cat];
+ }
+ }
+ else {
+ foreach($this->TagModel->GetListForProblem($this->Problem->No)
as $Tag) {
+ $ProblemCategories[$Tag->No] = $Tag->Name;
+ }
+ }
+ asort($AllCategories);
+ $this->SetData("AllCategories", $AllCategories, TRUE);
+ $this->SetData("ProblemCategories", $ProblemCategories, TRUE);
$this->Form->SetData($this->Problem);
$this->Form->AddHidden("No", $this->Problem->No);
$this->AddModule("ProblemInfoModule");
=======================================
--- /trunk/vanillaapp/design/problems.css Sat Jul 10 22:20:06 2010
+++ /trunk/vanillaapp/design/problems.css Sat Jul 10 22:20:45 2010
@@ -109,3 +109,19 @@
.CategoryParent {
color: gray;
}
+
+.ProblemCategory {
+ border: 1px solid silver;
+}
+
+#TagEntries {
+ margin-bottom: 8px;
+}
+
+.Template {
+ display: none;
+}
+
+a.ProblemCategory:hover {
+ background-color: yellow;
+}
=======================================
--- /trunk/vanillaapp/models/class.problemmodel.php Sat Jul 10 22:20:28 2010
+++ /trunk/vanillaapp/models/class.problemmodel.php Sat Jul 10 22:20:45 2010
@@ -21,11 +21,18 @@
public function __construct() {
parent::__construct('Problem');
$this->UserModel = new UserModel();
+ $this->TagModel = new TagModel();
}

- private function Augment($Problem) {
+ private function Augment($Problem, $IncludeTags=FALSE) {
$Problem->StateText = ProblemState::ToString($Problem->State);
$Problem->AuthorInfo = $this->UserModel->Get($Problem->Author);
+ if($IncludeTags) {
+ $Problem->Tags = array();
+ foreach($this->TagModel->GetListForProblem($Problem->No) as
$Tag) {
+ array_push($Problem->Tags, $Tag);
+ }
+ }
}

public function IsIDUnique($ID, $No) {
@@ -42,7 +49,7 @@
if(!is_object($ret)) {
$ret = $this->GetWhere(array("No" => $IdOrNo))->FirstRow();
}
- $this->Augment($ret);
+ $this->Augment($ret, TRUE);
return $ret;
}

=======================================
--- /trunk/vanillaapp/models/class.tagmodel.php Sat Jul 10 22:20:36 2010
+++ /trunk/vanillaapp/models/class.tagmodel.php Sat Jul 10 22:20:45 2010
@@ -19,6 +19,23 @@
->GroupBy("t.No")
->Get()->Result();
}
+
+ public function GetListForProblem($Problem) {
+ return $this->SQL
+ ->Select("t.No", "", "No")
+ ->Select("t.Name", "", "Name")
+ ->From("ProblemTagRelation r")
+ ->Where("r.Problem", $Problem)
+ ->Join("Tag t", "r.Tag = t.No")
+ ->Get()->Result();
+ }
+
+ public function SetTags($Problem, $Tags) {
+ $this->SQL->Delete("ProblemTagRelation", array("Problem" =>
$Problem));
+ foreach($Tags as $Tag) {
+ $this->SQL->Insert("ProblemTagRelation", array("Problem" =>
$Problem, "Tag" => intval($Tag)));
+ }
+ }

public function DeleteTag($No) {
$Cat = $this->SQL->Select("Name")->From("Tag")->Where("No",
$No)->Get()->FirstRow()->Name;
=======================================
--- /trunk/vanillaapp/views/problems/edit.php Sat Jul 10 22:19:39 2010
+++ /trunk/vanillaapp/views/problems/edit.php Sat Jul 10 22:20:45 2010
@@ -1,4 +1,4 @@
-<?=$this->Form->Open(); ?>
+<?=$this->Form->Open(array("onsubmit" => "return submitForm()")); ?>
<?=$this->Form->Errors(); ?>
<div class="Problem">
<h1 class="Name">
@@ -48,6 +48,17 @@
"relative_float" => "Ignore all whitespaces, compare real numbers with
tolerance",
"strict" => "Strict full-text comparison")));
?>
+ </div>
+ <div class="Tags">
+ <h2>Problem Categories</h2>
+ <input type="hidden" id="Categories" name="Categories"/>
+ <div id="TagEntries">
+ <a href="#" onclick="removeCategory(this);"
id="ProblemCategoryTemplate" class="ProblemCategory Template">Template</a>
+ <? foreach($this->ProblemCategories as $TagID => $TagName) { ?>
+ <a href="#" onclick="removeCategory(this);"
class="ProblemCategory" id="Category_<?=$TagID?>"><?=$TagName?></a>
+ <? } ?>
+ </div>
+ <?=$this->Form->DropDown("NewCategory", $this->AllCategories,
array("id" => "NewCategory"))?>
</div>
<div class="Attachments">
<h2>Attachments</h2>
@@ -78,6 +89,12 @@
<script language="javascript">
var table = null;
$(document).ready(function() {
+ $("#NewCategory").change(function() {
+ var val = $(this).val();
+ var name = $("#NewCategory option:selected").text();
+ addCategory(val, name);
+ $(this).val(-1);
+ });
$("textarea.TextBox").autoGrow();
table = $('#AttachmentListTable').dataTable( {
"bProcessing": true,
@@ -175,6 +192,20 @@

};

+ function removeCategory(elem) {
+ elem = $(elem);
+ elem.remove();
+ }
+ function addCategory(val, name) {
+ var id = "Category_" + val;
+ if($("#" + id).length > 0) {
+ return;
+ }
+ var newtag = $("#ProblemCategoryTemplate").clone();
+ $("#TagEntries").append(" ");
+
newtag.appendTo("#TagEntries").text(name).removeClass("Template").attr("id",
id);
+ }
+
function insertPictureLink(no) {
$("#Description").insertAtCaret('[InsertImage|' + no + ']');
}
@@ -192,5 +223,17 @@
$(elem).html("Really?").addClass("ConfirmDelete");
}
}
+
+ function submitForm() {
+ var allCategories = "";
+ $("#TagEntries a").each(function(index, value) {
+ var parts = value.id.split("_");
+ if(parts.length == 2 && parts[0] == "Category") {
+ allCategories += parts[1] + " ";
+ }
+ });
+ $("#Categories").val(allCategories);
+ return true;
+ }
</script>
<?=$this->Form->Close(); ?>

Reply all
Reply to author
Forward
0 new messages