merge branch ?charactergroupsqueststations?

This commit is contained in:
oliver 2016-01-28 22:33:53 +01:00
commit ba97244b15
13 changed files with 700 additions and 59 deletions

View file

@ -89,12 +89,20 @@
// Get Stations
$stations = null;
if(count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\SeminaryController::$character['characterroles'])) > 0) {
$stations = $this->Charactergroupsqueststations->getStationsForQuest($quest['id']);
}
elseif(!is_null($charactergroup)) {
$stations = $this->Charactergroupsqueststations->getStationsForQuestAndGroup($quest['id'], $charactergroup['id']);
foreach($stations as &$station) {
$stations = $this->Charactergroupsqueststations->getStationsForQuest($quest['id']);
foreach($stations as &$station)
{
// Icon
if(!is_null($station['stationpicture_id'])) {
$station['picture'] = $this->Media->getSeminaryMediaById($station['stationpicture_id']);
}
// Entered state
if(!is_null($charactergroup)) {
$station['entered'] = $this->Charactergroupsqueststations->hasCharactergroupEnteredStation(
$station['id'],
$charactergroup['id']
);
$station['solved'] = $this->Charactergroupsqueststations->hasCharactergroupSolvedStation(
$station['id'],
$charactergroup['id']

View file

@ -39,7 +39,11 @@
*/
public $permissions = array(
'index' => array('admin', 'moderator', 'user'),
'station' => array('admin', 'moderator', 'user')
'station' => array('admin', 'moderator', 'user'),
'create' => array('admin', 'moderator', 'user'),
'edit' => array('admin', 'moderator', 'user'),
'edittask' => array('admin', 'moderator', 'user'),
'delete' => array('admin', 'moderator', 'user')
);
/**
* User seminary permissions
@ -48,7 +52,11 @@
*/
public $seminaryPermissions = array(
'index' => array('admin', 'moderator', 'user'),
'station' => array('admin', 'moderator', 'user')
'station' => array('admin', 'moderator', 'user'),
'create' => array('admin', 'moderator'),
'edit' => array('admin', 'moderator'),
'edittask' => array('admin', 'moderator'),
'delete' => array('admin', 'moderator')
);
@ -124,8 +132,19 @@
// Get Station
$station = $this->Charactergroupsqueststations->getStationByUrl($quest['id'], $stationUrl);
if(!is_null($station['stationpicture_id'])) {
$station['picture'] = $this->Media->getSeminaryMediaById($station['stationpicture_id']);
// Get media
if(!is_null($station['rightimage_id'])) {
$station['rightimage'] = $this->Media->getSeminaryMediaById($station['rightimage_id']);
}
if(!is_null($station['rightav_id'])) {
$station['rightav'] = $this->Media->getSeminaryMediaById($station['rightav_id']);
}
if(!is_null($station['wrongimage_id'])) {
$station['wrongimage'] = $this->Media->getSeminaryMediaById($station['wrongimage_id']);
}
if(!is_null($station['wrongav_id'])) {
$station['wrongav'] = $this->Media->getSeminaryMediaById($station['wrongav_id']);
}
// Get Character group
@ -228,7 +247,9 @@
}
// Get allowed mimetypes
$mimetypes = \nre\configs\AppConfig::$mimetypes['icons'];
$iconMimetypes = \nre\configs\AppConfig::$mimetypes['icons'];
$imageMimetypes = \nre\configs\AppConfig::$mimetypes['stationimages'];
$avMimetypes = \nre\configs\AppConfig::$mimetypes['stationavs'];
// Values
$title = '';
@ -238,6 +259,12 @@
$latitude = null;
$rightText = '';
$wrongText = '';
$textMedia = array(
'rightimage' => null,
'rightav' => null,
'wrongimage' => null,
'wrongav' => null
);
$fields = array('title');
$validation = array();
@ -284,7 +311,7 @@
// Check mimetype
$mediaMimetype = null;
$icon['mimetype'] = \hhu\z\Utils::getMimetype($icon['tmp_name'], $icon['type']);
foreach($mimetypes as &$mimetype) {
foreach($iconMimetypes as &$mimetype) {
if($mimetype['mimetype'] == $icon['mimetype']) {
$mediaMimetype = $mimetype;
break;
@ -298,6 +325,51 @@
}
}
// Validate media
if(!empty($_FILES))
{
foreach(array_keys($textMedia) as $mediumKey)
{
if(array_key_exists($mediumKey, $_FILES) && $_FILES[$mediumKey]['error'] != UPLOAD_ERR_NO_FILE)
{
$mediumValidation = true;
$medium = $_FILES[$mediumKey];
// Check error
if($medium['error'] !== UPLOAD_ERR_OK) {
$mediumValidation = $this->Validation->addValidationResults($mediumValidation, 'error', $medium['error']);
}
else
{
// Check mimetype
$mediaMimetype = null;
$medium['mimetype'] = \hhu\z\Utils::getMimetype($medium['tmp_name'], $medium['type']);
$mediaMimetypes = (strpos($mediumKey, 'image') !== false) ? $imageMimetypes : $avMimetypes;
foreach($mediaMimetypes as &$mimetype) {
if($mimetype['mimetype'] == $medium['mimetype']) {
$mediaMimetype = $mimetype;
break;
}
}
if(is_null($mediaMimetype)) {
$mediumValidation = $this->Validation->addValidationResults($mediumValidation, 'mimetype', $medium['mimetype']);
}
elseif($medium['size'] > $mediaMimetype['size']) {
$mediumValidation = $this->Validation->addValidationResults($mediumValidation, 'size', $mediaMimetype['size']);
}
if($validation == true) {
$textMedia[$mediumKey] = $medium;
}
}
if($mediumValidation !== true) {
$validation = $this->Validation->addValidationResults($validation, $mediumKey, $mediumValidation);
}
}
}
}
// Create new Station
if($validation === true)
{
@ -330,6 +402,50 @@
}
}
// Upload media
$textMediaIds = array();
foreach($textMedia as $mediumKey => $medium)
{
if(!is_null($medium))
{
$mediaId = $this->Media->createStationMedia(
$this->Auth->getUserId(),
$seminary['id'],
sprintf('station-%d-%s', $station['id'], $mediumKey),
$medium['name'],
$medium['type'],
$medium['tmp_name']
);
$textMediaIds[$mediumKey] = $mediaId;
}
}
// Set media
if(array_key_exists('rightimage', $textMediaIds)) {
$this->Charactergroupsqueststations->setRightImageForStation(
$station['id'],
$textMediaIds['rightimage']
);
}
if(array_key_exists('rightav', $textMediaIds)) {
$this->Charactergroupsqueststations->setRightAvForStation(
$station['id'],
$textMediaIds['rightav']
);
}
if(array_key_exists('wrongimage', $textMediaIds)) {
$this->Charactergroupsqueststations->setWrongImageForStation(
$station['id'],
$textMediaIds['wrongimage']
);
}
if(array_key_exists('wrongav', $textMediaIds)) {
$this->Charactergroupsqueststations->setWrongAvForStation(
$station['id'],
$textMediaIds['wrongav']
);
}
// Redirect to Station page
$this->redirect(
$this->linker->link(
@ -364,7 +480,9 @@
$this->set('latitude', $latitude);
$this->set('righttext', $rightText);
$this->set('wrongtext', $wrongText);
$this->set('mimetypes', $mimetypes);
$this->set('iconMimetypes', $iconMimetypes);
$this->set('imageMimetypes', $imageMimetypes);
$this->set('avMimetypes', $avMimetypes);
$this->set('stationtypes', $stationtypes);
$this->set('validation', $validation);
}
@ -395,6 +513,20 @@
// Get Station
$station = $this->Charactergroupsqueststations->getStationByUrl($quest['id'], $stationUrl);
// Get media
if(!is_null($station['rightimage_id'])) {
$station['rightimage'] = $this->Media->getSeminaryMediaById($station['rightimage_id']);
}
if(!is_null($station['rightav_id'])) {
$station['rightav'] = $this->Media->getSeminaryMediaById($station['rightav_id']);
}
if(!is_null($station['wrongimage_id'])) {
$station['wrongimage'] = $this->Media->getSeminaryMediaById($station['wrongimage_id']);
}
if(!is_null($station['wrongav_id'])) {
$station['wrongav'] = $this->Media->getSeminaryMediaById($station['wrongav_id']);
}
// Get Quest types
$stationtypes = $this->Stationtypes->getStationtypes();
foreach($stationtypes as &$stationtype) {
@ -402,7 +534,9 @@
}
// Get allowed mimetypes
$mimetypes = \nre\configs\AppConfig::$mimetypes['icons'];
$iconMimetypes = \nre\configs\AppConfig::$mimetypes['icons'];
$imageMimetypes = \nre\configs\AppConfig::$mimetypes['stationimages'];
$avMimetypes = \nre\configs\AppConfig::$mimetypes['stationavs'];
// Values
$title = $station['title'];
@ -412,6 +546,12 @@
$latitude = $station['latitude'];
$rightText = $station['righttext'];
$wrongText = $station['wrongtext'];
$textMedia = array(
'rightimage' => null,
'rightav' => null,
'wrongimage' => null,
'wrongav' => null
);
$fields = array('title');
$validation = array();
@ -458,7 +598,7 @@
// Check mimetype
$mediaMimetype = null;
$icon['mimetype'] = \hhu\z\Utils::getMimetype($icon['tmp_name'], $icon['type']);
foreach($mimetypes as &$mimetype) {
foreach($iconMimetypes as &$mimetype) {
if($mimetype['mimetype'] == $icon['mimetype']) {
$mediaMimetype = $mimetype;
break;
@ -472,6 +612,51 @@
}
}
// Validate media
if(!empty($_FILES))
{
foreach(array_keys($textMedia) as $mediumKey)
{
if(array_key_exists($mediumKey, $_FILES) && $_FILES[$mediumKey]['error'] != UPLOAD_ERR_NO_FILE)
{
$mediumValidation = true;
$medium = $_FILES[$mediumKey];
// Check error
if($medium['error'] !== UPLOAD_ERR_OK) {
$mediumValidation = $this->Validation->addValidationResults($mediumValidation, 'error', $medium['error']);
}
else
{
// Check mimetype
$mediaMimetype = null;
$medium['mimetype'] = \hhu\z\Utils::getMimetype($medium['tmp_name'], $medium['type']);
$mediaMimetypes = (strpos($mediumKey, 'image') !== false) ? $imageMimetypes : $avMimetypes;
foreach($mediaMimetypes as &$mimetype) {
if($mimetype['mimetype'] == $medium['mimetype']) {
$mediaMimetype = $mimetype;
break;
}
}
if(is_null($mediaMimetype)) {
$mediumValidation = $this->Validation->addValidationResults($mediumValidation, 'mimetype', $medium['mimetype']);
}
elseif($medium['size'] > $mediaMimetype['size']) {
$mediumValidation = $this->Validation->addValidationResults($mediumValidation, 'size', $mediaMimetype['size']);
}
if($validation == true) {
$textMedia[$mediumKey] = $medium;
}
}
if($mediumValidation !== true) {
$validation = $this->Validation->addValidationResults($validation, $mediumKey, $mediumValidation);
}
}
}
}
// Edit Station
if($validation === true)
{
@ -504,6 +689,50 @@
}
}
// Upload media
$textMediaIds = array();
foreach($textMedia as $mediumKey => $medium)
{
if(!is_null($medium))
{
$mediaId = $this->Media->createStationMedia(
$this->Auth->getUserId(),
$seminary['id'],
sprintf('station-%d-%s', $station['id'], $mediumKey),
$medium['name'],
$medium['type'],
$medium['tmp_name']
);
$textMediaIds[$mediumKey] = $mediaId;
}
}
// Set media
if(array_key_exists('rightimage', $textMediaIds)) {
$this->Charactergroupsqueststations->setRightImageForStation(
$station['id'],
$textMediaIds['rightimage']
);
}
if(array_key_exists('rightav', $textMediaIds)) {
$this->Charactergroupsqueststations->setRightAvForStation(
$station['id'],
$textMediaIds['rightav']
);
}
if(array_key_exists('wrongimage', $textMediaIds)) {
$this->Charactergroupsqueststations->setWrongImageForStation(
$station['id'],
$textMediaIds['wrongimage']
);
}
if(array_key_exists('wrongav', $textMediaIds)) {
$this->Charactergroupsqueststations->setWrongAvForStation(
$station['id'],
$textMediaIds['wrongav']
);
}
// Redirect
if(!is_null($this->request->getPostParam('edit-task'))) {
// To task editing
@ -550,6 +779,7 @@
$this->set('seminary', $seminary);
$this->set('groupsgroup', $groupsgroup);
$this->set('quest', $quest);
$this->set('station', $station);
$this->set('title', $title);
$this->set('prolog', $prolog);
$this->set('task', $task);
@ -557,14 +787,16 @@
$this->set('latitude', $latitude);
$this->set('righttext', $rightText);
$this->set('wrongtext', $wrongText);
$this->set('mimetypes', $mimetypes);
$this->set('iconMimetypes', $iconMimetypes);
$this->set('imageMimetypes', $imageMimetypes);
$this->set('avMimetypes', $avMimetypes);
$this->set('stationtypes', $stationtypes);
$this->set('validation', $validation);
}
/**
* TODO Action: edittask.
* Action: edittask.
*
* Edit the task of a Character groups Quest Station.
*

View file

@ -25,14 +25,15 @@
* @var array
*/
public $permissions = array(
'index' => array('admin', 'moderator', 'user', 'guest'),
'seminarymoodpic' => array('admin', 'moderator', 'user'),
'seminarymap' => array('admin', 'moderator', 'user'),
'seminary' => array('admin', 'moderator', 'user'),
'avatar' => array('admin', 'moderator', 'user'),
'achievement' => array('admin', 'moderator', 'user'),
'charactergroup' => array('admin', 'moderator', 'user'),
'charactergroupsquest' => array('admin', 'moderator', 'user')
'index' => array('admin', 'moderator', 'user', 'guest'),
'seminarymoodpic' => array('admin', 'moderator', 'user'),
'seminarymap' => array('admin', 'moderator', 'user'),
'seminary' => array('admin', 'moderator', 'user'),
'avatar' => array('admin', 'moderator', 'user'),
'achievement' => array('admin', 'moderator', 'user'),
'charactergroup' => array('admin', 'moderator', 'user'),
'charactergroupsquest' => array('admin', 'moderator', 'user'),
'charactergroupsqueststation' => array('admin', 'moderator', 'user')
);
/**
* User seminary permissions
@ -40,17 +41,18 @@
* @var array
*/
public $seminaryPermissions = array(
'seminary' => array('admin', 'moderator', 'user', 'guest'),
'achievement' => array('admin', 'moderator', 'user', 'guest'),
'charactergroup' => array('admin', 'moderator', 'user', 'guest'),
'charactergroupsquest' => array('admin', 'moderator', 'user', 'guest')
'seminary' => array('admin', 'moderator', 'user', 'guest'),
'achievement' => array('admin', 'moderator', 'user', 'guest'),
'charactergroup' => array('admin', 'moderator', 'user', 'guest'),
'charactergroupsquest' => array('admin', 'moderator', 'user', 'guest'),
'charactergroupsqueststation' => array('admin', 'moderator', 'user', 'guest')
);
/**
* Required models
*
* @var array
*/
public $models = array('seminaries', 'achievements', 'media', 'avatars', 'charactergroups', 'charactergroupsquests', 'map');
public $models = array('seminaries', 'achievements', 'media', 'avatars', 'charactergroups', 'charactergroupsquests', 'charactergroupsqueststations', 'map');
@ -403,6 +405,47 @@
}
/**
* Action: charactergroupsqueststation
*
* Display the icon for a Character groups Quest Station.
*
* @throws \nre\exceptions\IdNotFoundException
* @param string $seminaryUrl URL-Title of a Seminary
* @param string $groupsgroupUrl URL-Title of a Character groups-group
* @param string $questUrl URL-Title of a Character groups Quest
* @param string $stationUrl URL-title of Station
*/
public function charactergroupsqueststation($seminaryUrl, $groupsgroupUrl, $questUrl, $stationUrl)
{
// Get seminary
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
// Get Character groups-group
$groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl);
// Get Character groups Quests
$quest = $this->Charactergroupsquests->getQuestByUrl($groupsgroup['id'], $questUrl);
// Get Station
$station = $this->Charactergroupsqueststations->getStationByUrl($quest['id'], $stationUrl);
// Get media
$media = $this->Media->getSeminaryMediaById($station['stationpicture_id']);
// Get file
$file = $this->getMediaFile($media, 'charactergroupsqueststation');
if(is_null($file)) {
return;
}
// Pass data to view
$this->set('media', $media);
$this->set('file', $file);
}
/**
@ -495,6 +538,14 @@
\nre\configs\AppConfig::$media[$action]['height']
);
break;
case 'charactergroupsqueststation':
$file = self::resizeImage(
$media['filename'],
$format,
\nre\configs\AppConfig::$media[$action]['width'],
\nre\configs\AppConfig::$media[$action]['height']
);
break;
default:
throw new ParamsNotValidException($action);
break;