add Character titles and let Characters choose gender and title
This commit is contained in:
parent
f70587db46
commit
320a583753
6 changed files with 354 additions and 36 deletions
|
@ -24,7 +24,7 @@
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('seminaries', 'characters', 'users', 'charactergroups', 'charactertypes', 'seminarycharacterfields', 'avatars', 'media', 'quests', 'questgroups', 'questtopics', 'xplevels');
|
||||
public $models = array('seminaries', 'characters', 'users', 'charactergroups', 'charactertypes', 'charactertitles', 'seminarycharacterfields', 'avatars', 'media', 'quests', 'questgroups', 'questtopics', 'xplevels');
|
||||
/**
|
||||
* Required components
|
||||
*
|
||||
|
@ -256,6 +256,7 @@
|
|||
|
||||
// Register Character
|
||||
$charactername = '';
|
||||
$gender = null;
|
||||
$validation = true;
|
||||
$fieldsValidation = true;
|
||||
if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('create')))
|
||||
|
@ -280,6 +281,11 @@
|
|||
$validation = $this->Validation->addValidationResult($validation, 'type', 'exist', false);
|
||||
}
|
||||
|
||||
// Validate gender
|
||||
if(is_null($gender) || !in_array(intval($gender), array(0, 1))) {
|
||||
$validation = $this->Validation->addValidationResult($validation, 'gender', 'correct', false);
|
||||
}
|
||||
|
||||
// Validate fields
|
||||
$fieldsValues = $this->request->getPostParam('fields');
|
||||
foreach($fields as &$field)
|
||||
|
@ -304,8 +310,15 @@
|
|||
// Register
|
||||
if($validation === true && $fieldsValidation === true)
|
||||
{
|
||||
$characterId = $this->Characters->createCharacter($this->Auth->getUserId(), $types[$typeIndex]['id'], $charactername);
|
||||
$character = $this->Characters->getCharacterById($characterId);
|
||||
$characterId = $this->Characters->createCharacter(
|
||||
$this->Auth->getUserId(),
|
||||
$types[$typeIndex]['id'],
|
||||
$charactername,
|
||||
$gender
|
||||
);
|
||||
$character = $this->Characters->getCharacterById(
|
||||
$characterId
|
||||
);
|
||||
|
||||
// Add Seminary fields
|
||||
foreach($fields as &$field) {
|
||||
|
@ -508,6 +521,11 @@
|
|||
$type['selected'] = ($type['url'] == $character['charactertype_url']);
|
||||
}
|
||||
|
||||
// Character titles
|
||||
$titles = $this->Charactertitles->getTitlesForCharacter(
|
||||
$character['id']
|
||||
);
|
||||
|
||||
// Character fields
|
||||
$fields = $this->Seminarycharacterfields->getFieldsForSeminary($seminary['id']);
|
||||
foreach($fields as &$field)
|
||||
|
@ -520,6 +538,15 @@
|
|||
|
||||
// Values
|
||||
$charactername = $character['name'];
|
||||
$gender = $character['gender'];
|
||||
$charactertitle = null;
|
||||
if(!is_null($character['charactertitle_id'])) {
|
||||
foreach($titles as &$title) {
|
||||
if($title['id'] == $character['charactertitle_id']) {
|
||||
$charactertitle = $title;
|
||||
}
|
||||
}
|
||||
}
|
||||
$validation = array();
|
||||
$fieldsValidation = true;
|
||||
|
||||
|
@ -532,6 +559,8 @@
|
|||
if($this->Characters->characterNameExists($charactername, $character['id'])) {
|
||||
$validation = $this->Validation->addValidationResult($validation, 'charactername', 'exist', true);
|
||||
}
|
||||
$gender = $this->request->getPostParam('gender');
|
||||
$charactertitleId = $this->request->getPostParam('title');
|
||||
|
||||
// Validate type
|
||||
$typeIndex = null;
|
||||
|
@ -546,6 +575,25 @@
|
|||
$validation = $this->Validation->addValidationResult($validation, 'type', 'exist', false);
|
||||
}
|
||||
|
||||
// Validate gender
|
||||
if(is_null($gender) || !in_array(intval($gender), array(0, 1))) {
|
||||
$validation = $this->Validation->addValidationResult($validation, 'gender', 'correct', false);
|
||||
}
|
||||
|
||||
// Validate title
|
||||
$charactertitle = null;
|
||||
if(!is_null($charactertitleId))
|
||||
{
|
||||
$charatcretitle = null;
|
||||
$charactertitleId = intval($charactertitleId);
|
||||
foreach($titles as &$title) {
|
||||
if($title['id'] === $charactertitleId) {
|
||||
$charactertitle = $title;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Validate fields
|
||||
$fieldsValues = $this->request->getPostParam('fields');
|
||||
foreach($fields as &$field)
|
||||
|
@ -573,7 +621,9 @@
|
|||
$this->Characters->editCharacter(
|
||||
$character['id'],
|
||||
$types[$typeIndex]['id'],
|
||||
$charactername
|
||||
$charactername,
|
||||
intval($gender),
|
||||
(!is_null($charactertitle)) ? $charactertitle['id'] : null
|
||||
);
|
||||
|
||||
// Set Seminary fields
|
||||
|
@ -604,8 +654,11 @@
|
|||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('types', $types);
|
||||
$this->set('titles', $titles);
|
||||
$this->set('fields', $fields);
|
||||
$this->set('charactername', $charactername);
|
||||
$this->set('gender', $gender);
|
||||
$this->set('charactertitle', $charactertitle);
|
||||
$this->set('validation', $validation);
|
||||
$this->set('fieldsValidation', $fieldsValidation);
|
||||
$this->set('validationSettings', $validationSettings);
|
||||
|
|
|
@ -734,12 +734,15 @@ CREATE TABLE `characters` (
|
|||
`charactertype_id` int(11) NOT NULL,
|
||||
`name` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`url` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`gender` bit(1) DEFAULT NULL,
|
||||
`charactertitle_id` int(11) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `name` (`name`),
|
||||
KEY `charactertype_id` (`charactertype_id`),
|
||||
KEY `user_id` (`user_id`),
|
||||
CONSTRAINT `characters_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `characters_ibfk_2` FOREIGN KEY (`charactertype_id`) REFERENCES `charactertypes` (`id`)
|
||||
CONSTRAINT `characters_ibfk_2` FOREIGN KEY (`charactertype_id`) REFERENCES `charactertypes` (`id`),
|
||||
CONSTRAINT `characters_ibfk_3` FOREIGN KEY (`charactertitle_id`) REFERENCES `charactertitles` (`id`) ON DELETE SET NULL ON UPDATE SET NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Charaktere';
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
|
||||
|
@ -856,6 +859,24 @@ CREATE TABLE `characters_characterroles` (
|
|||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Table structure for table `characters_charactertitles`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `characters_charactertitles`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE `characters_charactertitles` (
|
||||
`character_id` int(11) NOT NULL,
|
||||
`charactertitle_id` int(11) NOT NULL,
|
||||
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`character_id`,`charactertitle_id`),
|
||||
KEY `charactertitle_id` (`charactertitle_id`),
|
||||
CONSTRAINT `characters_charactertitles_ibfk_1` FOREIGN KEY (`character_id`) REFERENCES `characters` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `characters_charactertitles_ibfk_2` FOREIGN KEY (`charactertitle_id`) REFERENCES `charactertitles` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Table structure for table `characters_seminarycharacterfields`
|
||||
--
|
||||
|
@ -875,6 +896,30 @@ CREATE TABLE `characters_seminarycharacterfields` (
|
|||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Table structure for table `charactertitles`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `charactertitles`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE `charactertitles` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`created_user_id` int(11) NOT NULL,
|
||||
`seminary_id` int(11) NOT NULL,
|
||||
`hash` varchar(40) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`title_male` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`title_female` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `hash` (`hash`),
|
||||
KEY `created_user_id` (`created_user_id`),
|
||||
KEY `seminary_id` (`seminary_id`),
|
||||
CONSTRAINT `charactertitles_ibfk_1` FOREIGN KEY (`created_user_id`) REFERENCES `users` (`id`),
|
||||
CONSTRAINT `charactertitles_ibfk_2` FOREIGN KEY (`seminary_id`) REFERENCES `seminaries` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Table structure for table `charactertypes`
|
||||
--
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
{
|
||||
return $this->db->query(
|
||||
'SELECT '.
|
||||
'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps, cache_characters.quest_xps, cache_characters.avatar_id, '.
|
||||
'characters.id, characters.created, characters.user_id, characters.name, characters.url, character.gender, characters.charactertitle_id, cache_characters.xps, cache_characters.quest_xps, cache_characters.avatar_id, '.
|
||||
'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
|
||||
'xplevels.id AS xplevel_id, xplevels.level AS xplevel, '.
|
||||
'seminaries.id AS seminary_id, seminaries.url AS seminary_url, seminaries.title AS seminary_title, seminaries.url AS seminary_url '.
|
||||
|
@ -99,7 +99,7 @@
|
|||
{
|
||||
return $this->db->query(
|
||||
'SELECT '.
|
||||
'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps, cache_characters.quest_xps, cache_characters.avatar_id, '.
|
||||
'characters.id, characters.created, characters.user_id, characters.name, characters.url, characters.gender, characters.charactertitle_id, cache_characters.xps, cache_characters.quest_xps, cache_characters.avatar_id, '.
|
||||
'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
|
||||
'xplevels.id AS xplevel_id, xplevels.level AS xplevel, '.
|
||||
'seminaries.id AS seminary_id, seminaries.url AS seminary_url, seminaries.title AS seminary_title, seminaries.url AS seminary_url '.
|
||||
|
@ -141,7 +141,7 @@
|
|||
|
||||
return $this->db->query(
|
||||
'SELECT '.
|
||||
'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps, cache_characters.quest_xps, cache_characters.avatar_id, '.
|
||||
'characters.id, characters.created, characters.user_id, characters.name, characters.url, characters.gender, characters.charactertitle_id, cache_characters.xps, cache_characters.quest_xps, cache_characters.avatar_id, '.
|
||||
'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
|
||||
'xplevels.id AS xplevel_id, xplevels.level AS xplevel, '.
|
||||
'seminaries.id AS seminary_id, seminaries.url AS seminary_url, seminaries.title AS seminary_title, seminaries.url AS seminary_url '.
|
||||
|
@ -166,7 +166,7 @@
|
|||
case 'role':
|
||||
return $this->db->query(
|
||||
'SELECT DISTINCT '.
|
||||
'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps, cache_characters.quest_xps, cache_characters.avatar_id, '.
|
||||
'characters.id, characters.created, characters.user_id, characters.name, characters.url, characters.gender, characters.charactertitle_id, cache_characters.xps, cache_characters.quest_xps, cache_characters.avatar_id, '.
|
||||
'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
|
||||
'xplevels.id AS xplevel_id, xplevels.level AS xplevel, '.
|
||||
'seminaries.id AS seminary_id, seminaries.url AS seminary_url, seminaries.title AS seminary_title, seminaries.url AS seminary_url '.
|
||||
|
@ -188,7 +188,7 @@
|
|||
default:
|
||||
return $this->db->query(
|
||||
'SELECT DISTINCT '.
|
||||
'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps, cache_characters.quest_xps, cache_characters.avatar_id, '.
|
||||
'characters.id, characters.created, characters.user_id, characters.name, characters.url, characters.gender, characters.charactertitle_id, cache_characters.xps, cache_characters.quest_xps, cache_characters.avatar_id, '.
|
||||
'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
|
||||
'xplevels.id AS xplevel_id, xplevels.level AS xplevel, '.
|
||||
'seminaries.id AS seminary_id, seminaries.url AS seminary_url, seminaries.title AS seminary_title, seminaries.url AS seminary_url '.
|
||||
|
@ -222,7 +222,7 @@
|
|||
{
|
||||
return $this->db->query(
|
||||
'SELECT '.
|
||||
'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps, cache_characters.quest_xps, cache_characters.avatar_id, '.
|
||||
'characters.id, characters.created, characters.user_id, characters.name, characters.url, characters.gender, characters.charactertitle_id, cache_characters.xps, cache_characters.quest_xps, cache_characters.avatar_id, '.
|
||||
'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
|
||||
'xplevels.id AS xplevel_id, xplevels.level AS xplevel '.
|
||||
'FROM characters '.
|
||||
|
@ -250,7 +250,7 @@
|
|||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT '.
|
||||
'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps, cache_characters.quest_xps, cache_characters.avatar_id, '.
|
||||
'characters.id, characters.created, characters.user_id, characters.name, characters.url, characters.gender, characters.charactertitle_id, cache_characters.xps, cache_characters.quest_xps, cache_characters.avatar_id, '.
|
||||
'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
|
||||
'xplevels.id AS xplevel_id, xplevels.level AS xplevel '.
|
||||
'FROM characters '.
|
||||
|
@ -282,7 +282,7 @@
|
|||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT '.
|
||||
'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps, cache_characters.quest_xps, cache_characters.avatar_id, '.
|
||||
'characters.id, characters.created, characters.user_id, characters.name, characters.url, characters.gender, characters.charactertitle_id, cache_characters.xps, cache_characters.quest_xps, cache_characters.avatar_id, '.
|
||||
'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
|
||||
'xplevels.id AS xplevel_id, xplevels.level AS xplevel '.
|
||||
'FROM characters '.
|
||||
|
@ -313,7 +313,7 @@
|
|||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT '.
|
||||
'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps,cache_characters.quest_xps, cache_characters.avatar_id, '.
|
||||
'characters.id, characters.created, characters.user_id, characters.name, characters.url, characters.gender, characters.charactertitle_id, cache_characters.xps,cache_characters.quest_xps, cache_characters.avatar_id, '.
|
||||
'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
|
||||
'xplevels.id AS xplevel_id, xplevels.level AS xplevel '.
|
||||
'FROM characters '.
|
||||
|
@ -325,7 +325,7 @@
|
|||
$characterId
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($characterUrl);
|
||||
throw new \nre\exceptions\IdNotFoundException($characterId);
|
||||
}
|
||||
|
||||
|
||||
|
@ -342,7 +342,7 @@
|
|||
public function getCharactersWithRole($characterrole)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT characters.id, characters.created, characters.user_id, characters.name, characters.url '.
|
||||
'SELECT characters.id, characters.created, characters.user_id, characters.name, characters.url, characters.gender, characters.charactertitle_id '.
|
||||
'FROM characters '.
|
||||
'LEFT JOIN characters_characterroles ON characters_characterroles.character_id = characters.id '.
|
||||
'LEFT JOIN characterroles ON characterroles.id = characters_characterroles.characterrole_id '.
|
||||
|
@ -366,7 +366,7 @@
|
|||
{
|
||||
return $this->db->query(
|
||||
'SELECT '.
|
||||
'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps, cache_characters.quest_xps, cache_characters.avatar_id, '.
|
||||
'characters.id, characters.created, characters.user_id, characters.name, characters.url, characters.gender, characters.charactertitle_id, cache_characters.xps, cache_characters.quest_xps, cache_characters.avatar_id, '.
|
||||
'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
|
||||
'xplevels.id AS xplevel_id, xplevels.level AS xplevel, '.
|
||||
'count(DISTINCT achievement_id) AS c '.
|
||||
|
@ -433,7 +433,7 @@
|
|||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT '.
|
||||
'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps,cache_characters.quest_xps, cache_characters.avatar_id, '.
|
||||
'characters.id, characters.created, characters.user_id, characters.name, characters.url, characters.gender, characters.charactertitle_id, cache_characters.xps,cache_characters.quest_xps, cache_characters.avatar_id, '.
|
||||
'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
|
||||
'xplevels.id AS xplevel_id, xplevels.level AS xplevel '.
|
||||
'FROM characters '.
|
||||
|
@ -469,7 +469,7 @@
|
|||
{
|
||||
return $this->db->query(
|
||||
'SELECT '.
|
||||
'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps,cache_characters.quest_xps, cache_characters.avatar_id, '.
|
||||
'characters.id, characters.created, characters.user_id, characters.name, characters.url, characters.gender, characters.charactertitle_id, cache_characters.xps,cache_characters.quest_xps, cache_characters.avatar_id, '.
|
||||
'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
|
||||
'xplevels.id AS xplevel_id, xplevels.level AS xplevel '.
|
||||
'FROM characters '.
|
||||
|
@ -498,7 +498,7 @@
|
|||
{
|
||||
return $data = $this->db->query(
|
||||
'SELECT '.
|
||||
'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps,cache_characters.quest_xps, cache_characters.avatar_id, '.
|
||||
'characters.id, characters.created, characters.user_id, characters.name, characters.url, characters.gender, characters.charactertitle_id, cache_characters.xps,cache_characters.quest_xps, cache_characters.avatar_id, '.
|
||||
'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
|
||||
'xplevels.id AS xplevel_id, xplevels.level AS xplevel, '.
|
||||
'quests_characters.created AS submission_created '.
|
||||
|
@ -529,7 +529,7 @@
|
|||
{
|
||||
return $data = $this->db->query(
|
||||
'SELECT '.
|
||||
'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps,cache_characters.quest_xps, cache_characters.avatar_id, '.
|
||||
'characters.id, characters.created, characters.user_id, characters.name, characters.url, characters.gender, characters.charactertitle_id, cache_characters.xps,cache_characters.quest_xps, cache_characters.avatar_id, '.
|
||||
'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
|
||||
'xplevels.id AS xplevel_id, xplevels.level AS xplevel, '.
|
||||
'quests_characters.created AS submission_created '.
|
||||
|
@ -560,7 +560,7 @@
|
|||
{
|
||||
return $data = $this->db->query(
|
||||
'SELECT '.
|
||||
'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps,cache_characters.quest_xps, cache_characters.avatar_id, '.
|
||||
'characters.id, characters.created, characters.user_id, characters.name, characters.url, characters.gender, characters.charactertitle_id, cache_characters.xps,cache_characters.quest_xps, cache_characters.avatar_id, '.
|
||||
'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
|
||||
'xplevels.id AS xplevel_id, xplevels.level AS xplevel, '.
|
||||
'quests_characters.created AS submission_created '.
|
||||
|
@ -592,7 +592,7 @@
|
|||
{
|
||||
return $this->db->query(
|
||||
'SELECT '.
|
||||
'characters.id, characters.created, characters.user_id, characters.name, characters.url, cache_characters.xps, cache_characters.quest_xps, cache_characters.avatar_id, '.
|
||||
'characters.id, characters.created, characters.user_id, characters.name, characters.url, characters.gender, characters.charactertitle_id, cache_characters.xps, cache_characters.quest_xps, cache_characters.avatar_id, '.
|
||||
'charactertypes.id AS charactertype_id, charactertypes.name AS charactertype_name, charactertypes.url AS charactertype_url, '.
|
||||
'xplevels.id AS xplevel_id, xplevels.level AS xplevel, '.
|
||||
'seminaries.id AS seminary_id, seminaries.url AS seminary_url, seminaries.title AS seminary_title, seminaries.url AS seminary_url '.
|
||||
|
@ -636,23 +636,25 @@
|
|||
/**
|
||||
* Create a new Character.
|
||||
*
|
||||
* @param int $userId User-ID that creates the new character
|
||||
* @param int $charactertypeId ID of type of new Character
|
||||
* @param int $userId User-ID that creates the new character
|
||||
* @param int $charactertypeId ID of type of new Character
|
||||
* @param string $characterName Name for the new Character
|
||||
* @return int ID of Character
|
||||
* @param int $gender Gender of new Character
|
||||
* @return int ID of Character
|
||||
*/
|
||||
public function createCharacter($userId, $charactertypeId, $characterName)
|
||||
public function createCharacter($userId, $charactertypeId, $characterName, $gender)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO characters '.
|
||||
'(user_id, charactertype_id, name, url) '.
|
||||
'(user_id, charactertype_id, name, url, gender) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?, ?)',
|
||||
'iiss',
|
||||
'(?, ?, ?, ?, ?)',
|
||||
'iissi',
|
||||
$userId,
|
||||
$charactertypeId,
|
||||
$characterName,
|
||||
\nre\core\Linker::createLinkParam($characterName)
|
||||
\nre\core\Linker::createLinkParam($characterName),
|
||||
$gender
|
||||
);
|
||||
|
||||
|
||||
|
@ -663,20 +665,24 @@
|
|||
/**
|
||||
* Edit a new Character.
|
||||
*
|
||||
* @param int $characterId ID of the Character to edit
|
||||
* @param int $charactertypeId ID of new type of Character
|
||||
* @param int $characterId ID of the Character to edit
|
||||
* @param int $charactertypeId ID of new type of Character
|
||||
* @param string $characterName New name for Character
|
||||
* @param int $gender New gender of Character
|
||||
* @param int $charactertitleId ID of new Character title
|
||||
*/
|
||||
public function editCharacter($characterId, $charactertypeId, $characterName)
|
||||
public function editCharacter($characterId, $charactertypeId, $characterName, $gender, $charactertitleId)
|
||||
{
|
||||
$this->db->query(
|
||||
'UPDATE characters '.
|
||||
'SET charactertype_id = ?, name = ?, url = ? '.
|
||||
'SET charactertype_id = ?, name = ?, url = ?, gender = ?, charactertitle_id = ? '.
|
||||
'WHERE id = ?',
|
||||
'issi',
|
||||
'issiii',
|
||||
$charactertypeId,
|
||||
$characterName,
|
||||
\nre\core\Linker::createLinkParam($characterName),
|
||||
$gender,
|
||||
$charactertitleId,
|
||||
$characterId
|
||||
);
|
||||
}
|
||||
|
|
175
models/CharactertitlesModel.inc
Normal file
175
models/CharactertitlesModel.inc
Normal file
|
@ -0,0 +1,175 @@
|
|||
<?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 Charactertitles-table.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class CharactertitlesModel extends \hhu\z\Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new CharactertitlesModel.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get a Character title by its ID.
|
||||
*
|
||||
* @throws \nre\exceptions\IdNotFoundException
|
||||
* @param int $titleId ID of title
|
||||
* @return array Title data
|
||||
*/
|
||||
public function getTitleById($titleId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, title_male, title_female '.
|
||||
'FROM charactertitles '.
|
||||
'WHERE id = ?',
|
||||
'i',
|
||||
$titleId
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($titleId);
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all titles a Character owns.
|
||||
*
|
||||
* @param int $characterId ID of Character to get titles for
|
||||
* @return array List of title data
|
||||
*/
|
||||
public function getTitlesForCharacter($characterId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT charactertitles.id, title_male, title_female '.
|
||||
'FROM characters_charactertitles '.
|
||||
'INNER JOIN charactertitles ON charactertitles.id = characters_charactertitles.charactertitle_id '.
|
||||
'WHERE characters_charactertitles.character_id = ? '.
|
||||
'ORDER BY title_male, title_female ',
|
||||
'i',
|
||||
$characterId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// TODO addTitleToCharacter
|
||||
|
||||
/**
|
||||
* TODO Check if a Character title already exists.
|
||||
*
|
||||
* @param string $title Character title to check
|
||||
* @param int $seminaryId ID of Seminary
|
||||
* @param int $questId Do not check this ID (for editing)
|
||||
* @return boolean Whether Character title exists or not
|
||||
*/
|
||||
public function characterTitleExists($titleMale, $titleFemale, $seminaryId, $titleId=null)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id '.
|
||||
'FROM charactertitles '.
|
||||
'WHERE seminary_id = ? AND (title_male = ? OR title_female = ?)',
|
||||
'iss',
|
||||
$seminaryId,
|
||||
$titleMale,
|
||||
$titleFemale
|
||||
//\nre\core\Linker::createLinkParam($title)
|
||||
);
|
||||
|
||||
return (!empty($data) && (is_null($titleId) || $titleId != $data[0]['id']));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TODO Create a new Character title.
|
||||
*
|
||||
* @param int $userId User-ID that creates the new title
|
||||
* @param int $seminaryId ID of Questgroup
|
||||
* @param string $titleMale Title for male Characters
|
||||
* @param string $titleFemale Title for female Characters
|
||||
* @return int ID of new Character title
|
||||
*/
|
||||
public function createTitle($userId, $seminaryId, $titleMale, $titleFemale)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO charactertitles '.
|
||||
'(created_user_id, seminary_id, title_male, title_female) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?, ?)',
|
||||
'iiss',
|
||||
$userId, $seminaryId,
|
||||
$titleMale, $titleFemale
|
||||
//\nre\core\Linker::createLinkParam($title),
|
||||
);
|
||||
|
||||
|
||||
return $this->db->getInsertId();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TODO Edit a Character title.
|
||||
*
|
||||
* @param int $titleId ID of Character title to edit
|
||||
* @param string $titleMale Title for male Characters
|
||||
* @param string $titleFemale Title for female Characters
|
||||
*/
|
||||
public function editTitle($titleId, $titleMale, $titleFemale)
|
||||
{
|
||||
$this->db->query(
|
||||
'UPDATE charactertitles '.
|
||||
'SET title_male = ?, title_female = ? '.
|
||||
'WHERE id = ?',
|
||||
'ssi',
|
||||
$titleMale,
|
||||
$titleFemale,
|
||||
//\nre\core\Linker::createLinkParam($title),
|
||||
$titleId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TODO Delete a Character title.
|
||||
*
|
||||
* @param int $titleId ID of Character title to delete
|
||||
*/
|
||||
public function deleteTitle($titleId)
|
||||
{
|
||||
$this->db->query(
|
||||
'DELETE FROM charactertitles '.
|
||||
'WHERE id = ?',
|
||||
'i',
|
||||
$titleId
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
|
@ -34,6 +34,12 @@
|
|||
default: echo _('Character name invalid');
|
||||
}
|
||||
break;
|
||||
case 'gender':
|
||||
switch($setting) {
|
||||
case 'correct': echo _('Please select a gender');
|
||||
break;
|
||||
}
|
||||
break;
|
||||
} ?>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
|
@ -69,7 +75,28 @@
|
|||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
<label for="gender"><?=_('Gender')?>:</label>
|
||||
<select id="gender" name="gender">
|
||||
<option value=""><?=_('Select gender')?></option>
|
||||
<option value="0" <?php if($gender === 0) : ?>selected="selected"<?php endif ?>><?=_('Female')?></option>
|
||||
<option value="1" <?php if($gender === 1) : ?>selected="selected"<?php endif ?>><?=_('Male')?></option>
|
||||
</select>
|
||||
</fieldset>
|
||||
|
||||
<?php if(count($titles) > 0) : ?>
|
||||
<fieldset>
|
||||
<legend><?=_('Display settings')?></legend>
|
||||
<?php if(count($titles) > 0) : ?>
|
||||
<label><?=_('Charactertitle')?></label>
|
||||
<select id="title" name="title">
|
||||
<option value="" <?php if(is_null($charactertitle)) : ?>selected="selected"<?php endif ?>><?=_('no title')?></option>
|
||||
<?php foreach($titles as &$title) : ?>
|
||||
<option value="<?=$title['id']?>" <?php if(!is_null($charactertitle) && $title['id'] == $charactertitle['id']) : ?>selected="selected"<?php endif ?>><?=($gender) ? $title['title_male'] : $title['title_female']?></option>
|
||||
<?php endforeach ?>
|
||||
</select>
|
||||
<?php endif ?>
|
||||
</fieldset>
|
||||
<?php endif ?>
|
||||
|
||||
<?php if($fieldsValidation !== true) : ?>
|
||||
<ul>
|
||||
|
|
|
@ -32,6 +32,12 @@
|
|||
break;
|
||||
}
|
||||
break;
|
||||
case 'gender':
|
||||
switch($setting) {
|
||||
case 'correct': echo _('Please select a gender');
|
||||
break;
|
||||
}
|
||||
break;
|
||||
} ?>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
|
@ -57,6 +63,12 @@
|
|||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
<label for="gender"><?=_('Gender')?>:</label>
|
||||
<select id="gender" name="gender">
|
||||
<option value=""><?=_('Select gender')?></option>
|
||||
<option value="0"><?=_('Female')?></option>
|
||||
<option value="1"><?=_('Male')?></option>
|
||||
</select>
|
||||
</fieldset>
|
||||
|
||||
<?php if($fieldsValidation !== true) : ?>
|
||||
|
|
Loading…
Reference in a new issue