</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>';
$results[] = new ContribTrackerContribution ($id) ;
}
+ $plugin = plugin_get_object ('contribtracker') ;
+ usort ($results, array ($plugin, "ContribComparator")) ;
return $results ;
}
$results[] = new ContribTrackerContribution ($id) ;
}
+ $plugin = plugin_get_object ('contribtracker') ;
+ usort ($results, array ($plugin, "ContribComparator")) ;
return $results ;
}
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 {
$results[] = new ContribTrackerParticipation ($id) ;
}
+ $plugin = plugin_get_object ('contribtracker') ;
+ usort ($results, array ($plugin, "ParticipationComparator")) ;
return $results ;
}
$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 {
}
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 ()));
}
$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',
return false ;
}
+ db_begin () ;
+ $curindex = $this->getIndex() ;
$res = db_query_params ('DELETE FROM plugin_contribtracker_participation WHERE participation_id = $1',
array ($id)) ;
if (!$res) {
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'] ;
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']) ;
}
'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) ;
}
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) {
$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) ;
$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) ;
<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>' ;
}
</form>
<?php
$contribs = $plugin->getContributionsByGroup ($group) ;
- usort ($contribs, array ($plugin, "ContribComparator")) ;
if (count ($contribs) != 0) {
print '<h1>'._('Existing contributions').'</h1>' ;