search for the first text of a Questgroup recursively (Issue #77)
This commit is contained in:
parent
22ae4c46d7
commit
0294040063
3 changed files with 53 additions and 16 deletions
|
|
@ -126,10 +126,9 @@
|
||||||
|
|
||||||
// Get first Questgroup text
|
// Get first Questgroup text
|
||||||
$text = $this->Questgroups->getFirstQuestgroupText($questgroup['id']);
|
$text = $this->Questgroups->getFirstQuestgroupText($questgroup['id']);
|
||||||
if(!empty($text))
|
if(!is_null($text))
|
||||||
{
|
{
|
||||||
$text = \hhu\z\Utils::shortenString($text['text'], 100, 120).' …';
|
$questgroup['text'] = \hhu\z\Utils::shortenString($text, 100, 120).' …';
|
||||||
$questgroup['text'] = $text;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get cumulated data
|
// Get cumulated data
|
||||||
|
|
|
||||||
|
|
@ -179,27 +179,47 @@
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get first texts of a Questgroup.
|
* Get the first text of a Questgroup.
|
||||||
*
|
*
|
||||||
* @param int $questgroupId ID of a Questgroup
|
* @param int $questgroupId ID of a Questgroup
|
||||||
* @return array First Text of this Questgroup
|
* @return string First text of this Questgroup or NULL
|
||||||
*/
|
*/
|
||||||
public function getFirstQuestgroupText($questgroupId)
|
public function getFirstQuestgroupText($questgroupId)
|
||||||
{
|
{
|
||||||
$data = $this->db->query(
|
// Text of Questgroup itself
|
||||||
'SELECT id, pos, text '.
|
$questgroupTexts = $this->getQuestgroupTexts($questgroupId);
|
||||||
'FROM questgrouptexts '.
|
if(!empty($questgroupTexts)) {
|
||||||
'WHERE questgroup_id = ? '.
|
return $questgroupTexts[0]['text'];
|
||||||
'ORDER BY pos ASC '.
|
}
|
||||||
'LIMIT 1',
|
|
||||||
'i',
|
// Text of first Quest
|
||||||
$questgroupId
|
$quest = $this->Quests->getFirstQuestOfQuestgroup($questgroupId);
|
||||||
);
|
if(!is_null($quest))
|
||||||
if(!empty($data)) {
|
{
|
||||||
return $data[0];
|
$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->getQuestgroupsForHierarchy($hierarchy['id'], $questgroupId);
|
||||||
|
foreach($questgroups as &$group)
|
||||||
|
{
|
||||||
|
$childQuestgroupText = $this->getFirstQuestgroupText($group['id']);
|
||||||
|
if(!is_null($childQuestgroupText)) {
|
||||||
|
return $childQuestgroupText;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// No text found
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,24 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
* Get all Questtexts for a Quest.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue