implement icons for Character groups Quests and improve media handilng for Character groups
This commit is contained in:
parent
75b81302ca
commit
072333c88b
12 changed files with 334 additions and 96 deletions
|
|
@ -89,6 +89,10 @@
|
||||||
'charactergroup' => array(
|
'charactergroup' => array(
|
||||||
'width' => 80,
|
'width' => 80,
|
||||||
'height' => 80
|
'height' => 80
|
||||||
|
),
|
||||||
|
'charactergroupsquest' => array(
|
||||||
|
'width' => 80,
|
||||||
|
'height' => 80
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -100,14 +104,14 @@
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public static $mimetypes = array(
|
public static $mimetypes = array(
|
||||||
'images' => array(
|
'icons' => array(
|
||||||
array(
|
array(
|
||||||
'mimetype' => 'image/jpeg',
|
'mimetype' => 'image/jpeg',
|
||||||
'size' => 1048576
|
'size' => 102400
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'mimetype' => 'image/png',
|
'mimetype' => 'image/png',
|
||||||
'size' => 1048576
|
'size' => 204800
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
'charactergroupsquests' => array(
|
'charactergroupsquests' => array(
|
||||||
|
|
|
||||||
|
|
@ -470,7 +470,7 @@
|
||||||
$groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl);
|
$groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl);
|
||||||
|
|
||||||
// Get allowed mimetypes
|
// Get allowed mimetypes
|
||||||
$mimetypes = \nre\configs\AppConfig::$mimetypes['images'];
|
$mimetypes = \nre\configs\AppConfig::$mimetypes['icons'];
|
||||||
|
|
||||||
// Values
|
// Values
|
||||||
$charactergroupname = '';
|
$charactergroupname = '';
|
||||||
|
|
@ -489,7 +489,7 @@
|
||||||
}
|
}
|
||||||
$motto = $this->request->getPostParam('motto');
|
$motto = $this->request->getPostParam('motto');
|
||||||
|
|
||||||
// Upload icon
|
// Validate icon
|
||||||
$icon = null;
|
$icon = null;
|
||||||
if(!empty($_FILES) && array_key_exists('icon', $_FILES) && $_FILES['icon']['error'] != UPLOAD_ERR_NO_FILE)
|
if(!empty($_FILES) && array_key_exists('icon', $_FILES) && $_FILES['icon']['error'] != UPLOAD_ERR_NO_FILE)
|
||||||
{
|
{
|
||||||
|
|
@ -601,7 +601,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get allowed mimetypes
|
// Get allowed mimetypes
|
||||||
$mimetypes = \nre\configs\AppConfig::$mimetypes['images'];
|
$mimetypes = \nre\configs\AppConfig::$mimetypes['icons'];
|
||||||
|
|
||||||
// Values
|
// Values
|
||||||
$charactergroupname = $group['name'];
|
$charactergroupname = $group['name'];
|
||||||
|
|
@ -620,7 +620,7 @@
|
||||||
}
|
}
|
||||||
$motto = $this->request->getPostParam('motto');
|
$motto = $this->request->getPostParam('motto');
|
||||||
|
|
||||||
// Upload icon
|
// Validate icon
|
||||||
$icon = null;
|
$icon = null;
|
||||||
if(!empty($_FILES) && array_key_exists('icon', $_FILES) && $_FILES['icon']['error'] != UPLOAD_ERR_NO_FILE)
|
if(!empty($_FILES) && array_key_exists('icon', $_FILES) && $_FILES['icon']['error'] != UPLOAD_ERR_NO_FILE)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -81,12 +81,6 @@
|
||||||
// Get Character groups-groups
|
// Get Character groups-groups
|
||||||
$groups = $this->Charactergroups->getGroupsForQuest($quest['id']);
|
$groups = $this->Charactergroups->getGroupsForQuest($quest['id']);
|
||||||
|
|
||||||
// Media
|
|
||||||
$questmedia = null;
|
|
||||||
if(!is_null($quest['questsmedia_id'])) {
|
|
||||||
$questmedia = $this->Media->getSeminaryMediaById($quest['questsmedia_id']);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get uploads
|
// Get uploads
|
||||||
$uploads = $this->Charactergroupsquests->getMediaForQuest($quest['id']);
|
$uploads = $this->Charactergroupsquests->getMediaForQuest($quest['id']);
|
||||||
foreach($uploads as &$upload) {
|
foreach($uploads as &$upload) {
|
||||||
|
|
@ -105,7 +99,6 @@
|
||||||
$this->set('quest', $quest);
|
$this->set('quest', $quest);
|
||||||
$this->set('questgroup', $questgroup);
|
$this->set('questgroup', $questgroup);
|
||||||
$this->set('groups', $groups);
|
$this->set('groups', $groups);
|
||||||
$this->set('media', $questmedia);
|
|
||||||
$this->set('uploads', $uploads);
|
$this->set('uploads', $uploads);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -269,6 +262,9 @@
|
||||||
// Get Questgroups
|
// Get Questgroups
|
||||||
$questgroups = $this->Questgroups->getQuestgroupsForSeminary($seminary['id']);
|
$questgroups = $this->Questgroups->getQuestgroupsForSeminary($seminary['id']);
|
||||||
|
|
||||||
|
// Get allowed mimetypes
|
||||||
|
$mimetypes = \nre\configs\AppConfig::$mimetypes['icons'];
|
||||||
|
|
||||||
// Values
|
// Values
|
||||||
$title = '';
|
$title = '';
|
||||||
$xps = 0;
|
$xps = 0;
|
||||||
|
|
@ -294,6 +290,34 @@
|
||||||
$wonText = $this->request->getPostParam('wonText');
|
$wonText = $this->request->getPostParam('wonText');
|
||||||
$lostText = $this->request->getPostParam('lostText');
|
$lostText = $this->request->getPostParam('lostText');
|
||||||
|
|
||||||
|
// Validate icon
|
||||||
|
$icon = null;
|
||||||
|
if(!empty($_FILES) && array_key_exists('icon', $_FILES) && $_FILES['icon']['error'] != UPLOAD_ERR_NO_FILE)
|
||||||
|
{
|
||||||
|
$icon = $_FILES['icon'];
|
||||||
|
|
||||||
|
// Check error
|
||||||
|
if($icon['error'] !== UPLOAD_ERR_OK) {
|
||||||
|
$validation = $this->Validation->addValidationResult($validation, 'icon', 'error', $icon['error']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check mimetype
|
||||||
|
$mediaMimetype = null;
|
||||||
|
$icon['mimetype'] = \hhu\z\Utils::getMimetype($icon['tmp_name'], $icon['type']);
|
||||||
|
foreach($mimetypes as &$mimetype) {
|
||||||
|
if($mimetype['mimetype'] == $icon['mimetype']) {
|
||||||
|
$mediaMimetype = $mimetype;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(is_null($mediaMimetype)) {
|
||||||
|
$validation = $this->Validation->addValidationResult($validation, 'icon', 'mimetype', $icon['mimetype']);
|
||||||
|
}
|
||||||
|
elseif($icon['size'] > $mediaMimetype['size']) {
|
||||||
|
$validation = $this->Validation->addValidationResult($validation, 'icon', 'size', $mediaMimetype['size']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Validate Questgroup
|
// Validate Questgroup
|
||||||
$questgroupIndex = null;
|
$questgroupIndex = null;
|
||||||
foreach($questgroups as $index => &$questgroup)
|
foreach($questgroups as $index => &$questgroup)
|
||||||
|
|
@ -321,9 +345,25 @@
|
||||||
$wonText,
|
$wonText,
|
||||||
$lostText
|
$lostText
|
||||||
);
|
);
|
||||||
|
$quest = $this->Charactergroupsquests->getQuestById($questId);
|
||||||
|
|
||||||
|
// Upload icon
|
||||||
|
if(!is_null($icon))
|
||||||
|
{
|
||||||
|
$mediaId = $this->Media->createQuestMedia(
|
||||||
|
$this->Auth->getUserId(),
|
||||||
|
$seminary['id'],
|
||||||
|
sprintf('charactergroupsquest-%s', $quest['url']),
|
||||||
|
'',
|
||||||
|
$icon['mimetype'],
|
||||||
|
$icon['tmp_name']
|
||||||
|
);
|
||||||
|
if($mediaId !== false) {
|
||||||
|
$this->Charactergroupsquests->setMediaForQuest($quest['id'], $mediaId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Redirect to Quest page
|
// Redirect to Quest page
|
||||||
$quest = $this->Charactergroupsquests->getQuestById($questId);
|
|
||||||
$this->redirect($this->linker->link(array('quest', $seminary['url'], $groupsgroup['url'], $quest['url']), 1));
|
$this->redirect($this->linker->link(array('quest', $seminary['url'], $groupsgroup['url'], $quest['url']), 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -350,6 +390,7 @@
|
||||||
$this->set('rules', $rules);
|
$this->set('rules', $rules);
|
||||||
$this->set('wonText', $wonText);
|
$this->set('wonText', $wonText);
|
||||||
$this->set('lostText', $lostText);
|
$this->set('lostText', $lostText);
|
||||||
|
$this->set('mimetypes', $mimetypes);
|
||||||
$this->set('validation', $validation);
|
$this->set('validation', $validation);
|
||||||
$this->set('validationSettings', $validationSettings);
|
$this->set('validationSettings', $validationSettings);
|
||||||
}
|
}
|
||||||
|
|
@ -383,6 +424,9 @@
|
||||||
$questgroup['selected'] = ($questgroup['id'] == $quest['questgroups_id']);
|
$questgroup['selected'] = ($questgroup['id'] == $quest['questgroups_id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get allowed mimetypes
|
||||||
|
$mimetypes = \nre\configs\AppConfig::$mimetypes['icons'];
|
||||||
|
|
||||||
// Values
|
// Values
|
||||||
$title = $quest['title'];
|
$title = $quest['title'];
|
||||||
$xps = $quest['xps'];
|
$xps = $quest['xps'];
|
||||||
|
|
@ -408,6 +452,34 @@
|
||||||
$wonText = $this->request->getPostParam('wonText');
|
$wonText = $this->request->getPostParam('wonText');
|
||||||
$lostText = $this->request->getPostParam('lostText');
|
$lostText = $this->request->getPostParam('lostText');
|
||||||
|
|
||||||
|
// Validate icon
|
||||||
|
$icon = null;
|
||||||
|
if(!empty($_FILES) && array_key_exists('icon', $_FILES) && $_FILES['icon']['error'] != UPLOAD_ERR_NO_FILE)
|
||||||
|
{
|
||||||
|
$icon = $_FILES['icon'];
|
||||||
|
|
||||||
|
// Check error
|
||||||
|
if($icon['error'] !== UPLOAD_ERR_OK) {
|
||||||
|
$validation = $this->Validation->addValidationResult($validation, 'icon', 'error', $icon['error']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check mimetype
|
||||||
|
$mediaMimetype = null;
|
||||||
|
$icon['mimetype'] = \hhu\z\Utils::getMimetype($icon['tmp_name'], $icon['type']);
|
||||||
|
foreach($mimetypes as &$mimetype) {
|
||||||
|
if($mimetype['mimetype'] == $icon['mimetype']) {
|
||||||
|
$mediaMimetype = $mimetype;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(is_null($mediaMimetype)) {
|
||||||
|
$validation = $this->Validation->addValidationResult($validation, 'icon', 'mimetype', $icon['mimetype']);
|
||||||
|
}
|
||||||
|
elseif($icon['size'] > $mediaMimetype['size']) {
|
||||||
|
$validation = $this->Validation->addValidationResult($validation, 'icon', 'size', $mediaMimetype['size']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Validate Questgroup
|
// Validate Questgroup
|
||||||
$questgroupIndex = null;
|
$questgroupIndex = null;
|
||||||
foreach($questgroups as $index => &$questgroup)
|
foreach($questgroups as $index => &$questgroup)
|
||||||
|
|
@ -435,9 +507,25 @@
|
||||||
$wonText,
|
$wonText,
|
||||||
$lostText
|
$lostText
|
||||||
);
|
);
|
||||||
|
$quest = $this->Charactergroupsquests->getQuestById($quest['id']);
|
||||||
|
|
||||||
|
// Upload icon
|
||||||
|
if(!is_null($icon))
|
||||||
|
{
|
||||||
|
$mediaId = $this->Media->createQuestMedia(
|
||||||
|
$this->Auth->getUserId(),
|
||||||
|
$seminary['id'],
|
||||||
|
sprintf('charactergroupsquest-%s', $quest['url']),
|
||||||
|
'',
|
||||||
|
$icon['mimetype'],
|
||||||
|
$icon['tmp_name']
|
||||||
|
);
|
||||||
|
if($mediaId !== false) {
|
||||||
|
$this->Charactergroupsquests->setMediaForQuest($quest['id'], $mediaId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Redirect to Quest page
|
// Redirect to Quest page
|
||||||
$quest = $this->Charactergroupsquests->getQuestById($quest['id']);
|
|
||||||
$this->redirect($this->linker->link(array('quest', $seminary['url'], $groupsgroup['url'], $quest['url']), 1));
|
$this->redirect($this->linker->link(array('quest', $seminary['url'], $groupsgroup['url'], $quest['url']), 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -465,6 +553,7 @@
|
||||||
$this->set('rules', $rules);
|
$this->set('rules', $rules);
|
||||||
$this->set('wonText', $wonText);
|
$this->set('wonText', $wonText);
|
||||||
$this->set('lostText', $lostText);
|
$this->set('lostText', $lostText);
|
||||||
|
$this->set('mimetypes', $mimetypes);
|
||||||
$this->set('validation', $validation);
|
$this->set('validation', $validation);
|
||||||
$this->set('validationSettings', $validationSettings);
|
$this->set('validationSettings', $validationSettings);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,9 @@
|
||||||
'seminarymoodpic' => array('admin', 'moderator', 'user'),
|
'seminarymoodpic' => array('admin', 'moderator', 'user'),
|
||||||
'seminary' => array('admin', 'moderator', 'user'),
|
'seminary' => array('admin', 'moderator', 'user'),
|
||||||
'avatar' => array('admin', 'moderator', 'user'),
|
'avatar' => array('admin', 'moderator', 'user'),
|
||||||
'achievement' => array('admin', 'moderator', 'user')
|
'achievement' => array('admin', 'moderator', 'user'),
|
||||||
|
'charactergroup' => array('admin', 'moderator', 'user'),
|
||||||
|
'charactergroupsquest' => array('admin', 'moderator', 'user')
|
||||||
);
|
);
|
||||||
/**
|
/**
|
||||||
* User seminary permissions
|
* User seminary permissions
|
||||||
|
|
@ -37,15 +39,17 @@
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $seminaryPermissions = array(
|
public $seminaryPermissions = array(
|
||||||
'seminary' => array('admin', 'moderator', 'user', 'guest'),
|
'seminary' => array('admin', 'moderator', 'user', 'guest'),
|
||||||
'achievement' => array('admin', 'moderator', 'user', 'guest')
|
'achievement' => array('admin', 'moderator', 'user', 'guest'),
|
||||||
|
'charactergroup' => array('admin', 'moderator', 'user', 'guest'),
|
||||||
|
'charactergroupsquest' => array('admin', 'moderator', 'user', 'guest')
|
||||||
);
|
);
|
||||||
/**
|
/**
|
||||||
* Required models
|
* Required models
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $models = array('seminaries', 'achievements', 'media', 'avatars', 'charactergroups');
|
public $models = array('seminaries', 'achievements', 'media', 'avatars', 'charactergroups', 'charactergroupsquests');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -318,6 +322,48 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Action: charactergroupsquest
|
||||||
|
*
|
||||||
|
* Display the icon for a Character groups Quest of a Seminary.
|
||||||
|
*
|
||||||
|
* @throws 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
|
||||||
|
*/
|
||||||
|
public function charactergroupsquest($seminaryUrl, $groupsgroupUrl, $questUrl)
|
||||||
|
{
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
// Check media
|
||||||
|
if(is_null($quest['questsmedia_id'])) {
|
||||||
|
$this->redirect($this->linker->link(array('grafics','charactergroup.jpg')));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get media
|
||||||
|
$media = $this->Media->getSeminaryMediaById($quest['questsmedia_id']);
|
||||||
|
|
||||||
|
// Get file
|
||||||
|
$file = $this->getMediaFile($media, 'charactergroupsquest');
|
||||||
|
if(is_null($file)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Pass data to view
|
||||||
|
$this->set('media', $media);
|
||||||
|
$this->set('file', $file);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -425,6 +471,14 @@
|
||||||
\nre\configs\AppConfig::$media['charactergroup']['height']
|
\nre\configs\AppConfig::$media['charactergroup']['height']
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
case 'charactergroupsquest':
|
||||||
|
$file = self::resizeImage(
|
||||||
|
$media['filename'],
|
||||||
|
$format,
|
||||||
|
\nre\configs\AppConfig::$media['charactergroupsquest']['width'],
|
||||||
|
\nre\configs\AppConfig::$media['charactergroupsquest']['height']
|
||||||
|
);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new ParamsNotValidException($action);
|
throw new ParamsNotValidException($action);
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -230,6 +230,25 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the media for a Character groups Quest.
|
||||||
|
*
|
||||||
|
* @param int $questId ID of Quest to upload media for
|
||||||
|
* @param int $mediaId ID of Quests media
|
||||||
|
*/
|
||||||
|
public function setMediaForQuest($questId, $mediaId)
|
||||||
|
{
|
||||||
|
$this->db->query(
|
||||||
|
'UPDATE charactergroupsquests '.
|
||||||
|
'SET questsmedia_id = ? '.
|
||||||
|
'WHERE id = ?',
|
||||||
|
'ii',
|
||||||
|
$mediaId,
|
||||||
|
$questId
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Upload a media for a Character groups Quest.
|
* Upload a media for a Character groups Quest.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -136,114 +136,30 @@
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new Questsmedia by creating a new Seminarymedia and
|
* Create a new Quests media by creating a new Seminarymedia and
|
||||||
* adding it to the list of Questsmedia.
|
* adding it to the list of Quests media.
|
||||||
* TODO Currently only temporary for easier data import.
|
*
|
||||||
|
* @param int $userId ID of user that does the upload
|
||||||
|
* @param int $seminaryId ID of Seminary
|
||||||
|
* @param string $filename Filename of uploading media
|
||||||
|
* @param string $description Description for media
|
||||||
|
* @param string $mimetype Mimetype of media
|
||||||
|
* @param string $tmpFilename Name of temporary uploaded file
|
||||||
|
* @return mixed ID of media record or false if upload failed
|
||||||
*/
|
*/
|
||||||
public function createQuestMedia($userId, $seminaryId, $filename, $description, $mimetype, $tmpFilename)
|
public function createQuestMedia($userId, $seminaryId, $filename, $description, $mimetype, $tmpFilename)
|
||||||
{
|
|
||||||
$uploadId = false;
|
|
||||||
$this->db->setAutocommit(false);
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Create database record
|
|
||||||
$this->db->query(
|
|
||||||
'INSERT INTO seminarymedia '.
|
|
||||||
'(created_user_id, seminary_id, name, url, description, mimetype) '.
|
|
||||||
'VALUES '.
|
|
||||||
'(?, ? ,? ,?, ?, ?)',
|
|
||||||
'iissss',
|
|
||||||
$userId,
|
|
||||||
$seminaryId,
|
|
||||||
$filename,
|
|
||||||
\nre\core\Linker::createLinkParam($filename),
|
|
||||||
$description,
|
|
||||||
$mimetype
|
|
||||||
);
|
|
||||||
$uploadId = $this->db->getInsertId();
|
|
||||||
|
|
||||||
$this->db->query(
|
|
||||||
'INSERT INTO questsmedia '.
|
|
||||||
'(media_id, created_user_id) '.
|
|
||||||
'VALUES '.
|
|
||||||
'(?, ?)',
|
|
||||||
'ii',
|
|
||||||
$uploadId,
|
|
||||||
$userId
|
|
||||||
);
|
|
||||||
|
|
||||||
// Create filename
|
|
||||||
$filename = ROOT.DS.'seminarymedia'.DS.$uploadId;
|
|
||||||
if(!move_uploaded_file($tmpFilename, $filename))
|
|
||||||
{
|
|
||||||
$this->db->rollback();
|
|
||||||
$uploadId = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(\nre\exceptions\DatamodelException $e) {
|
|
||||||
$this->db->rollback();
|
|
||||||
$this->db->setAutocommit(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$this->db->setAutocommit(true);
|
|
||||||
return $uploadId;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new Character groups media by creating a new Seminarymedia and
|
|
||||||
* adding it to the list of media for Character groups.
|
|
||||||
*
|
|
||||||
* @param int $userId
|
|
||||||
* @param int $seminaryId
|
|
||||||
* @param string $filename
|
|
||||||
* @param string $description
|
|
||||||
* @param string $mimetype
|
|
||||||
* @param string $tmpFilename
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public function createCharactergroupMedia($userId, $seminaryId, $filename, $description, $mimetype, $tmpFilename)
|
|
||||||
{
|
{
|
||||||
$mediaId = false;
|
$mediaId = false;
|
||||||
$this->db->setAutocommit(false);
|
$this->db->setAutocommit(false);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Check for existing database record
|
// Create Seminary media record
|
||||||
$data = $this->db->query(
|
$mediaId = $this->createSeminaryMedia($userId, $seminaryId, $filename, $description, $mimetype);
|
||||||
'SELECT id '.
|
|
||||||
'FROM seminarymedia '.
|
|
||||||
'WHERE url = ?',
|
|
||||||
's',
|
|
||||||
\nre\core\Linker::createLinkParam($filename)
|
|
||||||
);
|
|
||||||
if(!empty($data)) {
|
|
||||||
$mediaId = $data[0]['id'];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create database record
|
// Add media to Quests media
|
||||||
if($mediaId === false)
|
|
||||||
{
|
|
||||||
$this->db->query(
|
|
||||||
'INSERT INTO seminarymedia '.
|
|
||||||
'(created_user_id, seminary_id, name, url, description, mimetype) '.
|
|
||||||
'VALUES '.
|
|
||||||
'(?, ? ,? ,?, ?, ?)',
|
|
||||||
'iissss',
|
|
||||||
$userId,
|
|
||||||
$seminaryId,
|
|
||||||
$filename,
|
|
||||||
\nre\core\Linker::createLinkParam($filename),
|
|
||||||
$description,
|
|
||||||
$mimetype
|
|
||||||
);
|
|
||||||
$mediaId = $this->db->getInsertId();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add media to Character groups media
|
|
||||||
$this->db->query(
|
$this->db->query(
|
||||||
'INSERT INTO charactergroupsmedia '.
|
'INSERT INTO questsmedia '.
|
||||||
'(seminarymedia_id, created_user_id) '.
|
'(media_id, created_user_id) '.
|
||||||
'VALUES '.
|
'VALUES '.
|
||||||
'(?, ?) '.
|
'(?, ?) '.
|
||||||
'ON DUPLICATE KEY UPDATE '.
|
'ON DUPLICATE KEY UPDATE '.
|
||||||
|
|
@ -255,7 +171,7 @@
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create filename
|
// Create filename
|
||||||
$filename = ROOT.DS.'seminarymedia'.DS.$mediaId;
|
$filename = ROOT.DS.\nre\configs\AppConfig::$dirs['seminarymedia'].DS.$mediaId;
|
||||||
if(!move_uploaded_file($tmpFilename, $filename))
|
if(!move_uploaded_file($tmpFilename, $filename))
|
||||||
{
|
{
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
|
|
@ -272,6 +188,106 @@
|
||||||
return $mediaId;
|
return $mediaId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new Character groups media by creating a new Seminarymedia and
|
||||||
|
* adding it to the list of media for Character groups.
|
||||||
|
*
|
||||||
|
* @param int $userId ID of user that does the upload
|
||||||
|
* @param int $seminaryId ID of Seminary
|
||||||
|
* @param string $filename Filename of uploading media
|
||||||
|
* @param string $description Description for media
|
||||||
|
* @param string $mimetype Mimetype of media
|
||||||
|
* @param string $tmpFilename Name of temporary uploaded file
|
||||||
|
* @return mixed ID of media record or false if upload failed
|
||||||
|
*/
|
||||||
|
public function createCharactergroupMedia($userId, $seminaryId, $filename, $description, $mimetype, $tmpFilename)
|
||||||
|
{
|
||||||
|
$mediaId = false;
|
||||||
|
$this->db->setAutocommit(false);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Create Seminary media record
|
||||||
|
$mediaId = $this->createSeminaryMedia($userId, $seminaryId, $filename, $description, $mimetype);
|
||||||
|
|
||||||
|
// Add media to Character groups media
|
||||||
|
$this->db->query(
|
||||||
|
'INSERT INTO charactergroupsmedia '.
|
||||||
|
'(seminarymedia_id, created_user_id) '.
|
||||||
|
'VALUES '.
|
||||||
|
'(?, ?) '.
|
||||||
|
'ON DUPLICATE KEY UPDATE '.
|
||||||
|
'created_user_id = ?',
|
||||||
|
'iii',
|
||||||
|
$mediaId,
|
||||||
|
$userId,
|
||||||
|
$userId
|
||||||
|
);
|
||||||
|
|
||||||
|
// Create filename
|
||||||
|
$filename = ROOT.DS.\nre\configs\AppConfig::$dirs['seminarymedia'].DS.$mediaId;
|
||||||
|
if(!move_uploaded_file($tmpFilename, $filename))
|
||||||
|
{
|
||||||
|
$this->db->rollback();
|
||||||
|
$mediaId = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(\nre\exceptions\DatamodelException $e) {
|
||||||
|
$this->db->rollback();
|
||||||
|
$this->db->setAutocommit(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$this->db->setAutocommit(true);
|
||||||
|
return $mediaId;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new Seminary media.
|
||||||
|
*
|
||||||
|
* @param int $userId ID of user that does the upload
|
||||||
|
* @param int $seminaryId ID of Seminary
|
||||||
|
* @param string $filename Filename of uploading media
|
||||||
|
* @param string $description Description for media
|
||||||
|
* @param string $mimetype Mimetype of media
|
||||||
|
* @return mixed ID of media record or false if upload failed
|
||||||
|
*/
|
||||||
|
private function createSeminaryMedia($userId, $seminaryId, $filename, $description, $mimetype)
|
||||||
|
{
|
||||||
|
// Check for existing database record
|
||||||
|
$data = $this->db->query(
|
||||||
|
'SELECT id '.
|
||||||
|
'FROM seminarymedia '.
|
||||||
|
'WHERE url = ?',
|
||||||
|
's',
|
||||||
|
\nre\core\Linker::createLinkParam($filename)
|
||||||
|
);
|
||||||
|
if(!empty($data)) {
|
||||||
|
return $data[0]['id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create database record
|
||||||
|
$this->db->query(
|
||||||
|
'INSERT INTO seminarymedia '.
|
||||||
|
'(created_user_id, seminary_id, name, url, description, mimetype) '.
|
||||||
|
'VALUES '.
|
||||||
|
'(?, ? ,? ,?, ?, ?)',
|
||||||
|
'iissss',
|
||||||
|
$userId,
|
||||||
|
$seminaryId,
|
||||||
|
$filename,
|
||||||
|
\nre\core\Linker::createLinkParam($filename),
|
||||||
|
$description,
|
||||||
|
$mimetype
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
return $this->db->getInsertId();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
||||||
1
views/binary/media/charactergroupsquest.tpl
Normal file
1
views/binary/media/charactergroupsquest.tpl
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<?=$file?>
|
||||||
|
|
@ -18,6 +18,17 @@
|
||||||
<?php foreach($settings as $setting => $value) : ?>
|
<?php foreach($settings as $setting => $value) : ?>
|
||||||
<li>
|
<li>
|
||||||
<?php switch($field) {
|
<?php switch($field) {
|
||||||
|
case 'icon':
|
||||||
|
switch($setting) {
|
||||||
|
case 'error': printf(_('Error during icon upload: %s'), $value);
|
||||||
|
break;
|
||||||
|
case 'mimetype': printf(_('Icon has wrong type “%s”'), $value);
|
||||||
|
break;
|
||||||
|
case 'size': echo _('Icon exceeds size maximum');
|
||||||
|
break;
|
||||||
|
default: echo _('Icon invalid');
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 'charactergroupname':
|
case 'charactergroupname':
|
||||||
switch($setting) {
|
switch($setting) {
|
||||||
case 'minlength': printf(_('Name is too short (min. %d chars)'), $value);
|
case 'minlength': printf(_('Name is too short (min. %d chars)'), $value);
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,17 @@
|
||||||
<?php foreach($settings as $setting => $value) : ?>
|
<?php foreach($settings as $setting => $value) : ?>
|
||||||
<li>
|
<li>
|
||||||
<?php switch($field) {
|
<?php switch($field) {
|
||||||
|
case 'icon':
|
||||||
|
switch($setting) {
|
||||||
|
case 'error': printf(_('Error during icon upload: %s'), $value);
|
||||||
|
break;
|
||||||
|
case 'mimetype': printf(_('Icon has wrong type “%s”'), $value);
|
||||||
|
break;
|
||||||
|
case 'size': echo _('Icon exceeds size maximum');
|
||||||
|
break;
|
||||||
|
default: echo _('Icon invalid');
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 'charactergroupname':
|
case 'charactergroupname':
|
||||||
switch($setting) {
|
switch($setting) {
|
||||||
case 'minlength': printf(_('Name is too short (min. %d chars)'), $value);
|
case 'minlength': printf(_('Name is too short (min. %d chars)'), $value);
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,17 @@
|
||||||
<?php foreach($settings as $setting => $value) : ?>
|
<?php foreach($settings as $setting => $value) : ?>
|
||||||
<li>
|
<li>
|
||||||
<?php switch($field) {
|
<?php switch($field) {
|
||||||
|
case 'icon':
|
||||||
|
switch($setting) {
|
||||||
|
case 'error': printf(_('Error during icon upload: %s'), $value);
|
||||||
|
break;
|
||||||
|
case 'mimetype': printf(_('Icon has wrong type “%s”'), $value);
|
||||||
|
break;
|
||||||
|
case 'size': echo _('Icon exceeds size maximum');
|
||||||
|
break;
|
||||||
|
default: echo _('Icon invalid');
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 'title':
|
case 'title':
|
||||||
switch($setting) {
|
switch($setting) {
|
||||||
case 'minlength': printf(_('Title is too short (min. %d chars)'), $value);
|
case 'minlength': printf(_('Title is too short (min. %d chars)'), $value);
|
||||||
|
|
@ -40,9 +51,6 @@
|
||||||
default: echo _('XPs invalid');
|
default: echo _('XPs invalid');
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
echo $exception->getMessage();
|
|
||||||
break;
|
|
||||||
} ?>
|
} ?>
|
||||||
</li>
|
</li>
|
||||||
<?php endforeach ?>
|
<?php endforeach ?>
|
||||||
|
|
@ -51,7 +59,17 @@
|
||||||
<?php endforeach ?>
|
<?php endforeach ?>
|
||||||
</ul>
|
</ul>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
<form method="post" action="" class="logreg">
|
<form method="post" action="" class="logreg" enctype="multipart/form-data">
|
||||||
|
<fieldset>
|
||||||
|
<legend><?=_('Icon')?></legend>
|
||||||
|
<input type="file" name="icon" />
|
||||||
|
<p><?=_('Allowed file types')?>:</p>
|
||||||
|
<ul>
|
||||||
|
<?php foreach($mimetypes as &$mimetype) : ?>
|
||||||
|
<li><?=sprintf(_('%s-files'), strtoupper(explode('/',$mimetype['mimetype'])[1]))?> <?php if($mimetype['size'] > 0) : ?>(<?=_('max.')?> <?=round($mimetype['size']/(1024*1024),2)?> MiB)<?php endif ?></li>
|
||||||
|
<?php endforeach ?>
|
||||||
|
</ul>
|
||||||
|
</fieldset>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<label for="title"><?=_('Title')?>:</label>
|
<label for="title"><?=_('Title')?>:</label>
|
||||||
<input type="text" id="title" name="title" placeholder="<?=_('Title')?>" title="<?=_('Title')?>" maxlength="<?=$validationSettings['title']['maxlength']?>" value="<?=$title?>" <?=(array_key_exists('title', $validation)) ? 'class="invalid"' : null?> />
|
<input type="text" id="title" name="title" placeholder="<?=_('Title')?>" title="<?=_('Title')?>" maxlength="<?=$validationSettings['title']['maxlength']?>" value="<?=$title?>" <?=(array_key_exists('title', $validation)) ? 'class="invalid"' : null?> />
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,17 @@
|
||||||
<?php foreach($settings as $setting => $value) : ?>
|
<?php foreach($settings as $setting => $value) : ?>
|
||||||
<li>
|
<li>
|
||||||
<?php switch($field) {
|
<?php switch($field) {
|
||||||
|
case 'icon':
|
||||||
|
switch($setting) {
|
||||||
|
case 'error': printf(_('Error during icon upload: %s'), $value);
|
||||||
|
break;
|
||||||
|
case 'mimetype': printf(_('Icon has wrong type “%s”'), $value);
|
||||||
|
break;
|
||||||
|
case 'size': echo _('Icon exceeds size maximum');
|
||||||
|
break;
|
||||||
|
default: echo _('Icon invalid');
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 'title':
|
case 'title':
|
||||||
switch($setting) {
|
switch($setting) {
|
||||||
case 'minlength': printf(_('Title is too short (min. %d chars)'), $value);
|
case 'minlength': printf(_('Title is too short (min. %d chars)'), $value);
|
||||||
|
|
@ -40,9 +51,6 @@
|
||||||
default: echo _('XPs invalid');
|
default: echo _('XPs invalid');
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
echo $exception->getMessage();
|
|
||||||
break;
|
|
||||||
} ?>
|
} ?>
|
||||||
</li>
|
</li>
|
||||||
<?php endforeach ?>
|
<?php endforeach ?>
|
||||||
|
|
@ -51,7 +59,18 @@
|
||||||
<?php endforeach ?>
|
<?php endforeach ?>
|
||||||
</ul>
|
</ul>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
<form method="post" action="" class="logreg">
|
<form method="post" action="" class="logreg" enctype="multipart/form-data">
|
||||||
|
<fieldset>
|
||||||
|
<legend><?=_('Icon')?></legend>
|
||||||
|
<img src="<?=$linker->link(array('media','charactergroupsquest',$seminary['url'],$groupsgroup['url'],$quest['url']))?>" /><br />
|
||||||
|
<input type="file" name="icon" />
|
||||||
|
<p><?=_('Allowed file types')?>:</p>
|
||||||
|
<ul>
|
||||||
|
<?php foreach($mimetypes as &$mimetype) : ?>
|
||||||
|
<li><?=sprintf(_('%s-files'), strtoupper(explode('/',$mimetype['mimetype'])[1]))?> <?php if($mimetype['size'] > 0) : ?>(<?=_('max.')?> <?=round($mimetype['size']/(1024*1024),2)?> MiB)<?php endif ?></li>
|
||||||
|
<?php endforeach ?>
|
||||||
|
</ul>
|
||||||
|
</fieldset>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<label for="title"><?=_('Title')?>:</label>
|
<label for="title"><?=_('Title')?>:</label>
|
||||||
<input type="text" id="title" name="title" placeholder="<?=_('Title')?>" title="<?=_('Title')?>" maxlength="<?=$validationSettings['title']['maxlength']?>" value="<?=$title?>" <?=(array_key_exists('title', $validation)) ? 'class="invalid"' : null?> />
|
<input type="text" id="title" name="title" placeholder="<?=_('Title')?>" title="<?=_('Title')?>" maxlength="<?=$validationSettings['title']['maxlength']?>" value="<?=$title?>" <?=(array_key_exists('title', $validation)) ? 'class="invalid"' : null?> />
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,7 @@
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
|
|
||||||
<div class="gbanner cf">
|
<div class="gbanner cf">
|
||||||
<?php if(!is_null($media)) : ?>
|
<img src="<?=$linker->link(array('media','charactergroupsquest',$seminary['url'],$groupsgroup['url'],$quest['url']))?>" class="grpqimg" />
|
||||||
<img src="<?=$linker->link(array('media','seminary',$seminary['url'],$media['url']))?>" class="grpqimg" />
|
|
||||||
<?php else : ?>
|
|
||||||
<img src="<?=$linker->link(array('grafics','charactergroup.jpg'))?>" class="gbanner">
|
|
||||||
<?php endif ?>
|
|
||||||
<h1><?=$quest['title']?></h1>
|
<h1><?=$quest['title']?></h1>
|
||||||
</div>
|
</div>
|
||||||
<ul class="gdata cf">
|
<ul class="gdata cf">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue