change user Seminary roles to Character roles
This commit is contained in:
parent
87f58e2c5b
commit
2185a7c2a4
26 changed files with 145 additions and 156 deletions
|
|
@ -81,13 +81,13 @@
|
|||
foreach($seminarymediaIds as &$seminarymediaId)
|
||||
{
|
||||
$replacement = null;
|
||||
if(!is_null(\hhu\z\controllers\SeminaryRoleController::$seminary) && $this->loadMediaModel())
|
||||
if(!is_null(\hhu\z\controllers\SeminaryController::$seminary) && $this->loadMediaModel())
|
||||
{
|
||||
try {
|
||||
$medium = self::$Media->getSeminaryMediaById($seminarymediaId);
|
||||
$replacement = sprintf(
|
||||
'<img src="%s" alt="%s" />',
|
||||
$this->linker->link(array('media','seminary', \hhu\z\controllers\SeminaryRoleController::$seminary['url'],$medium['url'])),
|
||||
$this->linker->link(array('media','seminary', \hhu\z\controllers\SeminaryController::$seminary['url'],$medium['url'])),
|
||||
$medium['description']
|
||||
);
|
||||
}
|
||||
|
|
|
|||
280
app/controllers/SeminaryController.inc
Normal file
280
app/controllers/SeminaryController.inc
Normal file
|
|
@ -0,0 +1,280 @@
|
|||
<?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\controllers;
|
||||
|
||||
|
||||
/**
|
||||
* Abstract class for implementing a Controller for a Seminary and its
|
||||
* concepts.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
abstract class SeminaryController extends \hhu\z\controllers\IntermediateController
|
||||
{
|
||||
/**
|
||||
* Required components
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $components = array('achievement', 'auth');
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('seminaries', 'characters', 'characterroles', 'achievements');
|
||||
/**
|
||||
* Current Seminary
|
||||
*
|
||||
* var array
|
||||
*/
|
||||
public static $seminary = null;
|
||||
/**
|
||||
* Character of current user and Seminary
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $character = null;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new Seminary Controller.
|
||||
*
|
||||
* @throws DriverNotFoundException
|
||||
* @throws DriverNotValidException
|
||||
* @throws ModelNotValidException
|
||||
* @throws ModelNotFoundException
|
||||
* @throws ViewNotFoundException
|
||||
* @param string $layoutName Name of the current Layout
|
||||
* @param string $action Current Action
|
||||
* @param Agent $agent Corresponding Agent
|
||||
*/
|
||||
public function __construct($layoutName, $action, $agent)
|
||||
{
|
||||
parent::__construct($layoutName, $action, $agent);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Prefilter that is executed before running the Controller.
|
||||
*
|
||||
* @param Request $request Current request
|
||||
* @param Response $response Current response
|
||||
*/
|
||||
public function preFilter(\nre\core\Request $request, \nre\core\Response $response)
|
||||
{
|
||||
parent::preFilter($request, $response);
|
||||
|
||||
// Get Seminary and Character data
|
||||
try {
|
||||
self::$seminary = $this->Seminaries->getSeminaryByUrl($this->request->getParam(3));
|
||||
if(!is_null(self::$user))
|
||||
{
|
||||
self::$character = $this->Characters->getCharacterForUserAndSeminary(self::$user['id'], self::$seminary['id']);
|
||||
self::$character['characterroles'] = array_map(function($r) { return $r['name']; }, $this->Characterroles->getCharacterrolesForCharacterById(self::$character['id']));
|
||||
}
|
||||
}
|
||||
catch(\nre\exceptions\IdNotFoundException $e) {
|
||||
}
|
||||
|
||||
// Check permissions
|
||||
$this->checkPermission($request, $response);
|
||||
|
||||
// Check achievements
|
||||
$this->checkAchievements($request, $response);
|
||||
|
||||
// Set Seminary and Character data
|
||||
$this->set('loggedSeminary', self::$seminary);
|
||||
$this->set('loggedCharacter', self::$character);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Postfilter that is executed after running the Controller.
|
||||
*
|
||||
* @param Request $request Current request
|
||||
* @param Response $response Current response
|
||||
*/
|
||||
public function postFilter(\nre\core\Request $request, \nre\core\Response $response)
|
||||
{
|
||||
parent::postFilter($request, $response);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Check user permissions.
|
||||
*
|
||||
* @throws AccessDeniedException
|
||||
*/
|
||||
private function checkPermission(\nre\core\Request $request, \nre\core\Response $response)
|
||||
{
|
||||
// Do not check index page
|
||||
if(is_null($request->getParam(3))) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Determine permissions for current action
|
||||
$action = $this->request->getParam(2, 'action');
|
||||
if(!property_exists($this, 'seminaryPermissions')) {
|
||||
return; // Allow if nothing is specified
|
||||
}
|
||||
if(!array_key_exists($action, $this->seminaryPermissions)) {
|
||||
return; // Allow if Action is not specified
|
||||
}
|
||||
$permissions = $this->seminaryPermissions[$action];
|
||||
|
||||
|
||||
// Check permissions
|
||||
if(!array_key_exists('characterroles', self::$character) || count(array_intersect(self::$character['characterroles'], $permissions)) == 0) {
|
||||
throw new \nre\exceptions\AccessDeniedException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check for newly achieved Achievements.
|
||||
*/
|
||||
private function checkAchievements(\nre\core\Request $request, \nre\core\Response $response)
|
||||
{
|
||||
// Check if Character is present
|
||||
if(is_null(self::$character)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get unachieved Achievments
|
||||
$achievements = $this->Achievements->getUnachhievedAchievementsForCharacter(self::$seminary['id'], self::$character['id']);
|
||||
if(in_array('user', self::$character['characterroles'])) {
|
||||
$achievements = array_merge($achievements, $this->Achievements->getUnachievedOnlyOnceAchievementsForSeminary(self::$seminary['id']));
|
||||
}
|
||||
|
||||
// Check conditions
|
||||
foreach($achievements as &$achievement)
|
||||
{
|
||||
// Get conditions
|
||||
$conditions = array();
|
||||
$progress = 0;
|
||||
switch($achievement['condition'])
|
||||
{
|
||||
// Date conditions
|
||||
case 'date':
|
||||
$conditionsDate = $this->Achievements->getAchievementConditionsDate($achievement['id']);
|
||||
foreach($conditionsDate as &$condition)
|
||||
{
|
||||
$conditions[] = array(
|
||||
'func' => 'checkAchievementConditionDate',
|
||||
'params' => array(
|
||||
$condition['select']
|
||||
)
|
||||
);
|
||||
}
|
||||
break;
|
||||
// Character conditions
|
||||
case 'character':
|
||||
$conditionsCharacter = $this->Achievements->getAchievementConditionsCharacter($achievement['id']);
|
||||
foreach($conditionsCharacter as &$condition)
|
||||
{
|
||||
$conditions[] = array(
|
||||
'func' => 'checkAchievementConditionCharacter',
|
||||
'params' => array(
|
||||
$condition['field'],
|
||||
$condition['value'],
|
||||
self::$character['id']
|
||||
)
|
||||
);
|
||||
}
|
||||
break;
|
||||
// Quest conditions
|
||||
case 'quest':
|
||||
$conditionsQuest = $this->Achievements->getAchievementConditionsQuest($achievement['id']);
|
||||
foreach($conditionsQuest as &$condition)
|
||||
{
|
||||
$conditions[] = array(
|
||||
'func' => 'checkAchievementConditionQuest',
|
||||
'params' => array(
|
||||
$condition['field'],
|
||||
$condition['count'],
|
||||
$condition['value'],
|
||||
$condition['status'],
|
||||
$condition['groupby'],
|
||||
$condition['quest_id'],
|
||||
self::$character['id']
|
||||
)
|
||||
);
|
||||
}
|
||||
break;
|
||||
// Achievement conditions
|
||||
case 'achievement':
|
||||
$conditionsAchievement = $this->Achievements->getAchievementConditionsAchievement($achievement['id']);
|
||||
foreach($conditionsAchievement as &$condition)
|
||||
{
|
||||
$conditions[] = array(
|
||||
'func' => 'checkAchievementConditionAchievement',
|
||||
'params' => array(
|
||||
$condition['field'],
|
||||
$condition['count'],
|
||||
$condition['value'],
|
||||
$condition['groupby'],
|
||||
$condition['meta_achievement_id'],
|
||||
self::$character['id']
|
||||
)
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Check conditions
|
||||
$achieved = ($achievement['all_conditions'] == 1);
|
||||
foreach($conditions as &$condition)
|
||||
{
|
||||
// Calculate result of condition
|
||||
$result = call_user_func_array(
|
||||
array(
|
||||
$this->Achievements,
|
||||
$condition['func']
|
||||
),
|
||||
$condition['params']
|
||||
);
|
||||
|
||||
// The overall result and abort if possible
|
||||
if($achievement['all_conditions'])
|
||||
{
|
||||
if(!$result) {
|
||||
$achieved = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if($result) {
|
||||
$achieved = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Set status
|
||||
if($achieved) {
|
||||
$this->Achievements->setAchievementAchieved($achievement['id'], self::$character['id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class AchievementsController extends \hhu\z\controllers\SeminaryRoleController
|
||||
class AchievementsController extends \hhu\z\controllers\SeminaryController
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
|
|
@ -59,7 +59,7 @@
|
|||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||
|
||||
// Get Character
|
||||
$character = SeminaryRoleController::$character;
|
||||
$character = SeminaryController::$character;
|
||||
|
||||
// Get seldom Achievements
|
||||
$seldomAchievements = $this->Achievements->getSeldomAchievements($seminary['id'], \nre\configs\AppConfig::$misc['achievements_range']);
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class CharactergroupsController extends \hhu\z\controllers\SeminaryRoleController
|
||||
class CharactergroupsController extends \hhu\z\controllers\SeminaryController
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class CharactergroupsquestsController extends \hhu\z\controllers\SeminaryRoleController
|
||||
class CharactergroupsquestsController extends \hhu\z\controllers\SeminaryController
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class CharactersController extends \hhu\z\controllers\SeminaryRoleController
|
||||
class CharactersController extends \hhu\z\controllers\SeminaryController
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
|
|
@ -268,9 +268,10 @@
|
|||
// Send notification mail to system moderators
|
||||
$subject = sprintf('new Character registration: %s', $charactername);
|
||||
$message = sprintf('User “%s” <%s> has registered a new Character “%s” for the Seminary “%s”', self::$user['username'], self::$user['email'], $charactername, self::$seminary['title']);
|
||||
$moderators = $this->Users->getUsersWithSeminaryRole(self::$seminary['id'], 'moderator');
|
||||
foreach($moderators as &$moderator)
|
||||
$characters = $this->Characters->getCharactersWithCharacterRole(self::$seminary['id'], 'moderator');
|
||||
foreach($characters as &$character)
|
||||
{
|
||||
$moderator = $this->Users->getUserById($character['user_id']);
|
||||
\hhu\z\Utils::sendMail($sender, $moderator['email'], $subject, $message);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,8 +50,8 @@
|
|||
|
||||
// Set userdata
|
||||
$this->set('loggedUser', IntermediateController::$user);
|
||||
$this->set('loggedSeminary', SeminaryRoleController::$seminary);
|
||||
$this->set('loggedCharacter', SeminaryRoleController::$character);
|
||||
$this->set('loggedSeminary', SeminaryController::$seminary);
|
||||
$this->set('loggedCharacter', SeminaryController::$character);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class LibraryController extends \hhu\z\controllers\SeminaryRoleController
|
||||
class LibraryController extends \hhu\z\controllers\SeminaryController
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
|
|
@ -59,7 +59,7 @@
|
|||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||
|
||||
// Get Character
|
||||
$character = SeminaryRoleController::$character;
|
||||
$character = SeminaryController::$character;
|
||||
|
||||
// Get Quest topics
|
||||
$totalQuestcount = 0;
|
||||
|
|
@ -100,7 +100,7 @@
|
|||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||
|
||||
// Get Character
|
||||
$character = SeminaryRoleController::$character;
|
||||
$character = SeminaryController::$character;
|
||||
|
||||
// Get Questtopic
|
||||
$questtopic = $this->Questtopics->getQuesttopicByUrl($seminary['id'], $questtopicUrl);
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class MediaController extends \hhu\z\controllers\SeminaryRoleController
|
||||
class MediaController extends \hhu\z\controllers\SeminaryController
|
||||
{
|
||||
/**
|
||||
* User permissions
|
||||
|
|
@ -220,7 +220,7 @@
|
|||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||
|
||||
// Get Character
|
||||
$character = SeminaryRoleController::$character;
|
||||
$character = SeminaryController::$character;
|
||||
|
||||
// Get Achievement
|
||||
$achievement = $this->Achievements->getAchievementByUrl($seminary['id'], $achievementUrl);
|
||||
|
|
|
|||
|
|
@ -35,8 +35,8 @@
|
|||
|
||||
// Set userdata
|
||||
$this->set('loggedUser', IntermediateController::$user);
|
||||
$this->set('loggedCharacter', SeminaryRoleController::$character);
|
||||
$this->set('loggedSeminary', SeminaryRoleController::$seminary);
|
||||
$this->set('loggedCharacter', SeminaryController::$character);
|
||||
$this->set('loggedSeminary', SeminaryController::$seminary);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class QuestgroupsController extends \hhu\z\controllers\SeminaryRoleController
|
||||
class QuestgroupsController extends \hhu\z\controllers\SeminaryController
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
|
|
@ -71,7 +71,7 @@
|
|||
$character = $this->Characters->getCharacterForUserAndSeminary($this->Auth->getUserId(), $seminary['id']);
|
||||
|
||||
// Check permission
|
||||
if(count(array_intersect(array('admin','moderator'), IntermediateController::$user['seminaryroles'])) == 0)
|
||||
if(count(array_intersect(array('admin','moderator'), SeminaryController::$character['characterroles'])) == 0)
|
||||
{
|
||||
$previousQuestgroup = $this->Questgroups->getPreviousQuestgroup($questgroup['id']);
|
||||
if(!is_null($previousQuestgroup)) {
|
||||
|
|
@ -97,7 +97,7 @@
|
|||
$group['solved'] = $this->Questgroups->hasCharacterSolvedQuestgroup($group['id'], $character['id']);
|
||||
|
||||
// Check permission of Questgroups
|
||||
if($i >= 1 && count(array_intersect(array('admin','moderator'), IntermediateController::$user['seminaryroles'])) == 0)
|
||||
if($i >= 1 && count(array_intersect(array('admin','moderator'), SeminaryController::$character['characterroles'])) == 0)
|
||||
{
|
||||
if(!$hierarchy['questgroups'][$i-1]['solved'])
|
||||
{
|
||||
|
|
@ -170,7 +170,7 @@
|
|||
$quests[] = $currentQuest;
|
||||
}
|
||||
}
|
||||
while(!is_null($currentQuest) && ($currentQuest['solved'] || count(array_intersect(array('admin','moderator'), IntermediateController::$user['seminaryroles'])) > 0));
|
||||
while(!is_null($currentQuest) && ($currentQuest['solved'] || count(array_intersect(array('admin','moderator'), SeminaryController::$character['characterroles'])) > 0));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class QuestsController extends \hhu\z\controllers\SeminaryRoleController
|
||||
class QuestsController extends \hhu\z\controllers\SeminaryController
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
|
|
@ -146,7 +146,7 @@
|
|||
$character = $this->Characters->getCharacterForUserAndSeminary($this->Auth->getUserId(), $seminary['id']);
|
||||
|
||||
// Check permissions
|
||||
if(count(array_intersect(array('admin','moderator'), IntermediateController::$user['seminaryroles'])) == 0)
|
||||
if(count(array_intersect(array('admin','moderator'), SeminaryController::$character['characterroles'])) == 0)
|
||||
{
|
||||
$previousQuests = $this->Quests->getPreviousQuests($quest['id']);
|
||||
if(count($previousQuests) == 0)
|
||||
|
|
|
|||
|
|
@ -17,14 +17,14 @@
|
|||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class SeminariesController extends \hhu\z\controllers\SeminaryRoleController
|
||||
class SeminariesController extends \hhu\z\controllers\SeminaryController
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('seminaries', 'users', 'userseminaryroles', 'questgroupshierarchy', 'questgroups', 'media');
|
||||
public $models = array('seminaries', 'users', 'characterroles', 'questgroupshierarchy', 'questgroups', 'media');
|
||||
/**
|
||||
* User permissions
|
||||
*
|
||||
|
|
@ -72,10 +72,10 @@
|
|||
// Character of currently logged-in user
|
||||
try {
|
||||
$seminary['usercharacter'] = $this->Characters->getCharacterForUserAndSeminary($this->Auth->getUserId(), $seminary['id']);
|
||||
$seminary['usercharacter']['characterroles'] = $this->Characterroles->getCharacterrolesForCharacterById($seminary['usercharacter']['id']);
|
||||
}
|
||||
catch(\nre\exceptions\IdNotFoundException $e) {
|
||||
}
|
||||
$seminary['userroles'] = $this->Userseminaryroles->getUserseminaryrolesForUserById(IntermediateController::$user['id'], $seminary['id']);
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -115,7 +115,7 @@
|
|||
foreach($hierarchy['questgroups'] as $i => &$questgroup)
|
||||
{
|
||||
// Check permission of Questgroups
|
||||
if($i >= 1 && count(array_intersect(array('admin','moderator'), IntermediateController::$user['seminaryroles'])) == 0)
|
||||
if($i >= 1 && count(array_intersect(array('admin','moderator'), SeminaryController::$character['characterroles'])) == 0)
|
||||
{
|
||||
if(!$this->Questgroups->hasCharacterSolvedQuestgroup($hierarchy['questgroups'][$i-1]['id'], $character['id']))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -35,15 +35,15 @@
|
|||
*/
|
||||
public function index()
|
||||
{
|
||||
if(is_null(SeminaryRoleController::$seminary)) {
|
||||
if(is_null(SeminaryController::$seminary)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get Seminary
|
||||
$seminary = SeminaryRoleController::$seminary;
|
||||
$seminary = SeminaryController::$seminary;
|
||||
|
||||
// Get Character
|
||||
$character = SeminaryRoleController::$character;
|
||||
$character = SeminaryController::$character;
|
||||
if(is_null($character)) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class SeminarymenuController extends \hhu\z\controllers\SeminaryRoleController
|
||||
class SeminarymenuController extends \hhu\z\controllers\SeminaryController
|
||||
{
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -17,21 +17,29 @@
|
|||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class UploadsController extends \hhu\z\controllers\IntermediateController
|
||||
class UploadsController extends \hhu\z\controllers\SeminaryController
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('uploads', 'users', 'userroles', 'seminaries');
|
||||
public $models = array('uploads', 'users', 'userroles', 'characterroles', 'seminaries');
|
||||
/**
|
||||
* User permissions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $permissions = array(
|
||||
'index' => array('admin', 'moderator', 'user', 'userseminaryroles')
|
||||
'index' => array('admin', 'moderator', 'user', 'guest')
|
||||
);
|
||||
/**
|
||||
* User seminary permissions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $seminaryPermissions = array(
|
||||
'seminary' => array('admin', 'moderator', 'user', 'guest')
|
||||
);
|
||||
|
||||
|
||||
|
|
@ -85,9 +93,9 @@
|
|||
// Owner of file
|
||||
if($upload['created_user_id'] != $user['id'])
|
||||
{
|
||||
// Seminary roles
|
||||
$userSeminaryRoles = array_map(function($r) { return $r['name']; }, $this->Userseminaryroles->getUserseminaryrolesForUserById($user['id'], $seminary['id']));
|
||||
if(count(array_intersect(array('admin', 'moderator'), $userSeminaryRoles)) == 0) {
|
||||
// Seminary permissions
|
||||
$characterRoles = array_map(function($r) { return $r['name']; }, $this->Characterroles->getCharacterrolesForCharacterById($character['id']));
|
||||
if(count(array_intersect(array('admin', 'moderator'), $characterRoles)) == 0) {
|
||||
throw new \nre\exceptions\AccessDeniedException();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('users', 'characters', 'avatars', 'media', 'userseminaryroles');
|
||||
public $models = array('users', 'characters', 'avatars', 'media', 'characterroles');
|
||||
/**
|
||||
* Required components
|
||||
*
|
||||
|
|
@ -87,8 +87,8 @@
|
|||
foreach($characters as &$character)
|
||||
{
|
||||
// Seminary roles
|
||||
$character['user_seminaryroles'] = $this->Userseminaryroles->getUserseminaryrolesForUserById(\hhu\z\controllers\IntermediateController::$user['id'], $character['seminary_id']);
|
||||
$character['user_seminaryroles'] = array_map(function($a) { return $a['name']; }, $character['user_seminaryroles']);
|
||||
$character['characterroles'] = $this->Characterroles->getCharacterrolesForCharacterById($character['id']);
|
||||
$character['characterroles'] = array_map(function($a) { return $a['name']; }, $character['characterroles']);
|
||||
|
||||
// Level
|
||||
$character['xplevel'] = $this->Characters->getXPLevelOfCharacters($character['id']);
|
||||
|
|
|
|||
57
models/CharacterrolesModel.inc
Normal file
57
models/CharacterrolesModel.inc
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
<?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 characterroles-table.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class CharacterrolesModel extends \hhu\z\Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new CharacterrolesModel.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get all characterroles for a Character referenced by its ID.
|
||||
*
|
||||
* @param int $userId ID of an user
|
||||
* @return array Characterroles for a Character
|
||||
*/
|
||||
public function getCharacterrolesForCharacterById($characterId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT characterroles.id, characterroles.created, characterroles.name '.
|
||||
'FROM characters_characterroles '.
|
||||
'LEFT JOIN characterroles ON characterroles.id = characters_characterroles.characterrole_id '.
|
||||
'WHERE characters_characterroles.character_id = ?',
|
||||
'i',
|
||||
$characterId
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -468,6 +468,29 @@
|
|||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Characters with the given Character role.
|
||||
*
|
||||
* @param int $seminaryId ID of Seminary
|
||||
* @param string $characterrole Character role
|
||||
* @return array List of users
|
||||
*/
|
||||
public function getCharactersWithCharacterRole($seminaryId, $characterrole)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT characters.id, characters.created, characters.charactertype_id, characters.name, characters.url, characters.user_id, characters.xps, characters.xplevel, characters.avatar_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, seminaries.id AS seminary_url, seminaries.title AS seminary_title, seminaries.url AS seminary_url '.
|
||||
'FROM v_characters AS characters '.
|
||||
'LEFT JOIN charactertypes ON charactertypes.id = characters.charactertype_id '.
|
||||
'LEFT JOIN seminaries ON seminaries.id = charactertypes.seminary_id '.
|
||||
'LEFT JOIN characters_characterroles ON characters_characterroles.character_id = characters.id '.
|
||||
'LEFT JOIN characterroles ON characterroles.id = characters_characterroles.characterrole_id '.
|
||||
'WHERE seminaries.id = ? AND characterroles.name = ?',
|
||||
'is',
|
||||
$seminaryId, $characterrole
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -70,28 +70,6 @@
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get users with the given user Seminary role.
|
||||
*
|
||||
* @param int $seminaryId ID of Seminary
|
||||
* @param string $userseminaryrole User Seminary role
|
||||
* @return array List of users
|
||||
*/
|
||||
public function getUsersWithSeminaryRole($seminaryId, $userseminaryrole)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT users.id, users.created, users.username, users.url, users.surname, users.prename, users.email '.
|
||||
'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_userseminaryroles.seminary_id = ? AND userseminaryroles.name = ? '.
|
||||
'ORDER BY username ASC',
|
||||
'is',
|
||||
$seminaryId, $userseminaryrole
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a user and its data by its ID.
|
||||
*
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue