New admin increase feature
TODO: Add to the menu somewhere TODO: Test ;-) Signed-off-by: Michael Tänzer <neo@nhng.de>
This commit is contained in:
parent
1169be1f58
commit
93f7bf20f6
3 changed files with 96 additions and 0 deletions
|
@ -7,6 +7,11 @@ class ManageAccountController extends Zend_Controller_Action
|
||||||
{
|
{
|
||||||
const MAX_POINTS_PER_ASSURANCE = 35;
|
const MAX_POINTS_PER_ASSURANCE = 35;
|
||||||
const MAX_ASSURANCE_POINTS = 100;
|
const MAX_ASSURANCE_POINTS = 100;
|
||||||
|
const MAX_POINTS_TOTAL = 150;
|
||||||
|
const ADMIN_INCREASE_FRAGMENT_SIZE = 2;
|
||||||
|
|
||||||
|
// Value used in the database to identify a admin increase
|
||||||
|
const ADMIN_INCREASE_METHOD = 'Administrative Increase';
|
||||||
|
|
||||||
protected $db;
|
protected $db;
|
||||||
|
|
||||||
|
@ -84,6 +89,70 @@ class ManageAccountController extends Zend_Controller_Action
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function adminIncreaseAction()
|
||||||
|
{
|
||||||
|
// Validate form
|
||||||
|
$form = $this->getAdminIncreaseForm();
|
||||||
|
if (!$this->getRequest()->isPost() || !$form->isValid($_POST)) {
|
||||||
|
$this->view->admin_increase_form = $form;
|
||||||
|
return $this->render('admin-increase-form');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Form is valid -> get values for processing
|
||||||
|
$values = $form->getValues();
|
||||||
|
|
||||||
|
// Get user data
|
||||||
|
$user['id'] = $this->getUserId();
|
||||||
|
$user['points'] = $this->getPoints($user['id']);
|
||||||
|
|
||||||
|
|
||||||
|
// Do the actual increase
|
||||||
|
$increase = array(); // Make sure the array is empty
|
||||||
|
$increase['from'] = $user['id'];
|
||||||
|
$increase['to'] = $user['id'];
|
||||||
|
$increase['location'] = $values['location'];
|
||||||
|
$increase['date'] = $values['date'];
|
||||||
|
$increase['method'] = self::ADMIN_INCREASE_METHOD;
|
||||||
|
$increase['when'] = new Zend_Db_Expr('now()');
|
||||||
|
$this->view->adminIncreasesDone = array();
|
||||||
|
|
||||||
|
$quantity = $values['quantity'];
|
||||||
|
do {
|
||||||
|
// Split up into multiple increases if fragment flag is set
|
||||||
|
if ($values['fragment'] == '1' &&
|
||||||
|
$quantity > self::ADMIN_INCREASE_FRAGMENT_SIZE) {
|
||||||
|
$increase['awarded'] = self::ADMIN_INCREASE_FRAGMENT_SIZE;
|
||||||
|
$quantity -= self::ADMIN_INCREASE_FRAGMENT_SIZE;
|
||||||
|
} else {
|
||||||
|
$increase['awarded'] = $quantity;
|
||||||
|
$quantity = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only assign points within the limit if unlimited flag is not set
|
||||||
|
if ($values['unlimited'] != '1') {
|
||||||
|
if ($user['points'] >= self::MAX_POINTS_TOTAL) {
|
||||||
|
// No more administrative increases should be done
|
||||||
|
break;
|
||||||
|
} elseif ($user['points'] + $increase['awarded'] > self::MAX_POINTS_TOTAL) {
|
||||||
|
$increase['awarded'] = self::MAX_POINTS_TOTAL - $user['points'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Admin increases always have `points` == `awarded`
|
||||||
|
$increase['points'] = $increase['awarded'];
|
||||||
|
|
||||||
|
$this->db->insert('notary', $increase);
|
||||||
|
|
||||||
|
$user['points'] += $increase['points'];
|
||||||
|
$this->view->adminIncreasesDone[] = $increase['points'];
|
||||||
|
} while ($quantity > 0);
|
||||||
|
|
||||||
|
// Maybe user is now assurer
|
||||||
|
$this->fixAssurerFlag($user['id']);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get and check the user ID of the current user
|
* Get and check the user ID of the current user
|
||||||
*
|
*
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Michael Tänzer
|
||||||
|
* @todo Text
|
||||||
|
*/
|
||||||
|
?>
|
||||||
|
|
||||||
|
<?php print $this->admin_increase_form ?>
|
|
@ -0,0 +1,19 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Michael Tänzer
|
||||||
|
* @todo Text
|
||||||
|
*/
|
||||||
|
?>
|
||||||
|
|
||||||
|
<h1><?php print I18n::_('Points added successfully')?></h1>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr><th>#</th><th><?php print I18n::_('Number of points')?></th></tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php foreach ($this->adminIncreasesDone as $i => $points) {
|
||||||
|
printf('<tr><td> %1$d </td><td> %2$d </td></tr>', $i, $points);
|
||||||
|
}?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
Loading…
Reference in a new issue