[evolvis-commits] r14111: Allow manual setting of ordering for participations
mirabilos at evolvis.org
mirabilos at evolvis.org
Mon Feb 28 03:51:01 CET 2011
Author: mirabilos
Date: 2011-02-28 03:51:01 +0100 (Mon, 28 Feb 2011)
New Revision: 14111
Modified:
trunk/gforge_base/evolvisforge-5.1/gforge/plugins/contribtracker/common/ContribTrackerPlugin.class.php
trunk/gforge_base/evolvisforge-5.1/gforge/plugins/contribtracker/lib/contribtracker-init.sql
trunk/gforge_base/evolvisforge-5.1/gforge/plugins/contribtracker/www/index.php
trunk/gforge_base/evolvisforge-5.1/gforge/plugins/contribtracker/www/project_admin.php
Log:
Allow manual setting of ordering for participations
Modified: trunk/gforge_base/evolvisforge-5.1/gforge/plugins/contribtracker/common/ContribTrackerPlugin.class.php
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/gforge/plugins/contribtracker/common/ContribTrackerPlugin.class.php 2011-02-28 02:50:59 UTC (rev 14110)
+++ trunk/gforge_base/evolvisforge-5.1/gforge/plugins/contribtracker/common/ContribTrackerPlugin.class.php 2011-02-28 02:51:01 UTC (rev 14111)
@@ -113,7 +113,6 @@
</tr>';
$contribs = $this->getContributionsByGroup ($group) ;
- usort ($contribs, array ($this, "ContribComparator")) ;
if (count ($contribs) == 0) {
echo '<tr><td colspan="5"><strong>'._('No contributions have been recorded for this project yet.').'</strong></td></tr>';
@@ -216,6 +215,8 @@
$results[] = new ContribTrackerContribution ($id) ;
}
+ $plugin = plugin_get_object ('contribtracker') ;
+ usort ($results, array ($plugin, "ContribComparator")) ;
return $results ;
}
@@ -229,6 +230,8 @@
$results[] = new ContribTrackerContribution ($id) ;
}
+ $plugin = plugin_get_object ('contribtracker') ;
+ usort ($results, array ($plugin, "ContribComparator")) ;
return $results ;
}
@@ -241,6 +244,18 @@
return 0 ;
}
}
+
+ function ParticipationComparator ($a, $b) {
+ if ($a->getContribution()->getDate() != $b->getContribution()->getDate()) {
+ return ($a->getContribution()->getDate() < $b->getContribution()->getDate()) ? -1 : 1 ;
+ } elseif ($a->getContribution() != $b->getContribution()) {
+ return ($a->getContribution() < $b->getContribution()) ? -1 : 1 ;
+ } elseif ($a->getIndex() != $b->getIndex()) {
+ return ($a->getIndex() < $b->getIndex()) ? -1 : 1 ;
+ } else {
+ return 0 ;
+ }
+ }
}
class ContribTrackerRole extends Error {
@@ -585,6 +600,8 @@
$results[] = new ContribTrackerParticipation ($id) ;
}
+ $plugin = plugin_get_object ('contribtracker') ;
+ usort ($results, array ($plugin, "ParticipationComparator")) ;
return $results ;
}
@@ -714,8 +731,17 @@
$results[] = new ContribTrackerParticipation ($id) ;
}
+ $plugin = plugin_get_object ('contribtracker') ;
+ usort ($results, array ($plugin, "ParticipationComparator")) ;
return $results ;
}
+
+ function getLastPartIndex () {
+ $res = db_query_params ('SELECT COUNT(*) AS c FROM plugin_contribtracker_participation WHERE contrib_id = $1',
+ array ($this->getId())) ;
+ $curindex = db_result ($res,0,'c') ;
+ return $curindex ;
+ }
}
class ContribTrackerParticipation extends Error {
@@ -748,10 +774,13 @@
}
db_begin () ;
- $res = db_query_params ('INSERT INTO plugin_contribtracker_participation (contrib_id,actor_id,role_id) VALUES ($1,$2,$3)',
+ $index = $contrib->getLastPartIndex () + 1;
+
+ $res = db_query_params ('INSERT INTO plugin_contribtracker_participation (contrib_id,actor_id,role_id,index) VALUES ($1,$2,$3,$4)',
array ($contrib->getID(),
$actor->getID(),
- $role->getID())) ;
+ $role->getID(),
+ $index)) ;
if (!$res || db_affected_rows ($res) < 1) {
$this->setError (sprintf(_('Could not create object in database: %s'),
db_error ()));
@@ -778,6 +807,10 @@
}
$id = $this->getId () ;
+ if ($contrib->getID() != $this->getContribution()->getID()) {
+ $this->setError (_('Cannot currently move a participation across contributions')) ;
+ return false ;
+ }
db_begin () ;
$res = db_query_params ('UPDATE plugin_contribtracker_participation SET (contrib_id,actor_id,role_id) = ($1,$2,$3) WHERE participation_id = $4',
@@ -803,6 +836,8 @@
return false ;
}
+ db_begin () ;
+ $curindex = $this->getIndex() ;
$res = db_query_params ('DELETE FROM plugin_contribtracker_participation WHERE participation_id = $1',
array ($id)) ;
if (!$res) {
@@ -810,12 +845,80 @@
db_error ())) ;
return false ;
}
+ $res = db_query_params ('UPDATE plugin_contribtracker_participation SET index = -index WHERE contrib_id = $1 and index > $2',
+ array ($this->getContribution()->getId(),
+ $curindex)) ;
+ if (!$res) {
+ $this->setError (sprintf(_('Could not update indices in database: %s'),
+ db_error ())) ;
+ return false ;
+ }
+ $res = db_query_params ('UPDATE plugin_contribtracker_participation SET index = -index -1 WHERE contrib_id = $1 and index < 0',
+ array ($this->getContribution()->getId())) ;
+ if (!$res) {
+ $this->setError (sprintf(_('Could not update indices in database: %s'),
+ db_error ())) ;
+ return false ;
+ }
+ db_commit () ;
$this->data_array = array () ;
return true ;
}
+ function moveUp () {
+ $id = $this->getId () ;
+ if (!$id) {
+ $this->setError (_('Cannot update a non-existing object')) ;
+ return false ;
+ }
+
+ $cur = $this->getIndex() ;
+ if ($cur == 1) {
+ return ;
+ }
+ $contrib_id = $this->getContribution()->getId() ;
+
+ db_begin () ;
+ $res = db_query_params ('UPDATE plugin_contribtracker_participation SET index = 0 WHERE participation_id = $1',
+ array ($id)) ;
+ $res = db_query_params ('UPDATE plugin_contribtracker_participation SET index = index+1 WHERE contrib_id = $1 AND index = $2',
+ array ($contrib_id,
+ $cur-1)) ;
+ $res = db_query_params ('UPDATE plugin_contribtracker_participation SET index = $1 WHERE contrib_id = $2 AND index = 0',
+ array ($cur - 1,
+ $contrib_id)) ;
+ db_commit () ;
+ }
+
+ function moveDown () {
+ $id = $this->getId () ;
+ if (!$id) {
+ $this->setError (_('Cannot update a non-existing object')) ;
+ return false ;
+ }
+
+ $lastid = $this->getContribution()->getLastPartIndex() ;
+
+ $cur = $this->getIndex() ;
+ if ($cur == $lastid) {
+ return ;
+ }
+ $contrib_id = $this->getContribution()->getId() ;
+
+ db_begin () ;
+ $res = db_query_params ('UPDATE plugin_contribtracker_participation SET index = 0 WHERE participation_id = $1',
+ array ($id)) ;
+ $res = db_query_params ('UPDATE plugin_contribtracker_participation SET index = index-1 WHERE contrib_id = $1 AND index = $2',
+ array ($contrib_id,
+ $cur+1)) ;
+ $res = db_query_params ('UPDATE plugin_contribtracker_participation SET index = $1 WHERE contrib_id = $2 AND index = 0',
+ array ($cur + 1,
+ $contrib_id)) ;
+ db_commit () ;
+ }
+
function getId () {
if (isset ($this->data_array['participation_id'])) {
return $this->data_array['participation_id'] ;
@@ -823,6 +926,13 @@
return false ;
}
}
+ function getIndex () {
+ if (isset ($this->data_array['index'])) {
+ return $this->data_array['index'] ;
+ } else {
+ return false ;
+ }
+ }
function getActor () {
return new ContribTrackerActor ($this->data_array['actor_id']) ;
}
Modified: trunk/gforge_base/evolvisforge-5.1/gforge/plugins/contribtracker/lib/contribtracker-init.sql
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/gforge/plugins/contribtracker/lib/contribtracker-init.sql 2011-02-28 02:50:59 UTC (rev 14110)
+++ trunk/gforge_base/evolvisforge-5.1/gforge/plugins/contribtracker/lib/contribtracker-init.sql 2011-02-28 02:51:01 UTC (rev 14111)
@@ -36,5 +36,7 @@
participation_id integer DEFAULT nextval('plugin_contribtracker_participation_pk_seq') PRIMARY KEY,
contrib_id integer NOT NULL REFERENCES plugin_contribtracker_contribution ON DELETE CASCADE,
actor_id integer NOT NULL REFERENCES plugin_contribtracker_actor,
- role_id integer NOT NULL REFERENCES plugin_contribtracker_role
+ role_id integer NOT NULL REFERENCES plugin_contribtracker_role,
+ index integer NOT NULL,
+ CONSTRAINT index_unicity UNIQUE(contrib_id,index)
) ;
Modified: trunk/gforge_base/evolvisforge-5.1/gforge/plugins/contribtracker/www/index.php
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/gforge/plugins/contribtracker/www/index.php 2011-02-28 02:50:59 UTC (rev 14110)
+++ trunk/gforge_base/evolvisforge-5.1/gforge/plugins/contribtracker/www/index.php 2011-02-28 02:51:01 UTC (rev 14111)
@@ -96,7 +96,6 @@
site_project_header ($params) ;
$contribs = $plugin->getContributionsByGroup ($group) ;
- usort ($contribs, array ($plugin, "ContribComparator")) ;
if (count ($contribs) == 0) {
print '<h1>'._('No contributions').'</h1>' ;
@@ -162,8 +161,6 @@
$contribs = $plugin->getContributions () ;
- usort ($contribs, array ($plugin, "ContribComparator")) ;
-
if (count ($contribs) == 0) {
print '<h1>'._('No contributions').'</h1>' ;
print _('No contributions have been recorded yet.') ;
Modified: trunk/gforge_base/evolvisforge-5.1/gforge/plugins/contribtracker/www/project_admin.php
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/gforge/plugins/contribtracker/www/project_admin.php 2011-02-28 02:50:59 UTC (rev 14110)
+++ trunk/gforge_base/evolvisforge-5.1/gforge/plugins/contribtracker/www/project_admin.php 2011-02-28 02:51:01 UTC (rev 14111)
@@ -35,7 +35,8 @@
'del_contrib',
'post_edit_contrib',
'del_part',
- 'add_part')) ;
+ 'add_part',
+ 'move_part')) ;
function check_contrib_id ($c_id, $g_id) {
$contrib = new ContribTrackerContribution ($c_id) ;
@@ -62,7 +63,17 @@
}
return $date ;
}
-
+function check_updown () {
+ $up = getStringFromRequest ('up') ;
+ $down = getStringFromRequest ('down') ;
+ if ($up != '') {
+ return 1 ;
+ } elseif ($down != '') {
+ return -1 ;
+ } else {
+ return 0 ;
+ }
+}
// Get and validate parameters, error if tampered with
switch ($action) {
@@ -93,6 +104,13 @@
$part_id = getIntFromRequest ('part_id') ;
check_part_id ($part_id, $contrib_id) ;
break ;
+case 'move_part':
+ $contrib_id = getIntFromRequest ('contrib_id') ;
+ check_contrib_id ($contrib_id, $group_id) ;
+ $part_id = getIntFromRequest ('part_id') ;
+ check_part_id ($part_id, $contrib_id) ;
+ $updown = check_updown () ;
+ break ;
case 'add_part':
$contrib_id = getIntFromRequest ('contrib_id') ;
check_contrib_id ($contrib_id, $group_id) ;
@@ -135,6 +153,15 @@
$part->delete () ;
$action = 'edit_contrib' ;
break ;
+case 'move_part':
+ $part = new ContribTrackerParticipation ($part_id) ;
+ if ($updown > 0) {
+ $part->moveUp() ;
+ } elseif ($updown < 0) {
+ $part->moveDown() ;
+ }
+ $action = 'edit_contrib' ;
+ break ;
case 'add_part':
$contrib = new ContribTrackerContribution ($contrib_id) ;
$actor = new ContribTrackerActor ($actor_id) ;
@@ -215,6 +242,14 @@
<input type="hidden" name="part_id" value="<?php echo $p->getId() ?>" />
<input type="submit" name="submit" value="<?php echo _('Delete') ?>" />
</form>
+<form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/project_admin.php') ?>" method="post">
+<input type="hidden" name="action" value="move_part" />
+<input type="hidden" name="group_id" value="<?php echo $group_id ?>" />
+<input type="hidden" name="contrib_id" value="<?php echo $contrib->getId() ?>" />
+<input type="hidden" name="part_id" value="<?php echo $p->getId() ?>" />
+<input type="submit" name="down" value="<?php echo _('Move participant down') ?>" />
+<input type="submit" name="up" value="<?php echo _('Move participant up') ?>" />
+</form>
<?php
print '</li>' ;
}
@@ -245,7 +280,6 @@
</form>
<?php
$contribs = $plugin->getContributionsByGroup ($group) ;
- usort ($contribs, array ($plugin, "ContribComparator")) ;
if (count ($contribs) != 0) {
print '<h1>'._('Existing contributions').'</h1>' ;
More information about the evolvis-commits
mailing list