hide map for Character groups Quest Stations when there are no stations

This commit is contained in:
oliver 2016-04-09 13:44:37 +02:00
commit df14dfafc3
4371 changed files with 1220224 additions and 0 deletions

View file

@ -0,0 +1,205 @@
<?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\components;
/**
* Component to handle achievements.
*
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
*/
class AchievementComponent extends \nre\core\Component
{
/**
* Required models
*
* @var array
*/
public $models = array('achievements', 'characterroles');
/**
* Construct a new Achievements-component.
*/
public function __construct()
{
parent::__construct();
}
/**
* Check for newly achieved Achievements.
*
* @param int $seminaryId ID of Seminary to check Achievements for
* @param int $characterId ID of Character to check Achievements for
* @param array $checkConditions Conditions to check
* @return array List of newly achieved achievements
*/
public function checkAchievements($seminaryId, $characterId, $checkConditions=null)
{
// Set conditions to check
if(!is_null($checkConditions) && !is_array($checkConditions)) {
$checkConditions = array($checkConditions);
}
// Get unachieved Achievments
$achievements = $this->Achievements->getUnachhievedAchievementsForCharacter($seminaryId, $characterId);
// Merge “only-once” Achievements
if(in_array('user', $this->Characterroles->getCharacterrolesForCharacterById($characterId))) {
$achievements = array_merge($achievements, $this->Achievements->getUnachievedOnlyOnceAchievementsForSeminary($seminaryId));
}
// Check conditions
$achievedAchievements = array();
foreach($achievements as &$achievement)
{
// Check condition to test
if(!is_null($checkConditions) && !in_array($achievement['condition'], $checkConditions)) {
continue;
}
// Check deadline
if(!is_null($achievement['deadline']) && $achievement['deadline'] < date('Y-m-d H:i:s')) {
continue;
}
// 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'],
$characterId
)
);
}
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'],
$characterId
)
);
}
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'],
$characterId
)
);
}
break;
}
// Do not achieve Achievements without conditions
if(empty($conditions)) {
continue;
}
// 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;
}
}
}
// Achievement achieved
if($achieved)
{
// Set status
$this->Achievements->setAchievementAchieved($achievement['id'], $characterId);
// Add to list
$achievedAchievements[] = $achievement;
}
}
// Return newly achieved Achievements
return $achievedAchievements;
}
}
?>

View file

@ -0,0 +1,79 @@
<?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\components;
/**
* Component to handle authentication and authorization.
*
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
*/
class AuthComponent extends \nre\core\Component
{
/**
* Key to save a user-ID as
*
* @var string
*/
const KEY_USER_ID = 'user_id';
/**
* Construct a new Auth-component.
*/
public function __construct()
{
// Start session
if(session_id() === '') {
session_start();
}
}
/**
* Set the ID of the user that is currently logged in.
*
* @param int $userId ID of the currently logged in user
*/
public function setUserId($userId)
{
if(is_null($userId)) {
unset($_SESSION[self::KEY_USER_ID]);
}
else {
$_SESSION[self::KEY_USER_ID] = $userId;
}
}
/**
* Get the ID of the user that is currently logged in.
*
* @return int ID of the currently logged in user
*/
public function getUserId()
{
if(array_key_exists(self::KEY_USER_ID, $_SESSION)) {
return $_SESSION[self::KEY_USER_ID];
}
return null;
}
}
?>

View file

@ -0,0 +1,120 @@
<?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\components;
/**
* Component to handle user notifications
*
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
*/
class NotificationComponent extends \nre\core\Component
{
/**
* Type: Achievement
*
* @var string
*/
const TYPE_ACHIEVEMENT = 'achievement';
/**
* Type: Character groups Achievement
*
* @var string
*/
const TYPE_CHARACTERGROUPSACHIEVEMENT = 'charactergroupsachievement';
/**
* Type: Character title
*
* @var string
*/
const TYPE_CHARACTERTITLE = 'charactertitle';
/**
* Type: Level-up
*
* @var string
*/
const TYPE_LEVELUP = 'levelup';
/**
* Key for Session-Array to store notifications in
*
* @var string
*/
const SESSION_KEY = 'notifications';
/**
* Construct a new Notification-component.
*/
public function __construct()
{
// Start session
if(session_id() === '') {
session_start();
}
// Prepare array
if(!array_key_exists(self::SESSION_KEY, $_SESSION)) {
$_SESSION[self::SESSION_KEY] = array();
}
}
/**
* Add a notification.
*
* @param string $type Type of notification
* @param string $message Message to display
* @param string $link Optional URL to link to
* @param string $image Optional URL of image to display
*/
public function addNotification($type, $message, $link=null, $image=null)
{
$_SESSION[self::SESSION_KEY][] = array(
'type' => $type,
'message' => $message,
'link' => $link,
'image' => $image
);
}
/**
* Get all registered notifiactions and clear them.
*
* @return array List of existing notifications
*/
public function getNotifications()
{
$notifications = $_SESSION[self::SESSION_KEY];
$this->clearNotifications();
return $notifications;
}
/**
* Clear all notifications currently registered
*/
public function clearNotifications()
{
unset($_SESSION[self::SESSION_KEY]);
$_SESSION[self::SESSION_KEY] = array();
}
}
?>

View file

@ -0,0 +1,89 @@
<?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\components;
/**
* Component to handle data for Questtypes between different Quest states.
*
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
*/
class QuesttypedataComponent extends \nre\core\Component
{
/**
* Session key
*
* @var string
*/
const SESSION_KEY = 'questtypes';
/**
* Construct a new QuesttypesData-component.
*/
public function __construct()
{
// Construct session place
if(!array_key_exists(self::SESSION_KEY, $_SESSION)) {
$_SESSION[self::SESSION_KEY] = array();
}
}
/**
* Set data with a key-value pair.
*
* @param int $questId ID of Quest to set data for
* @param mixed $key Key
* @param mixed $value Value
*/
public function set($questId, $key, $value)
{
// Construct array
if(!array_key_exists($questId, $_SESSION[self::SESSION_KEY])) {
$_SESSION[self::SESSION_KEY][$questId] = array();
}
// Set data
$_SESSION[self::SESSION_KEY][$questId][$key] = $value;
}
/**
* Get data by a key.
*
* @param int $questId ID of Quest to set data for
* @param mixed $key Key
* @return mixed Value
*/
public function get($questId, $key)
{
// Check array
if(!array_key_exists($questId, $_SESSION[self::SESSION_KEY])) {
return null;
}
if(!array_key_exists($key, $_SESSION[self::SESSION_KEY][$questId])) {
return null;
}
// Return data
return $_SESSION[self::SESSION_KEY][$questId][$key];
}
}
?>

View file

@ -0,0 +1,183 @@
<?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\components;
/**
* Component to validate user input.
*
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
*/
class ValidationComponent extends \nre\core\Component
{
/**
* Validation settings
*
* @var array
*/
private $config;
/**
* Construct a new Validation-component.
*/
public function __construct()
{
// Get validation settings from configuration
$this->config = \nre\configs\AppConfig::$validation;
}
/**
* Validate an user input.
*
* @param mixed $input User input to validate
* @param array $settings Validation setting
* @return mixed True or the settings the validation fails on
*/
public function validate($input, $settings)
{
$validation = array();
// Min string length
if(array_key_exists('minlength', $settings) && strlen($input) < $settings['minlength']) {
$validation['minlength'] = $settings['minlength'];
}
// Max string length
if(array_key_exists('maxlength', $settings) && strlen($input) > $settings['maxlength']) {
$validation['maxlength'] = $settings['maxlength'];
}
// Regex
if(array_key_exists('regex', $settings) && !preg_match($settings['regex'], $input)) {
$validation['regex'] = $settings['regex'];
}
// Return true or the failed fields
if(empty($validation)) {
return true;
}
return $validation;
}
/**
* Validate an user input parameter.
*
* @param array $params User input parameters
* @param array $index Names of parameter to validate and to validate against
* @return mixed True or the parameter with settings the validation failed on
*/
public function validateParam($params, $index)
{
// Check parameter
if(!array_key_exists($index, $params)) {
throw new \nre\exceptions\ParamsNotValidException($index);
}
// Check settings
if(!array_key_exists($index, $this->config)) {
return true;
}
// Validate parameter and return result
return $this->validate($params[$index], $this->config[$index]);
}
/**
* Validate user input parameters.
*
* @param array $params User input parameters
* @param array $indices Names of parameters to validate and to validate against
* @return mixed True or the parameters with settings the validation failed on
*/
public function validateParams($params, $indices)
{
// Validate parameters
$validation = true;
foreach($indices as $index) {
$validation = $this->addValidationResults($validation, $index, $this->validateParam($params, $index));
}
// Return validation results
return $validation;
}
/**
* Add a custom determined validation result to a validation
* array.
*
* @param mixed $validation Validation array to add result to
* @param string $index Name of parameter of the custom validation result
* @param string $setting Name of setting of the custom validation result
* @param mixed $result Validation result
* @return mixed The altered validation array
*/
public function addValidationResult($validation, $index, $setting, $result)
{
// Create validation array
if(!is_array($validation)) {
$validation = array();
}
// Add validation results
if(!array_key_exists($index, $validation)) {
$validation[$index] = array();
}
$validation[$index][$setting] = $result;
// Return new validation result
return $validation;
}
/**
* Add custom determined validation results to a validation
* arary.
*
* @param mixed $validation Validation array to add result to
* @param string $index Name of parameter of the custom validation result
* @param mixed $result Validation result
* @return mixed The altered validation array
*/
public function addValidationResults($validation, $index, $results)
{
// Create validation array
if(!is_array($validation)) {
$validation = array();
}
// Add validation results
if($results !== true) {
$validation[$index] = $results;
}
// Return new validation result
if(empty($validation)) {
return true;
}
return $validation;
}
}
?>