move Seminary and Character data determination to SeminaryRoleController
This commit is contained in:
parent
f64e19e273
commit
39643f4e36
9 changed files with 38 additions and 59 deletions
|
|
@ -31,18 +31,6 @@
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public static $user = null;
|
public static $user = null;
|
||||||
/**
|
|
||||||
* Current Seminary
|
|
||||||
*
|
|
||||||
* var array
|
|
||||||
*/
|
|
||||||
public static $seminary = null;
|
|
||||||
/**
|
|
||||||
* Character of current user and Seminary
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public static $character = null;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -79,22 +67,7 @@
|
||||||
// Get userdata
|
// Get userdata
|
||||||
try {
|
try {
|
||||||
self::$user = $this->Users->getUserById($this->Auth->getUserId());
|
self::$user = $this->Users->getUserById($this->Auth->getUserId());
|
||||||
|
self::$user['roles'] = array_map(function($r) { return $r['name']; }, $this->Userroles->getUserrolesForUserById(self::$user['id']));
|
||||||
// Determine user roles
|
|
||||||
self::$user['roles'] = array();
|
|
||||||
$roles = $this->Userroles->getUserrolesForUserById(self::$user['id']);
|
|
||||||
foreach($roles as &$role) {
|
|
||||||
self::$user['roles'][] = $role['name'];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Character
|
|
||||||
$controller = $this->agent->controller;
|
|
||||||
if(is_subclass_of($controller, '\hhu\z\controllers\SeminaryRoleController'))
|
|
||||||
{
|
|
||||||
$seminaryUrl = $this->request->getParam(3);
|
|
||||||
self::$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
|
||||||
self::$character = $this->Characters->getCharacterForUserAndSeminary(self::$user['id'], self::$seminary['id']);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch(\nre\exceptions\IdNotFoundException $e) {
|
catch(\nre\exceptions\IdNotFoundException $e) {
|
||||||
}
|
}
|
||||||
|
|
@ -104,8 +77,6 @@
|
||||||
|
|
||||||
// Set userdata
|
// Set userdata
|
||||||
$this->set('loggedUser', self::$user);
|
$this->set('loggedUser', self::$user);
|
||||||
$this->set('loggedSeminary', self::$seminary);
|
|
||||||
$this->set('loggedCharacter', self::$character);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,11 +33,17 @@
|
||||||
*/
|
*/
|
||||||
public $models = array('seminaries', 'userseminaryroles', 'characters', 'achievements');
|
public $models = array('seminaries', 'userseminaryroles', 'characters', 'achievements');
|
||||||
/**
|
/**
|
||||||
* Data of currently logged in user if any
|
* Current Seminary
|
||||||
|
*
|
||||||
|
* var array
|
||||||
|
*/
|
||||||
|
public static $seminary = null;
|
||||||
|
/**
|
||||||
|
* Character of current user and Seminary
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public static $user = null;
|
public static $character = null;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -71,11 +77,24 @@
|
||||||
{
|
{
|
||||||
parent::preFilter($request, $response);
|
parent::preFilter($request, $response);
|
||||||
|
|
||||||
|
// Get Seminary and Character data
|
||||||
|
try {
|
||||||
|
self::$seminary = $this->Seminaries->getSeminaryByUrl($this->request->getParam(3));
|
||||||
|
self::$character = $this->Characters->getCharacterForUserAndSeminary(self::$user['id'], self::$seminary['id']);
|
||||||
|
self::$user['seminaryroles'] = array_map(function($r) { return $r['name']; }, $this->Userseminaryroles->getUserseminaryrolesForUserById(self::$user['id'], self::$seminary['id']));
|
||||||
|
}
|
||||||
|
catch(\nre\exceptions\IdNotFoundException $e) {
|
||||||
|
}
|
||||||
|
|
||||||
// Check permissions
|
// Check permissions
|
||||||
$this->checkPermission($request, $response);
|
$this->checkPermission($request, $response);
|
||||||
|
|
||||||
// Check achievements
|
// Check achievements
|
||||||
$this->checkAchievements($request, $response);
|
$this->checkAchievements($request, $response);
|
||||||
|
|
||||||
|
// Set Seminary and Character data
|
||||||
|
$this->set('loggedSeminary', self::$seminary);
|
||||||
|
$this->set('loggedCharacter', self::$character);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -105,17 +124,6 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine user and seminary
|
|
||||||
$userId = $this->Auth->getUserId();
|
|
||||||
$seminary = $this->Seminaries->getSeminaryByUrl($request->getParam(3));
|
|
||||||
|
|
||||||
// Determine user seminary roles
|
|
||||||
$userSeminaryRoles = array();
|
|
||||||
$roles = $this->Userseminaryroles->getUserseminaryrolesForUserById($userId, $seminary['id']);
|
|
||||||
foreach($roles as &$role) {
|
|
||||||
$userSeminaryRoles[] = $role['name'];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Determine permissions for current action
|
// Determine permissions for current action
|
||||||
$action = $this->request->getParam(2, 'action');
|
$action = $this->request->getParam(2, 'action');
|
||||||
|
|
@ -129,7 +137,7 @@
|
||||||
|
|
||||||
|
|
||||||
// Check permissions
|
// Check permissions
|
||||||
if(count(array_intersect($userSeminaryRoles, $permissions)) == 0) {
|
if(count(array_intersect(self::$user['seminaryroles'], $permissions)) == 0) {
|
||||||
throw new \nre\exceptions\AccessDeniedException();
|
throw new \nre\exceptions\AccessDeniedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -186,7 +194,7 @@
|
||||||
'params' => array(
|
'params' => array(
|
||||||
$condition['field'],
|
$condition['field'],
|
||||||
$condition['value'],
|
$condition['value'],
|
||||||
$character['id']
|
self::$character['id']
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -205,7 +213,7 @@
|
||||||
$condition['status'],
|
$condition['status'],
|
||||||
$condition['groupby'],
|
$condition['groupby'],
|
||||||
$condition['quest_id'],
|
$condition['quest_id'],
|
||||||
$character['id']
|
self::$character['id']
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -223,7 +231,7 @@
|
||||||
$condition['value'],
|
$condition['value'],
|
||||||
$condition['groupby'],
|
$condition['groupby'],
|
||||||
$condition['meta_achievement_id'],
|
$condition['meta_achievement_id'],
|
||||||
$character['id']
|
self::$character['id']
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -263,7 +271,7 @@
|
||||||
|
|
||||||
// Set status
|
// Set status
|
||||||
if($achieved) {
|
if($achieved) {
|
||||||
$this->Achievements->setAchievementAchieved($achievement['id'], $character['id']);
|
$this->Achievements->setAchievementAchieved($achievement['id'], self::$character['id']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@
|
||||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||||
|
|
||||||
// Get Character
|
// Get Character
|
||||||
$character = IntermediateController::$character;
|
$character = SeminaryRoleController::$character;
|
||||||
|
|
||||||
// Get Achievements
|
// Get Achievements
|
||||||
$achievements = $this->Achievements->getAchievementsForSeminary($seminary['id']);
|
$achievements = $this->Achievements->getAchievementsForSeminary($seminary['id']);
|
||||||
|
|
|
||||||
|
|
@ -50,8 +50,8 @@
|
||||||
|
|
||||||
// Set userdata
|
// Set userdata
|
||||||
$this->set('loggedUser', IntermediateController::$user);
|
$this->set('loggedUser', IntermediateController::$user);
|
||||||
$this->set('loggedSeminary', IntermediateController::$seminary);
|
$this->set('loggedSeminary', SeminaryRoleController::$seminary);
|
||||||
$this->set('loggedCharacter', IntermediateController::$character);
|
$this->set('loggedCharacter', SeminaryRoleController::$character);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@
|
||||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||||
|
|
||||||
// Get Character
|
// Get Character
|
||||||
$character = IntermediateController::$character;
|
$character = SeminaryRoleController::$character;
|
||||||
|
|
||||||
// Get Quest topics
|
// Get Quest topics
|
||||||
$questtopics = $this->Questtopics->getQuesttopicsForSeminary($seminary['id']);
|
$questtopics = $this->Questtopics->getQuesttopicsForSeminary($seminary['id']);
|
||||||
|
|
@ -94,7 +94,7 @@
|
||||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||||
|
|
||||||
// Get Character
|
// Get Character
|
||||||
$character = IntermediateController::$character;
|
$character = SeminaryRoleController::$character;
|
||||||
|
|
||||||
// Get Questtopic
|
// Get Questtopic
|
||||||
$questtopic = $this->Questtopics->getQuesttopicByUrl($seminary['id'], $questtopicUrl);
|
$questtopic = $this->Questtopics->getQuesttopicByUrl($seminary['id'], $questtopicUrl);
|
||||||
|
|
|
||||||
|
|
@ -170,7 +170,7 @@
|
||||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||||
|
|
||||||
// Get Character
|
// Get Character
|
||||||
$character = IntermediateController::$character;
|
$character = SeminaryRoleController::$character;
|
||||||
|
|
||||||
// Get Achievement
|
// Get Achievement
|
||||||
$achievement = $this->Achievements->getAchievementByUrl($seminary['id'], $achievementUrl);
|
$achievement = $this->Achievements->getAchievementByUrl($seminary['id'], $achievementUrl);
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@
|
||||||
|
|
||||||
// Set userdata
|
// Set userdata
|
||||||
$this->set('loggedUser', IntermediateController::$user);
|
$this->set('loggedUser', IntermediateController::$user);
|
||||||
$this->set('loggedSeminary', IntermediateController::$seminary);
|
$this->set('loggedSeminary', SeminaryRoleController::$seminary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,15 +35,15 @@
|
||||||
*/
|
*/
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
if(is_null(IntermediateController::$seminary)) {
|
if(is_null(SeminaryRoleController::$seminary)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get Seminary
|
// Get Seminary
|
||||||
$seminary = IntermediateController::$seminary;
|
$seminary = SeminaryRoleController::$seminary;
|
||||||
|
|
||||||
// Get Character
|
// Get Character
|
||||||
$character = IntermediateController::$character;
|
$character = SeminaryRoleController::$character;
|
||||||
if(is_null($character)) {
|
if(is_null($character)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@
|
||||||
|
|
||||||
// Set userdata
|
// Set userdata
|
||||||
$this->set('loggedUser', IntermediateController::$user);
|
$this->set('loggedUser', IntermediateController::$user);
|
||||||
$this->set('loggedSeminary', IntermediateController::$seminary);
|
$this->set('loggedSeminary', SeminaryRoleController::$seminary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue