implement CRUD for Achievements (issue #318)
This commit is contained in:
parent
a982460289
commit
59778e2b2e
12 changed files with 1776 additions and 10 deletions
|
|
@ -219,6 +219,9 @@
|
|||
'questgroupshierarchytitle' => array(
|
||||
'minlength' => 1,
|
||||
'maxlength' => 64
|
||||
),
|
||||
'deadline' => array(
|
||||
'regex' => '/^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})?$/'
|
||||
)
|
||||
);
|
||||
|
||||
|
|
@ -261,7 +264,9 @@
|
|||
array('^charactergroupsquests/([^/]+)/([^/]+)/create/?$', 'charactergroupsquests/create/$1/$2', true),
|
||||
array('^charactergroupsquests/([^/]+)/([^/]+)/([^/]+)/?$', 'charactergroupsquests/quest/$1/$2/$3', true),
|
||||
array('^charactergroupsquests/([^/]+)/([^/]+)/([^/]+)/(edit|delete|manage)/?$', 'charactergroupsquests/$4/$1/$2/$3', true),
|
||||
array('^achievements/([^/]+)/?$', 'achievements/index/$1', true),
|
||||
array('^achievements/([^/]+)/(create|manage)/?$', 'achievements/$2/$1', true),
|
||||
array('^achievements/([^/]+)/([^/]+)/(edit|conditions|moveup|movedown|delete)/?$', 'achievements/$3/$1/$2', true),
|
||||
array('^achievements/([^/]+)/?$', 'achievements/index/$1', true),
|
||||
array('^library/([^/]+)/?$', 'library/index/$1', true),
|
||||
array('^library/([^/]+)/create/?$', 'library/create/$1', true),
|
||||
array('^library/([^/]+)/([^/]+)/?$', 'library/topic/$1/$2', true),
|
||||
|
|
@ -305,7 +310,9 @@
|
|||
array('^charactergroupsquests/create/([^/]+)/([^/]+)/?$', 'charactergroupsquests/$1/$2/create', true),
|
||||
array('^charactergroupsquests/quest/(.*)$', 'charactergroupsquests/$1', true),
|
||||
array('^charactergroupsquests/(edit|delete|manage)/([^/]+)/([^/]+)/([^/]+)$', 'charactergroupsquests/$2/$3/$4/$1', true),
|
||||
array('^achievements/index/(.*)$', 'achievements/$1', true),
|
||||
array('^achievements/index/(.*)$', 'achievements/$1', true),
|
||||
array('^achievements/(create|manage)/(.*)$', 'achievements/$2/$1', true),
|
||||
array('^achievements/(edit|conditions|moveup|movedown|delete)/(.*)$', 'achievements/$2/$1', true),
|
||||
array('^library/index/([^/]+)/?$', 'library/$1', true),
|
||||
array('^library/create/([^/]+)/?$', 'library/$1/create', true),
|
||||
array('^library/topic/([^/]+)/([^/]+)/?$', 'library/$1/$2', true),
|
||||
|
|
|
|||
|
|
@ -24,14 +24,25 @@
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('achievements', 'seminaries', 'media', 'characters');
|
||||
public $models = array('achievements', 'seminaries', 'media', 'characters', 'quests');
|
||||
/**
|
||||
* Required components
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $components = array('validation');
|
||||
/**
|
||||
* User permissions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $permissions = array(
|
||||
'index' => array('admin', 'moderator', 'user')
|
||||
'index' => array('admin', 'moderator', 'user'),
|
||||
'create' => array('admin', 'moderator', 'user'),
|
||||
'moveup' => array('admin', 'moderator', 'user'),
|
||||
'movedown' => array('admin', 'moderator', 'user'),
|
||||
'edit' => array('admin', 'moderator', 'user'),
|
||||
'delete' => array('admin', 'moderator', 'user')
|
||||
);
|
||||
/**
|
||||
* User seminary permissions
|
||||
|
|
@ -39,7 +50,12 @@
|
|||
* @var array
|
||||
*/
|
||||
public $seminaryPermissions = array(
|
||||
'index' => array('admin', 'moderator', 'user')
|
||||
'index' => array('admin', 'moderator', 'user'),
|
||||
'create' => array('admin'),
|
||||
'moveup' => array('admin', 'moderator'),
|
||||
'movedown' => array('admin', 'moderator'),
|
||||
'edit' => array('admin', 'moderator'),
|
||||
'delete' => array('admin')
|
||||
);
|
||||
|
||||
|
||||
|
|
@ -184,6 +200,759 @@
|
|||
$this->set('unachievedAchievements', $unachievedAchievements);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: manage.
|
||||
*
|
||||
* Manage Achievements of a Seminary.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param string $seminaryUrl URL-Title of Seminary
|
||||
*/
|
||||
public function manage($seminaryUrl)
|
||||
{
|
||||
// Get Seminary
|
||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||
|
||||
// Get Achievements
|
||||
$achievements = $this->Achievements->getAchievementsForSeminary($seminary['id']);
|
||||
|
||||
|
||||
// Set title
|
||||
$this->addTitleLocalized('Manage Achievements');
|
||||
$this->addTitle($seminary['title']);
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('achievements', $achievements);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: create.
|
||||
*
|
||||
* Create a new Achievement.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param string $seminaryUrl URL-title of Seminary
|
||||
*/
|
||||
public function create($seminaryUrl)
|
||||
{
|
||||
// Get seminary
|
||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||
|
||||
// Get Achievements conditions
|
||||
$conditions = $this->Achievements->getAchievementsConditions();
|
||||
|
||||
// Get allowed mimetypes
|
||||
$mimetypes = \nre\configs\AppConfig::$mimetypes['moodpics'];
|
||||
|
||||
// Values
|
||||
$title = '';
|
||||
$description = '';
|
||||
$progress = 0;
|
||||
$hidden = 0;
|
||||
$onlyOnce = 0;
|
||||
$allConditions = 1;
|
||||
$deadline = '';
|
||||
$condition = $conditions[0]['condition'];
|
||||
$fields = array('title', 'deadline');
|
||||
$validation = array();
|
||||
|
||||
// Create Achievement
|
||||
if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('edit')))
|
||||
{
|
||||
// Get params and validate them
|
||||
$validation = $this->Validation->validateParams($this->request->getPostParams(), $fields);
|
||||
$title = $this->request->getPostParam('title');
|
||||
if($this->Achievements->achievementTitleExists($seminary['id'], $title)) {
|
||||
$validation = $this->Validation->addValidationResult($validation, 'title', 'exist', true);
|
||||
}
|
||||
$description = $this->request->getPostParam('description');
|
||||
$progress = !is_null($this->request->getPostParam('progress'));
|
||||
$hidden = !is_null($this->request->getPostParam('hidden'));
|
||||
$onlyOnce = !is_null($this->request->getPostParam('only_once'));
|
||||
$allConditions = !is_null($this->request->getPostParam('all_conditions'));
|
||||
$deadline = $this->request->getPostParam('deadline');
|
||||
$condition = $this->request->getPostParam('condition');
|
||||
|
||||
// Validate condition
|
||||
$conditionIndex = null;
|
||||
foreach($conditions as $index => &$c) {
|
||||
if($condition == $c['condition']) {
|
||||
$conditionIndex = $index;
|
||||
}
|
||||
}
|
||||
if(is_null($conditionIndex)) {
|
||||
throw new \nre\exceptions\ParamsNotValidException($condition);
|
||||
}
|
||||
|
||||
// Validate images
|
||||
$images = array(
|
||||
'unachieved_image' => null,
|
||||
'achieved_image' => null
|
||||
);
|
||||
foreach($images as $key => $image)
|
||||
{
|
||||
if(!empty($_FILES) && array_key_exists($key, $_FILES) && $_FILES[$key]['error'] != UPLOAD_ERR_NO_FILE)
|
||||
{
|
||||
$images[$key] = $_FILES[$key];
|
||||
|
||||
// Check error
|
||||
if($images[$key]['error'] !== UPLOAD_ERR_OK) {
|
||||
$validation = $this->Validation->addValidationResult($validation, 'image', 'error', $image[$key]['error']);
|
||||
}
|
||||
|
||||
// Check mimetype
|
||||
$mediaMimetype = null;
|
||||
$images[$key]['mimetype'] = \hhu\z\Utils::getMimetype($images[$key]['tmp_name'], $images[$key]['type']);
|
||||
foreach($mimetypes as &$mimetype) {
|
||||
if($mimetype['mimetype'] == $images[$key]['mimetype']) {
|
||||
$mediaMimetype = $mimetype;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(is_null($mediaMimetype)) {
|
||||
$validation = $this->Validation->addValidationResult($validation, 'image', 'mimetype', $images[$key]['mimetype']);
|
||||
}
|
||||
elseif($images[$key]['size'] > $mediaMimetype['size']) {
|
||||
$validation = $this->Validation->addValidationResult($validation, 'image', 'size', $mediaMimetype['size']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create Achievement
|
||||
if($validation === true)
|
||||
{
|
||||
$achievementId = $this->Achievements->createAchievement(
|
||||
$this->Auth->getUserId(),
|
||||
$seminary['id'],
|
||||
$conditions[$conditionIndex]['id'],
|
||||
$title,
|
||||
$description,
|
||||
$progress,
|
||||
$hidden,
|
||||
$onlyOnce,
|
||||
$allConditions,
|
||||
(!empty($deadline)) ? $deadline : NULL
|
||||
);
|
||||
$achievement = $this->Achievements->getAchievementById($achievementId);
|
||||
|
||||
// Upload images
|
||||
foreach($images as $key => &$image)
|
||||
{
|
||||
if(!is_null($image))
|
||||
{
|
||||
$image['media_id'] = $this->Media->createAchievementMedia(
|
||||
$this->Auth->getUserId(),
|
||||
$seminary['id'],
|
||||
sprintf('achievement-%d', $achievement['id']).(substr($key, 0, 2) == 'un' ? '-locked' : NULL),
|
||||
'',
|
||||
$image['mimetype'],
|
||||
$image['tmp_name']
|
||||
);
|
||||
}
|
||||
}
|
||||
if(!is_null($images['unachieved_image']) && $images['unachieved_image']['media_id'] !== false) {
|
||||
$this->Achievements->setUnachievedMediaForAchievement($achievement['id'], $images['unachieved_image']['media_id']);
|
||||
}
|
||||
if(!is_null($images['achieved_image']) && $images['achieved_image']['media_id'] !== false) {
|
||||
$this->Achievements->setAchievedMediaForAchievement($achievement['id'], $images['achieved_image']['media_id']);
|
||||
}
|
||||
|
||||
// Redirect to condition editing
|
||||
//$this->redirect($this->linker->link(array('conditions', $seminary['url'], $achievement['url']), 1));
|
||||
}
|
||||
}
|
||||
|
||||
// Get validation settings
|
||||
$validationSettings = array();
|
||||
foreach($fields as &$field) {
|
||||
$validationSettings[$field] = \nre\configs\AppConfig::$validation[$field];
|
||||
}
|
||||
|
||||
|
||||
// Set title
|
||||
$this->addTitleLocalized('Create Achievement');
|
||||
$this->addTitle($seminary['title']);
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('title', $title);
|
||||
$this->set('description', $description);
|
||||
$this->set('progress', $progress);
|
||||
$this->set('hidden', $hidden);
|
||||
$this->set('onlyOnce', $onlyOnce);
|
||||
$this->set('allConditions', $allConditions);
|
||||
$this->set('deadline', $deadline);
|
||||
$this->set('condition', $condition);
|
||||
$this->set('conditions', $conditions);
|
||||
$this->set('mimetypes', $mimetypes);
|
||||
$this->set('validation', $validation);
|
||||
$this->set('validationSettings', $validationSettings);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: moveup.
|
||||
*
|
||||
* Move an Achievement up (decrement position).
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param string $seminaryUrl URL-title of Seminary
|
||||
* @param string $achievementUrl URL-title of Achievement
|
||||
*/
|
||||
public function moveup($seminaryUrl, $achievementUrl)
|
||||
{
|
||||
// Get seminary
|
||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||
|
||||
// Get Achievement
|
||||
$achievement = $this->Achievements->getAchievementByUrl($seminary['id'], $achievementUrl);
|
||||
|
||||
// Set position
|
||||
$this->Achievements->moveAchievement($achievement, true);
|
||||
|
||||
|
||||
// Redirect
|
||||
$this->redirect($this->linker->link(array('manage', $seminary['url']), 1, true, null, false, $achievement['url']));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: movedown.
|
||||
*
|
||||
* Move an Achievement down (increment position).
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param string $seminaryUrl URL-title of Seminary
|
||||
* @param string $achievementUrl URL-title of Achievement
|
||||
*/
|
||||
public function movedown($seminaryUrl, $achievementUrl)
|
||||
{
|
||||
// Get seminary
|
||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||
|
||||
// Get Achievement
|
||||
$achievement = $this->Achievements->getAchievementByUrl($seminary['id'], $achievementUrl);
|
||||
|
||||
// Set position
|
||||
$this->Achievements->moveAchievement($achievement, false);
|
||||
|
||||
|
||||
// Redirect
|
||||
$this->redirect($this->linker->link(array('manage', $seminary['url']), 1, true, null, false, $achievement['url']));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: edit.
|
||||
*
|
||||
* Edit an Achievement.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param string $seminaryUrl URL-title of Seminary
|
||||
* @param string $achievementUrl URL-title of Achievement to edit
|
||||
*/
|
||||
public function edit($seminaryUrl, $achievementUrl)
|
||||
{
|
||||
// Get seminary
|
||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||
|
||||
// Get Achievement
|
||||
$achievement = $this->Achievements->getAchievementByUrl($seminary['id'], $achievementUrl);
|
||||
|
||||
// Get Achievements conditions
|
||||
$conditions = $this->Achievements->getAchievementsConditions();
|
||||
|
||||
// Get allowed mimetypes
|
||||
$mimetypes = \nre\configs\AppConfig::$mimetypes['moodpics'];
|
||||
|
||||
// Values
|
||||
$title = $achievement['title'];
|
||||
$description = $achievement['description'];
|
||||
$progress = $achievement['progress'];
|
||||
$hidden = $achievement['hidden'];
|
||||
$onlyOnce = $achievement['only_once'];
|
||||
$allConditions = $achievement['all_conditions'];
|
||||
$deadline = $achievement['deadline'];
|
||||
$condition = $achievement['condition'];
|
||||
$fields = array('title', 'deadline');
|
||||
$validation = array();
|
||||
|
||||
// Edit Achievement
|
||||
if($this->request->getRequestMethod() == 'POST' && (!is_null($this->request->getPostParam('edit')) || !is_null($this->request->getPostParam('edit-conditions'))))
|
||||
{
|
||||
// Get params and validate them
|
||||
$validation = $this->Validation->validateParams($this->request->getPostParams(), $fields);
|
||||
$title = $this->request->getPostParam('title');
|
||||
if($this->Achievements->achievementTitleExists($seminary['id'], $title, $achievement['id'])) {
|
||||
$validation = $this->Validation->addValidationResult($validation, 'title', 'exist', true);
|
||||
}
|
||||
$description = $this->request->getPostParam('description');
|
||||
$progress = !is_null($this->request->getPostParam('progress'));
|
||||
$hidden = !is_null($this->request->getPostParam('hidden'));
|
||||
$onlyOnce = !is_null($this->request->getPostParam('only_once'));
|
||||
$allConditions = !is_null($this->request->getPostParam('all_conditions'));
|
||||
$deadline = $this->request->getPostParam('deadline');
|
||||
$condition = $this->request->getPostParam('condition');
|
||||
|
||||
// Validate condition
|
||||
$conditionIndex = null;
|
||||
foreach($conditions as $index => &$c) {
|
||||
if($condition == $c['condition']) {
|
||||
$conditionIndex = $index;
|
||||
}
|
||||
}
|
||||
if(is_null($conditionIndex)) {
|
||||
throw new \nre\exceptions\ParamsNotValidException($condition);
|
||||
}
|
||||
|
||||
// Validate images
|
||||
$images = array(
|
||||
'unachieved_image' => null,
|
||||
'achieved_image' => null
|
||||
);
|
||||
foreach($images as $key => $image)
|
||||
{
|
||||
if(!empty($_FILES) && array_key_exists($key, $_FILES) && $_FILES[$key]['error'] != UPLOAD_ERR_NO_FILE)
|
||||
{
|
||||
$images[$key] = $_FILES[$key];
|
||||
|
||||
// Check error
|
||||
if($images[$key]['error'] !== UPLOAD_ERR_OK) {
|
||||
$validation = $this->Validation->addValidationResult($validation, 'image', 'error', $image[$key]['error']);
|
||||
}
|
||||
|
||||
// Check mimetype
|
||||
$mediaMimetype = null;
|
||||
$images[$key]['mimetype'] = \hhu\z\Utils::getMimetype($images[$key]['tmp_name'], $images[$key]['type']);
|
||||
foreach($mimetypes as &$mimetype) {
|
||||
if($mimetype['mimetype'] == $images[$key]['mimetype']) {
|
||||
$mediaMimetype = $mimetype;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(is_null($mediaMimetype)) {
|
||||
$validation = $this->Validation->addValidationResult($validation, 'image', 'mimetype', $images[$key]['mimetype']);
|
||||
}
|
||||
elseif($images[$key]['size'] > $mediaMimetype['size']) {
|
||||
$validation = $this->Validation->addValidationResult($validation, 'image', 'size', $mediaMimetype['size']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Edit Achievement
|
||||
if($validation === true)
|
||||
{
|
||||
$this->Achievements->editAchievement(
|
||||
$achievement['id'],
|
||||
$conditions[$conditionIndex]['id'],
|
||||
$title,
|
||||
$description,
|
||||
$progress,
|
||||
$hidden,
|
||||
$onlyOnce,
|
||||
$allConditions,
|
||||
(!empty($deadline)) ? $deadline : NULL
|
||||
);
|
||||
|
||||
// Remove old conditions
|
||||
if($conditions[$conditionIndex]['condition'] != $achievement['condition'])
|
||||
{
|
||||
var_dump("remove");
|
||||
switch($achievement['condition'])
|
||||
{
|
||||
// Date conditions
|
||||
case 'date':
|
||||
foreach($this->Achievements->getAchievementConditionsDate($achievement['id']) as $c) {
|
||||
$this->Achievements->deleteAchievementConditionDate($c['id']);
|
||||
}
|
||||
break;
|
||||
// Character conditions
|
||||
case 'character':
|
||||
foreach($this->Achievements->getAchievementConditionsCharacter($achievement['id']) as $c) {
|
||||
$this->Achievements->deleteAchievementConditionCharacter($c['id']);
|
||||
}
|
||||
break;
|
||||
// Quest conditions
|
||||
case 'quest':
|
||||
foreach($this->Achievements->getAchievementConditionsQuest($achievement['id']) as $c) {
|
||||
$this->Achievements->deleteAchievementConditionQuest($c['id']);
|
||||
}
|
||||
break;
|
||||
// Achievement conditions
|
||||
case 'achievement':
|
||||
foreach($this->Achievements->getAchievementConditionsAchievement($achievement['id']) as $c) {
|
||||
$this->Achievements->deleteAchievementConditionAchievement($c['id']);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Upload images
|
||||
foreach($images as $key => &$image)
|
||||
{
|
||||
if(!is_null($image))
|
||||
{
|
||||
$image['media_id'] = $this->Media->createAchievementMedia(
|
||||
$this->Auth->getUserId(),
|
||||
$seminary['id'],
|
||||
sprintf('achievement-%d', $achievement['id']).(substr($key, 0, 2) == 'un' ? '-locked' : NULL),
|
||||
'',
|
||||
$image['mimetype'],
|
||||
$image['tmp_name']
|
||||
);
|
||||
}
|
||||
}
|
||||
if(!is_null($images['unachieved_image']) && $images['unachieved_image']['media_id'] !== false) {
|
||||
$this->Achievements->setUnachievedMediaForAchievement($achievement['id'], $images['unachieved_image']['media_id']);
|
||||
}
|
||||
if(!is_null($images['achieved_image']) && $images['achieved_image']['media_id'] !== false) {
|
||||
$this->Achievements->setAchievedMediaForAchievement($achievement['id'], $images['achieved_image']['media_id']);
|
||||
}
|
||||
|
||||
// Redirect
|
||||
if(!is_null($this->request->getPostParam('edit-conditions'))) {
|
||||
// To condition editing
|
||||
$this->redirect($this->linker->link(array('conditions', $seminary['url'], $achievement['url']), 1));
|
||||
}
|
||||
else {
|
||||
// To overview
|
||||
$this->redirect($this->linker->link(array('manage', $seminary['url']), 1, true, null, false, $achievement['url']));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get validation settings
|
||||
$validationSettings = array();
|
||||
foreach($fields as &$field) {
|
||||
$validationSettings[$field] = \nre\configs\AppConfig::$validation[$field];
|
||||
}
|
||||
|
||||
|
||||
// Set title
|
||||
$this->addTitleLocalized('Edit Achievement');
|
||||
$this->addTitle($seminary['title']);
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('achievement', $achievement);
|
||||
$this->set('title', $title);
|
||||
$this->set('description', $description);
|
||||
$this->set('progress', $progress);
|
||||
$this->set('hidden', $hidden);
|
||||
$this->set('onlyOnce', $onlyOnce);
|
||||
$this->set('allConditions', $allConditions);
|
||||
$this->set('deadline', $deadline);
|
||||
$this->set('condition', $condition);
|
||||
$this->set('conditions', $conditions);
|
||||
$this->set('mimetypes', $mimetypes);
|
||||
$this->set('validation', $validation);
|
||||
$this->set('validationSettings', $validationSettings);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: conditions.
|
||||
*
|
||||
* Edit conditions of an Achievement.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param string $seminaryUrl URL-title of Seminary
|
||||
* @param string $achievementUrl URL-title of Achievement to edit
|
||||
*/
|
||||
public function conditions($seminaryUrl, $achievementUrl)
|
||||
{
|
||||
// Get seminary
|
||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||
|
||||
// Get Achievement
|
||||
$achievement = $this->Achievements->getAchievementByUrl($seminary['id'], $achievementUrl);
|
||||
|
||||
// Get conditions
|
||||
$conditions = array();
|
||||
switch($achievement['condition'])
|
||||
{
|
||||
// Date conditions
|
||||
case 'date':
|
||||
$conditions = $this->Achievements->getAchievementConditionsDate($achievement['id']);
|
||||
break;
|
||||
// Character conditions
|
||||
case 'character':
|
||||
$conditions = $this->Achievements->getAchievementConditionsCharacter($achievement['id']);
|
||||
break;
|
||||
// Quest conditions
|
||||
case 'quest':
|
||||
$conditions = $this->Achievements->getAchievementConditionsQuest($achievement['id']);
|
||||
break;
|
||||
// Achievement conditions
|
||||
case 'achievement':
|
||||
$conditions = $this->Achievements->getAchievementConditionsAchievement($achievement['id']);
|
||||
break;
|
||||
}
|
||||
|
||||
// Values
|
||||
$characterFields = array(
|
||||
'id', 'created', 'user_id', 'name', 'url', 'xps', 'quest_xps', 'avatar_id',
|
||||
'charactertype_id', 'charactertype_name', 'charactertype_url',
|
||||
'xplevel_id', 'xplevel'
|
||||
);
|
||||
$questFields = array(
|
||||
'id', 'quest_id', 'character_id', 'created', 'status'
|
||||
);
|
||||
$achievementFields = array(
|
||||
'achievement_id', 'character_id', 'created'
|
||||
);
|
||||
$quests = $this->Quests->getQuestsForSeminary($seminary['id']);
|
||||
$achievements = $this->Achievements->getAchievementsForSeminary($seminary['id']);
|
||||
$deletes = array();
|
||||
|
||||
// Save conditions
|
||||
if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('edit')))
|
||||
{
|
||||
// Get entered conditions
|
||||
$selectedConditions = $this->request->getPostParam('conditions');
|
||||
$deletes = $this->request->getPostParam('deletes');
|
||||
if(!is_array($deletes)) {
|
||||
$deletes = array();
|
||||
}
|
||||
|
||||
// Edit or delete conditions
|
||||
foreach($conditions as &$condition)
|
||||
{
|
||||
$selectedCondition = $selectedConditions[$condition['id']];
|
||||
switch($achievement['condition'])
|
||||
{
|
||||
// Date conditions
|
||||
case 'date':
|
||||
if(array_key_exists($condition['id'], $deletes)) {
|
||||
$this->Achievements->deleteAchievementConditionDate($condition['id']);
|
||||
}
|
||||
else {
|
||||
$this->Achievements->editAchievementConditionDate(
|
||||
$condition['id'],
|
||||
$selectedCondition['select']
|
||||
);
|
||||
}
|
||||
break;
|
||||
// Character conditions
|
||||
case 'character':
|
||||
if(array_key_exists($condition['id'], $deletes)) {
|
||||
$this->Achievements->deleteAchievementConditionCharacter($condition['id']);
|
||||
}
|
||||
else {
|
||||
$this->Achievements->editAchievementConditionCharacter(
|
||||
$condition['id'],
|
||||
$selectedCondition['field'],
|
||||
$selectedCondition['value']
|
||||
);
|
||||
}
|
||||
break;
|
||||
// Quest conditions
|
||||
case 'quest':
|
||||
if(array_key_exists($condition['id'], $deletes)) {
|
||||
$this->Achievements->deleteAchievementConditionQuest($condition['id']);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Get selected Quest
|
||||
$questIndex = null;
|
||||
if(!empty($selectedCondition['quest'])) {
|
||||
foreach($quests as $index => &$quest) {
|
||||
if($quest['url'] == $selectedCondition['quest']) {
|
||||
$questIndex = $index;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Edit condition
|
||||
$this->Achievements->editAchievementConditionQuest(
|
||||
$condition['id'],
|
||||
$selectedCondition['field'],
|
||||
array_key_exists('count', $selectedCondition),
|
||||
$selectedCondition['value'],
|
||||
(!is_null($questIndex)) ? $quests[$questIndex]['id'] : null,
|
||||
($selectedCondition['status'] != '') ? $selectedCondition['status'] : null,
|
||||
(!empty($selectedCondition['groupby'])) ? $selectedCondition['groupby'] : null
|
||||
);
|
||||
}
|
||||
break;
|
||||
// Achievement conditions
|
||||
case 'achievement':
|
||||
if(array_key_exists($condition['id'], $deletes)) {
|
||||
$this->Achievements->deleteAchievementConditionAchievement($condition['id']);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Get selected Achievement
|
||||
$achievmentIndex = null;
|
||||
if(!empty($selectedCondition['achievement'])) {
|
||||
foreach($achievements as $index => &$a) {
|
||||
if($a['url'] == $selectedCondition['achievement']) {
|
||||
$achievementIndex = $index;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Edit condition
|
||||
$this->Achievements->editAchievementConditionAchievement(
|
||||
$condition['id'],
|
||||
$selectedCondition['field'],
|
||||
array_key_exists('count', $selectedCondition),
|
||||
$selectedCondition['value'],
|
||||
(!is_null($achievementIndex)) ? $achievements[$achievementIndex]['id'] : null,
|
||||
(!empty($selectedCondition['groupby'])) ? $selectedCondition['groupby'] : null
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Add new condition
|
||||
if(array_key_exists('new', $selectedConditions))
|
||||
{
|
||||
$condition = $selectedConditions['new'];
|
||||
switch($achievement['condition'])
|
||||
{
|
||||
// Date conditions
|
||||
case 'date':
|
||||
if(!empty($condition['select'])) {
|
||||
$this->Achievements->addAchievementConditionDate(
|
||||
$this->Auth->getUserId(),
|
||||
$achievement['id'],
|
||||
$condition['select']
|
||||
);
|
||||
}
|
||||
break;
|
||||
// Character conditions
|
||||
case 'character':
|
||||
if(!empty($condition['value'])) {
|
||||
$this->Achievements->addAchievementConditionCharacter(
|
||||
$this->Auth->getUserId(),
|
||||
$achievement['id'],
|
||||
$condition['field'],
|
||||
$condition['value']
|
||||
);
|
||||
}
|
||||
break;
|
||||
// Quest conditions
|
||||
case 'quest':
|
||||
if(!empty($condition['value']))
|
||||
{
|
||||
// Get selected Quest
|
||||
$questIndex = null;
|
||||
if(!empty($condition['quest'])) {
|
||||
foreach($quests as $index => &$quest) {
|
||||
if($quest['url'] == $condition['quest']) {
|
||||
$questIndex = $index;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Edit condition
|
||||
$this->Achievements->addAchievementConditionQuest(
|
||||
$this->Auth->getUserId(),
|
||||
$achievement['id'],
|
||||
$condition['field'],
|
||||
array_key_exists('count', $condition),
|
||||
$condition['value'],
|
||||
(!is_null($questIndex)) ? $quests[$questIndex]['id'] : null,
|
||||
($condition['status'] != '') ? $condition['status'] : null,
|
||||
(!empty($condition['groupby'])) ? $condition['groupby'] : null
|
||||
);
|
||||
}
|
||||
break;
|
||||
// Achievement conditions
|
||||
case 'achievement':
|
||||
if(!empty($condition['value']))
|
||||
{
|
||||
// Get selected Achievement
|
||||
$achievmentIndex = null;
|
||||
if(!empty($selectedCondition['achievement'])) {
|
||||
foreach($achievements as $index => &$a) {
|
||||
if($a['url'] == $selectedCondition['achievement']) {
|
||||
$achievementIndex = $index;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Edit condition
|
||||
$this->Achievements->addAchievementConditionAchievement(
|
||||
$this->Auth->getUserId(),
|
||||
$achievement['id'],
|
||||
$condition['field'],
|
||||
array_key_exists('count', $condition),
|
||||
$condition['value'],
|
||||
(!is_null($achievementIndex)) ? $achievements[$achievementIndex]['id'] : null,
|
||||
(!empty($condition['groupby'])) ? $condition['groupby'] : null
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Redirect to overview
|
||||
$this->redirect($this->linker->link(array('manage', $seminary['url']), 1, true, null, false, $achievement['url']));
|
||||
}
|
||||
|
||||
|
||||
// Set title
|
||||
$this->addTitleLocalized('Edit Achievement conditions');
|
||||
$this->addTitle($seminary['title']);
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('achievement', $achievement);
|
||||
$this->set('conditions', $conditions);
|
||||
$this->set('characterFields', $characterFields);
|
||||
$this->set('questFields', $questFields);
|
||||
$this->set('quests', $quests);
|
||||
$this->set('achievementFields', $achievementFields);
|
||||
$this->set('achievements', $achievements);
|
||||
$this->set('deletes', $deletes);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: delete.
|
||||
*
|
||||
* Delete an Achievement.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param string $seminaryUrl URL-title of Seminary
|
||||
* @param string $achievementUrl URL-title of Achievement
|
||||
*/
|
||||
public function delete($seminaryUrl, $achievementUrl)
|
||||
{
|
||||
// Get seminary
|
||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||
|
||||
// Get Achievement
|
||||
$achievement = $this->Achievements->getAchievementByUrl($seminary['id'], $achievementUrl);
|
||||
|
||||
// Check request method
|
||||
if($this->request->getRequestMethod() == 'POST')
|
||||
{
|
||||
// Check confirmation
|
||||
if(!is_null($this->request->getPostParam('delete')))
|
||||
{
|
||||
// Delete seminary
|
||||
$this->Achievements->deleteAchievement($achievement['id']);
|
||||
}
|
||||
|
||||
// Redirect to entry
|
||||
$this->redirect($this->linker->link(array('manage', $seminary['url']), 1));
|
||||
}
|
||||
|
||||
|
||||
// Set titile
|
||||
$this->addTitleLocalized('Delete seminary');
|
||||
|
||||
// Show confirmation
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('achievement', $achievement);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@
|
|||
public function getAchievementByUrl($seminaryId, $achievementUrl)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT achievements.id, achievementconditions.condition, title, url, description, progress, unachieved_achievementsmedia_id, achieved_achievementsmedia_id '.
|
||||
'SELECT achievements.id, achievementconditions.condition, seminary_id, pos, title, url, description, progress, hidden, only_once, all_conditions, deadline, unachieved_achievementsmedia_id, achieved_achievementsmedia_id '.
|
||||
'FROM achievements '.
|
||||
'LEFT JOIN achievementconditions ON achievementconditions.id = achievements.achievementcondition_id '.
|
||||
'WHERE seminary_id = ? AND url = ?',
|
||||
|
|
@ -60,6 +60,31 @@
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get an Achievement by its ID.
|
||||
*
|
||||
* @param int $achievementId ID of Achievement
|
||||
* @return array Achievement data
|
||||
*/
|
||||
public function getAchievementById($achievementId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT achievements.id, achievementconditions.condition, seminary_id, pos, title, url, description, progress, hidden, only_once, all_conditions, deadline, unachieved_achievementsmedia_id, achieved_achievementsmedia_id '.
|
||||
'FROM achievements '.
|
||||
'LEFT JOIN achievementconditions ON achievementconditions.id = achievements.achievementcondition_id '.
|
||||
'WHERE achievements.id = ?',
|
||||
'i',
|
||||
$achievementId
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($achievementId);
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all not yet achieved Achievements for a Seminary that can
|
||||
* only be achieved once (only by one Character).
|
||||
|
|
@ -213,6 +238,25 @@
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all Achievements for a Seminary.
|
||||
*
|
||||
* @param int $seminaryId ID of Seminary
|
||||
* @return array List of Achievements
|
||||
*/
|
||||
public function getAchievementsForSeminary($seminaryId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, created, created_user_id, achievementcondition_id, pos, title, url, description, progress, hidden, only_once, all_conditions, deadline, unachieved_achievementsmedia_id, achieved_achievementsmedia_id '.
|
||||
'FROM achievements '.
|
||||
'WHERE seminary_id = ? '.
|
||||
'ORDER BY pos ASC',
|
||||
'i',
|
||||
$seminaryId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the rank for the number of achieved Achievements.
|
||||
*
|
||||
|
|
@ -254,7 +298,7 @@
|
|||
public function getAchievementConditionsDate($achievementId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT `select` '.
|
||||
'SELECT id, `select` '.
|
||||
'FROM achievementconditions_date '.
|
||||
'WHERE achievement_id = ?',
|
||||
'i',
|
||||
|
|
@ -283,6 +327,59 @@
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a new date condition.
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $achievementId ID of Achievement to add condition to
|
||||
* @param string $select SELECT-string for condition
|
||||
*/
|
||||
public function addAchievementConditionDate($userId, $achievementId, $select)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO achievementconditions_date '.
|
||||
'(created_user_id, achievement_id, `select`) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?)',
|
||||
'iis',
|
||||
$userId,
|
||||
$achievementId,
|
||||
$select
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Edit a date condition.
|
||||
*
|
||||
* @param int $conditionId ID of condition to edit
|
||||
* @param string $select New SELECT-string for condition
|
||||
*/
|
||||
public function editAchievementConditionDate($conditionId, $select)
|
||||
{
|
||||
$this->db->query(
|
||||
'UPDATE achievementconditions_date '.
|
||||
'SET `select` = ? '.
|
||||
'WHERE id = ?',
|
||||
'si',
|
||||
$select,
|
||||
$conditionId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a date condition.
|
||||
*
|
||||
* @param int $conditionId ID of condition to delete
|
||||
*/
|
||||
public function deleteAchievementConditionDate($conditionId)
|
||||
{
|
||||
$this->db->query('DELETE FROM achievementconditions_date WHERE id = ?', 'i', $conditionId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all Character conditions for an Achievement.
|
||||
*
|
||||
|
|
@ -292,7 +389,7 @@
|
|||
public function getAchievementConditionsCharacter($achievementId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT field, value '.
|
||||
'SELECT id, field, value '.
|
||||
'FROM achievementconditions_character '.
|
||||
'WHERE achievement_id = ?',
|
||||
'i',
|
||||
|
|
@ -374,6 +471,63 @@
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a new Character condition.
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $achievementId ID of Achievement to add condition to
|
||||
* @param string $field Field to match
|
||||
* @param string $value Value to match
|
||||
*/
|
||||
public function addAchievementConditionCharacter($userId, $achievementId, $field, $value)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO achievementconditions_character '.
|
||||
'(created_user_id, achievement_id, field, value) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?, ?)',
|
||||
'iiss',
|
||||
$userId,
|
||||
$achievementId,
|
||||
$field,
|
||||
$value
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Edit a Character condition.
|
||||
*
|
||||
* @param int $conditionId ID of condition to edit
|
||||
* @param string $field Field to match
|
||||
* @param string $value Value to match
|
||||
*/
|
||||
public function editAchievementConditionCharacter($conditionId, $field, $value)
|
||||
{
|
||||
$this->db->query(
|
||||
'UPDATE achievementconditions_character '.
|
||||
'SET field = ?, value = ? '.
|
||||
'WHERE id = ?',
|
||||
'ssi',
|
||||
$field,
|
||||
$value,
|
||||
$conditionId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a Character condition.
|
||||
*
|
||||
* @param int $conditionId ID of condition to delete
|
||||
*/
|
||||
public function deleteAchievementConditionCharacter($conditionId)
|
||||
{
|
||||
$this->db->query('DELETE FROM achievementconditions_character WHERE id = ?', 'i', $conditionId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all Quest conditions for an Achievement.
|
||||
*
|
||||
|
|
@ -383,7 +537,7 @@
|
|||
public function getAchievementConditionsQuest($achievementId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT field, `count`, value, quest_id, status, groupby '.
|
||||
'SELECT id, field, `count`, value, quest_id, status, groupby '.
|
||||
'FROM achievementconditions_quest '.
|
||||
'WHERE achievement_id = ?',
|
||||
'i',
|
||||
|
|
@ -478,6 +632,79 @@
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a new Quest condition.
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $achievementId ID of Achievement to add condition to
|
||||
* @param string $field Field to match
|
||||
* @param boolean $count Count the value
|
||||
* @param string $value Value to match
|
||||
* @param int $questId ID of Quest (optional)
|
||||
* @param int $status Quest status (optional)
|
||||
* @param string $groupby Field to group by (optional)
|
||||
*/
|
||||
public function addAchievementConditionQuest($userId, $achievementId, $field, $count, $value, $questId=null, $status=null, $groupby=null)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO achievementconditions_quest '.
|
||||
'(created_user_id, achievement_id, field, count, value, quest_id, status, groupby) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?, ?, ?, ?, ?, ?)',
|
||||
'iisisiis',
|
||||
$userId,
|
||||
$achievementId,
|
||||
$field,
|
||||
$count,
|
||||
$value,
|
||||
$questId,
|
||||
$status,
|
||||
$groupby
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Edit a Quest condition.
|
||||
*
|
||||
* @param int $conditionId ID of condition to edit
|
||||
* @param string $field Field to match
|
||||
* @param boolean $count Count the value
|
||||
* @param string $value Value to match
|
||||
* @param int $questId ID of Quest (optional)
|
||||
* @param int $status Quest status (optional)
|
||||
* @param string $groupby Field to group by (optional)
|
||||
*/
|
||||
public function editAchievementConditionQuest($conditionId, $field, $count, $value, $questId=null, $status=null, $groupby=null)
|
||||
{
|
||||
$this->db->query(
|
||||
'UPDATE achievementconditions_quest '.
|
||||
'SET field = ?, count = ?, value = ?, quest_id = ?, status = ?, groupby = ? '.
|
||||
'WHERE id = ?',
|
||||
'sisiisi',
|
||||
$field,
|
||||
$count,
|
||||
$value,
|
||||
$questId,
|
||||
$status,
|
||||
$groupby,
|
||||
$conditionId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a Quest condition.
|
||||
*
|
||||
* @param int $conditionId ID of condition to delete
|
||||
*/
|
||||
public function deleteAchievementConditionQuest($conditionId)
|
||||
{
|
||||
$this->db->query('DELETE FROM achievementconditions_quest WHERE id = ?', 'i', $conditionId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all Metaachievement conditions for an Achievement.
|
||||
*
|
||||
|
|
@ -487,7 +714,7 @@
|
|||
public function getAchievementConditionsAchievement($achievementId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT field, `count`, value, meta_achievement_id, groupby '.
|
||||
'SELECT id, field, `count`, value, meta_achievement_id, groupby '.
|
||||
'FROM achievementconditions_achievement '.
|
||||
'WHERE achievement_id = ?',
|
||||
'i',
|
||||
|
|
@ -578,6 +805,75 @@
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a new Achievement condition.
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $achievementId ID of Achievement to add condition to
|
||||
* @param string $field Field to match
|
||||
* @param boolean $count Count the value
|
||||
* @param string $value Value to match
|
||||
* @param int $metaAchievementId ID of Meta-Achievement (optional)
|
||||
* @param string $groupby Field to group by (optional)
|
||||
*/
|
||||
public function addAchievementConditionAchievement($userId, $achievementId, $field, $count, $value, $metaAchievementId=null, $groupby=null)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO achievementconditions_achievement '.
|
||||
'(created_user_id, achievement_id, field, count, value, meta_achievement_id, groupby) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?, ?, ?, ?, ?)',
|
||||
'iisisis',
|
||||
$userId,
|
||||
$achievementId,
|
||||
$field,
|
||||
$count,
|
||||
$value,
|
||||
$metaAchievementId,
|
||||
$groupby
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Edit a Achievement condition.
|
||||
*
|
||||
* @param int $conditionId ID of condition to edit
|
||||
* @param string $field Field to match
|
||||
* @param boolean $count Count the value
|
||||
* @param string $value Value to match
|
||||
* @param int $metaAchievementId ID of Achievement (optional)
|
||||
* @param string $groupby Field to group by (optional)
|
||||
*/
|
||||
public function editAchievementConditionAchievement($conditionId, $field, $count, $value, $metaAchievementId=null, $groupby=null)
|
||||
{
|
||||
$this->db->query(
|
||||
'UPDATE achievementconditions_achievement '.
|
||||
'SET field = ?, count = ?, value = ?, meta_achievement_id = ?, groupby = ? '.
|
||||
'WHERE id = ?',
|
||||
'sisisi',
|
||||
$field,
|
||||
$count,
|
||||
$value,
|
||||
$metaAchievementId,
|
||||
$groupby,
|
||||
$conditionId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a Achievement condition.
|
||||
*
|
||||
* @param int $conditionId ID of condition to delete
|
||||
*/
|
||||
public function deleteAchievementConditionAchievement($conditionId)
|
||||
{
|
||||
$this->db->query('DELETE FROM achievementconditions_achievement WHERE id = ?', 'i', $conditionId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set an Achievement as achieved for a Character.
|
||||
*
|
||||
|
|
@ -621,6 +917,232 @@
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all existing Achievements conditions.
|
||||
*
|
||||
* @return array List of Achievements conditions
|
||||
*/
|
||||
public function getAchievementsConditions()
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, created, `condition` '.
|
||||
'FROM achievementconditions'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if an Achievement title already exists.
|
||||
*
|
||||
* @param int $seminaryId ID of Seminary
|
||||
* @param string $title Achievement title to check
|
||||
* @param int $characterId Do not check this ID (for editing)
|
||||
* @return boolean Whether Achievement title exists or not
|
||||
*/
|
||||
public function achievementTitleExists($seminaryId, $title, $achievementId=null)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id '.
|
||||
'FROM achievements '.
|
||||
'WHERE seminary_id = ? AND (title = ? OR url = ?)',
|
||||
'iss',
|
||||
$seminaryId,
|
||||
$title,
|
||||
\nre\core\Linker::createLinkParam($title)
|
||||
);
|
||||
|
||||
|
||||
return (!empty($data) && (is_null($achievementId) || $achievementId != $data[0]['id']));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new Achievement for a Seminary.
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $seminaryId ID of Seminary
|
||||
* @param int $conditionId ID of Achievement condition
|
||||
* @param string $title Title of new Achievement
|
||||
* @param string $description Description of new Achievement
|
||||
* @param boolean $progress Show progress
|
||||
* @param boolean $hidden Secret Achievement
|
||||
* @param boolean $onlyOnce Only achieveable by one user
|
||||
* @param boolean $allConditions Achievement must match all conditions
|
||||
* @param string $deadline Deadline for Achievement
|
||||
* @return int ID of newly created Achievement
|
||||
*/
|
||||
public function createAchievement($userId, $seminaryId, $conditionId, $title, $description, $progress, $hidden, $onlyOnce, $allConditions, $deadline)
|
||||
{
|
||||
// Get position
|
||||
$pos = $this->db->query(
|
||||
'SELECT COALESCE(MAX(pos),0)+1 AS pos '.
|
||||
'FROM achievements '.
|
||||
'WHERE seminary_id = ?',
|
||||
'i',
|
||||
$seminaryId
|
||||
);
|
||||
$pos = $pos[0]['pos'];
|
||||
|
||||
// Create Achievement
|
||||
$this->db->query(
|
||||
'INSERT INTO achievements '.
|
||||
'(created_user_id, seminary_id, achievementcondition_id, pos, title, url, description, progress, hidden, only_once, all_conditions, deadline) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
|
||||
'iiiisssiiiis',
|
||||
$userId,
|
||||
$seminaryId,
|
||||
$conditionId,
|
||||
$pos,
|
||||
$title,
|
||||
\nre\core\Linker::createLinkParam($title),
|
||||
$description,
|
||||
$progress,
|
||||
$hidden,
|
||||
$onlyOnce,
|
||||
$allConditions,
|
||||
$deadline
|
||||
);
|
||||
|
||||
|
||||
// Return ID
|
||||
return $this->db->getInsertId();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Move an Achievement up (decrement position) or down
|
||||
* (increment position).
|
||||
*
|
||||
* @param array $achievement Achievement to move
|
||||
* @param boolean $up True for moving up, false for down
|
||||
*/
|
||||
public function moveAchievement($achievement, $up)
|
||||
{
|
||||
$this->db->setAutocommit(false);
|
||||
try {
|
||||
// Set temporary position
|
||||
$this->db->query(
|
||||
'UPDATE achievements '.
|
||||
'SET pos = 0 '.
|
||||
'WHERE id = ?',
|
||||
'i',
|
||||
$achievement['id']
|
||||
);
|
||||
// Switch entry
|
||||
$this->db->query(
|
||||
'UPDATE achievements '.
|
||||
'SET pos = ? '.
|
||||
'WHERE seminary_id = ? AND pos = ?',
|
||||
'iii',
|
||||
$achievement['pos'],
|
||||
$achievement['seminary_id'],
|
||||
$achievement['pos'] + ($up ? -1 : 1)
|
||||
);
|
||||
// Set new position
|
||||
$this->db->query(
|
||||
'UPDATE achievements '.
|
||||
'SET pos = ? '.
|
||||
'WHERE id = ?',
|
||||
'ii',
|
||||
$achievement['pos'] + ($up ? -1 : 1),
|
||||
$achievement['id']
|
||||
);
|
||||
|
||||
$this->db->commit();
|
||||
}
|
||||
catch(\nre\exceptions\DatamodelException $e) {
|
||||
$this->db->rollback();
|
||||
$this->db->setAutocommit(true);
|
||||
throw $e;
|
||||
}
|
||||
$this->db->setAutocommit(true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Edit an Achievement of a Seminary.
|
||||
*
|
||||
* @param int $achievementId ID of Achievement to edit
|
||||
* @param int $conditionId ID of Achievement condition
|
||||
* @param string $title New title of Achievement
|
||||
* @param string $description New description of Achievement
|
||||
* @param boolean $progress Show progress
|
||||
* @param boolean $hidden Secret Achievement
|
||||
* @param boolean $onlyOnce Only achieveable by one user
|
||||
* @param boolean $allConditions Achievement must match all conditions
|
||||
* @param string $deadline Deadline for Achievement
|
||||
*/
|
||||
public function editAchievement($achievementId, $conditionId, $title, $description, $progress, $hidden, $onlyOnce, $allConditions, $deadline)
|
||||
{
|
||||
$this->db->query(
|
||||
'UPDATE achievements '.
|
||||
'SET achievementcondition_id = ?, title = ?, url = ?, description = ?, progress = ?, hidden = ?, only_once = ?, all_conditions = ?, deadline = ? '.
|
||||
'WHERE id = ?',
|
||||
'isssiiiisi',
|
||||
$conditionId,
|
||||
$title,
|
||||
\nre\core\Linker::createLinkParam($title),
|
||||
$description,
|
||||
$progress,
|
||||
$hidden,
|
||||
$onlyOnce,
|
||||
$allConditions,
|
||||
$deadline,
|
||||
$achievementId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set unachieved media for an Achievement.
|
||||
*
|
||||
* @param int $achievementId ID of Achievement to set media for
|
||||
* @param int $achievementsmediaId ID of achievementsmedia to set
|
||||
*/
|
||||
public function setUnachievedMediaForAchievement($achievementId, $achievementsmediaId)
|
||||
{
|
||||
$this->db->query(
|
||||
'UPDATE achievements '.
|
||||
'SET unachieved_achievementsmedia_id = ? '.
|
||||
'WHERE id = ?',
|
||||
'ii',
|
||||
$achievementsmediaId,
|
||||
$achievementId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set achieved media for an Achievement.
|
||||
*
|
||||
* @param int $achievementId ID of Achievement to set media for
|
||||
* @param int $achievementsmediaId ID of achievementsmedia to set
|
||||
*/
|
||||
public function setAchievedMediaForAchievement($achievementId, $achievementsmediaId)
|
||||
{
|
||||
$this->db->query(
|
||||
'UPDATE achievements '.
|
||||
'SET achieved_achievementsmedia_id = ? '.
|
||||
'WHERE id = ?',
|
||||
'ii',
|
||||
$achievementsmediaId,
|
||||
$achievementId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete an Achievement.
|
||||
*
|
||||
* @param int $achievementId ID of Achievement to delete
|
||||
*/
|
||||
public function deleteAchievement($achievementId)
|
||||
{
|
||||
$this->db->query('DELETE FROM achievements WHERE id = ?', 'i', $achievementId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -339,6 +339,48 @@
|
|||
}
|
||||
|
||||
|
||||
public function createAchievementMedia($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 Achievements media
|
||||
$this->db->query(
|
||||
'INSERT INTO achievementsmedia '.
|
||||
'(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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
|||
152
views/html/achievements/conditions.tpl
Normal file
152
views/html/achievements/conditions.tpl
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
<?php if(!is_null($seminary['achievements_seminarymedia_id'])) : ?>
|
||||
<div class="moodpic">
|
||||
<img src="<?=$linker->link(array('media','seminarymoodpic',$seminary['url'], 'achievements'))?>">
|
||||
</div>
|
||||
<?php endif ?>
|
||||
<ul class="breadcrumbs">
|
||||
<li><a href="<?=$linker->link(array('seminaries',$seminary['url']))?>"><?=$seminary['title']?></a></li>
|
||||
<li><i class="fa fa-chevron-right fa-fw"></i><a href="<?=$linker->link(array('achievements','index',$seminary['url']))?>"><?=_('Achievements')?></a></li>
|
||||
</ul>
|
||||
|
||||
<h1><?=_('Edit Achievement conditions')?></h1>
|
||||
<form method="post">
|
||||
<fieldset>
|
||||
<legend><?=_('Conditions')?></legend>
|
||||
<ul>
|
||||
<?php foreach($conditions as &$condition) : ?>
|
||||
<li>
|
||||
<?php if($achievement['condition'] == 'date') : ?>
|
||||
<label for="condition-<?=$condition['id']?>-select"><?=_('Date')?>:</label>
|
||||
<input id="condition-<?=$condition['id']?>-select" type="text" name="conditions[<?=$condition['id']?>][select]" placeholder="SELECT" value="<?=$condition['select']?>" />
|
||||
<?php elseif($achievement['condition'] == 'character') : ?>
|
||||
<label for="condition-<?=$condition['id']?>-value"><?=_('Field')?>:</label>
|
||||
<select id="condition-<?=$condition['id']?>-field" name="conditions[<?=$condition['id']?>][field]">
|
||||
<?php foreach($characterFields as &$field) : ?>
|
||||
<option value="<?=$field?>" <?php if($condition['field'] == $field) : ?>selected="selected"<?php endif ?>><?=$field?></option>
|
||||
<?php endforeach ?>
|
||||
</select><br />
|
||||
<label for="condition-<?=$condition['id']?>-value"><?=_('Value')?>:</label>
|
||||
<input id="condition-<?=$condition['id']?>-value" type="text" name="conditions[<?=$condition['id']?>][value]" placeholder="<?=_('Value')?>" value="<?=$condition['value']?>" />
|
||||
<?php elseif($achievement['condition'] == 'quest') : ?>
|
||||
<label for="condition-<?=$condition['id']?>-value"><?=_('Field')?>:</label>
|
||||
<select id="condition-<?=$condition['id']?>-field" name="conditions[<?=$condition['id']?>][field]">
|
||||
<?php foreach($questFields as &$field) : ?>
|
||||
<option value="<?=$field?>" <?php if($condition['field'] == $field) : ?>selected="selected"<?php endif ?>><?=$field?></option>
|
||||
<?php endforeach ?>
|
||||
</select><br />
|
||||
<input id="condition-<?=$condition['id']?>-count" type="checkbox" name="conditions[<?=$condition['id']?>][count]" <?php if($condition['count']) : ?>checked="checked"<?php endif ?> />
|
||||
<label for="condition-<?=$condition['id']?>-count"><?=_('Count')?></label><br />
|
||||
<label for="condition-<?=$condition['id']?>-value"><?=_('Value')?>:</label>
|
||||
<input id="condition-<?=$condition['id']?>-value" type="text" name="conditions[<?=$condition['id']?>][value]" placeholder="<?=_('Value')?>" value="<?=$condition['value']?>" /><br />
|
||||
<label for="condition-<?=$condition['id']?>-quest"><?=_('Quest')?>:</label>
|
||||
<select id="condition-<?=$condition['id']?>-quest" name="conditions[<?=$condition['id']?>][quest]">
|
||||
<option value="" <?php if(is_null($condition['quest_id'])) : ?>selected="selected"<?php endif ?>><?=_('unset')?><option>
|
||||
<?php foreach($quests as &$quest) : ?>
|
||||
<option value="<?=$quest['url']?>" <?php if($condition['quest_id'] == $quest['id']) : ?>selected="selected"<?php endif ?>><?=$quest['title']?></option>
|
||||
<?php endforeach ?>
|
||||
</select><br />
|
||||
<label for="condition-<?=$condition['id']?>-status"><?=_('Status')?>:</label>
|
||||
<select id="condition-<?=$condition['id']?>-status" name="conditions[<?=$condition['id']?>][status]">
|
||||
<option value="" <?php if(is_null($condition['status'])) : ?>selected="selected"<?php endif ?>><?=_('unset')?></option>
|
||||
<option value="0" <?php if(!is_null($condition['status']) && $condition['status'] == 0) : ?>selected="selected"<?php endif ?>><?=_('entered')?></option>
|
||||
<option value="1" <?php if($condition['status'] == 1) : ?>selected="selected"<?php endif ?>><?=_('submitted')?></option>
|
||||
<option value="2" <?php if($condition['status'] == 2) : ?>selected="selected"<?php endif ?>><?=_('unsolved')?></option>
|
||||
<option value="3" <?php if($condition['status'] == 3) : ?>selected="selected"<?php endif ?>><?=_('solved')?></option>
|
||||
</select><br />
|
||||
<label for="condition-<?=$condition['id']?>-groupby"><?=_('Group by')?>:</label>
|
||||
<input id="condition-<?=$condition['id']?>-groupby" type="text" name="conditions[<?=$condition['id']?>][groupby]" placeholder="<?=_('Group by')?>" value="<?=$condition['groupby']?>" />
|
||||
<?php elseif($achievement['condition'] == 'achievement') : ?>
|
||||
<label for="condition-<?=$condition['id']?>-value"><?=_('Field')?>:</label>
|
||||
<select id="condition-<?=$condition['id']?>-field" name="conditions[<?=$condition['id']?>][field]">
|
||||
<?php foreach($achievementFields as &$field) : ?>
|
||||
<option value="<?=$field?>" <?php if($condition['field'] == $field) : ?>selected="selected"<?php endif ?>><?=$field?></option>
|
||||
<?php endforeach ?>
|
||||
</select><br />
|
||||
<input id="condition-<?=$condition['id']?>-count" type="checkbox" name="conditions[<?=$condition['id']?>][count]" <?php if($condition['count']) : ?>checked="checked"<?php endif ?> />
|
||||
<label for="condition-<?=$condition['id']?>-count"><?=_('Count')?></label><br />
|
||||
<label for="condition-<?=$condition['id']?>-value"><?=_('Value')?>:</label>
|
||||
<input id="condition-<?=$condition['id']?>-value" type="text" name="conditions[<?=$condition['id']?>][value]" placeholder="<?=_('Value')?>" value="<?=$condition['value']?>" /><br />
|
||||
<label for="condition-<?=$condition['id']?>-achievement"><?=_('Achievement')?>:</label>
|
||||
<select id="condition-<?=$condition['id']?>-achievement" name="conditions[<?=$condition['id']?>][achievement]">
|
||||
<option value="" <?php if(is_null($condition['meta_achievement_id'])) : ?>selected="selected"<?php endif ?>><?=_('unset')?><option>
|
||||
<?php foreach($achievements as &$a) : ?>
|
||||
<option value="<?=$a['url']?>" <?php if($condition['meta_achievement_id'] == $a['id']) : ?>selected="selected"<?php endif ?>><?=$a['title']?></option>
|
||||
<?php endforeach ?>
|
||||
</select><br />
|
||||
<label for="condition-<?=$condition['id']?>-groupby"><?=_('Group by')?>:</label>
|
||||
<input id="condition-<?=$condition['id']?>-groupby" type="text" name="conditions[<?=$condition['id']?>][groupby]" placeholder="<?=_('Group by')?>" value="<?=$condition['groupby']?>" />
|
||||
<?php endif ?>
|
||||
<br />
|
||||
<input id="delete-<?=$condition['id']?>" type="checkbox" name="deletes[<?=$condition['id']?>]" <?php if(array_key_exists($condition['id'], $deletes)) : ?>checked="checked"<?php endif ?> />
|
||||
<label for="delete-<?=$condition['id']?>"><?=_('delete')?></label>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
<li>
|
||||
<?php if($achievement['condition'] == 'date') : ?>
|
||||
<label for="condition-new-select"><?=_('Date')?>:</label>
|
||||
<input id="condition-new-select" type="text" name="conditions[new][select]" placeholder="<?=_('New condition')?>" value="" />
|
||||
<?php elseif($achievement['condition'] == 'character') : ?>
|
||||
<label for="condition-new-field"><?=_('Field')?>:</label>
|
||||
<select id="condition-new-field" name="conditions[new][field]">
|
||||
<?php foreach($characterFields as &$field) : ?>
|
||||
<option value="<?=$field?>"><?=$field?></option>
|
||||
<?php endforeach ?>
|
||||
</select><br />
|
||||
<label for="condition-new-value"><?=_('Value')?>:</label>
|
||||
<input id="condition-new-value" type="text" name="conditions[new][value]" placeholder="<?=_('New condition')?>" value="" />
|
||||
<?php elseif($achievement['condition'] == 'quest') : ?>
|
||||
<label for="condition-new-field"><?=_('Field')?>:</label>
|
||||
<select id="condition-new-field" name="conditions[new][field]">
|
||||
<?php foreach($questFields as &$field) : ?>
|
||||
<option value="<?=$field?>"><?=$field?></option>
|
||||
<?php endforeach ?>
|
||||
</select><br />
|
||||
<input id="condition-new-count" type="checkbox" name="conditions[new][count]" />
|
||||
<label for="condition-new-count"><?=_('Count')?></label><br />
|
||||
<label for="condition-value"><?=_('Value')?>:</label>
|
||||
<input id="condition-new-value" type="number" name="conditions[new][value]" placeholder="<?=_('Value')?>" value="" /><br />
|
||||
<label for="condition-new-quest"><?=_('Quest')?>:</label>
|
||||
<select id="condition-new-quest" name="conditions[new][quest]">
|
||||
<option value=""><?=_('unset')?><option>
|
||||
<?php foreach($quests as &$quest) : ?>
|
||||
<option value="<?=$quest['url']?>"><?=$quest['title']?></option>
|
||||
<?php endforeach ?>
|
||||
</select><br />
|
||||
<label for="condition-new-status"><?=_('Status')?>:</label>
|
||||
<select id="condition-new-status" name="conditions[new][status]">
|
||||
<option value=""><?=_('unset')?></option>
|
||||
<option value="0"><?=_('entered')?></option>
|
||||
<option value="1"><?=_('submitted')?></option>
|
||||
<option value="2"><?=_('unsolved')?></option>
|
||||
<option value="3"><?=_('solved')?></option>
|
||||
</select><br />
|
||||
<label for="condition-new-groupby"><?=_('Group by')?>:</label>
|
||||
<input id="condition-new-groupby" type="text" name="conditions[new][groupby]" placeholder="<?=_('Group by')?>" value="" />
|
||||
<?php elseif($achievement['condition'] == 'achievement') : ?>
|
||||
<label for="condition-new-field"><?=_('Field')?>:</label>
|
||||
<select id="condition-new-field" name="conditions[new][field]">
|
||||
<?php foreach($achievementFields as &$field) : ?>
|
||||
<option value="<?=$field?>"><?=$field?></option>
|
||||
<?php endforeach ?>
|
||||
</select><br />
|
||||
<input id="condition-new-count" type="checkbox" name="conditions[new][count]" />
|
||||
<label for="condition-new-count"><?=_('Count')?></label><br />
|
||||
<label for="condition-new-value"><?=_('Value')?>:</label>
|
||||
<input id="condition-new-value" type="number" name="conditions[new][value]" placeholder="<?=_('Value')?>" value="" /><br />
|
||||
<label for="condition-new-achievement"><?=_('Achievement')?>:</label>
|
||||
<select id="condition-new-achievement" name="conditions[new][achievement]">
|
||||
<option value=""><?=_('unset')?><option>
|
||||
<?php foreach($achievements as &$a) : ?>
|
||||
<option value="<?=$a['url']?>"><?=$a['title']?></option>
|
||||
<?php endforeach ?>
|
||||
</select><br />
|
||||
<label for="condition-new-groupby"><?=_('Group by')?>:</label>
|
||||
<input id="condition-new-groupby" type="text" name="conditions[new][groupby]" placeholder="<?=_('Group by')?>" value="" />
|
||||
<?php else : ?>
|
||||
hallo
|
||||
<?php endif ?>
|
||||
</li>
|
||||
</ul>
|
||||
</fieldset>
|
||||
<input type="submit" name="edit" value="<?=_('save')?>" />
|
||||
</form>
|
||||
110
views/html/achievements/create.tpl
Normal file
110
views/html/achievements/create.tpl
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
<?php if(!is_null($seminary['achievements_seminarymedia_id'])) : ?>
|
||||
<div class="moodpic">
|
||||
<img src="<?=$linker->link(array('media','seminarymoodpic',$seminary['url'], 'achievements'))?>">
|
||||
</div>
|
||||
<?php endif ?>
|
||||
<ul class="breadcrumbs">
|
||||
<li><a href="<?=$linker->link(array('seminaries',$seminary['url']))?>"><?=$seminary['title']?></a></li>
|
||||
<li><i class="fa fa-chevron-right fa-fw"></i><a href="<?=$linker->link(array('achievements','index',$seminary['url']))?>"><?=_('Achievements')?></a></li>
|
||||
</ul>
|
||||
|
||||
<h1><?=_('Create Achievement')?></h1>
|
||||
<?php if($validation !== true) : ?>
|
||||
<ul>
|
||||
<?php foreach($validation as $field => &$settings) : ?>
|
||||
<li>
|
||||
<ul>
|
||||
<?php foreach($settings as $setting => $value) : ?>
|
||||
<li>
|
||||
<?php switch($field) {
|
||||
case 'media':
|
||||
switch($setting) {
|
||||
case 'error': printf(_('Error during picture upload: %s'), $value);
|
||||
break;
|
||||
case 'mimetype': printf(_('Picture has wrong type “%s”'), $value);
|
||||
break;
|
||||
case 'size': echo _('Picture exceeds size maximum');
|
||||
break;
|
||||
default: echo _('Picture invalid');
|
||||
}
|
||||
break;
|
||||
case 'title':
|
||||
switch($setting) {
|
||||
case 'minlength': printf(_('Title is too short (min. %d chars)'), $value);
|
||||
break;
|
||||
case 'maxlength': printf(_('Title is too long (max. %d chars)'), $value);
|
||||
break;
|
||||
case 'regex': echo _('Title contains illegal characters');
|
||||
break;
|
||||
case 'exist': echo _('Title already exists');
|
||||
break;
|
||||
default: echo _('Title invalid');
|
||||
}
|
||||
break;
|
||||
case 'deadline':
|
||||
switch($setting) {
|
||||
case 'regex': echo _('Deadline has wrong format');
|
||||
break;
|
||||
default: echo _('Deadline invalid');
|
||||
}
|
||||
break;
|
||||
} ?>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
<?php endif ?>
|
||||
<form method="post" class="logreg" enctype="multipart/form-data">
|
||||
<fieldset>
|
||||
<legend><?=_('Images')?></legend>
|
||||
<label for="unachievedImage"><?=_('Unachieved')?></label>
|
||||
<input id="unachievedImage" type="file" name="unachieved_image" accept="<?=implode(',', array_map(function($m) { return $m['mimetype']; }, $mimetypes))?>" /><br />
|
||||
<label for="achievedImage"><?=_('Achieved')?></label>
|
||||
<input id="achievedImage" type="file" name="achieved_image" accept="<?=implode(',', array_map(function($m) { return $m['mimetype']; }, $mimetypes))?>" /><br />
|
||||
<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>
|
||||
<label for="title"><?=_('Title')?>:</label>
|
||||
<input id="title" type="text" name="title" placeholder="<?=_('Title')?>" required="required" maxlength="<?=$validationSettings['title']['maxlength']?>" value="<?=$title?>" <?=(array_key_exists('title', $validation)) ? 'class="invalid"' : null?> /><br />
|
||||
<label for="description"><?=_('Description')?>:</label>
|
||||
<textarea id="description" name="description"><?=$description?></textarea><br />
|
||||
<input id="progress" type="checkbox" name="progress" <?php if($progress) : ?>checked="checked"<?php endif ?> />
|
||||
<label for="progress"><?=_('Show progress')?></label><br />
|
||||
<input id="hidden" type="checkbox" name="hidden" <?php if($hidden) : ?>checked="checked"<?php endif ?> />
|
||||
<label for="hidden"><?=_('Secret Achievement')?></label><br />
|
||||
<input id="onlyOnce" type="checkbox" name="only_once" <?php if($onlyOnce) : ?>checked="checked"<?php endif ?> />
|
||||
<label for="onlyOnce"><?=_('Only achieveable by one Character')?></label><br />
|
||||
<input id="allConditions" type="checkbox" name="all_conditions" <?php if($allConditions) : ?>checked="checked"<?php endif ?> />
|
||||
<label for="allConditions"><?=_('All conditions')?></label><br />
|
||||
<label for="deadline"><?=_('Deadline')?>:</label>
|
||||
<input id="deadline" type="datetime" name="deadline" placeholder="YYYY-MM-DD HH:MM:SS" pattern="<?=substr($validationSettings['deadline']['regex'],1,strrpos($validationSettings['deadline']['regex'],$validationSettings['deadline']['regex'][0])-1)?>" value="<?=$deadline?>" <?=(array_key_exists('deadline', $validation)) ? 'class="invalid"' : null?> />
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend><?=_('Conditions')?></legend>
|
||||
<select name="condition">
|
||||
<?php foreach($conditions as &$c) : ?>
|
||||
<option value="<?=$c['condition']?>" <?php if($c['condition'] == $condition) : ?>selected="selected"<?php endif ?>>
|
||||
<?php switch($c['condition']) {
|
||||
case 'date': echo _('Achievement conditions date');
|
||||
break;
|
||||
case 'character': echo _('Achievement conditions Character');
|
||||
break;
|
||||
case 'quest': echo _('Achievement conditions Quest');
|
||||
break;
|
||||
case 'achievement': echo _('Achievement conditions Achievement');
|
||||
break;
|
||||
} ?>
|
||||
</option>
|
||||
<?php endforeach ?>
|
||||
</select>
|
||||
</fieldset>
|
||||
<input type="submit" name="edit-conditions" value="<?=_('edit conditions')?>" />
|
||||
<input type="submit" name="edit" value="<?=_('save')?>" />
|
||||
</form>
|
||||
16
views/html/achievements/delete.tpl
Normal file
16
views/html/achievements/delete.tpl
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<?php if(!is_null($seminary['achievements_seminarymedia_id'])) : ?>
|
||||
<div class="moodpic">
|
||||
<img src="<?=$linker->link(array('media','seminarymoodpic',$seminary['url'], 'achievements'))?>">
|
||||
</div>
|
||||
<?php endif ?>
|
||||
<ul class="breadcrumbs">
|
||||
<li><a href="<?=$linker->link(array('seminaries',$seminary['url']))?>"><?=$seminary['title']?></a></li>
|
||||
<li><i class="fa fa-chevron-right fa-fw"></i><a href="<?=$linker->link(array('achievements','index',$seminary['url']))?>"><?=_('Achievements')?></a></li>
|
||||
</ul>
|
||||
|
||||
<h1><?=_('Delete Achievement')?></h1>
|
||||
<?=sprintf(_('Should the Achievement “%s” really be deleted?'), $achievement['title'])?>
|
||||
<form method="post">
|
||||
<input type="submit" name="delete" value="<?=_('delete')?>" />
|
||||
<input type="submit" name="not-delete" value="<?=_('cancel')?>" />
|
||||
</form>
|
||||
113
views/html/achievements/edit.tpl
Normal file
113
views/html/achievements/edit.tpl
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
<?php if(!is_null($seminary['achievements_seminarymedia_id'])) : ?>
|
||||
<div class="moodpic">
|
||||
<img src="<?=$linker->link(array('media','seminarymoodpic',$seminary['url'], 'achievements'))?>">
|
||||
</div>
|
||||
<?php endif ?>
|
||||
<ul class="breadcrumbs">
|
||||
<li><a href="<?=$linker->link(array('seminaries',$seminary['url']))?>"><?=$seminary['title']?></a></li>
|
||||
<li><i class="fa fa-chevron-right fa-fw"></i><a href="<?=$linker->link(array('achievements','index',$seminary['url']))?>"><?=_('Achievements')?></a></li>
|
||||
</ul>
|
||||
|
||||
<h1><?=_('Edit Achievement')?></h1>
|
||||
<?php if($validation !== true) : ?>
|
||||
<ul>
|
||||
<?php foreach($validation as $field => &$settings) : ?>
|
||||
<li>
|
||||
<ul>
|
||||
<?php foreach($settings as $setting => $value) : ?>
|
||||
<li>
|
||||
<?php switch($field) {
|
||||
case 'media':
|
||||
switch($setting) {
|
||||
case 'error': printf(_('Error during picture upload: %s'), $value);
|
||||
break;
|
||||
case 'mimetype': printf(_('Picture has wrong type “%s”'), $value);
|
||||
break;
|
||||
case 'size': echo _('Picture exceeds size maximum');
|
||||
break;
|
||||
default: echo _('Picture invalid');
|
||||
}
|
||||
break;
|
||||
case 'title':
|
||||
switch($setting) {
|
||||
case 'minlength': printf(_('Title is too short (min. %d chars)'), $value);
|
||||
break;
|
||||
case 'maxlength': printf(_('Title is too long (max. %d chars)'), $value);
|
||||
break;
|
||||
case 'regex': echo _('Title contains illegal characters');
|
||||
break;
|
||||
case 'exist': echo _('Title already exists');
|
||||
break;
|
||||
default: echo _('Title invalid');
|
||||
}
|
||||
break;
|
||||
case 'deadline':
|
||||
switch($setting) {
|
||||
case 'regex': echo _('Deadline has wrong format');
|
||||
break;
|
||||
default: echo _('Deadline invalid');
|
||||
}
|
||||
break;
|
||||
} ?>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
<?php endif ?>
|
||||
<form method="post" class="logreg" enctype="multipart/form-data">
|
||||
<fieldset>
|
||||
<legend><?=_('Images')?></legend>
|
||||
<img src="<?=$linker->link(array('media','achievement',$seminary['url'],$achievement['url'],'locked'))?>" />
|
||||
<label for="unachievedImage"><?=_('Unachieved')?></label>
|
||||
<input id="unachievedImage" type="file" name="unachieved_image" accept="<?=implode(',', array_map(function($m) { return $m['mimetype']; }, $mimetypes))?>" /><br />
|
||||
<img src="<?=$linker->link(array('media','achievement',$seminary['url'],$achievement['url']))?>" />
|
||||
<label for="achievedImage"><?=_('Achieved')?></label>
|
||||
<input id="achievedImage" type="file" name="achieved_image" accept="<?=implode(',', array_map(function($m) { return $m['mimetype']; }, $mimetypes))?>" /><br />
|
||||
<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>
|
||||
<label for="title"><?=_('Title')?>:</label>
|
||||
<input id="title" type="text" name="title" placeholder="<?=_('Title')?>" required="required" maxlength="<?=$validationSettings['title']['maxlength']?>" value="<?=$title?>" <?=(array_key_exists('title', $validation)) ? 'class="invalid"' : null?> /><br />
|
||||
<label for="description"><?=_('Description')?>:</label>
|
||||
<textarea id="description" name="description"><?=$description?></textarea><br />
|
||||
<input id="progress" type="checkbox" name="progress" <?php if($progress) : ?>checked="checked"<?php endif ?> />
|
||||
<label for="progress"><?=_('Show progress')?></label><br />
|
||||
<input id="hidden" type="checkbox" name="hidden" <?php if($hidden) : ?>checked="checked"<?php endif ?> />
|
||||
<label for="hidden"><?=_('Secret Achievement')?></label><br />
|
||||
<input id="onlyOnce" type="checkbox" name="only_once" <?php if($onlyOnce) : ?>checked="checked"<?php endif ?> />
|
||||
<label for="onlyOnce"><?=_('Only achieveable by one Character')?></label><br />
|
||||
<input id="allConditions" type="checkbox" name="all_conditions" <?php if($allConditions) : ?>checked="checked"<?php endif ?> />
|
||||
<label for="allConditions"><?=_('All conditions')?></label><br />
|
||||
<label for="deadline"><?=_('Deadline')?>:</label>
|
||||
<input id="deadline" type="datetime" name="deadline" placeholder="YYYY-MM-DD HH:MM:SS" pattern="<?=substr($validationSettings['deadline']['regex'],1,strrpos($validationSettings['deadline']['regex'],$validationSettings['deadline']['regex'][0])-1)?>" value="<?=$deadline?>" <?=(array_key_exists('deadline', $validation)) ? 'class="invalid"' : null?> />
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend><?=_('Condition')?></legend>
|
||||
<select name="condition">
|
||||
<?php foreach($conditions as &$c) : ?>
|
||||
<option value="<?=$c['condition']?>" <?php if($c['condition'] == $condition) : ?>selected="selected"<?php endif ?>>
|
||||
<?php switch($c['condition']) {
|
||||
case 'date': echo _('Achievement conditions date');
|
||||
break;
|
||||
case 'character': echo _('Achievement conditions Character');
|
||||
break;
|
||||
case 'quest': echo _('Achievement conditions Quest');
|
||||
break;
|
||||
case 'achievement': echo _('Achievement conditions Achievement');
|
||||
break;
|
||||
} ?>
|
||||
</option>
|
||||
<?php endforeach ?>
|
||||
</select>
|
||||
<i><?=_('Changing the condition will delete all current conditions')?>.</i>
|
||||
</fieldset>
|
||||
<input type="submit" name="edit-conditions" value="<?=_('edit conditions')?>" />
|
||||
<input type="submit" name="edit" value="<?=_('save')?>" />
|
||||
</form>
|
||||
|
|
@ -6,6 +6,13 @@
|
|||
<ul class="breadcrumbs">
|
||||
<li><a href="<?=$linker->link(array('seminaries',$seminary['url']))?>"><?=$seminary['title']?></a></li>
|
||||
</ul>
|
||||
<?php if(count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\SeminaryController::$character['characterroles'])) > 0) : ?>
|
||||
<nav class="admin">
|
||||
<li><a href="<?=$linker->link('create', 3)?>"><?=_('Create new Achievement')?></a></li>
|
||||
<li><a href="<?=$linker->link('manage', 3)?>"><?=_('Manage Achievements')?></a></li>
|
||||
</nav>
|
||||
<?php endif ?>
|
||||
|
||||
<h1><i class="fa fa-trophy fa-fw"></i><?=_('Achievements')?></h1>
|
||||
<p><?=_('Achievement description')?></p>
|
||||
<div class="cf">
|
||||
|
|
|
|||
28
views/html/achievements/manage.tpl
Normal file
28
views/html/achievements/manage.tpl
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<?php if(!is_null($seminary['achievements_seminarymedia_id'])) : ?>
|
||||
<div class="moodpic">
|
||||
<img src="<?=$linker->link(array('media','seminarymoodpic',$seminary['url'], 'achievements'))?>">
|
||||
</div>
|
||||
<?php endif ?>
|
||||
<ul class="breadcrumbs">
|
||||
<li><a href="<?=$linker->link(array('seminaries',$seminary['url']))?>"><?=$seminary['title']?></a></li>
|
||||
<li><i class="fa fa-chevron-right fa-fw"></i><a href="<?=$linker->link(array('achievements','index',$seminary['url']))?>"><?=_('Achievements')?></a></li>
|
||||
</ul>
|
||||
|
||||
<h1><i class="fa fa-trophy fa-fw"></i><?=_('Manage Achievements')?></h1>
|
||||
<ul class="achmnts">
|
||||
<?php foreach($achievements as $index => &$achievement) : ?>
|
||||
<li class="cf">
|
||||
<?php if(!is_null($achievement['achieved_achievementsmedia_id'])) : ?>
|
||||
<img src="<?=$linker->link(array('media','achievement',$seminary['url'],$achievement['url']))?>" />
|
||||
<?php endif ?>
|
||||
<h3 id="<?=$achievement['url']?>"><?=$achievement['title']?></h3>
|
||||
<p class="desc"><?=\hhu\z\Utils::t($achievement['description'])?></p>
|
||||
<ul class="admin">
|
||||
<?php if($index > 0) : ?><li><a href="<?=$linker->link(array('moveup',$seminary['url'],$achievement['url']),1)?>">↑</a></li><?php endif ?>
|
||||
<?php if($index < count($achievements)-1) : ?><li><a href="<?=$linker->link(array('movedown',$seminary['url'],$achievement['url']),1)?>">↓</a></li><?php endif ?>
|
||||
<li><a href="<?=$linker->link(array('edit',$seminary['url'],$achievement['url']),1)?>"><?=_('edit')?></a></li>
|
||||
<li><a href="<?=$linker->link(array('delete',$seminary['url'],$achievement['url']),1)?>"><?=_('delete')?></a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<?php endforeach?>
|
||||
</ul>
|
||||
0
views/html/achievements/movedown.tpl
Normal file
0
views/html/achievements/movedown.tpl
Normal file
0
views/html/achievements/moveup.tpl
Normal file
0
views/html/achievements/moveup.tpl
Normal file
Loading…
Add table
Add a link
Reference in a new issue