implement LibraryAgent
This commit is contained in:
parent
bf16cb9c9d
commit
64805a27db
8 changed files with 401 additions and 28 deletions
35
agents/intermediate/LibraryAgent.inc
Normal file
35
agents/intermediate/LibraryAgent.inc
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?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\agents\intermediate;
|
||||
|
||||
|
||||
/**
|
||||
* Agent to list Quest topics.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class LibraryAgent extends \nre\agents\IntermediateAgent
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Action: index.
|
||||
*/
|
||||
public function index(\nre\core\Request $request, \nre\core\Response $response)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -24,7 +24,7 @@
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('seminaries', 'characters', 'users', 'charactergroups', 'charactertypes', 'seminarycharacterfields', 'avatars', 'media');
|
||||
public $models = array('seminaries', 'characters', 'users', 'charactergroups', 'charactertypes', 'seminarycharacterfields', 'avatars', 'media', 'questtopics');
|
||||
/**
|
||||
* Required components
|
||||
*
|
||||
|
|
@ -123,6 +123,14 @@
|
|||
// Get Achievements
|
||||
$achievements = $this->Achievements->getAchievedAchievementsForCharacter($character['id']);
|
||||
|
||||
// Get Quest topics
|
||||
$questtopics = $this->Questtopics->getQuesttopicsForSeminary($seminary['id']);
|
||||
foreach($questtopics as &$questtopic)
|
||||
{
|
||||
$questtopic['questcount'] = $this->Questtopics->getQuestCountForQuesttopic($questtopic['id']);
|
||||
$questtopic['characterQuestcount'] = $this->Questtopics->getCharacterQuestCountForQuesttopic($questtopic['id'], $character['id']);
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
|
|
@ -131,6 +139,7 @@
|
|||
$this->set('user', $user);
|
||||
$this->set('groups', $groups);
|
||||
$this->set('achievements', $achievements);
|
||||
$this->set('questtopics', $questtopics);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
129
controllers/LibraryController.inc
Normal file
129
controllers/LibraryController.inc
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
<?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\controllers;
|
||||
|
||||
|
||||
/**
|
||||
* Controller of the LibraryAgent to list Quest topics.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class LibraryController extends \hhu\z\controllers\SeminaryRoleController
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('questtopics', 'seminaries', 'quests', 'questgroups');
|
||||
/**
|
||||
* User permissions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $permissions = array(
|
||||
'index' => array('admin', 'moderator', 'user')
|
||||
);
|
||||
/**
|
||||
* User seminary permissions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $seminaryPermissions = array(
|
||||
'index' => array('admin', 'moderator', 'user')
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Action: index.
|
||||
*
|
||||
* List Questtopics of a Seminary.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param string $seminaryUrl URL-Title of Seminary
|
||||
*/
|
||||
public function index($seminaryUrl)
|
||||
{
|
||||
// Get Seminary
|
||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||
|
||||
// Get Character
|
||||
$character = IntermediateController::$character;
|
||||
|
||||
// Get Quest topics
|
||||
$questtopics = $this->Questtopics->getQuesttopicsForSeminary($seminary['id']);
|
||||
foreach($questtopics as &$questtopic)
|
||||
{
|
||||
// Get Quest count
|
||||
$questtopic['questcount'] = $this->Questtopics->getQuestCountForQuesttopic($questtopic['id']);
|
||||
|
||||
// Get Character progress
|
||||
$questtopic['characterQuestcount'] = $this->Questtopics->getCharacterQuestCountForQuesttopic($questtopic['id'], $character['id']);
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('questtopics', $questtopics);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: topic.
|
||||
*
|
||||
* Show a Questtopic and its Quests with Questsubtopics.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param string $eminaryUrl URL-Title of Seminary
|
||||
* @param string $questtopicUrl URL-Title of Questtopic
|
||||
*/
|
||||
public function topic($seminaryUrl, $questtopicUrl)
|
||||
{
|
||||
// Get Seminary
|
||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||
|
||||
// Get Character
|
||||
$character = IntermediateController::$character;
|
||||
|
||||
// Get Questtopic
|
||||
$questtopic = $this->Questtopics->getQuesttopicByUrl($seminary['id'], $questtopicUrl);
|
||||
$questtopic['questcount'] = $this->Questtopics->getQuestCountForQuesttopic($questtopic['id']);
|
||||
$questtopic['characterQuestcount'] = $this->Questtopics->getCharacterQuestCountForQuesttopic($questtopic['id'], $character['id']);
|
||||
|
||||
// Get Quests
|
||||
$quests = array();
|
||||
foreach($this->Quests->getQuestsForQuesttopic($questtopic['id']) as $quest)
|
||||
{
|
||||
if($this->Quests->hasCharacterEnteredQuest($quest['id'], $character['id']))
|
||||
{
|
||||
// Get Questgroup
|
||||
$quest['questgroup'] = $this->Questgroups->getQuestgroupById($quest['questgroup_id']);
|
||||
|
||||
// Get Subtopics
|
||||
$quest['subtopics'] = $this->Questtopics->getQuestsubtopicsForQuest($quest['id']);
|
||||
|
||||
$quests[] = $quest;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('questtopic', $questtopic);
|
||||
$this->set('quests', $quests);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -325,6 +325,25 @@
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all Quests that are linked to a Questtopic.
|
||||
*
|
||||
* @param int $questtopicId ID of Questtopic
|
||||
* @return array Quests for this Questtopic
|
||||
*/
|
||||
public function getQuestsForQuesttopic($questtopicId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT DISTINCT quests.id, quests.questgroup_id, quests.questtype_id, quests.title, quests.url, quests.xps, quests.task, quests.right_text, quests.wrong_text, quests.questsmedia_id '.
|
||||
'FROM quests_questsubtopics '.
|
||||
'INNER JOIN quests ON quests.id = quests_questsubtopics.quest_id '.
|
||||
'WHERE quests_questsubtopics.questsubtopic_id = ?',
|
||||
'i',
|
||||
$questtopicId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
|||
154
models/QuesttopicsModel.inc
Normal file
154
models/QuesttopicsModel.inc
Normal file
|
|
@ -0,0 +1,154 @@
|
|||
<?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 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 = ?',
|
||||
'i',
|
||||
$seminaryId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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 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 = ?',
|
||||
'i',
|
||||
$questId
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -94,38 +94,16 @@
|
|||
</div>
|
||||
|
||||
<section>
|
||||
<h1><i class="fa fa-book fa-fw"></i>Thematischer Fortschritt</h1>
|
||||
<h1><i class="fa fa-book fa-fw"></i><?=_('Topic progress')?></h1>
|
||||
<ul class="ctopics cf">
|
||||
<?php foreach($questtopics as &$topic) : ?>
|
||||
<li>
|
||||
<p><small><a href="#">Klassifikation</a> (3/5)</small></p>
|
||||
<p><small><a href="<?=$linker->link(array('library','topic',$seminary['url'],$topic['url']))?>"><?=$topic['title']?></a> (<?=$topic['characterQuestcount']?>/<?=$topic['questcount']?>)</small></p>
|
||||
<div class="xpbar">
|
||||
<span style="width:60%"></span>
|
||||
</div>
|
||||
</li>
|
||||
<li>
|
||||
<p><small><a href="#">Thesauri</a> (1/10)</small></p>
|
||||
<div class="xpbar">
|
||||
<span style="width:10%"></span>
|
||||
</div>
|
||||
</li>
|
||||
<li>
|
||||
<p><small><a href="#">Indexierung</a> (3/5)</small></p>
|
||||
<div class="xpbar">
|
||||
<span style="width:20%"></span>
|
||||
</div>
|
||||
</li>
|
||||
<li>
|
||||
<p><small><a href="#">Recherche</a> (3/5)</small></p>
|
||||
<div class="xpbar">
|
||||
<span style="width:80%"></span>
|
||||
</div>
|
||||
</li>
|
||||
<li>
|
||||
<p><small><a href="#">Folksonomies</a> (3/5)</small></p>
|
||||
<div class="xpbar">
|
||||
<span style="width:70%"></span>
|
||||
<span style="width:<?=round($topic['characterQuestcount']/$topic['questcount']*100)?>%"></span>
|
||||
</div>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
|
|
|
|||
21
views/html/library/index.tpl
Normal file
21
views/html/library/index.tpl
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<?php if(!is_null($seminary['seminarymedia_id'])) : ?>
|
||||
<div class="moodpic">
|
||||
<img src="<?=$linker->link(array('media','seminaryheader',$seminary['url']))?>" />
|
||||
</div>
|
||||
<?php endif ?>
|
||||
<h1><a href="<?=$linker->link(array('seminaries',$seminary['url']))?>"><?=$seminary['title']?></a></h1>
|
||||
<h2><?=_('Questtopics')?></h2>
|
||||
|
||||
<ul>
|
||||
<?php foreach($questtopics as &$topic) : ?>
|
||||
<li>
|
||||
<h3><a href="<?=$linker->link(array('library','topic',$seminary['url'],$topic['url']))?>"><?=$topic['title']?></a></h3>
|
||||
<div class="cf">
|
||||
<div class="xpbar">
|
||||
<span style="width:<?=round($topic['characterQuestcount']/$topic['questcount']*100)?>%"></span>
|
||||
</div>
|
||||
<p class="xpnumeric"><?=$topic['characterQuestcount']?>/<?=$topic['questcount']?></p>
|
||||
</div>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
28
views/html/library/topic.tpl
Normal file
28
views/html/library/topic.tpl
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<?php if(!is_null($seminary['seminarymedia_id'])) : ?>
|
||||
<div class="moodpic">
|
||||
<img src="<?=$linker->link(array('media','seminaryheader',$seminary['url']))?>" />
|
||||
</div>
|
||||
<?php endif ?>
|
||||
<h1><a href="<?=$linker->link(array('seminaries',$seminary['url']))?>"><?=$seminary['title']?></a></h1>
|
||||
<h2><a href="<?=$linker->link(array('index',$seminary['url']),1)?>"><?=_('Questtopics')?></a></h2>
|
||||
<h3><?=$questtopic['title']?></h3>
|
||||
|
||||
<div class="cf">
|
||||
<div class="xpbar">
|
||||
<span style="width:<?=round($questtopic['characterQuestcount']/$questtopic['questcount']*100)?>%"></span>
|
||||
</div>
|
||||
<p class="xpnumeric"><?=$questtopic['characterQuestcount']?>/<?=$questtopic['questcount']?></p>
|
||||
</div>
|
||||
|
||||
<ul>
|
||||
<?php foreach($quests as &$quest) : ?>
|
||||
<li>
|
||||
<a href="<?=$linker->link(array('quests','quest',$seminary['url'],$quest['questgroup']['url'],$quest['url']))?>"><?=$quest['title']?></a>
|
||||
<ul>
|
||||
<?php foreach($quest['subtopics'] as &$subtopic) : ?>
|
||||
<li><?=$subtopic['title']?></li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
Loading…
Add table
Add a link
Reference in a new issue