implement CRUD for Character groups Quests (Issue #30)

This commit is contained in:
coderkun 2014-04-30 00:49:32 +02:00
commit 53c1002ab2
10 changed files with 754 additions and 41 deletions

View file

@ -80,6 +80,31 @@
}
/**
* Get a Character groups Quest by its ID.
*
* @throws 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 the Character groups for a Quest.
*
@ -131,6 +156,112 @@
}
/**
* 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']));
}
/**
* 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
);
}
/**
* 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);
}
}
?>