implement user roles and user seminary roles as basic ACL

This commit is contained in:
coderkun 2014-01-30 00:59:02 +01:00
commit fcc7e89fcd
10 changed files with 481 additions and 67 deletions

77
models/UserrolesModel.inc Normal file
View file

@ -0,0 +1,77 @@
<?php
/**
* The Legend of Z
*
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
* @copyright 2014 Heinrich-Heine-Universität Düsseldorf
* @license http://www.gnu.org/licenses/gpl.html
* @link https://bitbucket.org/coderkun/the-legend-of-z
*/
namespace hhu\z\models;
/**
* Model to interact with userroles-table.
*
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
*/
class UserrolesModel extends \hhu\z\Model
{
/**
* Construct a new UserrolesModel.
*/
public function __construct()
{
parent::__construct();
}
/**
* Get all userroles for an user referenced by its ID.
*
* @param int $userId ID of an user
* @return array Userroles for an user
*/
public function getUserrolesForUserById($userId)
{
return $this->db->query(
'SELECT userroles.id, userroles.created, userroles.name '.
'FROM users_userroles '.
'LEFT JOIN userroles ON userroles.id = users_userroles.userrole_id '.
'WHERE users_userroles.user_id = ?',
'i',
$userId
);
}
/**
* Get all userroles for an user referenced by its URL-username.
*
* @param string $userUrl URL-Username of an user
* @return array Userroles for an user
*/
public function getUserrolesForUserByUrl($userUrl)
{
return $this->db->query(
'SELECT userroles.id, userroles.created, userroles.name '.
'FROM users '.
'LEFT JOIN users_userroles ON users_userroles.user_id = users.id '.
'LEFT JOIN userroles ON userroles.id = users_userroles.userrole_id '.
'WHERE users.url = ?',
's',
$userUrl
);
}
}
?>

View file

@ -0,0 +1,78 @@
<?php
/**
* The Legend of Z
*
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
* @copyright 2014 Heinrich-Heine-Universität Düsseldorf
* @license http://www.gnu.org/licenses/gpl.html
* @link https://bitbucket.org/coderkun/the-legend-of-z
*/
namespace hhu\z\models;
/**
* Model to interact with userseminaryroles-table.
*
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
*/
class UserseminaryrolesModel extends \hhu\z\Model
{
/**
* Construct a new UserseminaryrolesModel.
*/
public function __construct()
{
parent::__construct();
}
/**
* Get all userseminaryroles for an user referenced by its ID.
*
* @param int $userId ID of an user
* @return array Userseminaryroles for an user
*/
public function getUserseminaryrolesForUserById($userId, $seminaryId)
{
return $this->db->query(
'SELECT userseminaryroles.id, userseminaryroles.created, userseminaryroles.name '.
'FROM users_userseminaryroles '.
'LEFT JOIN userseminaryroles ON userseminaryroles.id = users_userseminaryroles.userseminaryrole_id '.
'WHERE users_userseminaryroles.user_id = ? AND users_userseminaryroles.seminary_id = ?',
'ii',
$userId, $seminaryId
);
}
/**
* Get all userseminaryroles for an user referenced by its
* URL-username.
*
* @param string $userUrl URL-Username of an user
* @return array Userseminaryroles for an user
*/
public function getUserrolesForUserByUrl($userUrl)
{
return $this->db->query(
'SELECT userroles.id, userroles.created, userroles.name '.
'FROM users '.
'LEFT JOIN users_userseminaryroles ON users_userseminaryroles.user_id = users.id '.
'LEFT JOIN userseminaryroles ON userseminaryroles.id = users_userseminaryroles.userseminaryrole_id '.
'WHERE users.url = ?',
's',
$userUrl
);
}
}
?>