diff --git a/manager/application/controllers/ManageAccountController.php b/manager/application/controllers/ManageAccountController.php index 98147ba..6cb238a 100644 --- a/manager/application/controllers/ManageAccountController.php +++ b/manager/application/controllers/ManageAccountController.php @@ -7,6 +7,11 @@ class ManageAccountController extends Zend_Controller_Action { const MAX_POINTS_PER_ASSURANCE = 35; 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; @@ -84,6 +89,70 @@ class ManageAccountController extends Zend_Controller_Action 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 * diff --git a/manager/application/views/scripts/manage-account/admin-increase-form.phtml b/manager/application/views/scripts/manage-account/admin-increase-form.phtml new file mode 100644 index 0000000..16d6f31 --- /dev/null +++ b/manager/application/views/scripts/manage-account/admin-increase-form.phtml @@ -0,0 +1,8 @@ + + +admin_increase_form ?> diff --git a/manager/application/views/scripts/manage-account/admin-increase.phtml b/manager/application/views/scripts/manage-account/admin-increase.phtml new file mode 100644 index 0000000..bf984d3 --- /dev/null +++ b/manager/application/views/scripts/manage-account/admin-increase.phtml @@ -0,0 +1,19 @@ + + +
+ +# | |
---|---|
%1$d | %2$d |