replace tabs with spaces
This commit is contained in:
parent
50c38e0efa
commit
c79f0f213b
176 changed files with 27652 additions and 27647 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -1,182 +1,182 @@
|
|||
<?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 Avatars-tables.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class AvatarsModel extends \hhu\z\Model
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('media');
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new AvatarsModel.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get an Avatar by its ID
|
||||
*
|
||||
* @param int $avatarId ID of Avatar
|
||||
* @return array Avatar data
|
||||
*/
|
||||
public function getAvatarById($avatarId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, charactertype_id, xplevel_id, avatarpicture_id, small_avatarpicture_id '.
|
||||
'FROM avatars '.
|
||||
'WHERE id = ?',
|
||||
'i',
|
||||
$avatarId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get an Avatar by its Character type and XP-level.
|
||||
*
|
||||
* @param int $seminaryId ID of Seminary
|
||||
* @param string $charactertypeUrl URL-title of Character type
|
||||
* @param int $xplevel XP-level
|
||||
* @return array Avatar data
|
||||
*/
|
||||
public function getAvatarByTypeAndLevel($seminaryId, $charactertypeUrl, $xplevel)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT avatars.id, charactertype_id, xplevel_id, avatarpicture_id, small_avatarpicture_id '.
|
||||
'FROM avatars '.
|
||||
'INNER JOIN charactertypes ON charactertypes.id = avatars.charactertype_id '.
|
||||
'INNER JOIN xplevels ON xplevels.id = avatars.xplevel_id AND xplevels.seminary_id = charactertypes.seminary_id '.
|
||||
'WHERE charactertypes.seminary_id = ? AND charactertypes.url = ? AND xplevels.level = ?',
|
||||
'isi',
|
||||
$seminaryId,
|
||||
$charactertypeUrl,
|
||||
$xplevel
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($charactertypeUrl);
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
/**
|
||||
* 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;
|
||||
|
||||
|
||||
/**
|
||||
* Get an Avatar by its Character type and XP-level.
|
||||
*
|
||||
* @param int $charactertypeId ID of Character type
|
||||
* @param int $xplevelId ID of XP-level
|
||||
* @return array Avatar data
|
||||
*/
|
||||
public function getAvatarByTypeAndLevelId($charactertypeId, $xplevelId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, charactertype_id, xplevel_id, avatarpicture_id, small_avatarpicture_id '.
|
||||
'FROM avatars '.
|
||||
'WHERE charactertype_id = ? AND xplevel_id = ?',
|
||||
'ii',
|
||||
$charactertypeId,
|
||||
$xplevelId
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($charactertypeId.'-'.$xplevelId);
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
/**
|
||||
* Model to interact with Avatars-tables.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class AvatarsModel extends \hhu\z\Model
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('media');
|
||||
|
||||
|
||||
/**
|
||||
* Set the picture for an Avatar.
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $charactertypeId ID of Charactertype of Avatar
|
||||
* @param int $xplevelId ID of XP-level of Avatar
|
||||
* @param int $avatarpictureId ID of Avatar picture to set
|
||||
*/
|
||||
public function setAvatarForTypeAndLevel($userId, $charactertypeId, $xplevelId, $avatarpictureId)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO avatars '.
|
||||
'(created_user_id, charactertype_id, xplevel_id, avatarpicture_id) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?, ?) '.
|
||||
'ON DUPLICATE KEY UPDATE '.
|
||||
'avatarpicture_id = ?',
|
||||
'iiiii',
|
||||
$userId,
|
||||
$charactertypeId,
|
||||
$xplevelId,
|
||||
$avatarpictureId,
|
||||
$avatarpictureId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the portrait picture for an Avatar.
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $charactertypeId ID of Charactertype of Avatar
|
||||
* @param int $xplevelId ID of XP-level of Avatar
|
||||
* @param int $avatarpictureId ID of Avatar portrait picture to set
|
||||
*/
|
||||
public function setAvatarPortraitForTypeAndLevel($userId, $charactertypeId, $xplevelId, $avatarpictureId)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO avatars '.
|
||||
'(created_user_id, charactertype_id, xplevel_id, small_avatarpicture_id) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?, ?) '.
|
||||
'ON DUPLICATE KEY UPDATE '.
|
||||
'small_avatarpicture_id = ?',
|
||||
'iiiii',
|
||||
$userId,
|
||||
$charactertypeId,
|
||||
$xplevelId,
|
||||
$avatarpictureId,
|
||||
$avatarpictureId
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Construct a new AvatarsModel.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get an Avatar by its ID
|
||||
*
|
||||
* @param int $avatarId ID of Avatar
|
||||
* @return array Avatar data
|
||||
*/
|
||||
public function getAvatarById($avatarId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, charactertype_id, xplevel_id, avatarpicture_id, small_avatarpicture_id '.
|
||||
'FROM avatars '.
|
||||
'WHERE id = ?',
|
||||
'i',
|
||||
$avatarId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get an Avatar by its Character type and XP-level.
|
||||
*
|
||||
* @param int $seminaryId ID of Seminary
|
||||
* @param string $charactertypeUrl URL-title of Character type
|
||||
* @param int $xplevel XP-level
|
||||
* @return array Avatar data
|
||||
*/
|
||||
public function getAvatarByTypeAndLevel($seminaryId, $charactertypeUrl, $xplevel)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT avatars.id, charactertype_id, xplevel_id, avatarpicture_id, small_avatarpicture_id '.
|
||||
'FROM avatars '.
|
||||
'INNER JOIN charactertypes ON charactertypes.id = avatars.charactertype_id '.
|
||||
'INNER JOIN xplevels ON xplevels.id = avatars.xplevel_id AND xplevels.seminary_id = charactertypes.seminary_id '.
|
||||
'WHERE charactertypes.seminary_id = ? AND charactertypes.url = ? AND xplevels.level = ?',
|
||||
'isi',
|
||||
$seminaryId,
|
||||
$charactertypeUrl,
|
||||
$xplevel
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($charactertypeUrl);
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get an Avatar by its Character type and XP-level.
|
||||
*
|
||||
* @param int $charactertypeId ID of Character type
|
||||
* @param int $xplevelId ID of XP-level
|
||||
* @return array Avatar data
|
||||
*/
|
||||
public function getAvatarByTypeAndLevelId($charactertypeId, $xplevelId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, charactertype_id, xplevel_id, avatarpicture_id, small_avatarpicture_id '.
|
||||
'FROM avatars '.
|
||||
'WHERE charactertype_id = ? AND xplevel_id = ?',
|
||||
'ii',
|
||||
$charactertypeId,
|
||||
$xplevelId
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($charactertypeId.'-'.$xplevelId);
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the picture for an Avatar.
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $charactertypeId ID of Charactertype of Avatar
|
||||
* @param int $xplevelId ID of XP-level of Avatar
|
||||
* @param int $avatarpictureId ID of Avatar picture to set
|
||||
*/
|
||||
public function setAvatarForTypeAndLevel($userId, $charactertypeId, $xplevelId, $avatarpictureId)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO avatars '.
|
||||
'(created_user_id, charactertype_id, xplevel_id, avatarpicture_id) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?, ?) '.
|
||||
'ON DUPLICATE KEY UPDATE '.
|
||||
'avatarpicture_id = ?',
|
||||
'iiiii',
|
||||
$userId,
|
||||
$charactertypeId,
|
||||
$xplevelId,
|
||||
$avatarpictureId,
|
||||
$avatarpictureId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the portrait picture for an Avatar.
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $charactertypeId ID of Charactertype of Avatar
|
||||
* @param int $xplevelId ID of XP-level of Avatar
|
||||
* @param int $avatarpictureId ID of Avatar portrait picture to set
|
||||
*/
|
||||
public function setAvatarPortraitForTypeAndLevel($userId, $charactertypeId, $xplevelId, $avatarpictureId)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO avatars '.
|
||||
'(created_user_id, charactertype_id, xplevel_id, small_avatarpicture_id) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?, ?) '.
|
||||
'ON DUPLICATE KEY UPDATE '.
|
||||
'small_avatarpicture_id = ?',
|
||||
'iiiii',
|
||||
$userId,
|
||||
$charactertypeId,
|
||||
$xplevelId,
|
||||
$avatarpictureId,
|
||||
$avatarpictureId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copy all Avatars from a Seminary.
|
||||
*
|
||||
*
|
||||
* @param int $userId ID of copying user
|
||||
* @param array $charactertypeIds Mapping of Charactertype-IDs from source Seminary to target Seminary
|
||||
* @param array $xplevelIds Mapping of XP-level-IDs from source Seminary to targetSeminary
|
||||
|
|
@ -217,7 +217,7 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,383 +1,383 @@
|
|||
<?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
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('uploads', 'media');
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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, xps, questsmedia_id '.
|
||||
'FROM charactergroupsquests '.
|
||||
'WHERE charactergroupsgroup_id = ? '.
|
||||
'ORDER BY created ASC',
|
||||
'i',
|
||||
$groupsgroupId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a Character groups Quest by its URL.
|
||||
*
|
||||
* @throws \nre\exceptions\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 a Character groups Quest by its ID.
|
||||
*
|
||||
* @throws \nre\exceptions\IdNotFoundException
|
||||
* @param int $questId ID of the Character groups Quest
|
||||
* @return array Character groups Quest data
|
||||
*/
|
||||
public function getQuestById($questId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, questgroups_id, title, url, description, xps, rules, won_text, lost_text, questsmedia_id '.
|
||||
'FROM charactergroupsquests '.
|
||||
'WHERE id = ?',
|
||||
'i',
|
||||
$questId
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($questUrl);
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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 = ? '.
|
||||
'ORDER BY charactergroupsquests.created ASC',
|
||||
'i',
|
||||
$groupId
|
||||
);
|
||||
foreach($quests as &$quest) {
|
||||
$quest['group_xps'] = round($quest['xps'] * $quest['xps_factor'], 1);
|
||||
}
|
||||
|
||||
|
||||
return $quests;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get XPs of a Character group for a Character groups Quest.
|
||||
*
|
||||
* @param int $questId ID of Character groups Quest
|
||||
* @param int $groupId ID of Character group to get XPs of
|
||||
* @return array XP-record
|
||||
*/
|
||||
public function getXPsOfGroupForQuest($questId, $groupId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT charactergroupsquests_groups.created, charactergroupsquests_groups.xps_factor, charactergroupsquests.xps '.
|
||||
'FROM charactergroupsquests_groups '.
|
||||
'LEFT JOIN charactergroupsquests ON charactergroupsquests.id = charactergroupsquests_groups.charactergroupsquest_id '.
|
||||
'WHERE charactergroupsquests_groups.charactergroupsquest_id = ? AND charactergroupsquests_groups.charactergroup_id = ?',
|
||||
'ii',
|
||||
$questId,
|
||||
$groupId
|
||||
);
|
||||
if(empty($data)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$data = $data[0];
|
||||
$data['xps'] = round($data['xps'] * $data['xps_factor'], 1);
|
||||
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set XPs of a Character group for a Character groups Quest.
|
||||
*
|
||||
* @param int $questId ID of Character groups Quest
|
||||
* @param int $groupId ID of Character group to set XPs of
|
||||
* @param float $xpsFactor XPs-factor
|
||||
*/
|
||||
public function setXPsOfGroupForQuest($questId, $groupId, $xpsFactor)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO charactergroupsquests_groups '.
|
||||
'(charactergroupsquest_id, charactergroup_id, xps_factor) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?) '.
|
||||
'ON DUPLICATE KEY UPDATE '.
|
||||
'xps_factor = ?',
|
||||
'iidd',
|
||||
$questId,
|
||||
$groupId,
|
||||
$xpsFactor,
|
||||
$xpsFactor
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove a Character group from a Character groups Quest.
|
||||
*
|
||||
* @param int $questId ID of Character groups Quest
|
||||
* @param int $groupId ID of Character group to remove
|
||||
*/
|
||||
public function deleteGroupForQuest($questId, $groupId)
|
||||
{
|
||||
$this->db->query(
|
||||
'DELETE FROM charactergroupsquests_groups '.
|
||||
'WHERE charactergroupsquest_id = ? AND charactergroup_id = ?',
|
||||
'ii',
|
||||
$questId, $groupId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if a Character groups Quest title already exists.
|
||||
*
|
||||
* @param string $name Character groups Quest title to check
|
||||
* @param int $questId Do not check this ID (for editing)
|
||||
* @return boolean Whether Character groups Quest title exists or not
|
||||
*/
|
||||
public function characterGroupsQuestTitleExists($title, $questId=null)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id '.
|
||||
'FROM charactergroupsquests '.
|
||||
'WHERE title = ? OR url = ?',
|
||||
'ss',
|
||||
$title,
|
||||
\nre\core\Linker::createLinkParam($title)
|
||||
);
|
||||
|
||||
return (!empty($data) && (is_null($questId) || $questId != $data[0]['id']));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the media for a Character groups Quest.
|
||||
*
|
||||
* @param int $questId ID of Quest to upload media for
|
||||
* @param int $mediaId ID of Quests media
|
||||
*/
|
||||
public function setMediaForQuest($questId, $mediaId)
|
||||
{
|
||||
$this->db->query(
|
||||
'UPDATE charactergroupsquests '.
|
||||
'SET questsmedia_id = ? '.
|
||||
'WHERE id = ?',
|
||||
'ii',
|
||||
$mediaId,
|
||||
$questId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Upload a media for a Character groups Quest.
|
||||
*
|
||||
* @param int $userId ID of user that does the upload
|
||||
* @param int $seminaryId ID of Seminary
|
||||
* @param int $questId ID of Quest to upload media for
|
||||
* @param array $file File-array of file to upload
|
||||
* @param string $filename Filename for media
|
||||
* @return boolean Whether upload succeeded or not
|
||||
*/
|
||||
public function uploadMediaForQuest($userId, $seminaryId, $questId, $file, $filename)
|
||||
{
|
||||
// Save file on harddrive
|
||||
$uploadId = $this->Uploads->uploadSeminaryFile($userId, $seminaryId, $file['name'], $filename, $file['tmp_name'], $file['type']);
|
||||
if($uploadId === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create database record
|
||||
$this->db->query(
|
||||
'INSERT INTO charactergroupsquests_seminaryuploads '.
|
||||
'(seminaryupload_id, charactergroupsquest_id, created_user_id) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?) ',
|
||||
'iii',
|
||||
$uploadId, $questId, $userId
|
||||
);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get uploaded Medai for a Character groups Quest.
|
||||
*
|
||||
* @param int $questId ID of Quest to get media for
|
||||
* @return array Seminary uploads
|
||||
*/
|
||||
public function getMediaForQuest($questId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT seminaryupload_id, created, created_user_id '.
|
||||
'FROM charactergroupsquests_seminaryuploads '.
|
||||
'WHERE charactergroupsquest_id = ?',
|
||||
'i',
|
||||
$questId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new Character groups Quest.
|
||||
*
|
||||
* @param int $userId ID of user
|
||||
* @param int $groupsgroupId ID of Character groups-group
|
||||
* @param int $questgroupId ID of Quest group
|
||||
* @param string $title Title of new Quest
|
||||
* @param string $description Description of new Quset
|
||||
* @param int $xps Amount of XPs for new Quest
|
||||
* @param string $rules Rules of new Quest
|
||||
* @param string $wonText Won-text of new Quset
|
||||
* @param string $lostText Lost-text of new Quest
|
||||
* @return int ID of newly created Quest
|
||||
*/
|
||||
public function createQuest($userId, $groupsgroupId, $questgroupId, $title, $description, $xps, $rules, $wonText, $lostText)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO charactergroupsquests '.
|
||||
'(created_user_id, charactergroupsgroup_id, questgroups_id, title, url, description, xps, rules, won_text, lost_text) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
|
||||
'iiisssdsss',
|
||||
$userId,
|
||||
$groupsgroupId,
|
||||
$questgroupId,
|
||||
$title,
|
||||
\nre\core\Linker::createLinkParam($title),
|
||||
$description,
|
||||
$xps,
|
||||
$rules,
|
||||
$wonText,
|
||||
$lostText
|
||||
);
|
||||
|
||||
|
||||
return $this->db->getInsertId();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Edit a Character groups Quest.
|
||||
*
|
||||
* @param int $questId ID of Character groups Quest to edit
|
||||
* @param int $groupsgroupId ID of Character groups-group
|
||||
* @param int $questgroupId ID of Quest group
|
||||
* @param string $title Title of new Quest
|
||||
* @param string $description Description of new Quset
|
||||
* @param int $xps Amount of XPs for new Quest
|
||||
* @param string $rules Rules of new Quest
|
||||
* @param string $wonText Won-text of new Quset
|
||||
* @param string $lostText Lost-text of new Quest
|
||||
*/
|
||||
public function editQuest($questId, $groupsgroupId, $questgroupId, $title, $description, $xps, $rules, $wonText, $lostText)
|
||||
{
|
||||
$this->db->query(
|
||||
'UPDATE charactergroupsquests '.
|
||||
'SET charactergroupsgroup_id = ?, questgroups_id = ?, title = ?, url = ?, description = ?, xps = ?, rules = ?, won_text = ?, lost_text= ? '.
|
||||
'WHERE id = ?',
|
||||
'iisssdsssi',
|
||||
$groupsgroupId,
|
||||
$questgroupId,
|
||||
$title,
|
||||
\nre\core\Linker::createLinkParam($title),
|
||||
$description,
|
||||
$xps,
|
||||
$rules,
|
||||
$wonText,
|
||||
$lostText,
|
||||
$questId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('uploads', 'media');
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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, xps, questsmedia_id '.
|
||||
'FROM charactergroupsquests '.
|
||||
'WHERE charactergroupsgroup_id = ? '.
|
||||
'ORDER BY created ASC',
|
||||
'i',
|
||||
$groupsgroupId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a Character groups Quest by its URL.
|
||||
*
|
||||
* @throws \nre\exceptions\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 a Character groups Quest by its ID.
|
||||
*
|
||||
* @throws \nre\exceptions\IdNotFoundException
|
||||
* @param int $questId ID of the Character groups Quest
|
||||
* @return array Character groups Quest data
|
||||
*/
|
||||
public function getQuestById($questId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, questgroups_id, title, url, description, xps, rules, won_text, lost_text, questsmedia_id '.
|
||||
'FROM charactergroupsquests '.
|
||||
'WHERE id = ?',
|
||||
'i',
|
||||
$questId
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($questUrl);
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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 = ? '.
|
||||
'ORDER BY charactergroupsquests.created ASC',
|
||||
'i',
|
||||
$groupId
|
||||
);
|
||||
foreach($quests as &$quest) {
|
||||
$quest['group_xps'] = round($quest['xps'] * $quest['xps_factor'], 1);
|
||||
}
|
||||
|
||||
|
||||
return $quests;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get XPs of a Character group for a Character groups Quest.
|
||||
*
|
||||
* @param int $questId ID of Character groups Quest
|
||||
* @param int $groupId ID of Character group to get XPs of
|
||||
* @return array XP-record
|
||||
*/
|
||||
public function getXPsOfGroupForQuest($questId, $groupId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT charactergroupsquests_groups.created, charactergroupsquests_groups.xps_factor, charactergroupsquests.xps '.
|
||||
'FROM charactergroupsquests_groups '.
|
||||
'LEFT JOIN charactergroupsquests ON charactergroupsquests.id = charactergroupsquests_groups.charactergroupsquest_id '.
|
||||
'WHERE charactergroupsquests_groups.charactergroupsquest_id = ? AND charactergroupsquests_groups.charactergroup_id = ?',
|
||||
'ii',
|
||||
$questId,
|
||||
$groupId
|
||||
);
|
||||
if(empty($data)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$data = $data[0];
|
||||
$data['xps'] = round($data['xps'] * $data['xps_factor'], 1);
|
||||
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set XPs of a Character group for a Character groups Quest.
|
||||
*
|
||||
* @param int $questId ID of Character groups Quest
|
||||
* @param int $groupId ID of Character group to set XPs of
|
||||
* @param float $xpsFactor XPs-factor
|
||||
*/
|
||||
public function setXPsOfGroupForQuest($questId, $groupId, $xpsFactor)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO charactergroupsquests_groups '.
|
||||
'(charactergroupsquest_id, charactergroup_id, xps_factor) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?) '.
|
||||
'ON DUPLICATE KEY UPDATE '.
|
||||
'xps_factor = ?',
|
||||
'iidd',
|
||||
$questId,
|
||||
$groupId,
|
||||
$xpsFactor,
|
||||
$xpsFactor
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove a Character group from a Character groups Quest.
|
||||
*
|
||||
* @param int $questId ID of Character groups Quest
|
||||
* @param int $groupId ID of Character group to remove
|
||||
*/
|
||||
public function deleteGroupForQuest($questId, $groupId)
|
||||
{
|
||||
$this->db->query(
|
||||
'DELETE FROM charactergroupsquests_groups '.
|
||||
'WHERE charactergroupsquest_id = ? AND charactergroup_id = ?',
|
||||
'ii',
|
||||
$questId, $groupId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if a Character groups Quest title already exists.
|
||||
*
|
||||
* @param string $name Character groups Quest title to check
|
||||
* @param int $questId Do not check this ID (for editing)
|
||||
* @return boolean Whether Character groups Quest title exists or not
|
||||
*/
|
||||
public function characterGroupsQuestTitleExists($title, $questId=null)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id '.
|
||||
'FROM charactergroupsquests '.
|
||||
'WHERE title = ? OR url = ?',
|
||||
'ss',
|
||||
$title,
|
||||
\nre\core\Linker::createLinkParam($title)
|
||||
);
|
||||
|
||||
return (!empty($data) && (is_null($questId) || $questId != $data[0]['id']));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the media for a Character groups Quest.
|
||||
*
|
||||
* @param int $questId ID of Quest to upload media for
|
||||
* @param int $mediaId ID of Quests media
|
||||
*/
|
||||
public function setMediaForQuest($questId, $mediaId)
|
||||
{
|
||||
$this->db->query(
|
||||
'UPDATE charactergroupsquests '.
|
||||
'SET questsmedia_id = ? '.
|
||||
'WHERE id = ?',
|
||||
'ii',
|
||||
$mediaId,
|
||||
$questId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Upload a media for a Character groups Quest.
|
||||
*
|
||||
* @param int $userId ID of user that does the upload
|
||||
* @param int $seminaryId ID of Seminary
|
||||
* @param int $questId ID of Quest to upload media for
|
||||
* @param array $file File-array of file to upload
|
||||
* @param string $filename Filename for media
|
||||
* @return boolean Whether upload succeeded or not
|
||||
*/
|
||||
public function uploadMediaForQuest($userId, $seminaryId, $questId, $file, $filename)
|
||||
{
|
||||
// Save file on harddrive
|
||||
$uploadId = $this->Uploads->uploadSeminaryFile($userId, $seminaryId, $file['name'], $filename, $file['tmp_name'], $file['type']);
|
||||
if($uploadId === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create database record
|
||||
$this->db->query(
|
||||
'INSERT INTO charactergroupsquests_seminaryuploads '.
|
||||
'(seminaryupload_id, charactergroupsquest_id, created_user_id) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?) ',
|
||||
'iii',
|
||||
$uploadId, $questId, $userId
|
||||
);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get uploaded Medai for a Character groups Quest.
|
||||
*
|
||||
* @param int $questId ID of Quest to get media for
|
||||
* @return array Seminary uploads
|
||||
*/
|
||||
public function getMediaForQuest($questId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT seminaryupload_id, created, created_user_id '.
|
||||
'FROM charactergroupsquests_seminaryuploads '.
|
||||
'WHERE charactergroupsquest_id = ?',
|
||||
'i',
|
||||
$questId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new Character groups Quest.
|
||||
*
|
||||
* @param int $userId ID of user
|
||||
* @param int $groupsgroupId ID of Character groups-group
|
||||
* @param int $questgroupId ID of Quest group
|
||||
* @param string $title Title of new Quest
|
||||
* @param string $description Description of new Quset
|
||||
* @param int $xps Amount of XPs for new Quest
|
||||
* @param string $rules Rules of new Quest
|
||||
* @param string $wonText Won-text of new Quset
|
||||
* @param string $lostText Lost-text of new Quest
|
||||
* @return int ID of newly created Quest
|
||||
*/
|
||||
public function createQuest($userId, $groupsgroupId, $questgroupId, $title, $description, $xps, $rules, $wonText, $lostText)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO charactergroupsquests '.
|
||||
'(created_user_id, charactergroupsgroup_id, questgroups_id, title, url, description, xps, rules, won_text, lost_text) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
|
||||
'iiisssdsss',
|
||||
$userId,
|
||||
$groupsgroupId,
|
||||
$questgroupId,
|
||||
$title,
|
||||
\nre\core\Linker::createLinkParam($title),
|
||||
$description,
|
||||
$xps,
|
||||
$rules,
|
||||
$wonText,
|
||||
$lostText
|
||||
);
|
||||
|
||||
|
||||
return $this->db->getInsertId();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Edit a Character groups Quest.
|
||||
*
|
||||
* @param int $questId ID of Character groups Quest to edit
|
||||
* @param int $groupsgroupId ID of Character groups-group
|
||||
* @param int $questgroupId ID of Quest group
|
||||
* @param string $title Title of new Quest
|
||||
* @param string $description Description of new Quset
|
||||
* @param int $xps Amount of XPs for new Quest
|
||||
* @param string $rules Rules of new Quest
|
||||
* @param string $wonText Won-text of new Quset
|
||||
* @param string $lostText Lost-text of new Quest
|
||||
*/
|
||||
public function editQuest($questId, $groupsgroupId, $questgroupId, $title, $description, $xps, $rules, $wonText, $lostText)
|
||||
{
|
||||
$this->db->query(
|
||||
'UPDATE charactergroupsquests '.
|
||||
'SET charactergroupsgroup_id = ?, questgroups_id = ?, title = ?, url = ?, description = ?, xps = ?, rules = ?, won_text = ?, lost_text= ? '.
|
||||
'WHERE id = ?',
|
||||
'iisssdsssi',
|
||||
$groupsgroupId,
|
||||
$questgroupId,
|
||||
$title,
|
||||
\nre\core\Linker::createLinkParam($title),
|
||||
$description,
|
||||
$xps,
|
||||
$rules,
|
||||
$wonText,
|
||||
$lostText,
|
||||
$questId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copy all Character groups Quests from a Seminary.
|
||||
*
|
||||
*
|
||||
* @param int $userId ID of copying user
|
||||
* @param array $groupsgroupIds Mapping of Character groups-group-IDs from source Seminary to target Seminary
|
||||
* @param array $questgroupIds Mapping of Questgroup-IDs from source Seminary to target Seminary
|
||||
|
|
@ -424,17 +424,17 @@
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a Character groups Quest.
|
||||
*
|
||||
* @param int $questId ID of Character groups Quest to delete
|
||||
*/
|
||||
public function deleteQuest($questId)
|
||||
{
|
||||
$this->db->query('DELETE FROM charactergroupsquests WHERE id = ?', 'i', $questId);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
/**
|
||||
* Delete a Character groups Quest.
|
||||
*
|
||||
* @param int $questId ID of Character groups Quest to delete
|
||||
*/
|
||||
public function deleteQuest($questId)
|
||||
{
|
||||
$this->db->query('DELETE FROM charactergroupsquests WHERE id = ?', 'i', $questId);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,100 +1,100 @@
|
|||
<?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 characterroles-table.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class CharacterrolesModel extends \hhu\z\Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new CharacterrolesModel.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get all characterroles for a Character referenced by its ID.
|
||||
*
|
||||
* @param int $userId ID of an user
|
||||
* @return array Characterroles for a Character
|
||||
*/
|
||||
public function getCharacterrolesForCharacterById($characterId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT characterroles.id, characterroles.created, characterroles.name '.
|
||||
'FROM characters_characterroles '.
|
||||
'LEFT JOIN characterroles ON characterroles.id = characters_characterroles.characterrole_id '.
|
||||
'WHERE characters_characterroles.character_id = ?',
|
||||
'i',
|
||||
$characterId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a role to a Character.
|
||||
*
|
||||
* @param int $characterId ID of Character to add role to
|
||||
* @param string $characterrole Role to add
|
||||
*/
|
||||
public function addCharacterroleToCharacter($characterId, $characterrole)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT IGNORE INTO characters_characterroles '.
|
||||
'(character_id, characterrole_id) '.
|
||||
'SELECT ?, id '.
|
||||
'FROM characterroles '.
|
||||
'WHERE name = ?',
|
||||
'is',
|
||||
$characterId,
|
||||
$characterrole
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove a role from a Character.
|
||||
*
|
||||
* @param int $characterId ID of Character to remove role from
|
||||
* @param string $characterrole Role to remove
|
||||
*/
|
||||
public function removeCharacterroleFromCharacter($characterId, $characterrole)
|
||||
{
|
||||
$this->db->query(
|
||||
'DELETE FROM characters_characterroles '.
|
||||
'WHERE character_id = ? AND characterrole_id = ('.
|
||||
'SELECT id '.
|
||||
'FROM characterroles '.
|
||||
'WHERE name = ?'.
|
||||
')',
|
||||
'is',
|
||||
$characterId,
|
||||
$characterrole
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* 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 characterroles-table.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class CharacterrolesModel extends \hhu\z\Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new CharacterrolesModel.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get all characterroles for a Character referenced by its ID.
|
||||
*
|
||||
* @param int $userId ID of an user
|
||||
* @return array Characterroles for a Character
|
||||
*/
|
||||
public function getCharacterrolesForCharacterById($characterId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT characterroles.id, characterroles.created, characterroles.name '.
|
||||
'FROM characters_characterroles '.
|
||||
'LEFT JOIN characterroles ON characterroles.id = characters_characterroles.characterrole_id '.
|
||||
'WHERE characters_characterroles.character_id = ?',
|
||||
'i',
|
||||
$characterId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a role to a Character.
|
||||
*
|
||||
* @param int $characterId ID of Character to add role to
|
||||
* @param string $characterrole Role to add
|
||||
*/
|
||||
public function addCharacterroleToCharacter($characterId, $characterrole)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT IGNORE INTO characters_characterroles '.
|
||||
'(character_id, characterrole_id) '.
|
||||
'SELECT ?, id '.
|
||||
'FROM characterroles '.
|
||||
'WHERE name = ?',
|
||||
'is',
|
||||
$characterId,
|
||||
$characterrole
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove a role from a Character.
|
||||
*
|
||||
* @param int $characterId ID of Character to remove role from
|
||||
* @param string $characterrole Role to remove
|
||||
*/
|
||||
public function removeCharacterroleFromCharacter($characterId, $characterrole)
|
||||
{
|
||||
$this->db->query(
|
||||
'DELETE FROM characters_characterroles '.
|
||||
'WHERE character_id = ? AND characterrole_id = ('.
|
||||
'SELECT id '.
|
||||
'FROM characterroles '.
|
||||
'WHERE name = ?'.
|
||||
')',
|
||||
'is',
|
||||
$characterId,
|
||||
$characterrole
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,209 +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 Charactertypes-table.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class CharactertypesModel extends \hhu\z\Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new CharactertypesModel.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get all Character types of a Seminary.
|
||||
*
|
||||
* @param int $seminaryId ID of Seminary to get types of
|
||||
* @return array Character types
|
||||
*/
|
||||
public function getCharacterTypesForSeminary($seminaryId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, seminary_id, name, url '.
|
||||
'FROM charactertypes '.
|
||||
'WHERE seminary_id = ? '.
|
||||
'ORDER BY name ASC',
|
||||
'i',
|
||||
$seminaryId
|
||||
);
|
||||
}
|
||||
/**
|
||||
* 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;
|
||||
|
||||
|
||||
/**
|
||||
* Get Character type by its URL.
|
||||
*
|
||||
* @param int $seminaryId ID of Seminary
|
||||
* @param string $charactretypeUrl URL-title of Character type
|
||||
* @return array Character type data
|
||||
*/
|
||||
public function getCharactertypeByUrl($seminaryId, $charactertypeUrl)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, seminary_id, name, url '.
|
||||
'FROM charactertypes '.
|
||||
'WHERE seminary_id = ? AND url = ?',
|
||||
'is',
|
||||
$seminaryId,
|
||||
$charactertypeUrl
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($charactertypeUrl);
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
/**
|
||||
* Model to interact with Charactertypes-table.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class CharactertypesModel extends \hhu\z\Model
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Get Character type by its ID.
|
||||
*
|
||||
* @param string $charactertypeId ID of Character type
|
||||
* @return array Character type data
|
||||
*/
|
||||
public function getCharactertypeById($charactertypeId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, seminary_id, name, url '.
|
||||
'FROM charactertypes '.
|
||||
'WHERE id = ?',
|
||||
'i',
|
||||
$charactertypeId
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($charactertypeId);
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if a Charactertype name already exists.
|
||||
*
|
||||
* @param int $seminaryId ID of Seminary
|
||||
* @param string $name Charactertype name to check
|
||||
* @param int $charactertypeId Do not check this ID (for editing)
|
||||
* @return boolean Whether Charactertype name exists or not
|
||||
*/
|
||||
public function charactertypeNameExists($seminaryId, $name, $charactertypeId=null)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id '.
|
||||
'FROM charactertypes '.
|
||||
'WHERE seminary_id = ? AND (name = ? OR url = ?)',
|
||||
'iss',
|
||||
$seminaryId,
|
||||
$name,
|
||||
\nre\core\Linker::createLinkParam($name)
|
||||
);
|
||||
|
||||
return (!empty($data) && (is_null($charactertypeId) || $charactertypeId != $data[0]['id']));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new Charactertype for a Seminary.
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $seminaryId ID of Seminary
|
||||
* @param string $name Name for new Charactertype
|
||||
* @return int ID of newly created Charactertype
|
||||
*/
|
||||
public function createCharactertype($userId, $seminaryId, $name)
|
||||
{
|
||||
$charactertypeId = null;
|
||||
$this->db->setAutocommit(false);
|
||||
try {
|
||||
// Create Charactertype
|
||||
$this->db->query(
|
||||
'INSERT INTO charactertypes '.
|
||||
'(created_user_id, seminary_id, name, url) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?, ?) ',
|
||||
'iiss',
|
||||
$userId,
|
||||
$seminaryId,
|
||||
$name,
|
||||
\nre\core\Linker::createLinkParam($name)
|
||||
);
|
||||
$charactertypeId = $this->db->getInsertId();
|
||||
|
||||
// Create avatars
|
||||
$this->db->query(
|
||||
'INSERT INTO avatars '.
|
||||
'(created_user_id, charactertype_id, xplevel_id) '.
|
||||
'SELECT ?, ?, xplevels.id '.
|
||||
'FROM xplevels '.
|
||||
'WHERE seminary_id = ?',
|
||||
'iii',
|
||||
$userId,
|
||||
$charactertypeId,
|
||||
$seminaryId
|
||||
);
|
||||
|
||||
$this->db->commit();
|
||||
}
|
||||
catch(\Exception $e) {
|
||||
$this->db->rollback();
|
||||
$this->db->setAutocommit(true);
|
||||
throw $e;
|
||||
}
|
||||
$this->db->setAutocommit(true);
|
||||
/**
|
||||
* Construct a new CharactertypesModel.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get all Character types of a Seminary.
|
||||
*
|
||||
* @param int $seminaryId ID of Seminary to get types of
|
||||
* @return array Character types
|
||||
*/
|
||||
public function getCharacterTypesForSeminary($seminaryId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, seminary_id, name, url '.
|
||||
'FROM charactertypes '.
|
||||
'WHERE seminary_id = ? '.
|
||||
'ORDER BY name ASC',
|
||||
'i',
|
||||
$seminaryId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Character type by its URL.
|
||||
*
|
||||
* @param int $seminaryId ID of Seminary
|
||||
* @param string $charactretypeUrl URL-title of Character type
|
||||
* @return array Character type data
|
||||
*/
|
||||
public function getCharactertypeByUrl($seminaryId, $charactertypeUrl)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, seminary_id, name, url '.
|
||||
'FROM charactertypes '.
|
||||
'WHERE seminary_id = ? AND url = ?',
|
||||
'is',
|
||||
$seminaryId,
|
||||
$charactertypeUrl
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($charactertypeUrl);
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Character type by its ID.
|
||||
*
|
||||
* @param string $charactertypeId ID of Character type
|
||||
* @return array Character type data
|
||||
*/
|
||||
public function getCharactertypeById($charactertypeId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, seminary_id, name, url '.
|
||||
'FROM charactertypes '.
|
||||
'WHERE id = ?',
|
||||
'i',
|
||||
$charactertypeId
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($charactertypeId);
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if a Charactertype name already exists.
|
||||
*
|
||||
* @param int $seminaryId ID of Seminary
|
||||
* @param string $name Charactertype name to check
|
||||
* @param int $charactertypeId Do not check this ID (for editing)
|
||||
* @return boolean Whether Charactertype name exists or not
|
||||
*/
|
||||
public function charactertypeNameExists($seminaryId, $name, $charactertypeId=null)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id '.
|
||||
'FROM charactertypes '.
|
||||
'WHERE seminary_id = ? AND (name = ? OR url = ?)',
|
||||
'iss',
|
||||
$seminaryId,
|
||||
$name,
|
||||
\nre\core\Linker::createLinkParam($name)
|
||||
);
|
||||
|
||||
return (!empty($data) && (is_null($charactertypeId) || $charactertypeId != $data[0]['id']));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new Charactertype for a Seminary.
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $seminaryId ID of Seminary
|
||||
* @param string $name Name for new Charactertype
|
||||
* @return int ID of newly created Charactertype
|
||||
*/
|
||||
public function createCharactertype($userId, $seminaryId, $name)
|
||||
{
|
||||
$charactertypeId = null;
|
||||
$this->db->setAutocommit(false);
|
||||
try {
|
||||
// Create Charactertype
|
||||
$this->db->query(
|
||||
'INSERT INTO charactertypes '.
|
||||
'(created_user_id, seminary_id, name, url) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?, ?) ',
|
||||
'iiss',
|
||||
$userId,
|
||||
$seminaryId,
|
||||
$name,
|
||||
\nre\core\Linker::createLinkParam($name)
|
||||
);
|
||||
$charactertypeId = $this->db->getInsertId();
|
||||
|
||||
// Create avatars
|
||||
$this->db->query(
|
||||
'INSERT INTO avatars '.
|
||||
'(created_user_id, charactertype_id, xplevel_id) '.
|
||||
'SELECT ?, ?, xplevels.id '.
|
||||
'FROM xplevels '.
|
||||
'WHERE seminary_id = ?',
|
||||
'iii',
|
||||
$userId,
|
||||
$charactertypeId,
|
||||
$seminaryId
|
||||
);
|
||||
|
||||
$this->db->commit();
|
||||
}
|
||||
catch(\Exception $e) {
|
||||
$this->db->rollback();
|
||||
$this->db->setAutocommit(true);
|
||||
throw $e;
|
||||
}
|
||||
$this->db->setAutocommit(true);
|
||||
|
||||
|
||||
return $charactertypeId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Edit a Charactertype.
|
||||
*
|
||||
* @param int $charactertypeId ID of Charactertype to edit
|
||||
* @param string $name New name of Charactertype
|
||||
*/
|
||||
public function editCharactertype($charactertypeId, $name)
|
||||
{
|
||||
$this->db->query(
|
||||
'UPDATE charactertypes '.
|
||||
'SET name = ?, url = ? '.
|
||||
'WHERE id = ?',
|
||||
'ssi',
|
||||
$name,
|
||||
\nre\core\Linker::createLinkParam($name),
|
||||
$charactertypeId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return $charactertypeId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Edit a Charactertype.
|
||||
*
|
||||
* @param int $charactertypeId ID of Charactertype to edit
|
||||
* @param string $name New name of Charactertype
|
||||
*/
|
||||
public function editCharactertype($charactertypeId, $name)
|
||||
{
|
||||
$this->db->query(
|
||||
'UPDATE charactertypes '.
|
||||
'SET name = ?, url = ? '.
|
||||
'WHERE id = ?',
|
||||
'ssi',
|
||||
$name,
|
||||
\nre\core\Linker::createLinkParam($name),
|
||||
$charactertypeId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copy all Charactertypes of a Seminary.
|
||||
*
|
||||
*
|
||||
* @param int $userId ID of copying user
|
||||
* @param int $sourceSeminaryId ID of Seminary to copy from
|
||||
* @param int $targetSeminaryId ID of Seminary to copy to
|
||||
|
|
@ -237,16 +237,16 @@
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a Charactertype.
|
||||
*
|
||||
* @param int $charactertypeId ID of Charactertype to delete
|
||||
*/
|
||||
public function deleteCharactertype($charactertypeId)
|
||||
{
|
||||
$this->db->query('DELETE FROM charactertypes WHERE id = ?', 'i', $charactertypeId);
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Delete a Charactertype.
|
||||
*
|
||||
* @param int $charactertypeId ID of Charactertype to delete
|
||||
*/
|
||||
public function deleteCharactertype($charactertypeId)
|
||||
{
|
||||
$this->db->query('DELETE FROM charactertypes WHERE id = ?', 'i', $charactertypeId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,42 +1,42 @@
|
|||
<?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 maps-table.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class MapModel extends \hhu\z\Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new MapModel.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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 maps-table.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class MapModel extends \hhu\z\Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new MapModel.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the map of a Seminary.
|
||||
*
|
||||
*
|
||||
* @param int $seminaryId ID of Seminary to get map of
|
||||
* @return array Map data
|
||||
*/
|
||||
|
|
@ -56,7 +56,7 @@
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -1,325 +1,325 @@
|
|||
<?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 \nre\exceptions\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 a Questgroup hierarchy by its URL.
|
||||
*
|
||||
* @throws \nre\exceptions\IdNotFoundException
|
||||
* @param int $seminaryId ID of Seminary
|
||||
* @param int $questgroupshierarchyURL URL of a Questgroup hierarchy
|
||||
* @return array Questgroup hierarchy
|
||||
*/
|
||||
public function getHierarchyByUrl($seminaryId, $questgroupshierarchyUrl)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, seminary_id, parent_questgroupshierarchy_id, pos, title_singular, title_plural, url '.
|
||||
'FROM questgroupshierarchy '.
|
||||
'WHERE questgroupshierarchy.seminary_id = ? AND questgroupshierarchy.url = ?',
|
||||
'is',
|
||||
$seminaryId,
|
||||
$questgroupshierarchyUrl
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($questgroupshierarchyUrl);
|
||||
}
|
||||
|
||||
|
||||
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 getHierarchyOfSeminary($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 Questgroup-Hierarchy for a Questgroup.
|
||||
*
|
||||
* @param int $questgroupId ID of Questgroup
|
||||
* @return array Hierarchy for Questgroup
|
||||
*/
|
||||
public function getHierarchyForQuestgroup($questgroupId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT questgroups_questgroupshierarchy.parent_questgroup_id, questgroups_questgroupshierarchy.pos AS questgroup_pos, questgroupshierarchy.id, questgroupshierarchy.seminary_id, questgroupshierarchy.parent_questgroupshierarchy_id, questgroupshierarchy.pos, questgroupshierarchy.title_singular, questgroupshierarchy.title_plural, questgroupshierarchy.url '.
|
||||
'FROM questgroups_questgroupshierarchy '.
|
||||
'INNER JOIN questgroupshierarchy ON questgroupshierarchy.id = questgroups_questgroupshierarchy.questgroupshierarchy_id '.
|
||||
'WHERE questgroups_questgroupshierarchy.questgroup_id = ?',
|
||||
'i',
|
||||
$questgroupId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if a title for a Questgroupshierarchy already exists
|
||||
* for a Seminary.
|
||||
*
|
||||
* @param string $title
|
||||
* @param int $seminaryId
|
||||
* @param int $questgroupshierarchyId Do not check this Questgroupshierarchy (for editing)
|
||||
* @return Whether title already exists or not
|
||||
*/
|
||||
public function questgroupshierarchyTitleSingularExists($title, $seminaryId, $questgroupshierarchyId=null)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id '.
|
||||
'FROM questgroupshierarchy '.
|
||||
'WHERE seminary_id = ? AND (title_singular = ? OR url = ?) ',
|
||||
'iss',
|
||||
$seminaryId,
|
||||
$title,
|
||||
\nre\core\Linker::createLinkParam($title)
|
||||
);
|
||||
|
||||
|
||||
return (!empty($data) && (is_null($questgroupshierarchyId) || $questgroupshierarchyId != $data[0]['id']));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new Questgroupshierarchy for a Seminary
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $seminaryId ID of Seminary
|
||||
* @param int $parentQuestgroupsierarchyId ID of parent Questgroupshierarchy
|
||||
* @param string $title Title (singular)
|
||||
* @param string $course Title (plural)
|
||||
*/
|
||||
public function createQuestgroupshierarchy($userId, $seminaryId, $parentQuestgroupsierarchyId, $titleSingular, $titlePlural)
|
||||
{
|
||||
// Get last position
|
||||
$pos = $this->db->query(
|
||||
'SELECT COALESCE(MAX(pos),0) AS pos '.
|
||||
'FROM questgroupshierarchy '.
|
||||
'WHERE seminary_id = ? AND '.
|
||||
'parent_questgroupshierarchy_id '.(!is_null($parentQuestgroupsierarchyId) ? sprintf('= %d', $parentQuestgroupsierarchyId) : 'IS NULL'),
|
||||
'i',
|
||||
$seminaryId
|
||||
);
|
||||
$pos = intval($pos[0]['pos']);
|
||||
|
||||
// Create Questgroupshierarchy
|
||||
$this->db->query(
|
||||
'INSERT INTO questgroupshierarchy '.
|
||||
'(created_user_id, seminary_id, parent_questgroupshierarchy_id, pos, title_singular, title_plural, url) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?, ?, ?, ?, ?)',
|
||||
'iiiisss',
|
||||
$userId,
|
||||
$seminaryId,
|
||||
$parentQuestgroupsierarchyId,
|
||||
$pos + 1,
|
||||
$titleSingular,
|
||||
$titlePlural,
|
||||
\nre\core\Linker::createLinkParam($titleSingular)
|
||||
);
|
||||
|
||||
|
||||
return $this->db->getInsertId();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Edit a Questgroupshierarchy.
|
||||
*
|
||||
* @param int $questgroupshierarchyId ID of Questgroupshierarchy to edit
|
||||
* @param string $title New title (singular)
|
||||
* @param string $course New title (plural)
|
||||
*/
|
||||
public function editQuestgroupshierarchy($questgroupshierarchyId, $titleSingular, $titlePlural)
|
||||
{
|
||||
$this->db->query(
|
||||
'UPDATE questgroupshierarchy '.
|
||||
'SET title_singular = ?, title_plural = ?, url = ? '.
|
||||
'WHERE id = ?',
|
||||
'sssi',
|
||||
$titleSingular,
|
||||
$titlePlural,
|
||||
\nre\core\Linker::createLinkParam($titleSingular),
|
||||
$questgroupshierarchyId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Move a Questgroupshierarchy up (decrement position) or down
|
||||
* (increment position).
|
||||
*
|
||||
* @param array $questgroupshierarchy Questgroupshierarchy to move
|
||||
* @param boolean $up True for moving up, false for down
|
||||
*/
|
||||
public function moveQuestgroupshierarchy($questgroupshierarchy, $up)
|
||||
{
|
||||
$this->db->setAutocommit(false);
|
||||
try {
|
||||
// Set temporary position
|
||||
$this->db->query(
|
||||
'UPDATE questgroupshierarchy '.
|
||||
'SET pos = 0 '.
|
||||
'WHERE id = ?',
|
||||
'i',
|
||||
$questgroupshierarchy['id']
|
||||
);
|
||||
// Switch entry
|
||||
if(is_null($questgroupshierarchy['parent_questgroupshierarchy_id'])) {
|
||||
$this->db->query(
|
||||
'UPDATE questgroupshierarchy '.
|
||||
'SET pos = ? '.
|
||||
'WHERE parent_questgroupshierarchy_id IS NULL AND pos = ?',
|
||||
'ii',
|
||||
$questgroupshierarchy['pos'],
|
||||
$questgroupshierarchy['pos'] + ($up ? -1 : 1)
|
||||
);
|
||||
}
|
||||
else {
|
||||
$this->db->query(
|
||||
'UPDATE questgroupshierarchy '.
|
||||
'SET pos = ? '.
|
||||
'WHERE parent_questgroupshierarchy_id = ? AND pos = ?',
|
||||
'iii',
|
||||
$questgroupshierarchy['pos'],
|
||||
$questgroupshierarchy['parent_questgroupshierarchy_id'],
|
||||
$questgroupshierarchy['pos'] + ($up ? -1 : 1)
|
||||
);
|
||||
}
|
||||
// Set new position
|
||||
$this->db->query(
|
||||
'UPDATE questgroupshierarchy '.
|
||||
'SET pos = ? '.
|
||||
'WHERE id = ?',
|
||||
'ii',
|
||||
$questgroupshierarchy['pos'] + ($up ? -1 : 1),
|
||||
$questgroupshierarchy['id']
|
||||
);
|
||||
|
||||
$this->db->commit();
|
||||
}
|
||||
catch(\nre\exceptions\DatamodelException $e) {
|
||||
$this->db->rollback();
|
||||
$this->db->setAutocommit(true);
|
||||
throw $e;
|
||||
}
|
||||
$this->db->setAutocommit(true);
|
||||
}
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Copy complete Questgroupshierarchy of a Seminary.
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $sourceSeminaryId ID of Seminary to copy hierarchy from
|
||||
* @param int $targetSeminaryId ID of Seminary to copy hierarchy to
|
||||
* Construct a new QuestgroupshierarchyModel.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get a Questgroup hierarchy by its ID.
|
||||
*
|
||||
* throws \nre\exceptions\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 a Questgroup hierarchy by its URL.
|
||||
*
|
||||
* @throws \nre\exceptions\IdNotFoundException
|
||||
* @param int $seminaryId ID of Seminary
|
||||
* @param int $questgroupshierarchyURL URL of a Questgroup hierarchy
|
||||
* @return array Questgroup hierarchy
|
||||
*/
|
||||
public function getHierarchyByUrl($seminaryId, $questgroupshierarchyUrl)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, seminary_id, parent_questgroupshierarchy_id, pos, title_singular, title_plural, url '.
|
||||
'FROM questgroupshierarchy '.
|
||||
'WHERE questgroupshierarchy.seminary_id = ? AND questgroupshierarchy.url = ?',
|
||||
'is',
|
||||
$seminaryId,
|
||||
$questgroupshierarchyUrl
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($questgroupshierarchyUrl);
|
||||
}
|
||||
|
||||
|
||||
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 getHierarchyOfSeminary($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 Questgroup-Hierarchy for a Questgroup.
|
||||
*
|
||||
* @param int $questgroupId ID of Questgroup
|
||||
* @return array Hierarchy for Questgroup
|
||||
*/
|
||||
public function getHierarchyForQuestgroup($questgroupId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT questgroups_questgroupshierarchy.parent_questgroup_id, questgroups_questgroupshierarchy.pos AS questgroup_pos, questgroupshierarchy.id, questgroupshierarchy.seminary_id, questgroupshierarchy.parent_questgroupshierarchy_id, questgroupshierarchy.pos, questgroupshierarchy.title_singular, questgroupshierarchy.title_plural, questgroupshierarchy.url '.
|
||||
'FROM questgroups_questgroupshierarchy '.
|
||||
'INNER JOIN questgroupshierarchy ON questgroupshierarchy.id = questgroups_questgroupshierarchy.questgroupshierarchy_id '.
|
||||
'WHERE questgroups_questgroupshierarchy.questgroup_id = ?',
|
||||
'i',
|
||||
$questgroupId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if a title for a Questgroupshierarchy already exists
|
||||
* for a Seminary.
|
||||
*
|
||||
* @param string $title
|
||||
* @param int $seminaryId
|
||||
* @param int $questgroupshierarchyId Do not check this Questgroupshierarchy (for editing)
|
||||
* @return Whether title already exists or not
|
||||
*/
|
||||
public function questgroupshierarchyTitleSingularExists($title, $seminaryId, $questgroupshierarchyId=null)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id '.
|
||||
'FROM questgroupshierarchy '.
|
||||
'WHERE seminary_id = ? AND (title_singular = ? OR url = ?) ',
|
||||
'iss',
|
||||
$seminaryId,
|
||||
$title,
|
||||
\nre\core\Linker::createLinkParam($title)
|
||||
);
|
||||
|
||||
|
||||
return (!empty($data) && (is_null($questgroupshierarchyId) || $questgroupshierarchyId != $data[0]['id']));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new Questgroupshierarchy for a Seminary
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $seminaryId ID of Seminary
|
||||
* @param int $parentQuestgroupsierarchyId ID of parent Questgroupshierarchy
|
||||
* @param string $title Title (singular)
|
||||
* @param string $course Title (plural)
|
||||
*/
|
||||
public function createQuestgroupshierarchy($userId, $seminaryId, $parentQuestgroupsierarchyId, $titleSingular, $titlePlural)
|
||||
{
|
||||
// Get last position
|
||||
$pos = $this->db->query(
|
||||
'SELECT COALESCE(MAX(pos),0) AS pos '.
|
||||
'FROM questgroupshierarchy '.
|
||||
'WHERE seminary_id = ? AND '.
|
||||
'parent_questgroupshierarchy_id '.(!is_null($parentQuestgroupsierarchyId) ? sprintf('= %d', $parentQuestgroupsierarchyId) : 'IS NULL'),
|
||||
'i',
|
||||
$seminaryId
|
||||
);
|
||||
$pos = intval($pos[0]['pos']);
|
||||
|
||||
// Create Questgroupshierarchy
|
||||
$this->db->query(
|
||||
'INSERT INTO questgroupshierarchy '.
|
||||
'(created_user_id, seminary_id, parent_questgroupshierarchy_id, pos, title_singular, title_plural, url) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?, ?, ?, ?, ?)',
|
||||
'iiiisss',
|
||||
$userId,
|
||||
$seminaryId,
|
||||
$parentQuestgroupsierarchyId,
|
||||
$pos + 1,
|
||||
$titleSingular,
|
||||
$titlePlural,
|
||||
\nre\core\Linker::createLinkParam($titleSingular)
|
||||
);
|
||||
|
||||
|
||||
return $this->db->getInsertId();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Edit a Questgroupshierarchy.
|
||||
*
|
||||
* @param int $questgroupshierarchyId ID of Questgroupshierarchy to edit
|
||||
* @param string $title New title (singular)
|
||||
* @param string $course New title (plural)
|
||||
*/
|
||||
public function editQuestgroupshierarchy($questgroupshierarchyId, $titleSingular, $titlePlural)
|
||||
{
|
||||
$this->db->query(
|
||||
'UPDATE questgroupshierarchy '.
|
||||
'SET title_singular = ?, title_plural = ?, url = ? '.
|
||||
'WHERE id = ?',
|
||||
'sssi',
|
||||
$titleSingular,
|
||||
$titlePlural,
|
||||
\nre\core\Linker::createLinkParam($titleSingular),
|
||||
$questgroupshierarchyId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Move a Questgroupshierarchy up (decrement position) or down
|
||||
* (increment position).
|
||||
*
|
||||
* @param array $questgroupshierarchy Questgroupshierarchy to move
|
||||
* @param boolean $up True for moving up, false for down
|
||||
*/
|
||||
public function moveQuestgroupshierarchy($questgroupshierarchy, $up)
|
||||
{
|
||||
$this->db->setAutocommit(false);
|
||||
try {
|
||||
// Set temporary position
|
||||
$this->db->query(
|
||||
'UPDATE questgroupshierarchy '.
|
||||
'SET pos = 0 '.
|
||||
'WHERE id = ?',
|
||||
'i',
|
||||
$questgroupshierarchy['id']
|
||||
);
|
||||
// Switch entry
|
||||
if(is_null($questgroupshierarchy['parent_questgroupshierarchy_id'])) {
|
||||
$this->db->query(
|
||||
'UPDATE questgroupshierarchy '.
|
||||
'SET pos = ? '.
|
||||
'WHERE parent_questgroupshierarchy_id IS NULL AND pos = ?',
|
||||
'ii',
|
||||
$questgroupshierarchy['pos'],
|
||||
$questgroupshierarchy['pos'] + ($up ? -1 : 1)
|
||||
);
|
||||
}
|
||||
else {
|
||||
$this->db->query(
|
||||
'UPDATE questgroupshierarchy '.
|
||||
'SET pos = ? '.
|
||||
'WHERE parent_questgroupshierarchy_id = ? AND pos = ?',
|
||||
'iii',
|
||||
$questgroupshierarchy['pos'],
|
||||
$questgroupshierarchy['parent_questgroupshierarchy_id'],
|
||||
$questgroupshierarchy['pos'] + ($up ? -1 : 1)
|
||||
);
|
||||
}
|
||||
// Set new position
|
||||
$this->db->query(
|
||||
'UPDATE questgroupshierarchy '.
|
||||
'SET pos = ? '.
|
||||
'WHERE id = ?',
|
||||
'ii',
|
||||
$questgroupshierarchy['pos'] + ($up ? -1 : 1),
|
||||
$questgroupshierarchy['id']
|
||||
);
|
||||
|
||||
$this->db->commit();
|
||||
}
|
||||
catch(\nre\exceptions\DatamodelException $e) {
|
||||
$this->db->rollback();
|
||||
$this->db->setAutocommit(true);
|
||||
throw $e;
|
||||
}
|
||||
$this->db->setAutocommit(true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copy complete Questgroupshierarchy of a Seminary.
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $sourceSeminaryId ID of Seminary to copy hierarchy from
|
||||
* @param int $targetSeminaryId ID of Seminary to copy hierarchy to
|
||||
* @return array Mapping of hierarchy-IDs from source Seminary to target Seminary
|
||||
*/
|
||||
public function copyQuestgroupshierarchy($userId, $sourceSeminaryId, $targetSeminaryId)
|
||||
{
|
||||
// Get Hierarchy of Seminary
|
||||
$questgroupshierarchy = $this->getHierarchyOfSeminary($sourceSeminaryId);
|
||||
$questgroupshierarchy = $this->getHierarchyOfSeminary($sourceSeminaryId);
|
||||
|
||||
// Copy hierarchy
|
||||
$hierarchyIds = array();
|
||||
foreach($questgroupshierarchy as $hierarchy) {
|
||||
foreach($questgroupshierarchy as $hierarchy) {
|
||||
$this->copyHierarchy($userId, $sourceSeminaryId, $targetSeminaryId, $hierarchy, $hierarchyIds);
|
||||
}
|
||||
|
||||
|
|
@ -327,26 +327,26 @@
|
|||
return $hierarchyIds;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a Questgroupshierarchy.
|
||||
*
|
||||
* @param int $seminaryId ID of the seminary to delete
|
||||
*/
|
||||
public function deleteQuestgroupshierarchy($questgroupshierarchyId)
|
||||
{
|
||||
$this->db->query('DELETE FROM questgroupshierarchy WHERE id = ?', 'i', $questgroupshierarchyId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a Questgroupshierarchy.
|
||||
*
|
||||
* @param int $seminaryId ID of the seminary to delete
|
||||
*/
|
||||
public function deleteQuestgroupshierarchy($questgroupshierarchyId)
|
||||
{
|
||||
$this->db->query('DELETE FROM questgroupshierarchy WHERE id = ?', 'i', $questgroupshierarchyId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Copy a Questgroupshierarchy and its child hierarchy.
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $sourceSeminaryId ID of Seminary to copy hierarchy from
|
||||
* @param int $targetSeminaryId ID of Seminary to copy hierarchy to
|
||||
* Copy a Questgroupshierarchy and its child hierarchy.
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $sourceSeminaryId ID of Seminary to copy hierarchy from
|
||||
* @param int $targetSeminaryId ID of Seminary to copy hierarchy to
|
||||
* @param array $hierarchy Hierarchy to copy
|
||||
* @return array $hierarchyIds Mapping of hierarchy IDs from source Seminary to target Seminary
|
||||
*/
|
||||
|
|
@ -379,7 +379,7 @@
|
|||
$hierarchy['id']
|
||||
);
|
||||
}
|
||||
$hierarchyIds[$hierarchy['id']] = $this->db->getInsertId();
|
||||
$hierarchyIds[$hierarchy['id']] = $this->db->getInsertId();
|
||||
|
||||
// insert sub hierarchy
|
||||
$childHierarchy = $this->getChildQuestgroupshierarchy($hierarchy['id']);
|
||||
|
|
@ -387,7 +387,7 @@
|
|||
$this->copyHierarchy($userId, $sourceSeminaryId, $targetSeminaryId, $hierarchy, $hierarchyIds);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,111 +1,111 @@
|
|||
<?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 Questgrouptexts-table.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class QuestgrouptextsModel extends \hhu\z\Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new QuestgrouptextsModel.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
/**
|
||||
* 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 Questgrouptexts-table.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class QuestgrouptextsModel extends \hhu\z\Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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, questgroup_id '.
|
||||
'FROM questgrouptexts '.
|
||||
'WHERE questgroup_id = ? '.
|
||||
'ORDER BY pos ASC',
|
||||
'i',
|
||||
$questgroupId
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Construct a new QuestgrouptextsModel.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a Questgroup text to a Questgroup.
|
||||
*
|
||||
* @param int $userId ID of user
|
||||
* @param int $questgroupId ID of Questgroup to add text to
|
||||
* @param string $text Text to add
|
||||
*/
|
||||
public function addQuestgrouptextToQuestgroup($userId, $questgroupId, $text)
|
||||
{
|
||||
// Get position
|
||||
$pos = $this->db->query(
|
||||
'SELECT COALESCE(MAX(pos),0)+1 AS pos '.
|
||||
'FROM questgrouptexts '.
|
||||
'WHERE questgroup_id = ?',
|
||||
'i',
|
||||
$questgroupId
|
||||
);
|
||||
$pos = $pos[0]['pos'];
|
||||
|
||||
// Add Questgroup text
|
||||
$this->db->query(
|
||||
'INSERT INTO questgrouptexts '.
|
||||
'(created_user_id, questgroup_id, pos, text) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?, ?)',
|
||||
'iiis',
|
||||
$userId, $questgroupId, $pos, $text
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Edit a Questgroup text.
|
||||
*
|
||||
* @param int $questgrouptextId ID of Questgroup text to edit
|
||||
* @param string $text New text
|
||||
*/
|
||||
public function editQuestgrouptext($questgrouptextId, $text)
|
||||
{
|
||||
$this->db->query(
|
||||
'UPDATE questgrouptexts '.
|
||||
'SET text = ? '.
|
||||
'WHERE id = ?',
|
||||
'si',
|
||||
$text,
|
||||
$questgrouptextId
|
||||
);
|
||||
}
|
||||
/**
|
||||
* 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, questgroup_id '.
|
||||
'FROM questgrouptexts '.
|
||||
'WHERE questgroup_id = ? '.
|
||||
'ORDER BY pos ASC',
|
||||
'i',
|
||||
$questgroupId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a Questgroup text to a Questgroup.
|
||||
*
|
||||
* @param int $userId ID of user
|
||||
* @param int $questgroupId ID of Questgroup to add text to
|
||||
* @param string $text Text to add
|
||||
*/
|
||||
public function addQuestgrouptextToQuestgroup($userId, $questgroupId, $text)
|
||||
{
|
||||
// Get position
|
||||
$pos = $this->db->query(
|
||||
'SELECT COALESCE(MAX(pos),0)+1 AS pos '.
|
||||
'FROM questgrouptexts '.
|
||||
'WHERE questgroup_id = ?',
|
||||
'i',
|
||||
$questgroupId
|
||||
);
|
||||
$pos = $pos[0]['pos'];
|
||||
|
||||
// Add Questgroup text
|
||||
$this->db->query(
|
||||
'INSERT INTO questgrouptexts '.
|
||||
'(created_user_id, questgroup_id, pos, text) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?, ?)',
|
||||
'iiis',
|
||||
$userId, $questgroupId, $pos, $text
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Edit a Questgroup text.
|
||||
*
|
||||
* @param int $questgrouptextId ID of Questgroup text to edit
|
||||
* @param string $text New text
|
||||
*/
|
||||
public function editQuestgrouptext($questgrouptextId, $text)
|
||||
{
|
||||
$this->db->query(
|
||||
'UPDATE questgrouptexts '.
|
||||
'SET text = ? '.
|
||||
'WHERE id = ?',
|
||||
'si',
|
||||
$text,
|
||||
$questgrouptextId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copy Questgroup texts from one Questgroup to another.
|
||||
*
|
||||
*
|
||||
* @param $userId ID of copying user
|
||||
* @param $sourceQuestgroupId ID of source Questgroup
|
||||
* @param $targetQuestgroupId ID of target Questgroup
|
||||
|
|
@ -125,27 +125,27 @@
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a Questgroup text.
|
||||
*
|
||||
* @param array $questgrouptext Data of Questgroup text to delete
|
||||
*/
|
||||
public function deleteQuestgrouptext($questgrouptext)
|
||||
{
|
||||
// Delete Questgroup text
|
||||
$this->db->query('DELETE FROM questgrouptexts WHERE id = ?', 'i', $questgrouptext['id']);
|
||||
/**
|
||||
* Delete a Questgroup text.
|
||||
*
|
||||
* @param array $questgrouptext Data of Questgroup text to delete
|
||||
*/
|
||||
public function deleteQuestgrouptext($questgrouptext)
|
||||
{
|
||||
// Delete Questgroup text
|
||||
$this->db->query('DELETE FROM questgrouptexts WHERE id = ?', 'i', $questgrouptext['id']);
|
||||
|
||||
// Adjust positions
|
||||
$this->db->query(
|
||||
'UPDATE questgrouptexts '.
|
||||
'SET pos = pos - 1 '.
|
||||
'WHERE questgroup_id = ? AND pos > ?',
|
||||
'ii',
|
||||
$questgrouptext['questgroup_id'],
|
||||
$questgrouptext['pos']
|
||||
);
|
||||
}
|
||||
// Adjust positions
|
||||
$this->db->query(
|
||||
'UPDATE questgrouptexts '.
|
||||
'SET pos = pos - 1 '.
|
||||
'WHERE questgroup_id = ? AND pos > ?',
|
||||
'ii',
|
||||
$questgrouptext['questgroup_id'],
|
||||
$questgrouptext['pos']
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,320 +1,320 @@
|
|||
<?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
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('media');
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new QuesttextsModel.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the first text of a Quest.
|
||||
*
|
||||
* @param int $questId ID of a Quest
|
||||
* @return string First text of this Quest or NULL
|
||||
*/
|
||||
public function getFirstQuestText($questId)
|
||||
{
|
||||
$prolog = $this->getQuesttextsOfQuest($questId, 'Prolog');
|
||||
if(!empty($prolog)) {
|
||||
return $prolog[0]['text'];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all Questtexts for a Quest.
|
||||
*
|
||||
* @param int $questId ID of the Quest
|
||||
* @param string $questtexttypeUrl URL of the Questtexttype
|
||||
* @return array All Questtexts for a Quest
|
||||
*/
|
||||
public function getQuesttextsOfQuest($questId, $questtexttypeUrl=null)
|
||||
{
|
||||
if(is_null($questtexttypeUrl))
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT questtexts.id, questtexts.quest_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 = ?',
|
||||
'i',
|
||||
$questId
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT questtexts.id, questtexts.quest_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 = ?',
|
||||
'is',
|
||||
$questId,
|
||||
$questtexttypeUrl
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get count of Questtexts for a Quest.
|
||||
*
|
||||
* @param int $questId ID of the Quest
|
||||
* @param string $questtexttypeUrl URL of the Questtexttype
|
||||
* @return int Amount of Questtexts for a Quest
|
||||
*/
|
||||
public function getQuesttextCountOfQuest($questId, $questtexttypeUrl=null)
|
||||
{
|
||||
if(is_null($questtexttypeUrl))
|
||||
{
|
||||
$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 = ?',
|
||||
'i',
|
||||
$questId
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$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,
|
||||
$questtexttypeUrl
|
||||
);
|
||||
}
|
||||
if(!empty($data)) {
|
||||
return $data[0]['c'];
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get corresponding Questtexts for a Questgroup.
|
||||
*
|
||||
* @throws \nre\exceptions\IdNotFoundException
|
||||
* @param int $questgroupId ID of Questgroup to get the Questtexst for
|
||||
* @param array List of Questtexts
|
||||
*/
|
||||
public function getRelatedQuesttextsForQuestgroup($questgroupId)
|
||||
{
|
||||
return $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 questgroups_questtexts '.
|
||||
'LEFT JOIN questtexts ON questtexts.id = questgroups_questtexts.questtext_id '.
|
||||
'LEFT JOIN questtexttypes ON questtexttypes.id = questtexts.questtexttype_id '.
|
||||
'WHERE questgroups_questtexts.questgroup_id = ?',
|
||||
'i',
|
||||
$questgroupId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the Questtext that was last entered by a Character.
|
||||
*
|
||||
* @param int $characterId ID of Character
|
||||
* @param array $questtexts List of Questtexts to look into
|
||||
* @return array Questtext data
|
||||
*/
|
||||
public function pickQuesttextLastEnteredByCharacter($characterId, $questtexts)
|
||||
{
|
||||
if(count($questtexts) == 0) {
|
||||
return null;
|
||||
}
|
||||
$data = $this->db->query(
|
||||
sprintf(
|
||||
'SELECT quest_id '.
|
||||
'FROM quests_characters '.
|
||||
'WHERE character_id = ? AND quest_id IN (%s) AND status = ? '.
|
||||
'ORDER BY created DESC '.
|
||||
'LIMIT 1',
|
||||
implode(',', array_map(function($q) { return intval($q['quest_id']); }, $questtexts))
|
||||
),
|
||||
'ii',
|
||||
$characterId,
|
||||
\hhu\z\models\QuestsModel::QUEST_STATUS_ENTERED
|
||||
);
|
||||
if(count($data) == 0) {
|
||||
return $questtexts[0];
|
||||
}
|
||||
foreach($questtexts as &$questtext) {
|
||||
if($questtext['quest_id'] == $data[0]['quest_id']) {
|
||||
return $questtext;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all registered Questtexttypes.
|
||||
*
|
||||
* @return array Registered Questtexttypes
|
||||
*/
|
||||
public function getQuesttexttypes()
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, type, url '.
|
||||
'FROM questtexttypes'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a Questtexttype by its URL.
|
||||
*
|
||||
* @param string $questtexttypeUrl URL-type of Questtexttype
|
||||
* @return array Questtexttype data
|
||||
*/
|
||||
public function getQuesttexttypeByUrl($questtexttypeUrl)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, type, url '.
|
||||
'FROM questtexttypes '.
|
||||
'WHERE url = ?',
|
||||
's',
|
||||
$questtexttypeUrl
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a Questtexts to a Quest.
|
||||
*
|
||||
* @param int $userId ID of user
|
||||
* @param int $questId ID of Quest to add texts to
|
||||
* @param string $questtexttypeUrl URL-type of Questtexttype of texts
|
||||
* @param string $text Text to add.
|
||||
*/
|
||||
public function addQuesttextToQuest($userId, $questId, $questtexttypeUrl, $text)
|
||||
{
|
||||
$questtexttype = $this->getQuesttexttypeByUrl($questtexttypeUrl);
|
||||
if(is_null($questtexttype)) {
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
||||
// Get position
|
||||
$pos = $this->db->query(
|
||||
'SELECT COALESCE(MAX(pos),0)+1 AS pos '.
|
||||
'FROM questtexts '.
|
||||
'WHERE quest_id = ?',
|
||||
'i',
|
||||
$questId
|
||||
);
|
||||
$pos = $pos[0]['pos'];
|
||||
|
||||
// Add Questtext
|
||||
$this->db->query(
|
||||
'INSERT INTO questtexts '.
|
||||
'(created_user_id, quest_id, questtexttype_id, pos, text) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?, ?, ?)',
|
||||
'iiiis',
|
||||
$userId, $questId, $questtexttype['id'], $pos,
|
||||
$text
|
||||
);
|
||||
namespace hhu\z\models;
|
||||
|
||||
|
||||
// Return ID
|
||||
return $this->db->getInsertId();
|
||||
}
|
||||
/**
|
||||
* Model to interact with Questtexts-table.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class QuesttextsModel extends \hhu\z\Model
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('media');
|
||||
|
||||
|
||||
/**
|
||||
* Set the media for a Quest text.
|
||||
*
|
||||
* @param int $questtextId ID of Quest text to set media for
|
||||
* @param int $questmediaId ID of Questsmedia to set
|
||||
*/
|
||||
public function setQuestmedia($questtextId, $questsmediaId)
|
||||
{
|
||||
$this->db->query(
|
||||
'UPDATE questtexts '.
|
||||
'SET questsmedia_id = ? '.
|
||||
'WHERE id = ?',
|
||||
'ii',
|
||||
$questsmediaId,
|
||||
$questtextId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Edit a Quest text.
|
||||
*
|
||||
* @param int $questtextId ID of Quest text to edit
|
||||
* @param string $text New text
|
||||
*/
|
||||
public function editQuesttext($questtextId, $text)
|
||||
{
|
||||
$this->db->query(
|
||||
'UPDATE questtexts '.
|
||||
'SET text = ? '.
|
||||
'WHERE id = ?',
|
||||
'si',
|
||||
$text,
|
||||
$questtextId
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new QuesttextsModel.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the first text of a Quest.
|
||||
*
|
||||
* @param int $questId ID of a Quest
|
||||
* @return string First text of this Quest or NULL
|
||||
*/
|
||||
public function getFirstQuestText($questId)
|
||||
{
|
||||
$prolog = $this->getQuesttextsOfQuest($questId, 'Prolog');
|
||||
if(!empty($prolog)) {
|
||||
return $prolog[0]['text'];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all Questtexts for a Quest.
|
||||
*
|
||||
* @param int $questId ID of the Quest
|
||||
* @param string $questtexttypeUrl URL of the Questtexttype
|
||||
* @return array All Questtexts for a Quest
|
||||
*/
|
||||
public function getQuesttextsOfQuest($questId, $questtexttypeUrl=null)
|
||||
{
|
||||
if(is_null($questtexttypeUrl))
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT questtexts.id, questtexts.quest_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 = ?',
|
||||
'i',
|
||||
$questId
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT questtexts.id, questtexts.quest_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 = ?',
|
||||
'is',
|
||||
$questId,
|
||||
$questtexttypeUrl
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get count of Questtexts for a Quest.
|
||||
*
|
||||
* @param int $questId ID of the Quest
|
||||
* @param string $questtexttypeUrl URL of the Questtexttype
|
||||
* @return int Amount of Questtexts for a Quest
|
||||
*/
|
||||
public function getQuesttextCountOfQuest($questId, $questtexttypeUrl=null)
|
||||
{
|
||||
if(is_null($questtexttypeUrl))
|
||||
{
|
||||
$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 = ?',
|
||||
'i',
|
||||
$questId
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$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,
|
||||
$questtexttypeUrl
|
||||
);
|
||||
}
|
||||
if(!empty($data)) {
|
||||
return $data[0]['c'];
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get corresponding Questtexts for a Questgroup.
|
||||
*
|
||||
* @throws \nre\exceptions\IdNotFoundException
|
||||
* @param int $questgroupId ID of Questgroup to get the Questtexst for
|
||||
* @param array List of Questtexts
|
||||
*/
|
||||
public function getRelatedQuesttextsForQuestgroup($questgroupId)
|
||||
{
|
||||
return $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 questgroups_questtexts '.
|
||||
'LEFT JOIN questtexts ON questtexts.id = questgroups_questtexts.questtext_id '.
|
||||
'LEFT JOIN questtexttypes ON questtexttypes.id = questtexts.questtexttype_id '.
|
||||
'WHERE questgroups_questtexts.questgroup_id = ?',
|
||||
'i',
|
||||
$questgroupId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the Questtext that was last entered by a Character.
|
||||
*
|
||||
* @param int $characterId ID of Character
|
||||
* @param array $questtexts List of Questtexts to look into
|
||||
* @return array Questtext data
|
||||
*/
|
||||
public function pickQuesttextLastEnteredByCharacter($characterId, $questtexts)
|
||||
{
|
||||
if(count($questtexts) == 0) {
|
||||
return null;
|
||||
}
|
||||
$data = $this->db->query(
|
||||
sprintf(
|
||||
'SELECT quest_id '.
|
||||
'FROM quests_characters '.
|
||||
'WHERE character_id = ? AND quest_id IN (%s) AND status = ? '.
|
||||
'ORDER BY created DESC '.
|
||||
'LIMIT 1',
|
||||
implode(',', array_map(function($q) { return intval($q['quest_id']); }, $questtexts))
|
||||
),
|
||||
'ii',
|
||||
$characterId,
|
||||
\hhu\z\models\QuestsModel::QUEST_STATUS_ENTERED
|
||||
);
|
||||
if(count($data) == 0) {
|
||||
return $questtexts[0];
|
||||
}
|
||||
foreach($questtexts as &$questtext) {
|
||||
if($questtext['quest_id'] == $data[0]['quest_id']) {
|
||||
return $questtext;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all registered Questtexttypes.
|
||||
*
|
||||
* @return array Registered Questtexttypes
|
||||
*/
|
||||
public function getQuesttexttypes()
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, type, url '.
|
||||
'FROM questtexttypes'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a Questtexttype by its URL.
|
||||
*
|
||||
* @param string $questtexttypeUrl URL-type of Questtexttype
|
||||
* @return array Questtexttype data
|
||||
*/
|
||||
public function getQuesttexttypeByUrl($questtexttypeUrl)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, type, url '.
|
||||
'FROM questtexttypes '.
|
||||
'WHERE url = ?',
|
||||
's',
|
||||
$questtexttypeUrl
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a Questtexts to a Quest.
|
||||
*
|
||||
* @param int $userId ID of user
|
||||
* @param int $questId ID of Quest to add texts to
|
||||
* @param string $questtexttypeUrl URL-type of Questtexttype of texts
|
||||
* @param string $text Text to add.
|
||||
*/
|
||||
public function addQuesttextToQuest($userId, $questId, $questtexttypeUrl, $text)
|
||||
{
|
||||
$questtexttype = $this->getQuesttexttypeByUrl($questtexttypeUrl);
|
||||
if(is_null($questtexttype)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get position
|
||||
$pos = $this->db->query(
|
||||
'SELECT COALESCE(MAX(pos),0)+1 AS pos '.
|
||||
'FROM questtexts '.
|
||||
'WHERE quest_id = ?',
|
||||
'i',
|
||||
$questId
|
||||
);
|
||||
$pos = $pos[0]['pos'];
|
||||
|
||||
// Add Questtext
|
||||
$this->db->query(
|
||||
'INSERT INTO questtexts '.
|
||||
'(created_user_id, quest_id, questtexttype_id, pos, text) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?, ?, ?)',
|
||||
'iiiis',
|
||||
$userId, $questId, $questtexttype['id'], $pos,
|
||||
$text
|
||||
);
|
||||
|
||||
|
||||
// Return ID
|
||||
return $this->db->getInsertId();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the media for a Quest text.
|
||||
*
|
||||
* @param int $questtextId ID of Quest text to set media for
|
||||
* @param int $questmediaId ID of Questsmedia to set
|
||||
*/
|
||||
public function setQuestmedia($questtextId, $questsmediaId)
|
||||
{
|
||||
$this->db->query(
|
||||
'UPDATE questtexts '.
|
||||
'SET questsmedia_id = ? '.
|
||||
'WHERE id = ?',
|
||||
'ii',
|
||||
$questsmediaId,
|
||||
$questtextId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Edit a Quest text.
|
||||
*
|
||||
* @param int $questtextId ID of Quest text to edit
|
||||
* @param string $text New text
|
||||
*/
|
||||
public function editQuesttext($questtextId, $text)
|
||||
{
|
||||
$this->db->query(
|
||||
'UPDATE questtexts '.
|
||||
'SET text = ? '.
|
||||
'WHERE id = ?',
|
||||
'si',
|
||||
$text,
|
||||
$questtextId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copy Quest texts from one Quest to another.
|
||||
*
|
||||
*
|
||||
* @param int $userId ID of copying user
|
||||
* @param int $sourceQuestId ID of source Quest
|
||||
* @param int $targetQuestId ID of target Quest
|
||||
|
|
@ -325,7 +325,7 @@
|
|||
$questtextIds = array();
|
||||
|
||||
// Get Questtexts
|
||||
$questtexts = $this->getQuesttextsOfQuest($sourceQuestId);
|
||||
$questtexts = $this->getQuesttextsOfQuest($sourceQuestId);
|
||||
|
||||
// Copy each text
|
||||
foreach($questtexts as &$text)
|
||||
|
|
@ -361,29 +361,29 @@
|
|||
|
||||
return $questtextIds;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a Quest text.
|
||||
*
|
||||
* @param array $questtext Data of Quest text to delete
|
||||
*/
|
||||
public function deleteQuesttext($questtext)
|
||||
{
|
||||
// Delete Quest text
|
||||
$this->db->query('DELETE FROM questtexts WHERE id = ?', 'i', $questtext['id']);
|
||||
|
||||
// Adjust positions
|
||||
$this->db->query(
|
||||
'UPDATE questtexts '.
|
||||
'SET pos = pos - 1 '.
|
||||
'WHERE quest_id = ? AND pos > ?',
|
||||
'ii',
|
||||
$questtext['quest_id'],
|
||||
$questtext['pos']
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a Quest text.
|
||||
*
|
||||
* @param array $questtext Data of Quest text to delete
|
||||
*/
|
||||
public function deleteQuesttext($questtext)
|
||||
{
|
||||
// Delete Quest text
|
||||
$this->db->query('DELETE FROM questtexts WHERE id = ?', 'i', $questtext['id']);
|
||||
|
||||
// Adjust positions
|
||||
$this->db->query(
|
||||
'UPDATE questtexts '.
|
||||
'SET pos = pos - 1 '.
|
||||
'WHERE quest_id = ? AND pos > ?',
|
||||
'ii',
|
||||
$questtext['quest_id'],
|
||||
$questtext['pos']
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,110 +1,110 @@
|
|||
<?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 Questtopics-table.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class QuesttopicsModel extends \hhu\z\Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new QuesttopicsModel.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get a Questtopic by its URL.
|
||||
*
|
||||
* @param int $seminaryId ID of Seminary
|
||||
* @param string $questtopicUrl URL-Title of Questtopic
|
||||
* @return array Questtopic data
|
||||
*/
|
||||
public function getQuesttopicByUrl($seminaryId, $questtopicUrl)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, title, url '.
|
||||
'FROM questtopics '.
|
||||
'WHERE seminary_id = ? AND url = ?',
|
||||
'is',
|
||||
$seminaryId, $questtopicUrl
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($questtopicUrl);
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a Questtopic by its ID.
|
||||
*
|
||||
* @param int $questtopicId ID of Questtopic
|
||||
* @return array Questtopic data
|
||||
*/
|
||||
public function getQuesttopicById($questtopicId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, title, url '.
|
||||
'FROM questtopics '.
|
||||
'WHERE id = ?',
|
||||
'i',
|
||||
$questtopicId
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($questtopicId);
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all Questtopics for a Seminary.
|
||||
*
|
||||
* @param int $seminaryId ID of Seminary
|
||||
* @return array List of Questtopics
|
||||
*/
|
||||
public function getQuesttopicsForSeminary($seminaryId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, title, url '.
|
||||
'FROM questtopics '.
|
||||
'WHERE seminary_id = ? '.
|
||||
'ORDER BY title ASC',
|
||||
'i',
|
||||
$seminaryId
|
||||
);
|
||||
}
|
||||
/**
|
||||
* 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 Questtopics-table.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class QuesttopicsModel extends \hhu\z\Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new QuesttopicsModel.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get a Questtopic by its URL.
|
||||
*
|
||||
* @param int $seminaryId ID of Seminary
|
||||
* @param string $questtopicUrl URL-Title of Questtopic
|
||||
* @return array Questtopic data
|
||||
*/
|
||||
public function getQuesttopicByUrl($seminaryId, $questtopicUrl)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, title, url '.
|
||||
'FROM questtopics '.
|
||||
'WHERE seminary_id = ? AND url = ?',
|
||||
'is',
|
||||
$seminaryId, $questtopicUrl
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($questtopicUrl);
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a Questtopic by its ID.
|
||||
*
|
||||
* @param int $questtopicId ID of Questtopic
|
||||
* @return array Questtopic data
|
||||
*/
|
||||
public function getQuesttopicById($questtopicId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, title, url '.
|
||||
'FROM questtopics '.
|
||||
'WHERE id = ?',
|
||||
'i',
|
||||
$questtopicId
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($questtopicId);
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all Questtopics for a Seminary.
|
||||
*
|
||||
* @param int $seminaryId ID of Seminary
|
||||
* @return array List of Questtopics
|
||||
*/
|
||||
public function getQuesttopicsForSeminary($seminaryId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, title, url '.
|
||||
'FROM questtopics '.
|
||||
'WHERE seminary_id = ? '.
|
||||
'ORDER BY title ASC',
|
||||
'i',
|
||||
$seminaryId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copy all Questtopics and their subtopics of a Seminary.
|
||||
*
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $sourceSeminaryId ID of Seminary to copy from
|
||||
* @param int $targetSeminaryId ID of Seminary to copy to
|
||||
|
|
@ -175,301 +175,301 @@
|
|||
|
||||
return $questsubtopicIds;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get count of Quests that are linked to a Questtopic.
|
||||
*
|
||||
* @param int $questtopicId ID of Questtopic
|
||||
* @return int Count of Quests
|
||||
*/
|
||||
public function getQuestCountForQuesttopic($questtopicId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT count(DISTINCT quests_questsubtopics.quest_id) AS c ' .
|
||||
'FROM questsubtopics '.
|
||||
'LEFT JOIN quests_questsubtopics ON quests_questsubtopics.questsubtopic_id = questsubtopics.id '.
|
||||
'WHERE questsubtopics.questtopic_id = ?',
|
||||
'i',
|
||||
$questtopicId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0]['c'];
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get count of Quests that are linked to a Questtopic and are
|
||||
* unlocked by a Character.
|
||||
*
|
||||
* @param int $questtopicId ID of Questtopic
|
||||
* @param int $characterId ID of Character
|
||||
* @return int Count of Quests
|
||||
*/
|
||||
public function getCharacterQuestCountForQuesttopic($questtopicId, $characterId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT count(DISTINCT quests_characters.quest_id) AS c '.
|
||||
'FROM questsubtopics '.
|
||||
'LEFT JOIN quests_questsubtopics ON quests_questsubtopics.questsubtopic_id = questsubtopics.id '.
|
||||
'INNER JOIN quests_characters ON quests_characters.quest_id = quests_questsubtopics.quest_id AND quests_characters.character_id = ? AND quests_characters.status = 3 '.
|
||||
'WHERE questsubtopics.questtopic_id = ?',
|
||||
'ii',
|
||||
$characterId,
|
||||
$questtopicId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0]['c'];
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get alle Questsubtopics for a Questtopic.
|
||||
*
|
||||
* @param int $questtopicId ID of Questtopic
|
||||
* @return array List of Questsubtopics for this Questtopic
|
||||
*/
|
||||
public function getSubtopicsForQuesttopic($questtopicId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, questtopic_id, title, url '.
|
||||
'FROM questsubtopics '.
|
||||
'WHERE questsubtopics.questtopic_id = ? '.
|
||||
'ORDER BY title ASC',
|
||||
'i',
|
||||
$questtopicId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all Questsubtopics for a Quest.
|
||||
*
|
||||
* @param int $questId ID of Quest
|
||||
* @return array List of Questsubtopics
|
||||
*/
|
||||
public function getQuestsubtopicsForQuest($questId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT DISTINCT id, questtopic_id, title, url '.
|
||||
'FROM quests_questsubtopics '.
|
||||
'INNER JOIN questsubtopics ON questsubtopics.id = quests_questsubtopics.questsubtopic_id '.
|
||||
'WHERE quests_questsubtopics.quest_id = ? '.
|
||||
'ORDER BY questsubtopics.title ASC',
|
||||
'i',
|
||||
$questId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set Questsubtopics for a Quest.
|
||||
*
|
||||
* @param int $questId ID of Quest to set subtopics for
|
||||
* @param array $questsubtopicIds List of IDs of subtopics to set
|
||||
*/
|
||||
public function setQuestsubtopicsForQuest($questId, $questsubtopicIds)
|
||||
{
|
||||
$this->db->setAutocommit(false);
|
||||
try {
|
||||
// Remove Questsubtopics
|
||||
$this->db->query(
|
||||
'DELETE FROM quests_questsubtopics '.
|
||||
'WHERE quest_id = ?',
|
||||
'i',
|
||||
$questId
|
||||
);
|
||||
|
||||
// Add Questsubtopics
|
||||
foreach($questsubtopicIds as &$questsubtopicId)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO quests_questsubtopics '.
|
||||
'(quest_id, questsubtopic_id) '.
|
||||
'VALUES '.
|
||||
'(?, ?)',
|
||||
'ii',
|
||||
$questId, $questsubtopicId
|
||||
);
|
||||
}
|
||||
}
|
||||
catch(\nre\exceptions\DatamodelException $e) {
|
||||
$this->db->rollback();
|
||||
$this->db->setAutocommit(true);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$this->db->setAutocommit(true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if a Questtopic title already exists.
|
||||
*
|
||||
* @param string $title Questtopic title to check
|
||||
* @param int $questtopicId Do not check this ID (for editing)
|
||||
* @return boolean Whether Questtopic title exists or not
|
||||
*/
|
||||
public function questtopicTitleExists($title, $questtopicId=null)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id '.
|
||||
'FROM questtopics '.
|
||||
'WHERE title = ? OR url = ?',
|
||||
'ss',
|
||||
$title,
|
||||
\nre\core\Linker::createLinkParam($title)
|
||||
);
|
||||
|
||||
return (!empty($data) && (is_null($questtopicId) || $questtopicId != $data[0]['id']));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new Questtopic for a Seminary.
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $seminaryId ID of Seminary
|
||||
* @param string $title Title for new Questtopic
|
||||
* @return int ID of newly created Questtopic
|
||||
*/
|
||||
public function createQuesttopic($userId, $seminaryId, $title)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO questtopics '.
|
||||
'(created_user_id, seminary_id, title, url) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?, ?) ',
|
||||
'iiss',
|
||||
$userId,
|
||||
$seminaryId,
|
||||
$title,
|
||||
\nre\core\Linker::createLinkParam($title)
|
||||
);
|
||||
|
||||
return $this->db->getInsertId();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Edit a Questtopic.
|
||||
*
|
||||
* @param int $questtopicId ID of Questtopic to edit
|
||||
* @param string $title New title of Questtopic
|
||||
*/
|
||||
public function editQuesttopic($questtopicId, $title)
|
||||
{
|
||||
$this->db->query(
|
||||
'UPDATE questtopics '.
|
||||
'SET title = ?, url = ? '.
|
||||
'WHERE id = ?',
|
||||
'ssi',
|
||||
$title,
|
||||
\nre\core\Linker::createLinkParam($title),
|
||||
$questtopicId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a Questtopic.
|
||||
*
|
||||
* @param int $questtopicId ID of Questtopic to delete
|
||||
*/
|
||||
public function deleteQuesttopic($questtopicId)
|
||||
{
|
||||
$this->db->query('DELETE FROM questtopics WHERE id = ?', 'i', $questtopicId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if a Questsubtopic title already exists.
|
||||
*
|
||||
* @param int $questtopicId ID of Questtopic
|
||||
* @param string $title Questsubtopic title to check
|
||||
* @param int $questsubtopicId Do not check this ID (for editing)
|
||||
* @return boolean Whether Questsubtopic title exists or not
|
||||
*/
|
||||
public function questsubtopicTitleExists($questtopicId, $title, $questsubtopicId=null)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id '.
|
||||
'FROM questsubtopics '.
|
||||
'WHERE questtopic_id = ? AND (title = ? OR url = ?)',
|
||||
'iss',
|
||||
$questtopicId,
|
||||
$title,
|
||||
\nre\core\Linker::createLinkParam($title)
|
||||
);
|
||||
|
||||
return (!empty($data) && (is_null($questsubtopicId) || $questsubtopicId != $data[0]['id']));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new Questsubtopic for a Questtopic.
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $questtopicId ID of Qusttopic
|
||||
* @param string $title Title for new Questtopic
|
||||
* @return int ID of newly created Questsubtopic
|
||||
*/
|
||||
public function createQuestsubtopic($userId, $questtopicId, $title)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO questsubtopics '.
|
||||
'(created_user_id, questtopic_id, title, url) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?, ?) ',
|
||||
'iiss',
|
||||
$userId,
|
||||
$questtopicId,
|
||||
$title,
|
||||
\nre\core\Linker::createLinkParam($title)
|
||||
);
|
||||
|
||||
return $this->db->getInsertId();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Edit a Questsubtopic.
|
||||
*
|
||||
* @param int $questsubtopicId ID of Questsubtopic to edit
|
||||
* @param string $title New title of Questsubtopic
|
||||
*/
|
||||
public function editQuestsubtopic($questsubtopicId, $title)
|
||||
{
|
||||
$this->db->query(
|
||||
'UPDATE questsubtopics '.
|
||||
'SET title = ?, url = ? '.
|
||||
'WHERE id = ?',
|
||||
'ssi',
|
||||
$title,
|
||||
\nre\core\Linker::createLinkParam($title),
|
||||
$questsubtopicId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a Questsubtopic.
|
||||
*
|
||||
* @param int $questsubtopicId ID of Questsubtopic to delete
|
||||
*/
|
||||
public function deleteQuestsubtopic($questtopicId)
|
||||
{
|
||||
$this->db->query('DELETE FROM questsubtopics WHERE id = ?', 'i', $questtopicId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get count of Quests that are linked to a Questtopic.
|
||||
*
|
||||
* @param int $questtopicId ID of Questtopic
|
||||
* @return int Count of Quests
|
||||
*/
|
||||
public function getQuestCountForQuesttopic($questtopicId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT count(DISTINCT quests_questsubtopics.quest_id) AS c ' .
|
||||
'FROM questsubtopics '.
|
||||
'LEFT JOIN quests_questsubtopics ON quests_questsubtopics.questsubtopic_id = questsubtopics.id '.
|
||||
'WHERE questsubtopics.questtopic_id = ?',
|
||||
'i',
|
||||
$questtopicId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0]['c'];
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get count of Quests that are linked to a Questtopic and are
|
||||
* unlocked by a Character.
|
||||
*
|
||||
* @param int $questtopicId ID of Questtopic
|
||||
* @param int $characterId ID of Character
|
||||
* @return int Count of Quests
|
||||
*/
|
||||
public function getCharacterQuestCountForQuesttopic($questtopicId, $characterId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT count(DISTINCT quests_characters.quest_id) AS c '.
|
||||
'FROM questsubtopics '.
|
||||
'LEFT JOIN quests_questsubtopics ON quests_questsubtopics.questsubtopic_id = questsubtopics.id '.
|
||||
'INNER JOIN quests_characters ON quests_characters.quest_id = quests_questsubtopics.quest_id AND quests_characters.character_id = ? AND quests_characters.status = 3 '.
|
||||
'WHERE questsubtopics.questtopic_id = ?',
|
||||
'ii',
|
||||
$characterId,
|
||||
$questtopicId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0]['c'];
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get alle Questsubtopics for a Questtopic.
|
||||
*
|
||||
* @param int $questtopicId ID of Questtopic
|
||||
* @return array List of Questsubtopics for this Questtopic
|
||||
*/
|
||||
public function getSubtopicsForQuesttopic($questtopicId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, questtopic_id, title, url '.
|
||||
'FROM questsubtopics '.
|
||||
'WHERE questsubtopics.questtopic_id = ? '.
|
||||
'ORDER BY title ASC',
|
||||
'i',
|
||||
$questtopicId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all Questsubtopics for a Quest.
|
||||
*
|
||||
* @param int $questId ID of Quest
|
||||
* @return array List of Questsubtopics
|
||||
*/
|
||||
public function getQuestsubtopicsForQuest($questId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT DISTINCT id, questtopic_id, title, url '.
|
||||
'FROM quests_questsubtopics '.
|
||||
'INNER JOIN questsubtopics ON questsubtopics.id = quests_questsubtopics.questsubtopic_id '.
|
||||
'WHERE quests_questsubtopics.quest_id = ? '.
|
||||
'ORDER BY questsubtopics.title ASC',
|
||||
'i',
|
||||
$questId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set Questsubtopics for a Quest.
|
||||
*
|
||||
* @param int $questId ID of Quest to set subtopics for
|
||||
* @param array $questsubtopicIds List of IDs of subtopics to set
|
||||
*/
|
||||
public function setQuestsubtopicsForQuest($questId, $questsubtopicIds)
|
||||
{
|
||||
$this->db->setAutocommit(false);
|
||||
try {
|
||||
// Remove Questsubtopics
|
||||
$this->db->query(
|
||||
'DELETE FROM quests_questsubtopics '.
|
||||
'WHERE quest_id = ?',
|
||||
'i',
|
||||
$questId
|
||||
);
|
||||
|
||||
// Add Questsubtopics
|
||||
foreach($questsubtopicIds as &$questsubtopicId)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO quests_questsubtopics '.
|
||||
'(quest_id, questsubtopic_id) '.
|
||||
'VALUES '.
|
||||
'(?, ?)',
|
||||
'ii',
|
||||
$questId, $questsubtopicId
|
||||
);
|
||||
}
|
||||
}
|
||||
catch(\nre\exceptions\DatamodelException $e) {
|
||||
$this->db->rollback();
|
||||
$this->db->setAutocommit(true);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$this->db->setAutocommit(true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if a Questtopic title already exists.
|
||||
*
|
||||
* @param string $title Questtopic title to check
|
||||
* @param int $questtopicId Do not check this ID (for editing)
|
||||
* @return boolean Whether Questtopic title exists or not
|
||||
*/
|
||||
public function questtopicTitleExists($title, $questtopicId=null)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id '.
|
||||
'FROM questtopics '.
|
||||
'WHERE title = ? OR url = ?',
|
||||
'ss',
|
||||
$title,
|
||||
\nre\core\Linker::createLinkParam($title)
|
||||
);
|
||||
|
||||
return (!empty($data) && (is_null($questtopicId) || $questtopicId != $data[0]['id']));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new Questtopic for a Seminary.
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $seminaryId ID of Seminary
|
||||
* @param string $title Title for new Questtopic
|
||||
* @return int ID of newly created Questtopic
|
||||
*/
|
||||
public function createQuesttopic($userId, $seminaryId, $title)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO questtopics '.
|
||||
'(created_user_id, seminary_id, title, url) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?, ?) ',
|
||||
'iiss',
|
||||
$userId,
|
||||
$seminaryId,
|
||||
$title,
|
||||
\nre\core\Linker::createLinkParam($title)
|
||||
);
|
||||
|
||||
return $this->db->getInsertId();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Edit a Questtopic.
|
||||
*
|
||||
* @param int $questtopicId ID of Questtopic to edit
|
||||
* @param string $title New title of Questtopic
|
||||
*/
|
||||
public function editQuesttopic($questtopicId, $title)
|
||||
{
|
||||
$this->db->query(
|
||||
'UPDATE questtopics '.
|
||||
'SET title = ?, url = ? '.
|
||||
'WHERE id = ?',
|
||||
'ssi',
|
||||
$title,
|
||||
\nre\core\Linker::createLinkParam($title),
|
||||
$questtopicId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a Questtopic.
|
||||
*
|
||||
* @param int $questtopicId ID of Questtopic to delete
|
||||
*/
|
||||
public function deleteQuesttopic($questtopicId)
|
||||
{
|
||||
$this->db->query('DELETE FROM questtopics WHERE id = ?', 'i', $questtopicId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if a Questsubtopic title already exists.
|
||||
*
|
||||
* @param int $questtopicId ID of Questtopic
|
||||
* @param string $title Questsubtopic title to check
|
||||
* @param int $questsubtopicId Do not check this ID (for editing)
|
||||
* @return boolean Whether Questsubtopic title exists or not
|
||||
*/
|
||||
public function questsubtopicTitleExists($questtopicId, $title, $questsubtopicId=null)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id '.
|
||||
'FROM questsubtopics '.
|
||||
'WHERE questtopic_id = ? AND (title = ? OR url = ?)',
|
||||
'iss',
|
||||
$questtopicId,
|
||||
$title,
|
||||
\nre\core\Linker::createLinkParam($title)
|
||||
);
|
||||
|
||||
return (!empty($data) && (is_null($questsubtopicId) || $questsubtopicId != $data[0]['id']));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new Questsubtopic for a Questtopic.
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $questtopicId ID of Qusttopic
|
||||
* @param string $title Title for new Questtopic
|
||||
* @return int ID of newly created Questsubtopic
|
||||
*/
|
||||
public function createQuestsubtopic($userId, $questtopicId, $title)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO questsubtopics '.
|
||||
'(created_user_id, questtopic_id, title, url) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?, ?) ',
|
||||
'iiss',
|
||||
$userId,
|
||||
$questtopicId,
|
||||
$title,
|
||||
\nre\core\Linker::createLinkParam($title)
|
||||
);
|
||||
|
||||
return $this->db->getInsertId();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Edit a Questsubtopic.
|
||||
*
|
||||
* @param int $questsubtopicId ID of Questsubtopic to edit
|
||||
* @param string $title New title of Questsubtopic
|
||||
*/
|
||||
public function editQuestsubtopic($questsubtopicId, $title)
|
||||
{
|
||||
$this->db->query(
|
||||
'UPDATE questsubtopics '.
|
||||
'SET title = ?, url = ? '.
|
||||
'WHERE id = ?',
|
||||
'ssi',
|
||||
$title,
|
||||
\nre\core\Linker::createLinkParam($title),
|
||||
$questsubtopicId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a Questsubtopic.
|
||||
*
|
||||
* @param int $questsubtopicId ID of Questsubtopic to delete
|
||||
*/
|
||||
public function deleteQuestsubtopic($questtopicId)
|
||||
{
|
||||
$this->db->query('DELETE FROM questsubtopics WHERE id = ?', 'i', $questtopicId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,77 +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 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 all registered Questtypes.
|
||||
*
|
||||
* @return array List of registered Questtypes
|
||||
*/
|
||||
public function getQuesttypes()
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, title, url, classname '.
|
||||
'FROM questtypes '.
|
||||
'ORDER BY title ASC'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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];
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* 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 all registered Questtypes.
|
||||
*
|
||||
* @return array List of registered Questtypes
|
||||
*/
|
||||
public function getQuesttypes()
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, title, url, classname '.
|
||||
'FROM questtypes '.
|
||||
'ORDER BY title ASC'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,314 +1,314 @@
|
|||
<?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
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('questgroupshierarchy', 'questgroups', 'quests', 'questtopics', 'media', 'charactertypes', 'xplevels', 'avatars', 'achievements', 'charactergroups', 'charactergroupsquests', 'seminarycharacterfields');
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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, course, description, seminarymedia_id, charactergroups_seminarymedia_id, achievements_seminarymedia_id, library_seminarymedia_id, map_seminarymedia_id '.
|
||||
'FROM seminaries '.
|
||||
'ORDER BY created DESC'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a seminary and its data by its ID.
|
||||
*
|
||||
* @throws \nre\exceptions\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, course, description, seminarymedia_id, charactergroups_seminarymedia_id, achievements_seminarymedia_id, library_seminarymedia_id, map_seminarymedia_id '.
|
||||
'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 \nre\exceptions\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, course, description, seminarymedia_id, charactergroups_seminarymedia_id, achievements_seminarymedia_id, library_seminarymedia_id, map_seminarymedia_id '.
|
||||
'FROM seminaries '.
|
||||
'WHERE url = ?',
|
||||
's',
|
||||
$seminaryUrl
|
||||
);
|
||||
if(empty($seminary)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($seminaryUrl);
|
||||
}
|
||||
|
||||
|
||||
return $seminary[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculate sum of XPs for a Seminary.
|
||||
*
|
||||
* @param int $seminaryId ID of Seminary
|
||||
* @return int Total sum of XPs
|
||||
*/
|
||||
public function getTotalXPs($seminaryId)
|
||||
{
|
||||
$xps = 0;
|
||||
|
||||
// Questgroups
|
||||
$questgroupshierarchy = $this->Questgroupshierarchy->getHierarchyOfSeminary($seminaryId);
|
||||
foreach($questgroupshierarchy as &$hierarchy)
|
||||
{
|
||||
// Get Questgroups
|
||||
$questgroups = $this->Questgroups->getQuestgroupsForHierarchy($hierarchy['id']);
|
||||
foreach($questgroups as &$questgroup) {
|
||||
$xps += $questgroup['achievable_xps'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $xps;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if a Seminary title already exists.
|
||||
*
|
||||
* @param string $title Seminary title to check
|
||||
* @param int $seminaryId Do not check this ID (for editing)
|
||||
* @return boolean Whether Seminary title exists or not
|
||||
*/
|
||||
public function seminaryTitleExists($title, $seminaryId=null)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id '.
|
||||
'FROM seminaries '.
|
||||
'WHERE title = ? OR url = ?',
|
||||
'ss',
|
||||
$title,
|
||||
\nre\core\Linker::createLinkParam($title)
|
||||
);
|
||||
|
||||
return (!empty($data) && (is_null($seminaryId) || $seminaryId != $data[0]['id']));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new Seminary.
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param string $title Title of Seminary to create
|
||||
* @param string $course Course of Seminary
|
||||
* @param string $description Description of new Seminary
|
||||
* @return int ID of the newly created Seminary
|
||||
*/
|
||||
public function createSeminary($userId, $title, $course, $description)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO seminaries '.
|
||||
'(created_user_id, title, url, course, description) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?, ?, ?)',
|
||||
'issss',
|
||||
$userId,
|
||||
$title,
|
||||
\nre\core\Linker::createLinkParam($title),
|
||||
$course,
|
||||
$description
|
||||
);
|
||||
|
||||
|
||||
return $this->db->getInsertId();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the moodpic for a Seminary.
|
||||
*
|
||||
* @param int $seminaryId ID of Seminary to set moodpic for
|
||||
* @param int $mediaId ID of moodpic media
|
||||
*/
|
||||
public function setMoodpicForSeminary($seminaryId, $mediaId)
|
||||
{
|
||||
$this->db->query(
|
||||
'UPDATE seminaries '.
|
||||
'SET seminarymedia_id = ? '.
|
||||
'WHERE id = ?',
|
||||
'ii',
|
||||
$mediaId,
|
||||
$seminaryId
|
||||
);
|
||||
}
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('questgroupshierarchy', 'questgroups', 'quests', 'questtopics', 'media', 'charactertypes', 'xplevels', 'avatars', 'achievements', 'charactergroups', 'charactergroupsquests', 'seminarycharacterfields');
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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, course, description, seminarymedia_id, charactergroups_seminarymedia_id, achievements_seminarymedia_id, library_seminarymedia_id, map_seminarymedia_id '.
|
||||
'FROM seminaries '.
|
||||
'ORDER BY created DESC'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a seminary and its data by its ID.
|
||||
*
|
||||
* @throws \nre\exceptions\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, course, description, seminarymedia_id, charactergroups_seminarymedia_id, achievements_seminarymedia_id, library_seminarymedia_id, map_seminarymedia_id '.
|
||||
'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 \nre\exceptions\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, course, description, seminarymedia_id, charactergroups_seminarymedia_id, achievements_seminarymedia_id, library_seminarymedia_id, map_seminarymedia_id '.
|
||||
'FROM seminaries '.
|
||||
'WHERE url = ?',
|
||||
's',
|
||||
$seminaryUrl
|
||||
);
|
||||
if(empty($seminary)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($seminaryUrl);
|
||||
}
|
||||
|
||||
|
||||
return $seminary[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculate sum of XPs for a Seminary.
|
||||
*
|
||||
* @param int $seminaryId ID of Seminary
|
||||
* @return int Total sum of XPs
|
||||
*/
|
||||
public function getTotalXPs($seminaryId)
|
||||
{
|
||||
$xps = 0;
|
||||
|
||||
// Questgroups
|
||||
$questgroupshierarchy = $this->Questgroupshierarchy->getHierarchyOfSeminary($seminaryId);
|
||||
foreach($questgroupshierarchy as &$hierarchy)
|
||||
{
|
||||
// Get Questgroups
|
||||
$questgroups = $this->Questgroups->getQuestgroupsForHierarchy($hierarchy['id']);
|
||||
foreach($questgroups as &$questgroup) {
|
||||
$xps += $questgroup['achievable_xps'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $xps;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if a Seminary title already exists.
|
||||
*
|
||||
* @param string $title Seminary title to check
|
||||
* @param int $seminaryId Do not check this ID (for editing)
|
||||
* @return boolean Whether Seminary title exists or not
|
||||
*/
|
||||
public function seminaryTitleExists($title, $seminaryId=null)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id '.
|
||||
'FROM seminaries '.
|
||||
'WHERE title = ? OR url = ?',
|
||||
'ss',
|
||||
$title,
|
||||
\nre\core\Linker::createLinkParam($title)
|
||||
);
|
||||
|
||||
return (!empty($data) && (is_null($seminaryId) || $seminaryId != $data[0]['id']));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new Seminary.
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param string $title Title of Seminary to create
|
||||
* @param string $course Course of Seminary
|
||||
* @param string $description Description of new Seminary
|
||||
* @return int ID of the newly created Seminary
|
||||
*/
|
||||
public function createSeminary($userId, $title, $course, $description)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO seminaries '.
|
||||
'(created_user_id, title, url, course, description) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?, ?, ?)',
|
||||
'issss',
|
||||
$userId,
|
||||
$title,
|
||||
\nre\core\Linker::createLinkParam($title),
|
||||
$course,
|
||||
$description
|
||||
);
|
||||
|
||||
|
||||
return $this->db->getInsertId();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the moodpic for a Seminary.
|
||||
*
|
||||
* @param int $seminaryId ID of Seminary to set moodpic for
|
||||
* @param int $mediaId ID of moodpic media
|
||||
*/
|
||||
public function setMoodpicForSeminary($seminaryId, $mediaId)
|
||||
{
|
||||
$this->db->query(
|
||||
'UPDATE seminaries '.
|
||||
'SET seminarymedia_id = ? '.
|
||||
'WHERE id = ?',
|
||||
'ii',
|
||||
$mediaId,
|
||||
$seminaryId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the moodpic for the Character groups of a Seminary.
|
||||
*
|
||||
*
|
||||
* @param int $seminaryId ID of Seminary to set moodpic for Character groups for
|
||||
* @param int $seminaryMediaId ID of Seminarymedia to set as moodpic
|
||||
*/
|
||||
public function setMoodpicForCharactergroups($seminaryId, $seminaryMediaId)
|
||||
{
|
||||
$this->db->query(
|
||||
'UPDATE seminaries '.
|
||||
'SET charactergroups_seminarymedia_id = ? '.
|
||||
'WHERE id = ?',
|
||||
'ii',
|
||||
$seminaryMediaId,
|
||||
$seminaryId
|
||||
);
|
||||
$this->db->query(
|
||||
'UPDATE seminaries '.
|
||||
'SET charactergroups_seminarymedia_id = ? '.
|
||||
'WHERE id = ?',
|
||||
'ii',
|
||||
$seminaryMediaId,
|
||||
$seminaryId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the moodpic for the Achievements of a Seminary.
|
||||
*
|
||||
*
|
||||
* @param int $seminaryId ID of Seminary to set moodpic for Achievements for
|
||||
* @param int $seminaryMediaId ID of Seminarymedia to set as moodpic
|
||||
*/
|
||||
public function setMoodpicForAchievements($seminaryId, $seminaryMediaId)
|
||||
{
|
||||
$this->db->query(
|
||||
'UPDATE seminaries '.
|
||||
'SET achievements_seminarymedia_id = ? '.
|
||||
'WHERE id = ?',
|
||||
'ii',
|
||||
$seminaryMediaId,
|
||||
$seminaryId
|
||||
);
|
||||
$this->db->query(
|
||||
'UPDATE seminaries '.
|
||||
'SET achievements_seminarymedia_id = ? '.
|
||||
'WHERE id = ?',
|
||||
'ii',
|
||||
$seminaryMediaId,
|
||||
$seminaryId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the moodpic for the library of a Seminary.
|
||||
*
|
||||
*
|
||||
* @param int $seminaryId ID of Seminary to set moodpic for Library for
|
||||
* @param int $seminaryMediaId ID of Seminarymedia to set as moodpic
|
||||
*/
|
||||
public function setMoodpicForLibrary($seminaryId, $seminaryMediaId)
|
||||
{
|
||||
$this->db->query(
|
||||
'UPDATE seminaries '.
|
||||
'SET library_seminarymedia_id = ? '.
|
||||
'WHERE id = ?',
|
||||
'ii',
|
||||
$seminaryMediaId,
|
||||
$seminaryId
|
||||
);
|
||||
$this->db->query(
|
||||
'UPDATE seminaries '.
|
||||
'SET library_seminarymedia_id = ? '.
|
||||
'WHERE id = ?',
|
||||
'ii',
|
||||
$seminaryMediaId,
|
||||
$seminaryId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* (Re-) Calculate the amount of achievable XPs for a Seminary.
|
||||
*
|
||||
* (Re-) Calculate the amount of achievable XPs for a Seminary.
|
||||
*
|
||||
* @param int $seminaryId ID of Seminary to calculate XPs for
|
||||
*/
|
||||
public function calculateXPsForSeminary($seminaryId)
|
||||
{
|
||||
// Questgrouphierarchy and Questgroups
|
||||
$questgroupshierarchy = $this->Questgroupshierarchy->getHierarchyOfSeminary($seminaryId);
|
||||
foreach($questgroupshierarchy as &$hierarchy)
|
||||
{
|
||||
// Get Questgroups
|
||||
$hierarchy['questgroups'] = $this->Questgroups->getQuestgroupsForHierarchy($hierarchy['id']);
|
||||
foreach($hierarchy['questgroups'] as &$questgroup)
|
||||
{
|
||||
// Calculate achievable XPs
|
||||
$this->Questgroups->calculateXPsForQuestgroup($questgroup['id']);
|
||||
}
|
||||
}
|
||||
// Questgrouphierarchy and Questgroups
|
||||
$questgroupshierarchy = $this->Questgroupshierarchy->getHierarchyOfSeminary($seminaryId);
|
||||
foreach($questgroupshierarchy as &$hierarchy)
|
||||
{
|
||||
// Get Questgroups
|
||||
$hierarchy['questgroups'] = $this->Questgroups->getQuestgroupsForHierarchy($hierarchy['id']);
|
||||
foreach($hierarchy['questgroups'] as &$questgroup)
|
||||
{
|
||||
// Calculate achievable XPs
|
||||
$this->Questgroups->calculateXPsForQuestgroup($questgroup['id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Edit a seminary.
|
||||
*
|
||||
* @throws \nre\exceptions\DatamodelException
|
||||
* @param int $seminaryId ID of Seminary to edit
|
||||
* @param string $title New title of Seminary
|
||||
* @param string $course New course of Seminary
|
||||
* @param string $description New description of Seminary
|
||||
*/
|
||||
public function editSeminary($seminaryId, $title, $course, $description)
|
||||
{
|
||||
$this->db->query(
|
||||
'UPDATE seminaries '.
|
||||
'SET title = ?, url = ?, course = ?, description = ? '.
|
||||
'WHERE id = ?',
|
||||
'ssssi',
|
||||
$title,
|
||||
\nre\core\Linker::createLinkParam($title),
|
||||
$course,
|
||||
$description,
|
||||
$seminaryId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Edit a seminary.
|
||||
*
|
||||
* @throws \nre\exceptions\DatamodelException
|
||||
* @param int $seminaryId ID of Seminary to edit
|
||||
* @param string $title New title of Seminary
|
||||
* @param string $course New course of Seminary
|
||||
* @param string $description New description of Seminary
|
||||
*/
|
||||
public function editSeminary($seminaryId, $title, $course, $description)
|
||||
{
|
||||
$this->db->query(
|
||||
'UPDATE seminaries '.
|
||||
'SET title = ?, url = ?, course = ?, description = ? '.
|
||||
'WHERE id = ?',
|
||||
'ssssi',
|
||||
$title,
|
||||
\nre\core\Linker::createLinkParam($title),
|
||||
$course,
|
||||
$description,
|
||||
$seminaryId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copy a Seminary and its content.
|
||||
*
|
||||
*
|
||||
* @param int $userId ID of copying user
|
||||
* @param int $sourceSeminaryId ID of Seminary to copy
|
||||
* @param string $title Title of new Seminary
|
||||
|
|
@ -328,8 +328,8 @@
|
|||
* @param boolean $copyCharactergroupsquests Whether to copy Character groups Quests or not
|
||||
* @return ID of newly created Seminary
|
||||
*/
|
||||
public function copySeminary($userId, $sourceSeminaryId, $title, $course, $description, $copySeminaryfields, $copyMedia, $copyQuestgroupshierarchy, $copyQuestgroups, $copyQuests, $copyQuesttopics, $copyCharactertypes, $copyXPlevels, $copyAvatars, $copyAchievements, $copyCharactergroupsgroups, $copyCharactergroupsquests)
|
||||
{
|
||||
public function copySeminary($userId, $sourceSeminaryId, $title, $course, $description, $copySeminaryfields, $copyMedia, $copyQuestgroupshierarchy, $copyQuestgroups, $copyQuests, $copyQuesttopics, $copyCharactertypes, $copyXPlevels, $copyAvatars, $copyAchievements, $copyCharactergroupsgroups, $copyCharactergroupsquests)
|
||||
{
|
||||
// Get Seminary
|
||||
$seminary = $this->getSeminaryById($sourceSeminaryId);
|
||||
|
||||
|
|
@ -426,31 +426,31 @@
|
|||
// Recalculate XPs
|
||||
$this->calculateXPsForSeminary($targetSeminaryId);
|
||||
|
||||
$this->db->commit();
|
||||
}
|
||||
$this->db->commit();
|
||||
}
|
||||
catch(\Exception $e) {
|
||||
$this->db->rollback();
|
||||
$this->db->setAutocommit(true);
|
||||
throw $e;
|
||||
}
|
||||
$this->db->setAutocommit(true);
|
||||
$this->db->rollback();
|
||||
$this->db->setAutocommit(true);
|
||||
throw $e;
|
||||
}
|
||||
$this->db->setAutocommit(true);
|
||||
|
||||
|
||||
return $targetSeminaryId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a seminary.
|
||||
* TODO Delete media
|
||||
*
|
||||
* @param int $seminaryId ID of the seminary to delete
|
||||
*/
|
||||
public function deleteSeminary($seminaryId)
|
||||
{
|
||||
$this->db->query('DELETE FROM seminaries WHERE id = ?', 'i', $seminaryId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a seminary.
|
||||
* TODO Delete media
|
||||
*
|
||||
* @param int $seminaryId ID of the seminary to delete
|
||||
*/
|
||||
public function deleteSeminary($seminaryId)
|
||||
{
|
||||
$this->db->query('DELETE FROM seminaries WHERE id = ?', 'i', $seminaryId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,133 +1,133 @@
|
|||
<?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 all Character fields of a Seminary.
|
||||
*
|
||||
* @param int $seminaryId ID of Seminary to get fields of
|
||||
* @param array Seminary Character fields
|
||||
*/
|
||||
public function getFieldsForSeminary($seminaryId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT seminarycharacterfields.id, seminarycharacterfields.title, seminarycharacterfields.url, seminarycharacterfields.regex, seminarycharacterfields.required, seminarycharacterfieldtypes.id AS type_id, seminarycharacterfieldtypes.title AS type_title, seminarycharacterfieldtypes.url AS type_url '.
|
||||
'FROM seminarycharacterfields '.
|
||||
'LEFT JOIN seminarycharacterfieldtypes ON seminarycharacterfieldtypes.id = seminarycharacterfields.seminarycharacterfieldtype_id '.
|
||||
'WHERE seminarycharacterfields.seminary_id = ? '.
|
||||
'ORDER BY pos ASC',
|
||||
'i',
|
||||
$seminaryId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the value of a Seminary field for a Character.
|
||||
*
|
||||
* @param int $characterId ID of Character
|
||||
* @param int $seminarycharacterfieldId ID of seminarycharacterfield to set value of
|
||||
* @param string $value Value to set
|
||||
*/
|
||||
public function setSeminaryFieldOfCharacter($seminarycharacterfieldId, $characterId, $value)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO characters_seminarycharacterfields '.
|
||||
'(character_id, seminarycharacterfield_id, value) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?) '.
|
||||
'ON DUPLICATE KEY UPDATE '.
|
||||
'value = ?',
|
||||
'iiss',
|
||||
$characterId,
|
||||
$seminarycharacterfieldId,
|
||||
$value,
|
||||
$value
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Seminary Character fields of a Character.
|
||||
*
|
||||
* @param int $fieldId ID of Seminary Character field
|
||||
* @param int $characterId ID of the Character
|
||||
* @return array Seminary Character fields
|
||||
*/
|
||||
public function getSeminaryFieldOfCharacter($fieldId, $characterId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT created, value '.
|
||||
'FROM characters_seminarycharacterfields '.
|
||||
'WHERE seminarycharacterfield_id = ? AND character_id = ?',
|
||||
'ii',
|
||||
$fieldId,
|
||||
$characterId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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.id, seminarycharacterfields.title, seminarycharacterfields.url, seminarycharacterfields.regex, seminarycharacterfields.required, seminarycharacterfieldtypes.id AS type_id, seminarycharacterfieldtypes.title AS type_title, seminarycharacterfieldtypes.url AS type_url, 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
|
||||
);
|
||||
}
|
||||
/**
|
||||
* 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 all Character fields of a Seminary.
|
||||
*
|
||||
* @param int $seminaryId ID of Seminary to get fields of
|
||||
* @param array Seminary Character fields
|
||||
*/
|
||||
public function getFieldsForSeminary($seminaryId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT seminarycharacterfields.id, seminarycharacterfields.title, seminarycharacterfields.url, seminarycharacterfields.regex, seminarycharacterfields.required, seminarycharacterfieldtypes.id AS type_id, seminarycharacterfieldtypes.title AS type_title, seminarycharacterfieldtypes.url AS type_url '.
|
||||
'FROM seminarycharacterfields '.
|
||||
'LEFT JOIN seminarycharacterfieldtypes ON seminarycharacterfieldtypes.id = seminarycharacterfields.seminarycharacterfieldtype_id '.
|
||||
'WHERE seminarycharacterfields.seminary_id = ? '.
|
||||
'ORDER BY pos ASC',
|
||||
'i',
|
||||
$seminaryId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the value of a Seminary field for a Character.
|
||||
*
|
||||
* @param int $characterId ID of Character
|
||||
* @param int $seminarycharacterfieldId ID of seminarycharacterfield to set value of
|
||||
* @param string $value Value to set
|
||||
*/
|
||||
public function setSeminaryFieldOfCharacter($seminarycharacterfieldId, $characterId, $value)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO characters_seminarycharacterfields '.
|
||||
'(character_id, seminarycharacterfield_id, value) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?) '.
|
||||
'ON DUPLICATE KEY UPDATE '.
|
||||
'value = ?',
|
||||
'iiss',
|
||||
$characterId,
|
||||
$seminarycharacterfieldId,
|
||||
$value,
|
||||
$value
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Seminary Character fields of a Character.
|
||||
*
|
||||
* @param int $fieldId ID of Seminary Character field
|
||||
* @param int $characterId ID of the Character
|
||||
* @return array Seminary Character fields
|
||||
*/
|
||||
public function getSeminaryFieldOfCharacter($fieldId, $characterId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT created, value '.
|
||||
'FROM characters_seminarycharacterfields '.
|
||||
'WHERE seminarycharacterfield_id = ? AND character_id = ?',
|
||||
'ii',
|
||||
$fieldId,
|
||||
$characterId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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.id, seminarycharacterfields.title, seminarycharacterfields.url, seminarycharacterfields.regex, seminarycharacterfields.required, seminarycharacterfieldtypes.id AS type_id, seminarycharacterfieldtypes.title AS type_title, seminarycharacterfieldtypes.url AS type_url, 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
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copy all Character fields of a Seminary.
|
||||
*
|
||||
*
|
||||
* @param int $userId ID of copying user
|
||||
* @param int $sourceSeminaryId ID of Seminary to copy from
|
||||
* @param int $targetSeminaryId ID of Seminary to copy to
|
||||
|
|
@ -145,7 +145,7 @@
|
|||
$sourceSeminaryId
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,157 +1,157 @@
|
|||
<?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 handle files to upload.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class UploadsModel extends \hhu\z\Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new UploadsModel.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Upload a file and create a database record.
|
||||
*
|
||||
* @param int $userId ID of user that uploads the file
|
||||
* @param int $seminaryId ID of Seminary
|
||||
* @param string $name Name of file to upload
|
||||
* @param string $filename Filename of file to upload
|
||||
* @param string $tmpFilename Name of temporary uploaded file
|
||||
* @param string $mimetype Mimetype of file to upload
|
||||
* @return mixed ID of database record or false
|
||||
*/
|
||||
public function uploadSeminaryFile($userId, $seminaryId, $name, $filename, $tmpFilename, $mimetype)
|
||||
{
|
||||
$uploadId = false;
|
||||
$this->db->setAutocommit(false);
|
||||
|
||||
try {
|
||||
// Create database record
|
||||
$this->db->query(
|
||||
'INSERT INTO seminaryuploads '.
|
||||
'(created_user_id, seminary_id, name, url, mimetype) '.
|
||||
'VALUES '.
|
||||
'(?, ? ,? ,?, ?)',
|
||||
'iisss',
|
||||
$userId,
|
||||
$seminaryId,
|
||||
$name,
|
||||
\nre\core\Linker::createLinkParam($filename),
|
||||
$mimetype
|
||||
);
|
||||
$uploadId = $this->db->getInsertId();
|
||||
|
||||
// Create filename
|
||||
$filename = ROOT.DS.\nre\configs\AppConfig::$dirs['seminaryuploads'].DS.$filename;
|
||||
if(!move_uploaded_file($tmpFilename, $filename))
|
||||
{
|
||||
$this->db->rollback();
|
||||
$uploadId = false;
|
||||
}
|
||||
}
|
||||
catch(\nre\exceptions\DatamodelException $e) {
|
||||
$this->db->rollback();
|
||||
$this->db->setAutocommit(true);
|
||||
}
|
||||
|
||||
|
||||
$this->db->setAutocommit(true);
|
||||
return $uploadId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get an upload by its ID.
|
||||
*
|
||||
* @throws \nre\exceptions\IdNotFoundException
|
||||
* @param int $uploadId ID of the uploaded file
|
||||
* @return array Upload data
|
||||
*/
|
||||
public function getSeminaryuploadById($seminaryuploadId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, created, created_user_id, seminary_id, name, url, mimetype, public '.
|
||||
'FROM seminaryuploads '.
|
||||
'WHERE id = ?',
|
||||
'i',
|
||||
$seminaryuploadId
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($seminaryuploadId);
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get an upload by its URL.
|
||||
*
|
||||
* @throws \nre\exceptions\IdNotFoundException
|
||||
* @param int $seminaryId ID of Seminary
|
||||
* @param int $uploadId ID of the uploaded file
|
||||
* @return array Upload data
|
||||
*/
|
||||
public function getSeminaryuploadByUrl($seminaryId, $seminaryuploadUrl)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, created, created_user_id, seminary_id, name, url, mimetype, public '.
|
||||
'FROM seminaryuploads '.
|
||||
'WHERE seminary_id = ? AND url = ?',
|
||||
'is',
|
||||
$seminaryId,
|
||||
$seminaryuploadUrl
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($seminaryuploadUrl);
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
/**
|
||||
* 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 handle files to upload.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class UploadsModel extends \hhu\z\Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new UploadsModel.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Upload a file and create a database record.
|
||||
*
|
||||
* @param int $userId ID of user that uploads the file
|
||||
* @param int $seminaryId ID of Seminary
|
||||
* @param string $name Name of file to upload
|
||||
* @param string $filename Filename of file to upload
|
||||
* @param string $tmpFilename Name of temporary uploaded file
|
||||
* @param string $mimetype Mimetype of file to upload
|
||||
* @return mixed ID of database record or false
|
||||
*/
|
||||
public function uploadSeminaryFile($userId, $seminaryId, $name, $filename, $tmpFilename, $mimetype)
|
||||
{
|
||||
$uploadId = false;
|
||||
$this->db->setAutocommit(false);
|
||||
|
||||
try {
|
||||
// Create database record
|
||||
$this->db->query(
|
||||
'INSERT INTO seminaryuploads '.
|
||||
'(created_user_id, seminary_id, name, url, mimetype) '.
|
||||
'VALUES '.
|
||||
'(?, ? ,? ,?, ?)',
|
||||
'iisss',
|
||||
$userId,
|
||||
$seminaryId,
|
||||
$name,
|
||||
\nre\core\Linker::createLinkParam($filename),
|
||||
$mimetype
|
||||
);
|
||||
$uploadId = $this->db->getInsertId();
|
||||
|
||||
// Create filename
|
||||
$filename = ROOT.DS.\nre\configs\AppConfig::$dirs['seminaryuploads'].DS.$filename;
|
||||
if(!move_uploaded_file($tmpFilename, $filename))
|
||||
{
|
||||
$this->db->rollback();
|
||||
$uploadId = false;
|
||||
}
|
||||
}
|
||||
catch(\nre\exceptions\DatamodelException $e) {
|
||||
$this->db->rollback();
|
||||
$this->db->setAutocommit(true);
|
||||
}
|
||||
|
||||
|
||||
$this->db->setAutocommit(true);
|
||||
return $uploadId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get an upload by its ID.
|
||||
*
|
||||
* @throws \nre\exceptions\IdNotFoundException
|
||||
* @param int $uploadId ID of the uploaded file
|
||||
* @return array Upload data
|
||||
*/
|
||||
public function getSeminaryuploadById($seminaryuploadId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, created, created_user_id, seminary_id, name, url, mimetype, public '.
|
||||
'FROM seminaryuploads '.
|
||||
'WHERE id = ?',
|
||||
'i',
|
||||
$seminaryuploadId
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($seminaryuploadId);
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get an upload by its URL.
|
||||
*
|
||||
* @throws \nre\exceptions\IdNotFoundException
|
||||
* @param int $seminaryId ID of Seminary
|
||||
* @param int $uploadId ID of the uploaded file
|
||||
* @return array Upload data
|
||||
*/
|
||||
public function getSeminaryuploadByUrl($seminaryId, $seminaryuploadUrl)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, created, created_user_id, seminary_id, name, url, mimetype, public '.
|
||||
'FROM seminaryuploads '.
|
||||
'WHERE seminary_id = ? AND url = ?',
|
||||
'is',
|
||||
$seminaryId,
|
||||
$seminaryuploadUrl
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($seminaryuploadUrl);
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a Seminary upload.
|
||||
*
|
||||
*
|
||||
* @param int $uploadId ID of Seminary upload to delete
|
||||
*/
|
||||
public function deleteSeminaryupload($uploadId)
|
||||
{
|
||||
$this->db->setAutocommit(false);
|
||||
|
||||
try {
|
||||
$this->db->setAutocommit(false);
|
||||
|
||||
try {
|
||||
// Get Upload
|
||||
$upload = $this->getSeminaryuploadById($uploadId);
|
||||
|
||||
|
||||
// Delete database record
|
||||
$this->db->query(
|
||||
$this->db->query(
|
||||
'DELETE FROM seminaryuploads '.
|
||||
'WHERE id = ?',
|
||||
'i',
|
||||
|
|
@ -162,14 +162,14 @@
|
|||
$filename = ROOT.DS.\nre\configs\AppConfig::$dirs['seminaryuploads'].DS.$upload['url'];
|
||||
unlink($filename);
|
||||
}
|
||||
catch(\nre\exceptions\DatamodelException $e) {
|
||||
$this->db->rollback();
|
||||
$this->db->setAutocommit(true);
|
||||
}
|
||||
|
||||
$this->db->setAutocommit(true);
|
||||
catch(\nre\exceptions\DatamodelException $e) {
|
||||
$this->db->rollback();
|
||||
$this->db->setAutocommit(true);
|
||||
}
|
||||
|
||||
$this->db->setAutocommit(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,120 +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\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
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a role to a user.
|
||||
*
|
||||
* @param int $userId ID of user to add role to
|
||||
* @param string $userrole Role to add
|
||||
*/
|
||||
public function addUserroleToUser($userId, $userrole)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT IGNORE INTO users_userroles '.
|
||||
'(user_id, userrole_id) '.
|
||||
'SELECT ?, id '.
|
||||
'FROM userroles '.
|
||||
'WHERE name = ?',
|
||||
'is',
|
||||
$userId,
|
||||
$userrole
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove a role from a user.
|
||||
*
|
||||
* @param int $userId ID of user to remove role from
|
||||
* @param string $userrole Role to remove
|
||||
*/
|
||||
public function removeUserroleFromUser($userId, $userrole)
|
||||
{
|
||||
$this->db->query(
|
||||
'DELETE FROM users_userroles '.
|
||||
'WHERE user_id = ? AND userrole_id = ('.
|
||||
'SELECT id '.
|
||||
'FROM userroles '.
|
||||
'WHERE name = ?'.
|
||||
')',
|
||||
'is',
|
||||
$userId,
|
||||
$userrole
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* 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
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a role to a user.
|
||||
*
|
||||
* @param int $userId ID of user to add role to
|
||||
* @param string $userrole Role to add
|
||||
*/
|
||||
public function addUserroleToUser($userId, $userrole)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT IGNORE INTO users_userroles '.
|
||||
'(user_id, userrole_id) '.
|
||||
'SELECT ?, id '.
|
||||
'FROM userroles '.
|
||||
'WHERE name = ?',
|
||||
'is',
|
||||
$userId,
|
||||
$userrole
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove a role from a user.
|
||||
*
|
||||
* @param int $userId ID of user to remove role from
|
||||
* @param string $userrole Role to remove
|
||||
*/
|
||||
public function removeUserroleFromUser($userId, $userrole)
|
||||
{
|
||||
$this->db->query(
|
||||
'DELETE FROM users_userroles '.
|
||||
'WHERE user_id = ? AND userrole_id = ('.
|
||||
'SELECT id '.
|
||||
'FROM userroles '.
|
||||
'WHERE name = ?'.
|
||||
')',
|
||||
'is',
|
||||
$userId,
|
||||
$userrole
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,47 +1,47 @@
|
|||
<?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 count of registered users.
|
||||
*
|
||||
* @param string $username Only get users with the given username (optional)
|
||||
* @return int Count of users
|
||||
*/
|
||||
public function getUsersCount($username=null, $name=null, $email=null)
|
||||
{
|
||||
/**
|
||||
* 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 count of registered users.
|
||||
*
|
||||
* @param string $username Only get users with the given username (optional)
|
||||
* @return int Count of users
|
||||
*/
|
||||
public function getUsersCount($username=null, $name=null, $email=null)
|
||||
{
|
||||
// Create array of values
|
||||
$values = array();
|
||||
if(!is_null($username)) {
|
||||
|
|
@ -55,32 +55,32 @@
|
|||
}
|
||||
|
||||
// Execute query
|
||||
$data = $this->db->query(
|
||||
'SELECT count(DISTINCT id) AS c '.
|
||||
'FROM users '.
|
||||
$data = $this->db->query(
|
||||
'SELECT count(DISTINCT id) AS c '.
|
||||
'FROM users '.
|
||||
(!empty($values) ? sprintf('WHERE %s', implode(' AND ', $values)) : null)
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0]['c'];
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get registered users.
|
||||
*
|
||||
* @throws \nre\exceptions\ParamsNotValidException
|
||||
* @param string $sort Field to sort by
|
||||
* @param string $username Only get users with the given username (optional)
|
||||
* @param int $limit Limit amount of Characters (optional)
|
||||
* @param int $offset Offset (optional)
|
||||
* @return array Users
|
||||
*/
|
||||
public function getUsers($sort, $username=null, $name=null, $email=null, $limit=null, $offset=0)
|
||||
{
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0]['c'];
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get registered users.
|
||||
*
|
||||
* @throws \nre\exceptions\ParamsNotValidException
|
||||
* @param string $sort Field to sort by
|
||||
* @param string $username Only get users with the given username (optional)
|
||||
* @param int $limit Limit amount of Characters (optional)
|
||||
* @param int $offset Offset (optional)
|
||||
* @return array Users
|
||||
*/
|
||||
public function getUsers($sort, $username=null, $name=null, $email=null, $limit=null, $offset=0)
|
||||
{
|
||||
// Create array of values
|
||||
$values = array();
|
||||
if(!is_null($username)) {
|
||||
|
|
@ -94,337 +94,337 @@
|
|||
}
|
||||
|
||||
// Execute query
|
||||
switch($sort)
|
||||
{
|
||||
case 'username':
|
||||
case 'created':
|
||||
$orders = array(
|
||||
'username' => 'ASC',
|
||||
'created' => 'DESC'
|
||||
);
|
||||
|
||||
return $this->db->query(
|
||||
'SELECT id, created, username, url, surname, prename, email, mailing '.
|
||||
'FROM users '.
|
||||
switch($sort)
|
||||
{
|
||||
case 'username':
|
||||
case 'created':
|
||||
$orders = array(
|
||||
'username' => 'ASC',
|
||||
'created' => 'DESC'
|
||||
);
|
||||
|
||||
return $this->db->query(
|
||||
'SELECT id, created, username, url, surname, prename, email, mailing '.
|
||||
'FROM users '.
|
||||
(!empty($values) ? sprintf('WHERE %s ', implode(' AND ', $values)) : null).
|
||||
sprintf('ORDER BY %s %s ', $sort, $orders[$sort]).
|
||||
(!empty($limit) ? sprintf('LIMIT %d, %d', $offset, $limit) : null)
|
||||
);
|
||||
break;
|
||||
case 'role':
|
||||
return $this->db->query(
|
||||
'SELECT DISTINCT users.id, users.created, users.username, users.url, users.surname, users.prename, users.email, users.mailing '.
|
||||
'FROM users '.
|
||||
'LEFT JOIN users_userroles ON users_userroles.user_id = users.id '.
|
||||
'LEFT JOIN userroles ON userroles.id = users_userroles.user_id '.
|
||||
sprintf('ORDER BY %s %s ', $sort, $orders[$sort]).
|
||||
(!empty($limit) ? sprintf('LIMIT %d, %d', $offset, $limit) : null)
|
||||
);
|
||||
break;
|
||||
case 'role':
|
||||
return $this->db->query(
|
||||
'SELECT DISTINCT users.id, users.created, users.username, users.url, users.surname, users.prename, users.email, users.mailing '.
|
||||
'FROM users '.
|
||||
'LEFT JOIN users_userroles ON users_userroles.user_id = users.id '.
|
||||
'LEFT JOIN userroles ON userroles.id = users_userroles.user_id '.
|
||||
(!empty($values) ? sprintf('WHERE %s ', implode(' AND ', $values)) : null).
|
||||
'ORDER BY userroles.id IS NULL, userroles.id ASC '.
|
||||
(!empty($limit) ? sprintf('LIMIT %d, %d', $offset, $limit) : null)
|
||||
);
|
||||
break;
|
||||
default:
|
||||
throw new \nre\exceptions\ParamsNotValidException($sort);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get users with the given user role.
|
||||
*
|
||||
* @param string $userrole User role
|
||||
* @return array List of users
|
||||
*/
|
||||
public function getUsersWithRole($userrole)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT users.id, users.created, users.username, users.url, users.surname, users.prename, users.email, users.mailing '.
|
||||
'FROM users '.
|
||||
'LEFT JOIN users_userroles ON users_userroles.user_id = users.id '.
|
||||
'LEFT JOIN userroles ON userroles.id = users_userroles.userrole_id '.
|
||||
'WHERE userroles.name = ? '.
|
||||
'ORDER BY username ASC',
|
||||
's',
|
||||
$userrole
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a user and its data by its ID.
|
||||
*
|
||||
* @throws \nre\exceptions\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, mailing '.
|
||||
'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 \nre\exceptions\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, mailing '.
|
||||
'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 \nre\exceptions\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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if an username already exists.
|
||||
*
|
||||
* @param string $username Username to check
|
||||
* @param int $userId Do not check this ID (for editing)
|
||||
* @return boolean Whether username exists or not
|
||||
*/
|
||||
public function usernameExists($username, $userId=null)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id '.
|
||||
'FROM users '.
|
||||
'WHERE username = ? OR url = ?',
|
||||
'ss',
|
||||
$username,
|
||||
\nre\core\Linker::createLinkParam($username)
|
||||
);
|
||||
|
||||
|
||||
return (!empty($data) && (is_null($userId) || $userId != $data[0]['id']));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if an e‑mail address already exists.
|
||||
*
|
||||
* @param string $email E‑mail address to check
|
||||
* @param int $userId Do not check this ID (for editing)
|
||||
* @return boolean Whether e‑mail address exists or not
|
||||
*/
|
||||
public function emailExists($email, $userId=null)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id '.
|
||||
'FROM users '.
|
||||
'WHERE email = ?',
|
||||
's',
|
||||
$email
|
||||
);
|
||||
|
||||
|
||||
return (!empty($data) && (is_null($userId) || $userId != $data[0]['id']));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new user.
|
||||
*
|
||||
* @param string $username Username of the user to create
|
||||
* @param string $prename Prename of the user to create
|
||||
* @param string $surname Surname 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, $prename, $surname, $email, $password)
|
||||
{
|
||||
$userId = null;
|
||||
$this->db->setAutocommit(false);
|
||||
try {
|
||||
// Create user
|
||||
$this->db->query(
|
||||
'INSERT INTO users '.
|
||||
'(username, url, surname, prename, email, password) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?, ?, ?, ?)',
|
||||
'ssssss',
|
||||
$username,
|
||||
\nre\core\Linker::createLinkParam($username),
|
||||
$surname,
|
||||
$prename,
|
||||
$email,
|
||||
$this->hash($password)
|
||||
);
|
||||
$userId = $this->db->getInsertId();
|
||||
|
||||
// Add role “user”
|
||||
$this->db->query(
|
||||
'INSERT INTO users_userroles '.
|
||||
'(user_id, userrole_id) '.
|
||||
'SELECT ?, userroles.id '.
|
||||
'FROM userroles '.
|
||||
'WHERE userroles.name = ?',
|
||||
'is',
|
||||
$userId,
|
||||
'user'
|
||||
);
|
||||
}
|
||||
catch(Exception $e) {
|
||||
$this->db->rollback();
|
||||
$this->db->setAutocommit(true);
|
||||
throw $e;
|
||||
}
|
||||
$this->db->setAutocommit(true);
|
||||
|
||||
|
||||
return $userId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Edit a user.
|
||||
*
|
||||
* @throws \nre\exceptions\DatamodelException
|
||||
* @param int $userId ID of the user to delete
|
||||
* @param string $username New name of user
|
||||
* @param string $prename Prename of the user to create
|
||||
* @param string $surname Surname of the user to create
|
||||
* @param string $email Changed e‑mail-address of user
|
||||
* @param string $password Changed plaintext password of user
|
||||
* @param bool $mailing Whether to activate mailing or not
|
||||
*/
|
||||
public function editUser($userId, $username, $prename, $surname, $email, $password, $mailing)
|
||||
{
|
||||
$this->db->setAutocommit(false);
|
||||
try {
|
||||
// Update user data
|
||||
$this->db->query(
|
||||
'UPDATE users '.
|
||||
'SET username = ?, url = ?, prename = ?, surname = ?, email = ?, mailing = ? '.
|
||||
'WHERE id = ?',
|
||||
'sssssii',
|
||||
$username,
|
||||
\nre\core\Linker::createLinkParam($username),
|
||||
$prename,
|
||||
$surname,
|
||||
$email,
|
||||
$mailing,
|
||||
$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);
|
||||
}
|
||||
|
||||
}
|
||||
'ORDER BY userroles.id IS NULL, userroles.id ASC '.
|
||||
(!empty($limit) ? sprintf('LIMIT %d, %d', $offset, $limit) : null)
|
||||
);
|
||||
break;
|
||||
default:
|
||||
throw new \nre\exceptions\ParamsNotValidException($sort);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get users with the given user role.
|
||||
*
|
||||
* @param string $userrole User role
|
||||
* @return array List of users
|
||||
*/
|
||||
public function getUsersWithRole($userrole)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT users.id, users.created, users.username, users.url, users.surname, users.prename, users.email, users.mailing '.
|
||||
'FROM users '.
|
||||
'LEFT JOIN users_userroles ON users_userroles.user_id = users.id '.
|
||||
'LEFT JOIN userroles ON userroles.id = users_userroles.userrole_id '.
|
||||
'WHERE userroles.name = ? '.
|
||||
'ORDER BY username ASC',
|
||||
's',
|
||||
$userrole
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a user and its data by its ID.
|
||||
*
|
||||
* @throws \nre\exceptions\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, mailing '.
|
||||
'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 \nre\exceptions\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, mailing '.
|
||||
'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 \nre\exceptions\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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if an username already exists.
|
||||
*
|
||||
* @param string $username Username to check
|
||||
* @param int $userId Do not check this ID (for editing)
|
||||
* @return boolean Whether username exists or not
|
||||
*/
|
||||
public function usernameExists($username, $userId=null)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id '.
|
||||
'FROM users '.
|
||||
'WHERE username = ? OR url = ?',
|
||||
'ss',
|
||||
$username,
|
||||
\nre\core\Linker::createLinkParam($username)
|
||||
);
|
||||
|
||||
|
||||
return (!empty($data) && (is_null($userId) || $userId != $data[0]['id']));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if an e‑mail address already exists.
|
||||
*
|
||||
* @param string $email E‑mail address to check
|
||||
* @param int $userId Do not check this ID (for editing)
|
||||
* @return boolean Whether e‑mail address exists or not
|
||||
*/
|
||||
public function emailExists($email, $userId=null)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id '.
|
||||
'FROM users '.
|
||||
'WHERE email = ?',
|
||||
's',
|
||||
$email
|
||||
);
|
||||
|
||||
|
||||
return (!empty($data) && (is_null($userId) || $userId != $data[0]['id']));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new user.
|
||||
*
|
||||
* @param string $username Username of the user to create
|
||||
* @param string $prename Prename of the user to create
|
||||
* @param string $surname Surname 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, $prename, $surname, $email, $password)
|
||||
{
|
||||
$userId = null;
|
||||
$this->db->setAutocommit(false);
|
||||
try {
|
||||
// Create user
|
||||
$this->db->query(
|
||||
'INSERT INTO users '.
|
||||
'(username, url, surname, prename, email, password) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?, ?, ?, ?)',
|
||||
'ssssss',
|
||||
$username,
|
||||
\nre\core\Linker::createLinkParam($username),
|
||||
$surname,
|
||||
$prename,
|
||||
$email,
|
||||
$this->hash($password)
|
||||
);
|
||||
$userId = $this->db->getInsertId();
|
||||
|
||||
// Add role “user”
|
||||
$this->db->query(
|
||||
'INSERT INTO users_userroles '.
|
||||
'(user_id, userrole_id) '.
|
||||
'SELECT ?, userroles.id '.
|
||||
'FROM userroles '.
|
||||
'WHERE userroles.name = ?',
|
||||
'is',
|
||||
$userId,
|
||||
'user'
|
||||
);
|
||||
}
|
||||
catch(Exception $e) {
|
||||
$this->db->rollback();
|
||||
$this->db->setAutocommit(true);
|
||||
throw $e;
|
||||
}
|
||||
$this->db->setAutocommit(true);
|
||||
|
||||
|
||||
return $userId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Edit a user.
|
||||
*
|
||||
* @throws \nre\exceptions\DatamodelException
|
||||
* @param int $userId ID of the user to delete
|
||||
* @param string $username New name of user
|
||||
* @param string $prename Prename of the user to create
|
||||
* @param string $surname Surname of the user to create
|
||||
* @param string $email Changed e‑mail-address of user
|
||||
* @param string $password Changed plaintext password of user
|
||||
* @param bool $mailing Whether to activate mailing or not
|
||||
*/
|
||||
public function editUser($userId, $username, $prename, $surname, $email, $password, $mailing)
|
||||
{
|
||||
$this->db->setAutocommit(false);
|
||||
try {
|
||||
// Update user data
|
||||
$this->db->query(
|
||||
'UPDATE users '.
|
||||
'SET username = ?, url = ?, prename = ?, surname = ?, email = ?, mailing = ? '.
|
||||
'WHERE id = ?',
|
||||
'sssssii',
|
||||
$username,
|
||||
\nre\core\Linker::createLinkParam($username),
|
||||
$prename,
|
||||
$surname,
|
||||
$email,
|
||||
$mailing,
|
||||
$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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,170 +1,170 @@
|
|||
<?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 for XP-levels.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class XplevelsModel extends \hhu\z\Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new XplevelsModel.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get XP-level by its ID.
|
||||
*
|
||||
* @throws \nre\exceptions\IdNotFoundException
|
||||
* @param int $xplevelId ID of XP-level
|
||||
* @return array XP-level data
|
||||
*/
|
||||
public function getXPLevelById($xplevelId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, seminary_id, xps, level, name '.
|
||||
'FROM xplevels '.
|
||||
'WHERE id = ?',
|
||||
'i',
|
||||
$xplevelId
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($xplevelId);
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
/**
|
||||
* 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;
|
||||
|
||||
|
||||
/**
|
||||
* Get all XP-levels for a Seminary.
|
||||
*
|
||||
* @throws \nre\exceptions\IdNotFoundException
|
||||
* @param int $seminaryId ID of Seminary
|
||||
* @return array List of XP-level
|
||||
*/
|
||||
public function getXPLevelsForSeminary($seminaryId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, seminary_id, xps, level, name '.
|
||||
'FROM xplevels '.
|
||||
'WHERE seminary_id = ? '.
|
||||
'ORDER BY level ASC',
|
||||
'i',
|
||||
$seminaryId
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Model for XP-levels.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class XplevelsModel extends \hhu\z\Model
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Create a new XP-level for a Seminary.
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $seminaryId ID of Seminary
|
||||
* @param int $xps XPs of new XP-level
|
||||
* @param string $name Name of new XP-level (optional)
|
||||
*/
|
||||
public function createXPLevel($userId, $seminaryId, $xps, $name=null)
|
||||
{
|
||||
// Get level
|
||||
$level = $this->db->query(
|
||||
'SELECT COALESCE(MAX(level),0)+1 AS level '.
|
||||
'FROM xplevels '.
|
||||
'WHERE seminary_id = ?',
|
||||
'i',
|
||||
$seminaryId
|
||||
);
|
||||
$level = $level[0]['level'];
|
||||
|
||||
$this->db->setAutocommit(false);
|
||||
try {
|
||||
// Create XP-level
|
||||
$this->db->query(
|
||||
'INSERT INTO xplevels '.
|
||||
'(created_user_id, seminary_id, xps, level, name) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?, ?, ?)',
|
||||
'iiiis',
|
||||
$userId,
|
||||
$seminaryId,
|
||||
$xps,
|
||||
$level,
|
||||
$name
|
||||
);
|
||||
$xplevelId = $this->db->getInsertId();
|
||||
|
||||
// Create avatars
|
||||
$this->db->query(
|
||||
'INSERT INTO avatars '.
|
||||
'(created_user_id, charactertype_id, xplevel_id) '.
|
||||
'SELECT ?, charactertypes.id, ? '.
|
||||
'FROM charactertypes '.
|
||||
'WHERE seminary_id = ?',
|
||||
'iii',
|
||||
$userId,
|
||||
$xplevelId,
|
||||
$seminaryId
|
||||
);
|
||||
|
||||
$this->db->commit();
|
||||
}
|
||||
catch(\Exception $e) {
|
||||
$this->db->rollback();
|
||||
$this->db->setAutocommit(true);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$this->db->setAutocommit(true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Edit a XP-level.
|
||||
*
|
||||
* @param int $xplevelId ID of XP-level to edit
|
||||
* @param int $xps New XPs of XP-level
|
||||
* @param string $name New name of XP-level (optional)
|
||||
*/
|
||||
public function editXPLevel($xplevelId, $xps, $name=null)
|
||||
{
|
||||
$this->db->query(
|
||||
'UPDATE xplevels '.
|
||||
'SET xps = ?, name = ? '.
|
||||
'WHERE id = ?',
|
||||
'isi',
|
||||
$xps,
|
||||
$name,
|
||||
$xplevelId
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Construct a new XplevelsModel.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get XP-level by its ID.
|
||||
*
|
||||
* @throws \nre\exceptions\IdNotFoundException
|
||||
* @param int $xplevelId ID of XP-level
|
||||
* @return array XP-level data
|
||||
*/
|
||||
public function getXPLevelById($xplevelId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, seminary_id, xps, level, name '.
|
||||
'FROM xplevels '.
|
||||
'WHERE id = ?',
|
||||
'i',
|
||||
$xplevelId
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($xplevelId);
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all XP-levels for a Seminary.
|
||||
*
|
||||
* @throws \nre\exceptions\IdNotFoundException
|
||||
* @param int $seminaryId ID of Seminary
|
||||
* @return array List of XP-level
|
||||
*/
|
||||
public function getXPLevelsForSeminary($seminaryId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, seminary_id, xps, level, name '.
|
||||
'FROM xplevels '.
|
||||
'WHERE seminary_id = ? '.
|
||||
'ORDER BY level ASC',
|
||||
'i',
|
||||
$seminaryId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new XP-level for a Seminary.
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $seminaryId ID of Seminary
|
||||
* @param int $xps XPs of new XP-level
|
||||
* @param string $name Name of new XP-level (optional)
|
||||
*/
|
||||
public function createXPLevel($userId, $seminaryId, $xps, $name=null)
|
||||
{
|
||||
// Get level
|
||||
$level = $this->db->query(
|
||||
'SELECT COALESCE(MAX(level),0)+1 AS level '.
|
||||
'FROM xplevels '.
|
||||
'WHERE seminary_id = ?',
|
||||
'i',
|
||||
$seminaryId
|
||||
);
|
||||
$level = $level[0]['level'];
|
||||
|
||||
$this->db->setAutocommit(false);
|
||||
try {
|
||||
// Create XP-level
|
||||
$this->db->query(
|
||||
'INSERT INTO xplevels '.
|
||||
'(created_user_id, seminary_id, xps, level, name) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?, ?, ?)',
|
||||
'iiiis',
|
||||
$userId,
|
||||
$seminaryId,
|
||||
$xps,
|
||||
$level,
|
||||
$name
|
||||
);
|
||||
$xplevelId = $this->db->getInsertId();
|
||||
|
||||
// Create avatars
|
||||
$this->db->query(
|
||||
'INSERT INTO avatars '.
|
||||
'(created_user_id, charactertype_id, xplevel_id) '.
|
||||
'SELECT ?, charactertypes.id, ? '.
|
||||
'FROM charactertypes '.
|
||||
'WHERE seminary_id = ?',
|
||||
'iii',
|
||||
$userId,
|
||||
$xplevelId,
|
||||
$seminaryId
|
||||
);
|
||||
|
||||
$this->db->commit();
|
||||
}
|
||||
catch(\Exception $e) {
|
||||
$this->db->rollback();
|
||||
$this->db->setAutocommit(true);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$this->db->setAutocommit(true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Edit a XP-level.
|
||||
*
|
||||
* @param int $xplevelId ID of XP-level to edit
|
||||
* @param int $xps New XPs of XP-level
|
||||
* @param string $name New name of XP-level (optional)
|
||||
*/
|
||||
public function editXPLevel($xplevelId, $xps, $name=null)
|
||||
{
|
||||
$this->db->query(
|
||||
'UPDATE xplevels '.
|
||||
'SET xps = ?, name = ? '.
|
||||
'WHERE id = ?',
|
||||
'isi',
|
||||
$xps,
|
||||
$name,
|
||||
$xplevelId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Copy all XP-levels of a Seminary.
|
||||
*
|
||||
*
|
||||
* @param int $userId ID of copying user
|
||||
* @param int $sourceSeminaryId ID of Seminary to copy from
|
||||
* @param int $targetSeminaryId ID of Seminary to copy to
|
||||
|
|
@ -198,39 +198,39 @@
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a XP-level.
|
||||
*
|
||||
* @param int $xplevel XP-level to delete
|
||||
*/
|
||||
public function deleteXPLevel($xplevel)
|
||||
{
|
||||
$this->db->setAutocommit(false);
|
||||
try {
|
||||
// Delete XP-level
|
||||
$this->db->query('DELETE FROM xplevels WHERE id = ?', 'i', $xplevel['id']);
|
||||
/**
|
||||
* Delete a XP-level.
|
||||
*
|
||||
* @param int $xplevel XP-level to delete
|
||||
*/
|
||||
public function deleteXPLevel($xplevel)
|
||||
{
|
||||
$this->db->setAutocommit(false);
|
||||
try {
|
||||
// Delete XP-level
|
||||
$this->db->query('DELETE FROM xplevels WHERE id = ?', 'i', $xplevel['id']);
|
||||
|
||||
// Adjust levels
|
||||
$this->db->query(
|
||||
'UPDATE xplevels '.
|
||||
'SET level = level - 1 '.
|
||||
'WHERE seminary_id = ? AND level > ?',
|
||||
'ii',
|
||||
$xplevel['seminary_id'],
|
||||
$xplevel['level']
|
||||
);
|
||||
// Adjust levels
|
||||
$this->db->query(
|
||||
'UPDATE xplevels '.
|
||||
'SET level = level - 1 '.
|
||||
'WHERE seminary_id = ? AND level > ?',
|
||||
'ii',
|
||||
$xplevel['seminary_id'],
|
||||
$xplevel['level']
|
||||
);
|
||||
|
||||
$this->db->commit();
|
||||
}
|
||||
catch(\Exception $e) {
|
||||
$this->db->rollback();
|
||||
$this->db->setAutocommit(true);
|
||||
throw $e;
|
||||
}
|
||||
$this->db->commit();
|
||||
}
|
||||
catch(\Exception $e) {
|
||||
$this->db->rollback();
|
||||
$this->db->setAutocommit(true);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$this->db->setAutocommit(true);
|
||||
}
|
||||
|
||||
}
|
||||
$this->db->setAutocommit(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue