implement copying a complete Seminary (implements issue #7)
This commit is contained in:
parent
a7a4652a0e
commit
b2d00bc624
31 changed files with 2151 additions and 157 deletions
|
|
@ -19,6 +19,12 @@
|
|||
*/
|
||||
class AchievementsModel extends \hhu\z\Model
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('media');
|
||||
|
||||
|
||||
|
||||
|
|
@ -249,8 +255,9 @@
|
|||
public function getAchievementsForSeminary($seminaryId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, created, created_user_id, achievementcondition_id, pos, title, url, description, progress, hidden, only_once, all_conditions, deadline, unachieved_achievementsmedia_id, achieved_achievementsmedia_id '.
|
||||
'SELECT achievements.id, achievementconditions.condition, seminary_id, pos, title, url, description, progress, hidden, only_once, all_conditions, deadline, unachieved_achievementsmedia_id, achieved_achievementsmedia_id '.
|
||||
'FROM achievements '.
|
||||
'LEFT JOIN achievementconditions ON achievementconditions.id = achievements.achievementcondition_id '.
|
||||
'WHERE seminary_id = ? '.
|
||||
'ORDER BY pos ASC',
|
||||
'i',
|
||||
|
|
@ -371,6 +378,28 @@
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copy all date conditions of an Achievement.
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $sourceAchievementId ID of Achievement to copy conditions from
|
||||
* @param int $targetAchievementId ID of Achievement to copy conditions to
|
||||
*/
|
||||
public function copyAchievementConditionsDate($userId, $sourceAchievementId, $targetAchievementId)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO achievementconditions_date '.
|
||||
'(created_user_id, achievement_id, `select`) '.
|
||||
'SELECT ?, ?, `select` '.
|
||||
'FROM achievementconditions_date '.
|
||||
'WHERE achievement_id = ?',
|
||||
'iii',
|
||||
$userId, $targetAchievementId,
|
||||
$sourceAchievementId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a date condition.
|
||||
*
|
||||
|
|
@ -519,6 +548,28 @@
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copy all Character conditions of an Achievement.
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $sourceAchievementId ID of Achievement to copy conditions from
|
||||
* @param int $targetAchievementId ID of Achievement to copy conditions to
|
||||
*/
|
||||
public function copyAchievementConditionsCharacter($userId, $sourceAchievementId, $targetAchievementId)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO achievementconditions_character '.
|
||||
'(created_user_id, achievement_id, field, value) '.
|
||||
'SELECT ?, ?, field, value '.
|
||||
'FROM achievementconditions_character '.
|
||||
'WHERE achievement_id = ?',
|
||||
'iii',
|
||||
$userId, $targetAchievementId,
|
||||
$sourceAchievementId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a Character condition.
|
||||
*
|
||||
|
|
@ -696,6 +747,52 @@
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copy all Quest conditions of an Achievement.
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $sourceAchievementId ID of Achievement to copy conditions from
|
||||
* @param int $targetAchievementId ID of Achievement to copy conditions to
|
||||
* @param array $questIds Mapping of Quest-IDs from source Seminary to target Seminary
|
||||
*/
|
||||
public function copyAchievementConditionsQuest($userId, $sourceAchievementId, $targetAchievementId, $questIds)
|
||||
{
|
||||
// Get conditions
|
||||
$conditions = $this->getAchievementConditionsQuest($sourceAchievementId);
|
||||
|
||||
// Copy each condition
|
||||
foreach($conditions as &$condition)
|
||||
{
|
||||
if(is_null($condition['quest_id']))
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO achievementconditions_quest '.
|
||||
'(created_user_id, achievement_id, field, count, value, status, groupby) '.
|
||||
'SELECT ?, ?, field, count, value, status, groupby '.
|
||||
'FROM achievementconditions_quest '.
|
||||
'WHERE id = ?',
|
||||
'iii',
|
||||
$userId, $targetAchievementId,
|
||||
$condition['id']
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO achievementconditions_quest '.
|
||||
'(created_user_id, achievement_id, field, count, value, quest_id, status, groupby) '.
|
||||
'SELECT ?, ?, field, count, value, ?, status, groupby '.
|
||||
'FROM achievementconditions_quest '.
|
||||
'WHERE id = ?',
|
||||
'iiii',
|
||||
$userId, $targetAchievementId, $questIds[$condition['quest_id']],
|
||||
$condition['id']
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a Quest condition.
|
||||
*
|
||||
|
|
@ -865,6 +962,52 @@
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copy all Achievement conditions of an Achievement.
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $sourceAchievementId ID of Achievement to copy conditions from
|
||||
* @param int $targetAchievementId ID of Achievement to copy conditions to
|
||||
* @param array $achievementIds Mapping of Achievement-IDs from source Seminary to target Seminary
|
||||
*/
|
||||
public function copyAchievementConditionsAchievement($userId, $sourceAchievementId, $targetAchievementId, $achievementIds)
|
||||
{
|
||||
// Get conditions
|
||||
$conditions = $this->getAchievementConditionsAchievement($sourceAchievementId);
|
||||
|
||||
// Copy each condition
|
||||
foreach($conditions as &$condition)
|
||||
{
|
||||
if(is_null($condition['meta_achievement_id']) || !array_key_exists($condition['meta_achievement_id'], $achievementIds))
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO achievementconditions_achievement '.
|
||||
'(created_user_id, achievement_id, field, count, value, groupby) '.
|
||||
'SELECT ?, ?, field, count, value, groupby '.
|
||||
'FROM achievementconditions_achievement '.
|
||||
'WHERE id = ?',
|
||||
'iii',
|
||||
$userId, $targetAchievementId,
|
||||
$condition['id']
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO achievementconditions_achievement '.
|
||||
'(created_user_id, achievement_id, field, count, value, meta_achievement_id, groupby) '.
|
||||
'SELECT ?, ?, field, count, value, ?, groupby '.
|
||||
'FROM achievementconditions_achievement '.
|
||||
'WHERE id = ?',
|
||||
'iiii',
|
||||
$userId, $targetAchievementId, $achievementIds[$condition['meta_achievement_id']],
|
||||
$condition['id']
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a Achievement condition.
|
||||
*
|
||||
|
|
@ -1134,6 +1277,97 @@
|
|||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copy all Achievements of a Seminary.
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $sourceSeminaryId Seminary to copy from
|
||||
* @param int $targetSeminaryId Seminary to copy to
|
||||
* @param array $seminaryMediaIds Mapping of Seminarymedia-IDs from source Seminary to target Seminary
|
||||
* @param array $questIds Mapping of Quest-IDs from source Seminary to target Seminary (optional)
|
||||
*/
|
||||
public function copyAchievementsOfSeminary($userId, $sourceSeminaryId, $targetSeminaryId, $seminaryMediaIds, $questIds=null)
|
||||
{
|
||||
$achievementIds = array();
|
||||
|
||||
// Get Achievements
|
||||
$achievements = $this->getAchievementsForSeminary($sourceSeminaryId);
|
||||
|
||||
// Copy each Achievements
|
||||
foreach($achievements as &$achievement)
|
||||
{
|
||||
// Check Quest-IDs
|
||||
if($achievement['condition'] == 'quest' && is_null($questIds)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Copy Achievement
|
||||
$this->db->query(
|
||||
'INSERT INTO achievements '.
|
||||
'(created_user_id, seminary_id, achievementcondition_id, pos, title, url, description, progress, hidden, only_once, all_conditions, deadline) '.
|
||||
'SELECT ?, ?, achievementcondition_id, pos, title, url, description, progress, hidden, only_once, all_conditions, deadline '.
|
||||
'FROM achievements '.
|
||||
'WHERE id = ?',
|
||||
'iii',
|
||||
$userId, $targetSeminaryId,
|
||||
$achievement['id']
|
||||
);
|
||||
$achievementIds[$achievement['id']] = $this->db->getInsertId();
|
||||
|
||||
// Copy media
|
||||
if(!is_null($achievement['unachieved_achievementsmedia_id']))
|
||||
{
|
||||
$this->Media->copyAchievementMedia($userId, $seminaryMediaIds[$achievement['unachieved_achievementsmedia_id']]);
|
||||
$this->db->query(
|
||||
'UPDATE achievements '.
|
||||
'SET unachieved_achievementsmedia_id = ? '.
|
||||
'WHERE id = ?',
|
||||
'ii',
|
||||
$seminaryMediaIds[$achievement['unachieved_achievementsmedia_id']],
|
||||
$achievementIds[$achievement['id']]
|
||||
);
|
||||
}
|
||||
if(!is_null($achievement['achieved_achievementsmedia_id']))
|
||||
{
|
||||
$this->Media->copyAchievementMedia($userId, $seminaryMediaIds[$achievement['achieved_achievementsmedia_id']]);
|
||||
$this->db->query(
|
||||
'UPDATE achievements '.
|
||||
'SET achieved_achievementsmedia_id = ? '.
|
||||
'WHERE id = ?',
|
||||
'ii',
|
||||
$seminaryMediaIds[$achievement['achieved_achievementsmedia_id']],
|
||||
$achievementIds[$achievement['id']]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Copy Achievement conditions
|
||||
// Do this after copying the Achievements itself to ensure Meta-
|
||||
// Achievements work correctly
|
||||
foreach($achievements as &$achievement)
|
||||
{
|
||||
// Copy conditions
|
||||
switch($achievement['condition'])
|
||||
{
|
||||
case 'date':
|
||||
$this->copyAchievementConditionsDate($userId, $achievement['id'], $achievementIds[$achievement['id']]);
|
||||
break;
|
||||
case 'quest':
|
||||
if(!is_null($questIds)) {
|
||||
$this->copyAchievementConditionsQuest($userId, $achievement['id'], $achievementIds[$achievement['id']], $questIds);
|
||||
}
|
||||
break;
|
||||
case 'character':
|
||||
$this->copyAchievementConditionsCharacter($userId, $achievement['id'], $achievementIds[$achievement['id']]);
|
||||
break;
|
||||
case 'achievement':
|
||||
$this->copyAchievementConditionsAchievement($userId, $achievement['id'], $achievementIds[$achievement['id']], $achievementIds);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete an Achievement.
|
||||
|
|
|
|||
|
|
@ -19,6 +19,12 @@
|
|||
*/
|
||||
class AvatarsModel extends \hhu\z\Model
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('media');
|
||||
|
||||
|
||||
|
||||
|
|
@ -88,6 +94,32 @@
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
|
@ -140,6 +172,51 @@
|
|||
$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
|
||||
* @param array $seminaryMediaIds Mapping of Seminarymedia-IDs from source Seminary to target Seminary
|
||||
*/
|
||||
public function copyAvatars($userId, $charactertypeIds, $xplevelIds, $seminaryMediaIds)
|
||||
{
|
||||
// Copy Avatars
|
||||
foreach($charactertypeIds as $sourceCharactertypeId => $targetCharactertypeId)
|
||||
{
|
||||
foreach($xplevelIds as $sourceXplevelId => $targetXplevelId)
|
||||
{
|
||||
try {
|
||||
// Get Avatar
|
||||
$avatar = $this->getAvatarByTypeAndLevelId($sourceCharactertypeId, $sourceXplevelId);
|
||||
|
||||
// Copy media
|
||||
$this->Media->copyAvatarpicture($userId, $seminaryMediaIds[$avatar['avatarpicture_id']]);
|
||||
$this->Media->copyAvatarpicture($userId, $seminaryMediaIds[$avatar['small_avatarpicture_id']]);
|
||||
|
||||
// Copy Avatar
|
||||
$this->db->query(
|
||||
'INSERT INTO avatars '.
|
||||
'(created_user_id, charactertype_id, xplevel_id, avatarpicture_id, small_avatarpicture_id) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?, ?, ?)',
|
||||
'iiiii',
|
||||
$userId,
|
||||
$targetCharactertypeId,
|
||||
$targetXplevelId,
|
||||
$seminaryMediaIds[$avatar['avatarpicture_id']],
|
||||
$seminaryMediaIds[$avatar['small_avatarpicture_id']]
|
||||
);
|
||||
}
|
||||
catch(\nre\exceptions\IdNotFoundException $e) {
|
||||
// Not all combinations of charactertypes and XP-levels exist
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -176,6 +176,42 @@
|
|||
$groupsgroupId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copy all Character groups-groups 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
|
||||
* @param array Mapping of Character groups-groups-IDs from source Seminary to target Seminary
|
||||
*/
|
||||
public function copyGroupsgroupsOfSeminary($userId, $sourceSeminaryId, $targetSeminaryId)
|
||||
{
|
||||
$groupsgroupIds = array();
|
||||
|
||||
// Get Character groups
|
||||
$groupsgroups = $this->getGroupsroupsForSeminary($sourceSeminaryId);
|
||||
|
||||
// Copy each Groups-group
|
||||
foreach($groupsgroups as &$group)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO charactergroupsgroups '.
|
||||
'(created_user_id, seminary_id, name, url, preferred) '.
|
||||
'SELECT ?, ?, name, url, preferred '.
|
||||
'FROM charactergroupsgroups '.
|
||||
'WHERE id = ?',
|
||||
'iii',
|
||||
$userId, $targetSeminaryId,
|
||||
$group['id']
|
||||
);
|
||||
$groupsgroupIds[$group['id']] = $this->db->getInsertId();
|
||||
}
|
||||
|
||||
|
||||
return $groupsgroupIds;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('uploads');
|
||||
public $models = array('uploads', 'media');
|
||||
|
||||
|
||||
|
||||
|
|
@ -50,7 +50,7 @@
|
|||
public function getQuestsForCharactergroupsgroup($groupsgroupId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, questgroups_id, title, url, xps '.
|
||||
'SELECT id, questgroups_id, title, url, xps, questsmedia_id '.
|
||||
'FROM charactergroupsquests '.
|
||||
'WHERE charactergroupsgroup_id = ? '.
|
||||
'ORDER BY created ASC',
|
||||
|
|
@ -375,6 +375,55 @@
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @param array $seminaryMediaIds Mapping of Seminarymedia-IDs from source Seminary to target Seminary (optional)
|
||||
*/
|
||||
public function copyQuestsOfSeminary($userId, $groupsgroupIds, $questgroupIds, $seminaryMediaIds=null)
|
||||
{
|
||||
foreach($groupsgroupIds as $sourceGroupsgroupId => $targetGroupsgroupId)
|
||||
{
|
||||
// Get Quests
|
||||
$quests = $this->getQuestsForCharactergroupsgroup($sourceGroupsgroupId);
|
||||
|
||||
// Copy each Quest
|
||||
foreach($quests as &$quest)
|
||||
{
|
||||
// Copy Quest
|
||||
$this->db->query(
|
||||
'INSERT INTO charactergroupsquests '.
|
||||
'(created_user_id, charactergroupsgroup_id, questgroups_id, title, url, description, xps, rules, won_text, lost_text) '.
|
||||
'SELECT ?, ?, ?, title, url, description, xps, rules, won_text, lost_text '.
|
||||
'FROM charactergroupsquests '.
|
||||
'WHERE id = ?',
|
||||
'iiii',
|
||||
$userId, $targetGroupsgroupId, $questgroupIds[$quest['questgroups_id']],
|
||||
$quest['id']
|
||||
);
|
||||
$targetQuestId = $this->db->getInsertId();
|
||||
|
||||
// Copy media
|
||||
if(!is_null($seminaryMediaIds) && !is_null($quest['questsmedia_id']))
|
||||
{
|
||||
$this->Media->copyQuestsmedia($userId, $seminaryMediaIds[$quest['questsmedia_id']]);
|
||||
$this->db->query(
|
||||
'UPDATE charactergroupsquests '.
|
||||
'SET questsmedia_id = ? '.
|
||||
'WHERE id = ?',
|
||||
'ii',
|
||||
$seminaryMediaIds[$quest['questsmedia_id']],
|
||||
$targetQuestId
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a Character groups Quest.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -201,6 +201,42 @@
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @param array Mapping of Charactertype-IDs from source Seminary to targetSeminary
|
||||
*/
|
||||
public function copyCharactertypesOfSeminary($userId, $sourceSeminaryId, $targetSeminaryId)
|
||||
{
|
||||
$charactertypeIds = array();
|
||||
|
||||
// Get Charactertypes
|
||||
$charactertypes = $this->getCharacterTypesForSeminary($sourceSeminaryId);
|
||||
|
||||
// Copy each Charactertype
|
||||
foreach($charactertypes as &$type)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO charactertypes '.
|
||||
'(created_user_id, seminary_id, name, url) '.
|
||||
'SELECT ?, ?, name, url '.
|
||||
'FROM charactertypes '.
|
||||
'WHERE id = ?',
|
||||
'iii',
|
||||
$userId, $targetSeminaryId,
|
||||
$type['id']
|
||||
);
|
||||
$charactertypeIds[$type['id']] = $this->db->getInsertId();
|
||||
}
|
||||
|
||||
|
||||
return $charactertypeIds;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a Charactertype.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -133,6 +133,68 @@
|
|||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copy all media from 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
|
||||
* @return array Mapping of Media-IDs from source Seminary to target Seminary
|
||||
*/
|
||||
public function copySeminaryMedia($userId, $sourceSeminaryId, $targetSeminaryId)
|
||||
{
|
||||
$seminaryMediaIds = array();
|
||||
$copiedFiles = array();
|
||||
|
||||
// Get all media from a Seminary
|
||||
$seminaryMedia = $this->db->query(
|
||||
'SELECT id '.
|
||||
'FROM seminarymedia '.
|
||||
'WHERE seminary_id = ?',
|
||||
'i',
|
||||
$sourceSeminaryId
|
||||
);
|
||||
|
||||
// Copy each medium
|
||||
try {
|
||||
foreach($seminaryMedia as &$medium)
|
||||
{
|
||||
// Copy database record
|
||||
$this->db->query(
|
||||
'INSERT INTO seminarymedia '.
|
||||
'(created_user_id, seminary_id, name, url, description, mimetype) '.
|
||||
'SELECT ?, ?, name, url, description, mimetype '.
|
||||
'FROM seminarymedia '.
|
||||
'WHERE id = ?',
|
||||
'iii',
|
||||
$userId, $targetSeminaryId,
|
||||
$medium['id']
|
||||
);
|
||||
$seminaryMediaIds[$medium['id']] = $this->db->getInsertId();
|
||||
|
||||
// Copy file
|
||||
$sourceFilename = ROOT.DS.\nre\configs\AppConfig::$dirs['seminarymedia'].DS.$medium['id'];
|
||||
$targetFilename = ROOT.DS.\nre\configs\AppConfig::$dirs['seminarymedia'].DS.$seminaryMediaIds[$medium['id']];
|
||||
if(!copy($sourceFilename, $targetFilename)) {
|
||||
throw new \hhu\z\exceptions\FileCopyException(error_get_last());
|
||||
}
|
||||
$copiedFiles[] = $targetFilename;
|
||||
}
|
||||
}
|
||||
catch(\hhu\z\exceptions\FileCopyException $e) {
|
||||
// Cleanup
|
||||
foreach($copiedFiles as $filename) {
|
||||
unlink($filename);
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
|
||||
|
||||
// Return new media IDs
|
||||
return $seminaryMediaIds;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -227,6 +289,29 @@
|
|||
return $mediaId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copy an Avatar picture.
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $seminaryMediaId ID of Seminary media to copy
|
||||
*/
|
||||
public function copyAvatarpicture($userId, $avatarpictureId)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO avatarpictures '.
|
||||
'(seminarymedia_id, created_user_id) '.
|
||||
'VALUES '.
|
||||
'(?, ?) '.
|
||||
'ON DUPLICATE KEY UPDATE '.
|
||||
'created_user_id = ?',
|
||||
'iii',
|
||||
$avatarpictureId,
|
||||
$userId,
|
||||
$userId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new Questgroup picture (Moodpic).
|
||||
|
|
@ -280,6 +365,29 @@
|
|||
$this->db->setAutocommit(true);
|
||||
return $mediaId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copy a Questgroup picture.
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $seminaryMediaId ID of Seminary media to copy
|
||||
*/
|
||||
public function copyQuestgroupspicture($userId, $questgroupspictureId)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO questgroupspictures '.
|
||||
'(media_id, created_user_id) '.
|
||||
'VALUES '.
|
||||
'(?, ?) '.
|
||||
'ON DUPLICATE KEY UPDATE '.
|
||||
'created_user_id = ?',
|
||||
'iii',
|
||||
$questgroupspictureId,
|
||||
$userId,
|
||||
$userId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -337,6 +445,30 @@
|
|||
$this->db->setAutocommit(true);
|
||||
return $mediaId;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Copy media of a Quest.
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $seminaryMediaId ID of Quest media to copy
|
||||
*/
|
||||
public function copyQuestsmedia($userId, $seminaryMediaId)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO questsmedia '.
|
||||
'(media_id, created_user_id) '.
|
||||
'VALUES '.
|
||||
'(?, ?) '.
|
||||
'ON DUPLICATE KEY UPDATE '.
|
||||
'created_user_id = ?',
|
||||
'iii',
|
||||
$seminaryMediaId,
|
||||
$userId,
|
||||
$userId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -445,6 +577,30 @@
|
|||
$this->db->setAutocommit(true);
|
||||
return $mediaId;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Copy Achievement media.
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $seminaryMediaId ID of Seminary media to copy
|
||||
*/
|
||||
public function copyAchievementMedia($userId, $seminaryMediaId)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO achievementsmedia '.
|
||||
'(seminarymedia_id, created_user_id) '.
|
||||
'VALUES '.
|
||||
'(?, ?) '.
|
||||
'ON DUPLICATE KEY UPDATE '.
|
||||
'created_user_id = ?',
|
||||
'iii',
|
||||
$seminaryMediaId,
|
||||
$userId,
|
||||
$userId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -465,8 +621,9 @@
|
|||
$data = $this->db->query(
|
||||
'SELECT id '.
|
||||
'FROM seminarymedia '.
|
||||
'WHERE url = ?',
|
||||
's',
|
||||
'WHERE seminary_id = ? AND url = ?',
|
||||
'is',
|
||||
$seminaryId,
|
||||
\nre\core\Linker::createLinkParam($filename)
|
||||
);
|
||||
if(!empty($data)) {
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('questgroupshierarchy', 'quests');
|
||||
public $models = array('questgroupshierarchy', 'questgrouptexts', 'quests', 'questtexts', 'media');
|
||||
|
||||
|
||||
|
||||
|
|
@ -98,7 +98,7 @@
|
|||
public function getQuestgroupsForSeminary($seminaryId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, title, url, achievable_xps '.
|
||||
'SELECT id, title, url, questgroupspicture_id, achievable_xps '.
|
||||
'FROM questgroups '.
|
||||
'WHERE seminary_id = ? '.
|
||||
'ORDER BY title ASC',
|
||||
|
|
@ -396,6 +396,7 @@
|
|||
}
|
||||
|
||||
// XPs of child Questgroups
|
||||
//var_dump($this->Questgroupshierarchy);
|
||||
$questgroupHierarchy = $this->Questgroupshierarchy->getHierarchyForQuestgroup($questgroupId);
|
||||
if(!empty($questgroupHierarchy))
|
||||
{
|
||||
|
|
@ -519,6 +520,79 @@
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copy Questgroupshierarchy of Questgroups from a Seminary.
|
||||
*
|
||||
* @param array $questgroupshierarchyIds Mapping of hierarchy-IDs from source Seminary to target Seminary
|
||||
* @param array $questgroupIds Mapping of Questgroup-IDs from source Seminary to target Seminary
|
||||
*/
|
||||
public function copyQuestgroupsHierarchy($questgroupshierarchyIds, $questgroupIds)
|
||||
{
|
||||
foreach($questgroupIds as $sourceQuestgroupId => $targetQuestgroupId)
|
||||
{
|
||||
$hierarchy = $this->Questgroupshierarchy->getHierarchyForQuestgroup($sourceQuestgroupId);
|
||||
if(!is_null($hierarchy))
|
||||
{
|
||||
if(is_null($hierarchy['parent_questgroup_id']))
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO questgroups_questgroupshierarchy '.
|
||||
'(questgroup_id, questgroupshierarchy_id, parent_questgroup_id, pos) '.
|
||||
'VALUES '.
|
||||
'(?, ?, null, ?)',
|
||||
'iii',
|
||||
$targetQuestgroupId,
|
||||
$questgroupshierarchyIds[$hierarchy['id']],
|
||||
$hierarchy['questgroup_pos']
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO questgroups_questgroupshierarchy '.
|
||||
'(questgroup_id, questgroupshierarchy_id, parent_questgroup_id, pos) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?, ?)',
|
||||
'iiii',
|
||||
$targetQuestgroupId,
|
||||
$questgroupshierarchyIds[$hierarchy['id']],
|
||||
$questgroupIds[$hierarchy['parent_questgroup_id']],
|
||||
$hierarchy['questgroup_pos']
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copy all related Questgroups of Questtexts of a Seminary.
|
||||
*
|
||||
* @param array $questgroupIds Mapping of Questgroup-IDs from source Seminary to target Seminary
|
||||
* @param array $questtextIds Mapping of Questtext-IDs from source Seminary to target Seminary
|
||||
*/
|
||||
public function copyRelatedQuestgroups($questgroupIds, $questtextIds)
|
||||
{
|
||||
foreach($questgroupIds as $sourceQuestgroupId => $targetQuestgroupId)
|
||||
{
|
||||
$questtexts = $this->Questtexts->getRelatedQuesttextsForQuestgroup($sourceQuestgroupId);
|
||||
foreach($questtexts as &$questtext)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO questgroups_questtexts '.
|
||||
'(questgroup_id, questtext_id, entry_text) '.
|
||||
'SELECT ?, ?, entry_text '.
|
||||
'FROM questgroups_questtexts '.
|
||||
'WHERE questgroup_id = ? AND questtext_id = ?',
|
||||
'iiii',
|
||||
$targetQuestgroupId, $questtextIds[$questtext['id']],
|
||||
$sourceQuestgroupId, $questtext['id']
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Move a Questgroup up (decrement position) or down (increment
|
||||
* position).
|
||||
|
|
@ -604,6 +678,61 @@
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copy Questgroups of Seminary.
|
||||
*
|
||||
* @throws \nre\exceptions\DatamodelException
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $sourceSeminaryId ID of Seminary to copy Questgroups from
|
||||
* @param int $targetSeminaryId ID of Seminary to copy Questgroups to
|
||||
* @param array $questgroupshierarchyIds Mapping of hierarchy-IDs from source Seminary to target Seminary
|
||||
* @param array $seminaryMediaIds Mapping of Seminary-media-IDs from source Seminary to target Seminary (optional)
|
||||
* @return array Mapping of Questgroup-IDs from source Seminary to target Seminary
|
||||
*/
|
||||
public function copyQuestgroupsOfSeminary($userId, $sourceSeminaryId, $targetSeminaryId, $questgroupshierarchyIds, $seminaryMediaIds=null)
|
||||
{
|
||||
// Get Questgroups of source Seminary
|
||||
$questgroupIds = array();
|
||||
$questgroups = $this->getQuestgroupsForSeminary($sourceSeminaryId);
|
||||
foreach($questgroups as &$questgroup)
|
||||
{
|
||||
// Insert into target Seminary
|
||||
$this->db->query(
|
||||
'INSERT INTO questgroups '.
|
||||
'(created_user_id, seminary_id, title, url) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?, ?)',
|
||||
'iiss',
|
||||
$userId,
|
||||
$targetSeminaryId,
|
||||
$questgroup['title'],
|
||||
$questgroup['url']
|
||||
);
|
||||
$questgroupIds[$questgroup['id']] = $this->db->getInsertId();
|
||||
|
||||
// Copy media
|
||||
if(!is_null($seminaryMediaIds) && !is_null($questgroup['questgroupspicture_id']))
|
||||
{
|
||||
$this->Media->copyQuestgroupspicture($userId, $seminaryMediaIds[$questgroup['questgroupspicture_id']]);
|
||||
$this->db->query(
|
||||
'UPDATE questgroups '.
|
||||
'SET questgroupspicture_id = ? '.
|
||||
'WHERE id = ?',
|
||||
'ii',
|
||||
$seminaryMediaIds[$questgroup['questgroupspicture_id']],
|
||||
$questgroupIds[$questgroup['id']]
|
||||
);
|
||||
}
|
||||
|
||||
// Copy Questgroup texts
|
||||
$this->Questgrouptexts->copyQuestgrouptexts($userId, $questgroup['id'], $questgroupIds[$questgroup['id']]);
|
||||
}
|
||||
|
||||
|
||||
return $questgroupIds;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a Questgroup.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -302,7 +302,31 @@
|
|||
}
|
||||
$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);
|
||||
|
||||
// Copy hierarchy
|
||||
$hierarchyIds = array();
|
||||
foreach($questgroupshierarchy as $hierarchy) {
|
||||
$this->copyHierarchy($userId, $sourceSeminaryId, $targetSeminaryId, $hierarchy, $hierarchyIds);
|
||||
}
|
||||
|
||||
|
||||
return $hierarchyIds;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a Questgroupshierarchy.
|
||||
|
|
@ -313,6 +337,56 @@
|
|||
{
|
||||
$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
|
||||
* @param array $hierarchy Hierarchy to copy
|
||||
* @return array $hierarchyIds Mapping of hierarchy IDs from source Seminary to target Seminary
|
||||
*/
|
||||
private function copyHierarchy($userId, $sourceSeminaryId, $targetSeminaryId, $hierarchy, &$hierarchyIds)
|
||||
{
|
||||
// insert for new seminary
|
||||
if(is_null($hierarchy['parent_questgroupshierarchy_id']))
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO questgroupshierarchy '.
|
||||
'(created_user_id, seminary_id, parent_questgroupshierarchy_id, pos, title_singular, title_plural, url) '.
|
||||
'SELECT ?, ?, null, pos, title_singular, title_plural, url '.
|
||||
'FROM questgroupshierarchy '.
|
||||
'WHERE id = ?',
|
||||
'iii',
|
||||
$userId, $targetSeminaryId,
|
||||
$hierarchy['id']
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO questgroupshierarchy '.
|
||||
'(created_user_id, seminary_id, parent_questgroupshierarchy_id, pos, title_singular, title_plural, url) '.
|
||||
'SELECT ?, ?, ?, pos, title_singular, title_plural, url '.
|
||||
'FROM questgroupshierarchy '.
|
||||
'WHERE id = ?',
|
||||
'iiii',
|
||||
$userId, $targetSeminaryId, $hierarchyIds[$hierarchy['parent_questgroupshierarchy_id']],
|
||||
$hierarchy['id']
|
||||
);
|
||||
}
|
||||
$hierarchyIds[$hierarchy['id']] = $this->db->getInsertId();
|
||||
|
||||
// insert sub hierarchy
|
||||
$childHierarchy = $this->getChildQuestgroupshierarchy($hierarchy['id']);
|
||||
foreach($childHierarchy as $hierarchy) {
|
||||
$this->copyHierarchy($userId, $sourceSeminaryId, $targetSeminaryId, $hierarchy, $hierarchyIds);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,12 +19,6 @@
|
|||
*/
|
||||
class QuestgrouptextsModel extends \hhu\z\Model
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('questgroupshierarchy', 'questgroups', 'quests', 'questtexts');
|
||||
|
||||
|
||||
|
||||
|
|
@ -59,52 +53,6 @@
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the first text of a Questgroup.
|
||||
*
|
||||
* @param int $questgroupId ID of a Questgroup
|
||||
* @return string First text of this Questgroup or NULL
|
||||
*/
|
||||
public function getFirstQuestgroupText($questgroupId)
|
||||
{
|
||||
// Text of Questgroup itself
|
||||
$questgroupTexts = $this->getQuestgroupTexts($questgroupId);
|
||||
if(!empty($questgroupTexts)) {
|
||||
return $questgroupTexts[0]['text'];
|
||||
}
|
||||
|
||||
// Text of first Quest
|
||||
$quest = $this->Quests->getFirstQuestOfQuestgroup($questgroupId);
|
||||
if(!is_null($quest))
|
||||
{
|
||||
$questText = $this->Questtexts->getFirstQuestText($quest['id']);
|
||||
if(!is_null($questText)) {
|
||||
return $questText;
|
||||
}
|
||||
}
|
||||
|
||||
// Text of ChildQuestgroups
|
||||
$questgroupHierarchy = $this->Questgroupshierarchy->getHierarchyForQuestgroup($questgroupId);
|
||||
$childQuestgroupshierarchy = $this->Questgroupshierarchy->getChildQuestgroupshierarchy($questgroupHierarchy['id']);
|
||||
foreach($childQuestgroupshierarchy as &$hierarchy)
|
||||
{
|
||||
// Get Questgroups
|
||||
$questgroups = $this->Questgroups->getQuestgroupsForHierarchy($hierarchy['id'], $questgroupId);
|
||||
foreach($questgroups as &$group)
|
||||
{
|
||||
$childQuestgroupText = $this->getFirstQuestgroupText($group['id']);
|
||||
if(!is_null($childQuestgroupText)) {
|
||||
return $childQuestgroupText;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// No text found
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a Questgroup text to a Questgroup.
|
||||
*
|
||||
|
|
@ -155,6 +103,28 @@
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public function copyQuestgrouptexts($userId, $sourceQuestgroupId, $targetQuestgroupId)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO questgrouptexts '.
|
||||
'(created_user_id, questgroup_id, pos, text) '.
|
||||
'SELECT ?, ?, pos, text '.
|
||||
'FROM questgrouptexts '.
|
||||
'WHERE questgroup_id = ?',
|
||||
'iii',
|
||||
$userId, $targetQuestgroupId,
|
||||
$sourceQuestgroupId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a Questgroup text.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -43,6 +43,13 @@
|
|||
* @var int;
|
||||
*/
|
||||
const QUEST_STATUS_SOLVED = 3;
|
||||
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('questtypes', 'questtexts', 'media');
|
||||
|
||||
|
||||
|
||||
|
|
@ -481,7 +488,6 @@
|
|||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Mark a Quest for a Character.
|
||||
*
|
||||
|
|
@ -676,6 +682,83 @@
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copy all Quests from a Seminary.
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $seminaryId ID of Seminary to copy from
|
||||
* @param array $questgroupIds Mapping of Questgroup-IDs from source Seminary to target Seminary
|
||||
* @param array $seminaryMediaIds Mapping of Seminary-media-IDs from source Seminary to target Seminary (optional)
|
||||
* @return array Mapping of Quest-IDs from source Seminary to target Seminary
|
||||
*/
|
||||
public function copyQuests($userId, $sourceSeminaryId, $questgroupIds, $seminaryMediaIds=null)
|
||||
{
|
||||
$questIds = array();
|
||||
$questtextIds = array();
|
||||
|
||||
// Get Quests
|
||||
$quests = $this->getQuestsForSeminary($sourceSeminaryId);
|
||||
|
||||
// Copy each Quest
|
||||
foreach($quests as &$quest)
|
||||
{
|
||||
// Copy Quest
|
||||
$this->db->query(
|
||||
'INSERT INTO quests '.
|
||||
'(created_user_id, questgroup_id, questtype_id, title, url, xps, entry_text, wrong_text, task) '.
|
||||
'SELECT ?, ?, questtype_id, title, url, xps, entry_text, wrong_text, task '.
|
||||
'FROM quests '.
|
||||
'WHERE id = ?',
|
||||
'iii',
|
||||
$userId,
|
||||
$questgroupIds[$quest['questgroup_id']],
|
||||
$quest['id']
|
||||
);
|
||||
$questIds[$quest['id']] = $this->db->getInsertId();
|
||||
|
||||
// Copy media
|
||||
if(!is_null($seminaryMediaIds) && !is_null($quest['questsmedia_id']))
|
||||
{
|
||||
$this->Media->copyQuestsmedia($userId, $seminaryMediaIds[$quest['questsmedia_id']]);
|
||||
$this->db->query(
|
||||
'UPDATE quests '.
|
||||
'SET questsmedia_id = ? '.
|
||||
'WHERE id = ?',
|
||||
'ii',
|
||||
$seminaryMediaIds[$quest['questsmedia_id']],
|
||||
$questIds[$quest['id']]
|
||||
);
|
||||
}
|
||||
|
||||
// Copy texts
|
||||
$questtextIds = array_merge(
|
||||
$questtextIds,
|
||||
$this->Questtexts->copyQuesttexts($userId, $quest['id'], $questIds[$quest['id']], $seminaryMediaIds)
|
||||
);
|
||||
|
||||
// Copy content
|
||||
$questtype = $this->Questtypes->getQuesttypeById($quest['questtype_id']);
|
||||
if(!is_null($questtype['classname']))
|
||||
{
|
||||
// Load Questtype Model
|
||||
\hhu\z\models\QuesttypeModel::load($questtype['classname']);
|
||||
|
||||
// Construct Questtype Model
|
||||
$questtypeModel = \hhu\z\models\QuesttypeModel::factory($questtype['classname']);
|
||||
|
||||
// Copy content
|
||||
$questtypeModel->copyQuest($userId, $quest['id'], $questIds[$quest['id']], $seminaryMediaIds);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return array(
|
||||
'quests' => $questIds,
|
||||
'questtexts' => $questtextIds
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a Quest of a Seminary.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -19,6 +19,12 @@
|
|||
*/
|
||||
class QuesttextsModel extends \hhu\z\Model
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('media');
|
||||
|
||||
|
||||
|
||||
|
|
@ -304,6 +310,57 @@
|
|||
$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
|
||||
* @param array $seminaryMediaIds Mapping of Seminary-media-IDs from source Seminary to target Seminary (optional)
|
||||
*/
|
||||
public function copyQuesttexts($userId, $sourceQuestId, $targetQuestId, $seminaryMediaIds=null)
|
||||
{
|
||||
$questtextIds = array();
|
||||
|
||||
// Get Questtexts
|
||||
$questtexts = $this->getQuesttextsOfQuest($sourceQuestId);
|
||||
|
||||
// Copy each text
|
||||
foreach($questtexts as &$text)
|
||||
{
|
||||
// Copy text
|
||||
$this->db->query(
|
||||
'INSERT INTO questtexts '.
|
||||
'(created_user_id, quest_id, questtexttype_id, pos, text, out_text, abort_text) '.
|
||||
'SELECT ?, ?, questtexttype_id, pos, text, out_text, abort_text '.
|
||||
'FROM questtexts '.
|
||||
'WHERE id = ?',
|
||||
'iii',
|
||||
$userId, $targetQuestId,
|
||||
$text['id']
|
||||
);
|
||||
$questtextIds[$text['id']] = $this->db->getInsertId();
|
||||
|
||||
// Copy media
|
||||
if(!is_null($seminaryMediaIds) && !is_null($text['questsmedia_id']))
|
||||
{
|
||||
$this->Media->copyQuestsmedia($userId, $seminaryMediaIds[$text['questsmedia_id']]);
|
||||
$this->db->query(
|
||||
'UPDATE questtexts '.
|
||||
'SET questsmedia_id = ? '.
|
||||
'WHERE id = ?',
|
||||
'ii',
|
||||
$seminaryMediaIds[$text['questsmedia_id']],
|
||||
$questtextIds[$text['id']]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $questtextIds;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -100,6 +100,81 @@
|
|||
$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
|
||||
* @param array $questIds Mapping of Quest-IDs from source Seminary to target Seminary
|
||||
* @return array Mapping of Questsubtopic-IDs from source Seminary to targetSeminary
|
||||
*/
|
||||
public function copyQuesttopicsOfSeminary($userId, $sourceSeminaryId, $targetSeminaryId, $questIds)
|
||||
{
|
||||
$questsubtopicIds = array();
|
||||
|
||||
// Get Questtopics
|
||||
$questtopics = $this->getQuesttopicsForSeminary($sourceSeminaryId);
|
||||
foreach($questtopics as &$questtopic)
|
||||
{
|
||||
// Copy Questtopic
|
||||
$this->db->query(
|
||||
'INSERT INTO questtopics '.
|
||||
'(created_user_id, seminary_id, title, url) '.
|
||||
'SELECT ?, ?, title, url '.
|
||||
'FROM questtopics '.
|
||||
'WHERE id = ?',
|
||||
'iii',
|
||||
$userId, $targetSeminaryId,
|
||||
$questtopic['id']
|
||||
);
|
||||
$targetQuesttopicId = $this->db->getInsertId();
|
||||
|
||||
// Get Questsubtopics
|
||||
$questsubtopics = $this->getSubtopicsForQuesttopic($questtopic['id']);
|
||||
foreach($questsubtopics as &$questsubtopic)
|
||||
{
|
||||
// Copy Questsubtopic
|
||||
$this->db->query(
|
||||
'INSERT INTO questsubtopics '.
|
||||
'(created_user_id, questtopic_id, title, url) '.
|
||||
'SELECT ?, ?, title, url '.
|
||||
'FROM questsubtopics '.
|
||||
'WHERE id = ?',
|
||||
'iii',
|
||||
$userId, $targetQuesttopicId,
|
||||
$questsubtopic['id']
|
||||
);
|
||||
$questsubtopicIds[$questsubtopic['id']] = $this->db->getInsertId();
|
||||
|
||||
// Get Quest links
|
||||
$quests = $this->db->query(
|
||||
'SELECT quest_id '.
|
||||
'FROM quests_questsubtopics '.
|
||||
'WHERE questsubtopic_id = ?',
|
||||
'i',
|
||||
$questsubtopic['id']
|
||||
);
|
||||
foreach($quests as &$quest)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO quests_questsubtopics '.
|
||||
'(quest_id, questsubtopic_id) '.
|
||||
'VALUES '.
|
||||
'(?, ?)',
|
||||
'ii',
|
||||
$questIds[$quest['quest_id']],
|
||||
$questsubtopicIds[$questsubtopic['id']]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $questsubtopicIds;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('questgroupshierarchy', 'questgroups');
|
||||
public $models = array('questgroupshierarchy', 'questgroups', 'quests', 'questtopics', 'media', 'charactertypes', 'xplevels', 'avatars', 'achievements', 'charactergroups', 'charactergroupsquests', 'seminarycharacterfields');
|
||||
|
||||
|
||||
|
||||
|
|
@ -200,6 +200,28 @@
|
|||
$seminaryId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* (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']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -225,6 +247,122 @@
|
|||
$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
|
||||
* @param string $course Course of now Seminary
|
||||
* @param string $description Description of new Seminary
|
||||
* @param boolean $copySeminaryfields Whether to copy Seminary Character fields of not
|
||||
* @param boolean $copyMedia Whether to copy media or not
|
||||
* @param boolean $copyQuestgroupshierarchy Whether to copy Questgroupshierarchy or not
|
||||
* @param boolean $copyQuestgroups Whether to copy Questgroups or not
|
||||
* @param boolean $copyQuests Whether to copy Quests or not
|
||||
* @param boolean $copyQuesttopics Whether to copy Quest topics or not
|
||||
* @param boolean $copyCharactertypes Whether to copy Charactertypes or not
|
||||
* @param boolean $copyXPlevels Whether to copy XP-levels or not
|
||||
* @param boolean $copyAvatars Whether to copy Avatars or not
|
||||
* @param boolean $copyAchievements Whether to copy Achievements or not
|
||||
* @param boolean $copyCharactergroupsgroups Whether to copy Character groups-groups or not
|
||||
* @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)
|
||||
{
|
||||
$this->db->setAutocommit(false);
|
||||
try {
|
||||
// Create new Seminary
|
||||
$targetSeminaryId = $this->createSeminary($userId, $title, $course, $description);
|
||||
|
||||
// Copy Seminary fields
|
||||
if($copySeminaryfields) {
|
||||
$this->Seminarycharacterfields->copyFieldsOfSeminary($userId, $sourceSeminaryId, $targetSeminaryId);
|
||||
}
|
||||
|
||||
// Copy media
|
||||
$seminaryMediaIds = null;
|
||||
if($copyMedia) {
|
||||
$seminaryMediaIds = $this->Media->copySeminaryMedia($userId, $sourceSeminaryId, $targetSeminaryId);
|
||||
}
|
||||
|
||||
// Copy Quest content
|
||||
$questIds = null;
|
||||
$questgroupIds = null;
|
||||
// Questgroupshierarchy
|
||||
if($copyQuestgroupshierarchy)
|
||||
{
|
||||
$questgroupshierarchyIds = $this->Questgroupshierarchy->copyQuestgroupshierarchy($userId, $sourceSeminaryId, $targetSeminaryId);
|
||||
// Questgroups
|
||||
if($copyQuestgroups)
|
||||
{
|
||||
$questgroupIds = $this->Questgroups->copyQuestgroupsOfSeminary($userId, $sourceSeminaryId, $targetSeminaryId, $questgroupshierarchyIds, $seminaryMediaIds);
|
||||
$this->Questgroups->copyQuestgroupsHierarchy($questgroupshierarchyIds, $questgroupIds);
|
||||
// Quests
|
||||
if($copyQuests)
|
||||
{
|
||||
$questAndTextIds = $this->Quests->copyQuests($userId, $sourceSeminaryId, $questgroupIds, $seminaryMediaIds);
|
||||
$questIds = $questAndTextIds['quests'];
|
||||
$questtextIds = $questAndTextIds['questtexts'];
|
||||
$this->Questgroups->copyRelatedQuestgroups($questgroupIds, $questtextIds);
|
||||
// Questtopics
|
||||
if($copyQuesttopics) {
|
||||
$questsubtopicIds = $this->Questtopics->copyQuesttopicsOfSeminary($userId, $sourceSeminaryId, $targetSeminaryId, $questIds);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Copy Character content
|
||||
// Charactertypes
|
||||
if($copyCharactertypes)
|
||||
{
|
||||
$charactertypeIds = $this->Charactertypes->copyCharactertypesOfSeminary($userId, $sourceSeminaryId, $targetSeminaryId);
|
||||
// XP-levels
|
||||
if($copyXPlevels)
|
||||
{
|
||||
$xplevelIds = $this->Xplevels->copyXPLevelsOfSeminary($userId, $sourceSeminaryId, $targetSeminaryId);
|
||||
// Avatars
|
||||
if($copyAvatars && !is_null($seminaryMediaIds)) {
|
||||
$this->Avatars->copyAvatars($userId, $charactertypeIds, $xplevelIds, $seminaryMediaIds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Copy Achievements
|
||||
if($copyAchievements && !is_null($seminaryMediaIds)) {
|
||||
$this->Achievements->copyAchievementsOfSeminary($userId, $sourceSeminaryId, $targetSeminaryId, $seminaryMediaIds, $questIds);
|
||||
}
|
||||
|
||||
// Copy Charactergroups content
|
||||
// Charactergroupsgroups
|
||||
if($copyCharactergroupsgroups)
|
||||
{
|
||||
$characterGroupsgroupIds = $this->Charactergroups->copyGroupsgroupsOfSeminary($userId, $sourceSeminaryId, $targetSeminaryId);
|
||||
// Copy Charactergroupsquests
|
||||
if($copyCharactergroupsquests &!is_null($questgroupIds)) {
|
||||
$this->Charactergroupsquests->copyQuestsOfSeminary($userId, $characterGroupsgroupIds, $questgroupIds, $seminaryMediaIds);
|
||||
}
|
||||
}
|
||||
|
||||
// Recalculate XPs
|
||||
$this->calculateXPsForSeminary($targetSeminaryId);
|
||||
|
||||
$this->db->commit();
|
||||
}
|
||||
catch(\Exception $e) {
|
||||
$this->db->rollback();
|
||||
$this->db->setAutocommit(true);
|
||||
throw $e;
|
||||
}
|
||||
$this->db->setAutocommit(true);
|
||||
|
||||
|
||||
return $targetSeminaryId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -236,7 +374,7 @@
|
|||
{
|
||||
$this->db->query('DELETE FROM seminaries WHERE id = ?', 'i', $seminaryId);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -123,6 +123,28 @@
|
|||
$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
|
||||
*/
|
||||
public function copyFieldsOfSeminary($userId, $sourceSeminaryId, $targetSeminaryId)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO seminarycharacterfields '.
|
||||
'(created_user_id, seminary_id, pos, title, url, seminarycharacterfieldtype_id, regex, required) '.
|
||||
'SELECT ?, ?, pos, title, url, seminarycharacterfieldtype_id, regex, required '.
|
||||
'FROM seminarycharacterfields '.
|
||||
'WHERE seminary_id = ?',
|
||||
'iii',
|
||||
$userId, $targetSeminaryId,
|
||||
$sourceSeminaryId
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -161,6 +161,42 @@
|
|||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @param array Mapping of XP-level-IDs from source Seminary to targetSeminary
|
||||
*/
|
||||
public function copyXPLevelsOfSeminary($userId, $sourceSeminaryId, $targetSeminaryId)
|
||||
{
|
||||
$xplevelIds = array();
|
||||
|
||||
// Get XP-levels
|
||||
$xplevels = $this->getXPLevelsForSeminary($sourceSeminaryId);
|
||||
|
||||
// Copy each XP-level
|
||||
foreach($xplevels as &$level)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO xplevels '.
|
||||
'(created_user_id, seminary_id, xps, level, name) '.
|
||||
'SELECT ?, ?, xps, level, name '.
|
||||
'FROM xplevels '.
|
||||
'WHERE id = ?',
|
||||
'iii',
|
||||
$userId, $targetSeminaryId,
|
||||
$level['id']
|
||||
);
|
||||
$xplevelIds[$level['id']] = $this->db->getInsertId();
|
||||
}
|
||||
|
||||
|
||||
return $xplevelIds;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a XP-level.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue