Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mahara
mahara
Commits
3cc65def
Commit
3cc65def
authored
Jan 16, 2007
by
Martyn Smith
Committed by
Martyn Smith
Jan 16, 2007
Browse files
Added quota functions
parent
a256d4ad
Changes
2
Hide whitespace changes
Inline
Side-by-side
htdocs/auth/user.php
View file @
3cc65def
...
...
@@ -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
;
}
}
...
...
htdocs/lib/errors.php
View file @
3cc65def
...
...
@@ -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
*/
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment