summaryrefslogtreecommitdiff
path: root/manager
diff options
context:
space:
mode:
authorMichael Tänzer <neo@nhng.de>2011-06-28 01:20:56 +0200
committerMichael Tänzer <neo@nhng.de>2011-06-28 01:20:56 +0200
commit79ca9e7bee49273c5a115e2b21d54c8ea9aea3f6 (patch)
tree03b8aa6a9019c09c0aa5dacc5dd968fd9aeaed25 /manager
parentad8a76ce073646c159e1172384515acef9c28c83 (diff)
downloadcacert-mgr-79ca9e7bee49273c5a115e2b21d54c8ea9aea3f6.tar.gz
cacert-mgr-79ca9e7bee49273c5a115e2b21d54c8ea9aea3f6.tar.xz
cacert-mgr-79ca9e7bee49273c5a115e2b21d54c8ea9aea3f6.zip
Implement administrative increase in the user model
Signed-off-by: Michael Tänzer <neo@nhng.de>
Diffstat (limited to 'manager')
-rw-r--r--manager/application/controllers/ManageAccountController.php35
-rw-r--r--manager/application/models/User.php43
2 files changed, 38 insertions, 40 deletions
diff --git a/manager/application/controllers/ManageAccountController.php b/manager/application/controllers/ManageAccountController.php
index bcb1287..f3da229 100644
--- a/manager/application/controllers/ManageAccountController.php
+++ b/manager/application/controllers/ManageAccountController.php
@@ -94,54 +94,35 @@ class ManageAccountController extends Zend_Controller_Action
$values = $form->getValues();
// Get user data
- $user['id'] = $this->getUserId();
- $user['points'] = $this->getPoints($user['id']);
-
+ $user = Default_Model_User::findCurrentUser();
- // 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;
+ $points = self::ADMIN_INCREASE_FRAGMENT_SIZE;
$quantity -= self::ADMIN_INCREASE_FRAGMENT_SIZE;
} else {
- $increase['awarded'] = $quantity;
+ $points = $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) {
+ if ($user->getPoints() >= 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'];
+ } elseif ($user->getPoints() + $points > self::MAX_POINTS_TOTAL) {
+ $points = self::MAX_POINTS_TOTAL - $user->getPoints();
}
}
- // Admin increases always have `points` == `awarded`
- $increase['points'] = $increase['awarded'];
-
- $this->db->insert('notary', $increase);
-
- $user['points'] += $increase['points'];
- $this->view->adminIncreasesDone[] = $increase['points'];
+ $user->adminIncrease($points, $values['location'], $values['date']);
+ $this->view->adminIncreasesDone[] = $points;
} while ($quantity > 0);
- // Maybe user is now assurer
- $this->fixAssurerFlag($user['id']);
-
return;
}
diff --git a/manager/application/models/User.php b/manager/application/models/User.php
index 7b7a519..86556de 100644
--- a/manager/application/models/User.php
+++ b/manager/application/models/User.php
@@ -274,25 +274,42 @@ class Default_Model_User {
$addpoints = 1;
}
- $increase = array();
- $increase['from'] = $this->id;
- $increase['to'] = $this->id;
- $increase['points'] = $addpoints;
- $increase['awarded'] = $addpoints;
- $increase['location'] = $location;
- $increase['date'] = $date;
- $increase['method'] = 'Administrative Increase';
- $increase['when'] = new Zend_Db_Expr('now()');
-
- $this->db->insert('notary', $increase);
- $this->points += $addpoints;
- // No need to fix assurer flag here
+ $this->adminIncrease($addpoints, $location, $date);
}
return $rounddown;
}
/**
+ * Do an administrative increase
+ *
+ * @param $points int
+ * @param $location string
+ * @param $date string
+ */
+ public function adminIncrease($points, $location, $date) {
+ //Sanitize inputs
+ $points = intval($points);
+ $location = stripslashes($location);
+ $date = stripslashes($date);
+
+ $increase = array();
+ $increase['from'] = $this->id;
+ $increase['to'] = $this->id;
+ $increase['points'] = $points;
+ $increase['awarded'] = $points;
+ $increase['location'] = $location;
+ $increase['date'] = $date;
+ $increase['method'] = 'Administrative Increase';
+ $increase['when'] = new Zend_Db_Expr('now()');
+
+ $this->db->insert('notary', $increase);
+ $this->points += $points;
+
+ $this->fixAssurerFlag();
+ }
+
+ /**
* Maximum number of points the user may issue
*
* @return int