Alexander Nicolaysen Sørnes : Allow changing the order in which notes are displayed
Alexander Nicolaysen Sørnes
asornes at winehq.org
Mon Apr 25 17:51:36 CDT 2011
Module: appdb
Branch: master
Commit: 5f87b343e6d42c161db0e1d773d34ff645580a4f
URL: http://source.winehq.org/git/appdb.git/?a=commit;h=5f87b343e6d42c161db0e1d773d34ff645580a4f
Author: Alexander Nicolaysen Sørnes <alexsornes at gmail.com>
Date: Tue Apr 26 00:51:03 2011 +0200
Allow changing the order in which notes are displayed
---
include/tag.php | 27 +++++++-
include/tagAssignmentMgr.php | 143 ++++++++++++++++++++++++++++++++++++++++++
include/tag_Note.php | 28 ++++++++-
include/version.php | 3 +
tables/appdb_tables.sql | 1 +
5 files changed, 198 insertions(+), 4 deletions(-)
diff --git a/include/tag.php b/include/tag.php
index 3970b01..b9395c8 100644
--- a/include/tag.php
+++ b/include/tag.php
@@ -50,7 +50,7 @@ abstract class Tag extends ObjectManagerBase
return 'tags_'.$this->getTagClass();
}
- protected function getSQLTableForAssignments()
+ public function getSQLTableForAssignments()
{
return $this->objectGetSQLTable().'_assignments';
}
@@ -77,7 +77,21 @@ abstract class Tag extends ObjectManagerBase
public function assign($iId)
{
- $hResult = query_parameters("INSERT INTO ? (tagId, taggedId) VALUES('?', '?')", $this->getSQLTableForAssignments(), $this->iId, $iId);
+ if($this->isOrdered())
+ {
+ $hResult = query_parameters("SELECT MAX(position) as maxPos FROM ? WHERE tagId = '?'", $this->getSQLTableForAssignments(), $this->iId);
+
+ if(!$hResult)
+ return false;
+
+ $oRow = mysql_fetch_object($hResult);
+ $iPos = $oRow->maxPos + 1;
+
+ $hResult = query_parameters("INSERT INTO ? (tagId, taggedId, position) VALUES('?', '?', '?')", $this->getSQLTableForAssignments(), $this->iId, $iId, $iPos);
+ } else
+ {
+ $hResult = query_parameters("INSERT INTO ? (tagId, taggedId) VALUES('?', '?')", $this->getSQLTableForAssignments(), $this->iId, $iId);
+ }
if(!$hResult)
return false;
@@ -108,7 +122,9 @@ abstract class Tag extends ObjectManagerBase
public function getTaggedEntries()
{
- $hResult = query_parameters("SELECT taggedId FROM ? WHERE tagId = '?' AND state = 'accepted'", $this->getSQLTableForAssignments(), $this->iId);
+ $sOrderBy = $this->isOrdered() ? 'position ASC' : 'id ASC';
+
+ $hResult = query_parameters("SELECT taggedId FROM ? WHERE tagId = '?' AND state = 'accepted' ORDER BY $sOrderBy", $this->getSQLTableForAssignments(), $this->iId);
if(!$hResult)
return array();
@@ -314,6 +330,11 @@ public function objectGetEntriesCount()
{
return true;
}
+
+ protected function isOrdered()
+ {
+ return false;
+ }
}
?>
\ No newline at end of file
diff --git a/include/tagAssignmentMgr.php b/include/tagAssignmentMgr.php
new file mode 100644
index 0000000..006b2eb
--- /dev/null
+++ b/include/tagAssignmentMgr.php
@@ -0,0 +1,143 @@
+<?php
+
+abstract class TagAssignmentMgr extends ObjectManagerBase
+{
+ protected $aTaggedEntries;
+
+ function Constructor($iId = null, $oRow = null)
+ {
+ $this->iId = $iId;
+ $this->aTaggedEntries = $this->getTagObject($this->iId)->getTaggedEntries();
+ }
+
+ protected function objectGetSQLTable()
+ {
+ return $this->getTagObject()->getSQLTableForAssignments();
+ }
+
+ public function create()
+ {
+ return false;
+ }
+
+ public function update()
+ {
+ $i = 0;
+
+ foreach($this->aTaggedEntries as $oTag)
+ {
+ $hResult = query_parameters("UPDATE ? SET position = '?' WHERE taggedId = '?'", $this->objectGetSQLTable(), $i, $oTag->objectGetId());
+
+ if(!$hResult)
+ return false;
+
+ $i++;
+ }
+
+ return true;
+ }
+
+ public function objectGetEntries()
+ {
+ return false;
+ }
+
+ public function objectGetHeader()
+ {
+ return null;
+ }
+
+ public function objectGetTableRow()
+ {
+ return null;
+ }
+
+ public function outputEditor()
+ {
+ if(sizeof($this->aTaggedEntries) == 0)
+ echo 'This page allows you to sort associated entries, but since there are none . . . have fun!<br /><br />';
+ else if(sizeof($this->aTaggedEntries) == 1)
+ echo 'This page allows you to sort associated entries, but since there\'s only one . . . have fun!<br /><br />';
+ echo 'The following tags are assigned to this entry; this page allows you to change the order in which they are displayed:<br /><br />';
+
+ $iSize = min(sizeof($this->aTaggedEntries), 10);
+
+ echo '<div style="float: left;">';
+ $i = 0;
+ $shOptions = '';
+
+ foreach($this->aTaggedEntries as $oTag)
+ {
+ $shOptions .= '<option value="'.$oTag->objectGetId().'">'.$oTag->objectMakeLink()."</option>\n";
+ echo '<input type="hidden" name="iTagPlace'.$i.'" value="'.$oTag->objectGetId().'" />';
+ $i++;
+ }
+ echo "<select size=\"$iSize\" name=\"iTagAssocList\">\n";
+ echo $shOptions;
+ echo '</select></div>';
+ echo '<div style="margin-left: 10px; float: left;">';
+ echo "<script type=\"text/JavaScript\">\n";
+ echo "function swap(index1, index2) {\n";
+ echo "var selector = document.forms['sQform']['iTagAssocList'];\n";
+ echo "var item1 = selector.options[index1];\n";
+ echo "var item2 = selector.options[index2];\n";
+ echo "selector.options[index1] = new Option(item2.text, item2.value, item2.defaultSelected, item2.selected);\n";
+ echo "selector.options[index2] = item1;\n";
+ echo "var hidden1 = document.forms['sQform']['iTagPlace'+index1];\n";
+ echo "var hidden2 = document.forms['sQform']['iTagPlace'+index2];\n";
+ echo "var tmp = hidden1.value;\n";
+ echo "hidden1.value = hidden2.value;\n";
+ echo "hidden2.value = tmp;\n";
+ echo "}\n";
+ echo "function moveUp() {\n";
+ echo "var selector = document.forms['sQform']['iTagAssocList'];\n";
+ echo "var index = selector.selectedIndex;\n";
+ echo "if(index == 0)\n";
+ echo " return;\n";
+ echo "swap(index, index - 1);\n";
+ echo "}\n";
+ echo "function moveDown() {\n";
+ echo "var selector = document.forms['sQform']['iTagAssocList'];\n";
+ echo "var index = selector.selectedIndex;\n";
+ echo "if(index + 1 == selector.options.length)\n";
+ echo " return;\n";
+ echo "swap(index, index + 1);\n";
+ echo "}\n";
+ echo "</script>\n";
+ echo '<button onclick="moveUp()" type="button">Move up</button><br />';
+ echo '<button onclick="moveDown()" type="button">Move down</button>';
+ echo '</div>';
+ }
+
+ public function getOutputEditorValues($aClean)
+ {
+ $aDBTags = $this->getTagObject($this->iId)->getTaggedEntries();
+ $this->aTaggedEntries = array();
+
+ for($i = 0; $i < sizeof($aDBTags); $i++)
+ {
+ foreach($aDBTags as $oTag)
+ {
+ if($oTag->objectGetId() == $aClean['iTagPlace'.$i])
+ {
+ $this->aTaggedEntries[] = $oTag;
+ break;
+ }
+ }
+ }
+
+ if(sizeof($aDBTags) != sizeof($this->aTaggedEntries))
+ $this->aTaggedEntries = $aDBTags;
+ }
+
+ public function checkOutputEditorInput($aClean)
+ {
+ $shErrors = '';
+
+ return $shErrors;
+ }
+
+ protected abstract function getTagObject($iId, $oRow);
+}
+
+?>
\ No newline at end of file
diff --git a/include/tag_Note.php b/include/tag_Note.php
index 2644317..c293630 100644
--- a/include/tag_Note.php
+++ b/include/tag_Note.php
@@ -1,6 +1,7 @@
<?php
require_once(BASE.'include/tag.php');
+require_once(BASE.'include/tagAssignmentMgr.php');
class TagNoteVersion extends Tag
{
@@ -42,7 +43,7 @@ class TagNoteVersion extends Tag
return 'appVersion';
}
- protected function getSQLTableForAssignments()
+ public function getSQLTableForAssignments()
{
return 'tags_NoteVersion_assignments';
}
@@ -73,6 +74,31 @@ class TagNoteVersion extends Tag
{
return 'Note';
}
+
+ protected function isOrdered()
+ {
+ return true;
+ }
+}
+
+class TagNoteVersionAssignMgr extends TagAssignmentMgr
+{
+ function TagNoteVersionAssignMgr($iId = null, $oRow = null)
+ {
+ $this->Constructor($iId, $oRow);
+ }
+
+ protected function getTagObject($iId = null, $oRow = null)
+ {
+ return new TagNoteVersion($iId, $oRow);
+ }
+
+ public function canEdit()
+ {
+ $oVersion = new Version($this->iId);
+
+ return $oVersion->canEdit();
+ }
}
?>
\ No newline at end of file
diff --git a/include/version.php b/include/version.php
index 6708802..8286c5b 100644
--- a/include/version.php
+++ b/include/version.php
@@ -1011,6 +1011,9 @@ class version {
echo $shAdd.'" />';
echo "\t".'<input type="submit" value="Add note/how-to" class="button">'."\n";
echo '</form>'."\n";
+ echo '<form method="post" action="'.BASE.'objectManager.php?sClass=tagNoteVersionAssignMgr&sAction=edit&iId='.$this->iVersionId.'">';
+ echo '<input type="submit" value="Manage notes" />';
+ echo '</form>';
echo "</td></tr>";
}
$oMonitor = new Monitor();
diff --git a/tables/appdb_tables.sql b/tables/appdb_tables.sql
index fc4630f..9fb4672 100644
--- a/tables/appdb_tables.sql
+++ b/tables/appdb_tables.sql
@@ -186,6 +186,7 @@ create table tags_NoteVersion_assignments (
state enum('accepted','queued','rejected','pending','deleted') NOT NULL default 'accepted',
tagId int not null,
taggedId int not null,
+ position int not null,
key(id)
);
More information about the wine-cvs
mailing list