implement CharactergroupsAgent and include it in Seminary page
This commit is contained in:
parent
3f30fad8f2
commit
305a086ae6
8 changed files with 322 additions and 0 deletions
35
agents/intermediate/CharactergroupsAgent.inc
Normal file
35
agents/intermediate/CharactergroupsAgent.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 display Character groups.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class CharactergroupsAgent extends \nre\agents\IntermediateAgent
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Action: index.
|
||||
*/
|
||||
public function index(\nre\core\Request $request, \nre\core\Response $response)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -82,6 +82,7 @@
|
|||
array('^([^/]+)/([^/]+)/?$', 'questgropus/questgroup/$1/$2', true),
|
||||
// z/<Seminary>/<Questgroup>/<Quest> ⇒ z/quests/quest/<Seminary>/<Questgroup>/<Quest>
|
||||
array('^([^/]+)/([^/]+)/([^/]+)/?$', 'quests/quest/$1/$2/3', true)*/
|
||||
array('charactergroups/(?!(index|groupsgroup|group))', 'charactergroups/index/$1', true),
|
||||
array('media/(.*)', 'media/$1?layout=binary', false),
|
||||
array('media/(.*)', 'media/index/$1', true)
|
||||
);
|
||||
|
|
@ -98,6 +99,7 @@
|
|||
array('users/([^/]+)/(.*)', 'users/$2/$1', true),
|
||||
array('seminaries/seminary/(.*)', 'seminaries/$1', false),
|
||||
//array('seminaries/seminary/(.*)', '$1', false)
|
||||
array('charactergroup/index/(.*)', 'charactergroup/$1', true),
|
||||
array('media/index/(.*)', 'media/$1', true)
|
||||
);
|
||||
|
||||
|
|
|
|||
131
controllers/CharactergroupsController.inc
Normal file
131
controllers/CharactergroupsController.inc
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
<?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 CharactergroupsAgent to display Character groups.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class CharactergroupsController extends \hhu\z\controllers\SeminaryRoleController
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('seminaries', 'charactergroups');
|
||||
/**
|
||||
* User permissions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $permissions = array(
|
||||
'quest' => array('admin', 'moderator', 'user')
|
||||
);
|
||||
/**
|
||||
* User seminary permissions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $seminaryPermissions = array(
|
||||
'quest' => array('admin', 'moderator', 'user')
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Action: index.
|
||||
*
|
||||
* Show Character groups-groups for a Seminary.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param string $seminaryUrl URL-Title of a Seminary
|
||||
*/
|
||||
public function index($seminaryUrl)
|
||||
{
|
||||
// Get seminary
|
||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||
|
||||
// Get Character groups-groups
|
||||
$groupsgroups = $this->Charactergroups->getGroupsroupsForSeminary($seminary['id']);
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('groupsgroups', $groupsgroups);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: groupsgroups.
|
||||
*
|
||||
* Show Character groups for a Character groups-group of a
|
||||
* Seminary.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param string $seminaryUrl URL-Title of a Seminary
|
||||
* @param string $groupsgroupUrl URL-Title of a Character groups-group
|
||||
*/
|
||||
public function groupsgroup($seminaryUrl, $groupsgroupUrl)
|
||||
{
|
||||
// Get seminary
|
||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||
|
||||
// Get Character groups-group
|
||||
$groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl);
|
||||
|
||||
// Get Character groups
|
||||
$groups = $this->Charactergroups->getGroupsForGroupsgroup($groupsgroup['id']);
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('groupsgroup', $groupsgroup);
|
||||
$this->set('groups', $groups);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: group.
|
||||
*
|
||||
* Show a Character group for a Character groups-group of a
|
||||
* Seminary.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param string $seminaryUrl URL-Title of a Seminary
|
||||
* @param string $groupsgroupUrl URL-Title of a Character groups-group
|
||||
* @param string $groupUrl URL-Title of a Character group
|
||||
*/
|
||||
public function group($seminaryUrl, $groupsgroupUrl, $groupUrl)
|
||||
{
|
||||
// Get seminary
|
||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||
|
||||
// Get Character groups-group
|
||||
$groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl);
|
||||
|
||||
// Get Character group
|
||||
$group = $this->Charactergroups->getGroupByUrl($groupsgroup['id'], $groupUrl);
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('groupsgroup', $groupsgroup);
|
||||
$this->set('group', $group);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
127
models/CharactergroupsModel.inc
Normal file
127
models/CharactergroupsModel.inc
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
<?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 of the CharactergroupsAgent to interact with
|
||||
* Charactergroups-table.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class CharactergroupsModel extends \hhu\z\Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new CharactergroupsModel.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get Character groups-groups of a Seminary.
|
||||
*
|
||||
* @param int $seminaryId ID of the corresponding Seminary
|
||||
* @return array Character groups-groups data
|
||||
*/
|
||||
public function getGroupsroupsForSeminary($seminaryId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, name, url '.
|
||||
'FROM charactergroupsgroups '.
|
||||
'WHERE seminary_id = ?',
|
||||
'i',
|
||||
$seminaryId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a Character groups-group by its URL.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param int $seminaryId ID of the corresponding Seminary
|
||||
* @param string $groupsgroupUrl URL-name of the Character groups-group
|
||||
* @return array Character groups-group data
|
||||
*/
|
||||
public function getGroupsgroupByUrl($seminaryId, $groupsgroupUrl)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, name, url '.
|
||||
'FROM charactergroupsgroups '.
|
||||
'WHERE seminary_id = ? AND url = ?',
|
||||
'is',
|
||||
$seminaryId, $groupsgroupUrl
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($groupsgroupUrl);
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Character groups for a Character groups-group.
|
||||
*
|
||||
* @param int $groupsgroupId ID of the Character groups-group
|
||||
* @return array Character groups
|
||||
*/
|
||||
public function getGroupsForGroupsgroup($groupsgroupId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, name, url '.
|
||||
'FROM charactergroups '.
|
||||
'WHERE charactergroupsgroup_id = ?',
|
||||
'i',
|
||||
$groupsgroupId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a Character group by its URL.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param int $groupsgroupId ID of the Character groups-group
|
||||
* @param string $groupUrl URL-name of the Character group
|
||||
* @return array Character group data
|
||||
*/
|
||||
public function getGroupByUrl($groupsgroupId, $groupUrl)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, name, url '.
|
||||
'FROM charactergroups '.
|
||||
'WHERE charactergroupsgroup_id = ? AND url = ?',
|
||||
'is',
|
||||
$groupsgroupId, $groupUrl
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($groupUrl);
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
5
views/html/charactergroups/group.tpl
Normal file
5
views/html/charactergroups/group.tpl
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<h1><?=_('Seminaries')?></h1>
|
||||
<h2><?=$seminary['title']?></h2>
|
||||
<h3><?=_('Character Groups')?></h3>
|
||||
<h4><?=$groupsgroup['name']?></h4>
|
||||
<h5><?=$group['name']?></h5>
|
||||
10
views/html/charactergroups/groupsgroup.tpl
Normal file
10
views/html/charactergroups/groupsgroup.tpl
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<h1><?=_('Seminaries')?></h1>
|
||||
<h2><?=$seminary['title']?></h2>
|
||||
<h3><?=_('Character Groups')?></h3>
|
||||
<h4><?=$groupsgroup['name']?></h4>
|
||||
|
||||
<ul>
|
||||
<?php foreach($groups as &$group) : ?>
|
||||
<li><a href="<?=$linker->link(array('group',$seminary['url'],$groupsgroup['url'],$group['url']),1)?>"><?=$group['name']?></a></li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
9
views/html/charactergroups/index.tpl
Normal file
9
views/html/charactergroups/index.tpl
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<h1><?=_('Seminaries')?></h1>
|
||||
<h2><?=$seminary['title']?></h2>
|
||||
<h3><?=_('Character Groups')?></h3>
|
||||
|
||||
<ul>
|
||||
<?php foreach($groupsgroups as &$group) : ?>
|
||||
<li><a href="<?=$linker->link(array('groupsgroup',$seminary['url'],$group['url']),1)?>"><?=$group['name']?></a></li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
|
|
@ -4,6 +4,9 @@
|
|||
<li><a href="<?=$linker->link('edit', 3)?>"><?=_('Edit seminary')?></a></li>
|
||||
<li><a href="<?=$linker->link('delete', 3)?>"><?=_('Delete seminary')?></a></li>
|
||||
</nav>
|
||||
<nav>
|
||||
<li><a href="<?=$linker->link(array('charactergroups',$seminary['url']))?>"><?=_('Character Groups')?></a></li>
|
||||
</nav>
|
||||
<p>
|
||||
<?=sprintf(_('created by %s on %s'), $seminary['creator']['username'], $dateFormatter->format(new \DateTime($seminary['created'])))?>
|
||||
</p>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue