Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F12373658
usergroup.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
usergroup.php
View Options
<?php
/**
* _, __, _, _ __, _ _, _, _
* / \ |_) (_ | | \ | /_\ |\ |
* \ / |_) , ) | |_/ | | | | \|
* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
*
* UserGroup class
*
* @package ObsidianWorkspaces
* @subpackage Model
* @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
* @license http://www.opensource.org/licenses/bsd-license.php BSD
* @filesource
*/
use
Waystone\Workspaces\Engines\Errors\ErrorHandling
;
/**
* UserGroup class
*
* This class maps the users_groups table.
*/
class
UserGroup
{
public
$id
;
public
$code
;
public
$title
;
public
$description
;
/**
* Initializes a new instance
*
* @param int $id the primary key
*/
function
__construct
(
$id
=
NULL
)
{
if
(
$id
)
{
$this
->
id
=
$id
;
$this
->
load_from_database
();
}
}
/**
* Loads the object UserGroup (ie fill the properties) from the $_POST array
*/
function
load_from_form
()
{
if
(
array_key_exists
(
'code'
,
$_POST
))
$this
->
code
=
$_POST
[
'code'
];
if
(
array_key_exists
(
'title'
,
$_POST
))
$this
->
title
=
$_POST
[
'title'
];
if
(
array_key_exists
(
'description'
,
$_POST
))
$this
->
description
=
$_POST
[
'description'
];
}
/**
* Loads the object UserGroup (ie fill the properties) from the SQL row
*/
function
load_from_row
(
$row
)
{
$this
->
id
=
$row
[
'group_id'
];
$this
->
code
=
$row
[
'group_code'
];
$this
->
title
=
$row
[
'group_title'
];
$this
->
description
=
$row
[
'group_description'
];
}
/**
* Loads the object UserGroup (ie fill the properties) from the database
*/
function
load_from_database
()
{
global
$db
;
$id
=
$db
->
escape
(
$this
->
id
);
$sql
=
"SELECT * FROM "
.
TABLE_UGROUPS
.
" WHERE group_id = '"
.
$id
.
"'"
;
if
(!
$result
=
$db
->
query
(
$sql
))
ErrorHandling
::
messageAndDie
(
SQL_ERROR
,
"Unable to query users_groups"
,
''
,
__LINE__
,
__FILE__
,
$sql
);
if
(!
$row
=
$db
->
fetchRow
(
$result
))
{
$this
->
lastError
=
"UserGroup unknown: "
.
$this
->
id
;
return
false
;
}
$this
->
load_from_row
(
$row
);
return
true
;
}
/**
* Loads the specified user group from code
*
* @param string $code The user group code
* @return UserGroup The specified user group instance
*/
public
static
function
fromCode
(
$code
)
{
global
$db
;
$code
=
$db
->
escape
(
$code
);
$sql
=
"SELECT * FROM "
.
TABLE_UGROUPS
.
" WHERE group_code = '"
.
$code
.
"'"
;
if
(!
$result
=
$db
->
query
(
$sql
))
ErrorHandling
::
messageAndDie
(
SQL_ERROR
,
"Unable to query group"
,
''
,
__LINE__
,
__FILE__
,
$sql
);
if
(!
$row
=
$db
->
fetchRow
(
$result
))
{
throw
new
Exception
(
"Group unknown: "
.
$code
);
}
$instance
=
new
static
();
$instance
->
load_from_row
(
$row
);
return
$instance
;
}
/**
* Saves to database
*/
function
save_to_database
()
{
global
$db
;
$id
=
$this
->
id
?
"'"
.
$db
->
escape
(
$this
->
id
)
.
"'"
:
'NULL'
;
$code
=
$db
->
escape
(
$this
->
code
);
$title
=
$db
->
escape
(
$this
->
title
);
$description
=
$db
->
escape
(
$this
->
description
);
//Updates or inserts
$sql
=
"REPLACE INTO "
.
TABLE_UGROUPS
.
" (`group_id`, `group_code`, `group_title`, `group_description`) VALUES ('$id', '$code', '$title', '$description')"
;
if
(!
$db
->
query
(
$sql
))
{
ErrorHandling
::
messageAndDie
(
SQL_ERROR
,
"Unable to save"
,
''
,
__LINE__
,
__FILE__
,
$sql
);
}
if
(!
$this
->
id
)
{
//Gets new record id value
$this
->
id
=
$db
->
nextId
();
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Nov 1, 18:09 (1 d, 10 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3116030
Default Alt Text
usergroup.php (3 KB)
Attached To
Mode
rOBSIDIAN Obsidian Workspaces
Attached
Detach File
Event Timeline
Log In to Comment