implement Achievements
This commit is contained in:
parent
632382844a
commit
2437f331aa
11 changed files with 914 additions and 39 deletions
35
agents/intermediate/AchievementsAgent.inc
Normal file
35
agents/intermediate/AchievementsAgent.inc
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* The Legend of Z
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
* @copyright 2014 Heinrich-Heine-Universität Düsseldorf
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link https://bitbucket.org/coderkun/the-legend-of-z
|
||||
*/
|
||||
|
||||
namespace hhu\z\agents\intermediate;
|
||||
|
||||
|
||||
/**
|
||||
* Agent to list Achievements.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class AchievementsAgent extends \nre\agents\IntermediateAgent
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Action: index.
|
||||
*/
|
||||
public function index(\nre\core\Request $request, \nre\core\Response $response)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -73,6 +73,9 @@
|
|||
|
||||
// Check permissions
|
||||
$this->checkPermission($request, $response);
|
||||
|
||||
// Check achievements
|
||||
$this->checkAchievements($request, $response);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -131,6 +134,137 @@
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check for newly achieved Achievements.
|
||||
*/
|
||||
private function checkAchievements(\nre\core\Request $request, \nre\core\Response $response)
|
||||
{
|
||||
// Get Seminary
|
||||
$seminary = self::$seminary;
|
||||
|
||||
// Get Character
|
||||
$character = self::$character;
|
||||
|
||||
// Get unachieved Achievments
|
||||
$achievements = array_merge(
|
||||
$this->Achievements->getUnachhievedAchievementsForCharacter($seminary['id'], $character['id']),
|
||||
$this->Achievements->getUnachievedOnlyOnceAchievementsForSeminary($seminary['id'])
|
||||
);
|
||||
|
||||
// Check conditions
|
||||
foreach($achievements as &$achievement)
|
||||
{
|
||||
// Get conditions
|
||||
$conditions = array();
|
||||
$progress = 0;
|
||||
switch($achievement['condition'])
|
||||
{
|
||||
// Date conditions
|
||||
case 'date':
|
||||
$conditionsDate = $this->Achievements->getAchievementConditionsDate($achievement['id']);
|
||||
foreach($conditionsDate as &$condition)
|
||||
{
|
||||
$conditions[] = array(
|
||||
'func' => 'checkAchievementConditionDate',
|
||||
'params' => array(
|
||||
$condition['select']
|
||||
)
|
||||
);
|
||||
}
|
||||
break;
|
||||
// Character conditions
|
||||
case 'character':
|
||||
$conditionsCharacter = $this->Achievements->getAchievementConditionsCharacter($achievement['id']);
|
||||
foreach($conditionsCharacter as &$condition)
|
||||
{
|
||||
$conditions[] = array(
|
||||
'func' => 'checkAchievementConditionCharacter',
|
||||
'params' => array(
|
||||
$condition['field'],
|
||||
$condition['value'],
|
||||
$character['id']
|
||||
)
|
||||
);
|
||||
}
|
||||
break;
|
||||
// Quest conditions
|
||||
case 'quest':
|
||||
$conditionsQuest = $this->Achievements->getAchievementConditionsQuest($achievement['id']);
|
||||
foreach($conditionsQuest as &$condition)
|
||||
{
|
||||
$conditions[] = array(
|
||||
'func' => 'checkAchievementConditionQuest',
|
||||
'params' => array(
|
||||
$condition['field'],
|
||||
$condition['count'],
|
||||
$condition['value'],
|
||||
$condition['status'],
|
||||
$condition['groupby'],
|
||||
$condition['quest_id'],
|
||||
$character['id']
|
||||
)
|
||||
);
|
||||
}
|
||||
break;
|
||||
// Achievement conditions
|
||||
case 'achievement':
|
||||
$conditionsAchievement = $this->Achievements->getAchievementConditionsAchievement($achievement['id']);
|
||||
foreach($conditionsAchievement as &$condition)
|
||||
{
|
||||
$conditions[] = array(
|
||||
'func' => 'checkAchievementConditionAchievement',
|
||||
'params' => array(
|
||||
$condition['field'],
|
||||
$condition['count'],
|
||||
$condition['value'],
|
||||
$condition['groupby'],
|
||||
$condition['meta_achievement_id'],
|
||||
$character['id']
|
||||
)
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Check conditions
|
||||
$achieved = ($achievement['all_conditions'] == 1);
|
||||
foreach($conditions as &$condition)
|
||||
{
|
||||
// Calculate result of condition
|
||||
$result = call_user_func_array(
|
||||
array(
|
||||
$this->Achievements,
|
||||
$condition['func']
|
||||
),
|
||||
$condition['params']
|
||||
);
|
||||
|
||||
// The overall result and abort if possible
|
||||
if($achievement['all_conditions'])
|
||||
{
|
||||
if(!$result) {
|
||||
$achieved = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if($result) {
|
||||
$achieved = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Set status
|
||||
if($achieved) {
|
||||
$this->Achievements->setAchievementAchieved($achievement['id'], $character['id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
162
controllers/AchievementsController.inc
Normal file
162
controllers/AchievementsController.inc
Normal file
|
|
@ -0,0 +1,162 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* The Legend of Z
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
* @copyright 2014 Heinrich-Heine-Universität Düsseldorf
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link https://bitbucket.org/coderkun/the-legend-of-z
|
||||
*/
|
||||
|
||||
namespace hhu\z\controllers;
|
||||
|
||||
|
||||
/**
|
||||
* Controller of the Agent to list Achievements.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class AchievementsController extends \hhu\z\controllers\SeminaryRoleController
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('achievements', 'seminaries', 'media');
|
||||
/**
|
||||
* User permissions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $permissions = array(
|
||||
'index' => array('admin', 'moderator', 'user')
|
||||
);
|
||||
/**
|
||||
* User seminary permissions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $seminaryPermissions = array(
|
||||
'index' => array('admin', 'moderator', 'user')
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Action: index.
|
||||
*
|
||||
* List Achievements of a Seminary.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param string $seminaryUrl URL-Title of Seminary
|
||||
*/
|
||||
public function index($seminaryUrl)
|
||||
{
|
||||
// Get Seminary
|
||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||
|
||||
// Get Character
|
||||
$character = IntermediateController::$character;
|
||||
|
||||
// Get Achievements
|
||||
$achievements = $this->Achievements->getAchievementsForSeminary($seminary['id']);
|
||||
foreach($achievements as &$achievement)
|
||||
{
|
||||
// Get status for Character
|
||||
$achieved = $this->Achievements->hasCharacterAchievedAchievement($achievement['id'], $character['id']);
|
||||
|
||||
// Get Character progress
|
||||
if(!$achieved && $achievement['progress'])
|
||||
{
|
||||
$conditions = array();
|
||||
switch($achievement['condition'])
|
||||
{
|
||||
// Character conditions
|
||||
case 'character':
|
||||
$conditionsCharacter = $this->Achievements->getAchievementConditionsCharacter($achievement['id']);
|
||||
foreach($conditionsCharacter as &$condition)
|
||||
{
|
||||
$conditions[] = array(
|
||||
'func' => 'getAchievementConditionCharacterProgress',
|
||||
'params' => array(
|
||||
$condition['field'],
|
||||
$condition['value'],
|
||||
$character['id']
|
||||
)
|
||||
);
|
||||
}
|
||||
break;
|
||||
// Quest conditions
|
||||
case 'quest':
|
||||
$conditionsQuest = $this->Achievements->getAchievementConditionsQuest($achievement['id']);
|
||||
foreach($conditionsQuest as &$condition)
|
||||
{
|
||||
$conditions[] = array(
|
||||
'func' => 'getAchievementConditionQuestProgress',
|
||||
'params' => array(
|
||||
$condition['field'],
|
||||
$condition['count'],
|
||||
$condition['value'],
|
||||
$condition['status'],
|
||||
$condition['groupby'],
|
||||
$condition['quest_id'],
|
||||
$character['id']
|
||||
)
|
||||
);
|
||||
}
|
||||
break;
|
||||
// Achievement conditions
|
||||
case 'achievement':
|
||||
$conditionsAchievement = $this->Achievements->getAchievementConditionsAchievement($achievement['id']);
|
||||
foreach($conditionsAchievement as &$condition)
|
||||
{
|
||||
$conditions[] = array(
|
||||
'func' => 'getAchievementConditionAchievementProgress',
|
||||
'params' => array(
|
||||
$condition['field'],
|
||||
$condition['count'],
|
||||
$condition['value'],
|
||||
$condition['groupby'],
|
||||
$condition['meta_achievement_id'],
|
||||
$character['id']
|
||||
)
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
$characterProgresses = array();
|
||||
foreach($conditions as &$condition)
|
||||
{
|
||||
// Calculate progress of condition
|
||||
$characterProgresses[] = call_user_func_array(
|
||||
array(
|
||||
$this->Achievements,
|
||||
$condition['func']
|
||||
),
|
||||
$condition['params']
|
||||
);
|
||||
}
|
||||
|
||||
$achievement['characterProgress'] = array_sum($characterProgresses) / count($characterProgresses);
|
||||
}
|
||||
|
||||
// Get media
|
||||
$achievement['media_index'] = 'unachieved_achievementsmedia_id';
|
||||
if($achieved) {
|
||||
$achievement['media_index'] = 'achieved_achievementsmedia_id';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('achievements', $achievements);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -120,6 +120,9 @@
|
|||
// Get Character groups
|
||||
$groups = $this->Charactergroups->getGroupsForCharacter($character['id']);
|
||||
|
||||
// Get Achievements
|
||||
$achievements = $this->Achievements->getAchievedAchievementsForCharacter($character['id']);
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
|
|
@ -127,6 +130,7 @@
|
|||
$this->set('characterfields', $characterfields);
|
||||
$this->set('user', $user);
|
||||
$this->set('groups', $groups);
|
||||
$this->set('achievements', $achievements);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@
|
|||
'index' => array('admin', 'moderator', 'user', 'guest'),
|
||||
'seminaryheader' => array('admin', 'moderator', 'user', 'guest'),
|
||||
'seminary' => array('admin', 'moderator', 'user', 'guest'),
|
||||
'avatar' => array('admin', 'moderator', 'user')
|
||||
'achievement' => array('admin', 'moderator', 'user', 'guest')
|
||||
);
|
||||
/**
|
||||
* User seminary permissions
|
||||
|
|
@ -36,14 +36,15 @@
|
|||
* @var array
|
||||
*/
|
||||
public $seminaryPermissions = array(
|
||||
'seminary' => array('admin', 'moderator', 'user', 'guest')
|
||||
'seminary' => array('admin', 'moderator', 'user', 'guest'),
|
||||
'achievement' => array('admin', 'moderator', 'user', 'guest')
|
||||
);
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('seminaries', 'media');
|
||||
public $models = array('seminaries', 'achievements', 'media');
|
||||
|
||||
|
||||
|
||||
|
|
@ -153,6 +154,53 @@
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: achievement
|
||||
*
|
||||
* Display the achievement of a Seminary.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param string $seminaryUrl URL-title of the Seminary
|
||||
* @param string $achievementUrl URL-title of the Achievement
|
||||
* @param string $action Action for processing the media
|
||||
*/
|
||||
public function achievement($seminaryUrl, $achievementUrl)
|
||||
{
|
||||
// Get Seminary
|
||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||
|
||||
// Get Character
|
||||
$character = IntermediateController::$character;
|
||||
|
||||
// Get Achievement
|
||||
$achievement = $this->Achievements->getAchievementByUrl($seminary['id'], $achievementUrl);
|
||||
|
||||
// Get media
|
||||
$index = '';
|
||||
if(is_null($character) || !$this->Achievements->hasCharacterAchievedAchievement($achievement['id'], $character['id'])) {
|
||||
$index = 'unachieved_achievementsmedia_id';
|
||||
}
|
||||
else {
|
||||
$index = 'achieved_achievementsmedia_id';
|
||||
}
|
||||
if(is_null($achievement[$index])) {
|
||||
throw new \nre\exceptions\IdNotFoundException($achievementUrl);
|
||||
}
|
||||
$media = $this->Media->getSeminaryMediaById($achievement[$index]);
|
||||
|
||||
// Get file
|
||||
$file = $this->getMediaFile($media, null);
|
||||
if(is_null($file)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('media', $media);
|
||||
$this->set('file', $file);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('characters', 'quests', 'questgroups');
|
||||
public $models = array('characters', 'quests', 'questgroups', 'achievements');
|
||||
|
||||
|
||||
|
||||
|
|
@ -53,11 +53,16 @@
|
|||
$lastQuest['questgroup'] = $this->Questgroups->getQuestgroupById($lastQuest['questgroup_id']);
|
||||
}
|
||||
|
||||
// Get last achieved Achievement
|
||||
$achievements = $this->Achievements->getAchievedAchievementsForCharacter($character['id']);
|
||||
$lastAchievement = array_shift($achievements);
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('character', $character);
|
||||
$this->set('lastQuest', $lastQuest);
|
||||
$this->set('lastAchievement', $lastAchievement);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,477 @@
|
|||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get an Achievement by its URL.
|
||||
*
|
||||
* @param int $seminaryId ID of Seminary
|
||||
* @param string $achievementUrl URL-title of Achievement
|
||||
* @return array Achievement data
|
||||
*/
|
||||
public function getAchievementByUrl($seminaryId, $achievementUrl)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT achievements.id, achievementconditions.condition, title, url, description, progress, unachieved_achievementsmedia_id, achieved_achievementsmedia_id '.
|
||||
'FROM achievements '.
|
||||
'LEFT JOIN achievementconditions ON achievementconditions.id = achievements.achievementcondition_id '.
|
||||
'WHERE seminary_id = ? AND url = ?',
|
||||
'is',
|
||||
$seminaryId, $achievementUrl
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($achievementUrl);
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all Achievements of a Seminary.
|
||||
*
|
||||
* @param int $seminaryId ID of Seminary to get Achievements of
|
||||
* @return array Achievements data
|
||||
*/
|
||||
public function getAchievementsForSeminary($seminaryId, $includeHidden=false)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT achievements.id, achievementconditions.condition, title, url, description, progress, unachieved_achievementsmedia_id, achieved_achievementsmedia_id '.
|
||||
'FROM achievements '.
|
||||
'LEFT JOIN achievementconditions ON achievementconditions.id = achievements.achievementcondition_id '.
|
||||
'WHERE seminary_id = ? AND hidden <= ?',
|
||||
'ii',
|
||||
$seminaryId, $includeHidden
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all not yet achieved Achievements for a Seminary that can
|
||||
* only be achieved once (only by one Character).
|
||||
*
|
||||
* @param int $seminaryId ID of Seminary
|
||||
* @return array Achievements data
|
||||
*/
|
||||
public function getUnachievedOnlyOnceAchievementsForSeminary($seminaryId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT achievements.id, achievementconditions.condition, title, url, description, progress, hidden, only_once, all_conditions, unachieved_achievementsmedia_id, achieved_achievementsmedia_id '.
|
||||
'FROM achievements '.
|
||||
'LEFT JOIN achievementconditions ON achievementconditions.id = achievements.achievementcondition_id '.
|
||||
'WHERE achievements.seminary_id = ? AND only_once = 1 AND NOT EXISTS ('.
|
||||
'SELECT character_id '.
|
||||
'FROM achievements_characters '.
|
||||
'WHERE achievements_characters.achievement_id = achievements.id'.
|
||||
')',
|
||||
'i',
|
||||
$seminaryId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all achieved Achievements for a Character.
|
||||
*
|
||||
* @param int $characterId ID of Character
|
||||
* @return array Achievements data
|
||||
*/
|
||||
public function getAchievedAchievementsForCharacter($characterId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT achievements.id, achievements_characters.created, achievements.title, achievements.url, achievements.description, achievements.progress, unachieved_achievementsmedia_id, achieved_achievementsmedia_id '.
|
||||
'FROM achievements '.
|
||||
'INNER JOIN achievements_characters ON achievements_characters.achievement_id = achievements.id '.
|
||||
'WHERE achievements_characters.character_id = ? '.
|
||||
'ORDER BY achievements_characters.created DESC',
|
||||
'i',
|
||||
$characterId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all not yet achieved Achievements for a Character.
|
||||
*
|
||||
* @param int $seminaryId ID of Seminary
|
||||
* @param int $characterId ID of Character
|
||||
* @return array Achievements data
|
||||
*/
|
||||
public function getUnachhievedAchievementsForCharacter($seminaryId, $characterId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT achievements.id, achievementconditions.condition, title, url, description, progress, hidden, only_once, all_conditions, unachieved_achievementsmedia_id, achieved_achievementsmedia_id '.
|
||||
'FROM achievements '.
|
||||
'LEFT JOIN achievementconditions ON achievementconditions.id = achievements.achievementcondition_id '.
|
||||
'WHERE achievements.seminary_id = ? AND only_once = 0 AND NOT EXISTS ('.
|
||||
'SELECT character_id '.
|
||||
'FROM achievements_characters '.
|
||||
'WHERE '.
|
||||
'achievements_characters.achievement_id = achievements.id AND '.
|
||||
'achievements_characters.character_id = ?'.
|
||||
')',
|
||||
'ii',
|
||||
$seminaryId,
|
||||
$characterId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all date conditions for an Achievement.
|
||||
*
|
||||
* @param int $achievementId ID of Achievement
|
||||
* @return array Date conditions
|
||||
*/
|
||||
public function getAchievementConditionsDate($achievementId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT `select` '.
|
||||
'FROM achievementconditions_date '.
|
||||
'WHERE achievement_id = ?',
|
||||
'i',
|
||||
$achievementId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check a date condition.
|
||||
*
|
||||
* @param string $select SELECT-string with date-functions
|
||||
* @return boolean Result
|
||||
*/
|
||||
public function checkAchievementConditionDate($select)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT ('.$select.') AS got '
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return ($data[0]['got'] == 1);
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all Character conditions for an Achievement.
|
||||
*
|
||||
* @param int $achievementId ID of Achievement
|
||||
* @return array Character conditions
|
||||
*/
|
||||
public function getAchievementConditionsCharacter($achievementId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT field, value '.
|
||||
'FROM achievementconditions_character '.
|
||||
'WHERE achievement_id = ?',
|
||||
'i',
|
||||
$achievementId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check a Character condition.
|
||||
*
|
||||
* @param string $field Field to check
|
||||
* @param int $value The value the field has to match
|
||||
* @param int $characterId ID of Character
|
||||
* @return boolean Result
|
||||
*/
|
||||
public function checkAchievementConditionCharacter($field, $value, $characterId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
"SELECT ($field >= $value) AS got ".
|
||||
'FROM v_characters '.
|
||||
'WHERE user_id = ?',
|
||||
'i',
|
||||
$characterId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return ($data[0]['got'] == 1);
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the progress for a Character condition.
|
||||
*
|
||||
* @param string $field Field to check
|
||||
* @param int $value The value the field has to match
|
||||
* @param int $characterId ID of Character
|
||||
* @return float Percentage progress
|
||||
*/
|
||||
public function getAchievementConditionCharacterProgress($field, $value, $characterId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
"SELECT $field AS field ".
|
||||
'FROM v_characters '.
|
||||
'WHERE user_id = ?',
|
||||
'i',
|
||||
$characterId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0]['field'] / $value;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all Quest conditions for an Achievement.
|
||||
*
|
||||
* @param int $achievementId ID of Achievement
|
||||
* @return array Quest conditions
|
||||
*/
|
||||
public function getAchievementConditionsQuest($achievementId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT field, `count`, value, quest_id, status, groupby '.
|
||||
'FROM achievementconditions_quest '.
|
||||
'WHERE achievement_id = ?',
|
||||
'i',
|
||||
$achievementId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check a Quest condition.
|
||||
*
|
||||
* @param string $field Field to check
|
||||
* @param boolean $count Conut field-value
|
||||
* @param int $value The value the field has to match
|
||||
* @param int $status Status of Quest or NULL
|
||||
* @param string $groupby Field to group or NULL
|
||||
* @param int $questId ID of related Quest or NULL
|
||||
* @param int $characterId ID of Character
|
||||
* @return boolean Result
|
||||
*/
|
||||
public function checkAchievementConditionQuest($field, $count, $value, $status, $groupby, $questId, $characterId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT ('.(
|
||||
$count
|
||||
? "count($field) >= $value"
|
||||
: "$field = $value"
|
||||
). ') AS got '.
|
||||
'FROM quests_characters '.
|
||||
'WHERE '.
|
||||
'character_id = ?'.
|
||||
(!is_null($questId) ? " AND quest_id = $questId" : '').
|
||||
(!is_null($status) ? " AND status = $status" : '').
|
||||
(!is_null($groupby) ? " GROUP BY $groupby" : ''),
|
||||
'i',
|
||||
$characterId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
foreach($data as &$datum) {
|
||||
if($datum['got'] == 1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the progress for a Quest condition.
|
||||
*
|
||||
* @param string $field Field to check
|
||||
* @param boolean $count Conut field-value
|
||||
* @param int $value The value the field has to match
|
||||
* @param int $status Status of Quest or NULL
|
||||
* @param string $groupby Field to group or NULL
|
||||
* @param int $questId ID of related Quest or NULL
|
||||
* @param int $characterId ID of Character
|
||||
* @return float Percentage progress
|
||||
*/
|
||||
public function getAchievementConditionQuestProgress($field, $count, $value, $status, $groupby, $questId, $characterId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT '.(
|
||||
$count
|
||||
? "count($field)"
|
||||
: "$field"
|
||||
). ' AS field '.
|
||||
'FROM quests_characters '.
|
||||
'WHERE '.
|
||||
'character_id = ?'.
|
||||
(!is_null($questId) ? " AND quest_id = $questId" : '').
|
||||
(!is_null($status) ? " AND status = $status" : '').
|
||||
(!is_null($groupby) ? " GROUP BY $groupby" : ''),
|
||||
'i',
|
||||
$characterId
|
||||
);
|
||||
if(!empty($data))
|
||||
{
|
||||
$maxField = 0;
|
||||
foreach($data as &$datum) {
|
||||
$maxField = max($maxField, intval($datum['field']));
|
||||
}
|
||||
|
||||
return $maxField / $value;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all Metaachievement conditions for an Achievement.
|
||||
*
|
||||
* @param int $achievementId ID of Achievement
|
||||
* @return array Metaachievement conditions
|
||||
*/
|
||||
public function getAchievementConditionsAchievement($achievementId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT field, `count`, value, meta_achievement_id, groupby '.
|
||||
'FROM achievementconditions_achievement '.
|
||||
'WHERE achievement_id = ?',
|
||||
'i',
|
||||
$achievementId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check a Metaachievement condition.
|
||||
*
|
||||
* @param string $field Field to check
|
||||
* @param boolean $count Conut field-value
|
||||
* @param int $value The value the field has to match
|
||||
* @param string $groupby Field to group or NULL
|
||||
* @param int $metaAchievementId ID of related Achievement or NULL
|
||||
* @param int $characterId ID of Character
|
||||
* @return boolean Result
|
||||
*/
|
||||
public function checkAchievementConditionAchievement($field, $count, $value, $groupby, $metaAchievementId, $characterId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT ('.(
|
||||
$count
|
||||
? "count($field) >= $value"
|
||||
: "$field = $value"
|
||||
). ') AS got '.
|
||||
'FROM achievements_characters '.
|
||||
'WHERE '.
|
||||
'character_id = ?'.
|
||||
(!is_null($metaAchievementId) ? " AND achievement_id = $metaAchievementId" : '').
|
||||
(!is_null($groupby) ? " GROUP BY $groupby" : ''),
|
||||
'i',
|
||||
$characterId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
foreach($data as &$datum) {
|
||||
if($datum['got'] == 1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the progress for a Metaachievement condition.
|
||||
*
|
||||
* @param string $field Field to check
|
||||
* @param boolean $count Conut field-value
|
||||
* @param int $value The value the field has to match
|
||||
* @param string $groupby Field to group or NULL
|
||||
* @param int $metaAchievementId ID of related Achievement or NULL
|
||||
* @param int $characterId ID of Character
|
||||
* @return float Percentage progress
|
||||
*/
|
||||
public function getAchievementConditionAchievementProgress($field, $count, $value, $groupby, $metaAchievementId, $characterId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT '.(
|
||||
$count
|
||||
? "count($field)"
|
||||
: "$field"
|
||||
). ' AS field '.
|
||||
'FROM achievements_characters '.
|
||||
'WHERE '.
|
||||
'character_id = ?'.
|
||||
(!is_null($metaAchievementId) ? " AND achievement_id = $metaAchievementId" : '').
|
||||
(!is_null($groupby) ? " GROUP BY $groupby" : ''),
|
||||
'i',
|
||||
$characterId
|
||||
);
|
||||
if(!empty($data))
|
||||
{
|
||||
$maxField = 0;
|
||||
foreach($data as &$datum) {
|
||||
$maxField = max($maxField, intval($datum['field']));
|
||||
}
|
||||
|
||||
return $maxField / $value;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set an Achievement as achieved for a Character.
|
||||
*
|
||||
* @param int $achievementId ID of Achievement
|
||||
* @param int $characterId ID of Character
|
||||
*/
|
||||
public function setAchievementAchieved($achievementId, $characterId)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO achievements_characters '.
|
||||
'(achievement_id, character_id) '.
|
||||
'VALUES '.
|
||||
'(?, ?)',
|
||||
'ii',
|
||||
$achievementId, $characterId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if a Character has achieved an Achievement.
|
||||
*
|
||||
* @param int $achievementId ID of Achievement
|
||||
* @param int $characterId ID of Character
|
||||
* @return boolean Whether Character has achieved the Achievement or not
|
||||
*/
|
||||
public function hasCharacterAchievedAchievement($achievementId, $characterId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT character_id '.
|
||||
'FROM achievements_characters '.
|
||||
'WHERE achievement_id = ? AND character_id = ?',
|
||||
'ii',
|
||||
$achievementId, $characterId
|
||||
);
|
||||
|
||||
|
||||
return !empty($data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -88,21 +88,21 @@
|
|||
* Get a Seminary medium by its URL.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param int $seminaryId ID of the seminary
|
||||
* @param string $mediaURL URL-name of the Medium
|
||||
* @return array Medium data
|
||||
* @param int $seminaryId ID of the seminary
|
||||
* @param string $seminaryMediaUrl URL-name of the Seminary medium
|
||||
* @return array Seminary medium data
|
||||
*/
|
||||
public function getSeminaryMediaByUrl($seminaryId, $mediaUrl)
|
||||
public function getSeminaryMediaByUrl($seminaryId, $seminaryMediaUrl)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, name, url, description, mimetype '.
|
||||
'FROM seminarymedia '.
|
||||
'WHERE url = ?',
|
||||
's',
|
||||
$mediaUrl
|
||||
$seminaryMediaUrl
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($mediaUrl);
|
||||
throw new \nre\exceptions\IdNotFoundException($seminaryMediaUrl);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -114,9 +114,8 @@
|
|||
* Get a Seminary medium by its ID.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param int $seminaryId ID of the seminary
|
||||
* @param int $mediaId ID of the Medium
|
||||
* @return array Medium data
|
||||
* @param int $seminaryMediaId ID of the Seminary medium
|
||||
* @return array Seminary medium data
|
||||
*/
|
||||
public function getSeminaryMediaById($mediaId)
|
||||
{
|
||||
|
|
|
|||
28
views/html/achievements/index.tpl
Normal file
28
views/html/achievements/index.tpl
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<?php if(!is_null($seminary['seminarymedia_id'])) : ?>
|
||||
<div class="moodpic">
|
||||
<img src="<?=$linker->link(array('media','seminaryheader',$seminary['url']))?>" />
|
||||
</div>
|
||||
<?php endif ?>
|
||||
<h1><a href="<?=$linker->link(array('seminaries',$seminary['url']))?>"><?=$seminary['title']?></a></h1>
|
||||
<h2><?=_('Achievements')?></h2>
|
||||
|
||||
<ul>
|
||||
<?php foreach($achievements as &$achievement) : ?>
|
||||
<li>
|
||||
<?php if(!is_null($achievement[$achievement['media_index']])) : ?>
|
||||
<img src="<?=$linker->link(array('media','achievement',$seminary['url'],$achievement['url']))?>" />
|
||||
<?php endif ?>
|
||||
<h3><?=$achievement['title']?></h3>
|
||||
<?=\hhu\z\Utils::t($achievement['description'])?><br />
|
||||
|
||||
<?php if(array_key_exists('characterProgress', $achievement)) : ?>
|
||||
<div class="cf">
|
||||
<div class="xpbar">
|
||||
<span style="width:<?=round($achievement['characterProgress']*100)?>%"></span>
|
||||
</div>
|
||||
<p class="xpnumeric"><?=round($achievement['characterProgress']*100)?> %</p>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
</li>
|
||||
<?php endforeach?>
|
||||
</ul>
|
||||
|
|
@ -67,31 +67,15 @@
|
|||
<section class="fll48">
|
||||
<h1><i class="fa fa-trophy fa-fw"></i>Neue Achievements</h1>
|
||||
<ul class="cranks">
|
||||
<?php foreach($achievements as &$achievement) : ?>
|
||||
<li>
|
||||
<a href="#" title="Achievement-Titel"><img src="http://legende-von-zyren.de/img/achieve/1b.jpg"></a>
|
||||
<p><a href="#">Des Königs neue Quests</a></p>
|
||||
<p><small>erreicht am: 14.07.2014</small></p>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#" title="Achievement-Titel"><img src="http://legende-von-zyren.de/img/achieve/2b.jpg"></a>
|
||||
<p><a href="#">Des Königs neue Quests</a></p>
|
||||
<p><small>erreicht am: 14.07.2014</small></p>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#" title="Achievement-Titel"><img src="http://legende-von-zyren.de/img/achieve/3b.jpg"></a>
|
||||
<p><a href="#">Des Königs neue Quests</a></p>
|
||||
<p><small>erreicht am: 14.07.2014</small></p>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#" title="Achievement-Titel"><img src="http://legende-von-zyren.de/img/achieve/4b.jpg"></a>
|
||||
<p><a href="#">Des Königs neue Quests</a></p>
|
||||
<p><small>erreicht am: 14.07.2014</small></p>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#" title="Achievement-Titel"><img src="http://legende-von-zyren.de/img/achieve/5b.jpg"></a>
|
||||
<p><a href="#">Des Königs neue Quests</a></p>
|
||||
<p><small>erreicht am: 14.07.2014</small></p>
|
||||
<?php if(!is_null($achievement['achieved_achievementsmedia_id'])) : ?>
|
||||
<a href="#" title="Achievement-Titel"><img src="<?=$linker->link(array('media','achievement',$seminary['url'],$achievement['url']))?>"></a>
|
||||
<?php endif ?>
|
||||
<p><a href="#"><?=$achievement['title']?></a></p>
|
||||
<p><small><?=sprintf(_('achieved at: %s'), $dateFormatter->format(new \DateTime($achievement['created'])))?></small></p>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
|
|
|
|||
|
|
@ -16,16 +16,21 @@
|
|||
</section>
|
||||
<?php endif ?>
|
||||
|
||||
<?php if(!is_null($lastAchievement)) : ?>
|
||||
<section>
|
||||
<h1><?=('Last Achievement')?></h1>
|
||||
<ul class="cranks">
|
||||
<li>
|
||||
<a href="#" title="Achievement-Titel"><img src="http://legende-von-zyren.de/img/achieve/1b.jpg"></a>
|
||||
<p><a href="#">Des Königs neue Quests</a></p>
|
||||
<p><small>erreicht am: 14.07.2014</small></p>
|
||||
<?php if(!is_null($lastAchievement['achieved_achievementsmedia_id'])) : ?>
|
||||
<a href="#" title="Achievement-Titel"><img src="<?=$linker->link(array('media','achievement',$seminary['url'],$lastAchievement['url']))?>"></a>
|
||||
<?php endif ?>
|
||||
<p><a href="#"><?=$lastAchievement['title']?></a></p>
|
||||
<p><small><?=sprintf(_('achieved at: %s'), $dateFormatter->format(new \DateTime($lastAchievement['created'])))?></small></p>
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
<?php endif ?>
|
||||
|
||||
<section>
|
||||
<h1>Wille und die Majas</h1>
|
||||
<ul class="cranks">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue