correct input fields for Questtype ?Textinput? when marker is at the begin or end of text
This commit is contained in:
commit
2cf011e1ca
193 changed files with 16344 additions and 0 deletions
36
models/AchievementsModel.inc
Normal file
36
models/AchievementsModel.inc
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<?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\models;
|
||||
|
||||
|
||||
/**
|
||||
* Model to interact with Achievements-tables.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class AchievementsModel extends \hhu\z\Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new AchievementsModel.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
147
models/CharactergroupsModel.inc
Normal file
147
models/CharactergroupsModel.inc
Normal file
|
|
@ -0,0 +1,147 @@
|
|||
<?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\models;
|
||||
|
||||
|
||||
/**
|
||||
* Model of the CharactergroupsAgent to interact with
|
||||
* Charactergroups-table.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class CharactergroupsModel extends \hhu\z\Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new CharactergroupsModel.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get Character groups-groups of a Seminary.
|
||||
*
|
||||
* @param int $seminaryId ID of the corresponding Seminary
|
||||
* @return array Character groups-groups data
|
||||
*/
|
||||
public function getGroupsroupsForSeminary($seminaryId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, name, url '.
|
||||
'FROM charactergroupsgroups '.
|
||||
'WHERE seminary_id = ?',
|
||||
'i',
|
||||
$seminaryId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a Character groups-group by its URL.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param int $seminaryId ID of the corresponding Seminary
|
||||
* @param string $groupsgroupUrl URL-name of the Character groups-group
|
||||
* @return array Character groups-group data
|
||||
*/
|
||||
public function getGroupsgroupByUrl($seminaryId, $groupsgroupUrl)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, name, url '.
|
||||
'FROM charactergroupsgroups '.
|
||||
'WHERE seminary_id = ? AND url = ?',
|
||||
'is',
|
||||
$seminaryId, $groupsgroupUrl
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($groupsgroupUrl);
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Character groups for a Character groups-group.
|
||||
*
|
||||
* @param int $groupsgroupId ID of the Character groups-group
|
||||
* @return array Character groups
|
||||
*/
|
||||
public function getGroupsForGroupsgroup($groupsgroupId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, name, url, xps '.
|
||||
'FROM v_charactergroups '.
|
||||
'WHERE charactergroupsgroup_id = ?',
|
||||
'i',
|
||||
$groupsgroupId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Character groups for a Character.
|
||||
*
|
||||
* @param int $characterId ID of the Character
|
||||
* @return array Character groups
|
||||
*/
|
||||
public function getGroupsForCharacter($characterId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT charactergroups.id, charactergroups.charactergroupsgroup_id, charactergroups.name, charactergroups.url, charactergroups.xps, charactergroupsgroups.id AS charactergroupsgroup_id, charactergroupsgroups.name AS charactergroupsgroup_name, charactergroupsgroups.url AS charactergroupsgroup_url '.
|
||||
'FROM characters_charactergroups '.
|
||||
'LEFT JOIN v_charactergroups AS charactergroups ON charactergroups.id = characters_charactergroups.charactergroup_id '.
|
||||
'LEFT JOIN charactergroupsgroups ON charactergroupsgroups.id = charactergroups.charactergroupsgroup_id '.
|
||||
'WHERE characters_charactergroups.character_id = ?',
|
||||
'i',
|
||||
$characterId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a Character group by its URL.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param int $groupsgroupId ID of the Character groups-group
|
||||
* @param string $groupUrl URL-name of the Character group
|
||||
* @return array Character group data
|
||||
*/
|
||||
public function getGroupByUrl($groupsgroupId, $groupUrl)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, name, url, xps '.
|
||||
'FROM v_charactergroups '.
|
||||
'WHERE charactergroupsgroup_id = ? AND url = ?',
|
||||
'is',
|
||||
$groupsgroupId, $groupUrl
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($groupUrl);
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
136
models/CharactergroupsquestsModel.inc
Normal file
136
models/CharactergroupsquestsModel.inc
Normal file
|
|
@ -0,0 +1,136 @@
|
|||
<?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\models;
|
||||
|
||||
|
||||
/**
|
||||
* Model of the CharactergroupsquestsAgent to interact with
|
||||
* Charactergroupsquests-table.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class CharactergroupsquestsModel extends \hhu\z\Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new CharactergroupsquestsModel.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get Character groups Quests of a Character groups-groups.
|
||||
*
|
||||
* @param int $groupsgroupId ID of the Character groups-group
|
||||
* @return array Character groups Quest data
|
||||
*/
|
||||
public function getQuestsForCharactergroupsgroup($groupsgroupId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, questgroups_id, title, url '.
|
||||
'FROM charactergroupsquests '.
|
||||
'WHERE charactergroupsgroup_id = ?',
|
||||
'i',
|
||||
$groupsgroupId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a Character groups Quest by its URL.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param int $groupsgroupId ID of the Character groups-group
|
||||
* @param string $questUrl URL-title of the Character groups Quest
|
||||
* @return array Character groups Quest data
|
||||
*/
|
||||
public function getQuestByUrl($groupsgroupId, $questUrl)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, questgroups_id, title, url, description, xps, rules, won_text, lost_text, questsmedia_id '.
|
||||
'FROM charactergroupsquests '.
|
||||
'WHERE charactergroupsgroup_id = ? AND url = ?',
|
||||
'is',
|
||||
$groupsgroupId,
|
||||
$questUrl
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($questUrl);
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the Character groups for a Quest.
|
||||
*
|
||||
* @param int $questId ID of the Character groups Quest
|
||||
* @return array Character groups
|
||||
*/
|
||||
public function getGroupsForQuest($questId)
|
||||
{
|
||||
$groups = $this->db->query(
|
||||
'SELECT charactergroups.id, charactergroups.name, charactergroups.url, charactergroupsquests_groups.created, charactergroupsquests_groups.xps_factor, charactergroupsquests.xps '.
|
||||
'FROM charactergroupsquests_groups '.
|
||||
'LEFT JOIN charactergroups ON charactergroups.id = charactergroupsquests_groups.charactergroup_id '.
|
||||
'LEFT JOIN charactergroupsquests ON charactergroupsquests.id = charactergroupsquests_groups.charactergroupsquest_id '.
|
||||
'WHERE charactergroupsquests_groups.charactergroupsquest_id = ?',
|
||||
'i',
|
||||
$questId
|
||||
);
|
||||
foreach($groups as &$group) {
|
||||
$group['xps'] = round($group['xps'] * $group['xps_factor'], 1);
|
||||
}
|
||||
|
||||
|
||||
return $groups;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Character groups Quests for a Character group.
|
||||
*
|
||||
* @param int $groupId ID of the Character group
|
||||
* @return array Character groups Quests
|
||||
*/
|
||||
public function getQuestsForGroup($groupId)
|
||||
{
|
||||
$quests = $this->db->query(
|
||||
'SELECT charactergroupsquests.id, charactergroupsquests_groups.created, charactergroupsquests.title, charactergroupsquests.url, charactergroupsquests.xps, charactergroupsquests_groups.xps_factor '.
|
||||
'FROM charactergroupsquests_groups '.
|
||||
'LEFT JOIN charactergroupsquests ON charactergroupsquests.id = charactergroupsquests_groups.charactergroupsquest_id '.
|
||||
'WHERE charactergroupsquests_groups.charactergroup_id = ?',
|
||||
'i',
|
||||
$groupId
|
||||
);
|
||||
foreach($quests as &$quest) {
|
||||
$quest['group_xps'] = round($quest['xps'] * $quest['xps_factor'], 1);
|
||||
}
|
||||
|
||||
|
||||
return $quests;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
209
models/CharactersModel.inc
Normal file
209
models/CharactersModel.inc
Normal file
|
|
@ -0,0 +1,209 @@
|
|||
<?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\models;
|
||||
|
||||
|
||||
/**
|
||||
* Model to interact with Characters-table.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class CharactersModel extends \hhu\z\Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new CharactersModel.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get all characters for an user.
|
||||
*
|
||||
* @param int $userId ID of the user
|
||||
* @return array Characters
|
||||
*/
|
||||
public function getCharactersForUser($userId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT characters.id, characters.created, characters.charactertype_id, characters.name, characters.url, characters.xps, characters.xplevel, charactertypes.name AS charactertype_name, charactertypes.url AS charactertypes_url, seminaries.id AS seminary_url, seminaries.title AS seminary_title, seminaries.url AS seminary_url '.
|
||||
'FROM v_characters AS characters '.
|
||||
'LEFT JOIN charactertypes ON charactertypes.id = characters.charactertype_id '.
|
||||
'LEFT JOIN seminaries ON seminaries.id = charactertypes.seminary_id '.
|
||||
'WHERE user_id = ?',
|
||||
'i',
|
||||
$userId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Characters for a Seminary.
|
||||
*
|
||||
* @param int $seminaryId ID of the Seminary
|
||||
* @return array Characters
|
||||
*/
|
||||
public function getCharactersForSeminary($seminaryId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT characters.id, characters.created, characters.charactertype_id, characters.name, characters.url, characters.user_id, characters.xps, characters.xplevel, charactertypes.name AS charactertype_name, charactertypes.url AS charactertypes_url, seminaries.id AS seminary_url, seminaries.title AS seminary_title, seminaries.url AS seminary_url '.
|
||||
'FROM v_characters AS characters '.
|
||||
'LEFT JOIN charactertypes ON charactertypes.id = characters.charactertype_id '.
|
||||
'LEFT JOIN seminaries ON seminaries.id = charactertypes.seminary_id '.
|
||||
'WHERE seminaries.id = ?',
|
||||
'i',
|
||||
$seminaryId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Characters for a Character group.
|
||||
*
|
||||
* @param int $groupId ID of the Character group
|
||||
* @return array Characters
|
||||
*/
|
||||
public function getCharactersForGroup($groupId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT characters.id, characters.created, characters.charactertype_id, characters.name, characters.url, characters.user_id, characters.xps, characters_charactergroups.is_leader, charactertypes.name AS charactertype_name, charactertypes.url AS charactertypes_url '.
|
||||
'FROM v_characters AS characters '.
|
||||
'LEFT JOIN characters_charactergroups ON characters_charactergroups.character_id = characters.id '.
|
||||
'LEFT JOIN charactertypes ON charactertypes.id = characters.charactertype_id '.
|
||||
'WHERE characters_charactergroups.charactergroup_id = ?',
|
||||
'i',
|
||||
$groupId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the character of a user for a Seminary.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param int $userId ID of the user
|
||||
* @param int $seminaryId ID of the Seminary
|
||||
* @return array Character data
|
||||
*/
|
||||
public function getCharacterForUserAndSeminary($userId, $seminaryId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT characters.id, characters.created, characters.charactertype_id, characters.name, characters.url, characters.user_id, characters.xps, characters.xplevel, charactertypes.name AS charactertype_name, charactertypes.url AS charactertypes_url '.
|
||||
'FROM v_characters AS characters '.
|
||||
'LEFT JOIN charactertypes ON charactertypes.id = characters.charactertype_id '.
|
||||
'WHERE characters.user_id = ? AND charactertypes.seminary_id = ?',
|
||||
'ii',
|
||||
$userId, $seminaryId
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($userId);
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a Character by its Url.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param int $seminaryId ID of the Seminary
|
||||
* @param string $characterUrl URL-name of the Character
|
||||
* @return array Character data
|
||||
*/
|
||||
public function getCharacterByUrl($seminaryId, $characterUrl)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT characters.id, characters.created, characters.charactertype_id, characters.name, characters.url, characters.user_id, characters.xps, characters.xplevel, charactertypes.name AS charactertype_name, charactertypes.url AS charactertypes_url, media.url AS avatar_url, media.description AS avatar_description '.
|
||||
'FROM v_characters AS characters '.
|
||||
'LEFT JOIN charactertypes ON charactertypes.id = characters.charactertype_id '.
|
||||
'LEFT JOIN avatars ON avatars.id = characters.avatar_id '.
|
||||
'LEFT JOIN avatarpictures ON avatarpictures.media_id = avatars.avatarpicture_id '.
|
||||
'LEFT JOIN media ON media.id = avatarpictures.media_id '.
|
||||
'WHERE charactertypes.seminary_id = ? AND characters.url = ?',
|
||||
'is',
|
||||
$seminaryId, $characterUrl
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($characterUrl);
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a Character by its Id.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param string $characterId ID of the Character
|
||||
* @return array Character data
|
||||
*/
|
||||
public function getCharacterById($characterId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT characters.id, characters.created, characters.charactertype_id, characters.name, characters.url, characters.user_id, characters.xps, characters.xplevel, charactertypes.name AS charactertype_name, charactertypes.url AS charactertypes_url, media.url AS avatar_url, media.description AS avatar_description '.
|
||||
'FROM v_characters AS characters '.
|
||||
'LEFT JOIN charactertypes ON charactertypes.id = characters.charactertype_id '.
|
||||
'LEFT JOIN avatars ON avatars.id = characters.avatar_id '.
|
||||
'LEFT JOIN avatarpictures ON avatarpictures.media_id = avatars.avatarpicture_id '.
|
||||
'LEFT JOIN media ON media.id = avatarpictures.media_id '.
|
||||
'WHERE characters.id = ?',
|
||||
'i',
|
||||
$characterId
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($characterUrl);
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the XP-level of a Character.
|
||||
*
|
||||
* @param string $characterId ID of the Character
|
||||
* @return array XP-level of Character
|
||||
*/
|
||||
public function getXPLevelOfCharacters($characterId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT xplevels.xps, xplevels.level, xplevels.name '.
|
||||
'FROM v_charactersxplevels '.
|
||||
'INNER JOIN xplevels ON xplevels.id = v_charactersxplevels.xplevel_id '.
|
||||
'WHERE v_charactersxplevels.character_id = ?',
|
||||
'i',
|
||||
$characterId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
83
models/DatabaseModel.inc
Normal file
83
models/DatabaseModel.inc
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\models;
|
||||
|
||||
|
||||
/**
|
||||
* Default implementation of a database model.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
class DatabaseModel extends \nre\core\Model
|
||||
{
|
||||
/**
|
||||
* Database connection
|
||||
*
|
||||
* @static
|
||||
* @var DatabaseDriver
|
||||
*/
|
||||
protected $db = NULL;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new datamase model.
|
||||
*
|
||||
* @throws DatamodelException
|
||||
* @throws DriverNotFoundException
|
||||
* @throws DriverNotValidException
|
||||
* @param string $type Database type
|
||||
* @param array $config Connection settings
|
||||
*/
|
||||
function __construct($type, $config)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
// Load database driver
|
||||
$this->loadDriver($type);
|
||||
|
||||
// Establish database connection
|
||||
$this->connect($type, $config);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Load the database driver.
|
||||
*
|
||||
* @throws DriverNotFoundException
|
||||
* @throws DriverNotValidException
|
||||
* @param string $driverName Name of the database driver
|
||||
*/
|
||||
private function loadDriver($driverName)
|
||||
{
|
||||
\nre\core\Driver::load($driverName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Establish a connection to the database.
|
||||
*
|
||||
* @throws DatamodelException
|
||||
* @param string $driverName Name of the database driver
|
||||
* @param array $config Connection settings
|
||||
*/
|
||||
private function connect($driverName, $config)
|
||||
{
|
||||
$this->db = \nre\core\Driver::factory($driverName, $config);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
90
models/MediaModel.inc
Normal file
90
models/MediaModel.inc
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
<?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\models;
|
||||
|
||||
|
||||
/**
|
||||
* Model to interact with the Media-tables.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class MediaModel extends \hhu\z\Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new MediaModel.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get a 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
|
||||
*/
|
||||
public function getMediaByUrl($seminaryId, $mediaUrl)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, name, url, description, mimetype '.
|
||||
'FROM media '.
|
||||
'WHERE media.url = ?',
|
||||
's',
|
||||
$mediaUrl
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($mediaUrl);
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a Medium by its ID.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param int $seminaryId ID of the seminary
|
||||
* @param int $mediaId ID of the Medium
|
||||
* @return array Medium data
|
||||
*/
|
||||
public function getMediaById($mediaId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, name, url, description, mimetype '.
|
||||
'FROM media '.
|
||||
'WHERE media.id = ?',
|
||||
'i',
|
||||
$mediaId
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($mediaId);
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
424
models/QuestgroupsModel.inc
Normal file
424
models/QuestgroupsModel.inc
Normal file
|
|
@ -0,0 +1,424 @@
|
|||
<?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\models;
|
||||
|
||||
|
||||
/**
|
||||
* Model to interact with Questgroups-table.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class QuestgroupsModel extends \hhu\z\Model
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('questgroupshierarchy', 'quests');
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new QuestgroupsModel.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get all Questgroups for a Questgroup hierarchy.
|
||||
*
|
||||
* @param int $hierarchyId ID of the Questgroup hierarchy to get Questgroups for
|
||||
* @param int $parentQuestgroupId ID of the parent Questgroup hierarchy
|
||||
* @return array Questgroups for the given hierarchy
|
||||
*/
|
||||
public function getQuestgroupsForHierarchy($hierarchyId, $parentQuestgroupId=null)
|
||||
{
|
||||
// Get Questgroups
|
||||
$questgroups = array();
|
||||
if(is_null($parentQuestgroupId))
|
||||
{
|
||||
$questgroups = $this->db->query(
|
||||
'SELECT id, questgroupshierarchy_id, pos, title, url, questgroupspicture_id '.
|
||||
'FROM questgroups '.
|
||||
'WHERE questgroups.questgroupshierarchy_id = ? AND parent_questgroup_id IS NULL '.
|
||||
'ORDER BY questgroups.pos ASC',
|
||||
'i',
|
||||
$hierarchyId
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$questgroups = $this->db->query(
|
||||
'SELECT id, questgroupshierarchy_id, pos, title, url, questgroupspicture_id '.
|
||||
'FROM questgroups '.
|
||||
'WHERE questgroups.questgroupshierarchy_id = ? AND parent_questgroup_id = ? '.
|
||||
'ORDER BY questgroups.pos ASC',
|
||||
'ii',
|
||||
$hierarchyId, $parentQuestgroupId
|
||||
);
|
||||
}
|
||||
|
||||
// Add additional data
|
||||
foreach($questgroups as &$questgroup)
|
||||
{
|
||||
// Total XPs
|
||||
$questgroup['xps'] = $this->getAchievableXPsForQuestgroup($questgroup['id']);
|
||||
}
|
||||
|
||||
|
||||
// Return Questgroups
|
||||
return $questgroups;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a Questgroup by its ID.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param int $questgroupId ID of a Questgroup
|
||||
* @return array Questgroup data
|
||||
*/
|
||||
public function getQuestgroupById($questgroupId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, questgroupshierarchy_id, parent_questgroup_id, pos, title, url, questgroupspicture_id '.
|
||||
'FROM questgroups '.
|
||||
'WHERE questgroups.id = ?',
|
||||
'i',
|
||||
$questgroupId
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($questgroupId);
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a Questgroup by its URL.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param int $seminaryId ID of the corresponding seminary
|
||||
* @param string $questgroupURL URL-title of a Questgroup
|
||||
* @return array Questgroup data
|
||||
*/
|
||||
public function getQuestgroupByUrl($seminaryId, $questgroupUrl)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT questgroups.id, questgroups.questgroupshierarchy_id, questgroups.parent_questgroup_id, questgroups.pos, questgroups.title, questgroups.url, questgroups.questgroupspicture_id '.
|
||||
'FROM questgroups '.
|
||||
'LEFT JOIN questgroupshierarchy ON questgroupshierarchy.id = questgroups.questgroupshierarchy_id '.
|
||||
'WHERE questgroupshierarchy.seminary_id = ? AND questgroups.url = ?',
|
||||
'is',
|
||||
$seminaryId, $questgroupUrl
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($questgroupUrl);
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get texts of a Questgroup.
|
||||
*
|
||||
* @param int $questgroupId ID of a Questgroup
|
||||
* @return array Texts of this Questgroup
|
||||
*/
|
||||
public function getQuestgroupTexts($questgroupId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, pos, text '.
|
||||
'FROM questgrouptexts '.
|
||||
'WHERE questgroup_id = ? '.
|
||||
'ORDER BY pos ASC',
|
||||
'i',
|
||||
$questgroupId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get first texts of a Questgroup.
|
||||
*
|
||||
* @param int $questgroupId ID of a Questgroup
|
||||
* @return array First Text of this Questgroup
|
||||
*/
|
||||
public function getFirstQuestgroupText($questgroupId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, pos, text '.
|
||||
'FROM questgrouptexts '.
|
||||
'WHERE questgroup_id = ? '.
|
||||
'ORDER BY pos ASC '.
|
||||
'LIMIT 1',
|
||||
'i',
|
||||
$questgroupId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the next Questgroup.
|
||||
*
|
||||
* Determine the next Questgroup. If there is no next Questgroup
|
||||
* on the same level as the given Quest then the followed-up
|
||||
* Questgroup from a higher hierarchy level is returned.
|
||||
*
|
||||
* @param int $questgroupId ID of Questgroup to get next Questgroup of
|
||||
* @return array Questgroup data
|
||||
*/
|
||||
public function getNextQuestgroup($questgroupId)
|
||||
{
|
||||
$currentQuestgroup = $this->getQuestgroupById($questgroupId);
|
||||
$nextQuestgroup = $this->_getNextQuestgroup($currentQuestgroup['parent_questgroup_id'], $currentQuestgroup['pos']);
|
||||
while(is_null($nextQuestgroup) && !is_null($currentQuestgroup['parent_questgroup_id']))
|
||||
{
|
||||
$currentQuestgroup = $this->getQuestgroupById($currentQuestgroup['parent_questgroup_id']);
|
||||
$nextQuestgroup = $this->_getNextQuestgroup($currentQuestgroup['parent_questgroup_id'], $currentQuestgroup['pos']);
|
||||
}
|
||||
|
||||
|
||||
return $nextQuestgroup;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the previous Questgroup.
|
||||
*
|
||||
* Determine the previous Questgroup. If there is no previous
|
||||
* Questgroup on the same level as the given Quest then the
|
||||
* followed-up Questgroup from a higher hierarchy level is
|
||||
* returned.
|
||||
*
|
||||
* @param int $questgroupId ID of Questgroup to get previous Questgroup of
|
||||
* @return array Questgroup data
|
||||
*/
|
||||
public function getPreviousQuestgroup($questgroupId)
|
||||
{
|
||||
$currentQuestgroup = $this->getQuestgroupById($questgroupId);
|
||||
$previousQuestgroup = $this->_getPreviousQuestgroup($currentQuestgroup['parent_questgroup_id'], $currentQuestgroup['pos']);
|
||||
while(is_null($previousQuestgroup) && !is_null($currentQuestgroup['parent_questgroup_id']))
|
||||
{
|
||||
$currentQuestgroup = $this->getQuestgroupById($currentQuestgroup['parent_questgroup_id']);
|
||||
$previousQuestgroup = $this->_getPreviousQuestgroup($currentQuestgroup['parent_questgroup_id'], $currentQuestgroup['pos']);
|
||||
}
|
||||
|
||||
|
||||
return $previousQuestgroup;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine if the given Character has solved the Quests form
|
||||
* this Questgroup.
|
||||
*
|
||||
* @param int $questgroupId ID of Questgroup to check
|
||||
* @param int $characterId ID of Character to check
|
||||
* @result boolean Whether Character has solved the Questgroup or not
|
||||
*/
|
||||
public function hasCharacterSolvedQuestgroup($questgroupId, $characterId)
|
||||
{
|
||||
$currentQuestgroup = $this->getQuestgroupById($questgroupId);
|
||||
$childQuestgroupshierarchy = $this->Questgroupshierarchy->getChildQuestgroupshierarchy($currentQuestgroup['questgroupshierarchy_id']);
|
||||
$lastChildQuestgroupshierarchy = array_pop($childQuestgroupshierarchy);
|
||||
while(!is_null($lastChildQuestgroupshierarchy))
|
||||
{
|
||||
$questgroups = $this->getQuestgroupsForHierarchy($lastChildQuestgroupshierarchy['id'], $currentQuestgroup['id']);
|
||||
$currentQuestgroup = array_pop($questgroups);
|
||||
$childQuestgroupshierarchy = $this->Questgroupshierarchy->getChildQuestgroupshierarchy($currentQuestgroup['questgroupshierarchy_id']);
|
||||
$lastChildQuestgroupshierarchy = array_pop($childQuestgroupshierarchy);
|
||||
}
|
||||
|
||||
$quests = $this->Quests->getMainquestsForQuestgroup($currentQuestgroup['id']);
|
||||
$lastQuest = array_pop($quests);
|
||||
|
||||
|
||||
return $this->Quests->hasCharacterSolvedQuest($lastQuest['id'], $characterId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Summarize XPs of all Quests for a Questgroup and its
|
||||
* sub-Questgroups.
|
||||
*
|
||||
* @param int $questgroupId ID of Questgroup
|
||||
* @return Sum of XPs
|
||||
*/
|
||||
public function getAchievableXPsForQuestgroup($questgroupId)
|
||||
{
|
||||
// Sum of XPs
|
||||
$xps = 0;
|
||||
|
||||
// Current Questgroup
|
||||
$questgroup = $this->getQuestgroupById($questgroupId);
|
||||
|
||||
// Quests of current Questgroup
|
||||
$quests = $this->Quests->getMainquestsForQuestgroup($questgroup['id']);
|
||||
foreach($quests as &$quest) {
|
||||
$xps += $quest['xps'];
|
||||
}
|
||||
|
||||
// XPs of child Questgroups
|
||||
$childQuestgroupshierarchy = $this->Questgroupshierarchy->getChildQuestgroupshierarchy($questgroup['questgroupshierarchy_id']);
|
||||
foreach($childQuestgroupshierarchy as &$hierarchy)
|
||||
{
|
||||
$questgroups = $this->getQuestgroupsForHierarchy($hierarchy['id'], $questgroup['id']);
|
||||
foreach($questgroups as &$questgroup) {
|
||||
$xps += $this->getAchievableXPsForQuestgroup($questgroup['id']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Return summarized XPs
|
||||
return $xps;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Summarize XPs of all Quests for a Questgroup and its
|
||||
* sub-Questgroups solved by a Character.
|
||||
*
|
||||
* @param int $questgroupId ID of Questgroup
|
||||
* @param int $characterId ID of Character
|
||||
* @return Sum of XPs
|
||||
*/
|
||||
public function getAchievedXPsForQuestgroup($questgroupId, $characterId)
|
||||
{
|
||||
// Sum of XPs
|
||||
$xps = 0;
|
||||
|
||||
// Current Questgroup
|
||||
$questgroup = $this->getQuestgroupById($questgroupId);
|
||||
|
||||
// Quests of current Questgroup
|
||||
$quests = $this->Quests->getMainquestsForQuestgroup($questgroup['id']);
|
||||
foreach($quests as &$quest)
|
||||
{
|
||||
if($this->Quests->hasCharacterSolvedQuest($quest['id'], $characterId)) {
|
||||
$xps += $quest['xps'];
|
||||
}
|
||||
}
|
||||
|
||||
// XPs of child Questgroups
|
||||
$childQuestgroupshierarchy = $this->Questgroupshierarchy->getChildQuestgroupshierarchy($questgroup['questgroupshierarchy_id']);
|
||||
foreach($childQuestgroupshierarchy as &$hierarchy)
|
||||
{
|
||||
$questgroups = $this->getQuestgroupsForHierarchy($hierarchy['id'], $questgroup['id']);
|
||||
foreach($questgroups as &$questgroup) {
|
||||
$xps += $this->getAchievedXPsForQuestgroup($questgroup['id'], $characterId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Return summarized XPs
|
||||
return $xps;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the next (direct) Questgroup.
|
||||
*
|
||||
* @param int $parentQuestgroupId ID of parent Questgroup to get next Questgroup of
|
||||
* @param int $questgroupPos Position of Questgroup to get next Questgroup of
|
||||
* @return array Data of next Questgroup or NULL
|
||||
*/
|
||||
private function _getNextQuestgroup($parentQuestgroupId, $questgroupPos)
|
||||
{
|
||||
if(!is_null($parentQuestgroupId))
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT * '.
|
||||
'FROM questgroups '.
|
||||
'WHERE parent_questgroup_id = ? AND pos = ? + 1',
|
||||
'ii',
|
||||
$parentQuestgroupId, $questgroupPos
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT * '.
|
||||
'FROM questgroups '.
|
||||
'WHERE parent_questgroup_id IS NULL AND pos = ? + 1',
|
||||
'i',
|
||||
$questgroupPos
|
||||
);
|
||||
}
|
||||
if(empty($data)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the previous (direct) Questgroup.
|
||||
*
|
||||
* @param int $parentQuestgroupId ID of parent Questgroup to get previous Questgroup of
|
||||
* @param int $questgroupPos Position of Questgroup to get previous Questgroup of
|
||||
* @return array Data of previous Questgroup or NULL
|
||||
*/
|
||||
private function _getPreviousQuestgroup($parentQuestgroupId, $questgroupPos)
|
||||
{
|
||||
if(!is_null($parentQuestgroupId))
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT * '.
|
||||
'FROM questgroups '.
|
||||
'WHERE parent_questgroup_id = ? AND pos = ? - 1',
|
||||
'ii',
|
||||
$parentQuestgroupId, $questgroupPos
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT * '.
|
||||
'FROM questgroups '.
|
||||
'WHERE parent_questgroup_id IS NULL AND pos = ? - 1',
|
||||
'i',
|
||||
$questgroupPos
|
||||
);
|
||||
}
|
||||
if(empty($data)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
103
models/QuestgroupshierarchyModel.inc
Normal file
103
models/QuestgroupshierarchyModel.inc
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
<?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\models;
|
||||
|
||||
|
||||
/**
|
||||
* Model to interact with Questgroupshierarchy-table.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class QuestgroupshierarchyModel extends \hhu\z\Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new QuestgroupshierarchyModel.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get a Questgroup hierarchy by its ID.
|
||||
*
|
||||
* throws IdNotFoundException
|
||||
* @param int $questgroupshierarchyId ID of a Questgroup hierarchy
|
||||
* @return array Questgroup hierarchy
|
||||
*/
|
||||
public function getHierarchyById($questgroupshierarchyId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, seminary_id, parent_questgroupshierarchy_id, pos, title_singular, title_plural, url '.
|
||||
'FROM questgroupshierarchy '.
|
||||
'WHERE questgroupshierarchy.id = ?',
|
||||
'i',
|
||||
$questgroupshierarchyId
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($questgroupshierarchyId);
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the toplevel hierarchy entries of a Seminary.
|
||||
*
|
||||
* @param int $seminaryId ID of the seminary to get hierarchy for
|
||||
* @return array Toplevel hierarchy
|
||||
*/
|
||||
public function getHierarchyForSeminary($seminaryId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, seminary_id, parent_questgroupshierarchy_id, pos, title_singular, title_plural, url '.
|
||||
'FROM questgroupshierarchy '.
|
||||
'WHERE '.
|
||||
'questgroupshierarchy.seminary_id = ? AND '.
|
||||
'questgroupshierarchy.parent_questgroupshierarchy_id IS NULL '.
|
||||
'ORDER BY questgroupshierarchy.pos ASC',
|
||||
'i',
|
||||
$seminaryId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the child hierarchy entries of a Questgroup hierarchy.
|
||||
*
|
||||
* @param int $questgroupshierarchyId ID of a Questgroup hierarchy
|
||||
* @return array Child Questgroup hierarchy entries
|
||||
*/
|
||||
public function getChildQuestgroupshierarchy($questgroupshierarchyId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, seminary_id, parent_questgroupshierarchy_id, pos, title_singular, title_plural, url '.
|
||||
'FROM questgroupshierarchy '.
|
||||
'WHERE questgroupshierarchy.parent_questgroupshierarchy_id = ? '.
|
||||
'ORDER BY questgroupshierarchy.pos ASC',
|
||||
'i',
|
||||
$questgroupshierarchyId
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
344
models/QuestsModel.inc
Normal file
344
models/QuestsModel.inc
Normal file
|
|
@ -0,0 +1,344 @@
|
|||
<?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\models;
|
||||
|
||||
|
||||
/**
|
||||
* Model to interact with Quests-table.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class QuestsModel extends \hhu\z\Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new QuestsModel.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get all Quests for the given Questgroup.
|
||||
*
|
||||
* @param int $questgroupId ID of a Questgroup
|
||||
* @return array Quests of the given Questgroup
|
||||
*/
|
||||
public function getMainquestsForQuestgroup($questgroupId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, questtype_id, title, url, xps, task '.
|
||||
'FROM quests '.
|
||||
'INNER JOIN mainquests ON mainquests.quest_id = quests.id '.
|
||||
'WHERE questgroup_id = ?',
|
||||
'i',
|
||||
$questgroupId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a Quest and its data by its URL.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param int $seminaryId ID of the corresponding Seminary
|
||||
* @param int $questgroupId ID of the corresponding Questgroup
|
||||
* @param string $questURL URL-title of a Quest
|
||||
* @return array Quest data
|
||||
*/
|
||||
public function getQuestByUrl($seminaryId, $questgroupId, $questUrl)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT quests.id, quests.questtype_id, quests.title, quests.url, quests.xps, quests.task, quests.right_text, quests.wrong_text, quests.questsmedia_id, ('.
|
||||
'SELECT count(mainquests.quest_id) FROM mainquests WHERE mainquests.quest_id = quests.id) AS is_mainquest '.
|
||||
'FROM quests '.
|
||||
'LEFT JOIN questgroups ON questgroups.id = quests.questgroup_id '.
|
||||
'LEFT JOIN questgroupshierarchy ON questgroupshierarchy.id = questgroups.questgroupshierarchy_id '.
|
||||
'WHERE questgroupshierarchy.seminary_id = ? AND questgroups.id = ? AND quests.url = ?',
|
||||
'iis',
|
||||
$seminaryId, $questgroupId, $questUrl
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($questUrl);
|
||||
}
|
||||
|
||||
$data[0]['is_mainquest'] = ($data[0]['is_mainquest'] == 1);
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a Quest and its data by its ID.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param string $questId ID of a Quest
|
||||
* @return array Quest data
|
||||
*/
|
||||
public function getQuestById($questId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT quests.id, quests.questtype_id, quests.title, quests.url, quests.xps, quests.task, quests.right_text, quests.wrong_text, quests.questsmedia_id, ('.
|
||||
'SELECT count(mainquests.quest_id) FROM mainquests WHERE mainquests.quest_id = quests.id) AS is_mainquest '.
|
||||
'FROM quests '.
|
||||
'LEFT JOIN questgroups ON questgroups.id = quests.questgroup_id '.
|
||||
'LEFT JOIN questgroupshierarchy ON questgroupshierarchy.id = questgroups.questgroupshierarchy_id '.
|
||||
'WHERE quests.id = ?',
|
||||
'i',
|
||||
$questId
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($questId);
|
||||
}
|
||||
|
||||
$data[0]['is_mainquest'] = ($data[0]['is_mainquest'] == 1);
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a Sidequest and its data by its URL.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param int $seminaryId ID of the corresponding Seminary
|
||||
* @param int $questgroupId ID of the corresponding Questgroup
|
||||
* @param int $questId ID of the Quest
|
||||
* @param string $sidequestUrl URL-title of a Sidequest
|
||||
* @return array Sidequest data
|
||||
*/
|
||||
public function getSidequestByUrl($seminaryId, $questgroupId, $questId, $sidequestUrl)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT quests.id, quests.questtype_id, quests.title, quests.url, quests.xps, quests.task, quests.right_text, quests.wrong_text, quests.questsmedia_id '.
|
||||
'FROM quests '.
|
||||
'INNER JOIN sidequests ON sidequests.quest_id = quests.id '.
|
||||
'LEFT JOIN questtexts ON questtexts.id = sidequests.questtext_id '.
|
||||
'LEFT JOIN mainquests ON mainquests.quest_id = questtexts.mainquest_id '.
|
||||
'LEFT JOIN questgroups ON questgroups.id = quests.questgroup_id '.
|
||||
'LEFT JOIN questgroupshierarchy ON questgroupshierarchy.id = questgroups.questgroupshierarchy_id '.
|
||||
'LEFT JOIN seminaries ON seminaries.id = questgroupshierarchy.seminary_id '.
|
||||
'WHERE quests.url = ? AND mainquests.id = ? AND questgroups.id = ? AND seminaries.id = ?',
|
||||
'siii',
|
||||
$sidequestUrl,
|
||||
$questId,
|
||||
$questgroupId,
|
||||
$seminaryId
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($sidequestUrl);
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all sidequests for a Quest.
|
||||
*
|
||||
* @param int $questId ID of the quest
|
||||
* @return array Sidequests for the quest
|
||||
*/
|
||||
public function getSidequestsForQuest($questId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT quests.id, sidequests.questtext_id, quests.title, quests.url, sidequests.entry_text '.
|
||||
'FROM quests '.
|
||||
'INNER JOIN sidequests ON sidequests.quest_id = quests.id '.
|
||||
'LEFT JOIN questtexts ON questtexts.id = sidequests.questtext_id '.
|
||||
'WHERE questtexts.quest_id = ?',
|
||||
'i',
|
||||
$questId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all sidequests for a Questtext.
|
||||
*
|
||||
* @param int $questtextId ID of the questtext
|
||||
* @return array Sidequests for the questtext
|
||||
*/
|
||||
public function getSidequestsForQuesttext($questtextId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, questtext_id, title, url, entry_text '.
|
||||
'FROM quests '.
|
||||
'INNER JOIN sidequests ON sidequests.quest_id = quests.id '.
|
||||
'WHERE questtext_id = ?',
|
||||
'i',
|
||||
$questtextId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Quests that follow-up a Quest.
|
||||
*
|
||||
* @param int $questId ID of Quest to get next Quests of
|
||||
* @return array Quests data
|
||||
*/
|
||||
public function getNextQuests($questId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT quests.id, quests.title, quests.url, questgroups.title AS questgroup_title, questgroups.url AS questgroup_url '.
|
||||
'FROM mainquests_previousmainquests '.
|
||||
'LEFT JOIN mainquests ON mainquests.quest_id = mainquests_previousmainquests.mainquest_id '.
|
||||
'INNER JOIN quests ON quests.id = mainquests.quest_id '.
|
||||
'LEFT JOIN questgroups ON questgroups.id = quests.questgroup_id '.
|
||||
'LEFT JOIN questgroupshierarchy ON questgroupshierarchy.id = questgroups.questgroupshierarchy_id '.
|
||||
'WHERE mainquests_previousmainquests.previous_mainquest_id = ?',
|
||||
'i',
|
||||
$questId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Quests that the given Quests follows-up to.
|
||||
*
|
||||
* @param int $questId ID of Quest to get previous Quests of
|
||||
* @return array Quests data
|
||||
*/
|
||||
public function getPreviousQuests($questId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT quests.id, quests.title, quests.url, questgroups.title AS questgroup_title, questgroups.url AS questgroup_url '.
|
||||
'FROM mainquests_previousmainquests '.
|
||||
'LEFT JOIN mainquests ON mainquests.quest_id = mainquests_previousmainquests.previous_mainquest_id '.
|
||||
'INNER JOIN quests ON quests.id = mainquests.quest_id '.
|
||||
'LEFT JOIN questgroups ON questgroups.id = quests.questgroup_id '.
|
||||
'LEFT JOIN questgroupshierarchy ON questgroupshierarchy.id = questgroups.questgroupshierarchy_id '.
|
||||
'WHERE mainquests_previousmainquests.mainquest_id = ?',
|
||||
'i',
|
||||
$questId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Mark a Quest as solved for a Character.
|
||||
*
|
||||
* @param int $questId ID of Quest to mark as solved
|
||||
* @param int $characterId ID of Character that solved the Quest
|
||||
*/
|
||||
public function setQuestSolved($questId, $characterId)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO quests_characters '.
|
||||
'(quest_id, character_id, status) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?)',
|
||||
'iii',
|
||||
$questId,
|
||||
$characterId,
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Mark a Quest as unsolved for a Character.
|
||||
*
|
||||
* @param int $questId ID of Quest to mark as unsolved
|
||||
* @param int $characterId ID of Character that unsolved the Quest
|
||||
*/
|
||||
public function setQuestUnsolved($questId, $characterId)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO quests_characters '.
|
||||
'(quest_id, character_id, status) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?)',
|
||||
'iii',
|
||||
$questId,
|
||||
$characterId,
|
||||
-1
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine if the given Character has solved the given Quest.
|
||||
*
|
||||
* @param int $questId ID of Quest to check
|
||||
* @param int $characterId ID of Character to check
|
||||
* @result boolean Whether Character has solved the Quest or not
|
||||
*/
|
||||
public function hasCharacterSolvedQuest($questId, $characterId)
|
||||
{
|
||||
$count = $this->db->query(
|
||||
'SELECT count(id) AS c '.
|
||||
'FROM quests_characters '.
|
||||
'WHERE quest_id = ? AND character_id = ? AND status = 0',
|
||||
'ii',
|
||||
$questId,
|
||||
$characterId
|
||||
);
|
||||
|
||||
|
||||
return (!empty($count) && intval($count[0]['c']) > 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Characters that solved a Quest.
|
||||
*
|
||||
* @param int $questId ID of Quest to get Characters for
|
||||
* @return array Characters data
|
||||
*/
|
||||
public function getCharactersSolvedQuest($questId)
|
||||
{
|
||||
return $data = $this->db->query(
|
||||
'SELECT character_id, created, text '.
|
||||
'FROM questtypes_submit_characters '.
|
||||
'WHERE quest_id = ? AND EXISTS ('.
|
||||
'SELECT character_id FROM quests_characters WHERE quest_id = questtypes_submit_characters.quest_id AND status = 0'.
|
||||
')',
|
||||
'i',
|
||||
$questId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Characters that did not solved a Quest.
|
||||
*
|
||||
* @param int $questId ID of Quest to get Characters for
|
||||
* @return array Characters data
|
||||
*/
|
||||
public function getCharactersUnsolvedQuest($questId)
|
||||
{
|
||||
return $data = $this->db->query(
|
||||
'SELECT character_id, created, text '.
|
||||
'FROM questtypes_submit_characters '.
|
||||
'WHERE quest_id = ? AND NOT EXISTS ('.
|
||||
'SELECT character_id FROM quests_characters WHERE quest_id = questtypes_submit_characters.quest_id AND status = 0'.
|
||||
')',
|
||||
'i',
|
||||
$questId
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
135
models/QuesttextsModel.inc
Normal file
135
models/QuesttextsModel.inc
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
<?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\models;
|
||||
|
||||
|
||||
/**
|
||||
* Model to interact with Questtexts-table.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class QuesttextsModel extends \hhu\z\Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new QuesttextsModel.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get a Questtext for a Quest by its URL.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param int $questId ID of the Quest to get text for
|
||||
* @param string $questtexttypeUrl URL of the Questtexttype
|
||||
* @param int $pos Position of Questtexttype
|
||||
* @return array Questtexttype data
|
||||
*/
|
||||
public function getQuesttextByUrl($questId, $questtexttypeUrl, $pos)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT questtexts.id, questtexts.text, questtexts.pos, questtexts.out_text, questtexts.abort_text, questtexts.questsmedia_id, questtexttypes.id AS type_id, questtexttypes.type, questtexttypes.url AS type_url '.
|
||||
'FROM questtexts '.
|
||||
'LEFT JOIN questtexttypes ON questtexttypes.id = questtexts.questtexttype_id '.
|
||||
'WHERE questtexts.quest_id = ? AND questtexttypes.url = ? AND questtexts.pos = ?',
|
||||
'isi',
|
||||
$questId, $questtexttypeUrl, $pos
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($questtexttypeUrl);
|
||||
}
|
||||
|
||||
|
||||
return $data = $data[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get count of Questtexts for a Quest.
|
||||
*
|
||||
* @param int $questId ID of the Quest
|
||||
* @param string $questtexttypeUrl URL of the Questtexttype
|
||||
* @return int Conut of Questtexts for Quest
|
||||
*/
|
||||
public function getQuesttextsCountForQuest($questId, $questtexttypUrl)
|
||||
{
|
||||
$count = 0;
|
||||
$data = $this->db->query(
|
||||
'SELECT COUNT(questtexts.id) AS c '.
|
||||
'FROM questtexts '.
|
||||
'LEFT JOIN questtexttypes ON questtexttypes.id = questtexts.questtexttype_id '.
|
||||
'WHERE questtexts.quest_id = ? AND questtexttypes.url = ?',
|
||||
'is',
|
||||
$questId, $questtexttypUrl
|
||||
);
|
||||
if(!empty($data)) {
|
||||
$count = $data[0]['c'];
|
||||
}
|
||||
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get corresponding Questtext for a Sidequest.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param int $sidequestId ID of the Sidequest to get the Questtext for
|
||||
* @param array Questtext data
|
||||
*/
|
||||
public function getQuesttextForSidequest($sidequestId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT questtexts.id, questtexts.text, questtexts.pos, questtexts.quest_id, questtexttypes.id AS type_id, questtexttypes.type, questtexttypes.url AS type_url '.
|
||||
'FROM quests '.
|
||||
'INNER JOIN sidequests ON sidequests.quest_id = quests.id '.
|
||||
'LEFT JOIN questtexts ON questtexts.id = sidequests.questtext_id '.
|
||||
'LEFT JOIN questtexttypes ON questtexttypes.id = questtexts.questtexttype_id '.
|
||||
'WHERE quests.id = ?',
|
||||
'i',
|
||||
$sidequestId
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($sidequestId);
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all registered Questtexttypes.
|
||||
*
|
||||
* @return array Registered Questtexttypes
|
||||
*/
|
||||
public function getQuesttexttypes()
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, type, url '.
|
||||
'FROM questtexttypes'
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
62
models/QuesttypesModel.inc
Normal file
62
models/QuesttypesModel.inc
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
<?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\models;
|
||||
|
||||
|
||||
/**
|
||||
* Model to interact with Questtypes-table.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class QuesttypesModel extends \hhu\z\Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new QuesttypesModel.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get a Questtype by its ID
|
||||
*
|
||||
* @param int $questtypeId ID of Questtype
|
||||
* @return array Questtype data
|
||||
*/
|
||||
public function getQuesttypeById($questtypeId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT title, classname '.
|
||||
'FROM questtypes '.
|
||||
'WHERE id = ?',
|
||||
'i',
|
||||
$questtypeId
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($questtypeId);
|
||||
}
|
||||
|
||||
|
||||
return $data = $data[0];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
161
models/SeminariesModel.inc
Normal file
161
models/SeminariesModel.inc
Normal file
|
|
@ -0,0 +1,161 @@
|
|||
<?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\models;
|
||||
|
||||
|
||||
/**
|
||||
* Model of the SeminariesAgent to list registered seminaries.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class SeminariesModel extends \hhu\z\Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new SeminariesModel.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get registered seminaries.
|
||||
*
|
||||
* @return array Seminaries
|
||||
*/
|
||||
public function getSeminaries()
|
||||
{
|
||||
// Get seminaries
|
||||
return $this->db->query(
|
||||
'SELECT id, created, created_user_id, title, url, description '.
|
||||
'FROM seminaries '.
|
||||
'ORDER BY created DESC'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a seminary and its data by its ID.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param string $seminaryId ID of a seminary
|
||||
* @return array Seminary
|
||||
*/
|
||||
public function getSeminaryById($seminaryId)
|
||||
{
|
||||
$seminary = $this->db->query(
|
||||
'SELECT id, created, created_user_id, title, url, description '.
|
||||
'FROM seminaries '.
|
||||
'WHERE id = ?',
|
||||
'i',
|
||||
$seminaryId
|
||||
);
|
||||
if(empty($seminary)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($seminaryId);
|
||||
}
|
||||
|
||||
|
||||
return $seminary[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a seminary and its data by its URL-title.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param string $seminaryUrl URL-Title of a seminary
|
||||
* @return array Seminary
|
||||
*/
|
||||
public function getSeminaryByUrl($seminaryUrl)
|
||||
{
|
||||
$seminary = $this->db->query(
|
||||
'SELECT id, created, created_user_id, title, url, description '.
|
||||
'FROM seminaries '.
|
||||
'WHERE url = ?',
|
||||
's',
|
||||
$seminaryUrl
|
||||
);
|
||||
if(empty($seminary)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($seminaryUrl);
|
||||
}
|
||||
|
||||
|
||||
return $seminary[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new seminary.
|
||||
*
|
||||
* @param string $title Title of seminary to create
|
||||
* @param int $userId ID of creating user
|
||||
* @return int ID of the newly created seminary
|
||||
*/
|
||||
public function createSeminary($title, $userId)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO seminaries '.
|
||||
'(created_user_id, title, url) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?)',
|
||||
'iss',
|
||||
$userId,
|
||||
$title,
|
||||
\nre\core\Linker::createLinkParam($title)
|
||||
);
|
||||
|
||||
|
||||
return $this->db->getInsertId();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Edit a seminary.
|
||||
*
|
||||
* @throws DatamodelException
|
||||
* @param int $seminaryId ID of the seminary to delete
|
||||
* @param string $title New title of seminary
|
||||
*/
|
||||
public function editSeminary($seminaryId, $title)
|
||||
{
|
||||
$this->db->query(
|
||||
'UPDATE seminaries '.
|
||||
'SET title = ?, url = ? '.
|
||||
'WHERE id = ?',
|
||||
'ssi',
|
||||
$title,
|
||||
\nre\core\Linker::createLinkParam($title),
|
||||
$seminaryId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a seminary.
|
||||
*
|
||||
* @param int $seminaryId ID of the seminary to delete
|
||||
*/
|
||||
public function deleteSeminary($seminaryId)
|
||||
{
|
||||
$this->db->query('DELETE FROM seminaries WHERE id = ?', 'i', $seminaryId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
58
models/SeminarycharacterfieldsModel.inc
Normal file
58
models/SeminarycharacterfieldsModel.inc
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
<?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\models;
|
||||
|
||||
|
||||
/**
|
||||
* Model to interact with the Seminarycharacterfields-tables.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class SeminarycharacterfieldsModel extends \hhu\z\Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new SeminarycharacterfieldsModel.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get Seminary Character fields of a Character.
|
||||
*
|
||||
* @param int $characterId ID of the Character
|
||||
* @return array Seminary Character fields
|
||||
*/
|
||||
public function getFieldsForCharacter($characterId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT seminarycharacterfields.title, characters_seminarycharacterfields.value '.
|
||||
'FROM characters_seminarycharacterfields '.
|
||||
'LEFT JOIN seminarycharacterfields ON seminarycharacterfields.id = characters_seminarycharacterfields.seminarycharacterfield_id '.
|
||||
'LEFT JOIN seminarycharacterfieldtypes ON seminarycharacterfieldtypes.id = seminarycharacterfields.seminarycharacterfieldtype_id '.
|
||||
'WHERE characters_seminarycharacterfields.character_id = ?',
|
||||
'i',
|
||||
$characterId
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
77
models/UserrolesModel.inc
Normal file
77
models/UserrolesModel.inc
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
<?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\models;
|
||||
|
||||
|
||||
/**
|
||||
* Model to interact with userroles-table.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class UserrolesModel extends \hhu\z\Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new UserrolesModel.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get all userroles for an user referenced by its ID.
|
||||
*
|
||||
* @param int $userId ID of an user
|
||||
* @return array Userroles for an user
|
||||
*/
|
||||
public function getUserrolesForUserById($userId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT userroles.id, userroles.created, userroles.name '.
|
||||
'FROM users_userroles '.
|
||||
'LEFT JOIN userroles ON userroles.id = users_userroles.userrole_id '.
|
||||
'WHERE users_userroles.user_id = ?',
|
||||
'i',
|
||||
$userId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all userroles for an user referenced by its URL-username.
|
||||
*
|
||||
* @param string $userUrl URL-Username of an user
|
||||
* @return array Userroles for an user
|
||||
*/
|
||||
public function getUserrolesForUserByUrl($userUrl)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT userroles.id, userroles.created, userroles.name '.
|
||||
'FROM users '.
|
||||
'LEFT JOIN users_userroles ON users_userroles.user_id = users.id '.
|
||||
'LEFT JOIN userroles ON userroles.id = users_userroles.userrole_id '.
|
||||
'WHERE users.url = ?',
|
||||
's',
|
||||
$userUrl
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
249
models/UsersModel.inc
Normal file
249
models/UsersModel.inc
Normal file
|
|
@ -0,0 +1,249 @@
|
|||
<?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\models;
|
||||
|
||||
|
||||
/**
|
||||
* Model of the UsersAgent to list users and get their data.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class UsersModel extends \hhu\z\Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new UsersModel.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get registered users.
|
||||
*
|
||||
* @return array Users
|
||||
*/
|
||||
public function getUsers()
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, created, username, url, surname, prename, email '.
|
||||
'FROM users '.
|
||||
'ORDER BY username ASC'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a user and its data by its ID.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param int $userId ID of an user
|
||||
* @return array Userdata
|
||||
*/
|
||||
public function getUserById($userId)
|
||||
{
|
||||
// Get user
|
||||
$user = $this->db->query(
|
||||
'SELECT id, created, username, url, surname, prename, email '.
|
||||
'FROM users '.
|
||||
'WHERE id = ?',
|
||||
'i',
|
||||
$userId
|
||||
);
|
||||
if(empty($user)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($userId);
|
||||
}
|
||||
|
||||
|
||||
return $user[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a user and its data by its URL-username.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param string $userUrl URL-Username of an user
|
||||
* @return array Userdata
|
||||
*/
|
||||
public function getUserByUrl($userUrl)
|
||||
{
|
||||
// Get user
|
||||
$user = $this->db->query(
|
||||
'SELECT id, created, username, url, surname, prename, email '.
|
||||
'FROM users '.
|
||||
'WHERE url = ?',
|
||||
's',
|
||||
$userUrl
|
||||
);
|
||||
if(empty($user)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($userUrl);
|
||||
}
|
||||
|
||||
|
||||
return $user[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Log a user in if its credentials are valid.
|
||||
*
|
||||
* @throws DatamodelException
|
||||
* @param string $username The name of the user to log in
|
||||
* @param string $password Plaintext password of the user to log in
|
||||
*/
|
||||
public function login($username, $password)
|
||||
{
|
||||
$data = $this->db->query('SELECT id, password FROM users WHERE username = ?', 's', $username);
|
||||
if(!empty($data))
|
||||
{
|
||||
$data = $data[0];
|
||||
if($this->verify($password, $data['password'])) {
|
||||
return $data['id'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new user.
|
||||
*
|
||||
* @param string $username Username of the user to create
|
||||
* @param string $email E‑Mail-Address of the user to create
|
||||
* @param string $password Password of the user to create
|
||||
* @return int ID of the newly created user
|
||||
*/
|
||||
public function createUser($username, $email, $password)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO users '.
|
||||
'(username, url, email, password) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?, ?)',
|
||||
'ssss',
|
||||
$username,
|
||||
\nre\core\Linker::createLinkParam($username),
|
||||
$email,
|
||||
$this->hash($password)
|
||||
);
|
||||
|
||||
|
||||
return $this->db->getInsertId();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Edit a user.
|
||||
*
|
||||
* @throws DatamodelException
|
||||
* @param int $userId ID of the user to delete
|
||||
* @param string $username New name of user
|
||||
* @param string $email Changed e‑mail-address of user
|
||||
* @param string $password Changed plaintext password of user
|
||||
*/
|
||||
public function editUser($userId, $username, $email, $password)
|
||||
{
|
||||
try {
|
||||
// Update user data
|
||||
$this->db->query(
|
||||
'UPDATE users '.
|
||||
'SET username = ?, url = ?, email = ? '.
|
||||
'WHERE id = ?',
|
||||
'sssi',
|
||||
$username,
|
||||
\nre\core\Linker::createLinkParam($username),
|
||||
$email,
|
||||
$userId
|
||||
);
|
||||
|
||||
// Set new password
|
||||
if(!empty($password))
|
||||
{
|
||||
$this->db->query(
|
||||
'UPDATE users '.
|
||||
'SET password = ? '.
|
||||
'WHERE id = ?',
|
||||
'si',
|
||||
$this->hash($password),
|
||||
$userId
|
||||
);
|
||||
}
|
||||
}
|
||||
catch(Exception $e) {
|
||||
$this->db->rollback();
|
||||
$this->db->setAutocommit(true);
|
||||
throw $e;
|
||||
}
|
||||
$this->db->setAutocommit(true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a user.
|
||||
*
|
||||
* @param int $userId ID of the user to delete
|
||||
*/
|
||||
public function deleteUser($userId)
|
||||
{
|
||||
$this->db->query('DELETE FROM users WHERE id = ?', 'i', $userId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Hash a password.
|
||||
*
|
||||
* @param string $password Plaintext password
|
||||
* @return string Hashed password
|
||||
*/
|
||||
public function hash($password)
|
||||
{
|
||||
if(!function_exists('password_hash')) {
|
||||
\hhu\z\lib\Password::load();
|
||||
}
|
||||
|
||||
|
||||
return password_hash($password, PASSWORD_DEFAULT);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Verify a password.
|
||||
*
|
||||
* @param string $password Plaintext password to verify
|
||||
* @param string $hash Hashed password to match with
|
||||
* @return boolean Verified
|
||||
*/
|
||||
private function verify($password, $hash)
|
||||
{
|
||||
if(!function_exists('password_verify')) {
|
||||
\hhu\z\lib\Password::load();
|
||||
}
|
||||
|
||||
|
||||
return password_verify($password, $hash);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
78
models/UserseminaryrolesModel.inc
Normal file
78
models/UserseminaryrolesModel.inc
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
<?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\models;
|
||||
|
||||
|
||||
/**
|
||||
* Model to interact with userseminaryroles-table.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class UserseminaryrolesModel extends \hhu\z\Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new UserseminaryrolesModel.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get all userseminaryroles for an user referenced by its ID.
|
||||
*
|
||||
* @param int $userId ID of an user
|
||||
* @return array Userseminaryroles for an user
|
||||
*/
|
||||
public function getUserseminaryrolesForUserById($userId, $seminaryId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT userseminaryroles.id, userseminaryroles.created, userseminaryroles.name '.
|
||||
'FROM users_userseminaryroles '.
|
||||
'LEFT JOIN userseminaryroles ON userseminaryroles.id = users_userseminaryroles.userseminaryrole_id '.
|
||||
'WHERE users_userseminaryroles.user_id = ? AND users_userseminaryroles.seminary_id = ?',
|
||||
'ii',
|
||||
$userId, $seminaryId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all userseminaryroles for an user referenced by its
|
||||
* URL-username.
|
||||
*
|
||||
* @param string $userUrl URL-Username of an user
|
||||
* @return array Userseminaryroles for an user
|
||||
*/
|
||||
public function getUserrolesForUserByUrl($userUrl)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT userroles.id, userroles.created, userroles.name '.
|
||||
'FROM users '.
|
||||
'LEFT JOIN users_userseminaryroles ON users_userseminaryroles.user_id = users.id '.
|
||||
'LEFT JOIN userseminaryroles ON userseminaryroles.id = users_userseminaryroles.userseminaryrole_id '.
|
||||
'WHERE users.url = ?',
|
||||
's',
|
||||
$userUrl
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue