Implement administrative increase in the user model
Signed-off-by: Michael Tänzer <neo@nhng.de>
This commit is contained in:
parent
ad8a76ce07
commit
79ca9e7bee
2 changed files with 38 additions and 40 deletions
|
@ -94,54 +94,35 @@ class ManageAccountController extends Zend_Controller_Action
|
||||||
$values = $form->getValues();
|
$values = $form->getValues();
|
||||||
|
|
||||||
// Get user data
|
// Get user data
|
||||||
$user['id'] = $this->getUserId();
|
$user = Default_Model_User::findCurrentUser();
|
||||||
$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();
|
$this->view->adminIncreasesDone = array();
|
||||||
|
|
||||||
$quantity = $values['quantity'];
|
$quantity = $values['quantity'];
|
||||||
do {
|
do {
|
||||||
// Split up into multiple increases if fragment flag is set
|
// Split up into multiple increases if fragment flag is set
|
||||||
if ($values['fragment'] == '1' &&
|
if ($values['fragment'] == '1' &&
|
||||||
$quantity > self::ADMIN_INCREASE_FRAGMENT_SIZE) {
|
$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;
|
$quantity -= self::ADMIN_INCREASE_FRAGMENT_SIZE;
|
||||||
} else {
|
} else {
|
||||||
$increase['awarded'] = $quantity;
|
$points = $quantity;
|
||||||
$quantity = 0;
|
$quantity = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only assign points within the limit if unlimited flag is not set
|
// Only assign points within the limit if unlimited flag is not set
|
||||||
if ($values['unlimited'] != '1') {
|
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
|
// No more administrative increases should be done
|
||||||
break;
|
break;
|
||||||
} elseif ($user['points'] + $increase['awarded'] > self::MAX_POINTS_TOTAL) {
|
} elseif ($user->getPoints() + $points > self::MAX_POINTS_TOTAL) {
|
||||||
$increase['awarded'] = self::MAX_POINTS_TOTAL - $user['points'];
|
$points = self::MAX_POINTS_TOTAL - $user->getPoints();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Admin increases always have `points` == `awarded`
|
$user->adminIncrease($points, $values['location'], $values['date']);
|
||||||
$increase['points'] = $increase['awarded'];
|
$this->view->adminIncreasesDone[] = $points;
|
||||||
|
|
||||||
$this->db->insert('notary', $increase);
|
|
||||||
|
|
||||||
$user['points'] += $increase['points'];
|
|
||||||
$this->view->adminIncreasesDone[] = $increase['points'];
|
|
||||||
} while ($quantity > 0);
|
} while ($quantity > 0);
|
||||||
|
|
||||||
// Maybe user is now assurer
|
|
||||||
$this->fixAssurerFlag($user['id']);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -274,22 +274,39 @@ class Default_Model_User {
|
||||||
$addpoints = 1;
|
$addpoints = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$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 = array();
|
||||||
$increase['from'] = $this->id;
|
$increase['from'] = $this->id;
|
||||||
$increase['to'] = $this->id;
|
$increase['to'] = $this->id;
|
||||||
$increase['points'] = $addpoints;
|
$increase['points'] = $points;
|
||||||
$increase['awarded'] = $addpoints;
|
$increase['awarded'] = $points;
|
||||||
$increase['location'] = $location;
|
$increase['location'] = $location;
|
||||||
$increase['date'] = $date;
|
$increase['date'] = $date;
|
||||||
$increase['method'] = 'Administrative Increase';
|
$increase['method'] = 'Administrative Increase';
|
||||||
$increase['when'] = new Zend_Db_Expr('now()');
|
$increase['when'] = new Zend_Db_Expr('now()');
|
||||||
|
|
||||||
$this->db->insert('notary', $increase);
|
$this->db->insert('notary', $increase);
|
||||||
$this->points += $addpoints;
|
$this->points += $points;
|
||||||
// No need to fix assurer flag here
|
|
||||||
}
|
|
||||||
|
|
||||||
return $rounddown;
|
$this->fixAssurerFlag();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue