vote: Add support for deleting votes
This commit is contained in:
committed by
Chris Morgan
parent
835d82e49b
commit
8d9cefe7b6
@@ -55,6 +55,21 @@ class vote
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
/* A vote needs to have a versionId, so if it doesn't that means it is not in the
|
||||
database or it was not selected in the vote editor */
|
||||
if(!$this->iVersionId)
|
||||
return TRUE;
|
||||
|
||||
$hResult = query_parameters("DELETE FROM appVotes WHERE id = '?'", $this->iVoteId);
|
||||
|
||||
if(!$hResult)
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
class voteManager
|
||||
@@ -82,7 +97,7 @@ class voteManager
|
||||
|
||||
public function outputEditor($aClean = null)
|
||||
{
|
||||
echo "The following shows your current votes. Check the boxes next to the apps you wish to replace with a vote for ".version::fullNameLink($aClean['iVersionId']).".";
|
||||
echo "The following shows your current votes. Check the boxes next to the apps you wish to replace with a vote for ".version::fullNameLink($aClean['iVersionId'])." or delete.";
|
||||
|
||||
$oTable = new table();
|
||||
$this->aVotes = $this->getVotes();
|
||||
@@ -107,6 +122,11 @@ class voteManager
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
function objectGetMail($sAction, $bMailSubmitter, $bParentAction)
|
||||
{
|
||||
return array(null, null, null); /* No mail */
|
||||
}
|
||||
|
||||
public function mustBeQueued()
|
||||
{
|
||||
return FALSE;
|
||||
@@ -127,6 +147,22 @@ class voteManager
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$bSuccess = TRUE;
|
||||
|
||||
if(!is_array($this->aVotes))
|
||||
$this->aVotes = $this->getVotes();
|
||||
|
||||
foreach($this->aVotes as $oVote)
|
||||
{
|
||||
if(!$oVote->delete())
|
||||
$bSuccess = FALSE;
|
||||
}
|
||||
|
||||
return $bSuccess;
|
||||
}
|
||||
|
||||
public function update()
|
||||
{
|
||||
foreach($this->aVotes as $oVote)
|
||||
|
||||
@@ -23,7 +23,7 @@ function test_voteManager_getVotes()
|
||||
|
||||
/* Tests that the votes are saved to the database and that we cannot create more than MAX_VOTES.
|
||||
Note that a user always has MAX_VOTES even though they're not in the DB, so we use update instead of create */
|
||||
function test_vote_update()
|
||||
function test_vote_update_delete()
|
||||
{
|
||||
$iUserId = 655000;
|
||||
|
||||
@@ -60,13 +60,26 @@ function test_vote_update()
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* We don't normally delete votes, so we have to do it manually */
|
||||
query_parameters("DELETE FROM appVotes WHERE userId = '?'", $iUserId);
|
||||
/* Now the entries should be gone again */
|
||||
$oVoteManager->delete();
|
||||
$iExpected = 0;
|
||||
$iReceived = 0; /* Incremented below */
|
||||
foreach($oVoteManager->getVotes() as $oVote)
|
||||
{
|
||||
if($oVote->iVoteId)
|
||||
$iReceived++;
|
||||
}
|
||||
|
||||
if($iExpected != $iReceived)
|
||||
{
|
||||
echo "Expected $iExpected votes after deletion, got $iReceived\n";
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
run_test("test_voteManager_getVotes");
|
||||
run_test("test_vote_update");
|
||||
run_test("test_vote_update_delete");
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user