Commit 3cc65def authored by Martyn Smith's avatar Martyn Smith Committed by Martyn Smith
Browse files

Added quota functions

parent a256d4ad
......@@ -64,6 +64,8 @@ class User {
'inactivemailsent' => 0,
'staff' => false,
'admin' => false,
'quota' => 0,
'quotaused' => 0,
'firstname' => '',
'lastname' => '',
'preferredname' => '',
......@@ -104,6 +106,9 @@ class User {
if (!isset($this->defaults[$key])) {
throw new InvalidArgumentException($key);
}
if ($key == 'quotaused') {
throw new InvalidArgumentException('quotaused should be set via the quota_* methods');
}
$this->SESSION->set("user/$key", $value);
}
......@@ -205,6 +210,37 @@ class User {
return $this->stdclass;
}
public function quota_add($bytes) {
if (!is_numeric($bytes) || $bytes < 0) {
throw new InvalidArgumentException('parameter must be a positive integer to add to the quota');
}
if (!$this->quota_allowed($bytes)) {
throw new QuotaExceededException('Adding ' . $bytes . ' bytes would exceed the user\'s quota');
}
$newquota = $this->get('quotaused') + $bytes;
$this->SESSION->set("user/quotaused", $newquota);
update_record('usr', array('quotaused' => $newquota), array('id' => $this->get('id')));
}
public function quota_remove($bytes) {
if (!is_numeric($bytes) || $bytes < 0) {
throw new InvalidArgumentException('parameter must be a positive integer to remove from the quota');
}
$newquota = $this->get('quotaused') - $bytes;
if ($newquota < 0) {
$newquota = 0;
}
$this->SESSION->set("user/quotaused", $newquota);
update_record('usr', array('quotaused' => $newquota), array('id' => $this->get('id')));
}
public function quota_allowed($bytes) {
if ($this->get('quotaused') + $bytes > $this->get('quota')) {
return false;
}
return true;
}
}
......
......@@ -648,6 +648,11 @@ class UserNotFoundException extends UserException {}
*/
class CommunityNotFoundException extends UserException {}
/**
* Exception - fired when something happens that would make the user exceed their quota
*/
class QuotaExceededException extends UserException {}
/**
* Exception - anything to do with template parsing
*/
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment